Skip to content

Commit

Permalink
Merge pull request #40126 from rsulli55/migrate-dig-activities
Browse files Browse the repository at this point in the history
Add a can_resume_with function to activity_actor and migrate ACT_DIG and ACT_DIG_CHANNEL
  • Loading branch information
ifreund authored May 5, 2020
2 parents 50810da + 8f1cb97 commit 6f77ec7
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 160 deletions.
3 changes: 2 additions & 1 deletion doc/PLAYER_ACTIVITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ functions. Don't forget to add the deserialization function of your new
activity actor to the `deserialize_functions` map towards the bottom of
`activity_actor.cpp`.

4. `player_activity.cpp` Optionally update `can_resume_with`.
4. If this activity is resumable, `override`
`activity_actor::can_resume_with_internal`

5. Construct your activity actor and then pass it to the constructor for
`player_activity`. The newly constructed activity can then be assigned
Expand Down
182 changes: 178 additions & 4 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gates.h"
#include "iexamine.h"
#include "item.h"
#include "item_group.h"
#include "item_location.h"
#include "json.h"
#include "line.h"
Expand All @@ -36,6 +37,177 @@ static const trait_id trait_ILLITERATE( "ILLITERATE" );

static const std::string flag_USE_EAT_VERB( "USE_EAT_VERB" );

static const mtype_id mon_zombie( "mon_zombie" );
static const mtype_id mon_zombie_fat( "mon_zombie_fat" );
static const mtype_id mon_zombie_rot( "mon_zombie_rot" );
static const mtype_id mon_skeleton( "mon_skeleton" );
static const mtype_id mon_zombie_crawler( "mon_zombie_crawler" );

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

void dig_activity_actor::do_turn( player_activity &, Character & )
{
sfx::play_activity_sound( "tool", "shovel", sfx::get_heard_volume( location ) );
if( calendar::once_every( 1_minutes ) ) {
//~ Sound of a shovel digging a pit at work!
sounds::sound( location, 10, sounds::sound_t::activity, _( "hsh!" ) );
}
}

void dig_activity_actor::finish( player_activity &act, Character &who )
{
const bool grave = g->m.ter( location ) == t_grave;

if( grave ) {
if( one_in( 10 ) ) {
static const std::array<mtype_id, 5> monids = { {
mon_zombie, mon_zombie_fat,
mon_zombie_rot, mon_skeleton,
mon_zombie_crawler
}
};

g->place_critter_at( random_entry( monids ), byproducts_location );
g->m.furn_set( location, f_coffin_o );
who.add_msg_if_player( m_warning, _( "Something crawls out of the coffin!" ) );
} else {
g->m.spawn_item( location, "bone_human", rng( 5, 15 ) );
g->m.furn_set( location, f_coffin_c );
}
std::vector<item *> dropped = g->m.place_items( "allclothes", 50, location, location, false,
calendar::turn );
g->m.place_items( "grave", 25, location, location, false, calendar::turn );
g->m.place_items( "jewelry_front", 20, location, location, false, calendar::turn );
for( item * const &it : dropped ) {
if( it->is_armor() ) {
it->item_tags.insert( "FILTHY" );
it->set_damage( rng( 1, it->max_damage() - 1 ) );
}
}
g->events().send<event_type::exhumes_grave>( who.getID() );
}

g->m.ter_set( location, ter_id( result_terrain ) );

for( int i = 0; i < byproducts_count; i++ ) {
g->m.spawn_items( byproducts_location, item_group::items_from( byproducts_item_group,
calendar::turn ) );
}

const int helpersize = g->u.get_num_crafting_helpers( 3 );
who.mod_stored_nutr( 5 - helpersize );
who.mod_thirst( 5 - helpersize );
who.mod_fatigue( 10 - ( helpersize * 2 ) );
if( grave ) {
who.add_msg_if_player( m_good, _( "You finish exhuming a grave." ) );
} else {
who.add_msg_if_player( m_good, _( "You finish digging the %s." ),
g->m.ter( location ).obj().name() );
}

act.set_to_null();
}

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

jsout.member( "moves", moves_total );
jsout.member( "location", location );
jsout.member( "result_terrain", result_terrain );
jsout.member( "byproducts_location", byproducts_location );
jsout.member( "byproducts_count", byproducts_count );
jsout.member( "byproducts_item_group", byproducts_item_group );

jsout.end_object();
}

std::unique_ptr<activity_actor> dig_activity_actor::deserialize( JsonIn &jsin )
{
dig_activity_actor actor( 0, tripoint_zero,
{}, tripoint_zero, 0, {} );

JsonObject data = jsin.get_object();

data.read( "moves", actor.moves_total );
data.read( "location", actor.location );
data.read( "result_terrain", actor.result_terrain );
data.read( "byproducts_location", actor.byproducts_location );
data.read( "byproducts_count", actor.byproducts_count );
data.read( "byproducts_item_group", actor.byproducts_item_group );

return actor.clone();
}

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

void dig_channel_activity_actor::do_turn( player_activity &, Character & )
{
sfx::play_activity_sound( "tool", "shovel", sfx::get_heard_volume( location ) );
if( calendar::once_every( 1_minutes ) ) {
//~ Sound of a shovel digging a pit at work!
sounds::sound( location, 10, sounds::sound_t::activity, _( "hsh!" ) );
}
}

void dig_channel_activity_actor::finish( player_activity &act, Character &who )
{

g->m.ter_set( location, ter_id( result_terrain ) );

for( int i = 0; i < byproducts_count; i++ ) {
g->m.spawn_items( byproducts_location, item_group::items_from( byproducts_item_group,
calendar::turn ) );
}

who.mod_hunger( 5 );
who.mod_thirst( 5 );
who.mod_fatigue( 10 );
who.add_msg_if_player( m_good, _( "You finish digging up %s." ),
g->m.ter( location ).obj().name() );

act.set_to_null();
}

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

jsout.member( "moves", moves_total );
jsout.member( "location", location );
jsout.member( "result_terrain", result_terrain );
jsout.member( "byproducts_location", byproducts_location );
jsout.member( "byproducts_count", byproducts_count );
jsout.member( "byproducts_item_group", byproducts_item_group );

jsout.end_object();
}

std::unique_ptr<activity_actor> dig_channel_activity_actor::deserialize( JsonIn &jsin )
{
dig_channel_activity_actor actor( 0, tripoint_zero,
{}, tripoint_zero, 0, {} );

JsonObject data = jsin.get_object();

data.read( "moves", actor.moves_total );
data.read( "location", actor.location );
data.read( "result_terrain", actor.result_terrain );
data.read( "byproducts_location", actor.byproducts_location );
data.read( "byproducts_count", actor.byproducts_count );
data.read( "byproducts_item_group", actor.byproducts_item_group );

return actor.clone();
}

void hacking_activity_actor::start( player_activity &act, Character & )
{
act.moves_total = to_moves<int>( 5_minutes );
Expand Down Expand Up @@ -380,8 +552,8 @@ std::unique_ptr<activity_actor> migration_cancel_activity_actor::deserialize( Js

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

void open_gate_activity_actor::finish( player_activity &act, Character & )
Expand All @@ -394,7 +566,7 @@ void open_gate_activity_actor::serialize( JsonOut &jsout ) const
{
jsout.start_object();

jsout.member( "moves", moves );
jsout.member( "moves", moves_total );
jsout.member( "placement", placement );

jsout.end_object();
Expand All @@ -406,7 +578,7 @@ std::unique_ptr<activity_actor> open_gate_activity_actor::deserialize( JsonIn &j

JsonObject data = jsin.get_object();

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

return actor.clone();
Expand Down Expand Up @@ -475,6 +647,8 @@ namespace activity_actors
const std::unordered_map<activity_id, std::unique_ptr<activity_actor>( * )( JsonIn & )>
deserialize_functions = {
{ activity_id( "ACT_CONSUME" ), &consume_activity_actor::deserialize },
{ activity_id( "ACT_DIG" ), &dig_activity_actor::deserialize },
{ activity_id( "ACT_DIG_CHANNEL" ), &dig_channel_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 },
Expand Down
Loading

0 comments on commit 6f77ec7

Please sign in to comment.