Enemies will now get scared when their health is low.

master
Zed A. Shaw 3 weeks ago
parent 00f76dfb34
commit c4e01775bc
  1. 35
      systems.cpp
  2. 2
      tests/ai.cpp

@ -83,6 +83,12 @@ void System::enemy_pathing(GameLevel &level) {
map.neighbors(out, motion.random);
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
}
fmt::println("------- ARE THEY SCARED? {}", ent);
enemy_ai.dump();
if(enemy_ai.wants_to("run_away")) {
dbc::log("ENEMY IS SCARED");
}
}
});
@ -150,6 +156,13 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
}
// we need to send this event for everything that dies
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
} else if(float(combat.hp) / float(combat.max_hp) < 0.5f) {
fmt::println("ENEMY HP low: {}/{}", combat.hp, combat.max_hp);
if(world.has<ai::EntityAI>(ent)) {
auto& enemy_ai = world.get<ai::EntityAI>(ent);
enemy_ai.set_state("health_good", false);
enemy_ai.update();
}
}
});
@ -195,14 +208,20 @@ void System::combat(GameLevel &level) {
auto& enemy_ai = world.get<ai::EntityAI>(entity);
enemy_ai.set_state("enemy_found", true);
enemy_ai.update();
auto& enemy_combat = world.get<Combat>(entity);
if(enemy_ai.wants_to("kill_enemy")) {
auto& enemy_combat = world.get<Combat>(entity);
Events::Combat result {
player_combat.attack(enemy_combat), 0
};
Events::Combat result {
player_combat.attack(enemy_combat),
enemy_combat.attack(player_combat)
};
if(!enemy_combat.dead && world.has<ai::EntityAI>(entity)) {
auto& enemy_ai = world.get<ai::EntityAI>(entity);
enemy_ai.set_state("in_combat", true);
enemy_ai.update();
}
if(enemy_ai.wants_to("kill_enemy")) {
result.enemy_did = enemy_combat.attack(player_combat);
if(world.has<Animation>(entity)) {
auto& animation = world.get<Animation>(entity);
@ -212,9 +231,9 @@ void System::combat(GameLevel &level) {
if(auto snd = world.get_if<Sound>(entity)) {
sound::play(snd->attack);
}
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
}
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
}
}
}

@ -190,13 +190,11 @@ TEST_CASE("Confirm EntityAI behaves as expected", "[ai-enemy]") {
enemy.set_state("in_combat", true);
enemy.set_state("health_good", false);
enemy.update();
enemy.dump();
REQUIRE(enemy.wants_to("run_away"));
enemy.set_state("have_item", true);
enemy.set_state("have_healing", true);
enemy.set_state("in_combat", false);
enemy.update();
enemy.dump();
REQUIRE(enemy.wants_to("use_healing"));
}

Loading…
Cancel
Save