Skip to content

Keep monster alive long enough to leave the water - #21

Open
jquast wants to merge 1 commit into
SimHacker:mainfrom
jquast:up-fix-monster-spawn-disappears
Open

jquast wants to merge 1 commit into
SimHacker:mainfrom
jquast:up-fix-monster-spawn-disappears

Conversation

@jquast

@jquast jquast commented Sep 29, 2026 •

Copy link
Copy Markdown

makeMonster() places the monster on a river tile, and doMonsterSprite() ends a monster whose hot spot is over water, or one that comes within 60 px of its spawn point, so a spawned monster died almost immediately.

$ make -C packages/micropolis-engine install
$ cd apps/micropolis
$ node_modules/.bin/tsx -e "import { loadMicropolisMainModule } from './src/lib/wasm/node.ts'; import { createNoopJsCallback } from './src/lib/wasm/callbacks'; (async () => { const e = await loadMicropolisMainModule(); const ticks = []; for (let run = 0; run < 8; run += 1) { const m = new e.Micropolis(); m.setCallback(createNoopJsCallback(e), {}); m.init(); m.loadCity('/cities/deadwood.cty'); m.setEnableDisasters(true); m.makeMonster(); let died = -1; for (let i = 1; i <= 100; i += 1) { m.simTick(); if (!m.getActiveSprites().some((s) => s.type === 5)) { died = i; break; } } ticks.push(died < 0 ? '>100' : died); m.delete(); } console.log('death ticks:', ticks.join(', ')); })();"
death ticks: 27, 27, 21, 47, 1, 1, 1, 1

The same eight spawns after this commit:

death ticks: >100, >100, >100, >100, >100, >100, 78, >100
simcity-monster-fixed.mp4

Depends on #15 (the loader fix) and #20 (the monster bindings) to run the commands above.

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.
@jquast
jquast marked this pull request as ready for review September 29, 2026 17:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant