Skip to content

Commit

Permalink
Allow EOCs to search items by caloric content (#72886)
Browse files Browse the repository at this point in the history
* I am merely a conduit

Renech did literally all of this

Co-Authored-By: RenechCDDA <[email protected]>

* documentation

---------

Co-authored-by: RenechCDDA <[email protected]>
  • Loading branch information
Karol1223 and RenechCDDA authored Apr 9, 2024
1 parent ee2d713 commit dc205a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/EFFECT_ON_CONDITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ Run EOCs on items in your or NPC's inventory
| Syntax | Optionality | Value | Info |
| --- | --- | --- | --- |
| "u_run_inv_eocs" / "npc_run_inv_eocs" | **mandatory** | string or [variable object](#variable-object) | way the item would be picked; <br/>values can be:<br/>`all` - all items that match the conditions are picked;<br/> `random` - from all items that match the conditions, one picked;<br/>`manual` - menu is open with all items that can be picked, and you can choose one;<br/>`manual_mult` - same as `manual`, but multiple items can be picked |
| "search_data" | optional | `search_data` | sets the condition for the target item; lack of search_data means any item can be picked; conditions can be:<br/>`id` - id of a specific item;<br/>`category` - category of an item (case sensitive, should always be in lower case);<br/>`flags`- flag or flags the item has<br/>`excluded_flags`- flag or flags the item doesn't have<br/>`material` - material of an item;<br/>`worn_only` - if true, return only items, that are worn;<br/>`wielded_only` - if true, return only wielded items |
| "search_data" | optional | `search_data` | sets the condition for the target item; lack of search_data means any item can be picked; conditions can be:<br/>`id` - id of a specific item;<br/>`category` - category of an item (case sensitive, should always be in lower case);<br/>`flags`- flag or flags the item has<br/>`excluded_flags`- flag or flags the item doesn't have<br/>`material` - material of an item;<br/>`worn_only` - if true, return only items, that are worn;<br/>`wielded_only` - if true, return only wielded items;<br/>`calories` - minimum amount of kcal of an item |
| "title" | optional | string or [variable object](#variable-object) | name of the menu, that would be shown, if `manual` or `manual_mult` is used |
| "true_eocs" / "false_eocs" | optional | string, [variable object](##variable-object), inline EoC, or range of all of them | if item was picked successfully, all EoCs from `true_eocs` are run, otherwise all EoCs from `false_eocs` are run; picked item is returned as npc; for example, `n_hp()` return hp of an item |

Expand Down
11 changes: 11 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct item_search_data {
itype_id id;
item_category_id category;
material_id material;
int calories = 0;
std::vector<flag_id> flags;
std::vector<flag_id> excluded_flags;
bool worn_only;
Expand All @@ -182,6 +183,9 @@ struct item_search_data {
id = itype_id( jo.get_string( "id", "" ) );
category = item_category_id( jo.get_string( "category", "" ) );
material = material_id( jo.get_string( "material", "" ) );
if( jo.has_int( "calories" ) ) {
calories = jo.get_int( "calories" );
}
for( std::string flag : jo.get_string_array( "flags" ) ) {
flags.emplace_back( flag );
}
Expand All @@ -202,6 +206,13 @@ struct item_search_data {
if( !material.is_empty() && loc->made_of( material ) == 0 ) {
return false;
}
if( calories > 0 ) {
// This is very stupid but we need a dummy to calculate nutrients
npc dummy;
if( dummy.compute_effective_nutrients( *loc.get_item() ).kcal() < calories ) {
return false;
}
}
for( flag_id flag : flags ) {
if( !loc->has_flag( flag ) ) {
return false;
Expand Down

0 comments on commit dc205a2

Please sign in to comment.