Compare commits

...

6 Commits

Author SHA1 Message Date
Kevin Granade 8fcafdfc33 node to zone 2021-10-13 23:29:00 -07:00
Kevin Granade 8121923b3f Fixes 2021-10-13 21:38:53 -07:00
Kevin Granade a7ecf96e88 WIP overmap node 2021-10-13 21:20:41 -07:00
Kevin Granade e832612eae Add overlap check to cuboids and to map. 2021-10-13 21:20:41 -07:00
Kevin Granade d26ecc6bd3 Extract cleanup on submap exiting the reality bubble. 2021-10-13 21:20:41 -07:00
Kevin Granade 94aa269372 Split a mixing function into its own method 2021-10-13 21:20:41 -07:00
18 changed files with 586 additions and 63 deletions
@@ -8,7 +8,7 @@
"color": "cyan",
"move_cost_mod": 1,
"required_str": -1,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "FUNGUS", "TINY", "NOCOLLIDE" ],
"flags": [ "TRANSPARENT", "FUNGUS", "TINY", "NOCOLLIDE" ],
"examine_action": "flower_marloss",
"bash": { "str_min": 2, "str_max": 6, "sound": "poof.", "sound_fail": "poof." }
},
@@ -21,7 +21,7 @@
"color": "dark_gray",
"move_cost_mod": 1,
"required_str": -1,
"flags": [ "TRANSPARENT", "FLOWER", "FUNGUS", "TINY", "FLAMMABLE_ASH", "NOCOLLIDE" ],
"flags": [ "TRANSPARENT", "FLOWER", "FUNGUS", "TINY", "NOCOLLIDE" ],
"examine_action": "fungus",
"bash": { "str_min": 2, "str_max": 6, "sound": "poof.", "sound_fail": "poof." }
},
@@ -34,7 +34,7 @@
"bgcolor": "dark_gray",
"move_cost_mod": -10,
"required_str": -1,
"flags": [ "CONTAINER", "SEALED", "ALLOW_FIELD_EFFECT", "FLAMMABLE_ASH", "FUNGUS", "MOUNTABLE", "SHORT" ],
"flags": [ "CONTAINER", "SEALED", "ALLOW_FIELD_EFFECT", "FUNGUS", "MOUNTABLE", "SHORT" ],
"bash": { "str_min": 6, "str_max": 30, "sound": "poof.", "sound_fail": "poof." }
},
{
@@ -46,7 +46,7 @@
"bgcolor": "light_gray",
"move_cost_mod": 3,
"required_str": -1,
"flags": [ "TRANSPARENT", "CONTAINER", "SEALED", "ALLOW_FIELD_EFFECT", "FLAMMABLE_ASH", "FUNGUS", "MOUNTABLE", "SHORT" ],
"flags": [ "TRANSPARENT", "CONTAINER", "SEALED", "ALLOW_FIELD_EFFECT", "FUNGUS", "MOUNTABLE", "SHORT" ],
"bash": { "str_min": 6, "str_max": 20, "sound": "poof.", "sound_fail": "poof." }
},
{
@@ -59,7 +59,7 @@
"bgcolor": "light_gray",
"move_cost_mod": -1,
"required_str": -1,
"flags": [ "FLAMMABLE_ASH", "FUNGUS" ],
"flags": [ "FUNGUS" ],
"bash": { "str_min": 26, "str_max": 50, "sound": "poof.", "sound_fail": "squelch." }
}
]
@@ -8,7 +8,7 @@
"color": "pink",
"move_cost": 8,
"coverage": 40,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "FUNGUS", "SHRUB", "SHORT" ],
"flags": [ "TRANSPARENT", "FUNGUS", "SHRUB", "SHORT" ],
"examine_action": "shrub_marloss",
"bash": { "str_min": 4, "str_max": 60, "sound": "crunch.", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
@@ -20,7 +20,7 @@
"symbol": ".",
"color": "light_gray",
"move_cost": 3,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "DIGGABLE", "FUNGUS", "NOCOLLIDE" ],
"flags": [ "TRANSPARENT", "DIGGABLE", "FUNGUS", "NOCOLLIDE" ],
"bash": {
"sound": "smash",
"//": "muffled because fungus",
@@ -39,7 +39,7 @@
"symbol": ".",
"color": "light_gray",
"move_cost": 2,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "SUPPORTS_ROOF", "COLLAPSES", "INDOORS", "FLAT", "FUNGUS" ],
"flags": [ "TRANSPARENT", "SUPPORTS_ROOF", "COLLAPSES", "INDOORS", "FLAT", "FUNGUS" ],
"bash": { "sound": "smash", "ter_set": "t_null", "str_min": 20, "str_max": 400, "str_min_supported": 50 }
},
{
@@ -51,7 +51,7 @@
"symbol": ".",
"color": "light_gray",
"move_cost": 2,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "SUPPORTS_ROOF", "FLAT", "FUNGUS" ],
"flags": [ "TRANSPARENT", "SUPPORTS_ROOF", "FLAT", "FUNGUS" ],
"bash": { "sound": "smash", "ter_set": "t_null", "str_min": 20, "str_max": 400, "str_min_supported": 50 }
},
{
@@ -63,7 +63,7 @@
"symbol": ".",
"color": "light_gray",
"move_cost": 2,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "FLAT", "FUNGUS" ],
"flags": [ "TRANSPARENT", "FLAT", "FUNGUS" ],
"bash": { "sound": "SMASH!", "ter_set": "t_null", "str_min": 20, "str_max": 400, "str_min_supported": 50 }
},
{
@@ -76,7 +76,7 @@
"color": "dark_gray",
"move_cost": 0,
"coverage": 100,
"flags": [ "FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "FUNGUS", "WALL", "REDUCE_SCENT", "MINEABLE" ],
"flags": [ "NOITEM", "SUPPORTS_ROOF", "FUNGUS", "WALL", "REDUCE_SCENT", "MINEABLE" ],
"bash": { "str_min": 30, "str_max": 180, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -88,7 +88,7 @@
"color": "dark_gray",
"move_cost": 0,
"coverage": 100,
"flags": [ "FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "FUNGUS", "WALL", "NO_SCENT", "AUTO_WALL_SYMBOL", "MINEABLE" ],
"flags": [ "NOITEM", "SUPPORTS_ROOF", "FUNGUS", "WALL", "NO_SCENT", "AUTO_WALL_SYMBOL", "MINEABLE" ],
"bash": { "str_min": 30, "str_max": 180, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -99,7 +99,7 @@
"symbol": "#",
"color": "light_gray",
"move_cost": 4,
"flags": [ "TRANSPARENT", "THIN_OBSTACLE", "FLAMMABLE_ASH", "FUNGUS", "MOUNTABLE" ],
"flags": [ "TRANSPARENT", "THIN_OBSTACLE", "FUNGUS", "MOUNTABLE" ],
"bash": { "str_min": 10, "str_max": 70, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -111,7 +111,7 @@
"color": "dark_gray",
"move_cost": 8,
"coverage": 40,
"flags": [ "TRANSPARENT", "CONTAINER", "FLAMMABLE_ASH", "THIN_OBSTACLE", "PLACE_ITEM", "SHRUB", "FUNGUS", "SHORT" ],
"flags": [ "TRANSPARENT", "CONTAINER", "THIN_OBSTACLE", "PLACE_ITEM", "SHRUB", "FUNGUS", "SHORT" ],
"bash": { "str_min": 4, "str_max": 60, "sound": "crunch.", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -123,7 +123,7 @@
"color": "dark_gray",
"move_cost": 0,
"coverage": 80,
"flags": [ "FLAMMABLE_ASH", "NOITEM", "FUNGUS", "TREE", "REDUCE_SCENT" ],
"flags": [ "NOITEM", "FUNGUS", "TREE", "REDUCE_SCENT" ],
"bash": { "str_min": 40, "str_max": 180, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -134,7 +134,7 @@
"symbol": "1",
"color": "dark_gray",
"move_cost": 4,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "NOITEM", "FUNGUS", "YOUNG", "REDUCE_SCENT" ],
"flags": [ "TRANSPARENT", "NOITEM", "FUNGUS", "YOUNG", "REDUCE_SCENT" ],
"bash": { "str_min": 4, "str_max": 50, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
},
{
@@ -146,7 +146,7 @@
"color": "pink",
"move_cost": 0,
"coverage": 80,
"flags": [ "FLAMMABLE_ASH", "NOITEM", "FUNGUS", "TREE", "REDUCE_SCENT" ],
"flags": [ "NOITEM", "FUNGUS", "TREE", "REDUCE_SCENT" ],
"examine_action": "tree_marloss",
"bash": { "str_min": 40, "str_max": 180, "sound": "crunch!", "sound_fail": "poof!", "ter_set": "t_fungus" }
}
+35
View File
@@ -56,5 +56,40 @@
},
"monster": { "X": { "monster": "mon_fungaloid_tower" }, "Y": { "monster": "mon_fungaloid_queen" } }
}
},
{
"type": "mapgen",
"method": "json",
"om_terrain": [ "fungal_wasteland" ],
"weight": 100,
"object": {
"rows": [
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................"
],
"terrain": { ".": [ [ "t_grass_dead", 2 ], "t_fungus" ] }
}
}
]
@@ -1,4 +1,14 @@
[
{
"type": "overmap_terrain",
"id": "fungal_wasteland",
"name": "fungal wasteland",
"sym": ".",
"color": "light_gray",
"see_cost": 2,
"extras": "marloss",
"flags": [ "NO_ROTATE", "RISK_HIGH" ]
},
{
"type": "overmap_terrain",
"id": "fungal_tower",
@@ -7,6 +17,7 @@
"color": "yellow",
"see_cost": 3,
"extras": "marloss",
"node": { "spread": { "rate": "1 minute", "terrain_type": "t_fungus", "overmap_terrain": "fungal_wasteland" } },
"flags": [ "NO_ROTATE", "RISK_HIGH" ]
},
{
+1 -23
View File
@@ -2177,29 +2177,7 @@ bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY categ
// only bother mixing up a hash/random value if the tile has some sprites to randomly pick
// between
if( display_tile.fg.size() > 1 || display_tile.bg.size() > 1 ) {
static const auto rot32 = []( const unsigned int x, const int k ) {
return ( x << k ) | ( x >> ( 32 - k ) );
};
// use a fair mix function to turn the "random" seed into a random int
// taken from public domain code at http://burtleburtle.net/bob/c/lookup3.c 2015/12/11
unsigned int a = seed;
unsigned int b = -seed;
unsigned int c = seed * seed;
c ^= b;
c -= rot32( b, 14 );
a ^= c;
a -= rot32( c, 11 );
b ^= a;
b -= rot32( a, 25 );
c ^= b;
c -= rot32( b, 16 );
a ^= c;
a -= rot32( c, 4 );
b ^= a;
b -= rot32( a, 14 );
c ^= b;
c -= rot32( b, 24 );
loc_rand = c;
loc_rand = mixed_hash( seed );
// idle tile animations:
if( display_tile.animated ) {
+18
View File
@@ -98,6 +98,15 @@ struct half_open_cuboid : cuboid<Tripoint> {
Traits::y( p ) >= Traits::y( p_min ) && Traits::y( p ) < Traits::y( p_max ) &&
Traits::z( p ) >= Traits::z( p_min ) && Traits::z( p ) < Traits::z( p_max );
}
constexpr bool overlaps( const cuboid<Tripoint> &r ) const {
using Traits = point_traits<Tripoint>;
return !( Traits::x( r.p_min ) >= Traits::x( p_max ) ||
Traits::y( r.p_min ) >= Traits::y( p_max ) ||
Traits::z( r.p_min ) > Traits::z( p_max ) ||
Traits::x( p_min ) >= Traits::x( r.p_max ) ||
Traits::y( p_min ) >= Traits::y( r.p_max ) ||
Traits::z( p_min ) > Traits::z( r.p_max ) );
}
};
template<typename Tripoint, decltype( std::declval<cuboid<Tripoint>>(), int() ) = 0>
@@ -113,6 +122,15 @@ struct inclusive_cuboid : cuboid<Tripoint> {
Traits::y( p ) >= Traits::y( p_min ) && Traits::y( p ) <= Traits::y( p_max ) &&
Traits::z( p ) >= Traits::z( p_min ) && Traits::z( p ) <= Traits::z( p_max );
}
constexpr bool overlaps( const cuboid<Tripoint> &r ) const {
using Traits = point_traits<Tripoint>;
return !( Traits::x( r.p_min ) > Traits::x( p_max ) ||
Traits::y( r.p_min ) > Traits::y( p_max ) ||
Traits::z( r.p_min ) > Traits::z( p_max ) ||
Traits::x( p_min ) > Traits::x( r.p_max ) ||
Traits::y( p_min ) > Traits::y( r.p_max ) ||
Traits::z( p_min ) > Traits::z( r.p_max ) );
}
};
// Clamp p to the rectangle r.
+1 -4
View File
@@ -621,10 +621,7 @@ bool do_turn()
// Move hordes every 2.5 min
if( calendar::once_every( time_duration::from_minutes( 2.5 ) ) ) {
overmap_buffer.move_hordes();
if( u.has_trait( trait_HAS_NEMESIS ) ) {
overmap_buffer.move_nemesis();
}
overmap_buffer.do_tick( u.has_trait( trait_HAS_NEMESIS ) );
// Hordes that reached the reality bubble need to spawn,
// make them spawn in invisible areas only.
m.spawn_monsters( false );
+156 -5
View File
@@ -6641,6 +6641,135 @@ shift_bitset_cache<MAPSIZE_X, SEEX>( std::bitset<MAPSIZE_X *MAPSIZE_X> &cache,
template void
shift_bitset_cache<MAPSIZE, 1>( std::bitset<MAPSIZE *MAPSIZE> &cache, const point &s );
void map::update_zone( zone_of_influence &zone, const tripoint_abs_omt &grid_abs_omt )
{
tripoint omt_sm_origin = project_to<coords::sm>( grid_abs_omt ).raw();
std::array<tripoint, 4> submap_locations = {
omt_sm_origin, omt_sm_origin + point_east,
omt_sm_origin + point_south, omt_sm_origin + point_south_east
};
int new_coverage = 0;
for( tripoint submap_location : submap_locations ) {
submap *cur_submap = MAPBUFFER.lookup_submap( submap_location );
for( int x = 0; x < SEEX; ++x ) {
for( int y = 0; y < SEEY; ++y ) {
if( cur_submap->get_ter( point( x, y ) ) == zone.type->spread_terrain_type ) {
new_coverage++;
}
}
}
}
int previous_coverage = zone.omt_coverage[grid_abs_omt];
int change_in_coverage = previous_coverage - new_coverage;
zone.omt_coverage[grid_abs_omt] = new_coverage;
if( change_in_coverage > 0 ) {
zone.lost_coverage[grid_abs_omt] += change_in_coverage;
} else if( change_in_coverage < 0 ) {
debugmsg( "Zone coverage unexpectedly increased at %d/%d/%d from %d to %d.",
grid_abs_omt.x(), grid_abs_omt.y(), grid_abs_omt.z(),
previous_coverage, new_coverage );
}
}
void map::unload_submap( const tripoint &abs, tripoint grid )
{
const tripoint_abs_sm p( abs + grid );
submaps_with_active_items.erase( p.raw() );
// Rationalize actual remaining invasive terrain numbers with numbers stored
// in the overmap zone of influence.
tripoint_abs_omt grid_abs_omt = project_to<coords::omt>( p );
// Round-tripping gets us the origin of the OMT.
tripoint_abs_ms omt_ms_origin = project_to<coords::ms>( grid_abs_omt );
tripoint_abs_ms omt_end = omt_ms_origin + point( 24, 24 );
cuboid<tripoint_abs_ms> omt_bounds( omt_ms_origin, omt_end );
zone_of_influence *zone = overmap_buffer.nearby_zone( grid_abs_omt );
// Since zone data is tracked at an OMT scale, only tally up this data when
// the entire OMT has left the map.
if( zone && p.z() == zone->origin.z() && !overlaps( omt_bounds ) ) {
update_zone( *zone, grid_abs_omt );
}
}
void map::apply_zone_update( zone_of_influence &zone )
{
tripoint_abs_ms origin( sm_to_ms_copy( abs_sub ) );
tripoint_abs_ms end( origin + point( getmapsize() * SEEX, getmapsize() * SEEY ) );
// Two passes because I can't see a way to keep zone application consistent
// if we don't have an accurate tally from the start.
// Tally up existing converted terrain tiles.
tripoint_abs_omt map_origin = project_to<coords::omt>( tripoint_abs_sm( abs_sub ) );
tripoint_abs_omt map_end = project_to<coords::omt>(
tripoint_abs_sm( abs_sub + point( MAPSIZE - 1, MAPSIZE - 1 ) ) );
for( tripoint_abs_omt cursor = map_origin; cursor.x() <= map_end.x(); cursor += point_east ) {
for( cursor.y() = map_origin.y(); cursor.y() <= map_end.y(); cursor += point_south ) {
update_zone( zone, cursor );
}
}
// Apply repairs if any.
for( tripoint_abs_omt omt_location = map_origin; omt_location.x() <= map_end.x();
omt_location += point_east ) {
for( omt_location.y() = map_origin.y(); omt_location.y() <= map_end.y();
omt_location += point_south ) {
auto loss = zone.lost_coverage.find( omt_location );
auto regrowth = zone.omt_regrowth.find( omt_location );
bool damaged = false;
if( loss != zone.lost_coverage.end() ) {
if( regrowth == zone.omt_regrowth.end() || regrowth->second == 0 ) {
// If we have lost coverage but no allocated regrowth, just bail out.
continue;
}
damaged = true;
}
auto coverage = zone.omt_coverage.find( omt_location );
tripoint_abs_ms maptile_location = project_to<coords::ms>( omt_location );
std::vector<tripoint> regrowth_candidates;
point omt_start = point_zero;
if( maptile_location.x() < origin.x() ) {
omt_start.x = origin.x() - maptile_location.x();
}
if( maptile_location.y() < origin.y() ) {
omt_start.y = origin.y() - maptile_location.y();
}
point omt_end = point( SEEX * 2, SEEY * 2 );
if( maptile_location.x() + omt_end.x > end.x() ) {
omt_end.x = end.x() - maptile_location.x() + omt_end.x;
}
if( maptile_location.y() + omt_end.y > end.y() ) {
omt_end.y = end.y() - maptile_location.y() + omt_end.y;
}
// TODO: Clamp this to be inbounds for the map.
for( point omt_offset = omt_start; omt_offset.x < omt_end.y; ++omt_offset.x ) {
for( omt_offset.y = omt_start.y; omt_offset.y < omt_end.y; ++omt_offset.y ) {
tripoint_abs_ms abs_location = maptile_location + omt_offset;
tripoint local_location = getlocal( abs_location );
if( zone.can_grow_on_tile( abs_location, ter( local_location ) ) ) {
if( damaged ) {
regrowth_candidates.push_back( local_location );
continue;
}
if( ter_set( local_location, zone.type->spread_terrain_type ) ) {
coverage->second++;
}
}
}
}
if( regrowth != zone.omt_regrowth.end() &&
regrowth->second < static_cast<int>( regrowth_candidates.size() ) ) {
// Pick some regrowth candidates
std::shuffle( regrowth_candidates.begin(), regrowth_candidates.end(), rng_get_engine() );
regrowth_candidates.erase( regrowth_candidates.begin() + regrowth->second,
regrowth_candidates.end() );
}
for( const tripoint &candidate : regrowth_candidates ) {
ter_set( candidate, zone.type->spread_terrain_type );
coverage->second++;
loss->second--;
regrowth->second--;
}
}
}
}
void map::shift( const point &sp )
{
// Special case of 0-shift; refresh the map
@@ -6686,7 +6815,7 @@ void map::shift( const point &sp )
if( sp.y >= 0 ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
if( ( sp.x > 0 && gridx == 0 ) || ( sp.y > 0 && gridy == 0 ) ) {
submaps_with_active_items.erase( { abs.x + gridx, abs.y + gridy, gridz } );
unload_submap( abs, { gridx, gridy, gridz } );
}
if( gridx + sp.x < my_MAPSIZE && gridy + sp.y < my_MAPSIZE ) {
copy_grid( tripoint( gridx, gridy, gridz ),
@@ -6705,7 +6834,7 @@ void map::shift( const point &sp )
} else { // sy < 0; work through it backwards
for( int gridy = my_MAPSIZE - 1; gridy >= 0; gridy-- ) {
if( ( sp.x > 0 && gridx == 0 ) || gridy == my_MAPSIZE - 1 ) {
submaps_with_active_items.erase( { abs.x + gridx, abs.y + gridy, gridz } );
unload_submap( abs, { gridx, gridy, gridz } );
}
if( gridx + sp.x < my_MAPSIZE && gridy + sp.y >= 0 ) {
copy_grid( tripoint( gridx, gridy, gridz ),
@@ -6728,7 +6857,7 @@ void map::shift( const point &sp )
if( sp.y >= 0 ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
if( gridx == my_MAPSIZE - 1 || ( sp.y > 0 && gridy == 0 ) ) {
submaps_with_active_items.erase( { abs.x + gridx, abs.y + gridy, gridz } );
unload_submap( abs, { gridx, gridy, gridz } );
}
if( gridx + sp.x >= 0 && gridy + sp.y < my_MAPSIZE ) {
copy_grid( tripoint( gridx, gridy, gridz ),
@@ -6747,7 +6876,7 @@ void map::shift( const point &sp )
} else { // sy < 0; work through it backwards
for( int gridy = my_MAPSIZE - 1; gridy >= 0; gridy-- ) {
if( gridx == my_MAPSIZE - 1 || gridy == my_MAPSIZE - 1 ) {
submaps_with_active_items.erase( { abs.x + gridx, abs.y + gridy, gridz } );
unload_submap( abs, { gridx, gridy, gridz } );
}
if( gridx + sp.x >= 0 && gridy + sp.y >= 0 ) {
copy_grid( tripoint( gridx, gridy, gridz ),
@@ -6768,6 +6897,11 @@ void map::shift( const point &sp )
}
}
// Call up to overmap scale to catch up zones_of_influence and
// call back into map to apply results as needed.
// Hacky, replace by refactoring OMB to expose a method to just do zone ticks.
overmap_buffer.do_tick( false );
rebuild_vehicle_level_caches();
g->setremoteveh( remoteveh );
@@ -6875,6 +7009,7 @@ void map::loadn( const tripoint &grid, const bool update_vehicles, bool _actuali
const int old_abs_z = abs_sub.z; // Ugly, but necessary at the moment
abs_sub.z = grid.z;
const tripoint_abs_omt grid_abs_omt( sm_to_omt_copy( grid_abs_sub ) );
submap *tmpsub = MAPBUFFER.lookup_submap( grid_abs_sub );
if( tmpsub == nullptr ) {
@@ -6884,7 +7019,6 @@ void map::loadn( const tripoint &grid, const bool update_vehicles, bool _actuali
// Each overmap square is two nonants; to prevent overlap, generate only at
// squares divisible by 2.
// TODO: fix point types
const tripoint_abs_omt grid_abs_omt( sm_to_omt_copy( grid_abs_sub ) );
const tripoint grid_abs_sub_rounded = omt_to_sm_copy( grid_abs_omt.raw() );
const oter_id terrain_type = overmap_buffer.ter( grid_abs_omt );
@@ -7654,6 +7788,23 @@ const std::vector<tripoint> &map::trap_locations( const trap_id &type ) const
return traplocs[type.to_i()];
}
bool map::overlaps( const cuboid<tripoint_abs_ms> &bounds ) const
{
return overlaps( cuboid<tripoint>( getlocal( bounds.p_min ),
getlocal( bounds.p_max ) ) );
}
bool map::overlaps( const cuboid<tripoint> &p ) const
{
static constexpr tripoint map_boundary_min( 0, 0, -OVERMAP_DEPTH );
static constexpr tripoint map_boundary_max( MAPSIZE_Y, MAPSIZE_X, OVERMAP_HEIGHT + 1 );
static constexpr half_open_cuboid<tripoint> map_boundaries(
map_boundary_min, map_boundary_max );
return map_boundaries.overlaps( p );
}
bool map::inbounds( const tripoint_abs_ms &p ) const
{
return inbounds( getlocal( p ) );
+18
View File
@@ -65,6 +65,7 @@ class vehicle;
class zone_data;
struct fragment_cloud;
struct maptile;
struct zone_of_influence;
struct partial_con;
struct spawn_data;
struct trap;
@@ -541,6 +542,17 @@ class map
*/
void vertical_shift( int newz );
/**
* Updates the designated map area to catch up with new state from the
* overmap zone of influence.
*/
void apply_zone_update( zone_of_influence &zone );
private:
/**
* Updates the specified zone with information from the map.
*/
void update_zone( zone_of_influence &zone, const tripoint_abs_omt &grid_abs_omt );
public:
void clear_spawns();
void clear_traps();
@@ -1653,6 +1665,8 @@ class map
bool inbounds( const point &p ) const {
return inbounds( tripoint( p, 0 ) );
}
bool overlaps( const cuboid<tripoint_abs_ms> &bounds ) const;
bool overlaps( const cuboid<tripoint> &p ) const;
bool inbounds_z( const int z ) const {
return z >= -OVERMAP_DEPTH && z <= OVERMAP_HEIGHT;
@@ -1730,6 +1744,10 @@ class map
loadn( tripoint( grid, abs_sub.z ), update_vehicles, _actualize );
}
}
// This doesn't mean erase from memory, the submap is owned by mapbuffer.
// This means handle any cleanup we need when a submap leves the active area.
void unload_submap( const tripoint &abs, tripoint grid );
/**
* Fast forward a submap that has just been loading into this map.
* This is used to rot and remove rotten items, grow plants, fill funnels etc.
+46
View File
@@ -165,6 +165,43 @@ struct overmap_static_spawns : public overmap_spawns {
}
};
// Defines an area on the overmap that can grow and adjust terrain autonomously.
struct zone_of_influence_type {
// How often the area grows, this occurs independently of player presence.
time_duration spread_rate;
// Map from existing terrain to a terrain type to transform them into,
// Make terrain_type a from:to map
ter_id spread_terrain_type;
// A new overmap-scale terrain type to apply once an area has been spread to.
// Essentially this updates the symbol and name shown to the player on the overmap.
oter_type_str_id spread_overmap_type;
// The OMT that is the origin of this entry, used as a label for lookup in serialization.
oter_type_str_id parent;
};
// Holds the instance data for the above autonomously growing zone.
struct zone_of_influence {
zone_of_influence( const tripoint_abs_omt &p, const zone_of_influence_type *new_type ) :
origin( p ), type( new_type ), last_spread( calendar::start_of_cataclysm ), area( 0 ) {}
const tripoint_abs_omt origin;
const zone_of_influence_type *type;
time_point last_spread;
// The number of tiles worth of terrain adjustments that have been accumulated.
// Terrain alterations only occur when the player approaches.
int area;
// Tracks terrain tiles allocated to different OMTs in the area.
std::map<tripoint_abs_omt, int> omt_coverage;
// Tracks terrain tiles lost from player action, these get prioritized for replenishment.
std::map<tripoint_abs_omt, int> lost_coverage;
// Tracks tiles reserved for placement after being destroyed.
std::map<tripoint_abs_omt, int> omt_regrowth;
// Radius of affected area in tiles, calculated by working backwards from the affected area,
float radius() {
return std::sqrt( area / M_PI );
}
bool can_grow_on_tile( const tripoint_abs_ms &abs_location, ter_id target_terrain_type );
};
//terrain flags enum! this is for tracking the indices of each flag.
enum class oter_flags : int {
known_down = 0,
@@ -268,10 +305,15 @@ struct oter_type_t {
return has_connections() && connect_group == other->connect_group;
}
const cata::optional<zone_of_influence_type> &get_zone_of_influence() const {
return zone_type;
}
private:
enum_bitset<oter_flags> flags;
std::vector<oter_id> directional_peers;
std::string connect_group; // Group for connection when rendering overmap tiles
cata::optional<zone_of_influence_type> zone_type;
void register_terrain( const oter_t &peer, size_t n, size_t max_n );
};
@@ -393,6 +435,10 @@ struct oter_t {
return type->has_flag( oter_flags::ravine_edge );
}
const cata::optional<zone_of_influence_type> &get_zone_of_influence() const {
return type->get_zone_of_influence();
}
private:
om_direction::type dir = om_direction::type::none;
uint32_t symbol;
+114
View File
@@ -31,6 +31,7 @@
#include "generic_factory.h"
#include "json.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapbuffer.h"
#include "mapgen.h"
@@ -617,6 +618,17 @@ void oter_type_t::load( const JsonObject &jo, const std::string &src )
assign( jo, "color", color, strict );
assign( jo, "land_use_code", land_use_code, strict );
if( jo.has_member( "zone" ) ) {
zone_of_influence_type zone;
JsonObject zone_jo = jo.get_object( "zone" );
JsonObject spread_jo = zone_jo.get_object( "spread" );
assign( spread_jo, "rate", zone.spread_rate, strict );
assign( spread_jo, "terrain_type", zone.spread_terrain_type, strict );
assign( spread_jo, "overmap_terrain", zone.spread_overmap_type, strict );
zone.parent = id;
zone_type = zone;
}
if( jo.has_member( "looks_like" ) ) {
std::vector<std::string> ll;
if( jo.has_array( "looks_like" ) ) {
@@ -2808,6 +2820,13 @@ std::vector<point_abs_omt> overmap::find_extras( const int z, const std::string
return extra_locations;
}
void overmap::add_zone_of_influence( const tripoint_om_omt &p,
const zone_of_influence_type &zone_type )
{
tripoint_abs_omt zone_origin( project_combine( pos(), p ) );
zones_of_influence.emplace_back( zone_origin, &zone_type );
}
bool overmap::inbounds( const tripoint_om_omt &p, int clearance )
{
static constexpr tripoint_om_omt overmap_boundary_min( 0, 0, -OVERMAP_DEPTH );
@@ -3596,6 +3615,98 @@ void overmap::signal_hordes( const tripoint_rel_sm &p_rel, const int sig_power )
}
}
// function object that initializes with a point as its input
struct point_hash_generator {
using result_type = unsigned int;
point p;
unsigned int operator()() const {
return mixed_hash( std::hash<point> {}( p ) );
}
static constexpr unsigned int min() {
return std::numeric_limits<unsigned int>::min();
}
static constexpr unsigned int max() {
return std::numeric_limits<unsigned int>::max();
}
};
static int point_rng( point p, int lo, int hi )
{
static std::uniform_int_distribution<int> rng_int_dist;
point_hash_generator gen{ p };
return rng_int_dist( gen, std::uniform_int_distribution<>::param_type( lo, hi ) );
}
bool zone_of_influence::can_grow_on_tile( const tripoint_abs_ms &abs_location,
ter_id target_terrain_type )
{
if( type->spread_terrain_type == target_terrain_type ) {
return false;
}
tripoint_abs_ms zone_origin = project_to<coords::ms>( origin ) + point( SEEX, SEEY );
float distance = rl_dist_exact( zone_origin.raw(), abs_location.raw() );
// The hash function applies some noise to the outer edge of the area.
int point_percentage = point_rng( abs_location.xy().raw(), 1, 100 );
float zone_radius = radius();
// TODO: Make this continuous instead of piecewise.
return ( point_percentage <= 10 && distance <= zone_radius * sqrt( 1.5 ) ) ||
( point_percentage <= 30 && distance <= zone_radius * sqrt( 1.3 ) ) ||
( point_percentage <= 50 && distance <= zone_radius * sqrt( 1.1 ) ) ||
( point_percentage <= 70 && distance <= zone_radius * sqrt( 0.9 ) ) ||
( point_percentage <= 90 && distance <= zone_radius * sqrt( 0.7 ) ) ||
distance <= zone_radius * sqrt( 0.5 );
}
void overmap::update_zones_of_influence()
{
map &m = get_map();
for( zone_of_influence &zone : zones_of_influence ) {
int num_ticks = ( calendar::turn - zone.last_spread ) / zone.type->spread_rate;
unsigned int growth = num_ticks;
if( num_ticks > 0 ) {
zone.last_spread += zone.type->spread_rate * num_ticks;
}
// This performs https://en.wikipedia.org/wiki/Reservoir_sampling to select
// up to growth elements from the lost_coverage set.
std::vector<tripoint_abs_omt> selected_points;
int global_index = 0;
for( std::pair<const tripoint_abs_omt, int> &local_lost_coverage : zone.lost_coverage ) {
int index = 0;
for( ; index < local_lost_coverage.second &&
selected_points.size() <= growth; ++index, ++global_index ) {
// First fill up the vector.
selected_points.push_back( local_lost_coverage.first );
}
for( ; index < local_lost_coverage.second; ++index, ++global_index ) {
unsigned int replacement = rng( 0, global_index - 1 );
if( replacement < growth ) {
selected_points[ replacement + 1 ] = local_lost_coverage.first;
}
}
}
// Once we've selected our candidates, we transfer globally available capacity into
// capacity reserved for a particular OMT.
for( const tripoint_abs_omt &selected_point : selected_points ) {
growth--;
zone.omt_regrowth[selected_point]++;
auto loss = zone.lost_coverage.find( selected_point );
if( loss->second == zone.omt_regrowth[ selected_point ] ) {
zone.lost_coverage.erase( loss );
zone.omt_regrowth.erase( selected_point );
}
}
zone.area += growth;
tripoint_abs_ms ms_origin = project_to<coords::ms>( zone.origin ) + point( SEEX, SEEY );
int zone_radius = zone.radius();
tripoint_abs_ms ms_min = ms_origin + point( -zone_radius, -zone_radius );
tripoint_abs_ms ms_max = ms_origin + point( zone_radius, zone_radius );
cuboid<tripoint_abs_ms> zone_bounds( ms_min, ms_max );
if( m.overlaps( zone_bounds ) ) {
m.apply_zone_update( zone );
}
}
}
void overmap::signal_nemesis( const tripoint_abs_sm p_abs_sm )
{
//CONVERT ABS SM TO OM_SM
@@ -5491,6 +5602,9 @@ static std::vector<tripoint_om_omt> place_fixed_overmap_special(
const oter_id tid = elem.terrain->get_rotated( dir );
om.ter_set( location, tid );
if( tid->get_zone_of_influence() ) {
om.add_zone_of_influence( location, *tid->get_zone_of_influence() );
}
if( blob ) {
for( int x = -2; x <= 2; x++ ) {
+6
View File
@@ -299,6 +299,9 @@ class overmap
void add_extra( const tripoint_om_omt &p, const string_id<map_extra> &id );
void delete_extra( const tripoint_om_omt &p );
// Add an active overmap entity that will be periodically updated.
void add_zone_of_influence( const tripoint_om_omt &p,
const zone_of_influence_type &zone_type );
/**
* Getter for overmap scents.
* @returns a reference to a scent_trace from the requested location.
@@ -401,6 +404,7 @@ class overmap
std::array<map_layer, OVERMAP_LAYERS> layer;
std::unordered_map<tripoint_abs_omt, scent_trace> scents;
std::vector<zone_of_influence> zones_of_influence;
// Records the locations where a given overmap special was placed, which
// can be used after placement to lookup whether a given location was created
// as part of a special.
@@ -470,6 +474,8 @@ class overmap
void place_nemesis( const tripoint_abs_omt p );
bool remove_nemesis(); // returns true if nemesis found and removed
void update_zones_of_influence();
static bool obsolete_terrain( const std::string &ter );
void convert_terrain(
const std::unordered_map<tripoint_om_omt, std::string> &needs_conversion );
+16 -1
View File
@@ -1011,6 +1011,11 @@ static void draw_om_sidebar(
}
}
}
// TODO: Mask this with a flag so we're not always scanning for it.
zone_of_influence *zone = overmap_buffer.nearby_zone( center );
if( zone && zone->origin != center ) {
zone = nullptr;
}
// Draw the vertical line
for( int j = 0; j < TERMY; j++ ) {
@@ -1027,7 +1032,17 @@ static void draw_om_sidebar(
// Draw text describing the overmap tile at the cursor position.
int lines = 1;
if( center_seen && !viewing_weather ) {
if( !mgroups.empty() ) {
if( zone ) {
int line_number = 6;
mvwprintz( wbar, point( 3, line_number++ ),
c_blue, " area: %d", zone->area );
mvwprintz( wbar, point( 3, line_number++ ),
c_blue, " covered omt area: %d", zone->omt_coverage.size() );
mvwprintz( wbar, point( 3, line_number++ ),
c_blue, " damaged omts: %d", zone->lost_coverage.size() );
mvwprintz( wbar, point( 3, line_number++ ),
c_blue, " regrowing omts: %d", zone->omt_regrowth.size() );
} else if( !mgroups.empty() ) {
int line_number = 6;
for( const auto &mgroup : mgroups ) {
mvwprintz( wbar, point( 3, line_number++ ),
+26 -6
View File
@@ -547,18 +547,18 @@ void overmapbuffer::process_mongroups()
}
}
void overmapbuffer::move_hordes()
void overmapbuffer::do_tick( bool has_nemesis )
{
// arbitrary radius to include nearby overmaps (aside from the current one)
const int radius = MAPSIZE * 2;
const tripoint_abs_sm center = get_player_character().global_sm_location();
for( auto &om : get_overmaps_near( center, radius ) ) {
for( overmap *om : get_overmaps_near( center, radius ) ) {
om->move_hordes();
om->update_zones_of_influence();
}
if( !has_nemesis ) {
return;
}
}
void overmapbuffer::move_nemesis()
{
for( std::pair<const point_abs_om, std::unique_ptr<overmap>> &omp : overmaps ) {
omp.second->move_nemesis();
fix_nemesis( *omp.second );
@@ -575,6 +575,26 @@ void overmapbuffer::remove_nemesis()
}
}
zone_of_influence *overmapbuffer::nearby_zone( const tripoint_abs_omt &p )
{
// arbitrary radius to include nearby overmaps (aside from the current one)
const int radius = MAPSIZE * 20;
// TODO: Make this return a list of all the zones_of_influence in range.
zone_of_influence *nearest_zone = nullptr;
int nearest_zone_distance = radius * 2;
tripoint_abs_sm sm_p = project_to<coords::sm>( p );
for( overmap *om : get_overmaps_near( sm_p, radius ) ) {
for( zone_of_influence &zone : om->zones_of_influence ) {
int distance = rl_dist( zone.origin, p );
if( distance < nearest_zone_distance && distance < zone.radius() ) {
nearest_zone = &zone;
nearest_zone_distance = distance;
}
}
}
return nearest_zone;
}
std::vector<mongroup *> overmapbuffer::monsters_at( const tripoint_abs_omt &p )
{
// (x,y) are overmap terrain coordinates, they spawn 2x2 submaps,
+7 -7
View File
@@ -417,10 +417,11 @@ class overmapbuffer
*/
void process_mongroups();
/**
* Let hordes move a step. Note that this may move monster groups inside the reality bubble,
* Advance any active entities at overmap scale by a tick.
* Note that this may move monster groups inside the reality bubble,
* therefore you should probably call @ref map::spawn_monsters to spawn them.
*/
void move_hordes();
void do_tick( bool has_nemesis );
/**
* Signal nemesis horde to player location
* @param p is the player's location, which functions as the signal origin
@@ -431,15 +432,14 @@ class overmapbuffer
* adds a nemesis horde into the hordes list of the overmap where the kill_nemesis mision is targeted
*/
void add_nemesis( const tripoint_abs_omt &p );
/**
* moves 'nemesis' horde spawned by the "hunted" trait across every overmap
* regardless of distance from player
*/
void move_nemesis();
/**
* removes 'nemesis' horde spawned by the "hunted" on player death
*/
void remove_nemesis();
/**
* Return the nearest zone of influence that overlaps the current location, if any.
*/
zone_of_influence *nearby_zone( const tripoint_abs_omt &p );
// hordes -- this uses overmap terrain coordinates!
std::vector<mongroup *> monsters_at( const tripoint_abs_omt &p );
/**
+27
View File
@@ -154,3 +154,30 @@ std::vector<point> closest_points_first( const point &center, int min_dist, int
return result;
}
unsigned int mixed_hash( unsigned int seed )
{
static const auto rot32 = []( const unsigned int x, const int k ) {
return ( x << k ) | ( x >> ( 32 - k ) );
};
// use a fair mix function to turn the "random" seed into a random int
// taken from public domain code at http://burtleburtle.net/bob/c/lookup3.c 2015/12/11
unsigned int a = seed;
unsigned int b = -seed;
unsigned int c = seed * seed;
c ^= b;
c -= rot32( b, 14 );
a ^= c;
a -= rot32( c, 11 );
b ^= a;
b -= rot32( a, 25 );
c ^= b;
c -= rot32( b, 16 );
a ^= c;
a -= rot32( c, 4 );
b ^= a;
b -= rot32( a, 14 );
c ^= b;
c -= rot32( b, 24 );
return c;
}
+2
View File
@@ -365,6 +365,8 @@ struct hash<tripoint> {
};
} // namespace std
unsigned int mixed_hash( unsigned int seed );
static constexpr std::array<point, 4> four_adjacent_offsets{{
point_north, point_east, point_south, point_west
}};
+85
View File
@@ -495,6 +495,15 @@ void overmap::load_legacy_monstergroups( JsonIn &jsin )
}
}
// Define a specialized template instance that can decode a tripoint_abs_omt.
// TODO: generalize for all the coordinate types?
template<>
struct key_from_json_string<tripoint_abs_omt, void> {
tripoint_abs_omt operator()( const std::string &s ) {
return tripoint_abs_omt( tripoint::from_string( s ) );
}
};
// throws std::exception
void overmap::unserialize( std::istream &fin )
{
@@ -727,6 +736,51 @@ void overmap::unserialize( std::istream &fin )
}
}
}
} else if( name == "zone_of_influence" ) {
jsin.start_array();
while( !jsin.end_array() ) {
tripoint_abs_omt origin;
const zone_of_influence_type *type = nullptr;
time_point last_spread = calendar::start_of_cataclysm;
int area = 0;
std::map<tripoint_abs_omt, int> omt_coverage;
std::map<tripoint_abs_omt, int> lost_coverage;
std::map<tripoint_abs_omt, int> omt_regrowth;
jsin.start_object();
while( !jsin.end_object() ) {
const std::string zone_member_name = jsin.get_member_name();
if( zone_member_name == "origin" ) {
jsin.read( origin );
} else if( zone_member_name == "parent" ) {
// TODO: Bundle up the more robust ter loading from
std::string parent = jsin.get_string();
oter_str_id omt_id( parent );
if( omt_id.is_valid() && omt_id->get_zone_of_influence() ) {
type = &*omt_id->get_zone_of_influence();
} else {
debugmsg( "Bad OMT id %s in overmap zone of influence loading.", parent.c_str() );
}
} else if( zone_member_name == "last_spread" ) {
jsin.read( last_spread );
} else if( zone_member_name == "area" ) {
jsin.read( area );
} else if( zone_member_name == "omt_coverage" ) {
jsin.read( omt_coverage );
} else if( zone_member_name == "lost_coverage" ) {
jsin.read( lost_coverage );
} else if( zone_member_name == "omt_regrowth" ) {
jsin.read( omt_regrowth );
}
}
zone_of_influence zone( origin, type );
zone.last_spread = last_spread;
zone.area = area;
zone.omt_coverage = std::move( omt_coverage );
zone.lost_coverage = std::move( lost_coverage );
zone.omt_regrowth = std::move( omt_regrowth );
zones_of_influence.push_back( std::move( zone ) );
}
} else if( name == "mapgen_arg_storage" ) {
jsin.read( mapgen_arg_storage, true );
} else if( name == "mapgen_arg_index" ) {
@@ -1147,6 +1201,37 @@ void overmap::serialize( std::ostream &fout ) const
json.end_array();
fout << std::endl;
if( !zones_of_influence.empty() ) {
json.member( "zone_of_influence" );
json.start_array();
for( const zone_of_influence &zone : zones_of_influence ) {
json.start_object();
json.member( "origin", zone.origin );
json.member( "last_spread", zone.last_spread );
json.member( "area", zone.area );
json.member( "omt_coverage" );
json.start_object();
for( const std::pair<const tripoint_abs_omt, int> &coverage : zone.omt_coverage ) {
json.member( coverage.first.to_string_writable(), coverage.second );
}
json.end_object();
json.member( "lost_coverage" );
json.start_object();
for( const std::pair<const tripoint_abs_omt, int> &lost : zone.lost_coverage ) {
json.member( lost.first.to_string_writable(), lost.second );
}
json.end_object();
json.member( "omt_regrowth" );
json.start_object();
for( const std::pair<const tripoint_abs_omt, int> &regrowth : zone.omt_regrowth ) {
json.member( regrowth.first.to_string_writable(), regrowth.second );
}
json.end_object();
json.member( "parent", zone.type->parent.str() );
json.end_object();
}
json.end_array();
}
json.member( "mapgen_arg_storage", mapgen_arg_storage );
fout << std::endl;
json.member( "mapgen_arg_index" );