Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

`set_item_category_spawn_rates` should take math

Open Standing-Storm opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

I thought "Oh, it would be neat to have certain loot categories decrease with time from the Cataclysm!" only to find out that set_item_category_spawn_rates only takes numbers.

Solution you would like.

set_item_category_spawn_rates should accept math.

Describe alternatives you have considered.

No response

Additional context

Untitled2

Standing-Storm avatar Dec 01 '24 21:12 Standing-Storm

try this

diff --git a/src/npctalk.cpp b/src/npctalk.cpp
index a04b7ebec9..6bb407b1c2 100644
--- a/src/npctalk.cpp
+++ b/src/npctalk.cpp
@@ -5290,23 +5290,23 @@ talk_effect_fun_t::func f_set_item_category_spawn_rates( const JsonObject &jo,
         std::string_view member, const std::string_view )
 {
     if( jo.has_array( member ) ) {
-        std::set<std::pair<item_category_id, float>> rates;
+        std::set<std::pair<item_category_id, dbl_or_var>> rates;
         for( const JsonObject joi : jo.get_array( member ) ) {
             item_category_id cat( joi.get_string( "id" ) );
-            float spawn_rate = joi.get_float( "spawn_rate" );
+            dbl_or_var spawn_rate = get_dbl_or_var( joi.get_member( "spawn_rate" ), "spawn_rate", true );
             rates.insert( std::make_pair( cat, spawn_rate ) );
         }
-        return [rates]( dialogue const &/* d */ ) {
-            for( const std::pair<item_category_id, float> &rate : rates ) {
-                rate.first.obj().set_spawn_rate( rate.second );
+        return [rates]( dialogue const & d ) {
+            for( const std::pair<item_category_id, dbl_or_var> &rate : rates ) {
+                rate.first.obj().set_spawn_rate( rate.second.evaluate( d ) );
             }
         };
     } else {
         JsonObject joi = jo.get_member( member );
         item_category_id cat( joi.get_string( "id" ) );
-        float spawn_rate = joi.get_float( "spawn_rate" );
-        return [cat, spawn_rate]( dialogue const &/* d */ ) {
-            cat.obj().set_spawn_rate( spawn_rate );
+        dbl_or_var spawn_rate = get_dbl_or_var( joi.get_member( "spawn_rate" ), "spawn_rate", true );
+        return [cat, spawn_rate]( dialogue const & d ) {
+            cat.obj().set_spawn_rate( spawn_rate.evaluate( d ) );
         };
     }
 }

GuardianDll avatar Dec 02 '24 18:12 GuardianDll

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

github-actions[bot] avatar Jan 07 '25 02:01 github-actions[bot]