I want to start this thread for querstions and answers of what specific things in .json files do to make modding easier. I will start by asking how the item groups works.
"type" : "item_group",
"id" : "child_items",
"items":[
["chocolate", 50]]
In this bit of code, what does the 50 do?
Looking at the code, the ‘50’ seems to be the probability of the item spawning:
(src\item_factory.cpp:1348)
if (subtype == "old") {
JsonArray items = jsobj.get_array("items");
while (items.has_more()) {
if( items.test_object() ) {
JsonObject subobj = items.next_object();
add_entry( ig, subobj );
} else {
JsonArray pair = items.next_array();
ig->add_item_entry(pair.get_string(0), pair.get_int(1));
}
}
return;
}
Don’t know if this makes sense to you, but it assigns the second value in the array (the 50 in your example), to the ‘probability’ attribute in the code below:
(src\item_group.cpp:325)
for( const auto &elem : items ) {
if( rng( 0, 99 ) >= ( elem )->probability ) {
continue;
}
ItemList tmp = ( elem )->create( birthday, rec );
result.insert(result.end(), tmp.begin(), tmp.end());
}
This tells me that the value is a percentage of spawning, when it’s 100 the item always spawns. I think it is used in map generation. Sorry, I’m not an expert on the Cataclysm code (yet).
Actually, its a weighted average. It totals up all of those numbers and then uses that to determine what spawns. So, if the total adds up to 700, then chocolate will spawn 50/700 times.
I was gonna say yeah, weight. In monster drop and some mapgen entries you’ll see a different type of item_group, with subtype collection. These can use percentages, whereas normal itemgroups use weighted lists.
},{
"type" : "item_group",
"subtype": "collection",
"id": "cleansing_flame_casualties",
"entries":
[
{ "group": "underwear", "damage": [1, 4]},
{ "group": "shirts", "damage": [1, 4]},
{ "group": "pants", "damage": [1, 4]},
{ "group": "shoes", "damage": [1, 4]},
{ "group": "cleansing_flame_gear", "damage": [1, 4], "prob": 10 },
{ "group": "cleansing_flame_gear_magic", "prob": 25 },
{ "item": "corpse"}
]
},{
This spawns a corpse 100% of the time, calls various clothing item groups 100% of the time (with varying damage levels), calls an item group 10% of the time (with random damage), and calls another item group 25% of the time.