Skip to content

Commit

Permalink
Migrate ACT_CLEAR_RUBBLE to the new activity actor system. (#55720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedcharles authored Apr 9, 2022
1 parent 9442cdb commit d5c61d0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 42 deletions.
38 changes: 38 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5665,6 +5665,44 @@ std::unique_ptr<activity_actor> churn_activity_actor::deserialize( JsonValue &js
return actor.clone();
}

void clear_rubble_activity_actor::start( player_activity &act, Character & )
{
act.moves_total = moves;
act.moves_left = moves;
}

void clear_rubble_activity_actor::finish( player_activity &act, Character &who )
{
const tripoint &pos = act.placement;
map &here = get_map();
who.add_msg_if_player( m_info, _( "You clear up the %s." ), here.furnname( pos ) );
here.furn_set( pos, f_null );

act.set_to_null();

here.maybe_trigger_trap( pos, who, true );
}

void clear_rubble_activity_actor::serialize( JsonOut &jsout ) const
{
jsout.start_object();

jsout.member( "moves", moves );

jsout.end_object();
}

std::unique_ptr<activity_actor> clear_rubble_activity_actor::deserialize( JsonValue &jsin )
{
clear_rubble_activity_actor actor( {} );

JsonObject data = jsin.get_object();

data.read( "moves", actor.moves );

return actor.clone();
}

void firstaid_activity_actor::start( player_activity &act, Character & )
{
act.moves_total = moves;
Expand Down
25 changes: 25 additions & 0 deletions src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,31 @@ class churn_activity_actor : public activity_actor
item_location tool;
};

class clear_rubble_activity_actor : public activity_actor
{
public:
clear_rubble_activity_actor() = default;
explicit clear_rubble_activity_actor( int moves ) : moves( moves ) {}

activity_id get_type() const override {
return activity_id( "ACT_CLEAR_RUBBLE" );
}

void start( player_activity &act, Character &who ) override;
void do_turn( player_activity &, Character & ) override {}
void finish( player_activity &act, Character &who ) override;

std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<clear_rubble_activity_actor>( *this );
}

void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonValue &jsin );

private:
int moves;
};

class disable_activity_actor : public activity_actor
{
public:
Expand Down
21 changes: 3 additions & 18 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ static const activity_id ACT_BLEED( "ACT_BLEED" );
static const activity_id ACT_BUILD( "ACT_BUILD" );
static const activity_id ACT_BUTCHER( "ACT_BUTCHER" );
static const activity_id ACT_BUTCHER_FULL( "ACT_BUTCHER_FULL" );
static const activity_id ACT_CLEAR_RUBBLE( "ACT_CLEAR_RUBBLE" );
static const activity_id ACT_CONSUME_DRINK_MENU( "ACT_CONSUME_DRINK_MENU" );
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
static const activity_id ACT_CONSUME_FUEL_MENU( "ACT_CONSUME_FUEL_MENU" );
Expand Down Expand Up @@ -272,9 +271,9 @@ activity_handlers::do_turn_functions = {
{ ACT_OPERATION, operation_do_turn },
{ ACT_ROBOT_CONTROL, robot_control_do_turn },
{ ACT_TREE_COMMUNION, tree_communion_do_turn },
{ ACT_STUDY_SPELL, study_spell_do_turn},
{ ACT_STUDY_SPELL, study_spell_do_turn },
{ ACT_WAIT_STAMINA, wait_stamina_do_turn },
{ ACT_MULTIPLE_DIS, multiple_dis_do_turn }
{ ACT_MULTIPLE_DIS, multiple_dis_do_turn },
};

const std::map< activity_id, std::function<void( player_activity *, Character * )> >
Expand All @@ -301,7 +300,6 @@ activity_handlers::finish_functions = {
{ ACT_HEATING, heat_item_finish },
{ ACT_MEND_ITEM, mend_item_finish },
{ ACT_TOOLMOD_ADD, toolmod_add_finish },
{ ACT_CLEAR_RUBBLE, clear_rubble_finish },
{ ACT_WAIT, wait_finish },
{ ACT_WAIT_WEATHER, wait_weather_finish },
{ ACT_WAIT_NPC, wait_npc_finish },
Expand All @@ -323,7 +321,7 @@ activity_handlers::finish_functions = {
{ ACT_PULL_CREATURE, pull_creature_finish },
{ ACT_MIND_SPLICER, mind_splicer_finish },
{ ACT_SPELLCASTING, spellcasting_finish },
{ ACT_STUDY_SPELL, study_spell_finish }
{ ACT_STUDY_SPELL, study_spell_finish },
};

namespace io
Expand Down Expand Up @@ -2529,19 +2527,6 @@ void activity_handlers::toolmod_add_finish( player_activity *act, Character *you
act->targets[1].remove_item();
}

void activity_handlers::clear_rubble_finish( player_activity *act, Character *you )
{
const tripoint &pos = act->placement;
map &here = get_map();
you->add_msg_if_player( m_info, _( "You clear up the %s." ),
here.furnname( pos ) );
here.furn_set( pos, f_null );

act->set_to_null();

here.maybe_trigger_trap( pos, *you, true );
}

// This activity opens the menu (it's not meant to queue consumption of items)
void activity_handlers::eat_menu_do_turn( player_activity *, Character * )
{
Expand Down
17 changes: 0 additions & 17 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,11 @@ void armor_layers_do_turn( player_activity *act, Character *you );
void atm_do_turn( player_activity *act, Character *you );
void build_do_turn( player_activity *act, Character *you );
void butcher_do_turn( player_activity *act, Character *you );
void chop_logs_do_turn( player_activity *act, Character *you );
void chop_planks_do_turn( player_activity *act, Character *you );
void chop_tree_do_turn( player_activity *act, Character *you );
void chop_trees_do_turn( player_activity *act, Character *you );
void churn_do_turn( player_activity *act, Character *you );
void consume_drink_menu_do_turn( player_activity *act, Character *you );
void consume_food_menu_do_turn( player_activity *act, Character *you );
void consume_fuel_menu_do_turn( player_activity *act, Character *you );
void consume_meds_menu_do_turn( player_activity *act, Character *you );
void cracking_do_turn( player_activity *act, Character *you );
void drop_do_turn( player_activity *act, Character *you );
void eat_menu_do_turn( player_activity *act, Character *you );
void fertilize_plot_do_turn( player_activity *act, Character *you );
void fetch_do_turn( player_activity *act, Character *you );
Expand All @@ -186,7 +180,6 @@ void game_do_turn( player_activity *act, Character *you );
void generic_game_do_turn( player_activity *act, Character *you );
void hand_crank_do_turn( player_activity *act, Character *you );
void jackhammer_do_turn( player_activity *act, Character *you );
void move_items_do_turn( player_activity *act, Character *you );
void move_loot_do_turn( player_activity *act, Character *you );
void multiple_butcher_do_turn( player_activity *act, Character *you );
void multiple_chop_planks_do_turn( player_activity *act, Character *you );
Expand All @@ -201,9 +194,7 @@ void pickaxe_do_turn( player_activity *act, Character *you );
void pulp_do_turn( player_activity *act, Character *you );
void repair_item_do_turn( player_activity *act, Character *you );
void robot_control_do_turn( player_activity *act, Character *you );
void spellcasting_do_turn( player_activity *act, Character *you );
void start_fire_do_turn( player_activity *act, Character *you );
void stash_do_turn( player_activity *act, Character *you );
void study_spell_do_turn( player_activity *act, Character *you );
void tidy_up_do_turn( player_activity *act, Character *you );
void travel_do_turn( player_activity *act, Character *you );
Expand All @@ -213,7 +204,6 @@ void vehicle_repair_do_turn( player_activity *act, Character *you );
void vibe_do_turn( player_activity *act, Character *you );
void view_recipe_do_turn( player_activity *act, Character *you );
void wait_stamina_do_turn( player_activity *act, Character *you );
void wear_do_turn( player_activity *act, Character *you );

// defined in activity_handlers.cpp
extern const std::map< activity_id, std::function<void( player_activity *, Character * )> >
Expand All @@ -222,17 +212,11 @@ do_turn_functions;
/** activity_finish functions: */
void atm_finish( player_activity *act, Character *you );
void butcher_finish( player_activity *act, Character *you );
void chop_logs_finish( player_activity *act, Character *you );
void chop_planks_finish( player_activity *act, Character *you );
void chop_tree_finish( player_activity *act, Character *you );
void clear_rubble_finish( player_activity *act, Character *you );
void cracking_finish( player_activity *act, Character *guy );
void eat_menu_finish( player_activity *act, Character *you );
void fill_pit_finish( player_activity *act, Character *you );
void fish_finish( player_activity *act, Character *you );
void generic_game_finish( player_activity *act, Character *you );
void gunmod_add_finish( player_activity *act, Character *you );
void hand_crank_finish( player_activity *act, Character *you );
void heat_item_finish( player_activity *act, Character *you );
void jackhammer_finish( player_activity *act, Character *you );
void mend_item_finish( player_activity *act, Character *you );
Expand All @@ -244,7 +228,6 @@ void pull_creature_finish( player_activity *act, Character *you );
void pulp_finish( player_activity *act, Character *you );
void repair_item_finish( player_activity *act, Character *you );
void robot_control_finish( player_activity *act, Character *you );
void shear_finish( player_activity *act, Character *you );
void socialize_finish( player_activity *act, Character *you );
void spellcasting_finish( player_activity *act, Character *you );
void start_engines_finish( player_activity *act, Character *you );
Expand Down
3 changes: 1 addition & 2 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@

static const activity_id ACT_ATM( "ACT_ATM" );
static const activity_id ACT_BUILD( "ACT_BUILD" );
static const activity_id ACT_CLEAR_RUBBLE( "ACT_CLEAR_RUBBLE" );
static const activity_id ACT_OPERATION( "ACT_OPERATION" );
static const activity_id ACT_PLANT_SEED( "ACT_PLANT_SEED" );

Expand Down Expand Up @@ -1357,7 +1356,7 @@ void iexamine::rubble( Character &you, const tripoint &examp )
!query_yn( _( "Clear up that %s?" ), here.furnname( examp ) ) ) {
return;
}
you.assign_activity( ACT_CLEAR_RUBBLE, moves, -1, 0 );
you.assign_activity( player_activity( clear_rubble_activity_actor( moves ) ) );
you.activity.placement = examp;
}

Expand Down
4 changes: 1 addition & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
#include "weather_gen.h"
#include "weather_type.h"

static const activity_id ACT_CLEAR_RUBBLE( "ACT_CLEAR_RUBBLE" );
static const activity_id ACT_FILL_PIT( "ACT_FILL_PIT" );
static const activity_id ACT_FISH( "ACT_FISH" );
static const activity_id ACT_GAME( "ACT_GAME" );
Expand Down Expand Up @@ -3182,8 +3181,7 @@ cata::optional<int> iuse::clear_rubble( Character *p, item *it, bool, const trip
for( std::size_t i = 0; i < helpersize; i++ ) {
add_msg( m_info, _( "%s helps with this task…" ), helpers[i]->get_name() );
}
player_activity act( ACT_CLEAR_RUBBLE, moves / bonus, bonus );
p->assign_activity( act );
p->assign_activity( player_activity( clear_rubble_activity_actor( moves / bonus ) ) );
p->activity.placement = pnt;
return it->type->charges_to_use();
}
Expand Down
3 changes: 1 addition & 2 deletions src/savegame_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ static const activity_id ACT_ATM( "ACT_ATM" );
static const activity_id ACT_BUILD( "ACT_BUILD" );
static const activity_id ACT_BURROW( "ACT_BURROW" );
static const activity_id ACT_BUTCHER( "ACT_BUTCHER" );
static const activity_id ACT_CLEAR_RUBBLE( "ACT_CLEAR_RUBBLE" );
static const activity_id ACT_CRACKING( "ACT_CRACKING" );
static const activity_id ACT_DISASSEMBLE( "ACT_DISASSEMBLE" );
static const activity_id ACT_FILL_LIQUID( "ACT_FILL_LIQUID" );
Expand Down Expand Up @@ -249,7 +248,7 @@ void player_activity::deserialize_legacy_type( int legacy_type, activity_id &des
ACT_MEND_ITEM,
activity_id::NULL_ID(), // ACT_GUNMOD_ADD
ACT_WAIT_NPC,
ACT_CLEAR_RUBBLE,
activity_id::NULL_ID(), // ACT_CLEAR_RUBBLE
ACT_MEDITATE,
activity_id::NULL_ID() // NUM_ACTIVITIES
};
Expand Down

0 comments on commit d5c61d0

Please sign in to comment.