From 84766a7d49d3c1e233e13191c86d4ada2bbe2ddc Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 20 Apr 2018 14:18:16 +0200 Subject: Refactor and improve the hivemind + better AI debugging. --- src/game/units.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/game/units.cpp') diff --git a/src/game/units.cpp b/src/game/units.cpp index 20e74a7..a342a09 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -272,15 +272,17 @@ void unit_t::random_walk(void) move.random_walk_time = game->time; } -void hivemind_attack(unit_t *source, bool have_target, v2f_t target) +void state_t::hivemind_alert(v2f_t x, float r, bool do_move, v2f_t move_to) { rectf_t search; std::list ents; - search[0] = source->x - v2f_t(12, 12); - search[1] = source->x + v2f_t(12, 12); + search[0] = x - v2f_t(r, r); + search[1] = x + v2f_t(r, r); - ents = source->game->world.get_entities(search, CF_BODY_SMALL); + ents = world.get_entities(search, CF_BODY_SMALL); + + printf("alert with r=%f\n", r); for (world::entity_t *ent : ents) { unit_t *unit; @@ -290,6 +292,9 @@ void hivemind_attack(unit_t *source, bool have_target, v2f_t target) unit = dynamic_cast(ent); + if ((unit->x - x).len() > r) + continue; + if (unit->type != unit_t::UNIT_SPIDER) continue; @@ -298,15 +303,22 @@ void hivemind_attack(unit_t *source, bool have_target, v2f_t target) unit->wake(); - if (!have_target) + if (!do_move) continue; // Move towards the target if it's close, otherwise walk // randomly to avoid fire. - if ((unit->x - target).len() > 25.0f) + if ((unit->x - move_to).len() > 25.0f) continue; - unit->start_moving(target); + unit->start_moving(move_to); + } + + if (debug_AI) { + fx_debug_hivemind_t *debug; + + debug = new fx_debug_hivemind_t(this, x, r, do_move, move_to); + debug->place(&world); } } -- cgit