Skip to content

Commit

Permalink
Fix for overlapping farm zones NPC Shuffle (#35518)
Browse files Browse the repository at this point in the history
* fix for overlapping farm zones

* extraneous line

* stop everything going in reverse
  • Loading branch information
davidpwbrown authored and ZhilkinSerg committed Nov 18, 2019
1 parent f388e84 commit 42bcb5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
33 changes: 15 additions & 18 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,21 +1801,6 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
return final_map;
}

static bool plant_activity( player &p, const zone_data *zone, const tripoint src_loc )
{
const std::string seed = dynamic_cast<const plot_options &>( zone->get_options() ).get_seed();
std::vector<item *> seed_inv = p.items_with( [seed]( const item & itm ) {
return itm.typeId() == itype_id( seed );
} );
// we dont have the required seed, even though we should at this point.
// move onto the next tile, and if need be that will prompt a fetch seeds activity.
if( seed_inv.empty() ) {
return false;
}
iexamine::plant_seed( p, src_loc, itype_id( seed ) );
return true;
}

static void construction_activity( player &p, const zone_data *zone, const tripoint src_loc,
const activity_reason_info &act_info, const std::vector<construction> &list_constructions,
activity_id activity_to_restore )
Expand Down Expand Up @@ -2468,7 +2453,7 @@ static bool generic_multi_activity_check_requirement( player &p, const activity_

bool &can_do_it = act_info.can_do;
const do_activity_reason &reason = act_info.reason;
const zone_data *zone = mgr.get_zone_at( src );
const zone_data *zone = mgr.get_zone_at( src, get_zone_for_act( act_id ) );

const bool needs_to_be_in_zone = act_id == activity_id( "ACT_FETCH_REQUIRED" ) ||
act_id == activity_id( "ACT_MULTIPLE_FARM" ) ||
Expand Down Expand Up @@ -2648,8 +2633,20 @@ static bool generic_multi_activity_do( player &p, const activity_id &act_id,
p.activity.placement = src;
return false;
} else if( reason == NEEDS_PLANTING && g->m.has_flag_ter_or_furn( "PLANTABLE", src_loc ) ) {
if( !plant_activity( p, zone, src_loc ) ) {
return true;
std::vector<zone_data> zones = mgr.get_zones( zone_type_id( "FARM_PLOT" ),
g->m.getabs( src_loc ) );
for( const zone_data &zone : zones ) {
const std::string seed = dynamic_cast<const plot_options &>( zone.get_options() ).get_seed();
std::vector<item *> seed_inv = p.items_with( [seed]( const item & itm ) {
return itm.typeId() == itype_id( seed );
} );
// we dont have the required seed, even though we should at this point.
// move onto the next tile, and if need be that will prompt a fetch seeds activity.
if( seed_inv.empty() ) {
continue;
}
iexamine::plant_seed( p, src_loc, itype_id( seed ) );
break;
}
} else if( reason == NEEDS_CHOPPING && p.has_quality( quality_id( "AXE" ), 1 ) ) {
if( chop_plank_activity( p, src_loc ) ) {
Expand Down
8 changes: 2 additions & 6 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,13 @@ bool zone_manager::has_loot_dest_near( const tripoint &where ) const

const zone_data *zone_manager::get_zone_at( const tripoint &where, const zone_type_id &type ) const
{
for( auto it = zones.rbegin(); it != zones.rend(); ++it ) {
const auto &zone = *it;

for( const zone_data &zone : zones ) {
if( zone.has_inside( where ) && zone.get_type() == type ) {
return &zone;
}
}
auto vzones = g->m.get_vehicle_zones( g->get_levz() );
for( auto it = vzones.rbegin(); it != vzones.rend(); ++it ) {
const auto &zone = *it;

for( const zone_data *zone : vzones ) {
if( zone->has_inside( where ) && zone->get_type() == type ) {
return zone;
}
Expand Down

0 comments on commit 42bcb5a

Please sign in to comment.