Skip to content

Commit

Permalink
Merge pull request #30288 from mlangsdorf/npc_better_destinations
Browse files Browse the repository at this point in the history
npc: improve NPC omt_destination finding
  • Loading branch information
ZhilkinSerg authored May 7, 2019
2 parents 2f35a9c + d4435da commit 6b2ce8f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 56 deletions.
65 changes: 59 additions & 6 deletions data/json/npcs/destination_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,84 @@
{
"type": "overmap_location",
"id": "source_of_anything",
"terrains": [ "house", "s_gas", "s_pharm", "s_hardware", "s_sports", "s_liquor", "s_gun", "s_library" ]
"terrains": [
"house",
"s_gas",
"s_pharm",
"s_hardware",
"s_sports",
"s_liquor",
"s_gun",
"s_library",
"megastore_entrance",
"fire_station",
"mil_surplus",
"mansion_entry"
]
},
{
"type": "overmap_location",
"id": "source_of_ammo",
"terrains": [ "house", "s_gun" ]
"terrains": [ "house", "s_gun", "mil_surplus", "mansion_entry" ]
},
{
"type": "overmap_location",
"id": "source_of_gun",
"terrains": [ "s_gun" ]
"terrains": [ "s_gun", "pawn", "hdwr_large_entrance", "mansion_entry" ]
},
{
"type": "overmap_location",
"id": "source_of_weapon",
"terrains": [ "s_gun", "s_sports", "s_hardware" ]
"terrains": [ "s_gun", "s_sports", "s_hardware", "megastore_entrance", "hdwr_large_entrance", "fire_station", "mansion_entry" ]
},
{
"type": "overmap_location",
"id": "source_of_drink",
"terrains": [ "s_gas", "s_pharm", "s_liquor", "s_grocery" ]
"terrains": [
"s_gas",
"s_pharm",
"s_pharm_1",
"s_restaurant",
"s_restaurant_1",
"s_restaurant_2",
"s_restaurant_3",
"s_restaurant_coffee",
"s_restaurant_coffee_1",
"s_restaurant_coffee_2",
"s_teashop",
"s_teashop_1",
"bar",
"bar_1",
"s_liquor",
"s_grocery",
"megastore_entrance",
"mansion_entry"
]
},
{
"type": "overmap_location",
"id": "source_of_food",
"terrains": [ "s_grocery" ]
"terrains": [
"s_grocery",
"farm_1",
"2farm_1",
"dairy_farm_NW",
"sugar_house",
"orchard_stall",
"s_restaurant",
"s_restaurant_1",
"s_restaurant_2",
"s_restaurant_3",
"s_restaurant_fast",
"s_restaurant_fast_1",
"s_butcher",
"s_butcher_1",
"s_butcher_2",
"s_pizza_parlor",
"s_pizza_parlor_1",
"megastore_entrance",
"bakery",
"mansion_entry"
]
}
]
30 changes: 0 additions & 30 deletions data/json/overmap/special_locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,6 @@
"id": "road",
"terrains": [ "hiway_ns", "hiway_ew", "ranch_camp_77", "necropolis_a_11", "road", "road_nesw_manhole" ]
},
{
"type": "overmap_location",
"id": "need_none",
"terrains": [ "house", "s_gas", "s_pharm", "s_hardware", "s_sports", "s_liquor", "s_gun", "s_library" ]
},
{
"type": "overmap_location",
"id": "need_ammo",
"terrains": [ "house", "s_gun" ]
},
{
"type": "overmap_location",
"id": "need_gun",
"terrains": [ "s_gun" ]
},
{
"type": "overmap_location",
"id": "need_weapon",
"terrains": [ "s_gun", "s_sports", "s_hardware" ]
},
{
"type": "overmap_location",
"id": "need_drink",
"terrains": [ "s_gas", "s_pharm", "s_liquor", "s_grocery" ]
},
{
"type": "overmap_location",
"id": "need_food",
"terrains": [ "s_grocery" ]
},
{
"type": "overmap_location",
"id": "forest_trail",
Expand Down
2 changes: 0 additions & 2 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,6 @@ class npc : public player
*/
tripoint goal;
std::vector<tripoint> omt_path;
tripoint wander_pos; // Not actually used (should be: wander there when you hear a sound)
int wander_time;

/**
* Location and index of the corpse we'd like to pulp (if any).
Expand Down
36 changes: 29 additions & 7 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "monster.h"
#include "mtype.h"
#include "npctalk.h"
#include "options.h"
#include "overmap_location.h"
#include "overmapbuffer.h"
#include "projectile.h"
Expand Down Expand Up @@ -3221,22 +3222,43 @@ void npc::set_omt_destination()
return;
}

tripoint surface_omt_loc = global_omt_location();
// We need that, otherwise find_closest won't work properly
surface_omt_loc.z = 0;

// also, don't bother looking if the CITY_SIZE is 0, just go somewhere at random
const int city_size = get_option<int>( "CITY_SIZE" );
if( city_size == 0 ) {
goal = surface_omt_loc + point( rng( -90, 90 ), rng( -90, 90 ) );
return;
}


decide_needs();
if( needs.empty() ) { // We don't need anything in particular.
needs.push_back( need_none );
}

// We need that, otherwise find_closest won't work properly
// TODO: Allow finding sewers and stuff
tripoint surface_omt_loc = global_omt_location();
surface_omt_loc.z = 0;
std::string dest_type;
for( const auto &fulfill : needs ) {
dest_type = get_location_for( fulfill )->get_random_terrain().id().str();
goal = overmap_buffer.find_closest( surface_omt_loc, dest_type, 150, false );
if( goal != overmap::invalid_tripoint ) {
break;
}
}

// couldn't find any places to go, so go somewhere.
if( goal == overmap::invalid_tripoint ) {
goal = surface_omt_loc + point( rng( -90, 90 ), rng( -90, 90 ) );
return;
}

std::string dest_type = get_location_for( needs.front() )->get_random_terrain().id().str();
goal = overmap_buffer.find_closest( surface_omt_loc, dest_type, 0, false );

DebugLog( D_INFO, DC_ALL ) << "npc::set_omt_destination - new goal for NPC [" << get_name() <<
"] with ["
<< get_need_str_id( needs.front() ) << "] is [" << dest_type << "] in ["
<< get_need_str_id( needs.front() ) << "] is [" << dest_type <<
"] in ["
<< goal.x << "," << goal.y << "," << goal.z << "].";
}

Expand Down
11 changes: 0 additions & 11 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,13 +1276,6 @@ void npc::load( JsonObject &data )

data.read( "personality", personality );

data.read( "wandf", wander_time );
data.read( "wandx", wander_pos.x );
data.read( "wandy", wander_pos.y );
if( !data.read( "wandz", wander_pos.z ) ) {
wander_pos.z = posz();
}

if( !data.read( "submap_coords", submap_coords ) ) {
// Old submap coordinates are for the point (0, 0, 0) on local map
// New ones are for submap that contains pos
Expand Down Expand Up @@ -1466,10 +1459,6 @@ void npc::store( JsonOut &json ) const
json.member( "myclass", myclass.str() );

json.member( "personality", personality );
json.member( "wandf", wander_time );
json.member( "wandx", wander_pos.x );
json.member( "wandy", wander_pos.y );
json.member( "wandz", wander_pos.z );

json.member( "submap_coords", submap_coords );

Expand Down

0 comments on commit 6b2ce8f

Please sign in to comment.