Skip to content

Commit

Permalink
Merge pull request #36100 from davidpwbrown/camp_upgrade_vehicle_fixes
Browse files Browse the repository at this point in the history
Camp upgrade vehicle fixes
  • Loading branch information
Rivet-the-Zombie authored Dec 17, 2019
2 parents ff7d191 + 6903cca commit befe6dd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ void talk_function::start_camp( npc &p )
}
const recipe &making = camp_type.obj();
if( !run_mapgen_update_func( making.get_blueprint(), omt_pos ) ) {
popup( _( "%s failed to start the %s basecamp." ), p.disp_name(), making.get_blueprint() );
popup( _( "%s failed to start the %s basecamp, perhaps there is a vehicle in the way." ),
p.disp_name(), making.get_blueprint() );
return;
}
get_basecamp( p, camp_type.str() );
Expand Down Expand Up @@ -2383,7 +2384,8 @@ bool basecamp::upgrade_return( const point &dir, const std::string &miss,
return false;
}
if( !run_mapgen_update_func( making.get_blueprint(), upos ) ) {
popup( _( "%s failed to build the %s upgrade." ), comp->disp_name(),
popup( _( "%s failed to build the %s upgrade, perhaps there is a vehicle in the way." ),
comp->disp_name(),
making.get_blueprint() );
return false;
}
Expand Down Expand Up @@ -2720,7 +2722,8 @@ bool basecamp::survey_return()
_( "Select an expansion:" ) );

if( !run_mapgen_update_func( expansion_type.str(), where ) ) {
popup( _( "%s failed to add the %s expansion" ), comp->disp_name(),
popup( _( "%s failed to add the %s expansion, perhaps there is a vehicle in the way." ),
comp->disp_name(),
expansion_type->blueprint_name() );
return false;
}
Expand Down
54 changes: 53 additions & 1 deletion src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ class jmapgen_alternativly : public jmapgen_piece
chosen->get().apply( dat, x, y );
}
}
bool has_vehicle_collision( mapgendata &dat, int x, int y ) const override {
return dat.m.veh_at( tripoint( x, y, dat.zlevel() ) ).has_value();
}
};

/**
Expand Down Expand Up @@ -1739,6 +1742,30 @@ class jmapgen_nested : public jmapgen_piece

ptr->nest( dat, point( x.get(), y.get() ) );
}
bool has_vehicle_collision( mapgendata &dat, int x, int y ) const override {
const weighted_int_list<std::string> &selected_entries = neighbors.test(
dat ) ? entries : else_entries;
if( selected_entries.empty() ) {
return false;
}

for( auto &entry : selected_entries ) {
if( entry.obj == "null" ) {
continue;
}
const auto iter = nested_mapgen.find( entry.obj );
if( iter == nested_mapgen.end() ) {
return false;
}
for( auto &nest : iter->second ) {
if( nest->has_vehicle_collision( dat, {x, y} ) ) {
return true;
}
}
}

return false;
}
};

jmapgen_objects::jmapgen_objects( const point &offset, const point &mapsize )
Expand Down Expand Up @@ -2552,6 +2579,31 @@ void mapgen_function_json_base::formatted_set_incredibly_simple( map &m, const p
}
}

bool mapgen_function_json_base::has_vehicle_collision( mapgendata &dat, const point &offset ) const
{
if( do_format ) {
for( int y = 0; y < mapgensize.y; y++ ) {
for( int x = 0; x < mapgensize.x; x++ ) {
const point p( x, y );
const ter_furn_id &tdata = format[calc_index( p )];
const point map_pos = p + offset;
if( ( tdata.furn != f_null || tdata.ter != t_null ) &&
dat.m.veh_at( tripoint( map_pos.x, map_pos.y, dat.zlevel() ) ).has_value() ) {
return true;
}
}
}
}

for( auto &elem : setmap_points ) {
if( elem.has_vehicle_collision( dat, offset ) ) {
return true;
}
}

return objects.has_vehicle_collision( dat, offset );
}

/*
* Apply mapgen as per a derived-from-json recipe; in theory fast, but not very versatile
*/
Expand Down Expand Up @@ -7702,7 +7754,7 @@ bool update_mapgen_function_json::update_map( const tripoint &omt_pos, const poi
{
tinymap update_tmap;
const tripoint sm_pos = omt_to_sm_copy( omt_pos );
update_tmap.load( sm_pos, false );
update_tmap.load( sm_pos, true );

mapgendata md( omt_pos, update_tmap, 0.0f, calendar::start_of_cataclysm, miss );

Expand Down
1 change: 1 addition & 0 deletions src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class mapgen_function_json_base
public:
bool check_inbounds( const jmapgen_int &x, const jmapgen_int &y, const JsonObject &jso ) const;
size_t calc_index( const point &p ) const;
bool has_vehicle_collision( mapgendata &dat, const point &offset ) const;

private:
std::string jdata;
Expand Down

0 comments on commit befe6dd

Please sign in to comment.