Skip to content

Commit

Permalink
typified submap.h/cpp (CleverRaven#74911)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell authored Jul 8, 2024
1 parent e7d0f7d commit 1e228ca
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 522 deletions.
20 changes: 10 additions & 10 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void editmap::draw_main_ui_overlay()
if( sm ) {
const tripoint_bub_ms sm_origin = origin_p + tripoint( x * SEEX, y * SEEY, target.z() );
for( const spawn_point &sp : sm->spawns ) {
const tripoint_bub_ms spawn_p = sm_origin + sp.pos;
const tripoint_bub_ms spawn_p = sm_origin + rebase_rel( sp.pos );
const auto spawn_it = spawns.find( spawn_p );
if( spawn_it == spawns.end() ) {
const Creature::Attitude att = sp.friendly ? Creature::Attitude::FRIENDLY : Creature::Attitude::ANY;
Expand Down Expand Up @@ -1918,7 +1918,7 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )
} else if( gpmenu.ret == 1 ) {
tmpmap.rotate( 1 );
} else if( gpmenu.ret == 2 ) {
const point target_sub( target.x() / SEEX, target.y() / SEEY );
const point_rel_sm target_sub( target.x() / SEEX, target.y() / SEEY );

here.set_transparency_cache_dirty( target.z() );
here.set_outside_cache_dirty( target.z() );
Expand All @@ -1933,21 +1933,21 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
// Apply previewed mapgen to map. Since this is a function for testing, we try avoid triggering
// functions that would alter the results
const tripoint dest_pos = target_sub + tripoint( x, y, z );
const tripoint src_pos = tripoint{ x, y, z };
const tripoint_rel_sm dest_pos = target_sub + tripoint( x, y, z );
const tripoint_rel_sm src_pos = tripoint_rel_sm{ x, y, z };

submap *destsm = here.get_submap_at_grid( dest_pos );
submap *srcsm = tmpmap.get_submap_at_grid( src_pos );
if( srcsm == nullptr || destsm == nullptr ) {
debugmsg( "Tried to apply previewed mapgen at (%d,%d,%d) but the submap is not loaded", src_pos.x,
src_pos.y, src_pos.z );
debugmsg( "Tried to apply previewed mapgen at (%d,%d,%d) but the submap is not loaded", src_pos.x(),
src_pos.y(), src_pos.z() );
continue;
}

std::swap( *destsm, *srcsm );

for( auto &veh : destsm->vehicles ) {
veh->sm_pos = dest_pos;
veh->sm_pos = dest_pos.raw();
}

if( !destsm->spawns.empty() ) { // trigger spawnpoints
Expand All @@ -1960,11 +1960,11 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )
// Since we cleared the vehicle cache of the whole z-level (not just the generate map), we add it back here
for( int x = 0; x < here.getmapsize(); x++ ) {
for( int y = 0; y < here.getmapsize(); y++ ) {
const tripoint dest_pos = tripoint( x, y, target.z() );
const tripoint_rel_sm dest_pos = tripoint_rel_sm( x, y, target.z() );
const submap *destsm = here.get_submap_at_grid( dest_pos );
if( destsm == nullptr ) {
debugmsg( "Tried to update vehicle cache at (%d,%d,%d) but the submap is not loaded", dest_pos.x,
dest_pos.y, dest_pos.z );
debugmsg( "Tried to update vehicle cache at (%d,%d,%d) but the submap is not loaded", dest_pos.x(),
dest_pos.y(), dest_pos.z() );
continue;
}
here.update_vehicle_list( destsm, target.z() ); // update real map's vcaches
Expand Down
10 changes: 10 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5040,11 +5040,21 @@ monster *game::place_critter_at( const mtype_id &id, const tripoint &p )
return place_critter_around( id, p, 0 );
}

monster *game::place_critter_at( const mtype_id &id, const tripoint_bub_ms &p )
{
return place_critter_around( id, p.raw(), 0 );
}

monster *game::place_critter_at( const shared_ptr_fast<monster> &mon, const tripoint &p )
{
return place_critter_around( mon, p, 0 );
}

monster *game::place_critter_at( const shared_ptr_fast<monster> &mon, const tripoint_bub_ms &p )
{
return place_critter_around( mon, p.raw(), 0 );
}

monster *game::place_critter_around( const mtype_id &id, const tripoint &center, const int radius )
{
// TODO: change this into an assert, it must never happen.
Expand Down
3 changes: 3 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,11 @@ class game
* the one contained in @p mon).
*/
/** @{ */
// TODO: Get rid of untyped overload.
monster *place_critter_at( const mtype_id &id, const tripoint &p );
monster *place_critter_at( const mtype_id &id, const tripoint_bub_ms &p );
monster *place_critter_at( const shared_ptr_fast<monster> &mon, const tripoint &p );
monster *place_critter_at( const shared_ptr_fast<monster> &mon, const tripoint_bub_ms &p );
monster *place_critter_around( const mtype_id &id, const tripoint &center, int radius );
monster *place_critter_around( const shared_ptr_fast<monster> &mon, const tripoint &center,
int radius, bool forced = false );
Expand Down
7 changes: 6 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10258,12 +10258,17 @@ bool item::spill_contents( Character &c )
}

bool item::spill_contents( const tripoint &pos )
{
return item::spill_contents( tripoint_bub_ms( pos ) );
}

bool item::spill_contents( const tripoint_bub_ms &pos )
{
if( ( !is_container() && !is_magazine() && !uses_magazine() ) ||
is_container_empty() ) {
return true;
}
return contents.spill_contents( pos );
return contents.spill_contents( pos.raw() );
}

bool item::spill_open_pockets( Character &guy, const item *avoid )
Expand Down
2 changes: 2 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,9 @@ class item : public visitable
* @param pos Position to dump the contents on.
* @return If the item is now empty.
*/
// TODO: Get rid of untyped overload.
bool spill_contents( const tripoint &pos );
bool spill_contents( const tripoint_bub_ms &pos );
bool spill_open_pockets( Character &guy, const item *avoid = nullptr );
// spill items that don't fit in the container
void overflow( const tripoint &pos, const item_location &loc = item_location::nowhere );
Expand Down
8 changes: 4 additions & 4 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ bool map::build_transparency_cache( const int zlev )

// calculates transparency of a single tile
// x,y - coords in map local coords
auto calc_transp = [&]( const point & p ) {
const point sp = p - sm_offset;
auto calc_transp = [&]( const point_sm_ms & p ) {
const point_sm_ms sp = p - sm_offset;
float value = LIGHT_TRANSPARENCY_OPEN_AIR;

if( !( cur_submap->get_ter( sp ).obj().transparent &&
cur_submap->get_furn( sp ).obj().transparent ) ) {
return std::make_pair( LIGHT_TRANSPARENCY_SOLID, LIGHT_TRANSPARENCY_SOLID );
}
if( outside_cache[p.x][p.y] ) {
if( outside_cache[p.x()][p.y()] ) {
// FIXME: Places inside vehicles haven't been marked as
// inside yet so this is incorrectly penalising for
// weather in vehicles.
Expand All @@ -159,7 +159,7 @@ bool map::build_transparency_cache( const int zlev )
if( cur_submap->is_uniform() ) {
float value;
float dummy;
std::tie( value, dummy ) = calc_transp( sm_offset );
std::tie( value, dummy ) = calc_transp( point_sm_ms( sm_offset ) );
// if rebuild_all==true all values were already set to LIGHT_TRANSPARENCY_OPEN_AIR
if( !rebuild_all || value != LIGHT_TRANSPARENCY_OPEN_AIR ) {
bool opaque = value <= LIGHT_TRANSPARENCY_SOLID;
Expand Down
Loading

0 comments on commit 1e228ca

Please sign in to comment.