From 84a648723674934ef46e1799404d778474a74aeb Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 13 Apr 2018 11:30:01 +0200 Subject: Explosions, better AI and misc refactoring. --- src/game/unit_spider.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/game/unit_spider.cpp') 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; } -- cgit