Skip to content

Commit

Permalink
refactor(content): convert mine special to mutable (#3696)
Browse files Browse the repository at this point in the history
Converted mine tunnels to mutable
  • Loading branch information
Vollch authored Nov 17, 2023
1 parent 41a1672 commit 55a0cae
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 84 deletions.
2 changes: 1 addition & 1 deletion data/json/overmap/overmap_mutable/lab.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"//": "Nested special, does not spawn by itself",
"type": "overmap_special",
"id": "lab_basement",
"subtype": "mutable",
"locations": [ "subterranean_empty" ],
"occurrences": [ 0, 0 ],
"flags": [ "RESTRICTED" ],
"check_for_locations": [ [ [ 0, 0, 0 ], [ "subterranean_empty" ] ] ],
"joins": [ "lab_to_lab" ],
"overmaps": {
Expand Down
32 changes: 32 additions & 0 deletions data/json/overmap/overmap_mutable/mine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"type": "overmap_special",
"id": "mine_tunnel",
"subtype": "mutable",
"locations": [ "subterranean_empty" ],
"occurrences": [ 0, 0 ],
"flags": [ "RESTRICTED" ],
"check_for_locations": [ [ [ 0, 0, 0 ], [ "subterranean_empty" ] ], [ [ 0, 0, -1 ], [ "subterranean_empty" ] ] ],
"joins": [ "mine_to_mine", "mine_shaft" ],
"overmaps": {
"above_entrance": { "overmap": "empty_rock", "below": "mine_shaft" },
"straight_tunnel": { "overmap": "mine", "north": "mine_to_mine", "south": "mine_to_mine" },
"corner": { "overmap": "mine", "north": "mine_to_mine", "east": "mine_to_mine" },
"stairs_down": { "overmap": "mine_down", "north": "mine_to_mine", "below": "mine_shaft" },
"stairs_up": { "overmap": "mine", "north": "mine_to_mine", "above": "mine_shaft" },
"finale": { "overmap": "mine_finale", "north": "mine_to_mine" },
"fallback": { "overmap": "mine", "above": "mine_shaft" }
},
"root": "above_entrance",
"phases": [
[
{ "overmap": "straight_tunnel", "max": { "poisson": 6 } },
{ "overmap": "corner", "max": { "poisson": 6 } },
{ "overmap": "stairs_down", "max": { "poisson": 3 } },
{ "overmap": "stairs_up", "join": "mine_shaft" }
],
[ { "overmap": "finale", "max": 1 } ],
[ { "overmap": "fallback" } ]
]
}
]
4 changes: 4 additions & 0 deletions data/json/overmap/overmap_special/mine.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{ "point": [ 0, -1, 0 ], "connection": "local_road", "from": [ 0, 0, 0 ] },
{ "point": [ 1, -1, 0 ], "connection": "local_road", "from": [ 1, 0, 0 ] }
],
"place_nested": [ { "point": [ 0, 0, -1 ], "special": "mine_tunnel" } ],
"locations": [ "wilderness" ],
"city_distance": [ 10, 40 ],
"city_sizes": [ 4, -1 ],
Expand Down Expand Up @@ -58,6 +59,7 @@
{ "point": [ 0, -1, 0 ], "connection": "local_road", "from": [ 0, 0, 0 ] },
{ "point": [ 1, -1, 0 ], "connection": "local_road", "from": [ 1, 0, 0 ] }
],
"place_nested": [ { "point": [ 0, 0, -1 ], "special": "mine_tunnel" } ],
"locations": [ "wilderness" ],
"city_distance": [ 10, 40 ],
"city_sizes": [ 4, -1 ],
Expand Down Expand Up @@ -92,6 +94,7 @@
{ "point": [ 0, -1, 0 ], "connection": "local_road", "from": [ 0, 0, 0 ] },
{ "point": [ 1, -1, 0 ], "connection": "local_road", "from": [ 1, 0, 0 ] }
],
"place_nested": [ { "point": [ 0, 0, -1 ], "special": "mine_tunnel" } ],
"locations": [ "wilderness" ],
"city_distance": [ 10, 40 ],
"city_sizes": [ 4, -1 ],
Expand Down Expand Up @@ -121,6 +124,7 @@
{ "point": [ 0, -1, 0 ], "connection": "local_road", "from": [ 0, 0, 0 ] },
{ "point": [ 1, -1, 0 ], "connection": "local_road", "from": [ 1, 0, 0 ] }
],
"place_nested": [ { "point": [ 0, 0, -1 ], "special": "mine_tunnel" } ],
"locations": [ "wilderness" ],
"city_distance": [ 10, 40 ],
"city_sizes": [ 4, -1 ],
Expand Down
4 changes: 4 additions & 0 deletions doc/src/content/docs/en/mod/json/reference/json_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,10 @@ These branches are also the valid entries for the categories of `dreams` in `dre
contain any lake terrain.
- `UNIQUE` Location is unique and will only occur once per overmap. `occurrences` is overridden to
define a percent chance (e.g. `"occurrences" : [75, 100]` is 75%)
- `ENDGAME` Location will have highest priority during special placement, and won't be affected by
any occurrences normalizations.
- `RESTRICTED` Location will never be spawned as starting locations. Intended(but not limited) to
use with incomplete nested specials.

### Overmap terrains

Expand Down
5 changes: 4 additions & 1 deletion src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4741,9 +4741,12 @@ void map::draw_mine( mapgendata &dat )

for( int i = 0; i < SEEX * 2; i++ ) {
for( int j = 0; j < SEEY * 2; j++ ) {
int i_reverse = SEEX * 2 - 1 - i;
int j_reverse = SEEY * 2 - 1 - j;
if( i >= dat.w_fac + rng( 0, 2 ) && i <= EAST_EDGE - dat.e_fac - rng( 0, 2 ) &&
j >= dat.n_fac + rng( 0, 2 ) && j <= SOUTH_EDGE - dat.s_fac - rng( 0, 2 ) &&
i + j >= 4 && ( SEEX * 2 - i ) + ( SEEY * 2 - j ) >= 6 ) {
i + j >= 3 && i_reverse + j_reverse >= 3 &&
i + j_reverse >= 3 && j + i_reverse >= 3 ) {
ter_set( point( i, j ), t_rock_floor );
} else {
ter_set( point( i, j ), t_rock );
Expand Down
83 changes: 2 additions & 81 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3203,40 +3203,8 @@ void overmap::generate( const overmap *north, const overmap *east,

bool overmap::generate_sub( const int z )
{
// We need to generate at least 3 z-levels for labs
bool requires_sub = z > -4;

std::vector<city> mine_points;

// These are so common that it's worth checking first as int.
const std::unordered_set<oter_id> skip_above = {
oter_id( "empty_rock" ), oter_id( "forest" ), oter_id( "field" ),
oter_id( "forest_thick" ), oter_id( "forest_water" )
};

for( int i = 0; i < OMAPX; i++ ) {
for( int j = 0; j < OMAPY; j++ ) {
tripoint_om_omt p( i, j, z );
const oter_id oter_above = ter( p + tripoint_above );
const oter_id oter_ground = ter( tripoint_om_omt( p.xy(), 0 ) );

// implicitly skip skip_above oter_ids
if( skip_above.count( oter_above ) > 0 ) {
continue;
}

if( is_ot_match( "mine_entrance", oter_ground, ot_match_type::prefix ) && z == -2 ) {
mine_points.emplace_back( ( p + tripoint_west ).xy(), rng( 6 + z, 10 + z ) );
requires_sub = true;
} else if( oter_above == "mine_down" ) {
ter_set( p, oter_id( "mine" ) );
mine_points.emplace_back( p.xy(), rng( 6 + z, 10 + z ) );
// technically not all finales need a sub level,
// but at this point we don't know
requires_sub = true;
}
}
}
// We need to generate at least 2 z-levels for subways CHUD
bool requires_sub = z > -2;

for( auto &i : cities ) {
tripoint_om_omt omt_pos( i.pos, z );
Expand All @@ -3253,10 +3221,6 @@ bool overmap::generate_sub( const int z )
}
}

for( auto &i : mine_points ) {
build_mine( tripoint_om_omt( i.pos, z ), i.size );
}

return requires_sub;
}

Expand Down Expand Up @@ -4647,49 +4611,6 @@ void overmap::build_city_street(
}
}

void overmap::build_mine( const tripoint_om_omt &origin, int s )
{
bool finale = s <= rng( 1, 3 );
const oter_id mine( "mine" );
const oter_id mine_finale_or_down( finale ? "mine_finale" : "mine_down" );
const oter_id empty_rock( "empty_rock" );

int built = 0;
if( s < 2 ) {
s = 2;
}
tripoint_om_omt p = origin;
// Don't overwrite existing mapgen
int attempts_left = 100;
while( ter( p ) != empty_rock && attempts_left > 0 ) {
if( one_in( 2 ) ) {
p.x() += rng( 0, 1 ) * 2 - 1;
} else {
p.y() += rng( 0, 1 ) * 2 - 1;
}
attempts_left -= 1;
}
if( !inbounds( p ) ) {
return;
}
while( built < s ) {
ter_set( p, mine );
std::vector<tripoint_om_omt> next;
for( point offset : four_adjacent_offsets ) {
if( ter( p + offset ) == empty_rock ) {
next.push_back( p + offset );
}
}
if( next.empty() ) { // Dead end! Go down!
ter_set( p, mine_finale_or_down );
return;
}
p = random_entry( next );
built++;
}
ter_set( p, mine_finale_or_down );
}

pf::directed_path<point_om_omt> overmap::lay_out_connection(
const overmap_connection &connection, const point_om_omt &source, const point_om_omt &dest,
int z, const bool must_be_unexplored ) const
Expand Down
1 change: 0 additions & 1 deletion src/overmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ class overmap
void build_city_street( const overmap_connection &connection, const point_om_omt &p, int cs,
om_direction::type dir, const city &town, std::vector<tripoint_om_omt> &sewers,
int block_width = 2 );
void build_mine( const tripoint_om_omt &origin, int s );

// Connection laying
pf::directed_path<point_om_omt> lay_out_connection(
Expand Down
4 changes: 4 additions & 0 deletions src/start_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ tripoint_abs_omt start_location::find_player_initial_location() const

// Look for special having that terrain
for( const auto &special : overmap_specials::get_all() ) {
if( special.has_flag( "RESTRICTED" ) ) {
continue;
}

const auto &terrains = special.all_terrains();
if( std::none_of( terrains.begin(), terrains.end(),
[&loc]( const oter_str_id & t ) {
Expand Down

0 comments on commit 55a0cae

Please sign in to comment.