Skip to content

Commit

Permalink
Merge pull request #35627 from ralreegorganon/region-terrain-types
Browse files Browse the repository at this point in the history
Add regional terrain/furniture resolution to mapgen
  • Loading branch information
ZhilkinSerg authored Nov 22, 2019
2 parents 287240a + d3adb53 commit c8611b4
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 25 deletions.
13 changes: 13 additions & 0 deletions data/json/furniture_and_terrain/furniture-regional-pseudo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"type": "furniture",
"id": "f_region_flower",
"name": "this should never actually show up, it's a pseudo furniture",
"description": "this should never actually show up, it's a pseudo furniture",
"symbol": " ",
"color": "black",
"move_cost_mod": 0,
"required_str": 0,
"flags": [ "TRANSPARENT", "NOITEM" ]
}
]
32 changes: 32 additions & 0 deletions data/json/furniture_and_terrain/terrain-regional-pseudo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"type": "terrain",
"id": "t_region_groundcover",
"name": "this should never actually show up, it's a pseudo terrain",
"description": "this should never actually show up, it's a pseudo terrain",
"symbol": " ",
"color": "black",
"move_cost": 0,
"flags": [ "TRANSPARENT", "NOITEM" ]
},
{
"type": "terrain",
"id": "t_region_tree",
"name": "this should never actually show up, it's a pseudo terrain",
"description": "this should never actually show up, it's a pseudo terrain",
"symbol": " ",
"color": "black",
"move_cost": 0,
"flags": [ "TRANSPARENT", "NOITEM" ]
},
{
"type": "terrain",
"id": "t_region_shrub",
"name": "this should never actually show up, it's a pseudo terrain",
"description": "this should never actually show up, it's a pseudo terrain",
"symbol": " ",
"color": "black",
"move_cost": 0,
"flags": [ "TRANSPARENT", "NOITEM" ]
}
]
33 changes: 22 additions & 11 deletions data/json/mapgen/trailhead.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@
":": "t_window_bars",
"c": "t_woodchips",
"W": "t_water_pump",
"T": "t_floor"
"T": "t_floor",
"7": [ "t_region_tree", "t_region_shrub" ],
"f": "t_dirt"
},
"furniture": {
"b": "f_boulder_small",
"s": "f_sign",
"B": "f_bench",
"=": "f_bench",
"w": "f_woodstove",
",": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ],
";": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ],
".": [ [ "f_region_flower", 1 ], [ "f_null", 100 ] ]
},
"furniture": { "b": "f_boulder_small", "s": "f_sign", "B": "f_bench", "=": "f_bench", "w": "f_woodstove" },
"toilets": { "T": { } }
},
{
Expand Down Expand Up @@ -54,8 +65,8 @@
";;;.. ;;;;;",
";;;;. ;;;;;",
";;;;; ;;;;;",
";;;;;tttt tttt;;;;;",
";;;;;b..b ss b..b;;;;;"
";77;;tttt tttt;;;;;",
"7777;b..b ss b..b;;;;;"
],
"palettes": [ "trailhead" ],
"place_vehicles": [
Expand Down Expand Up @@ -91,11 +102,11 @@
";;;... ...;;",
";;... |-|;;",
";;... . . . +T|;;",
";;;.. . |-|;;",
";;;;. . . . +T|;;",
";;;.. . |-|;7",
";;;;. . . . +T|;7",
";;;;; ;|-|;;",
";;;;;==== sss;;;;;;",
";;;;;;;;; ;;;;;;;;;"
";;;;;==== sss;;;;;7",
";;;;77;77 ;;;;;;;7;"
],
"palettes": [ "trailhead" ],
"place_vehicles": [ { "chance": 100, "fuel": 0, "rotation": 0, "status": 1, "vehicle": "campground_vehicles", "x": 17, "y": 9 } ],
Expand Down Expand Up @@ -136,7 +147,7 @@
";;;;. . . . ;;;;;",
";;;;; ;;;;;",
";;;;;tttt tttt;;;;;",
";;;;;b..b s s b..b;;;;;"
";;7;;b..b s s b..b;;7;;"
],
"palettes": [ "trailhead" ],
"place_vehicles": [
Expand Down Expand Up @@ -175,8 +186,8 @@
";;;c|B###+ ..;;;;;;;b",
";;;c|BB#w|s ..;;;;;;;;",
";;;c|--:-| ;;;;;;;;;",
";;;ccccccc ;;;;;;b;;",
";;;b;b;b; ;;b;;;;;;"
";7;ccccccc ;;;;;;b;;",
";;;b;b;b; ;;b;;;;7;"
],
"palettes": [ "trailhead" ],
"place_items": [ { "item": "camping", "x": [ 5, 5 ], "y": [ 18, 20 ], "chance": 70 } ],
Expand Down
62 changes: 61 additions & 1 deletion data/json/regional_map_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,67 @@
"type": "region_settings",
"id": "default",
"default_oter": "field",
"default_groundcover": [ [ "t_grass", 4 ], [ "t_grass_long", 2 ], [ "t_dirt", 1 ] ],
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
"region_terrain_and_furniture": {
"terrain": {
"t_region_groundcover": { "t_grass": 4, "t_grass_long": 2, "t_dirt": 1 },
"t_region_shrub": {
"t_underbrush": 30,
"t_shrub": 5,
"t_shrub_blueberry": 1,
"t_shrub_strawberry": 1,
"t_shrub_blackberry": 1,
"t_shrub_raspberry": 1,
"t_shrub_huckleberry": 1,
"t_shrub_grape": 1,
"t_shrub_rose": 1,
"t_shrub_hydrangea": 1,
"t_shrub_lilac": 1
},
"t_region_tree": {
"t_tree": 128,
"t_tree_young": 128,
"t_tree_birch": 16,
"t_tree_elm": 16,
"t_tree_cottonwood": 16,
"t_tree_pine": 32,
"t_tree_maple": 32,
"t_tree_willow": 32,
"t_tree_hickory": 16,
"t_tree_walnut": 8,
"t_tree_chestnut": 8,
"t_tree_hazelnut": 2,
"t_tree_beech": 2,
"t_tree_blackjack": 8,
"t_tree_coffee": 2,
"t_tree_apple": 2,
"t_tree_apricot": 2,
"t_tree_cherry": 2,
"t_tree_juniper": 2,
"t_tree_peach": 2,
"t_tree_pear": 2,
"t_tree_plum": 2,
"t_tree_elderberry": 2,
"t_tree_mulberry": 2,
"t_tree_deadpine": 16,
"t_tree_hickory_dead": 16,
"t_tree_dead": 16
}
},
"furniture": {
"f_region_flower": {
"f_black_eyed_susan": 1,
"f_lily": 1,
"f_flower_tulip": 1,
"f_flower_spurge": 1,
"f_chamomile": 1,
"f_dandelion": 1,
"f_datura": 1,
"f_dahlia": 1,
"f_bluebell": 1
}
}
},
"river_scale": 1.0,
"field_coverage": {
"percent_coverage": 0.9333,
Expand Down
10 changes: 9 additions & 1 deletion data/json/test_regions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"type": "region_settings",
"id": "desert_test",
"default_oter": "field",
"default_groundcover": [ [ "t_searth_test", 3 ], [ "t_sand", 1 ] ],
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
"region_terrain_and_furniture": {
"terrain": {
"t_region_groundcover": { "t_searth_test": 3, "t_sand": 1 },
"t_region_shrub": { "t_shrub": 1 },
"t_region_tree": { "t_tree_willow": 1, "t_tree_dead": 1 }
},
"furniture": { "f_region_flower": { "f_mutcactus_test": 1 } }
},
"field_coverage": {
"percent_coverage": 1.9333,
"default_ter": "t_sand",
Expand Down
10 changes: 9 additions & 1 deletion data/mods/desert_region/desert_regional_map_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"type": "region_settings",
"id": "default",
"default_oter": "desert",
"default_groundcover": [ [ "t_searth_test", 4 ], [ "t_sand", 1 ] ],
"default_groundcover": [ [ "t_region_groundcover", 1 ] ],
"region_terrain_and_furniture": {
"terrain": {
"t_region_groundcover": { "t_searth_test": 4, "t_sand": 1 },
"t_region_shrub": { "t_shrub": 1 },
"t_region_tree": { "t_tree_willow": 1, "t_tree_dead": 1 }
},
"furniture": { "f_region_flower": { "f_mutcactus_test": 1 } }
},
"river_scale": 0.0,
"field_coverage": {
"percent_coverage": 0.1333,
Expand Down
66 changes: 55 additions & 11 deletions doc/REGION_SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ The **region_settings** define the attributes for map generation that apply to a
The general settings define the default overmap terrain and ground cover. Additional sections are
as follows:

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

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

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

## Region Terrain / Furniture

The **region_terrain_and_furniture** section defines the resolution of regional terrain/furniture
to their actual terrain and furniture types for the region, with a weighted list for
terrain/furniture entry that defines the relative weight of a given entry when mapgen resolves the
regional entry to an actual entry.

### Fields

| Identifier | Description |
| ----------- | ------------------------------------------------------------------ |
| `terrain` | List of regional terrain and their corresponding weighted lists. |
| `furniture` | List of regional furniture and their corresponding weighted lists. |

### Example
```json
{
"region_terrain_and_furniture": {
"terrain": {
"t_region_groundcover": {
"t_grass": 4,
"t_grass_long": 2,
"t_dirt": 1
}
},
"furniture": {
"f_region_flower": {
"f_black_eyed_susan": 1,
"f_lily": 1,
"f_flower_tulip": 1,
"f_flower_spurge": 1,
"f_chamomile": 1,
"f_dandelion": 1,
"f_datura": 1,
"f_dahlia": 1,
"f_bluebell": 1
}
}
}
}
```


## Field Coverage

The **field_coverage** section defines the furniture and terrain that make up the flora that
Expand Down
8 changes: 8 additions & 0 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,8 @@ void mapgen_function_json::generate( mapgendata &md )

objects.apply( md, point_zero );

resolve_regional_terrain_and_furniture( md );

m->rotate( rotation.get() );

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

objects.apply( dat, offset );

resolve_regional_terrain_and_furniture( dat );
}

/*
Expand Down Expand Up @@ -6263,6 +6267,8 @@ void map::draw_connections( mapgendata &dat )
}
}
}

resolve_regional_terrain_and_furniture( dat );
}

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

resolve_regional_terrain_and_furniture( md );

return true;
}

Expand Down
16 changes: 16 additions & 0 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4608,3 +4608,19 @@ void place_stairs( mapgendata &dat )
}
}
}

void resolve_regional_terrain_and_furniture( const mapgendata &dat )
{
for( const tripoint &p : dat.m.points_on_zlevel() ) {
const ter_id tid_before = dat.m.ter( p );
const ter_id tid_after = dat.region.region_terrain_and_furniture.resolve( tid_before );
if( tid_after != tid_before ) {
dat.m.ter_set( p, tid_after );
}
const furn_id fid_before = dat.m.furn( p );
const furn_id fid_after = dat.region.region_terrain_and_furniture.resolve( fid_before );
if( fid_after != fid_before ) {
dat.m.furn_set( p, fid_after );
}
}
}
3 changes: 3 additions & 0 deletions src/mapgen_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint
bool run_mapgen_func( const std::string &mapgen_id, mapgendata &dat );
std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_update(
const std::string &update_mapgen_id );

void resolve_regional_terrain_and_furniture( const mapgendata &dat );

#endif
Loading

0 comments on commit c8611b4

Please sign in to comment.