Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upMake multiple use_methods work #11275
Conversation
BevapDin
reviewed
Feb 16, 2015
| iuse::cut_up( p, &salvage_tool, &*it, false ); | ||
| p->assign_activity( ACT_LONGSALVAGE, 0 ); | ||
| return; | ||
| const auto *use_fun = salvage_tool.type->get_use( "salvage" ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 16, 2015
Contributor
Please remove the *, it will be contained in the auto type anyway. It's redundant n most cases.
BevapDin
reviewed
Feb 16, 2015
|
|
||
| const item_action &item_action_generator::get_action( const item_action_id &id ) const | ||
| { | ||
| const auto &iter = item_actions.find( id ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 16, 2015
Contributor
Nitpicking: the reference works and is probably completely valid, but it's confusing, why not make it a regular variable?
This comment has been minimized.
This comment has been minimized.
|
Nice! |
BevapDin
reviewed
Feb 16, 2015
| moves_per_part = obj.get_int( "moves_per_part", 25 ); | ||
| if( obj.has_array( "material_whitelist" ) ) { | ||
| JsonArray jarr = obj.get_array( "material_whitelist" ); | ||
| for( int i = 0; i < (int)jarr.size(); ++i ) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 16, 2015
Contributor
Better: for( size_t i = 0; i < jarr.size(); ...
Or use the "canonical" way (used nearly everywhere else):
while( jarr.has_more() ) {
const auto v = jarr.next_string();Or use JsonObject::get_string_array:
material_whitelist = obj.get_string_array( "material_whitelist" );Also: I agree with Rivet on this PR.
BevapDin
reviewed
Feb 16, 2015
| it->make( target_id ); | ||
| it->active = true; | ||
| } else { | ||
| p->add_msg_if_player( m_bad, _(failure_message.c_str()) ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 16, 2015
Contributor
Careful here: failure_message defaults to an empty string and the translation system will translate the empty string into some debug information about the translation data, you probably don't want that. Check whether the message is empty before displaying it. You can see the translation of the empty string in #10882.
BevapDin
reviewed
Feb 16, 2015
|
|
||
| bool usable = um.get_actor_ptr()->can_use( this, used, false, pos() ); | ||
| const std::string &aname = item_action_generator::generator().get_action_name( um ); | ||
| umenu.addentry( num_total, usable, MENU_AUTOASSIGN, aname.c_str() ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 16, 2015
Contributor
There is an overloaded version of addentry that takes a proper std::string, so you don't need to supply a const char* - call it without the .c_str().
Giving a const char * invokes the string formating, if aname contains a format specifier like "%s", the function will try to access the parameters behind the format and there are none, that's bad.
Note: nice use of the named constant MENU_AUTOASSIGN instead of the literal value
bkentel
reviewed
Feb 17, 2015
| ctxt.register_action("HELP_KEYBINDINGS"); | ||
| ctxt.register_action("QUIT"); | ||
| for( auto id : item_actions ) { | ||
| for( auto id : am ) { |
This comment has been minimized.
This comment has been minimized.
bkentel
reviewed
Feb 17, 2015
| popup( _("You do not have an item that can perform this action.") ); | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| item_action_map map_actions_to_items( player &p ) | ||
| item_action_generator::item_action_generator() |
This comment has been minimized.
This comment has been minimized.
bkentel
reviewed
Feb 17, 2015
| @@ -120,9 +129,39 @@ item_action_map map_actions_to_items( player &p ) | |||
| return candidates; | |||
| } | |||
|
|
|||
| std::string item_action_generator::get_action_name( const item_action_id &id ) const | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Feb 17, 2015
Author
Contributor
The last change was from const ref to pure string, because BevapDin said it would be less confusing this way. At least that's how I understood it.
This comment has been minimized.
This comment has been minimized.
bkentel
reviewed
Feb 17, 2015
| material_whitelist.push_back("kevlar"); | ||
| material_whitelist.push_back("plastic"); | ||
| material_whitelist.push_back("wood"); | ||
| material_whitelist.push_back("wool"); |
This comment has been minimized.
This comment has been minimized.
bkentel
reviewed
Feb 17, 2015
| virtual long use( player*, item*, bool, point ) const; | ||
| virtual iuse_actor *clone() const; | ||
| }; | ||
|
|
This comment has been minimized.
This comment has been minimized.
Coolthulhu
added some commits
Feb 17, 2015
Coolthulhu
force-pushed the
cataclysmbnteam:multi-use-method
branch
Feb 26, 2015
Coolthulhu
force-pushed the
cataclysmbnteam:multi-use-method
branch
to
1d348da
Feb 26, 2015
Coolthulhu
changed the title
[WIP] Make multiple use_methods work
Make multiple use_methods work
Feb 26, 2015
This comment has been minimized.
This comment has been minimized.
|
Un-WiPing this. Has a minor issue: when a fire weapon runs out of charges, it won't print a message. This isn't easily fixable, but it still works much better than in master branch, where it prints an activation menu when the fuel runs out (as if the player activated the weapon). |
This comment has been minimized.
This comment has been minimized.
|
What makes it a hard fix? (Since you're waist deep in that code) |
This comment has been minimized.
This comment has been minimized.
|
Not exactly hard (it can be worked around), but more like a bit hacky - when the fuel runs out, the item function is called with This means it's impossible to tell if the item was activated when at low fuel or if it simply ran out of it. I'll probably make another commit where I implement the old method of doing this, but it will be more of a hack than a fix. |
This comment has been minimized.
This comment has been minimized.
|
OK, got it to work. Wasn't hard, but it isn't exactly the proper solution. |
This comment has been minimized.
This comment has been minimized.
|
To sum up changes (and make it easier to test):
|
This comment has been minimized.
This comment has been minimized.
|
Large PR does not go in when we're prepping for release, sorry. |
kevingranade
reviewed
Mar 8, 2015
| item_action_map map_actions_to_items( player &p ) | ||
| item_action_generator::item_action_generator() = default; | ||
|
|
||
| item_action_generator::~item_action_generator() = default; |
This comment has been minimized.
This comment has been minimized.
kevingranade
Mar 8, 2015
Member
I seem to remember mingw having issues with explicit default destructors, or was that something else?
This comment has been minimized.
This comment has been minimized.
narc0tiq
Mar 8, 2015
Contributor
If I recall correctly, explicit default virtual destructors on subclasses are a problem with gcc 4.7 -- it loses the virtual and then complains about it. Shouldn't be a problem here.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bkentel
Mar 11, 2015
Contributor
It's only the combination of virtual and = default that causes problems on older GCCs AFAIK. I haven't take a careful look at this PR, but what's broken that would indicate the defaulted special member functions?
This comment has been minimized.
This comment has been minimized.
narc0tiq
Mar 11, 2015
Contributor
@kevingranade If you're referencing #11530, that's from some other defaulted destructor -- this one is non-virtual and has nothing to do with the it_{,artifact}_{tool,armor} classes.
This comment has been minimized.
This comment has been minimized.
kevingranade
Mar 11, 2015
Member
Yea my bad, I was following along on my phone and didn't have the details.
kevingranade
reviewed
Mar 8, 2015
| static hp_part use_healing_item(player *p, item *it, int normal_power, int head_power, | ||
| int torso_power, int bleed, | ||
| int bite, int infect, bool force) | ||
| hp_part use_healing_item(player *p, item *it, int normal_power, int head_power, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 8, 2015
Author
Contributor
Yep - I use it to cauterize from iuse_actor.cpp. Currently as extern, but it would probably work better if all the invocations were actually iuse_actor type - medical item functions are simply checking for under water and then invoking use_healing_item. Except for first aid kit, which also assigns an activity.
kevingranade
self-assigned this
Mar 10, 2015
kevingranade
merged commit d4f9b74
into
CleverRaven:master
Mar 10, 2015
1 check passed
narc0tiq
reviewed
Mar 10, 2015
| add_msg(m_bad, _("You no longer have the necessary tools to keep salvaging!")); | ||
| } | ||
|
|
||
| item &salvage_tool = p->i_at( act->values[2] ); |
This comment has been minimized.
This comment has been minimized.
narc0tiq
Mar 10, 2015
Contributor
Yo, it looks like you broke longsalvage so hard, we still can't figure it out. For reference, longsalvage is "Cut up all you can". I'm not convinced you ever tested it.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 10, 2015
Author
Contributor
Tested it in parts - it worked at start, later on I focused on fireweapons.
Will try to fix it now.
EDIT: Yep, I actually forgot to test longsalvage - did test only "shortsalvage".
Still, should be easy to fix.
Coolthulhu commentedFeb 16, 2015
An absolutely huge PR that allows items to have multiple use_methods.
Marking as [WIP] until 0.C is out.
The PR is so huge mostly because I had to update not only the system itself, but also some items.
I moved knives and fire melee weapons (fire katana etc.) into iuse_actors.
iuse::knifeis now 4 iuse_actors:salvage,inscribe,cauterizeandenzlave.I changed the iuse_actor loading function, because I needed it to be able to load many functions with just a single json object. Otherwise any object with KNIFE function would have to be changed into one with 4 actors, which would bloat the jsons (KNIFE is the most often used function).
At the moment multiple iuse_functions only work with iuse_actor functions (will debugmsg and fail if there's more than one and at least one isn't iuse_actor). This is because only iuse_actors store their own "names".
Item action menu becomes a fair bit more useful: now you can use it to cauterize wounds directly, for example (before you'd have to pick knife->cauterize).