From 4d186571d543a9e52afc62920ac00b7ebe5a35bd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 23 Aug 2019 16:31:09 +0200 Subject: HDB: Fix closed loops with laser beams Nipun was able to construct such position in Map28 which led to a closed loop and the game hung. We're inserting a watchdog here now. --- engines/hdb/ai-bots.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'engines') diff --git a/engines/hdb/ai-bots.cpp b/engines/hdb/ai-bots.cpp index 33a15c08dd..ac4b24197c 100644 --- a/engines/hdb/ai-bots.cpp +++ b/engines/hdb/ai-bots.cpp @@ -1407,6 +1407,8 @@ void aiLaserAction(AIEntity *e) { AIEntity *hit = e; int moveOK = 0; + int moveCount = 0; + do { int nx = hit->tileX; int ny = hit->tileY; @@ -1541,6 +1543,13 @@ void aiLaserAction(AIEntity *e) { hit = NULL; } } + + moveCount++; + + // It is possible to set a configuration which leads to a closed loop. + // Thus, we're breaking it here + if (moveCount > 1000) + hit = NULL; } while (hit && hit->type == AI_DIVERTER); } -- cgit v1.2.3