Skip to content

Commit

Permalink
Resolve review suggestions
Browse files Browse the repository at this point in the history
Rename Boiling to strict,
Remove redundant branching and error throwing code
  • Loading branch information
QuillInkwell committed Feb 3, 2025
1 parent 3442e3b commit 1b1de60
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/JSON/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| climate_control_str_chill() ||| u, n | return amount of chill climate control that character currently has (character feels better in cold places with it), in warmth points; default 0, affected by CLIMATE_CONTROL_HEAT enchantment.<br/><br/>Example:<br/>`"condition": { "math": [ "n_climate_control_str_chill() < 0" ] }`|
| calories() ||| u, n | Return amount of calories character has. If used on item, return amount of calories this item gives when consumed (not affected by enchantments or mutations). Optional kwargs:<br/>`format`: `s`/`v` - return the value in specific format. Can be `percent` (return percent to the healthy amount of calories, `100` being the target, bmi 25, or 110000 kcal) or `raw`. If now used, `raw` is used by default.<br/>`dont_affect_weariness`: `true`/`false` (default false) When assigning value, whether the gained/spent calories should be tracked by weariness.<br/><br/>Example:<br/>`"condition": { "math": [ "u_calories() < 0" ] }`<br/>`"condition": { "math": [ "u_calories('format': 'percent') > 0" ] }`<br/>`"condition": { "math": [ "u_calories() = 110000" ] }`|
| get_calories_daily() ||| g | Return amount of calories character consumed before, up to 30 days, in kcal. Calorie diary is something only character has, so it can't be used with NPCs. Optional kwargs:<br/>`day`: `d/v` - picks the date the value would be pulled from, from 0 to 30. Default 0, meaning amount of calories you consumed today.<br/>`type`: `s/v` - picks the data that would be pulled. Possible values are: `spent` - how much calories character spent in different activities throughout the day; `gained` - how much calories character ate that day; `ingested` - how much calories character processed that day; `total` - `gained` minus `spent`. Default is `total`;<br/><br/>Example:<br/>`"condition": { "math": [ "get_calories_daily() > 1000" ] }`<br/> `{ "math": [ "foo = get_calories_daily('type':'gained', 'day':'1')" ] }`|
| quality( `s` / `v` ) | ✅ | ❌ | u, n | Return the level of a specified item tool quality. Only usable on item talkers.<br/>Argument is the quality ID. Returns the lowest integer value if the item lacks the specified quality.<br/>Optional kwargs:<br/>`boiling`: `true` / `false` (default false) When true the item must be empty to have the boiling quality.<br/><br/>Example<br/>`"condition: { "math": [ " u_quality('HACK') > 0 " ] }`<br/>`{ "math": [ "_cut_quality = u_quality('CUT') " ] }`<br/>`condition: { "math": [ " u_quality('BOIL', 'boiling': true ) > 0" ] }`
| quality( `s` / `v` ) | ✅ | ❌ | u, n | Return the level of a specified item tool quality. Only usable on item talkers.<br/>Argument is the quality ID. Returns the lowest integer value if the item lacks the specified quality.<br/>Optional kwargs:<br/>`strict`: `true` / `false` (default false) When true the item must be empty to have the boiling quality.<br/><br/>Example<br/>`"condition: { "math": [ " u_quality('HACK') > 0 " ] }`<br/>`{ "math": [ "_cut_quality = u_quality('CUT') " ] }`<br/>`condition: { "math": [ " u_quality('BOIL', 'strict': true ) > 0" ] }`

#### List of Character and item aspects
These can be read or written to with `val()`.
Expand Down
4 changes: 2 additions & 2 deletions src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,9 @@ bool item_location::can_reload_with( const item_location &ammo, bool now ) const
return reloadable->can_reload_with( *ammo, now );
}

int item_location::get_quality( const std::string &quality, bool boiling ) const
int item_location::get_quality( const std::string &quality, bool strict ) const
{
const item_location tool = *this;
quality_id qualityid( quality );
return tool->get_quality_nonrecursive( qualityid, boiling );
return tool->get_quality_nonrecursive( qualityid, strict );
}
2 changes: 1 addition & 1 deletion src/item_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class item_location
* @param quality the name of quality to check the level of
* @param boiling true if the item is required to be empty to have the boiling quality
*/
int get_quality( const std::string &quality, bool boiling ) const;
int get_quality( const std::string &quality, bool strict ) const;

private:
class impl;
Expand Down
13 changes: 5 additions & 8 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1692,18 +1692,15 @@ diag_eval_dbl_f weight_eval( char scope, std::vector<diag_value> const & /* para
diag_eval_dbl_f quality_eval( char scope, std::vector<diag_value> const &params /* params */,
diag_kwargs const &kwargs /* kwargs */ )
{
diag_value boiling_val = kwargs.kwarg_or( "boiling" );
diag_value strict_val = kwargs.kwarg_or( "strict" );

return[quality_param = params[0], boiling_val,
return[quality_param = params[0], strict_val,
beta = is_beta( scope )]( const_dialogue const & d ) {
item_location const *it = d.const_actor( beta )->get_const_item();

Check failure on line 1699 in src/math_parser_diag.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

unused variable 'it' [-Werror,-Wunused-variable]

Check failure on line 1699 in src/math_parser_diag.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

unused variable 'it' [clang-diagnostic-unused-variable,-warnings-as-errors]
if( it && *it ) {
std::string quality = quality_param.str( d );
bool boiling = is_true( boiling_val.dbl( d ) );
std::string quality = quality_param.str( d );
bool strict = is_true( strict_val.dbl( d ) );

return d.const_actor( beta )->get_quality( quality, boiling );
}
throw math::runtime_error( "For quality(), talker is not an item" );
return d.const_actor( beta )->get_quality( quality, strict );
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/talker_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ int talker_item_const::get_weight() const
return units::to_milligram( me_it_const->get_item()->weight() );
}

int talker_item_const::get_quality( const std::string &quality, bool boiling ) const
int talker_item_const::get_quality( const std::string &quality, bool strict ) const
{
return me_it_const->get_quality( quality, boiling );
return me_it_const->get_quality( quality, strict );
}

void talker_item::set_value( const std::string &var_name, const std::string &value )
Expand Down
2 changes: 1 addition & 1 deletion src/talker_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class talker_item_const: public const_talker_cloner<talker_item_const>
int encumbrance_at( bodypart_id & ) const override;
int get_volume() const override;
int get_weight() const override;
int get_quality( const std::string &, bool boiling ) const override;
int get_quality( const std::string &, bool strict ) const override;

private:
const item_location *me_it_const{};
Expand Down

0 comments on commit 1b1de60

Please sign in to comment.