diff --git a/systems.cpp b/systems.cpp index d1cfee5..5d7891b 100644 --- a/systems.cpp +++ b/systems.cpp @@ -146,22 +146,23 @@ void System::motion(GameLevel &level) { }); } -void System::distribute_loot(GameLevel &level, Entity& ent) { +void System::distribute_loot(GameLevel &level, Position target_pos) { auto& world = *level.world; - - // BUG: I constantly open a config when I have GameConfig already auto& config = world.get_the(); + int inventory_count = Random::uniform(0, 3); - ritual::JunkPile pile; - auto& junk = config.rituals["junk"]; + if(inventory_count > 0) { + // do a clone of the things we need, like Position + auto junk_entity = world.entity(); - ritual::JunkPile select_from; - for(auto& el : junk.items()) { - select_from.contents.push_back(el.key()); - } + ritual::JunkPile pile; + auto& junk = config.rituals["junk"]; + + ritual::JunkPile select_from; + for(auto& el : junk.items()) { + select_from.contents.push_back(el.key()); + } - int inventory_count = Random::uniform(0, 3); - if(inventory_count > 0) { 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)); @@ -169,13 +170,16 @@ void System::distribute_loot(GameLevel &level, Entity& ent) { } auto entity_data = config.devices["GRAVE_STONE"]; - components::configure_entity(world, ent, entity_data["components"]); - world.set(ent, pile); + components::configure_entity(world, junk_entity, entity_data["components"]); + world.set(junk_entity, pile); // BUG: inventory_count here isn't really used to remove it - world.set(ent, {inventory_count, entity_data}); + world.set(junk_entity, {inventory_count, entity_data}); + world.set(junk_entity, target_pos); + level.collision->insert(target_pos.location, junk_entity); + level.world->send(Events::GUI::ENTITY_SPAWN, junk_entity, {}); } else { dbc::log("DEAD BODY NOT IMPLEMENTED, for now just removing enemy"); - remove_from_world(level, ent); + level.collision->remove(target_pos.location); // BUG: should maybe add a component to the world for "dead thing no loot" that // has no collision or goes away after some kind of animation // Something like: @@ -215,22 +219,18 @@ void System::death(GameLevel &level) { // NOTE: this could be a separate system but also could be a function in // components:: for(auto ent : dead_things) { - // remove their enemy setting - world.remove(ent); - world.remove(ent); - world.remove(ent); - world.remove(ent); - world.remove(ent); - world.remove(ent); - world.remove(ent); - world.remove(ent); - if(auto snd = world.get_if(ent)) { sound::stop(snd->attack); sound::play(snd->death); } - System::distribute_loot(level, ent); + auto pos = world.get(ent); + // NOTE: distribute loot is responsible for either removing or replacing + // the collision for this entity. It has to do this since it's determining + // if a junkpile goes there or nothing + System::distribute_loot(level, pos); + + world.destroy(ent); } } @@ -332,6 +332,10 @@ void System::collision(GameLevel &level) { } } +/* + * This isn't for destroying something, but just removing it + * from the world for say, putting into a container or inventory. + */ void System::remove_from_world(GameLevel &level, Entity entity) { auto& item_pos = level.world->get(entity); level.collision->remove(item_pos.location); diff --git a/systems.hpp b/systems.hpp index a6adbff..92c8bfe 100644 --- a/systems.hpp +++ b/systems.hpp @@ -28,7 +28,7 @@ namespace System { std::shared_ptr sprite_effect(GameLevel &level, Entity entity); void player_status(GameLevel &level); - void distribute_loot(GameLevel &level, Entity& ent); + void distribute_loot(GameLevel &level, Position target_pos); void pickup(GameLevel &level, Entity entity);