Skip to content

Commit

Permalink
Multidrop code cleanup + optimization (#885)
Browse files Browse the repository at this point in the history
* Untangle 'allows_selecting' from 'activatable'
The first is a per-column setting, the second is whether the column has items that can be selected

(cherry picked from commit 322725a521e0713754c05f0bd8e375b81ee54949)

* Cleanup of inventory_ui types and visibility

* Use alias instead of magic item pointers in drop multiselector

* Remove ancient activity migration code

* Move ACT_WASH, ACT_STASH, ACT_DROP to activity actors
  • Loading branch information
olanti-p authored Sep 15, 2021
1 parent 5d99566 commit 295e8b0
Show file tree
Hide file tree
Showing 22 changed files with 433 additions and 336 deletions.
4 changes: 3 additions & 1 deletion data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@
"type": "activity_type",
"verb": "washing",
"rooted": true,
"based_on": "speed"
"suspendable": false,
"based_on": "speed",
"no_resume": true
},
{
"id": "ACT_HACKSAW",
Expand Down
90 changes: 90 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,37 @@ std::unique_ptr<activity_actor> dig_channel_activity_actor::deserialize( JsonIn
return actor.clone();
}

drop_activity_actor::drop_activity_actor( Character &ch, const drop_locations &items,
bool force_ground, const tripoint &relpos )
: force_ground( force_ground ), relpos( relpos )
{
this->items = pickup::reorder_for_dropping( ch, items );
}

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

jsout.member( "items", items );
jsout.member( "force_ground", force_ground );
jsout.member( "relpos", relpos );

jsout.end_object();
}

std::unique_ptr<activity_actor> drop_activity_actor::deserialize( JsonIn &jsin )
{
drop_activity_actor actor;

JsonObject data = jsin.get_object();

data.read( "items", actor.items );
data.read( "force_ground", actor.force_ground );
data.read( "relpos", actor.relpos );

return actor.clone();
}

void hacking_activity_actor::start( player_activity &act, Character & )
{
act.moves_total = to_moves<int>( 5_minutes );
Expand Down Expand Up @@ -841,6 +872,62 @@ std::unique_ptr<activity_actor> open_gate_activity_actor::deserialize( JsonIn &j
return actor.clone();
}

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

stash_activity_actor::stash_activity_actor( Character &ch, const drop_locations &items,
const tripoint &relpos ) : relpos( relpos )
{
this->items = pickup::reorder_for_dropping( ch, items );
}

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

jsout.member( "items", items );
jsout.member( "relpos", relpos );

jsout.end_object();
}

std::unique_ptr<activity_actor> stash_activity_actor::deserialize( JsonIn &jsin )
{
stash_activity_actor actor;

JsonObject data = jsin.get_object();

data.read( "items", actor.items );
data.read( "relpos", actor.relpos );

return actor.clone();
}

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

jsout.member( "targets", targets );
jsout.member( "moves_total", moves_total );

jsout.end_object();
}

std::unique_ptr<activity_actor> wash_activity_actor::deserialize( JsonIn &jsin )
{
wash_activity_actor actor;

JsonObject data = jsin.get_object();

data.read( "targets", actor.targets );
data.read( "moves_total", actor.moves_total );

return actor.clone();
}

namespace activity_actors
{

Expand All @@ -850,11 +937,14 @@ deserialize_functions = {
{ activity_id( "ACT_AIM" ), &aim_activity_actor::deserialize },
{ activity_id( "ACT_DIG" ), &dig_activity_actor::deserialize },
{ activity_id( "ACT_DIG_CHANNEL" ), &dig_channel_activity_actor::deserialize },
{ activity_id( "ACT_DROP" ), &drop_activity_actor::deserialize },
{ 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 },
{ activity_id( "ACT_STASH" ), &stash_activity_actor::deserialize },
{ activity_id( "ACT_WASH" ), &wash_activity_actor::deserialize },
};
} // namespace activity_actors

Expand Down
82 changes: 82 additions & 0 deletions src/activity_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "clone_ptr.h"
#include "item_handling_util.h"
#include "item_location.h"
#include "memory_fast.h"
#include "optional.h"
Expand Down Expand Up @@ -289,6 +290,34 @@ class dig_channel_activity_actor : public activity_actor
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};

class drop_activity_actor : public activity_actor
{
private:
std::list<pickup::act_item> items;
bool force_ground = false;
tripoint relpos;

public:
drop_activity_actor() = default;
drop_activity_actor( Character &ch, const drop_locations &items,
bool force_ground, const tripoint &relpos );

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

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

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

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

class hacking_activity_actor : public activity_actor
{
private:
Expand Down Expand Up @@ -437,6 +466,59 @@ class open_gate_activity_actor : public activity_actor
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};

class stash_activity_actor : public activity_actor
{
private:
std::list<pickup::act_item> items;
tripoint relpos;

public:
stash_activity_actor() = default;
stash_activity_actor( Character &ch, const drop_locations &items, const tripoint &relpos );

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

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

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

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

class wash_activity_actor : public activity_actor
{
private:
iuse_locations targets;
int moves_total = 0;

public:
wash_activity_actor() = default;
wash_activity_actor( const iuse_locations &targets, int moves_total ) :
targets( targets ), moves_total( moves_total ) {};

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

void start( player_activity &act, Character & ) 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<wash_activity_actor>( *this );
}

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

namespace activity_actors
{

Expand Down
6 changes: 0 additions & 6 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ static const activity_id ACT_CRAFT( "ACT_CRAFT" );
static const activity_id ACT_DISASSEMBLE( "ACT_DISASSEMBLE" );
static const activity_id ACT_DISMEMBER( "ACT_DISMEMBER" );
static const activity_id ACT_DISSECT( "ACT_DISSECT" );
static const activity_id ACT_DROP( "ACT_DROP" );
static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
static const activity_id ACT_FERTILIZE_PLOT( "ACT_FERTILIZE_PLOT" );
static const activity_id ACT_FETCH_REQUIRED( "ACT_FETCH_REQUIRED" );
Expand Down Expand Up @@ -172,7 +171,6 @@ static const activity_id ACT_SOCIALIZE( "ACT_SOCIALIZE" );
static const activity_id ACT_SPELLCASTING( "ACT_SPELLCASTING" );
static const activity_id ACT_START_ENGINES( "ACT_START_ENGINES" );
static const activity_id ACT_START_FIRE( "ACT_START_FIRE" );
static const activity_id ACT_STASH( "ACT_STASH" );
static const activity_id ACT_STUDY_SPELL( "ACT_STUDY_SPELL" );
static const activity_id ACT_TIDY_UP( "ACT_TIDY_UP" );
static const activity_id ACT_TOOLMOD_ADD( "ACT_TOOLMOD_ADD" );
Expand All @@ -188,7 +186,6 @@ static const activity_id ACT_WAIT( "ACT_WAIT" );
static const activity_id ACT_WAIT_NPC( "ACT_WAIT_NPC" );
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
static const activity_id ACT_WAIT_WEATHER( "ACT_WAIT_WEATHER" );
static const activity_id ACT_WASH( "ACT_WASH" );
static const activity_id ACT_WEAR( "ACT_WEAR" );

static const efftype_id effect_ai_waiting( "ai_waiting" );
Expand Down Expand Up @@ -267,8 +264,6 @@ activity_handlers::do_turn_functions = {
{ ACT_CRAFT, craft_do_turn },
{ ACT_FILL_LIQUID, fill_liquid_do_turn },
{ ACT_PICKAXE, pickaxe_do_turn },
{ ACT_DROP, drop_do_turn },
{ ACT_STASH, stash_do_turn },
{ ACT_PULP, pulp_do_turn },
{ ACT_GAME, game_do_turn },
{ ACT_GENERIC_GAME, generic_game_do_turn },
Expand Down Expand Up @@ -377,7 +372,6 @@ activity_handlers::finish_functions = {
{ ACT_CONSUME_FOOD_MENU, eat_menu_finish },
{ ACT_CONSUME_DRINK_MENU, eat_menu_finish },
{ ACT_CONSUME_MEDS_MENU, eat_menu_finish },
{ ACT_WASH, washing_finish },
{ ACT_HACKSAW, hacksaw_finish },
{ ACT_PRY_NAILS, pry_nails_finish },
{ ACT_CHOP_TREE, chop_tree_finish },
Expand Down
Loading

0 comments on commit 295e8b0

Please sign in to comment.