|
|
|
@ -53,10 +53,9 @@ void System::lighting(GameLevel &level) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void System::generate_paths(GameLevel &level) { |
|
|
|
|
auto player = level.world->get_the<Player>(); |
|
|
|
|
const auto &player_position = level.world->get<Position>(player.entity); |
|
|
|
|
const auto &player_pos = player_position(level); |
|
|
|
|
|
|
|
|
|
level.map->set_target(player_position.location); |
|
|
|
|
level.map->set_target(player_pos.location); |
|
|
|
|
level.map->make_paths(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -90,12 +89,10 @@ void System::enemy_ai_initialize(GameLevel &level) { |
|
|
|
|
void System::enemy_pathing(GameLevel &level) { |
|
|
|
|
auto &world = *level.world; |
|
|
|
|
auto &map = *level.map; |
|
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
|
|
|
|
|
|
const auto &player_position = world.get<Position>(player.entity); |
|
|
|
|
const auto &player_pos = player_position(level); |
|
|
|
|
|
|
|
|
|
world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) { |
|
|
|
|
if(ent != player.entity) { |
|
|
|
|
if(ent != level.player) { |
|
|
|
|
auto& enemy_ai = world.get<ai::EntityAI>(ent); |
|
|
|
|
Point out = position.location; // copy
|
|
|
|
|
|
|
|
|
@ -109,7 +106,7 @@ void System::enemy_pathing(GameLevel &level) { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
map.clear_target(player_position.location); |
|
|
|
|
map.clear_target(player_pos.location); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -240,17 +237,16 @@ inline void animate_entity(World &world, Entity entity) { |
|
|
|
|
void System::combat(GameLevel &level, int attack_id) { |
|
|
|
|
auto &collider = *level.collision; |
|
|
|
|
auto &world = *level.world; |
|
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
|
auto& the_belt = world.get_the<ritual::Belt>(); |
|
|
|
|
|
|
|
|
|
if(!the_belt.has(attack_id)) return; |
|
|
|
|
|
|
|
|
|
auto& ritual = the_belt.get(attack_id); |
|
|
|
|
const auto& player_position = world.get<Position>(player.entity); |
|
|
|
|
auto& player_combat = world.get<Combat>(player.entity); |
|
|
|
|
const auto& player_pos = player_position(level); |
|
|
|
|
auto& player_combat = world.get<Combat>(level.player); |
|
|
|
|
|
|
|
|
|
// this is guaranteed to not return the given position
|
|
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
|
auto [found, nearby] = collider.neighbors(player_pos.location); |
|
|
|
|
combat::BattleEngine battle; |
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
@ -297,12 +293,10 @@ void System::combat(GameLevel &level, int attack_id) { |
|
|
|
|
void System::collision(GameLevel &level) { |
|
|
|
|
auto &collider = *level.collision; |
|
|
|
|
auto &world = *level.world; |
|
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
|
|
|
|
|
|
const auto& player_position = world.get<Position>(player.entity); |
|
|
|
|
const auto& player_pos = player_position(level); |
|
|
|
|
|
|
|
|
|
// this is guaranteed to not return the given position
|
|
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
|
auto [found, nearby] = collider.neighbors(player_pos.location); |
|
|
|
|
int combat_count = 0; |
|
|
|
|
|
|
|
|
|
// AI: I think also this would a possible place to run AI decisions
|
|
|
|
@ -320,7 +314,7 @@ void System::collision(GameLevel &level) { |
|
|
|
|
|
|
|
|
|
if(combat_count == 0) { |
|
|
|
|
// BUG: this is probably how we get stuck in combat
|
|
|
|
|
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, player.entity, player.entity); |
|
|
|
|
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, level.player, level.player); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -337,13 +331,29 @@ void System::remove_from_world(GameLevel &level, Entity entity) { |
|
|
|
|
level.world->remove<Position>(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void System::pickup(GameLevel &level, Entity entity) { |
|
|
|
|
void System::pickup(GameLevel &level) { |
|
|
|
|
auto &world = *level.world; |
|
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
|
auto &collision = *level.collision; |
|
|
|
|
auto pos = player_position(level); |
|
|
|
|
|
|
|
|
|
if(!collision.something_there(pos.aiming_at)) { |
|
|
|
|
dbc::log("nothing there"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto entity = level.collision->find(pos.aiming_at, [&](auto data) -> bool { |
|
|
|
|
return (world.has<InventoryItem>(data.entity) || |
|
|
|
|
world.has<Device>(data.entity)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if(world.has<InventoryItem>(entity)) { |
|
|
|
|
if(entity == DinkyECS::NONE) { |
|
|
|
|
dbc::log("no inventory or devices there"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// use spatial find to find an item with inventory...
|
|
|
|
|
if(auto item = world.get_if<InventoryItem>(entity)) { |
|
|
|
|
// NOTE: this might need to be a separate system so that people can leave stuff alone
|
|
|
|
|
auto item = world.get<InventoryItem>(entity); |
|
|
|
|
remove_from_world(level, entity); |
|
|
|
|
|
|
|
|
|
if(world.has<ritual::JunkPile>(entity)) { |
|
|
|
@ -358,14 +368,15 @@ void System::pickup(GameLevel &level, Entity entity) { |
|
|
|
|
// NOTE: chests are different from say a torch, maybe 2 events or the
|
|
|
|
|
// GUI figures out which it is, then when you click either pick it up
|
|
|
|
|
// and move it or show the loot container UI
|
|
|
|
|
world.send<Events::GUI>(Events::GUI::LOOT_ITEM, entity, item); |
|
|
|
|
world.send<Events::GUI>(Events::GUI::LOOT_ITEM, entity, *item); |
|
|
|
|
} |
|
|
|
|
} else if(world.has<Device>(entity)) { |
|
|
|
|
System::device(world, player.entity, entity); |
|
|
|
|
System::device(world, level.player, entity); |
|
|
|
|
} else { |
|
|
|
|
// Bug #81 is related to this
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void System::device(World &world, Entity actor, Entity item) { |
|
|
|
|
auto& device = world.get<Device>(item); |
|
|
|
|
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); |
|
|
|
@ -387,15 +398,14 @@ void System::device(World &world, Entity actor, Entity item) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void System::plan_motion(World& world, Position move_to) { |
|
|
|
|
auto& player = world.get_the<Player>(); |
|
|
|
|
auto& player_position = world.get<Position>(player.entity); |
|
|
|
|
void System::plan_motion(GameLevel& level, Position move_to) { |
|
|
|
|
auto& player_pos = player_position(level); |
|
|
|
|
|
|
|
|
|
player_position.aiming_at = move_to.aiming_at; |
|
|
|
|
player_pos.aiming_at = move_to.aiming_at; |
|
|
|
|
|
|
|
|
|
auto& motion = world.get<Motion>(player.entity); |
|
|
|
|
motion.dx = move_to.location.x - player_position.location.x; |
|
|
|
|
motion.dy = move_to.location.y - player_position.location.y; |
|
|
|
|
auto& motion = level.world->get<Motion>(level.player); |
|
|
|
|
motion.dx = move_to.location.x - player_pos.location.x; |
|
|
|
|
motion.dy = move_to.location.y - player_pos.location.y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|