diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 5c0dddfe399eb..2b4d3bb814f6c 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -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() ); @@ -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; } @@ -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; } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index fc4d6580e5e5e..936b58b8d34fe 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -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(); + } }; /** @@ -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 &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 ) @@ -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 */ @@ -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 ); diff --git a/src/mapgen.h b/src/mapgen.h index 4816d0c48f4e1..e21be63201c30 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -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;