Skip to content

Commit

Permalink
Unhardcode dead vegetation extras (CleverRaven#73022)
Browse files Browse the repository at this point in the history
* Unhardcode mx_dead_vegetation and mx_point_dead_vegetation

* Update map_extras.cpp
  • Loading branch information
Procyonae authored Apr 15, 2024
1 parent 065774f commit 316fd4b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 47 deletions.
5 changes: 5 additions & 0 deletions data/json/itemgroups/trash_and_debris.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@
[ "bag_body_bag", 1 ]
]
},
{
"type": "item_group",
"id": "dead_vegetation",
"items": [ { "item": "twig", "prob": 15, "count": [ 5, 20 ] }, [ "withered", 60 ], [ "stick_long", 15 ], [ "stick", 30 ] ]
},
{
"type": "item_group",
"id": "trash",
Expand Down
96 changes: 96 additions & 0 deletions data/json/mapgen/map_extras/dead_vegetation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[
{
"type": "mapgen",
"method": "json",
"update_mapgen_id": "mx_dead_vegetation",
"object": {
"place_nested": [
{ "chunks": [ "15x15_dead_vegetation" ], "x": [ 4, 5 ], "y": [ 4, 5 ] },
{ "chunks": [ "15x15_dead_vegetation" ], "x": [ 0, 4 ], "y": [ 0, 9 ] },
{ "chunks": [ "15x15_dead_vegetation" ], "x": [ 5, 9 ], "y": [ 0, 9 ] },
{ "chunks": [ "15x15_dead_vegetation" ], "x": [ 0, 9 ], "y": [ 0, 4 ] },
{ "chunks": [ "15x15_dead_vegetation" ], "x": [ 0, 9 ], "y": [ 5, 9 ] }
]
}
},
{
"type": "mapgen",
"method": "json",
"update_mapgen_id": "mx_point_dead_vegetation",
"object": { "place_nested": [ { "chunks": [ "15x15_dead_vegetation" ], "x": [ 0, 9 ], "y": [ 0, 9 ] } ] }
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "15x15_dead_vegetation",
"object": {
"mapgensize": [ 15, 15 ],
"place_nested": [
{ "chunks": [ "7x7_dead_vegetation" ], "x": [ 0, 8 ], "y": [ 0, 8 ] },
{ "chunks": [ "7x7_dead_vegetation" ], "x": [ 0, 8 ], "y": [ 0, 8 ] },
{ "chunks": [ "7x7_dead_vegetation" ], "x": [ 0, 8 ], "y": [ 0, 8 ] }
]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "7x7_dead_vegetation",
"object": {
"mapgensize": [ 7, 7 ],
"rows": [
" xxx ",
" xXXXx ",
"xXXXXXx",
"xXXXXXx",
"xXXXXXx",
" xXXXx ",
" xxx "
],
"nested": { "X": { "chunks": [ "1x1_dead_vegetation" ] }, "x": { "chunks": [ "1x1_dead_vegetation", "null" ] } }
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "1x1_dead_vegetation",
"object": {
"mapgensize": [ 1, 1 ],
"ter_furn_transforms": { " ": { "transform": "dead_vegetation" } },
"place_items": [ { "item": "dead_vegetation", "x": 0, "y": 0, "chance": 1 } ]
}
},
{
"type": "ter_furn_transform",
"id": "dead_vegetation",
"//": "Ideally place withered plant item somehow",
"furniture": [
{
"result": "f_null",
"valid_flags": [ "PLANT", "FLOWER", "ORGANIC" ],
"//": "Ideally place a withered plant, for now we just place items randomly"
}
],
"terrain": [
{
"result": "t_grass_dead",
"valid_terrain": [ "t_grass", "t_grass_long", "t_grass_tall", "t_grass_golf", "t_grass_white", "t_moss", "t_forestfloor" ]
},
{ "result": "t_tree_deadpine", "valid_terrain": [ "t_tree_pine" ] },
{ "result": "t_tree_birch_harvested", "valid_terrain": [ "t_tree_birch" ] },
{ "result": "t_tree_dead", "valid_terrain": [ "t_tree_willow" ] },
{ "result": "t_tree_hickory_dead", "valid_terrain": [ "t_tree_hickory", "t_tree_hickory_harvested" ] },
{
"result": "t_dirt",
"valid_flags": [ "SHRUB" ],
"//": "Ideally place sticks half the time, for now we just place items randomly"
},
{
"result": "t_dirt",
"valid_flags": [ "YOUNG" ],
"//": "Ideally place a long stick half the time, for now we just place items randomly"
},
{ "result": [ [ "t_tree_dead", 9 ], [ "t_trunk", 4 ], [ "t_stump", 3 ] ], "valid_flags": [ "TREE" ] }
]
}
]
4 changes: 2 additions & 2 deletions data/json/overmap/map_extras.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
"type": "map_extra",
"name": { "str": "Dead Vegetation" },
"description": "Dead vegetation is here.",
"generator": { "generator_method": "map_extra_function", "generator_id": "mx_dead_vegetation" },
"generator": { "generator_method": "update_mapgen", "generator_id": "mx_dead_vegetation" },
"min_max_zlevel": [ 0, 0 ],
"sym": ".",
"color": "brown",
Expand All @@ -457,7 +457,7 @@
"type": "map_extra",
"name": { "str": "Dead Vegetation (Point)" },
"description": "Dead vegetation is here.",
"generator": { "generator_method": "map_extra_function", "generator_id": "mx_point_dead_vegetation" },
"generator": { "generator_method": "update_mapgen", "generator_id": "mx_point_dead_vegetation" },
"min_max_zlevel": [ 0, 0 ],
"sym": ".",
"color": "brown",
Expand Down
45 changes: 0 additions & 45 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ 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_dead_vegetation( "mx_dead_vegetation" );
static const map_extra_id map_extra_mx_fungal_zone( "mx_fungal_zone" );
static const map_extra_id map_extra_mx_grove( "mx_grove" );
static const map_extra_id map_extra_mx_helicopter( "mx_helicopter" );
Expand All @@ -130,7 +129,6 @@ static const map_extra_id map_extra_mx_looters( "mx_looters" );
static const map_extra_id map_extra_mx_minefield( "mx_minefield" );
static const map_extra_id map_extra_mx_null( "mx_null" );
static const map_extra_id map_extra_mx_point_burned_ground( "mx_point_burned_ground" );
static const map_extra_id map_extra_mx_point_dead_vegetation( "mx_point_dead_vegetation" );
static const map_extra_id map_extra_mx_pond( "mx_pond" );
static const map_extra_id map_extra_mx_portal_in( "mx_portal_in" );
static const map_extra_id map_extra_mx_reed( "mx_reed" );
Expand Down Expand Up @@ -1319,47 +1317,6 @@ static bool mx_clay_deposit( map &m, const tripoint &abs_sub )
return false;
}

static bool mx_dead_vegetation( map &m, const tripoint &abs_sub )
{
// This map extra kills all plant life, creating area of desolation.
// Possible result of acid rain / radiation / etc.,
// but reason is not exposed (no rads, acid pools, etc.)

for( int i = 0; i < SEEX * 2; i++ ) {
for( int j = 0; j < SEEY * 2; j++ ) {
const tripoint loc( i, j, abs_sub.z );

dead_vegetation_parser( m, loc );
}
}

return true;
}

static bool mx_point_dead_vegetation( map &m, const tripoint &abs_sub )
{
// This map extra creates patch of dead vegetation using a simple cellular automaton.
// Lesser version of mx_dead_vegetation

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

// Generate the cells for dead vegetation.
std::vector<std::vector<int>> current = CellularAutomata::generate_cellular_automaton( width,
height, 55, 5, 4, 3 );

for( int i = 0; i < width; i++ ) {
for( int j = 0; j < height; j++ ) {
if( current[i][j] == 1 ) {
const tripoint loc( i, j, abs_sub.z );
dead_vegetation_parser( m, loc );
}
}
}

return true;
}

static void burned_ground_parser( map &m, const tripoint &loc )
{
const furn_t &fid = m.furn( loc ).obj();
Expand Down Expand Up @@ -2199,8 +2156,6 @@ static FunctionMap builtin_functions = {
{ map_extra_mx_shrubbery, mx_shrubbery },
{ map_extra_mx_pond, mx_pond },
{ map_extra_mx_clay_deposit, mx_clay_deposit },
{ map_extra_mx_dead_vegetation, mx_dead_vegetation },
{ map_extra_mx_point_dead_vegetation, mx_point_dead_vegetation },
{ 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 316fd4b

Please sign in to comment.