Skip to content

Commit

Permalink
Merge pull request #78722 from Procyonae/UnhardcodeClayDepositExtra
Browse files Browse the repository at this point in the history
Unhardcode mx_clay_deposit
  • Loading branch information
Maleclypse authored Dec 26, 2024
2 parents 1e44b42 + b942dde commit 8bd4c5d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
53 changes: 53 additions & 0 deletions data/json/mapgen/map_extras/clay_deposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"type": "mapgen",
"method": "json",
"update_mapgen_id": "mx_clay_deposit",
"object": {
"place_nested": [
{ "chunks": [ "15x15_clay_deposit" ], "x": [ 0, 9 ], "y": [ 0, 9 ] },
{ "chunks": [ [ "15x15_clay_deposit", 1 ], [ "null", 3 ] ], "x": [ 4, 5 ], "y": [ 4, 5 ] },
{ "chunks": [ [ "15x15_clay_deposit", 1 ], [ "null", 3 ] ], "x": [ 0, 4 ], "y": [ 0, 9 ] },
{ "chunks": [ [ "15x15_clay_deposit", 1 ], [ "null", 3 ] ], "x": [ 5, 9 ], "y": [ 0, 9 ] },
{ "chunks": [ [ "15x15_clay_deposit", 1 ], [ "null", 3 ] ], "x": [ 0, 9 ], "y": [ 0, 4 ] },
{ "chunks": [ [ "15x15_clay_deposit", 1 ], [ "null", 3 ] ], "x": [ 0, 9 ], "y": [ 5, 9 ] }
]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "15x15_clay_deposit",
"object": {
"mapgensize": [ 15, 15 ],
"place_nested": [
{ "chunks": [ "7x7_clay_deposit" ], "x": [ 0, 8 ], "y": [ 0, 8 ] },
{ "chunks": [ "7x7_clay_deposit" ], "x": [ 0, 8 ], "y": [ 0, 8 ] },
{ "chunks": [ "7x7_clay_deposit" ], "x": [ 0, 8 ], "y": [ 0, 8 ] }
]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "7x7_clay_deposit",
"object": {
"mapgensize": [ 7, 7 ],
"rows": [
" xxx ",
" xXXXx ",
"xXXXXXx",
"xXXXXXx",
"xXXXXXx",
" xXXXx ",
" xxx "
],
"terrain": { "X": "t_clay", "x": [ "t_clay", "t_null" ] },
"furniture": {
"X": [ [ "f_burdock", 1 ], [ "f_dogbane", 1 ], [ "f_japanese_knotweed", 1 ], [ "f_null", 21 ] ],
"x": [ [ "f_burdock", 1 ], [ "f_dogbane", 1 ], [ "f_japanese_knotweed", 1 ], [ "f_null", 13 ] ]
},
"flags": [ "ERASE_ALL_BEFORE_PLACING_TERRAIN" ]
}
}
]
2 changes: 1 addition & 1 deletion data/json/overmap/map_extras.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
"type": "map_extra",
"name": { "str": "Clay Deposit" },
"description": "Small clay deposit is here.",
"generator": { "generator_method": "map_extra_function", "generator_id": "mx_clay_deposit" },
"generator": { "generator_method": "update_mapgen", "generator_id": "mx_clay_deposit" },
"min_max_zlevel": [ 0, 0 ],
"sym": "c",
"color": "brown",
Expand Down
48 changes: 0 additions & 48 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ static const itype_id itype_withered( "withered" );
static const map_extra_id map_extra_mx_burned_ground( "mx_burned_ground" );
static const map_extra_id map_extra_mx_casings( "mx_casings" );
static const map_extra_id map_extra_mx_city_trap( "mx_city_trap" );
static const map_extra_id map_extra_mx_clay_deposit( "mx_clay_deposit" );
static const map_extra_id map_extra_mx_corpses( "mx_corpses" );
static const map_extra_id map_extra_mx_fungal_zone( "mx_fungal_zone" );
static const map_extra_id map_extra_mx_grove( "mx_grove" );
Expand Down Expand Up @@ -157,7 +156,6 @@ static const oter_type_str_id oter_type_road( "road" );

static const relic_procgen_id relic_procgen_data_alien_reality( "alien_reality" );

static const ter_str_id ter_t_clay( "t_clay" );
static const ter_str_id ter_t_coast_rock_surf( "t_coast_rock_surf" );
static const ter_str_id ter_t_dirt( "t_dirt" );
static const ter_str_id ter_t_dirtmound( "t_dirtmound" );
Expand Down Expand Up @@ -1289,51 +1287,6 @@ static bool mx_pond( map &m, const tripoint &abs_sub )
return true;
}

static bool mx_clay_deposit( map &m, const tripoint &abs_sub )
{
// This map extra creates small clay deposits using a simple cellular automaton.

constexpr int width = SEEX * 2;
constexpr int height = SEEY * 2;

for( int tries = 0; tries < 5; tries++ ) {
// Generate the cells for our clay deposit.
std::vector<std::vector<int>> current = CellularAutomata::generate_cellular_automaton( width,
height, 35, 5, 4, 3 );

// With our settings for the CA, it's sometimes possible to get a bad generation with not enough
// alive cells (or even 0).
int alive_count = 0;
for( int i = 0; i < width; i++ ) {
for( int j = 0; j < height; j++ ) {
alive_count += current[i][j];
}
}

// If we have fewer than 4 alive cells, lets try again.
if( alive_count < 4 ) {
continue;
}

// Loop through and turn every live cell into clay.
for( int i = 0; i < width; i++ ) {
for( int j = 0; j < height; j++ ) {
if( current[i][j] == 1 ) {
const tripoint location( i, j, abs_sub.z );
m.furn_set( location, furn_str_id::NULL_ID() );
m.ter_set( location, ter_t_clay );
}
}
}

// If we got here, it meant we had a successful try and can just break out of
// our retry loop.
return true;
}

return false;
}

static void burned_ground_parser( map &m, const tripoint &loc )
{
const furn_t &fid = m.furn( loc ).obj();
Expand Down Expand Up @@ -2205,7 +2158,6 @@ static FunctionMap builtin_functions = {
{ map_extra_mx_grove, mx_grove },
{ map_extra_mx_shrubbery, mx_shrubbery },
{ map_extra_mx_pond, mx_pond },
{ map_extra_mx_clay_deposit, mx_clay_deposit },
{ map_extra_mx_burned_ground, mx_burned_ground },
{ map_extra_mx_point_burned_ground, mx_point_burned_ground },
{ map_extra_mx_casings, mx_casings },
Expand Down

0 comments on commit 8bd4c5d

Please sign in to comment.