Skip to content

Commit 6bf86bb

Browse files
authored
add support for fault applying via itemgroup (#81585)
* add support for fault applying via itemgroup * please clang
1 parent 3fe918c commit 6bf86bb

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

doc/JSON/ITEM_SPAWN.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Each entry can have more values (shown above as `...`). They allow further prop
9797
"artifact": <object>
9898
"event": <string>
9999
"snippets": <string>
100+
"faults": <object>
100101
```
101102

102103
`contents` is added as contents of the created item. It is not checked if they can be put into the item. This allows water, that contains a book, that contains a steel frame, that contains a corpse.
@@ -117,8 +118,6 @@ Each entry can have more values (shown above as `...`). They allow further prop
117118
118119
`event`: A reference to a holiday in the `holiday` enum. If specified, the entry only spawns during the specified real holiday. This works the same way as the seasonal title screens, where the holiday is checked against the current system's time. If the holiday matches, the item's spawn probability is taken from the `prob` field. Otherwise, the spawn probability becomes 0.
119120
120-
`snippets`: If item uses `snippet_category` instead of description, and snippets contain ids, allow to pick a specific description of an item to spawn; see [JSON_INFO.md#snippets](JSON_INFO.md#snippets)
121-
122121
Current possible values are:
123122
- "none" (Not event-based. Same as omitting the "event" field.)
124123
- "new_year"
@@ -128,6 +127,16 @@ Current possible values are:
128127
- "thanksgiving"
129128
- "christmas"
130129
130+
`snippets`: If item uses `snippet_category` instead of description, and snippets contain ids, allow to pick a specific description of an item to spawn; see [JSON_INFO.md#snippets](JSON_INFO.md#snippets)
131+
132+
`faults`: If item can have this fault or faults, it would be spawned with it applied. Possible values are:
133+
`id`: array of fault id that should be applied, if possible
134+
`chance`: chance to apply any of the faults. Default is 100, always apply
135+
For example:
136+
```json
137+
{ "group": "nested_ar10", "prob": 89, "faults": { "id": [ "fault_stovepipe" ], "chance": 50 } },
138+
```
139+
131140
`artifact`: This object determines that the item or group that is spawned by this entry will become an artifact. Here is an example:
132141
```jsonc
133142
"artifact": { "procgen_id": "cult", "rules": { "power_level": 1000, "max_attributes": 5, "max_negative_power": -2000 } }

src/item_factory.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,15 @@ void Item_factory::add_entry( Item_group &ig, const JsonObject &obj,
46414641
use_modifier = true;
46424642
}
46434643

4644+
if( obj.has_object( "faults" ) ) {
4645+
JsonObject jo = obj.get_object( "faults" );
4646+
int chance = jo.get_int( "chance", 100 );
4647+
for( std::string ids : jo.get_array( "id" ) ) {
4648+
modifier.faults.emplace_back( fault_id( ids ), chance );
4649+
}
4650+
use_modifier = true;
4651+
}
4652+
46444653
if( use_modifier ) {
46454654
sptr->modifier.emplace( std::move( modifier ) );
46464655
}

src/item_group.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ void Item_modifier::modify( item &new_item, const std::string &context ) const
517517

518518
new_item.set_itype_variant( variant );
519519

520+
if( !faults.empty() ) {
521+
for( const std::pair<fault_id, int> &f : faults ) {
522+
if( x_in_y( f.second, 100 ) ) {
523+
new_item.set_fault( f.first, false, false );
524+
}
525+
}
526+
}
527+
520528
{
521529
// create container here from modifier or from default to get max charges later
522530
std::optional<item> cont;

src/item_group.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ class Item_modifier
278278
*/
279279
std::string variant;
280280

281+
/**
282+
* add this faults to item, if possible
283+
*/
284+
std::vector<std::pair<fault_id, int>> faults;
285+
281286
/**
282287
* Custom sub set of snippets to be randomly chosen from and then applied to the item.
283288
*/

0 commit comments

Comments
 (0)