summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/game.hpp2
-rw-r--r--src/game/unit_nest.cpp6
-rw-r--r--src/game/unit_spider.cpp12
-rw-r--r--src/game/units.cpp9
4 files changed, 19 insertions, 10 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 089faf0..6d6a80b 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -168,7 +168,7 @@ namespace game {
class fx_aim_marker_t;
unit_t *find_target(world::world_t *world, v2f_t x, float r, bool friendly);
- void hivemind_attack(unit_t *source, v2f_t target);
+ void hivemind_attack(unit_t *source, bool have_target, v2f_t target);
class unit_t : public entity_t {
protected:
diff --git a/src/game/unit_nest.cpp b/src/game/unit_nest.cpp
index 5890d34..89846c2 100644
--- a/src/game/unit_nest.cpp
+++ b/src/game/unit_nest.cpp
@@ -82,13 +82,17 @@ void unit_nest_t::on_spawn(void)
void unit_nest_t::on_damage(unit_t *attacker)
{
if (attacker)
- hivemind_attack(this, attacker->x);
+ hivemind_attack(this, true, attacker->x);
+ else
+ hivemind_attack(this, false, v2f_t(0, 0));
assets::nest.pain.play_3d(x);
}
void unit_nest_t::on_death(void)
{
+ hivemind_attack(this, false, v2f_t(0, 0));
+
render_layer = render::LAYER_FLAT;
cmodel.cflags = CF_BACKGROUND;
assets::nest.death.play_3d(x);
diff --git a/src/game/unit_spider.cpp b/src/game/unit_spider.cpp
index 5d6253d..7d4d0a1 100644
--- a/src/game/unit_spider.cpp
+++ b/src/game/unit_spider.cpp
@@ -53,7 +53,7 @@ void unit_spider_t::target_and_attack(void)
// Tell everyone about a new target.
if (!have_target)
- hivemind_attack(this, target->x);
+ hivemind_attack(this, true, target->x);
have_target = true;
wake_time = game->time;
@@ -103,14 +103,16 @@ void unit_spider_t::on_damage(unit_t *attacker)
{
assets::spider.sounds.play_3d(x);
- if (!attacker)
- return;
-
- hivemind_attack(this, attacker->x);
+ if (attacker)
+ hivemind_attack(this, true, attacker->x);
+ else
+ hivemind_attack(this, false, v2f_t(0, 0));
}
void unit_spider_t::on_death(void)
{
+ hivemind_attack(this, false, v2f_t(0, 0));
+
if (health < -5) {
assets::soldier.gib_sound.play_3d(x);
game->deletion_list.insert(this);
diff --git a/src/game/units.cpp b/src/game/units.cpp
index 11379cb..968e93e 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -288,13 +288,13 @@ void unit_t::random_walk(void)
move.random_walk_time = game->time;
}
-void hivemind_attack(unit_t *source, v2f_t target)
+void hivemind_attack(unit_t *source, bool have_target, 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);
+ search[0] = source->x - v2f_t(12, 12);
+ search[1] = source->x + v2f_t(12, 12);
ents = source->game->world.get_entities(search, CF_BODY_SMALL);
@@ -314,6 +314,9 @@ void hivemind_attack(unit_t *source, v2f_t target)
unit->wake();
+ if (!have_target)
+ continue;
+
// Move towards the target if it's close, otherwise walk
// randomly to avoid fire.
if ((unit->x - target).len() > 25.0f)