Skip to content

Commit d3adb53

Browse files
Add regional terrain/furniture resolution to mapgen
Adds functionality to the regional map settings and mapgen so that regional terrains like a "t_region_shrub" can be used in JSON mapgen to denote regional appropriate terrain/furniture should be used, and the actual weighted list of valid terrain/furniture can be defined in the region settings and resolved from the regional "pseudo terrain" to an actual terrain/furniture during mapgen.
1 parent 14e05ae commit d3adb53

12 files changed

+374
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"type": "furniture",
4+
"id": "f_region_flower",
5+
"name": "this should never actually show up, it's a pseudo furniture",
6+
"description": "this should never actually show up, it's a pseudo furniture",
7+
"symbol": " ",
8+
"color": "black",
9+
"move_cost_mod": 0,
10+
"required_str": 0,
11+
"flags": [ "TRANSPARENT", "NOITEM" ]
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"type": "terrain",
4+
"id": "t_region_groundcover",
5+
"name": "this should never actually show up, it's a pseudo terrain",
6+
"description": "this should never actually show up, it's a pseudo terrain",
7+
"symbol": " ",
8+
"color": "black",
9+
"move_cost": 0,
10+
"flags": [ "TRANSPARENT", "NOITEM" ]
11+
},
12+
{
13+
"type": "terrain",
14+
"id": "t_region_tree",
15+
"name": "this should never actually show up, it's a pseudo terrain",
16+
"description": "this should never actually show up, it's a pseudo terrain",
17+
"symbol": " ",
18+
"color": "black",
19+
"move_cost": 0,
20+
"flags": [ "TRANSPARENT", "NOITEM" ]
21+
},
22+
{
23+
"type": "terrain",
24+
"id": "t_region_shrub",
25+
"name": "this should never actually show up, it's a pseudo terrain",
26+
"description": "this should never actually show up, it's a pseudo terrain",
27+
"symbol": " ",
28+
"color": "black",
29+
"move_cost": 0,
30+
"flags": [ "TRANSPARENT", "NOITEM" ]
31+
}
32+
]

data/json/mapgen/trailhead.json

+22-11
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@
2020
":": "t_window_bars",
2121
"c": "t_woodchips",
2222
"W": "t_water_pump",
23-
"T": "t_floor"
23+
"T": "t_floor",
24+
"7": [ "t_region_tree", "t_region_shrub" ],
25+
"f": "t_dirt"
26+
},
27+
"furniture": {
28+
"b": "f_boulder_small",
29+
"s": "f_sign",
30+
"B": "f_bench",
31+
"=": "f_bench",
32+
"w": "f_woodstove",
33+
",": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ],
34+
";": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ],
35+
".": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ]
2436
},
25-
"furniture": { "b": "f_boulder_small", "s": "f_sign", "B": "f_bench", "=": "f_bench", "w": "f_woodstove" },
2637
"toilets": { "T": { } }
2738
},
2839
{
@@ -54,8 +65,8 @@
5465
";;;.. ;;;;;",
5566
";;;;. ;;;;;",
5667
";;;;; ;;;;;",
57-
";;;;;tttt tttt;;;;;",
58-
";;;;;b..b ss b..b;;;;;"
68+
";77;;tttt tttt;;;;;",
69+
"7777;b..b ss b..b;;;;;"
5970
],
6071
"palettes": [ "trailhead" ],
6172
"place_vehicles": [
@@ -91,11 +102,11 @@
91102
";;;... ...;;",
92103
";;... |-|;;",
93104
";;... . . . +T|;;",
94-
";;;.. . |-|;;",
95-
";;;;. . . . +T|;;",
105+
";;;.. . |-|;7",
106+
";;;;. . . . +T|;7",
96107
";;;;; ;|-|;;",
97-
";;;;;==== sss;;;;;;",
98-
";;;;;;;;; ;;;;;;;;;"
108+
";;;;;==== sss;;;;;7",
109+
";;;;77;77 ;;;;;;;7;"
99110
],
100111
"palettes": [ "trailhead" ],
101112
"place_vehicles": [ { "chance": 100, "fuel": 0, "rotation": 0, "status": 1, "vehicle": "campground_vehicles", "x": 17, "y": 9 } ],
@@ -136,7 +147,7 @@
136147
";;;;. . . . ;;;;;",
137148
";;;;; ;;;;;",
138149
";;;;;tttt tttt;;;;;",
139-
";;;;;b..b s s b..b;;;;;"
150+
";;7;;b..b s s b..b;;7;;"
140151
],
141152
"palettes": [ "trailhead" ],
142153
"place_vehicles": [
@@ -175,8 +186,8 @@
175186
";;;c|B###+ ..;;;;;;;b",
176187
";;;c|BB#w|s ..;;;;;;;;",
177188
";;;c|--:-| ;;;;;;;;;",
178-
";;;ccccccc ;;;;;;b;;",
179-
";;;b;b;b; ;;b;;;;;;"
189+
";7;ccccccc ;;;;;;b;;",
190+
";;;b;b;b; ;;b;;;;7;"
180191
],
181192
"palettes": [ "trailhead" ],
182193
"place_items": [ { "item": "camping", "x": [ 5, 5 ], "y": [ 18, 20 ], "chance": 70 } ],

data/json/regional_map_settings.json

+61-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,67 @@
33
"type": "region_settings",
44
"id": "default",
55
"default_oter": "field",
6-
"default_groundcover": [ [ "t_grass", 4 ], [ "t_grass_long", 2 ], [ "t_dirt", 1 ] ],
6+
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
7+
"region_terrain_and_furniture": {
8+
"terrain": {
9+
"t_region_groundcover": { "t_grass": 4, "t_grass_long": 2, "t_dirt": 1 },
10+
"t_region_shrub": {
11+
"t_underbrush": 30,
12+
"t_shrub": 5,
13+
"t_shrub_blueberry": 1,
14+
"t_shrub_strawberry": 1,
15+
"t_shrub_blackberry": 1,
16+
"t_shrub_raspberry": 1,
17+
"t_shrub_huckleberry": 1,
18+
"t_shrub_grape": 1,
19+
"t_shrub_rose": 1,
20+
"t_shrub_hydrangea": 1,
21+
"t_shrub_lilac": 1
22+
},
23+
"t_region_tree": {
24+
"t_tree": 128,
25+
"t_tree_young": 128,
26+
"t_tree_birch": 16,
27+
"t_tree_elm": 16,
28+
"t_tree_cottonwood": 16,
29+
"t_tree_pine": 32,
30+
"t_tree_maple": 32,
31+
"t_tree_willow": 32,
32+
"t_tree_hickory": 16,
33+
"t_tree_walnut": 8,
34+
"t_tree_chestnut": 8,
35+
"t_tree_hazelnut": 2,
36+
"t_tree_beech": 2,
37+
"t_tree_blackjack": 8,
38+
"t_tree_coffee": 2,
39+
"t_tree_apple": 2,
40+
"t_tree_apricot": 2,
41+
"t_tree_cherry": 2,
42+
"t_tree_juniper": 2,
43+
"t_tree_peach": 2,
44+
"t_tree_pear": 2,
45+
"t_tree_plum": 2,
46+
"t_tree_elderberry": 2,
47+
"t_tree_mulberry": 2,
48+
"t_tree_deadpine": 16,
49+
"t_tree_hickory_dead": 16,
50+
"t_tree_dead": 16
51+
}
52+
},
53+
"furniture": {
54+
"f_region_flower": {
55+
"f_black_eyed_susan": 1,
56+
"f_lily": 1,
57+
"f_flower_tulip": 1,
58+
"f_flower_spurge": 1,
59+
"f_chamomile": 1,
60+
"f_dandelion": 1,
61+
"f_datura": 1,
62+
"f_dahlia": 1,
63+
"f_bluebell": 1
64+
}
65+
}
66+
},
767
"river_scale": 1.0,
868
"field_coverage": {
969
"percent_coverage": 0.9333,

data/json/test_regions.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
"type": "region_settings",
44
"id": "desert_test",
55
"default_oter": "field",
6-
"default_groundcover": [ [ "t_searth_test", 3 ], [ "t_sand", 1 ] ],
6+
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
7+
"region_terrain_and_furniture": {
8+
"terrain": {
9+
"t_region_groundcover": { "t_searth_test": 3, "t_sand": 1 },
10+
"t_region_shrub": { "t_shrub": 1 },
11+
"t_region_tree": { "t_tree_willow": 1, "t_tree_dead": 1 }
12+
},
13+
"furniture": { "f_region_flower": { "f_mutcactus_test": 1 } }
14+
},
715
"field_coverage": {
816
"percent_coverage": 1.9333,
917
"default_ter": "t_sand",

data/mods/desert_region/desert_regional_map_settings.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
"type": "region_settings",
44
"id": "default",
55
"default_oter": "desert",
6-
"default_groundcover": [ [ "t_searth_test", 4 ], [ "t_sand", 1 ] ],
6+
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
7+
"region_terrain_and_furniture": {
8+
"terrain": {
9+
"t_region_groundcover": { "t_searth_test": 4, "t_sand": 1 },
10+
"t_region_shrub": { "t_shrub": 1 },
11+
"t_region_tree": { "t_tree_willow": 1, "t_tree_dead": 1 }
12+
},
13+
"furniture": { "f_region_flower": { "f_mutcactus_test": 1 } }
14+
},
715
"river_scale": 0.0,
816
"field_coverage": {
917
"percent_coverage": 0.1333,

doc/REGION_SETTINGS.md

+55-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ The **region_settings** define the attributes for map generation that apply to a
44
The general settings define the default overmap terrain and ground cover. Additional sections are
55
as follows:
66

7-
| Section | Description |
8-
| ------------------------------- | ------------------------------------------------------------------- |
9-
| `field_coverage` | Defines the flora that cover the `field` overmap terrain. |
10-
| `overmap_lake_settings` | Defines parameters for generating lakes in the region. |
11-
| `overmap_forest_settings` | Defines parameters for generating forests and swamps in the region. |
12-
| `forest_mapgen_settings` | Defines flora (and "stuff") that cover the `forest` terrain types. |
13-
| `forest_trail_settings` | Defines the overmap and local structure of forest trails. |
14-
| `city` | Defines the structural compositions of cities. |
15-
| `map_extras` | Defines the map extra groups referenced by overmap terrains. |
16-
| `weather` | Defines the base weather attributes for the region. |
17-
| `overmap_feature_flag_settings` | Defines operations on overmap features based on their flags. |
7+
| Section | Description |
8+
| ------------------------------- | --------------------------------------------------------------------- |
9+
| `region_terrain_and_furniture` | Defines the resolution of regional terrain/furniture to actual types. |
10+
| `field_coverage` | Defines the flora that cover the `field` overmap terrain. |
11+
| `overmap_lake_settings` | Defines parameters for generating lakes in the region. |
12+
| `overmap_forest_settings` | Defines parameters for generating forests and swamps in the region. |
13+
| `forest_mapgen_settings` | Defines flora (and "stuff") that cover the `forest` terrain types. |
14+
| `forest_trail_settings` | Defines the overmap and local structure of forest trails. |
15+
| `city` | Defines the structural compositions of cities. |
16+
| `map_extras` | Defines the map extra groups referenced by overmap terrains. |
17+
| `weather` | Defines the base weather attributes for the region. |
18+
| `overmap_feature_flag_settings` | Defines operations on overmap features based on their flags. |
1819

1920
Note that for the default region, all attributes and sections are required.
2021

@@ -41,6 +42,49 @@ Note that for the default region, all attributes and sections are required.
4142
}
4243
```
4344

45+
## Region Terrain / Furniture
46+
47+
The **region_terrain_and_furniture** section defines the resolution of regional terrain/furniture
48+
to their actual terrain and furniture types for the region, with a weighted list for
49+
terrain/furniture entry that defines the relative weight of a given entry when mapgen resolves the
50+
regional entry to an actual entry.
51+
52+
### Fields
53+
54+
| Identifier | Description |
55+
| ----------- | ------------------------------------------------------------------ |
56+
| `terrain` | List of regional terrain and their corresponding weighted lists. |
57+
| `furniture` | List of regional furniture and their corresponding weighted lists. |
58+
59+
### Example
60+
```json
61+
{
62+
"region_terrain_and_furniture": {
63+
"terrain": {
64+
"t_region_groundcover": {
65+
"t_grass": 4,
66+
"t_grass_long": 2,
67+
"t_dirt": 1
68+
}
69+
},
70+
"furniture": {
71+
"f_region_flower": {
72+
"f_black_eyed_susan": 1,
73+
"f_lily": 1,
74+
"f_flower_tulip": 1,
75+
"f_flower_spurge": 1,
76+
"f_chamomile": 1,
77+
"f_dandelion": 1,
78+
"f_datura": 1,
79+
"f_dahlia": 1,
80+
"f_bluebell": 1
81+
}
82+
}
83+
}
84+
}
85+
```
86+
87+
4488
## Field Coverage
4589

4690
The **field_coverage** section defines the furniture and terrain that make up the flora that

src/mapgen.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,8 @@ void mapgen_function_json::generate( mapgendata &md )
25992599

26002600
objects.apply( md, point_zero );
26012601

2602+
resolve_regional_terrain_and_furniture( md );
2603+
26022604
m->rotate( rotation.get() );
26032605

26042606
if( md.terrain_type()->is_rotatable() ) {
@@ -2620,6 +2622,8 @@ void mapgen_function_json_nested::nest( mapgendata &dat, const point &offset ) c
26202622
}
26212623

26222624
objects.apply( dat, offset );
2625+
2626+
resolve_regional_terrain_and_furniture( dat );
26232627
}
26242628

26252629
/*
@@ -6263,6 +6267,8 @@ void map::draw_connections( mapgendata &dat )
62636267
}
62646268
}
62656269
}
6270+
6271+
resolve_regional_terrain_and_furniture( dat );
62666272
}
62676273

62686274
void map::place_spawns( const mongroup_id &group, const int chance,
@@ -7754,6 +7760,8 @@ bool update_mapgen_function_json::update_map( mapgendata &md, const point &offse
77547760
}
77557761
objects.apply( md, offset );
77567762

7763+
resolve_regional_terrain_and_furniture( md );
7764+
77577765
return true;
77587766
}
77597767

src/mapgen_functions.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -4608,3 +4608,19 @@ void place_stairs( mapgendata &dat )
46084608
}
46094609
}
46104610
}
4611+
4612+
void resolve_regional_terrain_and_furniture( const mapgendata &dat )
4613+
{
4614+
for( const tripoint &p : dat.m.points_on_zlevel() ) {
4615+
const ter_id tid_before = dat.m.ter( p );
4616+
const ter_id tid_after = dat.region.region_terrain_and_furniture.resolve( tid_before );
4617+
if( tid_after != tid_before ) {
4618+
dat.m.ter_set( p, tid_after );
4619+
}
4620+
const furn_id fid_before = dat.m.furn( p );
4621+
const furn_id fid_after = dat.region.region_terrain_and_furniture.resolve( fid_before );
4622+
if( fid_after != fid_before ) {
4623+
dat.m.furn_set( p, fid_after );
4624+
}
4625+
}
4626+
}

src/mapgen_functions.h

+3
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,7 @@ bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint
9999
bool run_mapgen_func( const std::string &mapgen_id, mapgendata &dat );
100100
std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_update(
101101
const std::string &update_mapgen_id );
102+
103+
void resolve_regional_terrain_and_furniture( const mapgendata &dat );
104+
102105
#endif

0 commit comments

Comments
 (0)