diff --git a/doc/NPCs.md b/doc/NPCs.md index 5ffdf4fc63d96..98e5a6a0dea0f 100644 --- a/doc/NPCs.md +++ b/doc/NPCs.md @@ -1339,7 +1339,7 @@ _some functions support array arguments or kwargs, denoted with square brackets | effect_duration(`s`/`v`) | ✅ | ✅ | u, n | Return the characters duration of effect.
Argument is effect ID.

Optional kwargs:
`bodypart`: `s`/`v` - Specify the bodypart to get/set duration of effect.
`unit`: `s`/`v` - Specify the unit of the duration. Omitting will use seconds.

Example:
`"condition": { "math": [ "u_effect_duration('bite', 'bodypart': 'torso')", ">", "1"] }`
`{ "math": [ "_thing", "=", "u_effect_duration('yrax_overcharged', 'bodypart': 'torso', 'unit': 'hours')" ] }`| | encumbrance(`s`/`v`) | ✅ | ❌ | u, n | Return the characters total encumbrance of a body part.
Argument is bodypart ID.
For items, returns typical encumbrance of the item.

Example:
`"condition": { "math": [ "u_encumbrance('torso')", ">", "0"] }`| | energy(`s`/`v`) | ✅ | ❌ | u, n | Return a numeric value (in millijoules) for an energy string (see [Units](JSON_INFO.md#units)).

Example:
`{ "math": [ "u_val('power')", "-=", "energy('25 kJ')" ] }`| -| faction_like(`s`/`v`)
faction_respect(`s`/`v`)
faction_trust(`s`/`v`) | ✅ | ❌ | N/A
(global) | Return the like/respect/trust value a faction has for the avatar.
Argument is faction ID.

Example:
`"condition": { "math": [ "faction_like('hells_raiders') < -60" ] }`| +| faction_like(`s`/`v`)
faction_respect(`s`/`v`)
faction_trust(`s`/`v`)
faction_food_supply(`s`/`v`)
faction_wealth(`s`/`v`)
faction_power(`s`/`v`)
faction_size(`s`/`v`) | ✅ | ✅ | N/A
(global) | Return the like/respect/trust/fac_food_supply/wealth/power/size value a faction has for the avatar.
Argument is faction ID.

Example:
`"condition": { "math": [ "faction_like('hells_raiders') < -60" ] }`| | field_strength(`s`/`v`) | ✅ | ❌ | u, n, global | Return the strength of a field on the tile.
Argument is field ID.

Optional kwargs:
`location`: `v` - center search on this location

The `location` kwarg is mandatory in the global scope.

Examples:
`"condition": { "math": [ "u_field_strength('fd_blood')", ">", "5" ] }`

`"condition": { "math": [ "field_strength('fd_blood_insect', 'location': u_search_loc)", ">", "5" ] }`| | has_flag(`s`/`v`) | ✅ | ❌ | u, n | Check whether the actor has a flag. Meant to be used as condition for ternaries. Arguemnt is trait ID.

Example:
`"condition": { "math": [ "u_blorg", "=", "u_has_flag('MUTATION_TRESHOLD') ? 100 : 15" ] }`| | has_trait(`s`/`v`) | ✅ | ❌ | u, n | Check whether the actor has a trait. Meant to be used as condition for ternaries. Arguemnt is trait ID.

Example:
`"condition": { "math": [ "u_blorg", "=", "u_has_trait('FEEBLE') ? 100 : 15" ] }`| diff --git a/src/math_parser_diag.cpp b/src/math_parser_diag.cpp index 98f111dd9fb56..bbf429c58058c 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -270,6 +270,78 @@ std::function faction_trust_ass( char /* scope */, }; } +std::function faction_food_supply_eval( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue & d ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + return fac->food_supply.calories; + }; +} + +std::function faction_food_supply_ass( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue const & d, double val ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + fac->food_supply.calories = val; + }; +} + +std::function faction_wealth_eval( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue & d ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + return fac->wealth; + }; +} + +std::function faction_wealth_ass( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue const & d, double val ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + fac->wealth = val; + }; +} + +std::function faction_power_eval( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue & d ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + return fac->power; + }; +} + +std::function faction_power_ass( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue const & d, double val ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + fac->power = val; + }; +} + +std::function faction_size_eval( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue & d ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + return fac->size; + }; +} + +std::function faction_size_ass( char /* scope */, + std::vector const ¶ms, diag_kwargs const &/* kwargs */ ) +{ + return [fac_val = params[0]]( dialogue const & d, double val ) { + faction *fac = g->faction_manager_ptr->get( faction_id( fac_val.str( d ) ) ); + fac->size = val; + }; +} + std::function field_strength_eval( char scope, std::vector const ¶ms, diag_kwargs const &kwargs ) { @@ -1678,6 +1750,10 @@ std::map const dialogue_eval_f{ { "faction_like", { "g", 1, faction_like_eval } }, { "faction_respect", { "g", 1, faction_respect_eval } }, { "faction_trust", { "g", 1, faction_trust_eval } }, + { "faction_food_supply", { "g", 1, faction_food_supply_eval } }, + { "faction_wealth", { "g", 1, faction_wealth_eval } }, + { "faction_power", { "g", 1, faction_power_eval } }, + { "faction_size", { "g", 1, faction_size_eval } }, { "field_strength", { "ung", 1, field_strength_eval } }, { "gun_damage", { "un", 1, gun_damage_eval } }, { "game_option", { "g", 1, option_eval } }, @@ -1733,6 +1809,10 @@ std::map const dialogue_assign_f{ { "faction_like", { "g", 1, faction_like_ass } }, { "faction_respect", { "g", 1, faction_respect_ass } }, { "faction_trust", { "g", 1, faction_trust_ass } }, + { "faction_food_supply", { "g", 1, faction_food_supply_ass } }, + { "faction_wealth", { "g", 1, faction_wealth_ass } }, + { "faction_power", { "g", 1, faction_power_ass } }, + { "faction_size", { "g", 1, faction_size_ass } }, { "hp", { "un", 1, hp_ass } }, { "pain", { "un", 0, pain_ass } }, { "school_level_adjustment", { "un", 1, school_level_adjustment_ass } },