Skip to content

Commit e756551

Browse files
authored
Merge pull request #82980 from RenechCDDA/audit_activity_var
(Mostly) fix butchering activity from zones
2 parents 9fa7d1a + 21f2d15 commit e756551

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/activity_item_handling.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "activity_actor_definitions.h"
1818
#include "avatar.h"
19+
#include "butchery.h"
1920
#include "calendar.h"
2021
#include "cata_utility.h"
2122
#include "character.h"
@@ -78,7 +79,6 @@
7879
#include "weather.h"
7980

8081
static const activity_id ACT_BUILD( "ACT_BUILD" );
81-
static const activity_id ACT_BUTCHER_FULL( "ACT_BUTCHER_FULL" );
8282
static const activity_id ACT_FETCH_REQUIRED( "ACT_FETCH_REQUIRED" );
8383
static const activity_id ACT_FISH( "ACT_FISH" );
8484
static const activity_id ACT_MOVE_LOOT( "ACT_MOVE_LOOT" );
@@ -1209,7 +1209,8 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
12091209
int small_count = 0;
12101210
for( const item &i : here.i_at( src_loc ) ) {
12111211
// make sure nobody else is working on that corpse right now
1212-
if( i.is_corpse() && !i.has_var( "activity_var" ) ) {
1212+
if( i.is_corpse() &&
1213+
( !i.has_var( "activity_var" ) || i.get_var( "activity_var" ) == you.name ) ) {
12131214
const mtype corpse = *i.get_mtype();
12141215
if( corpse.size > creature_size::medium ) {
12151216
big_count += 1;
@@ -1219,6 +1220,9 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
12191220
corpses.push_back( i );
12201221
}
12211222
}
1223+
if( corpses.empty() ) {
1224+
return activity_reason_info::fail( do_activity_reason::NO_COMPONENTS );
1225+
}
12221226
bool b_rack_present = false;
12231227
for( const tripoint_bub_ms &pt : here.points_in_radius( src_loc, 2 ) ) {
12241228
if( here.has_flag_furn( ter_furn_flag::TFLAG_BUTCHER_EQ, pt ) ) {
@@ -1970,21 +1974,23 @@ static bool butcher_corpse_activity( Character &you, const tripoint_bub_ms &src_
19701974
{
19711975
map &here = get_map();
19721976
map_stack items = here.i_at( src_loc );
1977+
std::vector<butchery_data> bd;
19731978
for( item &elem : items ) {
1974-
if( elem.is_corpse() && !elem.has_var( "activity_var" ) ) {
1979+
if( elem.is_corpse() &&
1980+
( !elem.has_var( "activity_var" ) || elem.get_var( "activity_var" ) == you.name ) ) {
19751981
const mtype corpse = *elem.get_mtype();
19761982
if( corpse.size > creature_size::medium && reason != do_activity_reason::NEEDS_BIG_BUTCHERING ) {
19771983
continue;
19781984
}
19791985
elem.set_var( "activity_var", you.name );
1980-
you.assign_activity( ACT_BUTCHER_FULL, 0, true );
1981-
you.activity.targets.emplace_back( map_cursor( src_loc ), &elem );
1982-
you.activity.placement = here.get_abs( src_loc );
1983-
you.may_activity_occupancy_after_end_items_loc.emplace_back( map_cursor{here.get_abs( src_loc )},
1984-
&elem );
1985-
return true;
1986+
item_location corpse_loc = item_location( map_cursor( src_loc ), &elem );
1987+
bd.emplace_back( corpse_loc, butcher_type::FULL );
19861988
}
19871989
}
1990+
if( !bd.empty() ) {
1991+
you.assign_activity( butchery_activity_actor( bd ) );
1992+
return true;
1993+
}
19881994
return false;
19891995
}
19901996

@@ -3486,6 +3492,11 @@ bool generic_multi_activity_handler( player_activity &act, Character &you, bool
34863492
}
34873493
// if we got here, we need to revert otherwise NPC will be stuck in AI Limbo and have a head explosion.
34883494
if( you.backlog.empty() || src_set.empty() ) {
3495+
/**
3496+
* This should really be a debug message, but too many places rely on this broken behavior.
3497+
* debugmsg( "Reverting %s activity for %s, probable infinite loop", activity_to_restore.c_str(),
3498+
* you.get_name() );
3499+
*/
34893500
check_npc_revert( you );
34903501
if( player_activity( activity_to_restore ).is_multi_type() ) {
34913502
you.assign_activity( activity_id::NULL_ID() );

src/character.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <vector>
1717

1818
#include "action.h"
19+
#include "activity_actor.h"
1920
#include "activity_actor_definitions.h"
2021
#include "activity_handlers.h"
2122
#include "addiction.h"
@@ -129,8 +130,6 @@
129130
#include "weather_type.h"
130131
#include "wound.h"
131132

132-
class activity_actor;
133-
134133
static const activity_id ACT_AUTODRIVE( "ACT_AUTODRIVE" );
135134
static const activity_id ACT_CONSUME_DRINK_MENU( "ACT_CONSUME_DRINK_MENU" );
136135
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
@@ -9120,6 +9119,13 @@ void Character::set_knows_creature_type( const mtype_id &c )
91209119
void Character::assign_activity( const activity_id &type, int moves, int index, int pos,
91219120
const std::string &name )
91229121
{
9122+
// This is not a perfect safety net, but I don't know of another way to get all activity actors and what activity_ids might be associated with them.
9123+
for( const auto &actor_ptr : activity_actors::deserialize_functions ) {
9124+
if( actor_ptr.first == type ) {
9125+
debugmsg( "Tried to assign generic activity %s to activity that has an actor!", type.c_str() );
9126+
return;
9127+
}
9128+
}
91239129
assign_activity( player_activity( type, moves, index, pos, name ) );
91249130
}
91259131

src/player_activity.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "character.h"
1313
#include "construction.h"
1414
#include "creature.h"
15+
#include "debug.h"
1516
#include "dialogue.h"
1617
#include "effect_on_condition.h"
1718
#include "event.h"
@@ -22,6 +23,7 @@
2223
#include "itype.h"
2324
#include "magic.h"
2425
#include "map.h"
26+
#include "messages.h"
2527
#include "rng.h"
2628
#include "skill.h"
2729
#include "sounds.h"
@@ -382,6 +384,8 @@ void player_activity::do_turn( Character &you )
382384
dialogue d( get_talker_for( you ), nullptr );
383385
type->completion_EOC->activate_activation_only( d, "player activities" );
384386
}
387+
add_msg_debug( debugmode::DF_ACTIVITY, "Setting activity %s to null for %s, no moves left.",
388+
type.c_str(), you.name );
385389
get_event_bus().send<event_type::character_finished_activity>( you.getID(), type, false );
386390
g->wait_popup_reset();
387391
if( actor ) {

0 commit comments

Comments
 (0)