Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Apr 1, 2019
1 parent e6b6e21 commit c5336f6
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 58 deletions.
8 changes: 0 additions & 8 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
"type": "activity_type",
"stop_phrase": "Stop crafting?",
"based_on": "neither",
"refuel_fires": true,
"no_resume": true
},
{
"id": "ACT_LONGCRAFT",
"type": "activity_type",
"stop_phrase": "Stop crafting?",
"based_on": "neither",
"refuel_fires": true
},
{
Expand Down
7 changes: 2 additions & 5 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const std::map< activity_id, std::function<void( player_activity *, player * )>
activity_handlers::do_turn_functions = {
{ activity_id( "ACT_BURROW" ), burrow_do_turn },
{ activity_id( "ACT_CRAFT" ), craft_do_turn },
{ activity_id( "ACT_LONGCRAFT" ), craft_do_turn },
{ activity_id( "ACT_FILL_LIQUID" ), fill_liquid_do_turn },
{ activity_id( "ACT_PICKAXE" ), pickaxe_do_turn },
{ activity_id( "ACT_DROP" ), drop_do_turn },
Expand Down Expand Up @@ -138,8 +137,6 @@ activity_handlers::finish_functions = {
{ activity_id( "ACT_WAIT_NPC" ), wait_npc_finish },
{ activity_id( "ACT_SOCIALIZE" ), socialize_finish },
{ activity_id( "ACT_TRY_SLEEP" ), try_sleep_finish },
// { activity_id( "ACT_CRAFT" ), craft_finish },
// { activity_id( "ACT_LONGCRAFT" ), longcraft_finish },
{ activity_id( "ACT_DISASSEMBLE" ), disassemble_finish },
{ activity_id( "ACT_BUILD" ), build_finish },
{ activity_id( "ACT_VIBE" ), vibe_finish },
Expand Down Expand Up @@ -2627,7 +2624,7 @@ void activity_handlers::try_sleep_finish( player_activity *act, player *p )

void activity_handlers::craft_do_turn( player_activity *act, player *p )
{
int pos = act->values.front();
const int pos = act->values.front();
item &craft = p->i_at( pos );

const recipe &rec = craft.get_making();
Expand All @@ -2650,7 +2647,7 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
craft.item_counter += crafting_speed * p->get_moves();
p->set_moves( 0 );
act->set_to_null();

if( craft.item_counter >= rec.time ) {
item craft_copy = craft;
p->i_rem( pos );
Expand Down
2 changes: 0 additions & 2 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ void wait_weather_finish( player_activity *act, player *p );
void wait_npc_finish( player_activity *act, player *p );
void socialize_finish( player_activity *act, player *p );
void try_sleep_finish( player_activity *act, player *p );
// void craft_finish( player_activity *act, player *p );
// void longcraft_finish( player_activity *act, player *p );
void disassemble_finish( player_activity *act, player *p );
void build_finish( player_activity *act, player *p );
void vibe_finish( player_activity *act, player *p );
Expand Down
7 changes: 3 additions & 4 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,11 @@ void player::start_craft( const recipe &making, int batch_size, bool is_long )
{
if( making.ident().is_null() ) {
debugmsg( "no recipe with id %s found", activity.name );
// activity.set_to_null();
return;
}

// Use up the components and tools
std::list<item> used = consume_components_for_craft( making, batch_size );
const std::list<item> used = consume_components_for_craft( making, batch_size );
if( last_craft->has_cached_selections() && used.empty() ) {
// This signals failure, even though there seem to be several paths where it shouldn't...
return;
Expand All @@ -532,7 +531,7 @@ void player::start_craft( const recipe &making, int batch_size, bool is_long )

item craft( &making, batch_size, std::vector<item>( used.begin(), used.end() ) );

int pos = get_item_position( set_item_inventory( *this, craft ) );
const int pos = get_item_position( set_item_inventory( *this, craft ) );
if( pos == INT_MIN ) {
add_msg_if_player( _( "Activate the %s to start crafting" ), craft.tname() );
} else {
Expand All @@ -551,7 +550,7 @@ void player::start_craft( const recipe &making, int batch_size, bool is_long )
void player::complete_craft( item &craft )
{
const recipe &making = craft.get_making(); // Which recipe is it?
int batch_size = craft.charges;
const int batch_size = craft.charges;

/* to be modified and moved to ACT_CRAFT */
int secondary_dice = 0;
Expand Down
1 change: 0 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11235,7 +11235,6 @@ void player::assign_activity( const player_activity &act, bool allow_resume )
add_msg_if_player( _( "You resume your task." ) );
activity = backlog.front();
backlog.pop_front();
activity.resume_with( act );
} else {
if( activity ) {
backlog.push_front( activity );
Expand Down
31 changes: 1 addition & 30 deletions src/player_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,7 @@ bool player_activity::can_resume_with( const player_activity &other, const Chara
return false;
}

if( id() == activity_id( "ACT_CRAFT" ) || id() == activity_id( "ACT_LONGCRAFT" ) ) {
// The last value is a time stamp, and the last coord is the player
// position. We want to allow either to have changed.
// (This would be much less hacky in the hypothetical future of
// activity_handler_actors).
if( !( values.size() == other.values.size() &&
!values.empty() &&
std::equal( values.begin(), values.end() - 1, other.values.begin() ) &&
coords.size() == other.coords.size() &&
!coords.empty() &&
std::equal( coords.begin(), coords.end() - 1, other.coords.begin() ) ) ) {
return false;
}
} else if( id() == activity_id( "ACT_CLEAR_RUBBLE" ) ) {
if( id() == activity_id( "ACT_CLEAR_RUBBLE" ) ) {
if( other.coords.empty() || other.coords[0] != coords[0] ) {
return false;
}
Expand All @@ -195,22 +182,6 @@ bool player_activity::can_resume_with( const player_activity &other, const Chara
position == other.position && name == other.name && targets == other.targets;
}

void player_activity::resume_with( const player_activity &other )
{
if( id() == activity_id( "ACT_CRAFT" ) || id() == activity_id( "ACT_LONGCRAFT" ) ) {
// For crafting actions, we need to update the start turn and position
// to the resumption time values. These are stored in the last
// elements of values and coords respectively.
if( !( !values.empty() && values.size() == other.values.size() &&
!coords.empty() && coords.size() == other.coords.size() ) ) {
debugmsg( "Activities incompatible; should not have resumed" );
return;
}
values.back() = other.values.back();
coords.back() = other.coords.back();
}
}

bool player_activity::is_distraction_ignored( distraction_type type ) const
{
return ignored_distractions.find( type ) != ignored_distractions.end();
Expand Down
7 changes: 0 additions & 7 deletions src/player_activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ class player_activity
* can be resumed instead of starting the other activity.
*/
bool can_resume_with( const player_activity &other, const Character &who ) const;
/**
* When an old activity A is resumed by a new activity B, normally B is
* discarded and the saved A is simply used in its place. However,
* this will be called on A, passing B as an argument, in case A needs
* to grab any values from B.
*/
void resume_with( const player_activity &other );

bool is_distraction_ignored( distraction_type type ) const;
void ignore_distraction( distraction_type type );
Expand Down
2 changes: 1 addition & 1 deletion src/savegame_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void player_activity::deserialize_legacy_type( int legacy_type, activity_id &des
activity_id( "ACT_GAME" ),
activity_id( "ACT_WAIT" ),
activity_id( "ACT_CRAFT" ),
activity_id( "ACT_LONGCRAFT" ),
activity_id::NULL_ID(), // ACT_LONGCRAFT is deprecated
activity_id( "ACT_DISASSEMBLE" ),
activity_id( "ACT_BUTCHER" ),
activity_id( "ACT_LONGSALVAGE" ),
Expand Down

0 comments on commit c5336f6

Please sign in to comment.