From 8b64122a463ac98e35d635cd44afe57df44706b2 Mon Sep 17 00:00:00 2001
From: Standing-Storm <120433252+Standing-Storm@users.noreply.github.com>
Date: Thu, 2 May 2024 22:24:38 -0500
Subject: [PATCH] Add perceived kwarg to pain_eval math function, apply it in
Mind Over Matter (#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>
---
.../effectoncondition/eoc_power_effects.json | 2 +-
doc/NPCs.md | 2 +-
src/math_parser_diag.cpp | 18 +++++++++++++++---
src/talker.h | 3 +++
src/talker_character.cpp | 5 +++++
src/talker_character.h | 1 +
src/talker_monster.cpp | 5 +++++
src/talker_monster.h | 2 ++
8 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json b/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json
index 870985f3a6c1f..4aea3abd48c2d 100644
--- a/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json
+++ b/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json
@@ -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)))"
]
diff --git a/doc/NPCs.md b/doc/NPCs.md
index 644b67cb0cf63..16f7592cd2a24 100644
--- a/doc/NPCs.md
+++ b/doc/NPCs.md
@@ -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
(global) | Returns current phase of the Moon.
MOON_NEW = 0,
WAXING_CRESCENT = 1,
HALF_MOON_WAXING = 2,
WAXING_GIBBOUS = 3,
FULL = 4,
WANING_GIBBOUS = 5,
HALF_MOON_WANING = 6,
WANING_CRESCENT = 7 | | num_input(`s`/`v`,`d`/`v`) | ✅ | ❌ | N/A
(global) | Prompt the player for a number.
Arguments are Prompt text, Default Value:
`"math": [ "u_value_to_set", "=", "num_input('Playstyle Perks Cost?', 4)" ]`| -| pain() | ✅ | ✅ | u, n | Return or set pain
Example:
`{ "math": [ "n_pain()", "=", "u_pain() + 9000" ] }`| +| pain() | ✅ | ✅ | u, n | Return or set pain. Optional kwargs:
`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.
Example:
`{ "math": [ "n_pain()", "=", "u_pain() + 9000" ] }`
`{ "math": [ "u_pain('type': 'perceived' )", ">=", "40" ] }` | | proficiency(`s`/`v`) | ✅ | ✅ | u, n | Return or set proficiency
Argument is proficiency ID.
Optional kwargs:
`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).
`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.
Example:
`{ "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.
Argument is school ID.
Example:
`"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.
Argument is school ID.
Example:
`{ "math": [ "u_school_level_adjustment('MAGUS')", "+=", "3"] }`| diff --git a/src/math_parser_diag.cpp b/src/math_parser_diag.cpp index ac73ca2509771..dc9e65c5c0ccb 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -808,10 +808,22 @@ std::functionmoon_phase_eval( char /* scope */, } std::function pain_eval( char scope, - std::vector const &/* params */, diag_kwargs const &/* kwargs */ ) + std::vector 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; + } }; } diff --git a/src/talker.h b/src/talker.h index aa715ae95eae0..b92ebbf0c89eb 100644 --- a/src/talker.h +++ b/src/talker.h @@ -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 ) {} diff --git a/src/talker_character.cpp b/src/talker_character.cpp index d7548755c41ef..b12146efc0b12 100644 --- a/src/talker_character.cpp +++ b/src/talker_character.cpp @@ -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 ); diff --git a/src/talker_character.h b/src/talker_character.h index dbac8bae97f39..fe0a5d04f0eda 100644 --- a/src/talker_character.h +++ b/src/talker_character.h @@ -71,6 +71,7 @@ class talker_character_const: public talker_cloner 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; diff --git a/src/talker_monster.cpp b/src/talker_monster.cpp index c0400ad9a6182..9de4b67dc24fd 100644 --- a/src/talker_monster.cpp +++ b/src/talker_monster.cpp @@ -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 ); diff --git a/src/talker_monster.h b/src/talker_monster.h index 703f34a26e3d8..9cdb9a993c285 100644 --- a/src/talker_monster.h +++ b/src/talker_monster.h @@ -43,6 +43,8 @@ class talker_monster_const: public talker_cloner 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;