Skip to content

Commit

Permalink
Merge pull request #33673 from ipcyborg/fix-32965-construction-zones-v2
Browse files Browse the repository at this point in the history
Fixed "Zone construction build wooden wall builds window instead. #32965" (rebased)
  • Loading branch information
ZhilkinSerg authored Aug 30, 2019
2 parents 99d7029 + 0872768 commit 9845ec8
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 166 deletions.
8 changes: 2 additions & 6 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
"type": "activity_type",
"activity_level": "ACTIVE_EXERCISE",
"verb": "constructing",
"suspendable": false,
"based_on": "neither",
"no_resume": true
"based_on": "neither"
},
{
"id": "ACT_TIDY_UP",
"type": "activity_type",
"activity_level": "MODERATE_EXERCISE",
"verb": "tidying up",
"suspendable": false,
"based_on": "neither",
"no_resume": true
"based_on": "neither"
},
{
"id": "ACT_GAME",
Expand Down
10 changes: 1 addition & 9 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3087,14 +3087,6 @@ void activity_handlers::operation_finish( player_activity *act, player *p )
act->set_to_null();
}

static bool character_has_skill_for( const player *p, const construction &con )
{
return std::all_of( con.required_skills.begin(), con.required_skills.end(),
[&]( const std::pair<skill_id, int> &pr ) {
return p->get_skill_level( pr.first ) >= pr.second;
} );
}

void activity_handlers::churn_do_turn( player_activity *act, player *p )
{
( void )act;
Expand Down Expand Up @@ -3134,7 +3126,7 @@ void activity_handlers::build_do_turn( player_activity *act, player *p )
}
// if you ( or NPC ) are finishing someone elses started construction...
const construction &built = list_constructions[pc->id];
if( !character_has_skill_for( p, built ) ) {
if( !p->meets_skill_requirements( built ) ) {
add_msg( m_info, _( "%s can't work on this construction anymore." ), p->disp_name() );
p->cancel_activity();
if( p->is_npc() ) {
Expand Down
28 changes: 26 additions & 2 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ enum do_activity_reason : int {
CAN_DO_CONSTRUCTION, // Can do construction.
CAN_DO_FETCH, // Can do fetch - this is usually the default result for fetch task
CAN_DO_PREREQ, // for constructions - cant build the main construction, but can build the pre-req
CAN_DO_PREREQ_2, // Can do the second pre-req deep below the desired one.
NO_COMPONENTS, // can't do the activity there due to lack of components /tools
NO_COMPONENTS_PREREQ, // need components to build the pre-requisite for the actual desired construction
NO_COMPONENTS_PREREQ_2, // need components to the second pre-req deep.
DONT_HAVE_SKILL, // don't have the required skill
NO_ZONE, // There is no required zone anymore
ALREADY_DONE, // the activity is done already ( maybe by someone else )
Expand All @@ -47,6 +45,32 @@ enum do_activity_reason : int {
BLOCKING_TILE // Something has made it's way onto the tile, so the activity cannot proceed
};

struct activity_reason_info {
do_activity_reason reason; //reason for success or fail
bool can_do; //is it possible to do this
cata::optional<size_t> con_idx; //construction index

activity_reason_info( do_activity_reason reason_, bool can_do_,
cata::optional<size_t> con_idx_ = cata::optional<size_t>() ) :
reason( reason_ ),
can_do( can_do_ ),
con_idx( con_idx_ )
{ }

static activity_reason_info ok( const do_activity_reason &reason_ ) {
return activity_reason_info( reason_, true );
}

static activity_reason_info build( const do_activity_reason &reason_, bool can_do_,
size_t con_idx_ ) {
return activity_reason_info( reason_, can_do_, con_idx_ );
}

static activity_reason_info fail( const do_activity_reason &reason_ ) {
return activity_reason_info( reason_, false );
}
};

int butcher_time_to_cut( const player &u, const item &corpse_item, butcher_type action );

// activity_item_handling.cpp
Expand Down
Loading

0 comments on commit 9845ec8

Please sign in to comment.