Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow professions to start with a nearby vehicle - trucker profession #37314

Merged
merged 6 commits into from Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions data/json/professions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
56 changes: 56 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ bool game::start_game()
add_msg( m_debug, "cannot place starting pet, no space!" );
}
}
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() );
Expand All @@ -848,6 +851,59 @@ bool game::start_game()
return true;
}

void game::place_starting_vehicle( const vproto_id &starting_vehicle )
This conversation was marked as resolved.
Show resolved Hide resolved
{
vehicle veh( starting_vehicle );
std::vector<std::string> omt_search_types;
if( veh.max_ground_velocity() > 0 ) {
omt_search_types.push_back( "road" );
omt_search_types.push_back( "field" );
This conversation was marked as resolved.
Show resolved Hide resolved
} 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<std::string> &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 );
// 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<tripoint> goals = overmap_buffer.find_all( omt_origin, find_params );
This conversation was marked as resolved.
Show resolved Hide resolved
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(
This conversation was marked as resolved.
Show resolved Hide resolved
SEEX, SEEY );
static const std::vector<int> 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" );
This conversation was marked as resolved.
Show resolved Hide resolved
return nullptr;
}

//Make any nearby overmap npcs active, and put them in the right location.
void game::load_npcs()
{
Expand Down
5 changes: 4 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +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( 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<std::string> &omt_search_types );
// V Menu Functions and helpers:
void list_items_monsters(); // Called when you invoke the `V`-menu

Expand Down
9 changes: 8 additions & 1 deletion src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<item> prof_items = prof->items( male, get_mutations() );

for( item &it : prof_items ) {
Expand Down Expand Up @@ -1476,14 +1478,19 @@ tab_direction set_profession( const catacurses::window &w, avatar &u, points_lef
}
}
// Profession pet
cata::optional<mtype_id> montype;
if( !sorted_profs[cur_id]->pets().empty() ) {
buffer += colorize( _( "Pets:" ), c_light_blue ) + "\n";
for( auto elem : sorted_profs[cur_id]->pets() ) {
monster mon( elem );
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";
Expand Down
3 changes: 2 additions & 1 deletion src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
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;
// this *should* be unique but just in case
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ class player : public Character

bool reach_attacking = false;
bool manual_examine = false;

vproto_id starting_vehicle;
std::vector<mtype_id> starting_pets;

void make_craft_with_command( const recipe_id &id_to_make, int batch_size, bool is_long = false,
Expand Down
13 changes: 12 additions & 1 deletion src/profession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -434,6 +440,11 @@ std::list<item> profession::items( bool male, const std::vector<trait_id> &trait
return result;
}

vproto_id profession::vehicle() const
{
return _starting_vehicle;
}

std::vector<mtype_id> profession::pets() const
{
return _starting_pets;
Expand Down
3 changes: 3 additions & 0 deletions src/profession.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pldata.h"
#include "translations.h"
#include "type_id.h"
#include "veh_type.h"

template<typename T>
class generic_factory;
Expand Down Expand Up @@ -69,6 +70,7 @@ class profession
std::vector<bionic_id> _starting_CBMs;
std::vector<trait_id> _starting_traits;
std::vector<mtype_id> _starting_pets;
vproto_id _starting_vehicle = vproto_id::NULL_ID();
// the int is what level the spell starts at
std::map<spell_id, int> _starting_spells;
std::set<std::string> flags; // flags for some special properties of the profession
Expand Down Expand Up @@ -103,6 +105,7 @@ class profession
signed int point_cost() const;
std::list<item> items( bool male, const std::vector<trait_id> &traits ) const;
std::vector<addiction> addictions() const;
vproto_id vehicle() const;
std::vector<mtype_id> pets() const;
std::vector<bionic_id> CBMs() const;
StartingSkillList skills() const;
Expand Down
1 change: 1 addition & 0 deletions src/string_id_null_ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it should be MAKE_NULL_ID2 as vehicle_prototype is a struct, not a class. It seems not to affect most compilers, but VS would bitch about this when linking.

MAKE_NULL_ID( anatomy, "null_anatomy" )
MAKE_NULL_ID( martialart, "style_none" )
MAKE_NULL_ID( recipe, "null" )
Expand Down