From 625f625684fdb426542d5dbf46cf978e10a27ed7 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Sat, 22 Aug 2026 14:06:10 +0000 Subject: [PATCH] Keep a new monster alive long enough to leave the water makeMonster() places the monster on a river tile, and doMonsterSprite() kills any monster whose hot spot is over water, so a spawn was killed on its first tick while still standing on the river it appeared on. That function also ends a monster that comes back within 60 px of origX/origY, which initSprite sets to the spawn point, so a monster turned for home and vanished with 712 of its 1000 ticks left. Gate both exits on count, which initSprite sets to 1000 at spawn and the turn-for-home transition resets, so the monster lives at least MONSTER_SPAWN_GRACE ticks. The count != 0 term stays, preserving the exhaustion semantics. The window has to be that large. The monster moves 2 pixels a tick against 16-pixel tiles and keeps stepping back into the water, so a 20-tick window moves the death to tick 20. Measured over 40 spawns per setting, seeds set before the city load so each run starts from the same world: with no window 4 monsters die within two ticks and 16 within 100, with a 20-tick window none die before tick 20 and 16 still die within 100, with 500 none die within 100 and the earliest is tick 214. 500 is the figure micropolisJS uses for the same check (monsterSprite.js: tileValue === RIVER && this.count < 500). A monster can still be killed earlier by leaving the map, which doMonsterSprite() ends with a c == -1 test of its own. --- packages/micropolis-engine/src/sprite.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/micropolis-engine/src/sprite.cpp b/packages/micropolis-engine/src/sprite.cpp index 5cab2c8f..bcac6f22 100644 --- a/packages/micropolis-engine/src/sprite.cpp +++ b/packages/micropolis-engine/src/sprite.cpp @@ -1012,6 +1012,10 @@ void Micropolis::doMonsterSprite(SimSprite *sprite) static const short ND2[4] = { 1, 2, 3, 0 }; static const short nn1[4] = { 2, 5, 8, 11 }; static const short nn2[4] = { 11, 2, 5, 8 }; + static const int MONSTER_LIFE = 1000; + // Covers a monster working its way along a coastline, where it keeps + // stepping back into the water. + static const int MONSTER_SPAWN_GRACE = 500; short d, z, c; if (sprite->soundCount > 0) { @@ -1116,7 +1120,7 @@ void Micropolis::doMonsterSprite(SimSprite *sprite) sprite->destX = sprite->origX; sprite->destY = sprite->origY; - } else { + } else if (sprite->count <= MONSTER_LIFE - MONSTER_SPAWN_GRACE) { sprite->frame = 0; return; @@ -1212,7 +1216,9 @@ void Micropolis::doMonsterSprite(SimSprite *sprite) c = getChar(sprite->x + sprite->xHot, sprite->y + sprite->yHot); if (c == -1 - || (c == RIVER && sprite->count != 0 && sprite->control == -1)) { + || (c == RIVER && sprite->count != 0 + && sprite->count <= MONSTER_LIFE - MONSTER_SPAWN_GRACE + && sprite->control == -1)) { sprite->frame = 0; /* kill scary monster */ } @@ -1910,9 +1916,8 @@ void Micropolis::makeShipHere(int x, int y) /** * Start a new monster sprite. - * @todo Make monster over land, because it disappears if it's made over water. - * Better yet make monster not disappear for a while after it's created, - * over land or water. Should never disappear prematurely. + * Spawns on a river tile; doMonsterSprite() keeps it alive for its first + * MONSTER_SPAWN_GRACE ticks. */ void Micropolis::makeMonster() {