summaryrefslogtreecommitdiff
path: root/src/game/units.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-13 11:30:01 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-13 11:30:01 +0200
commit84a648723674934ef46e1799404d778474a74aeb (patch)
tree2a468b9d991942f7ecf23068177a986163522314 /src/game/units.cpp
parentdd83ee59e481d58f5c30751d9dead295750857ca (diff)
Explosions, better AI and misc refactoring.
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r--src/game/units.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index fb0ce3c..6bce474 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -209,8 +209,10 @@ void unit_t::damage(int points, unit_t *attacker)
health -= points;
if (health <= 0)
die(attacker);
- else
+ else {
wake();
+ on_damage(attacker);
+ }
}
void unit_t::die(unit_t *killer)
@@ -273,4 +275,36 @@ void unit_t::random_walk(void)
move.random_walk_time = game->time;
}
+void hivemind_attack(unit_t *source, v2f_t target)
+{
+ rectf_t search;
+ std::list<world::entity_t*> ents;
+
+ search[0] = source->x - v2f_t(5, 5);
+ search[1] = source->x + v2f_t(5, 5);
+
+ ents = source->game->world.get_entities(search, CF_BODY_SMALL);
+
+ for (world::entity_t *ent : ents) {
+ unit_t *unit;
+
+ if (ent->type != ET_UNIT)
+ continue;
+
+ unit = dynamic_cast<unit_t*>(ent);
+
+ if (unit->type != unit_t::UNIT_SPIDER)
+ continue;
+
+ if ((unit->x - target).len() > 25.0f)
+ continue;
+
+ if (unit->have_target)
+ continue;
+
+ unit->wake();
+ unit->start_moving(target);
+ }
+}
+
} // namespace game