From 42bcb5a20a19bd5077497ca2ef98f1044dd63403 Mon Sep 17 00:00:00 2001 From: davidpwbrown <39344466+davidpwbrown@users.noreply.github.com> Date: Mon, 18 Nov 2019 07:17:52 +0000 Subject: [PATCH] Fix for overlapping farm zones NPC Shuffle (#35518) * fix for overlapping farm zones * extraneous line * stop everything going in reverse --- src/activity_item_handling.cpp | 33 +++++++++++++++------------------ src/clzones.cpp | 8 ++------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index 2087b21319557..0050ccf20650f 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -1801,21 +1801,6 @@ static std::vector> 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( zone->get_options() ).get_seed(); - std::vector 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 &list_constructions, activity_id activity_to_restore ) @@ -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" ) || @@ -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 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( zone.get_options() ).get_seed(); + std::vector 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 ) ) { diff --git a/src/clzones.cpp b/src/clzones.cpp index 5ab9879e0d6a9..3ccb1ff499ecc 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -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; }