Skip to content

Commit

Permalink
Merge pull request #74169 from PatrikLundell/3D_mapgen
Browse files Browse the repository at this point in the history
3D mapgen
  • Loading branch information
Maleclypse authored Jun 19, 2024
2 parents b67ff6c + 86a14f6 commit f5f9556
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 269 deletions.
86 changes: 60 additions & 26 deletions data/json/mapgen/bugs/nest_dermatik.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
[
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "nest_dermatik_paper_roof",
"object": { "mapgensize": [ 1, 1 ], "rows": [ "#" ], "terrain": { "#": "t_roof_paper" } }
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "nest_dermatik_paper_wall",
"object": {
"mapgensize": [ 1, 1 ],
"rows": [ "#" ],
"terrain": { "#": "t_paper" },
"place_nested": [ { "chunks": [ "nest_dermatik_paper_roof" ], "x": 0, "y": 0, "z": 1 } ]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "nest_dermatik_dirt_roof",
"object": { "mapgensize": [ 1, 1 ], "rows": [ "#" ], "terrain": { "#": "t_dirt" } }
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "nest_dermatik_dirt_wall",
"object": {
"mapgensize": [ 1, 1 ],
"rows": [ "#" ],
"terrain": { "#": "t_wall_dirt" },
"place_nested": [ { "chunks": [ "nest_dermatik_dirt_roof" ], "x": 0, "y": 0, "z": 1 } ]
}
},
{
"type": "mapgen",
"method": "json",
Expand Down Expand Up @@ -35,7 +69,6 @@
"t": [ "t_region_tree", "t_region_groundcover" ],
",": [ "t_region_tree" ],
"-": [ "t_wall_dirt" ],
"#": [ [ "t_paper", 3 ], "t_wall_dirt" ],
".": [ "t_mud_underground", [ "t_floor_paper", 2 ] ],
"0": [ "t_pit_shallow" ]
},
Expand All @@ -48,7 +81,8 @@
{ "monster": "mon_dermatik_larva", "x": [ 3, 22 ], "y": [ 8, 22 ], "repeat": [ 2, 4 ] },
{ "monster": "mon_dermatik_midwife", "x": [ 10, 12 ], "y": [ 14, 17 ], "repeat": [ 0, 2 ] },
{ "monster": "mon_dermatik", "x": [ 0, 23 ], "y": [ 0, 23 ], "repeat": [ 1, 4 ] }
]
],
"nested": { "#": { "chunks": [ [ "nest_dermatik_paper_wall", 3 ], [ "nest_dermatik_dirt_wall", 1 ] ] } }
}
},
{
Expand All @@ -59,31 +93,31 @@
"fill_ter": "t_open_air",
"rows": [
" ",
" ",
" ,, ",
" ,,,,,,,,, ",
" ,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,,,,,,,, ",
" ,,,,,,,,,,,, ",
" ,,, , ",
" "
" - ",
" - ---- ",
" ---...-..--- ",
" --.--..-...--- - ",
" -... .- ...------ ",
" -- . . ..-..--- ",
" --- ....- . ..-- ",
" - .. ..... .--- ",
" - .. .. .... --.- ",
" -- . .... ..-- ",
" --... . ..... ...-- ",
" -- . . ....... ..--- ",
" -- ...... . .-- ",
" -... ........ ...- ",
" - ... ......... .-- ",
" --. ......... .--- ",
" -- ....... . ..-- ",
"--.... .. . . ... ...- ",
" - . ......-- ",
" ------... .......-- ",
" ---- ... -.----- ",
" ---------- - ",
" --- -- "
],
"terrain": { ",": [ "t_roof_paper" ] }
"terrain": { "-": [ "t_dirt" ], ".": [ "t_roof_paper" ] }
}
}
]
39 changes: 26 additions & 13 deletions doc/MAPGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ Placing things using x/y coordinates ("place_monsters", "place_loot", "place_ite
coordinates beyond 24x24. An important limitation is that ranged random coordinates (such as "x": `[ 10, 18 ]`) must not
cross the 24x24 terrain boundaries. Ranges such as `[ 0, 23 ]` and `[ 50, 70 ]` are valid, but `[ 0, 47 ]` and
`[ 15, 35 ]` are not because they extend beyond a single 24x24 block. Note that the syntax supports an optional
*relative* "z" coordinate (NOT absolute Z level, although it often would look the same as the reference is often zero),
but it is usable only for faction camp construction for the time being (mapgen separates Z levels by using different
overmap terrain identifiers instead).
*relative* "z" coordinate (NOT absolute Z level, although it often would look the same as the reference is often zero).
Usage of Z level offsets for mapgen (as opposed to later map modifications, such as faction camps) has the limitation
that mapgen flags only take effect for positive offsets (e.g. providing a roof and roof furniture for a building generated
with a probability), but not for negative ones (generating something below the current reference level). This restriction
is due to technical limitations (it's costly and messy to determine a level generation order dynamically).

Example:

Expand Down Expand Up @@ -281,6 +283,14 @@ Examples:
* The old mapgen.cpp system involved *The Biggest "if / else if / else if / .." Statement Known to Man*(tm), and is only
halfway converted to the "builtin" mapgen class. This means that while custom mapgen functions are allowed, the game
will cheerfully forget the default if one is added.
* Mapgen flags don't have any effect on "real" mapgen negative Z level offsets due to technical limitations. They work
normally for generation after mapgen (such as the addition of a camp structure, or other post generation
modifications), as well as for positive Z level offsets for the original generation of maps (e.g. adding upper
stories or roofs to buildings placed using probabilities). Negative offsets will still be applied, but any benefits
from flag directives will be lost. Instead, the overlay produced by the offset orders will be applied by merging
the overlay to the base level map generated once that level has actually been generated. It's expected that things
that need to include a Z level offset will most commonly be defining a base and what's above it, which is why that
direction has the complete support.
* TODO: Add to this list.


Expand Down Expand Up @@ -433,7 +443,10 @@ Some mapgens are intended to be layered on top of existing terrain. This can be
nested mapgen, or regular mapgen with a predecessor. When the mapgen changes an existing terrain,
the tile may already contain preexisting furniture, traps and items. The following flags provide
a mechanism for specifying the behaviour to follow in such situations. It is an error if existing
furniture, traps or items are encountered but no behaviour has been given.
furniture, traps or items are encountered but no behaviour has been given. Note that flags do NOT
affect magens on creation of a new overmap when the Z level offset is negative (i.e. something placed
at a lower Z level than the overmap level being generated) and no error reports are generated. This
is a technical limitation, not a desired feature.

A blanket policy can be set using one of these three (mutually exclusive) shorthand flags:
- `ALLOW_TERRAIN_UNDER_OTHER_DATA` retains preexisting furniture, traps and items without triggering
Expand Down Expand Up @@ -527,7 +540,7 @@ Example:
| line | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`, `"field_remove"`, `"creature_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation", "item_remove", "creature_remove", and "field_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| x, y | Start X, Y coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range. Example: `"x": 12, "y": [ 5, 15 ]`
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| x2, y2 | End X, Y coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range. Example: `"x": 22, "y": [ 15, 20 ]`
| amount | Radiation amount. Value from `0-100`.
| chance | (optional) One-in-N chance to apply
Expand All @@ -554,7 +567,7 @@ Example:
| square | Allowed values: `"terrain"`, `"furniture"`, `"trap"`, `"radiation"`, `"trap_remove"`, `"item_remove"`, `"field_remove"`, `"creature_remove"`
| id | Terrain, furniture, or trap ID. Examples: `"id": "f_counter"`, `"id": "tr_beartrap"`. Omit for "radiation", "item_remove", creature_remove, and "field_remove". For `trap_remove` if tr_null is used any traps present will be removed.
| x, y | Top-left corner of square.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| x2, y2 | Bottom-right corner of square.

## Spawn a single monster with "place_monster"
Expand All @@ -568,7 +581,7 @@ Value: `[ array of {objects} ]: [ { "monster": ... } ]`
| monster | ID of the monster to spawn.
| group | ID of the monster group from which the spawned monster is selected. `monster` and `group` should not be used together. `group` will act over `monster`.
| x, y | Spawn coordinates ( specific or area rectangle ). Value: 0-23 or `[ 0-23, 0-23 ]` - random value between `[ a, b ]`.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| chance | Percentage chance to do spawning. If repeat is used each repeat has separate chance.
| repeat | The spawning is repeated this many times. Can be a number or a range.
| pack_size | How many monsters are spawned. Can be single number or range like `[1-4]`. Is affected by the chance and spawn density. Ignored when spawning from a group.
Expand Down Expand Up @@ -649,7 +662,7 @@ Using `place_monsters` to spawn a group of monsters works in a similar fashion t
|--|--|
| monster | The ID of the monster group that you wish to spawn |
| x, y | Spawn coordinates ( specific or area rectangle ). Value: 0-23 or `[ 0-23, 0-23 ]` - random value between `[ a, b ]`.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| chance | Represents a 1 in N chance that the entire group will spawn. This is done once for each repeat. If this dice roll fails, the entire group specified will not spawn. Leave blank to guarantee spawns.
| repeat | The spawning is repeated this many times. Can be a number or a range. Again, this represents the number of times the group will be spawned.
| density | This number is multiplied by the spawn density of the world the player is in and then probabilistically rounded to determine how many times to spawn the group. This is done for each time the spawn is repeated. For instance, if the final multiplier from this calculation ends up being `2`, and the repeat value is `6`, then the group will be spawned `2 * 6` or 12 times.
Expand All @@ -660,7 +673,7 @@ Using `place_npcs` to spawn a group of npcs.
|Field|Description |
|--|--|
| x, y | Spawn coordinates ( specific or area rectangle ). Value: 0-23 or `[ 0-23, 0-23 ]` - random value between `[ a, b ]`.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| class | The class of the npc that you wish to spawn |
| add_trait | A string of array of strings for traits the npc starts with.
| unique_id | A string for the unique_id the npc has.
Expand All @@ -671,7 +684,7 @@ Using `place_variables` to set a group of variables.
|Field|Description |
|--|--|
| x, y | Spawn coordinates ( specific or area rectangle ). Value: 0-23 or `[ 0-23, 0-23 ]` - random value between `[ a, b ]`.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| name | The name of the global variable to set with the absolute coordinates of x and y.

## Spawn specific items with a "place_item" array
Expand All @@ -690,7 +703,7 @@ Example:
| --- | ---
| item | (required) ID of the item to spawn
| x, y | (required) Spawn coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| amount | (required) Number of items to spawn. Single integer, or range `[ a, b ]` for a random value in that range.
| chance | (optional) One-in-N chance to spawn item.
| repeat | (optional) Value: `[ n1, n2 ]`. Spawn item randomly between `n1` and `n2` times. Only makes sense if the coordinates are random. Example: `[ 1, 3 ]` - repeat 1-3 times.
Expand All @@ -710,7 +723,7 @@ Example:
| --- | ---
| id | (required) ID of the faction to apply ownership to.
| x, y | (required) Spawn coordinates. Value from `0-23`, or range `[ 0-23, 0-23 ]` for a random value in that range.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.

This is an array, so multiple entries can be defined.

Expand Down Expand Up @@ -1172,7 +1185,7 @@ Place_nested allows for conditional spawning of chunks based on the `"id"`s and/
| --- | ---
| chunks/else_chunks | (required, string) the nested_mapgen_id of the chunk that will be conditionally placed. Chunks are placed if the specified neighbor matches, and "else_chunks" otherwise.
| x and y | (required, int) the cardinal position in which the chunk will be placed.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported, and it can only be used for faction camps.
| z | (optional) Relative Z coordinate for placement at a different Z level than the nominal one. Value from `-20 to 20`. Also note that range is not supported.
| neighbors | (optional) Any of the neighboring overmaps that should be checked before placing the chunk. Each direction is associated with a list of overmap `"id"` substrings. See [JSON_INFO.md](JSON_INFO.md#Starting-locations) "terrain" section to do more advanced searches, note this field defaults to CONTAINS not TYPE.
| joins | (optional) Any mutable overmap special joins that should be checked before placing the chunk. Each direction is associated with a list of join `"id"` strings.
| flags | (optional) Any overmap terrain flags that should be checked before placing the chunk. Each direction is associated with a list of `oter_flags` flags.
Expand Down
Loading

0 comments on commit f5f9556

Please sign in to comment.