Refactor out the junk randomizer and put it in rituals where it belongs.
This commit is contained in:
parent
05d54ff661
commit
521180b086
3 changed files with 25 additions and 14 deletions
21
rituals.cpp
21
rituals.cpp
|
@ -196,4 +196,25 @@ namespace ritual {
|
|||
contents.erase(item_id);
|
||||
}
|
||||
}
|
||||
|
||||
JunkPile random_junk(components::GameConfig &config, int count) {
|
||||
dbc::check(count > 0, "cant' call random_junk with count < 0");
|
||||
// this means the entity dropped loot, so make a lootable tombstone
|
||||
ritual::JunkPile pile;
|
||||
auto& junk = config.rituals["junk"];
|
||||
|
||||
ritual::JunkPile select_from;
|
||||
for(auto& el : junk.items()) {
|
||||
select_from.contents.push_back(el.key());
|
||||
}
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
size_t max_junk = select_from.contents.size();
|
||||
auto& item = select_from.contents.at(Random::uniform(size_t(0), max_junk-1));
|
||||
pile.contents.push_back(item);
|
||||
}
|
||||
|
||||
dbc::check(pile.contents.size() > 0, "ritual::random_junk returned junk size == 0");
|
||||
return pile;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue