Skip to content

Commit

Permalink
Merge pull request #36235 from ymber/mapgen_items
Browse files Browse the repository at this point in the history
Allow defining anonymous itemgroups in mapgen
  • Loading branch information
kevingranade authored Dec 30, 2019
2 parents 1c9dafc + 553f5af commit 13b78c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
19 changes: 13 additions & 6 deletions data/json/mapgen_palettes/apartment.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@
"d": { "item": "dresser", "chance": 70, "repeat": [ 1, 3 ] },
"e": { "item": "fridge", "chance": 70, "repeat": [ 1, 10 ] },
"j": { "item": "trash", "chance": 65, "repeat": [ 1, 3 ] },
"o": [
{ "item": "magazines", "chance": 30 },
{ "item": "novels", "chance": 40 },
{ "item": "alcohol", "chance": 30 },
{ "item": "manuals", "chance": 20 }
],
"o": {
"item": {
"subtype": "distribution",
"entries": [
{ "group": "magazines" },
{ "group": "SUS_fiction_bookcase" },
{
"distribution": [ { "group": "SUS_tailoring_bookcase" }, { "group": "SUS_crafts_bookcase" }, { "group": "SUS_cooking_bookcase" } ]
}
]
},
"chance": 75
},
"O": { "item": "oven", "chance": 70 },
"p": { "item": "mail", "chance": 30, "repeat": [ 2, 5 ] },
"r": [ { "item": "dresser", "chance": 30 }, { "item": "jackets", "chance": 60 } ],
Expand Down
2 changes: 1 addition & 1 deletion doc/MAPGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ Places a gas pump with gasoline (or sometimes diesel) in it. Values:

### 2.5.6 "items"
Places items from an item group. Values:
- "item": (required, string) the item group to use.
- "item": (required, string or itemgroup object) the item group to use.
- "chance": (optional, integer or min/max array) x in 100 chance that a loop will continue to spawn items from the group (which itself may spawn multiple items or not depending on its type, see `ITEM_SPAWN.md`), unless the chance is 100, in which case it will trigger the item group spawn exactly 1 time (see `map::place_items`).
- "repeat": (optional, integer or min/max array) the number of times to repeat this placement, default is 1.

Expand Down
11 changes: 4 additions & 7 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,14 +1041,11 @@ class jmapgen_liquid_item : public jmapgen_piece
class jmapgen_item_group : public jmapgen_piece
{
public:
std::string group_id;
Group_tag group_id;
jmapgen_int chance;
jmapgen_item_group( const JsonObject &jsi ) :
group_id( jsi.get_string( "item" ) )
, chance( jsi, "chance", 1, 1 ) {
if( !item_group::group_is_defined( group_id ) ) {
set_mapgen_defer( jsi, "item", "no such item group '" + group_id + "'" );
}
jmapgen_item_group( const JsonObject &jsi ) : chance( jsi, "chance", 1, 1 ) {
JsonValue group = jsi.get_member( "item" );
group_id = item_group::load_item_group( group, "collection" );
repeat = jmapgen_int( jsi, "repeat", 1, 1 );
}
void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override {
Expand Down

0 comments on commit 13b78c9

Please sign in to comment.