Skip to content

Commit

Permalink
Add perceived kwarg to pain_eval math function, apply it in Mind Over…
Browse files Browse the repository at this point in the history
… Matter (CleverRaven#72938)

* Initial commit

* Retool to kwarg (thanks GuardianDII)

* Update src/math_parser_diag.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Standing-Storm and github-actions[bot] authored May 3, 2024
1 parent 262e2b6 commit 8b64122
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ "not": { "u_has_effect": "effect_psi_too_much_pain_cant_channel" } },
{
"math": [
"u_pain() - u_val('pkill')",
"u_pain('type': 'perceived')",
">=",
"40 + ( 15 * ((u_has_trait('CONCENTRATION_GOOD')) + (u_has_trait('CONCENTRATION_BAD') ? -1 : 0) + (u_has_trait('INT_ALPHA')) + (u_has_trait('CONCENTRATION_DEBUG') ? 50 : 0) + (u_has_proficiency('prof_concentration_basic') ? 1 : 0) + (u_has_proficiency('prof_concentration_intermediate') ? 2 : 0) + (u_has_proficiency('prof_concentration_master') ? 3 : 0)))"
]
Expand Down
2 changes: 1 addition & 1 deletion doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| mon_groups_nearby(`s`/`v`...) ||| u, n, global | Same as `monsters_nearby()`, but arguments are monster groups |
| moon_phase() ||| N/A<br/>(global) | Returns current phase of the Moon. <pre>MOON_NEW = 0,<br/>WAXING_CRESCENT = 1,<br/>HALF_MOON_WAXING = 2,<br/>WAXING_GIBBOUS = 3,<br/>FULL = 4,<br/>WANING_GIBBOUS = 5,<br/>HALF_MOON_WANING = 6,<br/>WANING_CRESCENT = 7 |
| num_input(`s`/`v`,`d`/`v`) ||| N/A<br/>(global) | Prompt the player for a number.<br/>Arguments are Prompt text, Default Value:<br/>`"math": [ "u_value_to_set", "=", "num_input('Playstyle Perks Cost?', 4)" ]`|
| pain() ||| u, n | Return or set pain<br/> Example:<br/>`{ "math": [ "n_pain()", "=", "u_pain() + 9000" ] }`|
| pain() ||| u, n | Return or set pain. Optional kwargs:<br/>`type`: `s/v` - return the value of specific format. Can be `perceived` (return pain value minus painkillers) or `raw`. If not used, `raw` is used by default. <br/> Example:<br/>`{ "math": [ "n_pain()", "=", "u_pain() + 9000" ] }` <br/>`{ "math": [ "u_pain('type': 'perceived' )", ">=", "40" ] }` |
| proficiency(`s`/`v`) ||| u, n | Return or set proficiency<br/>Argument is proficiency ID.<br/><br/> Optional kwargs:<br/>`format`: `s` - `percent` return or set how many percent done the learning is. `permille` does likewise for permille. `time_spent` return or set total time spent. `time_left` return or set the remaining time. `total_time_required` return total time required to train a given proficiency (read only).<br/>`direct`: `true`/`false`/`d` - false (default) perform the adjustment by practicing the proficiency for the given amount of time. This will likely result in different values than specified. `true` perform the adjustment directly, bypassing other factors that may affect it.<br/><br/>Example:<br/>`{ "math": [ "u_proficiency('prof_intro_chemistry', 'format': 'percent')", "=", "50" ] }`|
| school_level(`s`/`v`) ||| u, n | Return the highest level of spells known of that school.<br/>Argument is school ID.<br/><br/>Example:<br/>`"condition": { "math": [ "u_school_level('MAGUS')", ">=", "3"] }`|
| school_level_adjustment(`s`/`v`) ||| u, n | Return or set temporary caster level adjustment. Only useable by EoCs that trigger on the event `opens_spellbook`. Old values will be reset to 0 before the event triggers. To avoid overwriting values from other EoCs, it is recommended to adjust the values here with `+=` or `-=` instead of setting it to an absolute value.<br/>Argument is school ID.<br/><br/>Example:<br/>`{ "math": [ "u_school_level_adjustment('MAGUS')", "+=", "3"] }`|
Expand Down
18 changes: 15 additions & 3 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,22 @@ std::function<double( dialogue & )> moon_phase_eval( char /* scope */,
}

std::function<double( dialogue & )> pain_eval( char scope,
std::vector<diag_value> const &/* params */, diag_kwargs const &/* kwargs */ )
std::vector<diag_value> const &/* params */, diag_kwargs const &kwargs )
{
return [beta = is_beta( scope )]( dialogue const & d ) {
return d.actor( beta )->pain_cur();
diag_value format_value( std::string( "raw" ) );
if( kwargs.count( "type" ) != 0 ) {
format_value = *kwargs.at( "type" );
}
return [format_value, beta = is_beta( scope )]( dialogue const & d ) {
std::string format = format_value.str( d );
if( format == "perceived" ) {
return d.actor( beta )->perceived_pain_cur();
} else if( format == "raw" ) {
return d.actor( beta )->pain_cur();
} else {
debugmsg( R"(Unknown type "%s" for pain())", format );
return 0;
}
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ class talker
virtual int pain_cur() const {
return 0;
}
virtual int perceived_pain_cur() const {
return 0;
}
virtual void attack_target( Creature &, bool, const matec_id &,
bool, int ) {}

Expand Down
5 changes: 5 additions & 0 deletions src/talker_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ int talker_character_const::pain_cur() const
return me_chr_const->get_pain();
}

int talker_character_const::perceived_pain_cur() const
{
return me_chr_const->get_perceived_pain();
}

double talker_character_const::armor_at( damage_type_id &dt, bodypart_id &bp ) const
{
return me_chr_const->worn.damage_resist( dt, bp );
Expand Down
1 change: 1 addition & 0 deletions src/talker_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class talker_character_const: public talker_cloner<talker_character_const>
int per_cur() const override;
int attack_speed() const override;
int pain_cur() const override;
int perceived_pain_cur() const override;
double armor_at( damage_type_id &dt, bodypart_id &bp ) const override;
int coverage_at( bodypart_id & ) const override;
int encumbrance_at( bodypart_id & ) const override;
Expand Down
5 changes: 5 additions & 0 deletions src/talker_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ int talker_monster_const::pain_cur() const
return me_mon_const->get_pain();
}

int talker_monster_const::perceived_pain_cur() const
{
return me_mon_const->get_perceived_pain();
}

bool talker_monster_const::has_effect( const efftype_id &effect_id, const bodypart_id &bp ) const
{
return me_mon_const->has_effect( effect_id, bp );
Expand Down
2 changes: 2 additions & 0 deletions src/talker_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class talker_monster_const: public talker_cloner<talker_monster_const>

int pain_cur() const override;

int perceived_pain_cur() const override;

// effects and values
bool has_effect( const efftype_id &effect_id, const bodypart_id &bp ) const override;
effect get_effect( const efftype_id &effect_id, const bodypart_id &bp ) const override;
Expand Down

0 comments on commit 8b64122

Please sign in to comment.