summaryrefslogtreecommitdiff
path: root/src/game/unit_spider.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/unit_spider.cpp
parentdd83ee59e481d58f5c30751d9dead295750857ca (diff)
Explosions, better AI and misc refactoring.
Diffstat (limited to 'src/game/unit_spider.cpp')
-rw-r--r--src/game/unit_spider.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/game/unit_spider.cpp b/src/game/unit_spider.cpp
index 9ff8fc1..df9073c 100644
--- a/src/game/unit_spider.cpp
+++ b/src/game/unit_spider.cpp
@@ -33,6 +33,8 @@ unit_spider_t::unit_spider_t(game::state_t *game) : unit_t(game, UNIT_SPIDER)
ignore_waking = false;
health = max_health = 4;
+
+ sleep();
}
void unit_spider_t::target_and_attack(void)
@@ -45,12 +47,12 @@ void unit_spider_t::target_and_attack(void)
target = find_target(world, x, 10.0f, true);
if (!target) {
- if (health < max_health)
- random_walk();
-
+ have_target = false;
return;
}
+ have_target = true;
+ wake_time = game->time;
start_moving(target->x);
next_targetting = game->now + game->prng.next_float(0.2f, 0.4f);
@@ -72,18 +74,31 @@ void unit_spider_t::on_think(void)
{
target_and_attack();
- keep_moving(4.0);
+ if (have_target || game->now - wake_time < 10.0) {
+ if (!have_target && !move.moving)
+ random_walk();
- if (!move.moving && wake_time + 5 < game->now)
+ keep_moving(4.0);
+ } else
sleep();
}
-void unit_spider_t::on_wake(void)
+void unit_spider_t::on_damage(unit_t *attacker)
{
+ if (!attacker)
+ return;
+
+ hivemind_attack(this, attacker->x);
}
void unit_spider_t::on_death(void)
{
+ if (health < -5) {
+ assets::soldier.gib_sound.play_3d(x);
+ game->deletion_list.insert(this);
+ return;
+ }
+
render_layer = render::LAYER_FLAT;
cmodel.cflags = CF_BACKGROUND;
}