summaryrefslogtreecommitdiff
path: root/src/game/units.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r--src/game/units.cpp26
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);
}
}