From 80bf3062d73708e323d8f62cbe4e5a29ef630b1a Mon Sep 17 00:00:00 2001 From: dpwb Date: Thu, 23 Jan 2020 01:21:08 +0000 Subject: [PATCH 1/6] profession starting vehicle profession description handling for null default to fix other profs change to profession starting skill Update data/json/professions.json Co-Authored-By: matskuman5 Update data/json/professions.json Co-Authored-By: Anton Burmistrov Update src/game.cpp Co-Authored-By: Anton Burmistrov Update doc/JSON_INFO.md replace nullid with optional to appease VS linker errrors capitalize profession name Update src/string_id_null_ids.cpp from review:shortern optional checks from review : restructure find_closest() to find_all() fix using parameter remove redundant return move comment before declaration add fallback searches/support for boats/sm_pos setting remove double increment remove sorting as find_all() is now sorted by default Update professions.json Update src/game.cpp Co-Authored-By: codemime Update src/game.cpp Co-Authored-By: codemime --- data/json/professions.json | 17 ++++++++++ doc/JSON_INFO.md | 16 +++++++--- src/game.cpp | 65 ++++++++++++++++++++++++++++++++++++++ src/game.h | 4 +++ src/newcharacter.cpp | 9 +++++- src/overmapbuffer.cpp | 3 +- src/player.h | 2 +- src/profession.cpp | 13 +++++++- src/profession.h | 3 ++ 9 files changed, 124 insertions(+), 8 deletions(-) diff --git a/data/json/professions.json b/data/json/professions.json index 86f7358649af8..7c3d7230f1b9b 100644 --- a/data/json/professions.json +++ b/data/json/professions.json @@ -1481,6 +1481,23 @@ "female": [ "bra", "panties" ] } }, + { + "type": "profession", + "ident": "trucker", + "name": "Trucker", + "description": "You ruled the road in your big rig and managed to drive it somewhere you hoped was safe when the riots hit. Now it's just you and your trusty truck cab.", + "points": 5, + "skills": [ { "level": 1, "name": "mechanics" }, { "level": 4, "name": "driving" } ], + "vehicle": "semi_truck", + "items": { + "both": { + "items": [ "tank_top", "socks", "boots_steel", "pants", "multitool", "wristwatch", "gloves_work", "hat_ball" ], + "entries": [ { "group": "charged_cell_phone" } ] + }, + "male": [ "boxer_shorts" ], + "female": [ "bra", "panties" ] + } + }, { "type": "profession", "ident": "lumberjack", diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 558aefa103f23..8daf02a4eba57 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -803,12 +803,20 @@ Example for mods: This mod removes one of the rocks (the other rock is still created), the t-shirt, adds a 2x4 item and gives female characters a t-shirt with the special snippet id. -#### `pet` +#### `pets` -(optional, string mtype_id) +(optional, array of string mtype_ids ) -A string that is the same as a monster id -player will start with this as a tamed pet. +A list of strings, each is the same as a monster id +player will start with these as tamed pets. + +#### `vehicle` + +(optional, string vproto_id ) + +A string, which is the same as a vehicle ( vproto_id ) +player will start with this as a nearby vehicle. +( it will find the nearest road and place it there, then mark it as "remembered" on the overmap ) #### `flags` diff --git a/src/game.cpp b/src/game.cpp index 76136a41b2ec6..ed1fe6ec6c065 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -838,6 +838,7 @@ bool game::start_game() add_msg( m_debug, "cannot place starting pet, no space!" ); } } + place_starting_vehicle( u.starting_vehicle ); // Assign all of this scenario's missions to the player. for( const mission_type_id &m : scen->missions() ) { const auto mission = mission::reserve_new( m, character_id() ); @@ -848,6 +849,70 @@ bool game::start_game() return true; } +void game::place_starting_vehicle( cata::optional starting_vehicle ) +{ + if( !starting_vehicle ) { + return; + } + vehicle veh( *starting_vehicle ); + std::vector omt_search_types; + if( veh.can_float() ) { + omt_search_types.push_back( "river" ); + omt_search_types.push_back( "lake" ); + } + if( veh.max_ground_velocity() > 0 ) { + omt_search_types.push_back( "road" ); + omt_search_types.push_back( "field" ); + } + if( omt_search_types.empty() ) { + return; + } + find_location_for_starting_vehicle( *starting_vehicle, omt_search_types ); + +} + +void game::find_location_for_starting_vehicle( vproto_id id, + const std::vector &omt_search_types ) +{ + for( const std::string &search_type : omt_search_types ) { + omt_find_params find_params; + find_params.must_see = false; + find_params.cant_see = false; + find_params.types.emplace_back( search_type, ot_match_type::type ); + for( int count = 0; count < 10; ++count ) { + // find nearest road + find_params.min_distance = count * 2; + find_params.search_range = 10 + count * 2; + // if player spawns underground, park their car on the surface. + tripoint omt_origin = u.global_omt_location(); + omt_origin.z = 0; + std::vector goals = overmap_buffer.find_all( omt_origin, find_params ); + for( const tripoint &goal : goals ) { + if( goal != overmap::invalid_tripoint ) { + // try place vehicle there. + tinymap target_map; + target_map.load( omt_to_sm_copy( goal ), false ); + tripoint origin = target_map.getlocal( sm_to_ms_copy( omt_to_sm_copy( goal ) ) ) + point( + SEEX, SEEY ); + vehicle *veh = target_map.add_vehicle( id, origin, rng( -90, 90 ), rng( 50, 80 ), + 0, + false ); + if( veh ) { + tripoint abs_local = g->m.getlocal( target_map.getabs( origin ) ); + tripoint p_m = ms_to_sm_remain( abs_local ); + veh->sm_pos = p_m; + veh->pos = abs_local.xy(); + overmap_buffer.add_vehicle( veh ); + target_map.save(); + return; + } + } + } + } + } + debugmsg( "could not place starting vehicle" ); +} + //Make any nearby overmap npcs active, and put them in the right location. void game::load_npcs() { diff --git a/src/game.h b/src/game.h index b267103adb732..97b6c023b7bab 100644 --- a/src/game.h +++ b/src/game.h @@ -733,6 +733,10 @@ class game // Data Initialization void init_autosave(); // Initializes autosave parameters void create_starting_npcs(); // Creates NPCs that start near you + // try and place starting vehicle on a nearby road. + void place_starting_vehicle( cata::optional starting_vehicle ); + void find_location_for_starting_vehicle( const vproto_id id, + std::vector omt_search_types ); // V Menu Functions and helpers: void list_items_monsters(); // Called when you invoke the `V`-menu diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 8e38efc495c45..5abbef1cf45c2 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -52,6 +52,7 @@ #include "pimpl.h" #include "type_id.h" #include "cata_string_consts.h" +#include "veh_type.h" // Colors used in this file: (Most else defaults to c_light_gray) #define COL_STAT_ACT c_white // Selected stat @@ -518,6 +519,7 @@ bool avatar::create( character_type type, const std::string &tempname ) for( mtype_id elem : prof->pets() ) { starting_pets.push_back( elem ); } + starting_vehicle = prof->vehicle(); std::list prof_items = prof->items( male, get_mutations() ); for( item &it : prof_items ) { @@ -1476,7 +1478,6 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef } } // Profession pet - cata::optional montype; if( !sorted_profs[cur_id]->pets().empty() ) { buffer += colorize( _( "Pets:" ), c_light_blue ) + "\n"; for( auto elem : sorted_profs[cur_id]->pets() ) { @@ -1484,6 +1485,12 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef buffer += mon.get_name() + "\n"; } } + // Profession vehicle + if( sorted_profs[cur_id]->vehicle() ) { + buffer += colorize( _( "Vehicle:" ), c_light_blue ) + "\n"; + vproto_id veh_id = *sorted_profs[cur_id]->vehicle(); + buffer += veh_id->name; + } // Profession spells if( !sorted_profs[cur_id]->spells().empty() ) { buffer += colorize( _( "Spells:" ), c_light_blue ) + "\n"; diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index 2de6c86b85028..872b3f094d260 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -600,7 +600,8 @@ void overmapbuffer::remove_vehicle( const vehicle *veh ) void overmapbuffer::add_vehicle( vehicle *veh ) { - const point omt = ms_to_omt_copy( g->m.getabs( veh->global_pos3().xy() ) ); + point abs_pos = g->m.getabs( veh->global_pos3().xy() ); + const point omt = ms_to_omt_copy( abs_pos ); const overmap_with_local_coords om_loc = get_om_global( omt ); int id = om_loc.om->vehicles.size() + 1; // this *should* be unique but just in case diff --git a/src/player.h b/src/player.h index d3c2e13f3b96f..07038476f2d7e 100644 --- a/src/player.h +++ b/src/player.h @@ -943,7 +943,7 @@ class player : public Character bool reach_attacking = false; bool manual_examine = false; - + cata::optional starting_vehicle; std::vector starting_pets; void make_craft_with_command( const recipe_id &id_to_make, int batch_size, bool is_long = false, diff --git a/src/profession.cpp b/src/profession.cpp index 20765f0229e7b..0585a0e103951 100644 --- a/src/profession.cpp +++ b/src/profession.cpp @@ -171,6 +171,9 @@ void profession::load( const JsonObject &jo, const std::string & ) _description_male = to_translation( "prof_desc_male", desc ); _description_female = to_translation( "prof_desc_female", desc ); } + if( jo.has_string( "vehicle" ) ) { + _starting_vehicle = vproto_id( jo.get_string( "vehicle" ) ); + } if( jo.has_array( "pets" ) ) { for( JsonObject subobj : jo.get_array( "pets" ) ) { int count = subobj.get_int( "amount" ); @@ -286,7 +289,10 @@ void profession::check_definition() const if( !item_group::group_is_defined( _starting_items_female ) ) { debugmsg( "_starting_items_female group is undefined" ); } - + if( _starting_vehicle && !_starting_vehicle->is_valid() ) { + debugmsg( "vehicle prototype %s for profession %s does not exist", _starting_vehicle->c_str(), + id.c_str() ); + } for( const auto &a : _starting_CBMs ) { if( !a.is_valid() ) { debugmsg( "bionic %s for profession %s does not exist", a.c_str(), id.c_str() ); @@ -434,6 +440,11 @@ std::list profession::items( bool male, const std::vector &trait return result; } +cata::optional profession::vehicle() const +{ + return _starting_vehicle; +} + std::vector profession::pets() const { return _starting_pets; diff --git a/src/profession.h b/src/profession.h index 8c3c5fb96340e..bf89e72a9931f 100644 --- a/src/profession.h +++ b/src/profession.h @@ -13,6 +13,7 @@ #include "pldata.h" #include "translations.h" #include "type_id.h" +#include "veh_type.h" template class generic_factory; @@ -69,6 +70,7 @@ class profession std::vector _starting_CBMs; std::vector _starting_traits; std::vector _starting_pets; + cata::optional _starting_vehicle; // the int is what level the spell starts at std::map _starting_spells; std::set flags; // flags for some special properties of the profession @@ -103,6 +105,7 @@ class profession signed int point_cost() const; std::list items( bool male, const std::vector &traits ) const; std::vector addictions() const; + cata::optional vehicle() const; std::vector pets() const; std::vector CBMs() const; StartingSkillList skills() const; From 935f95aa2048afd9a84d7175e53d50022871e210 Mon Sep 17 00:00:00 2001 From: dpwb Date: Mon, 10 Feb 2020 09:38:43 +0000 Subject: [PATCH 2/6] random cardinal angles --- src/game.cpp | 6 +++--- src/game.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ed1fe6ec6c065..6058475f9c046 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -871,8 +871,7 @@ void game::place_starting_vehicle( cata::optional starting_vehicle ) } -void game::find_location_for_starting_vehicle( vproto_id id, - const std::vector &omt_search_types ) +void game::find_location_for_starting_vehicle( const vproto_id id, std::vector &omt_search_types ) { for( const std::string &search_type : omt_search_types ) { omt_find_params find_params; @@ -894,7 +893,8 @@ void game::find_location_for_starting_vehicle( vproto_id id, target_map.load( omt_to_sm_copy( goal ), false ); tripoint origin = target_map.getlocal( sm_to_ms_copy( omt_to_sm_copy( goal ) ) ) + point( SEEX, SEEY ); - vehicle *veh = target_map.add_vehicle( id, origin, rng( -90, 90 ), rng( 50, 80 ), + std::vector angles = {0, 90, 180, 270}; + vehicle *veh = target_map.add_vehicle( id, origin, random_entry( angles ), rng( 50, 80 ), 0, false ); if( veh ) { diff --git a/src/game.h b/src/game.h index 97b6c023b7bab..24f80cb66634d 100644 --- a/src/game.h +++ b/src/game.h @@ -736,7 +736,7 @@ class game // try and place starting vehicle on a nearby road. void place_starting_vehicle( cata::optional starting_vehicle ); void find_location_for_starting_vehicle( const vproto_id id, - std::vector omt_search_types ); + std::vector &omt_search_types ); // V Menu Functions and helpers: void list_items_monsters(); // Called when you invoke the `V`-menu From a834e986a1e5c2782c65e58128b9b85a18d1a164 Mon Sep 17 00:00:00 2001 From: dpwb Date: Mon, 10 Feb 2020 10:13:02 +0000 Subject: [PATCH 3/6] astyle --- src/game.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game.cpp b/src/game.cpp index 6058475f9c046..703d83d1200a3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -871,7 +871,8 @@ void game::place_starting_vehicle( cata::optional starting_vehicle ) } -void game::find_location_for_starting_vehicle( const vproto_id id, std::vector &omt_search_types ) +void game::find_location_for_starting_vehicle( const vproto_id id, + std::vector &omt_search_types ) { for( const std::string &search_type : omt_search_types ) { omt_find_params find_params; From 012a3c983072b4b7d7640e33962e912901da635d Mon Sep 17 00:00:00 2001 From: dpwb Date: Mon, 10 Feb 2020 10:15:35 +0000 Subject: [PATCH 4/6] use const ref and move condition to calling code --- src/game.cpp | 9 ++++----- src/game.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 703d83d1200a3..19c6f9f02e594 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -838,7 +838,9 @@ bool game::start_game() add_msg( m_debug, "cannot place starting pet, no space!" ); } } - place_starting_vehicle( u.starting_vehicle ); + if( u.starting_vehicle ) { + place_starting_vehicle( u.starting_vehicle ); + } // Assign all of this scenario's missions to the player. for( const mission_type_id &m : scen->missions() ) { const auto mission = mission::reserve_new( m, character_id() ); @@ -849,11 +851,8 @@ bool game::start_game() return true; } -void game::place_starting_vehicle( cata::optional starting_vehicle ) +void game::place_starting_vehicle( const cata::optional &starting_vehicle ) { - if( !starting_vehicle ) { - return; - } vehicle veh( *starting_vehicle ); std::vector omt_search_types; if( veh.can_float() ) { diff --git a/src/game.h b/src/game.h index 24f80cb66634d..6a26f6efe6e83 100644 --- a/src/game.h +++ b/src/game.h @@ -734,7 +734,7 @@ class game void init_autosave(); // Initializes autosave parameters void create_starting_npcs(); // Creates NPCs that start near you // try and place starting vehicle on a nearby road. - void place_starting_vehicle( cata::optional starting_vehicle ); + void place_starting_vehicle( const cata::optional &starting_vehicle ); void find_location_for_starting_vehicle( const vproto_id id, std::vector &omt_search_types ); From 463f781eaa6f448f9bd446102d66a61828aca7b7 Mon Sep 17 00:00:00 2001 From: dpwb Date: Thu, 13 Feb 2020 13:28:58 +0000 Subject: [PATCH 5/6] apply suggestions from code review --- src/game.cpp | 73 +++++++++++++++++--------------------- src/game.h | 7 ++-- src/newcharacter.cpp | 2 +- src/overmapbuffer.cpp | 2 +- src/player.h | 2 +- src/profession.cpp | 6 ++-- src/profession.h | 4 +-- src/string_id_null_ids.cpp | 1 + 8 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 19c6f9f02e594..437c29575ee92 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -851,66 +851,57 @@ bool game::start_game() return true; } -void game::place_starting_vehicle( const cata::optional &starting_vehicle ) +void game::place_starting_vehicle( const vproto_id &starting_vehicle ) { - vehicle veh( *starting_vehicle ); + vehicle veh( starting_vehicle ); std::vector omt_search_types; - if( veh.can_float() ) { - omt_search_types.push_back( "river" ); - omt_search_types.push_back( "lake" ); - } if( veh.max_ground_velocity() > 0 ) { omt_search_types.push_back( "road" ); omt_search_types.push_back( "field" ); + } else if( veh.can_float() ) { + omt_search_types.push_back( "river" ); + omt_search_types.push_back( "lake" ); } - if( omt_search_types.empty() ) { - return; - } - find_location_for_starting_vehicle( *starting_vehicle, omt_search_types ); + place_vehicle_nearby( starting_vehicle, u.global_omt_location().xy(), 1, 30, omt_search_types ); } -void game::find_location_for_starting_vehicle( const vproto_id id, - std::vector &omt_search_types ) +vehicle *game::place_vehicle_nearby( const vproto_id &id, const point &origin, int min_distance, + int max_distance, const std::vector &omt_search_types ) { for( const std::string &search_type : omt_search_types ) { omt_find_params find_params; find_params.must_see = false; find_params.cant_see = false; find_params.types.emplace_back( search_type, ot_match_type::type ); - for( int count = 0; count < 10; ++count ) { - // find nearest road - find_params.min_distance = count * 2; - find_params.search_range = 10 + count * 2; - // if player spawns underground, park their car on the surface. - tripoint omt_origin = u.global_omt_location(); - omt_origin.z = 0; - std::vector goals = overmap_buffer.find_all( omt_origin, find_params ); - for( const tripoint &goal : goals ) { - if( goal != overmap::invalid_tripoint ) { - // try place vehicle there. - tinymap target_map; - target_map.load( omt_to_sm_copy( goal ), false ); - tripoint origin = target_map.getlocal( sm_to_ms_copy( omt_to_sm_copy( goal ) ) ) + point( - SEEX, SEEY ); - std::vector angles = {0, 90, 180, 270}; - vehicle *veh = target_map.add_vehicle( id, origin, random_entry( angles ), rng( 50, 80 ), - 0, - false ); - if( veh ) { - tripoint abs_local = g->m.getlocal( target_map.getabs( origin ) ); - tripoint p_m = ms_to_sm_remain( abs_local ); - veh->sm_pos = p_m; - veh->pos = abs_local.xy(); - overmap_buffer.add_vehicle( veh ); - target_map.save(); - return; - } - } + // find nearest road + find_params.min_distance = min_distance; + find_params.search_range = max_distance; + // if player spawns underground, park their car on the surface. + const tripoint omt_origin( origin.x, origin.y, 0 ); + std::vector goals = overmap_buffer.find_all( omt_origin, find_params ); + for( const tripoint &goal : goals ) { + // try place vehicle there. + tinymap target_map; + target_map.load( omt_to_sm_copy( goal ), false ); + tripoint origin = target_map.getlocal( sm_to_ms_copy( omt_to_sm_copy( goal ) ) ) + point( + SEEX, SEEY ); + static const std::vector angles = {0, 90, 180, 270}; + vehicle *veh = target_map.add_vehicle( id, origin, random_entry( angles ), rng( 50, 80 ), + 0, + false ); + if( veh ) { + tripoint abs_local = g->m.getlocal( target_map.getabs( origin ) ); + veh->sm_pos = ms_to_sm_remain( abs_local ); + veh->pos = abs_local.xy(); + overmap_buffer.add_vehicle( veh ); + target_map.save(); + return veh; } } } debugmsg( "could not place starting vehicle" ); + return nullptr; } //Make any nearby overmap npcs active, and put them in the right location. diff --git a/src/game.h b/src/game.h index 6a26f6efe6e83..c8d03b35cc928 100644 --- a/src/game.h +++ b/src/game.h @@ -734,10 +734,9 @@ class game void init_autosave(); // Initializes autosave parameters void create_starting_npcs(); // Creates NPCs that start near you // try and place starting vehicle on a nearby road. - void place_starting_vehicle( const cata::optional &starting_vehicle ); - void find_location_for_starting_vehicle( const vproto_id id, - std::vector &omt_search_types ); - + void place_starting_vehicle( const vproto_id &starting_vehicle ); + vehicle *place_vehicle_nearby( const vproto_id &id, const point &origin, int min_distance, + int max_distance, const std::vector &omt_search_types ); // V Menu Functions and helpers: void list_items_monsters(); // Called when you invoke the `V`-menu diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 5abbef1cf45c2..1364aa4da65d4 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -1488,7 +1488,7 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef // Profession vehicle if( sorted_profs[cur_id]->vehicle() ) { buffer += colorize( _( "Vehicle:" ), c_light_blue ) + "\n"; - vproto_id veh_id = *sorted_profs[cur_id]->vehicle(); + vproto_id veh_id = sorted_profs[cur_id]->vehicle(); buffer += veh_id->name; } // Profession spells diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index 872b3f094d260..516c69e5fc9db 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -600,7 +600,7 @@ void overmapbuffer::remove_vehicle( const vehicle *veh ) void overmapbuffer::add_vehicle( vehicle *veh ) { - point abs_pos = g->m.getabs( veh->global_pos3().xy() ); + const point abs_pos = g->m.getabs( veh->global_pos3().xy() ); const point omt = ms_to_omt_copy( abs_pos ); const overmap_with_local_coords om_loc = get_om_global( omt ); int id = om_loc.om->vehicles.size() + 1; diff --git a/src/player.h b/src/player.h index 07038476f2d7e..262c258fd5f4d 100644 --- a/src/player.h +++ b/src/player.h @@ -943,7 +943,7 @@ class player : public Character bool reach_attacking = false; bool manual_examine = false; - cata::optional starting_vehicle; + vproto_id starting_vehicle; std::vector starting_pets; void make_craft_with_command( const recipe_id &id_to_make, int batch_size, bool is_long = false, diff --git a/src/profession.cpp b/src/profession.cpp index 0585a0e103951..87f4c62ddd64f 100644 --- a/src/profession.cpp +++ b/src/profession.cpp @@ -289,8 +289,8 @@ void profession::check_definition() const if( !item_group::group_is_defined( _starting_items_female ) ) { debugmsg( "_starting_items_female group is undefined" ); } - if( _starting_vehicle && !_starting_vehicle->is_valid() ) { - debugmsg( "vehicle prototype %s for profession %s does not exist", _starting_vehicle->c_str(), + if( _starting_vehicle && !_starting_vehicle.is_valid() ) { + debugmsg( "vehicle prototype %s for profession %s does not exist", _starting_vehicle.c_str(), id.c_str() ); } for( const auto &a : _starting_CBMs ) { @@ -440,7 +440,7 @@ std::list profession::items( bool male, const std::vector &trait return result; } -cata::optional profession::vehicle() const +vproto_id profession::vehicle() const { return _starting_vehicle; } diff --git a/src/profession.h b/src/profession.h index bf89e72a9931f..3af14b3c274e8 100644 --- a/src/profession.h +++ b/src/profession.h @@ -70,7 +70,7 @@ class profession std::vector _starting_CBMs; std::vector _starting_traits; std::vector _starting_pets; - cata::optional _starting_vehicle; + vproto_id _starting_vehicle = vproto_id::NULL_ID(); // the int is what level the spell starts at std::map _starting_spells; std::set flags; // flags for some special properties of the profession @@ -105,7 +105,7 @@ class profession signed int point_cost() const; std::list items( bool male, const std::vector &traits ) const; std::vector addictions() const; - cata::optional vehicle() const; + vproto_id vehicle() const; std::vector pets() const; std::vector CBMs() const; StartingSkillList skills() const; diff --git a/src/string_id_null_ids.cpp b/src/string_id_null_ids.cpp index 3c57688a3b1dd..15648c9294284 100644 --- a/src/string_id_null_ids.cpp +++ b/src/string_id_null_ids.cpp @@ -26,6 +26,7 @@ MAKE_NULL_ID( faction, "NULL" ) MAKE_NULL_ID( ammunition_type, "NULL" ) MAKE_NULL_ID( vpart_info, "null" ) MAKE_NULL_ID( emit, "null" ) +MAKE_NULL_ID( vehicle_prototype, "null" ) MAKE_NULL_ID( anatomy, "null_anatomy" ) MAKE_NULL_ID( martialart, "style_none" ) MAKE_NULL_ID( recipe, "null" ) From 6f4a07c3db2feeac5c1f517aca095f716746ea7e Mon Sep 17 00:00:00 2001 From: dpwb Date: Mon, 17 Feb 2020 13:07:36 +0000 Subject: [PATCH 6/6] implement suggestions from review --- src/game.cpp | 42 +++++++++++++++++++----------------------- src/game.h | 5 ++--- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 437c29575ee92..e96aa66d02852 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -838,8 +838,10 @@ bool game::start_game() add_msg( m_debug, "cannot place starting pet, no space!" ); } } - if( u.starting_vehicle ) { - place_starting_vehicle( u.starting_vehicle ); + if( u.starting_vehicle && + !place_vehicle_nearby( u.starting_vehicle, u.global_omt_location().xy(), 1, 30, + std::vector {} ) ) { + debugmsg( "could not place starting vehicle" ); } // Assign all of this scenario's missions to the player. for( const mission_type_id &m : scen->missions() ) { @@ -851,25 +853,22 @@ bool game::start_game() return true; } -void game::place_starting_vehicle( const vproto_id &starting_vehicle ) -{ - vehicle veh( starting_vehicle ); - std::vector omt_search_types; - if( veh.max_ground_velocity() > 0 ) { - omt_search_types.push_back( "road" ); - omt_search_types.push_back( "field" ); - } else if( veh.can_float() ) { - omt_search_types.push_back( "river" ); - omt_search_types.push_back( "lake" ); - } - place_vehicle_nearby( starting_vehicle, u.global_omt_location().xy(), 1, 30, omt_search_types ); - -} - vehicle *game::place_vehicle_nearby( const vproto_id &id, const point &origin, int min_distance, int max_distance, const std::vector &omt_search_types ) { - for( const std::string &search_type : omt_search_types ) { + std::vector search_types = omt_search_types; + if( search_types.empty() ) { + vehicle veh( id ); + std::vector omt_search_types; + if( veh.max_ground_velocity() > 0 ) { + search_types.push_back( "road" ); + search_types.push_back( "field" ); + } else if( veh.can_float() ) { + search_types.push_back( "river" ); + search_types.push_back( "lake" ); + } + } + for( const std::string &search_type : search_types ) { omt_find_params find_params; find_params.must_see = false; find_params.cant_see = false; @@ -879,13 +878,11 @@ vehicle *game::place_vehicle_nearby( const vproto_id &id, const point &origin, i find_params.search_range = max_distance; // if player spawns underground, park their car on the surface. const tripoint omt_origin( origin.x, origin.y, 0 ); - std::vector goals = overmap_buffer.find_all( omt_origin, find_params ); - for( const tripoint &goal : goals ) { + for( const tripoint &goal : overmap_buffer.find_all( omt_origin, find_params ) ) { // try place vehicle there. tinymap target_map; target_map.load( omt_to_sm_copy( goal ), false ); - tripoint origin = target_map.getlocal( sm_to_ms_copy( omt_to_sm_copy( goal ) ) ) + point( - SEEX, SEEY ); + const tripoint origin( SEEX, SEEY, goal.z ); static const std::vector angles = {0, 90, 180, 270}; vehicle *veh = target_map.add_vehicle( id, origin, random_entry( angles ), rng( 50, 80 ), 0, @@ -900,7 +897,6 @@ vehicle *game::place_vehicle_nearby( const vproto_id &id, const point &origin, i } } } - debugmsg( "could not place starting vehicle" ); return nullptr; } diff --git a/src/game.h b/src/game.h index c8d03b35cc928..fbbca30dcfdbd 100644 --- a/src/game.h +++ b/src/game.h @@ -733,10 +733,9 @@ class game // Data Initialization void init_autosave(); // Initializes autosave parameters void create_starting_npcs(); // Creates NPCs that start near you - // try and place starting vehicle on a nearby road. - void place_starting_vehicle( const vproto_id &starting_vehicle ); + // create vehicle nearby, for example; for a profession vehicle. vehicle *place_vehicle_nearby( const vproto_id &id, const point &origin, int min_distance, - int max_distance, const std::vector &omt_search_types ); + int max_distance, const std::vector &omt_search_types = {} ); // V Menu Functions and helpers: void list_items_monsters(); // Called when you invoke the `V`-menu