From 2e99700d1c6e81a867cc62722a4fbb9df64b41c4 Mon Sep 17 00:00:00 2001 From: End3r991 <110078815+End3r991@users.noreply.github.com> Date: Mon, 12 Feb 2024 23:52:41 +0100 Subject: [PATCH] Update npcmove.cpp --- src/npcmove.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/npcmove.cpp b/src/npcmove.cpp index e1b2701a4b46..843c44bfaae9 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -4260,24 +4260,25 @@ void npc::set_omt_destination() std::string dest_type; for( const auto &fulfill : needs ) { - // look for the closest occurence of any of that locations terrain types - std::vector loc_list = get_location_for( fulfill )->get_all_terrains(); - std::shuffle( loc_list.begin(), loc_list.end(), rng_get_engine() ); - omt_find_params find_params; - std::vector> temp_types; - for( const oter_type_id &elem : loc_list ) { - std::pair temp_pair; - temp_pair.first = elem.id().str(); - temp_pair.second = ot_match_type::type; - temp_types.push_back( temp_pair ); - } - find_params.search_range = 75; - find_params.min_distance = 0; - find_params.must_see = false; - find_params.cant_see = false; - find_params.types = temp_types; - find_params.existing_only = false; - goal = overmap_buffer.find_closest( surface_omt_loc, find_params ); + auto cache_iter = goal_cache.find( fulfill ); + if( cache_iter != goal_cache.end() && cache_iter->second.omt_loc == surface_omt_loc ) { + goal = cache_iter->second.goal; + } else { + // look for the closest occurrence of any of that locations terrain types + omt_find_params find_params; + for( const oter_type_id &elem : get_location_for( fulfill )->get_all_terrains() ) { + std::pair temp_pair; + temp_pair.first = elem.id().str(); + temp_pair.second = ot_match_type::type; + find_params.types.push_back( temp_pair ); + } + find_params.search_range = 75; + find_params.existing_only = false; + goal = overmap_buffer.find_closest( surface_omt_loc, find_params ); + npc_need_goal_cache &cache = goal_cache[fulfill]; + cache.goal = goal; + cache.omt_loc = surface_omt_loc; + } omt_path.clear(); if( goal != overmap::invalid_tripoint ) { omt_path = overmap_buffer.get_travel_path( surface_omt_loc, goal, overmap_path_params::for_npc() );