From 8f1b534ad63e4e9556e70d2b31358eee4fec2ad7 Mon Sep 17 00:00:00 2001 From: "Standing-StormStanding-Storm git config --global user.name Standing-Storm git config --global user.name Standing-Storm" Date: Tue, 9 Apr 2024 16:03:11 -0500 Subject: [PATCH 1/3] Initial commit --- .../effectoncondition/eoc_power_effects.json | 2 +- doc/NPCs.md | 1 + src/math_parser_diag.cpp | 9 +++++++++ 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, 27 insertions(+), 1 deletion(-) diff --git a/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json b/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json index a99c924f393b8..d013919c647c7 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_perceived_pain()", ">=", "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 b163f4f59dde5..a618a810e14cf 100644 --- a/doc/NPCs.md +++ b/doc/NPCs.md @@ -1352,6 +1352,7 @@ _some functions support array arguments or kwargs, denoted with square brackets | 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" ] }`| +| perceived_pain() | ✅ | ❌ | u, n | Return perceived pain: value of pain - value of painkillers
Example:
`{ "math": [ "u_perceived_pain()", ">=", "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 146395375a472..feefacec6cb5c 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -811,6 +811,14 @@ std::function pain_eval( char scope, }; } +std::function perceived_pain_eval( char scope, + std::vector const &/* params */, diag_kwargs const &/* kwargs */ ) +{ + return [beta = is_beta( scope )]( dialogue const & d ) { + return d.actor( beta )->perceived_pain_cur(); + }; +} + std::function pain_ass( char scope, std::vector const &/* params */, diag_kwargs const &/* kwargs */ ) { @@ -1467,6 +1475,7 @@ std::map const dialogue_eval_f{ { "moon_phase", { "g", 0, moon_phase_eval } }, { "num_input", { "g", 2, num_input_eval } }, { "pain", { "un", 0, pain_eval } }, + { "perceived_pain", { "un", 0, perceived_pain_eval } }, { "school_level", { "un", 1, school_level_eval}}, { "school_level_adjustment", { "un", 1, school_level_adjustment_eval } }, { "skill", { "un", 1, skill_eval } }, diff --git a/src/talker.h b/src/talker.h index c251552a4d7c1..7b111e99fda2c 100644 --- a/src/talker.h +++ b/src/talker.h @@ -563,6 +563,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 d6422a29619bd..a025d732af2d8 100644 --- a/src/talker_character.cpp +++ b/src/talker_character.cpp @@ -687,6 +687,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 d6a9b30973d87..a4103b5fd818b 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; From 20921a3c42e5a8e0f948fac716d02b8143cbe8bd Mon Sep 17 00:00:00 2001 From: "Standing-StormStanding-Storm git config --global user.name Standing-Storm git config --global user.name Standing-Storm" Date: Fri, 26 Apr 2024 15:31:52 -0500 Subject: [PATCH 2/3] Retool to kwarg (thanks GuardianDII) --- .../effectoncondition/eoc_power_effects.json | 2 +- doc/NPCs.md | 3 +- src/math_parser_diag.cpp | 29 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json b/data/mods/MindOverMatter/effectoncondition/eoc_power_effects.json index d013919c647c7..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_perceived_pain()", + "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 a618a810e14cf..8079084cc3079 100644 --- a/doc/NPCs.md +++ b/doc/NPCs.md @@ -1351,8 +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" ] }`| -| perceived_pain() | ✅ | ❌ | u, n | Return perceived pain: value of pain - value of painkillers
Example:
`{ "math": [ "u_perceived_pain()", ">=", "40" ] }`| +| 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 feefacec6cb5c..a863f24dd5911 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -804,19 +804,23 @@ std::function moon_phase_eval( char /* scope */, } std::function pain_eval( char scope, - std::vector const &/* params */, diag_kwargs const &/* kwargs */ ) -{ - return [beta = is_beta( scope )]( dialogue const & d ) { - return d.actor( beta )->pain_cur(); - }; -} - -std::function perceived_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 )->perceived_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; + } + }; } std::function pain_ass( char scope, @@ -1475,7 +1479,6 @@ std::map const dialogue_eval_f{ { "moon_phase", { "g", 0, moon_phase_eval } }, { "num_input", { "g", 2, num_input_eval } }, { "pain", { "un", 0, pain_eval } }, - { "perceived_pain", { "un", 0, perceived_pain_eval } }, { "school_level", { "un", 1, school_level_eval}}, { "school_level_adjustment", { "un", 1, school_level_adjustment_eval } }, { "skill", { "un", 1, skill_eval } }, From 615780c584d2c1dd6f0000ddfc1c2d795acb0698 Mon Sep 17 00:00:00 2001 From: Standing-Storm <120433252+Standing-Storm@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:04:55 -0500 Subject: [PATCH 3/3] Update src/math_parser_diag.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/math_parser_diag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math_parser_diag.cpp b/src/math_parser_diag.cpp index bdb03f8979582..700c120a52b0d 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -824,7 +824,7 @@ std::function pain_eval( char scope, debugmsg( R"(Unknown type "%s" for pain())", format ); return 0; } - }; + }; } std::function pain_ass( char scope,