From e77c5b1e01eeb55625d8cf072bedd5a34658b865 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 13 Apr 2018 13:48:01 +0200 Subject: Better random walking so spiders don't get stuck so often. --- src/game/unit_spider.cpp | 18 ++++++++++++------ src/game/units.cpp | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/game/unit_spider.cpp b/src/game/unit_spider.cpp index 4f0fbd9..5d6253d 100644 --- a/src/game/unit_spider.cpp +++ b/src/game/unit_spider.cpp @@ -82,15 +82,21 @@ void unit_spider_t::on_wake(void) void unit_spider_t::on_think(void) { + if (game->now - wake_time > 10.0) { + sleep(); + return; + } + target_and_attack(); - if (have_target || game->now - wake_time < 10.0) { - if (!have_target && !move.moving) - random_walk(); + if (!have_target && !move.moving) + random_walk(); - keep_moving(4.0); - } else - sleep(); + if (!keep_moving(4.0)) { + // Try to get unstuck. + next_targetting = game->now + 0.6; + random_walk(); + } } void unit_spider_t::on_damage(unit_t *attacker) diff --git a/src/game/units.cpp b/src/game/units.cpp index 6bce474..e7263c0 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -271,7 +271,11 @@ void unit_t::random_walk(void) game->time - move.random_walk_time < MSEC(1000)) return; - start_moving(x + game->prng.unit_vec2() * 10); + move.moving = true; + move.blocked = false; + move.dst = x + game->prng.unit_vec2() * 10; + move.path.clear(); + move.path.push_back(move.dst); move.random_walk_time = game->time; } -- cgit