|
|
@ -20,6 +20,7 @@ |
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
using namespace components; |
|
|
|
using namespace components; |
|
|
|
|
|
|
|
using namespace DinkyECS; |
|
|
|
using lighting::LightSource; |
|
|
|
using lighting::LightSource; |
|
|
|
|
|
|
|
|
|
|
|
void System::lighting(GameLevel &level) { |
|
|
|
void System::lighting(GameLevel &level) { |
|
|
@ -100,7 +101,7 @@ void System::enemy_pathing(GameLevel &level) { |
|
|
|
map.clear_target(player_position.location); |
|
|
|
map.clear_target(player_position.location); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::init_positions(DinkyECS::World &world, SpatialMap &collider) { |
|
|
|
void System::init_positions(World &world, SpatialMap &collider) { |
|
|
|
world.query<Position>([&](auto ent, auto &pos) { |
|
|
|
world.query<Position>([&](auto ent, auto &pos) { |
|
|
|
if(world.has<Combat>(ent)) { |
|
|
|
if(world.has<Combat>(ent)) { |
|
|
|
const auto& combat = world.get<Combat>(ent); |
|
|
|
const auto& combat = world.get<Combat>(ent); |
|
|
@ -113,7 +114,7 @@ void System::init_positions(DinkyECS::World &world, SpatialMap &collider) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) { |
|
|
|
inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, Motion &motion, Entity ent) { |
|
|
|
Point move_to = { |
|
|
|
Point move_to = { |
|
|
|
position.location.x + motion.dx, |
|
|
|
position.location.x + motion.dx, |
|
|
|
position.location.y + motion.dy |
|
|
|
position.location.y + motion.dy |
|
|
@ -140,7 +141,7 @@ void System::motion(GameLevel &level) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::distribute_loot(DinkyECS::World &world, DinkyECS::Entity& ent, nlohmann::json& entity_data) { |
|
|
|
void System::distribute_loot(World &world, Entity& ent, nlohmann::json& entity_data) { |
|
|
|
dbc::log("!!!!!!!!!!!!! THIS is where you update the dead body contents"); |
|
|
|
dbc::log("!!!!!!!!!!!!! THIS is where you update the dead body contents"); |
|
|
|
int inventory_count = entity_data["inventory_count"]; |
|
|
|
int inventory_count = entity_data["inventory_count"]; |
|
|
|
world.set<InventoryItem>(ent, {inventory_count, entity_data}); |
|
|
|
world.set<InventoryItem>(ent, {inventory_count, entity_data}); |
|
|
@ -168,7 +169,7 @@ void System::death(GameLevel &level) { |
|
|
|
auto &world = *level.world; |
|
|
|
auto &world = *level.world; |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto& config = world.get_the<GameConfig>(); |
|
|
|
auto& config = world.get_the<GameConfig>(); |
|
|
|
std::vector<DinkyECS::Entity> dead_things; |
|
|
|
std::vector<Entity> dead_things; |
|
|
|
|
|
|
|
|
|
|
|
world.query<Combat>([&](auto ent, auto &combat) { |
|
|
|
world.query<Combat>([&](auto ent, auto &combat) { |
|
|
|
// bring out yer dead
|
|
|
|
// bring out yer dead
|
|
|
@ -217,7 +218,7 @@ void System::death(GameLevel &level) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) { |
|
|
|
inline void animate_entity(World &world, Entity entity) { |
|
|
|
if(world.has<Animation>(entity)) { |
|
|
|
if(world.has<Animation>(entity)) { |
|
|
|
auto& animation = world.get<Animation>(entity); |
|
|
|
auto& animation = world.get<Animation>(entity); |
|
|
|
animation.play(); |
|
|
|
animation.play(); |
|
|
@ -315,7 +316,7 @@ void System::collision(GameLevel &level) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::pickup(GameLevel &level, DinkyECS::Entity entity) { |
|
|
|
void System::pickup(GameLevel &level, Entity entity) { |
|
|
|
auto &world = *level.world; |
|
|
|
auto &world = *level.world; |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
|
|
|
|
|
|
|
@ -346,7 +347,7 @@ void System::pickup(GameLevel &level, DinkyECS::Entity entity) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) { |
|
|
|
void System::device(World &world, Entity actor, Entity item) { |
|
|
|
auto& device = world.get<Device>(item); |
|
|
|
auto& device = world.get<Device>(item); |
|
|
|
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); |
|
|
|
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); |
|
|
|
|
|
|
|
|
|
|
@ -367,7 +368,7 @@ void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::plan_motion(DinkyECS::World& world, Point move_to) { |
|
|
|
void System::plan_motion(World& world, Point move_to) { |
|
|
|
auto& player = world.get_the<Player>(); |
|
|
|
auto& player = world.get_the<Player>(); |
|
|
|
auto& player_position = world.get<Position>(player.entity); |
|
|
|
auto& player_position = world.get<Position>(player.entity); |
|
|
|
auto& motion = world.get<Motion>(player.entity); |
|
|
|
auto& motion = world.get<Motion>(player.entity); |
|
|
@ -380,7 +381,7 @@ void System::plan_motion(DinkyECS::World& world, Point move_to) { |
|
|
|
* just avoid GameMap unlike the others. |
|
|
|
* just avoid GameMap unlike the others. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir) { |
|
|
|
std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir) { |
|
|
|
DinkyECS::World &world = *level.world; |
|
|
|
World &world = *level.world; |
|
|
|
Map &map = *level.map; |
|
|
|
Map &map = *level.map; |
|
|
|
|
|
|
|
|
|
|
|
auto player_pos = world.get<Position>(level.player).location; |
|
|
|
auto player_pos = world.get<Position>(level.player).location; |
|
|
@ -446,7 +447,7 @@ void System::player_status(GameLevel &level) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::Entity entity) { |
|
|
|
std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, Entity entity) { |
|
|
|
if(level.world->has<SpriteEffect>(entity)) { |
|
|
|
if(level.world->has<SpriteEffect>(entity)) { |
|
|
|
auto& se = level.world->get<SpriteEffect>(entity); |
|
|
|
auto& se = level.world->get<SpriteEffect>(entity); |
|
|
|
|
|
|
|
|
|
|
@ -462,7 +463,7 @@ std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::En |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DinkyECS::Entity System::spawn_item(DinkyECS::World& world, const std::string& name) { |
|
|
|
Entity System::spawn_item(World& world, const std::string& name) { |
|
|
|
Config config("assets/items.json"); |
|
|
|
Config config("assets/items.json"); |
|
|
|
auto& item_config = config[name]; |
|
|
|
auto& item_config = config[name]; |
|
|
|
auto item_id = world.entity(); |
|
|
|
auto item_id = world.entity(); |
|
|
@ -472,7 +473,7 @@ DinkyECS::Entity System::spawn_item(DinkyECS::World& world, const std::string& n |
|
|
|
return item_id; |
|
|
|
return item_id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool System::drop_item(GameLevel& level, DinkyECS::Entity item) { |
|
|
|
bool System::drop_item(GameLevel& level, Entity item) { |
|
|
|
auto& world = *level.world; |
|
|
|
auto& world = *level.world; |
|
|
|
auto& map = *level.map; |
|
|
|
auto& map = *level.map; |
|
|
|
auto& collision = *level.collision; |
|
|
|
auto& collision = *level.collision; |
|
|
@ -497,3 +498,23 @@ bool System::drop_item(GameLevel& level, DinkyECS::Entity item) { |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool System::place_in_container(World& world, Entity cont_id, const std::string& name, Entity world_entity) { |
|
|
|
|
|
|
|
auto& container = world.get<inventory::Model>(cont_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(container.has(world_entity)) { |
|
|
|
|
|
|
|
// NOTE: I think this would be a move?!
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else if(container.has(name)) { |
|
|
|
|
|
|
|
// this is an already occupied slot
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
container.add(name, world_entity); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void System::remove_from_container(World& world, Entity cont_id, const std::string& name) { |
|
|
|
|
|
|
|
auto& container = world.get<inventory::Model>(cont_id); |
|
|
|
|
|
|
|
container.remove(name); |
|
|
|
|
|
|
|
} |
|
|
|