Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u_vitamin enchantment conditions do not work #74923

Closed
Standing-Storm opened this issue Jul 6, 2024 · 1 comment · Fixed by #74929
Closed

u_vitamin enchantment conditions do not work #74923

Standing-Storm opened this issue Jul 6, 2024 · 1 comment · Fixed by #74929
Labels
(S2 - Confirmed) Bug that's been confirmed to exist

Comments

@Standing-Storm
Copy link
Contributor

Standing-Storm commented Jul 6, 2024

Describe the bug

Trying to make an enchantment affected by levels of a custom vitamin and it was behaving very strangely. Checking the same with with the iron base-game vitamin, enchantment conditions appear to not work with it.

Attach save file

Pennyhill-trimmed.tar.gz

Steps to reproduce

Copying the following JSON somewhere into your game so it loads:

{ "type": "mutation", "id": "TEST_MUTATION_IRON", "name": { "str": "The testing mutation." }, "points": 0, "description": "The iron in your blood makes you super strong.", "starting_trait": false, "purifiable": false, "valid": false, "enchantments": [ { "condition": { "math": [ "u_vitamin('iron')", ">=", "0" ] }, "values": [ { "value": "STRENGTH", "add": 25 } ] } ]}

  1. Load game
  2. Check needs. Notice that your iron is -5
  3. Check Strength. It's 33, meaning the enchantment above is working even though it should only work when iron is greater than 0.

Expected behavior

u_vitamin works with enchantment conditions

Screenshots

image
image

Versions and configuration

  • OS: Windows
    • OS Version: 10.0.22621.3737 (22H2)
  • Game Version: 7f60041 [64-bit]
  • Graphics Version: Tiles
  • Game Language: English [en]
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Portal Storms Ignore NPCs [personal_portal_storms],
    Slowdown Fungal Growth [no_fungal_growth]
    ]

Additional context

Check #74921 for what I was trying to do

@Standing-Storm Standing-Storm added the (S1 - Need confirmation) Report waiting on confirmation of reproducibility label Jul 6, 2024
@andrei8l
Copy link
Contributor

andrei8l commented Jul 6, 2024

/confirmed talker infrastructure is being bad again

diff --git a/src/math_parser_diag.cpp b/src/math_parser_diag.cpp
index 11de324929..693d46ad53 100644
--- a/src/math_parser_diag.cpp
+++ b/src/math_parser_diag.cpp
@@ -1464,11 +1464,11 @@ std::function<double( dialogue & )> vitamin_eval( char scope,
         std::vector<diag_value> const &params, diag_kwargs const &/* kwargs */ )
 {
     return[beta = is_beta( scope ), id = params[0]]( dialogue const & d ) {
-        if( d.actor( beta )->get_character() ) {
-            return static_cast<talker const *>( d.actor( beta ) )
-                   ->get_character()
-                   ->vitamin_get( vitamin_id( id.str( d ) ) );
+        talker const *const actor = d.actor( beta );
+        if( Character const *const chr = actor->get_character(); chr != nullptr ) {
+            return chr->vitamin_get( vitamin_id( id.str( d ) ) );
         }
+        debugmsg( "Tried to access vitamins of a non-Character talker" );
         return 0;
     };
 }

(ie. static cast the talker for the if check too)

vision_range() needs the same treatment.

@github-actions github-actions bot added (S2 - Confirmed) Bug that's been confirmed to exist and removed (S1 - Need confirmation) Report waiting on confirmation of reproducibility labels Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(S2 - Confirmed) Bug that's been confirmed to exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants