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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "goap.hpp"
|
||||
#include "ai.hpp"
|
||||
#include "config.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
namespace ritual {
|
||||
using JunkItem = std::string;
|
||||
|
@ -96,4 +97,6 @@ namespace ritual {
|
|||
bool no_selections();
|
||||
void consume_crafting();
|
||||
};
|
||||
|
||||
JunkPile random_junk(components::GameConfig& config, int count);
|
||||
}
|
||||
|
|
15
systems.cpp
15
systems.cpp
|
@ -144,20 +144,7 @@ void System::distribute_loot(GameLevel &level, Position target_pos) {
|
|||
auto loot_entity = world.entity();
|
||||
|
||||
if(inventory_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 < inventory_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);
|
||||
}
|
||||
auto pile = ritual::random_junk(config, inventory_count);
|
||||
|
||||
auto entity_data = config.devices["GRAVE_STONE"];
|
||||
components::configure_entity(world, loot_entity, entity_data["components"]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue