diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-04-20 14:18:16 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-04-20 14:18:16 +0200 |
commit | 84766a7d49d3c1e233e13191c86d4ada2bbe2ddc (patch) | |
tree | 57f733939a9fd9c0cb1c3157da37e90b2c08b547 /src/game/units.cpp | |
parent | 0bc4eaebc6cb4410c5dbf3d89ae02634cfe72e27 (diff) |
Refactor and improve the hivemind + better AI debugging.
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r-- | src/game/units.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
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<world::entity_t*> 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<unit_t*>(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); } } |