From dd87a23f60d2af150684d161e2b2b199bc1866b8 Mon Sep 17 00:00:00 2001 From: rsulli55 Date: Sat, 2 May 2020 11:52:56 -0700 Subject: [PATCH] Migrate ACT_OPEN_GATE to the activity actor system (#40039) * Migrate ACT_OPEN_GATE to the new activity actor system Per issue #40013 the goal is to migrate all activities from activity_handlers.cpp to the new activity actor system references #40013 * Removed uneccessary includes from activity_actor.cpp and activity_handlers.cpp * Update src/activity_actor.cpp Remove unnecessary setting of `act.placement` Co-authored-by: Isaac Freund * Update parameters to open_gate_activity_actor constructor * Remove unnecessary function declaration from activity_handlers.h Co-authored-by: Isaac Freund --- src/activity_actor.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/activity_actor.h | 26 ++++++++++++++++++++++++++ src/activity_handlers.cpp | 11 ----------- src/activity_handlers.h | 1 - src/gates.cpp | 6 ++++-- 5 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 309accf37b170..d5f18c88ab69b 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -11,6 +11,7 @@ #include "debug.h" #include "enums.h" #include "game.h" +#include "gates.h" #include "iexamine.h" #include "item.h" #include "item_location.h" @@ -374,6 +375,40 @@ std::unique_ptr migration_cancel_activity_actor::deserialize( Js return migration_cancel_activity_actor().clone(); } +void open_gate_activity_actor::start( player_activity &act, Character & ) +{ + act.moves_total = moves; + act.moves_left = moves; +} + +void open_gate_activity_actor::finish( player_activity &act, Character & ) +{ + gates::open_gate( placement ); + act.set_to_null(); +} + +void open_gate_activity_actor::serialize( JsonOut &jsout ) const +{ + jsout.start_object(); + + jsout.member( "moves", moves ); + jsout.member( "placement", placement ); + + jsout.end_object(); +} + +std::unique_ptr open_gate_activity_actor::deserialize( JsonIn &jsin ) +{ + open_gate_activity_actor actor( 0, tripoint_zero ); + + JsonObject data = jsin.get_object(); + + data.read( "moves", actor.moves ); + data.read( "placement", actor.placement ); + + return actor.clone(); +} + namespace activity_actors { @@ -383,6 +418,7 @@ deserialize_functions = { { activity_id( "ACT_HACKING" ), &hacking_activity_actor::deserialize }, { activity_id( "ACT_MIGRATION_CANCEL" ), &migration_cancel_activity_actor::deserialize }, { activity_id( "ACT_MOVE_ITEMS" ), &move_items_activity_actor::deserialize }, + { activity_id( "ACT_OPEN_GATE" ), &open_gate_activity_actor::deserialize }, { activity_id( "ACT_PICKUP" ), &pickup_activity_actor::deserialize }, }; } // namespace activity_actors diff --git a/src/activity_actor.h b/src/activity_actor.h index 03fcc266db84c..d593551cc9f6c 100644 --- a/src/activity_actor.h +++ b/src/activity_actor.h @@ -176,6 +176,32 @@ class migration_cancel_activity_actor : public activity_actor static std::unique_ptr deserialize( JsonIn &jsin ); }; +class open_gate_activity_actor : public activity_actor +{ + private: + int moves; + tripoint placement; + + public: + open_gate_activity_actor( int gate_moves, const tripoint &gate_placement ) : + moves( gate_moves ), placement( gate_placement ) {} + + activity_id get_type() const override { + return activity_id( "ACT_OPEN_GATE" ); + } + + void start( player_activity &act, Character & ) override; + void do_turn( player_activity &, Character & ) override {}; + void finish( player_activity &act, Character & ) override; + + std::unique_ptr clone() const override { + return std::make_unique( *this ); + } + + void serialize( JsonOut &jsout ) const override; + static std::unique_ptr deserialize( JsonIn &jsin ); +}; + namespace activity_actors { diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index b87717d030d8a..6f92a905ef715 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -43,7 +43,6 @@ #include "game.h" #include "game_constants.h" #include "game_inventory.h" -#include "gates.h" #include "handle_liquid.h" #include "harvest.h" #include "iexamine.h" @@ -166,7 +165,6 @@ static const activity_id ACT_MULTIPLE_CONSTRUCTION( "ACT_MULTIPLE_CONSTRUCTION" static const activity_id ACT_MULTIPLE_MINE( "ACT_MULTIPLE_MINE" ); static const activity_id ACT_MULTIPLE_FARM( "ACT_MULTIPLE_FARM" ); static const activity_id ACT_MULTIPLE_FISH( "ACT_MULTIPLE_FISH" ); -static const activity_id ACT_OPEN_GATE( "ACT_OPEN_GATE" ); static const activity_id ACT_OPERATION( "ACT_OPERATION" ); static const activity_id ACT_OXYTORCH( "ACT_OXYTORCH" ); static const activity_id ACT_PICKAXE( "ACT_PICKAXE" ); @@ -380,7 +378,6 @@ activity_handlers::finish_functions = { { ACT_PULP, pulp_finish }, { ACT_CRACKING, cracking_finish }, { ACT_LOCKPICK, lockpicking_finish }, - { ACT_OPEN_GATE, open_gate_finish }, { ACT_REPAIR_ITEM, repair_item_finish }, { ACT_HEATING, heat_item_finish }, { ACT_MEND_ITEM, mend_item_finish }, @@ -2621,14 +2618,6 @@ void activity_handlers::lockpicking_finish( player_activity *act, player *p ) act->set_to_null(); } -void activity_handlers::open_gate_finish( player_activity *act, player * ) -{ - // Don't use reference and don't inline, because act can change - const tripoint pos = act->placement; - gates::open_gate( pos ); - act->set_to_null(); -} - enum repeat_type : int { // REPEAT_INIT should be zero. In some scenarios (veh welder), activity value default to zero. REPEAT_INIT = 0, // Haven't found repeat value yet. diff --git a/src/activity_handlers.h b/src/activity_handlers.h index 3643965983960..df6cc2eb19990 100644 --- a/src/activity_handlers.h +++ b/src/activity_handlers.h @@ -211,7 +211,6 @@ void plant_seed_finish( player_activity *act, player *p ); void oxytorch_finish( player_activity *act, player *p ); void cracking_finish( player_activity *act, player *p ); void lockpicking_finish( player_activity *act, player *p ); -void open_gate_finish( player_activity *act, player * ); void repair_item_finish( player_activity *act, player *p ); void mend_item_finish( player_activity *act, player *p ); void gunmod_add_finish( player_activity *act, player *p ); diff --git a/src/gates.cpp b/src/gates.cpp index 41ee9aefac866..2c5f1fea2d708 100644 --- a/src/gates.cpp +++ b/src/gates.cpp @@ -244,8 +244,10 @@ void gates::open_gate( const tripoint &pos, player &p ) const gate_data &gate = gates_data.obj( gid ); p.add_msg_if_player( gate.pull_message ); - p.assign_activity( ACT_OPEN_GATE, gate.moves ); - p.activity.placement = pos; + p.assign_activity( player_activity( open_gate_activity_actor( + gate.moves, + pos + ) ) ); } // Doors namespace