Skip to content

Commit

Permalink
Migrate ACT_OPEN_GATE to the activity actor system (#40039)
Browse files Browse the repository at this point in the history
* 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 <ifreund@ifreund.xyz>

* Update parameters to open_gate_activity_actor constructor

* Remove unnecessary function declaration from activity_handlers.h

Co-authored-by: Isaac Freund <ifreund@ifreund.xyz>
  • Loading branch information
rsulli55 and ifreund authored May 2, 2020
1 parent 0bf295e commit dd87a23
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
36 changes: 36 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -374,6 +375,40 @@ std::unique_ptr<activity_actor> 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<activity_actor> 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
{

Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/activity_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ class migration_cancel_activity_actor : public activity_actor
static std::unique_ptr<activity_actor> 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<activity_actor> clone() const override {
return std::make_unique<open_gate_activity_actor>( *this );
}

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

namespace activity_actors
{

Expand Down
11 changes: 0 additions & 11 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 4 additions & 2 deletions src/gates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd87a23

Please sign in to comment.