CleverRaven/Cataclysm-DDA — pull request #7092 by BevapDin (2014-04-08 12:14:35+00:00)
Title: Improve item spawn system [WIP] [CR]

I implemented a new spawn system, as proposed here: http://smf.cataclysmdda.com/index.php?topic=4480

It uses the json format and does not use the proposed formatting because I didn't wanted to write yet another parser.

Item groups can spawn several items at once. This is a bit different from the current system. The current system randomly chooses a single item type and the caller (e.g. mapgen.cpp) create the item. Some functions (`map::place_items`) may repeat this until a check against the random generator fails.

This new system allows to set the amount in the json files: specify a item collection with 3 items (each having a probability of 100 %), and it will spawn all 3 items all the time. Os simply add `count` or `count-min` and `count-max` entries.

The spawn entry for a science map extra could look like this:
```
[
{
"type" : "item_group",
"subtype": "collection",
"id": "map_extra_science",
"entries":
[
{ "item": "corpse", "damage": 3 },
{ "item": "id_science", "prob": 50 },
{ "item": "coat_lab", "damage-min": 1, "damage-max": 3 },
{ "group": "science" },
{ "group": "lab_pants", "damage-min": 1, "damage-max": 3 },
{ "group": "lab_shoes", "damage-min": 1, "damage-max": 3 },
{ "group": "lab_torso", "damage-min": 1, "damage-max": 3 },
{ "group": "underwear", "damage-min": 1, "damage-max": 3 }

]
}, {
"type" : "item_group",
"subtype": "distribution",
"id": "underwear",
"groups":
[
["female_underwear", 50],
["male_underwear", 50]
]
}, {
"type" : "item_group",
"subtype": "collection",
"id": "female_underwear",
"groups":
[
"female_underwear_top",
"female_underwear_bottom"
]
}, {
"type" : "item_group",
"subtype": "collection",
"id": "male_underwear",
"groups":
[
"male_underwear_top",
"male_underwear_bottom"
]
}
]
```
The probability defaults to 100 in collections, which makes a id card appear half of the time. It also creates exactly one pant item, one shoe item. It can still create 2 lab coats because one is created per default (item: coat_lab) and another may come from the item group lab_torso.

I added a debug menu entry. One can choose a item group there. The item group is asked to create items 100 times. The items are counted and displayed.

The system does not have the `+` or `|` operator as proposed in the forum. Those can be emulated with item groups.

Any requests for more item properties?

How to move the spawn behavior that is currently coded in C++ into json? Should this

The format allows anonymous (unnamed) groups:
```
{
"type" : "item_group",
"subtype": "distribution",
"id": "hazmat_monster",
"entries":
[
{ "group": "hazmat_full" },
{ "collection":
[
{ "group": "hazmat_torso" },
{ "group": "hazmat_gloves" },
{ "group": "hazmat_boots" },
{ "group": "hazmat_mask" },
{ "group": "hazmat_eyes", "prob": 33 }
]
}
]
}
```
This piece of json is nearly equal to the code in mondeath.cpp line 574. (probability of 1/3 can not be expressed, but 33% is a good approximation)