Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menus to kitchen unit and welding rig (Finally Ready!) #3395

Merged
merged 14 commits into from Oct 16, 2013

Conversation

Projects
None yet
4 participants
@NaturesWitness
Copy link
Contributor

commented Oct 1, 2013

In my quest to make the RV kitchen unit and welding rig have all the same features as their portable counterparts, I'm trying to add the use_hotplate and soldier_weld iuse menus to them. As I don't actually know how to code, it's a disaster, errors out the wazoo. I'm hoping if I try to put this together, people who actually know how to code will see it, laugh for a while at all the idiotic mistakes, and help me fix it.

EDIT - Thanks to the help (and endless patience of) Kevingranade and atomicdryad, this is complete and functional! Tested and works, I think this really adds to the usefulness of the RV kitchen and welding rig, and it also gets rid of the annoying string of yes/no prompts the RV kitchen gave you, and replaces it with a neat, tidy menu selection instead.

Add hotplate menu to kitchen unit try 1
In my quest to make the kitchen usable as a hotplate to heat food and
cauterize, here's my first try.  Needless to say, it's a disaster,
errors out the wazoo.  Not really sure what I'm doing, just hoping
people who can actually code can tell me how to make this work :)
game.cpp Outdated
@@ -7297,6 +7297,35 @@ void game::pickup(int posx, int posy, int min)
veh->refill("water", amt);
}
}
if (query_yn(_("Use hotplate?")))

This comment has been minimized.

Copy link
@kevingranade

kevingranade Oct 2, 2013

Member

tabs, no, evil.
Also there are enough prompts here that it should probably be a menu instead of a bunch of prompts.

game.cpp Outdated
@@ -7248,7 +7248,7 @@ void game::list_items()
}

// Pick up items at (posx, posy).
void game::pickup(int posx, int posy, int min)
void game::pickup(int posx, int posy, int min, game *g, player *p, item *it, bool t)

This comment has been minimized.

Copy link
@kevingranade

kevingranade Oct 2, 2013

Member

You don't need to add the parameters to pickup.

game.cpp Outdated
if (query_yn(_("Use hotplate?")))
{
{
if(it->charges == 0)

This comment has been minimized.

Copy link
@kevingranade

kevingranade Oct 2, 2013

Member

Instead of replicating the hotplate code here, generate a fake hotplate, and call the iuse function on it. This involves draining charges from the vehicle's batteries and then refilling what's left afterwards. Take a look at vehicle::fire_turret_internal() for an example of doing this with a UPS.

NaturesWitness added some commits Oct 2, 2013

remove tabs, extra parameters
Trying again, still lots of errors.  I always forget how to deal with
"not declared in this scope"
try 3
Still pretty confused, trying to implement Kevin's idea to create a fake
hotplate and use it.  Couldn't even find UPS mentioned in vehiclle.cpp,
trying code from map.cpp for other parts of kitchen unit.  I have a
feeling this attempt is just gibberish, but who knows.
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2013

I probably shouldn't try to code late at night, I have no idea what I'm doing with this. I couldn't find any mention of the UPS in vehicle.cpp, and I'm not sure how to get a menu to try to use an item. I'll sleep on it, and maybe in the morning it'll all make sense.

@kevingranade

This comment has been minimized.

Copy link
Member

commented Oct 2, 2013

oh.... oops, that PR hasn't landed yet, my bad. PR #3361

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2013

Well I got some sleep and feel much better. Will try and work on this more later today, have to help the neighbor with some stuff so might not be till later tonight. Plus I'm currently addicted to watching a let's play series by Totalbiscuit and Jesse Cox playing a game called "Terraria" which mostly involves them randomly fumbling about and Jesse repeatedly falling to his death down holes (look it up, it's hysterical, also Terraria is a really cool game).

Try 4, now with 20% less gibberish!
This may be the first code I've added to this PR that isn't just random
scribbles.  It still doesn't work, of course, but it FEELS less moronic.
Anyway, this adds Kevin's suggestions of turning the string of prompts
into a menu and using the code from vehicle::fire_turret_internal to
create a fake hotplate that uses the vehicle's battery.  I think the
menu part of this is functional, but I still don't know how to make it
actually use the fake hotplate.  I also need to figure out how to
declare the extra functions in the menu.  Here's the list of compile
errors this generated, maybe we can get this sorted out.
C:\Documents and Settings\Mason\My
Documents\GitHub\Cataclysm-DDA\game.cpp||In member function 'void
game::pickup(int, int, int)':|
C:\Documents and Settings\Mason\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7303|error: 'drain' was not
declared in this scope|
C:\Documents and Settings\Mason\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7304|error: 'tmp' was not
declared in this scope|
C:\Documents and Settings\Mason\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7305|error: invalid use of
non-static member function 'void iuse::hotplate(game*, player*, item*,
bool)'|
C:\Documents and Settings\Mason\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7307|error: 'refill' was not
declared in this scope|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 8 seconds) ===|
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 3, 2013

I think I'm at least making progress, although there are still issues to work out (listed in pull description)

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 4, 2013

Okay to fix these undefined reference bugs, I think I need to get game.cpp to look at vehicle.cpp to find the blocks for vehicle::refill and vehicle::drain. The problem is, I don't know how to do it. I tried adding #include vehicle.h to game .cpp but that didn't do anything. What am I missing here?

@kevingranade

This comment has been minimized.

Copy link
Member

commented Oct 4, 2013

the context. The code you're copying from is inside the vehicle class, so it can call drain() and refill() directly, since this code is not in the vehicle code, it needs to access it like veh->drain() and veh->refill(). Also something's weird about if(choice == 2)break;

Progress made! (I think?)
Thanks to Kevin's advice this is down to just two errors!  Here's the
list:
C:\Documents and Settings\Barbara\My
Documents\GitHub\Cataclysm-DDA\game.cpp||In member function 'void
game::pickup(int, int, int)':|
C:\Documents and Settings\Barbara\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7304|error: 'tmp' was not
declared in this scope|
C:\Documents and Settings\Barbara\My
Documents\GitHub\Cataclysm-DDA\game.cpp|7305|error: invalid use of
non-static member function 'void iuse::hotplate(game*, player*, item*,
bool)'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 10 seconds) ===|

The first error I think is being caused because the code is still trying
to give the tmp_hotplate item to the fake NPC "tmp", who isn't here.  I
think this needs to be given to the PLAYER, because if I add in the tmp
NPC the hotplate will looks for items inthe3 NPC's inventory, not the
players.  So now I need the command to give this to the player, which I
can't figure out.
The second error is from me not knowing how to get Cata to "use" the
fake hotplate we're generating.  so far, all my guesses are coming up
empty, and I can't find an example in the code to copy.
If we can iron these two bugs out, I think this will all work!
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 5, 2013

Only two errors left, in the home stretch!

Add NPC to hold the hotplate
Adds an NPC to hold the hotplate, as I can't figure out how to give it
to the player.  Still don't know how to actually use the hotplate, I've
tried about everything I can think of.
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 5, 2013

Well adding an NPC to hold the hotplate quieted one of the errors, but I'm not sure if it will actually work. Now the only thing left is to get it to apply the hotplate, which I'm having no luck with at all. Care to give me a hint Kevin?

@kevingranade

This comment has been minimized.

Copy link
Member

commented Oct 6, 2013

Rather than spawning a NPC to hold the fake hotplate, what you want to do is spawn a fake hotplate and pass it to iuse::hotplate(). See player::use() around line 7474 for how that's done.
Also you need to exit the function if you actually use the kitchen so it doesn't also popup the vehicle examine menu.

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 6, 2013

Okay thanks I'll try and get another commit up tonight.

Trying again
Okay ditched the fake NPC and figured out how to give this to the
player.  Also added the got_water = true line to prevent us going to
examine vehicle.  Problem is now that I've given the hotplate to the
player I can't figure out how to get rid of it afterword.  I tried
u.i.rem but couldn't get it working.  Also still can't figure out how to
set the values in iuse::hotplate to make it compile.
@kevingranade

This comment has been minimized.

Copy link
Member

commented Oct 7, 2013

You shouldn't need to give it to the player, just make an item object, load it with some charges, and pass it and a reference to the player to the iuse method. Mucking with the inventory while we do this is the last thing you want to do. To use it in crafting (does that work?) it needs to be added to the "crafting inventory" that gets generated on the fly from items near the player. Cancelling the action is currently a problem, but I'm making some changes to iuse that should prevent that from being a problem.

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 7, 2013

I'm starting to get the feeling this may simply be too complicated for me to do with my limited knowledge of coding. Any chance you or someone else could just wrap this up for me? I have a feeling someone like you or Glyph could finish this up in about ten minutes, and once it's done for the kitchen I can just look at the code and get the welding rig part done. Sorry to pass the buck like this, but at this rate this'll never get done. BTW the crafting part of this was already in before, I just wanted to add the functionality of the iuse menus so people could repair their armor, heat food, etc. with the battery power in their vehicle.

Almost there!
Needed to take a break from this for a few days, was getting
frustrating.  I think I almost have it, I'm just missing one value for
line 7304.  Got rid of adding the hotplate to inventory, and I think I
fixed the code for refunding the remaining charges to the battery.  I
think I'm literally 5 letters away from this working, can anyone tell me
what the last line needs to be?
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 10, 2013

Okay took a break from this for a few days and feel much better. Removed the adding the hotplate to inventory thing, so there should only be one bug left. I think I have the u.use command in right, I just can't figure out what the second function value should be. I have no idea how values for this function work, can anyone tell me what the second entry needs to be?

@atomicdryad

This comment has been minimized.

Copy link

commented on 2edd276 Oct 11, 2013

This would be the inventory letter of the item...which means it needs to go into inventory -.-
Then
hotplate_ref.invlet
would be arg2 to u.use
The system needs an overhaul, yeah.....

This comment has been minimized.

Copy link

replied Oct 11, 2013

I'm gonna take a look at this and see if it's possible to work without inventory cheese. I'll PR your PR if I do

@atomicdryad

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2013

Not sure why I can't pr, but check out atomicdryad@57a038c

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 11, 2013

You. Are. AWESOME! It works! I'll get a new commit up in a sec, and then I'll see if I can use the code from this as a reference to get the welding rig fixed. Huge thanks to both of you for all the help with this, this would have gone nowhere without your help, aka doing all the parts I don't understand, which is about all of it. I really am trying to learn something when doing these, so I can be more helpful in adding stuff to this fun game.

NaturesWitness added some commits Oct 11, 2013

It works!!!
Thanks to the efforts of Kevin and dryad, this actually works!  Now all
that's left is to finish the welding rig part of this, which I'll try
and get committed soon.
Menu polishing
Now that the mechanics part of this works, I can focus on cleaning up
the menu part of it.  Ditched the last of the huge string of yes-no
queries from the old version, now examining the kitchen unit gives us a
nice, neat menu instead.  Also renamed the got_water bool in this
function to used_feature to avoid any confusion, and altered it's
placement in the code order to prevent the examine vehicle menu from
popping up after using the kitchen unit functions.  Now all that's left
is to add in the welding rig code, and finally vehicle-mounted equipment
will be just as useful as carried equipment!
Added welding rig, getting weird bug
So I added in the code for the welding rig, and it kinda works.  The
problem is, it only works if you've dropped an item in the welding rig.
Otherwise, you just get the "you can't do that while onboard!" message
it gives you when you try to examine a vehicle while in it.  Also, if
you do drop an item in the welding rig, it lets you examine the vehicle
even if you're onboard.  I'm not quite sure what's causing this, I'm
probably missing a ; or a , somewhere.  I'll try and look at this again
tomorrow, but if someone could glance at this and see what boneheaded
thing I missed, it would really help.
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 12, 2013

Just realized these have one other problem; they bypass the check for if you're on board the vehicle when you try to examine it. I guess this is going to be harder than I thought, oh well I'll try and work on it today.

@atomicdryad

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2013

Hm, well they didn't check before iirc?
if( u.in_vehicle ) {..
should work any rate

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 13, 2013

There's something wrong with the menus in this; the kitchen unit works, but the game seems to be missing the code for the welding rig. Anyone know what's wrong with this?

Fixed welding rig menu
Figured out why the welding rig menu wasn't appearing; I forgot to add
the presence of a welding as a condition to shunt player_examine to
pickup.  With that done, this is finally complete!
@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 14, 2013

Hooray, it's finished! Thank you Kevingranade for all the advice you gave me while I was fumbling in the dark with this, and a big thanks to atomicdryad for writing the code block that actually made the hotplate iuse command work. I've tested this and it works great, the only other thing I think I could add to this would be a fix for the RV kitchen and welding rig not checking if you're standing in the vehicle before giving you the vehicle examine screen, but that probably is better addressed in a new PR.

@ACCount12

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2013

Is it possible to add some tools to welding rig or kitchen unit ingame? I think attaching hand press (and other tools, even unpowered ones) to rig can make some crafting recipes much less boring.

@NaturesWitness

This comment has been minimized.

Copy link
Contributor Author

commented Oct 15, 2013

It is possible, kitchen unit actually provides a pot and pan when standing near it. Both the kitchen and rig can store items, so if you just put your tools in them you can use all of them when standing near it. One feature of Cata that isn't well documented is that while crafting, you can use any tool or component that is two squares or less away from your character, it can be on the ground, in a container, wherever.

atomicdryad added a commit that referenced this pull request Oct 16, 2013

Merge pull request #3395 from NaturesWitness/improve-weld-rig
Merge kitchen unit / welding rig improvements.

@atomicdryad atomicdryad merged commit 222b5cc into CleverRaven:master Oct 16, 2013

1 check passed

default Merged build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.