summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-13 13:48:01 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-13 13:48:01 +0200
commite77c5b1e01eeb55625d8cf072bedd5a34658b865 (patch)
tree683a2ecb2bfae408a0a3f351c203b9a1b372ed76 /src
parent1378213595c5072625003ddeffa4986b64940c53 (diff)
Better random walking so spiders don't get stuck so often.
Diffstat (limited to 'src')
-rw-r--r--src/game/unit_spider.cpp18
-rw-r--r--src/game/units.cpp6
2 files changed, 17 insertions, 7 deletions
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;
}