CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.67k stars 4.18k forks source link

Giving Refugee Center beggars soda triggers cannibalism response #77981

Open WatermelonsEverywhere opened 5 days ago

WatermelonsEverywhere commented 5 days ago

Describe the bug

Giving a Refugee Center beggar a can of sealed peach sparkling water as a food offer triggers the "They know what you've done." hostile cannibalism response.

Attach save file

Coletown-trimmed.tar.gz

Steps to reproduce

  1. Acquire a can of sealed peach sparkling water through natural means or spawning it.
  2. Offer can of peach sparkling water to a Refugee Center beggar when the dialogue option for donating food is shown.

Expected behavior

For the beggars to recieve the peach sparkling water as any other donated food or drink item.

Screenshots

No response

Versions and configuration

Additional context

No response

RenechCDDA commented 5 days ago

Okay that's confirmed, and weird as hell. Let's see where the problem lays.

RenechCDDA commented 5 days ago

Okay I'm just stupid and used std::map::count. I knew vitamins was a std::map, but for some reason my brain was thinking of it as a different type of container. Easy enough fix.

RenechCDDA commented 5 days ago

Absolute bare minimum patch:

index 3dca58c371..ab19237744 100644
--- a/src/math_parser_diag.cpp
+++ b/src/math_parser_diag.cpp
@@ -1655,7 +1655,8 @@ diag_eval_dbl_f vitamin_eval( char scope, std::vector<diag_value> const &params,
         }
         if( item_location const *const itm = actor->get_const_item(); itm != nullptr ) {
             const nutrients &nutrient_data = default_character_compute_effective_nutrients( *itm->get_item() );
-            return static_cast<int>( nutrient_data.vitamins().count( vitamin_id( id.str( d ) ) ) );
+            const auto &v = nutrient_data.vitamins().find( vitamin_id( id.str( d ) ) );
+            return v != nutrient_data.vitamins().end() ? v->second : 0;
         }
         debugmsg( "Tried to access vitamins of a non-Character/non-item talker" );
         return 0;
Owlblocks commented 2 days ago

I'm looking into this. I tried @RenechCDDA 's patch and it doesn't seem to have fixed it... but the bug is inconsistent and doesn't always trigger. I'll try toying with it some more.