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

Get roofs generated for basecamps #72724

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,9 @@ bool generate_uniform_omt( const tripoint_abs_sm &p, const oter_id &terrain_type
class tinymap : private map
{
friend class editmap;
protected:
tinymap( int mapsize, bool zlev ) : map( mapsize, zlev ) {};

public:
tinymap() : map( 2, false ) {}
bool inbounds( const tripoint &p ) const override;
Expand Down Expand Up @@ -2637,4 +2640,18 @@ class fake_map : public tinymap
~fake_map() override;
static constexpr int fake_map_z = -OVERMAP_DEPTH;
};

/**
* Smallmap is similar to tinymap in that it covers a single overmap terrain (OMT) tile, but differs
* from it in that it covers all Z levels, not just a single one. It's intended usage is for cases
* where you need to operate on an OMT, but cannot guarantee you needs are restricted to a single
* Z level.
* The smallmap's natural relative reference system is the tripoint_omt_ms one.
*/
class smallmap : public tinymap
{
public:
smallmap() : tinymap( 2, true ) {}
void add_roofs();
};
#endif // CATA_SRC_MAP_H
27 changes: 18 additions & 9 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7688,27 +7688,36 @@ bool update_mapgen_function_json::update_map(
return false;
}

std::unique_ptr<tinymap> p_update_tmap = std::make_unique<tinymap>();
tinymap &update_tmap = *p_update_tmap;
std::unique_ptr<smallmap> p_update_smap = std::make_unique<smallmap>();
smallmap &update_smap = *p_update_smap;

update_tmap.load( omt_pos, true );
update_tmap.rotate( 4 - rotation );
update_tmap.mirror( mirror_horizontal, mirror_vertical );
update_smap.load( omt_pos, true );
update_smap.rotate( 4 - rotation );
update_smap.mirror( mirror_horizontal, mirror_vertical );

mapgendata md_base( omt_pos, *update_tmap.cast_to_map(), 0.0f, calendar::start_of_cataclysm, miss );
mapgendata md_base( omt_pos, *update_smap.cast_to_map(), 0.0f, calendar::start_of_cataclysm, miss );
mapgendata md( md_base, args );

bool const u = update_map( md, offset, verify );
update_tmap.mirror( mirror_horizontal, mirror_vertical );
update_tmap.rotate( rotation );
update_smap.mirror( mirror_horizontal, mirror_vertical );
update_smap.rotate( rotation );

if( get_map().inbounds( project_to<coords::ms>( omt_pos ) ) ) {
// trigger main map cleanup
p_update_tmap.reset();
p_update_smap.reset();
// trigger new traps, etc
g->place_player( get_avatar().pos(), true );
}

// Trigger magic to add roofs (within load) if needed.
if( omt_pos.z() < OVERMAP_HEIGHT ) {
std::unique_ptr<smallmap> p_roof_smap = std::make_unique<smallmap>();
smallmap &roof_smap = *p_roof_smap;
// The loading of the Z level above is not necessary, but looks better.
const tripoint_abs_omt omt_above = { omt_pos.x(), omt_pos.y(), omt_pos.z() + 1 };
roof_smap.load( omt_above, false );
}

return u;
}

Expand Down
Loading