Skip to content

Commit

Permalink
expose new faction values to math
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll committed Aug 14, 2024
1 parent 54be579 commit fa1e5c7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br/>Argument is effect ID.<br/><br/>Optional kwargs:<br/>`bodypart`: `s`/`v` - Specify the bodypart to get/set duration of effect.<br/>`unit`: `s`/`v` - Specify the unit of the duration. Omitting will use seconds.<br/><br/> Example:<br/>`"condition": { "math": [ "u_effect_duration('bite', 'bodypart': 'torso')", ">", "1"] }`<br/>`{ "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.<br/>Argument is bodypart ID. <br/> For items, returns typical encumbrance of the item. <br/><br/>Example:<br/>`"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)).<br/><br/>Example:<br/>`{ "math": [ "u_val('power')", "-=", "energy('25 kJ')" ] }`|
| faction_like(`s`/`v`)<br/>faction_respect(`s`/`v`)<br/>faction_trust(`s`/`v`) || | N/A<br/>(global) | Return the like/respect/trust value a faction has for the avatar.<br/>Argument is faction ID.<br/><br/>Example:<br/>`"condition": { "math": [ "faction_like('hells_raiders') < -60" ] }`|
| faction_like(`s`/`v`)<br/>faction_respect(`s`/`v`)<br/>faction_trust(`s`/`v`)<br/>faction_food_supply(`s`/`v`)<br/>faction_wealth(`s`/`v`)<br/>faction_power(`s`/`v`)<br/>faction_size(`s`/`v`) || | N/A<br/>(global) | Return the like/respect/trust/fac_food_supply/wealth/power/size value a faction has for the avatar.<br/>Argument is faction ID.<br/><br/>Example:<br/>`"condition": { "math": [ "faction_like('hells_raiders') < -60" ] }`|
| field_strength(`s`/`v`) ||| u, n, global | Return the strength of a field on the tile.<br/>Argument is field ID.<br/><br/>Optional kwargs:<br/> `location`: `v` - center search on this location<br/><br/>The `location` kwarg is mandatory in the global scope.<br/><br/>Examples:<br/>`"condition": { "math": [ "u_field_strength('fd_blood')", ">", "5" ] }`<br/><br/>`"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.<br/><br/> Example:<br/>`"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.<br/><br/> Example:<br/>`"condition": { "math": [ "u_blorg", "=", "u_has_trait('FEEBLE') ? 100 : 15" ] }`|
Expand Down
80 changes: 80 additions & 0 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,78 @@ std::function<void( dialogue &, double )> faction_trust_ass( char /* scope */,
};
}

std::function<double( dialogue & )> faction_food_supply_eval( char /* scope */,
std::vector<diag_value> const &params, 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<void( dialogue &, double )> faction_food_supply_ass( char /* scope */,
std::vector<diag_value> const &params, 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<double( dialogue & )> faction_wealth_eval( char /* scope */,
std::vector<diag_value> const &params, 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<void( dialogue &, double )> faction_wealth_ass( char /* scope */,
std::vector<diag_value> const &params, 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<double( dialogue & )> faction_power_eval( char /* scope */,
std::vector<diag_value> const &params, 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<void( dialogue &, double )> faction_power_ass( char /* scope */,
std::vector<diag_value> const &params, 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<double( dialogue & )> faction_size_eval( char /* scope */,
std::vector<diag_value> const &params, 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<void( dialogue &, double )> faction_size_ass( char /* scope */,
std::vector<diag_value> const &params, 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<double( dialogue & )> field_strength_eval( char scope,
std::vector<diag_value> const &params, diag_kwargs const &kwargs )
{
Expand Down Expand Up @@ -1678,6 +1750,10 @@ std::map<std::string_view, dialogue_func_eval> 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 } },
Expand Down Expand Up @@ -1733,6 +1809,10 @@ std::map<std::string_view, dialogue_func_ass> 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 } },
Expand Down

0 comments on commit fa1e5c7

Please sign in to comment.