Repository navigation
WIP: Chase creatures that run away, as DK II does, without getting Imps killed - #871
Draft
scottyhutch wants to merge 107 commits into
Draft
scottyhutch wants to merge 107 commits into
scottyhutch wants to merge 107 commits into
Conversation
Checked against DKII.EXE (target choice 0x45CB00, Horned Reaper target choice 0x45E1B0, damage to the heart 0x4DA200): - A fighting creature that finds no enemy creature to fight, or only workers further away than the heart, goes for the nearest enemy Dungeon Heart it can see and get to. Imps (non-fighters) leave hearts alone. - The heart stands on the centre 3x3 of its room, which can't be walked on. The original puts attack points round the heart and passes their damage on to the heart; here the creature walks to the nearest reachable tile of the ring round the centre and hits the heart object from there. - A hit takes the creature's melee damage off the heart object's health, which already starts at DUNGEON_HEART_OBJECT_HEALTH and regenerates. - While it hits a heart it looks again each tick (the original picks a target again while attacking, 0x45E9F0 calling 0x45CB00) and turns on any fighter that comes into sight. It never goes back to the heart while a fighter is in sight. A fighter behind a closer worker counts. - Tiles next to the heart that are walls are skipped before any path search, and the search stops at the first tile it can reach. - A heart it can't reach at all, even through doors it can break, is dropped as the target, so the creature does something else instead of standing still. Enemy doors on the way are still broken down. The attack target can now be a heart object, so getAttackTarget returns an IEntityController. What happens when the heart is destroyed (the keeper losing, level win or loss) is not done here. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts: - CreatureState.java: both sides added imports (IEntityController from this PR, Task and TaskType from master's tonihele#551 lair recovery). Kept all three. Post-merge fix: - DungeonHeartAttackTest: master's CreatureController constructor now takes a GameEventService (tonihele#778). The test passes a stub for it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A creature that should run from an enemy stood its ground in any Dungeon Heart, so an imp claiming the ruins of a beaten keeper's heart attacked the heroes there and was killed. On level7 the Giants that patrol Gormagon's old dungeon killed the player's imps about every 100 ticks this way, while in DK II they lose none. Now a creature only stays to fight in its own heart, and only while the heart still stands. Anywhere else it flees as usual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a creature hit a heart it only turned on a fighter, so heroes that dug into a dungeon kept hitting the heart while the keeper's Imps worked next to them. In DKII.EXE the target choice (0x45CB00) that runs again while attacking takes the heart over a worker target only when the heart is nearer than that worker. Do the same when picking a target again, as the first pick already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In DK II a creature gains its own experience per second only while it fights another creature. Hitting a Dungeon Heart or other objects teaches it nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every health change reset the own land regeneration timer, so a creature that was hit at least once a second never regained any health. An Imp fighting heroes in its own Dungeon Heart died without healing at all. DKII.EXE's creature tick (0x488930) adds the own land health increase on every tick on the creature's own land, whatever happens to its health. Regenerate every second on a fixed beat instead, and don't reset the timer on damage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In their own Dungeon Heart non-fighters no longer flee, but they also chased any enemy they could see and fought it until they died. In DK II an imp only hits back at an enemy that is attacking it in melee reach and otherwise goes on working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's imps keep working next to heroes that are after someone else, but go into their withdraw state the moment any enemy that isn't an imp picks them as its target (0x45EC80 with 0x45EC10), before it reaches them. The fight state (0x45F030) runs the same check every turn, so an imp that is hitting back turns away when the hero turns on it. Near their own standing Dungeon Heart, within 13 square tiles of its centre (0xD000 in 0x45BDF0), creatures stand their ground and imps hit back at an enemy in reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II sends a keeper's withdrawing creature to its Dungeon Heart's centre plus or minus 2 tiles on each axis, the sign picked at random (0x4611D0). The withdraw (state 0xCB) ends on arrival (0xCA) and an Imp goes back to its job loop (0x463DF0). Near its heart it then fights the hero it meets (0x45BDF0, where an Imp's reach is one tile), so Imps hit and run instead of standing in a fight or running far away. - Withdraw to a random corner 2 tiles from the heart's centre instead of always the top-left one. - A non-fighter's FLEE ends when it arrives; it withdraws again if an enemy is still after it. - An Imp near its heart hits back at an enemy within one tile. - A worker also weighs withdrawing during its own swing, as 0x45F030 runs 0x45EC80 every turn; the swing isn't restarted as FIGHT meanwhile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In DK II an attacker of a Dungeon Heart doesn't go for the heart itself but for the nearest of the three Arch Pillars around it (object type 94 in the heart room, 0x45CB00), so attackers end up spread around the heart. A creature now hits the heart from a ring tile next to the pillar nearest to it, and a worker only draws it away while it is still on its way there. While hitting the heart, the creature picks its target again every 10 turns (0x45E9F0) instead of every turn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's withdraw point (0x4611D0) is 2 tiles either way of the heart room's position, which is a tile down and right of the heart's centre (room +0x27), and the position itself when the creature can't get there. On level 5 the Imps end on the corners of the heart's centre 3x3: (15,24) a quarter of the time and (17,26) otherwise. Our heart's centre 3x3 can't be walked on, so the creature stops on the tile next to the point, out of the centre. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0x4611D0 only checks that the point can be reached (0x4D0E60) and falls back to the room's position. Use the path search for both instead of assuming the heart's centre 3x3 can't be walked on, so the creature stops next to the position only when it can't stand on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chase builds on both the heart attack (tonihele#758, arch pillars and the 10-turn re-pick) and the Imp withdraw to the heart (tonihele#844). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hasing DK II's fight state picks a target again (0x45CB00) when the creature steps onto another tile or every 10 turns, an Imp every 4 (the 4-bit counter in +0x3E6, 0x45E9F0), and keeps the target it has when the pick finds nothing. While it chases a creature out of reach (state 8, 0x470E30) it drops the target and picks again every turn, and only chases on while that pick is the same creature. OpenKeeper kept a creature target until it was gone and only picked again every 10 turns while hitting a heart. getAttackTarget now uses the same cadence for every target: AttackTarget remembers the tile it was picked on, a creature in reach picks again on another tile or after 10 turns (Imps 4), and a chaser picks every turn and drops a target it no longer picks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In DK II a fighting creature doesn't drop a target that withdraws: the fight state (0x45F030) only drops one that is gone, off the map or not attackable, and a withdrawing creature stays attackable. While it chases a creature that withdraws (state 8, 0x470E30, the target walking to 0xCA/0xFB, 0x45F000) it counts the turns in +0x53D, and after ticks per second x GOOD_CREATURES_CHASE_ENEMY_DURATION_SECONDS (variable 213, 3 s) for a good creature or EVIL_CREATURES_CHASE_ENEMY_DURATION_SECONDS (214, 7 s) for an evil one it gives up: +0x53B = the target, drop it, back to what it was doing. 0x488930 clears +0x53B after 60 turns, and while it is set the target scans (0x45B140, 0x45B500, 0x45BAD0) skip creatures that withdraw. Otherwise they are fair game. OpenKeeper dropped a fleeing target at once and never picked one. Now AttackTarget remembers when the chase of a fleeing target started (it is only counted while the target is out of reach), the creature gives up after the level's chase duration and gets a ChaseBackOff component, and fresh picks leave fleeing creatures out of reach alone only for the 60 turns after giving up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After DK II's target pick (0x45CB00) has chosen a creature, the attackers of the creature first, a creature that isn't an Imp checks the enemy hearts in sight whenever it has no target or its target is a worker (creature data +0x686 bit 1): a heart room's Arch Pillar (object type 94) strictly nearer than the target replaces it. That runs after the attackers list too, so a worker that attacks a creature next to a pillar doesn't draw it off the heart. The heart attack let a worker that attacks the creature draw it away from the pillar. Imps hitting back near their own heart then turned every hero on them, and the hit on a withdrawing Imp lands anyway. Now only a worker nearer than the pillar draws it away, as for one that doesn't attack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In DK II a chasing creature (state 8, 0x470E30) that gets its target in range only changes back to the fight state; the fight state (0x45F030) starts the swing on a later turn, and only once the creature faces the target: CPhysicalThing_4B2AE0 turns it towards the target by at most its turn speed a turn (creature data +0x6A0 = level record +0x1310 / ticks per second, file offset 0xF20, in 2048ths of a full circle per second) and the attack waits until no turn is left. A Giant turns half a circle a second, an Imp two. OpenKeeper swung the moment the target came in reach, whichever way the creature faced, so a hero walking at a withdrawing Imp hit it as it went past. The FIGHT state now stops a creature that arrives and attacks from the next turn on, after turnToAttackTarget has turned it to the target at its turn speed. The creature field that was read as unk3cc is that turn speed and is renamed. Hearts are left to the heart attack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's creatures push each other aside as they move: the separation steering (0x4D2DF0, with 0x4D2B80 for each creature nearby) keeps two creatures apart by their radii, so an Imp that withdraws to its heart goes round the hero it runs from. The level 7 trace shows it: Imp 428, picked by the Giant 1.6 tiles away, runs past it 0.9 tiles off and is not hit. OpenKeeper's creatures walk through each other, and with the chase an Imp running to its heart, or walking to a job, went straight over the tile of the hero after it and took the hit. A creature that withdraws, and a worker walking to its job, now plans a way round the tiles the enemies it senses stand on, and goes through only when there is no other way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A creature gained its experience per second only while a swing or a spell cast was under way, and then only once for every full second of those, so in a melee it learnt about a quarter of what DK II gives. On level7 the level 1 hero Giant fighting keeper 3's Goblins reaches level 2 in the middle of that fight in DK II (tick 380). Here it was still level 1 when the fight ended and only reached level 2 around tick 1500. In DKII.EXE the per-tick callback of the battle state group (group 0x16, CState_476FC0 calls the group's tick function, 0x47A870) adds the creature data's experience per tick (+0x6B7, the experience per second divided by the ticks per second when the level loads, at least 1) times the level percentage, while the creature is in state 199 or 200 and its fight target is a creature. That is the whole time it is next to its target, waiting for the next swing too, but not while it walks up to it (state 8, which runs the same group callback but fails the state check). 0x457880 levels the creature up as soon as the experience reaches the level's need, and 0x48B120 scales the health to the new maximum, so the fight goes on with more health. CreatureExperienceSystem now gives the experience per second divided by the ticks per second on every tick a creature is fighting, swinging or casting at another creature without walking. Work keeps its once a second timer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II picks a fight target again on a new tile or every 10 turns only outside a fight: 0x45E9F0 returns before that pick when the creature's state class is the fight class (CState_478050 == 0x16), and the fight state 0x45F030 calls the pick (0x45CB00) only when the creature has no target (+0x502 is 0). So a creature hitting a creature in reach stays on it until it is gone or knocked out, or until it gets out of reach and the chase state 0x470E30 picks again every turn. OpenKeeper picked again every 10 turns while hitting too, and went for whichever enemy was nearest then. In level 7 the hero Giant at keeper 3's portal swapped between the Goblins hitting it, so the others got it from behind. getAttackTarget now keeps a creature target in reach while in the FIGHT or MELEE_ATTACK state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's heroes go for the heart's Arch Pillars and stop only once they are within their melee range and half a tile of one (0x45CB00 sets the range for an object target, 0x45E8F0 checks it in the fight state). The pillars stand at the room tiles 7, 16 and 18 (0x4DB700): 1.2 tiles north of the heart's centre and 1.1 tiles to each side, 0.6 tiles south. DungeonHeartTarget.isInReach was tile based, so an attacker stopped as soon as it stepped onto a tile next to the heart, and every later one stopped on the same spot. It now measures from the creature's position to the nearest pillar, and creatures walk only to the tiles next to the heart that reach a pillar from their centre. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…awing # Conflicts: # src/main/java/toniarts/openkeeper/game/controller/creature/DungeonHeartTarget.java # src/test/java/toniarts/openkeeper/game/controller/creature/DungeonHeartAttackTest.java
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts 88be3f1. DK II's path search (0x4D0320, 0x4D0150) works on a navigation grid that only the map tiles (CMap_44F370, CMap_44FC40), doors (0x4A66F0, 0x4A6800) and rooms (0x454FD0) write; creatures never go in it. Creatures only keep apart through the separation steering (0x4D2DF0, 0x4D2B80), which OpenKeeper now has (tonihele#917). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts: # src/main/java/toniarts/openkeeper/game/controller/creature/CreatureController.java # src/test/java/toniarts/openkeeper/game/controller/creature/CreatureControllerTest.java
# Conflicts: # src/test/java/toniarts/openkeeper/game/controller/creature/CreatureControllerTest.java
ChaseBackOff is an entity component but was not registered with the serializer, so it could not be sent over the network or saved. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Master's HealthSystem.isHorny now reads the creature definition, so the own-land regeneration test stubs getCreature, as tonihele#871 already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 20, 2026
…ht-style Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P55VempAatH4iFU1KdjdoA
…rawing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rawing Kept this branch's withdraw rules in shouldFleeOrAttack: a worker withdraws as soon as an enemy fighter picks it as its target (0x45EC80) and near its own heart hits back at an enemy a tile away, which covers tonihele#840's rule. Kept both sides' constants, and took master's fixtures in the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II keeps and picks a target that runs away like any other (0x45F030, 0x45BDF0), which is the rule behind tonihele#1374. This branch already carries it with the chase limit, the back-off and the Horned Reaper exemption; the test guards the kept-in-reach case the other tests miss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's target search for non-fighters (0x45BDF0) takes an enemy that is an Imp (creature type 1) wherever the Imp is, and any other enemy only near its own Dungeon Heart. In both cases the reach is one tile. The Imp then goes into the fight state (0x45CB00, state 199). OpenKeeper only had the near-heart part, so rival Imps worked side by side and kept claiming each other's floor back and forth. In DK II they fight when they meet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps this branch's target pick and chase back-off turns next to master's OTHER_ALIGNMENT_DISTANCE_FACTOR, and takes tonihele#844's attack line, where a non-fighter takes on an enemy Imp in reach anywhere (0x45BDF0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's enemy Imp check in 0x45BDF0 only asks whether the Imp can be attacked (creature flag 0x40 of +0x3EA, set in 0x45A8B0), not whether it is fleeing (0x100000), the same as for the targets of fighters that this branch keeps when they run away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 25, 2026
…t-by-fight-style Brings in the current tonihele#871, which carries tonihele#844 (62ae20b) and master. The target scan keeps this branch's single scored pick over all enemies and drops master's fighters-only pass: DK II's pick (0x45CB00) takes the nearest creature attacking it, else runs the scan of its fight style over every enemy (0x45B800, 0x45B140, 0x45BAD0, 0x45B500), and only when that finds a worker (flag 1 of creature data +0x686) or nothing does it take a heart pillar, if one is strictly nearer. It keeps master's isNoticed, the sight and hearing test those scans make (0x45B140, 0x45BAD0, 0x45B500), and drops the doubled hasRoomForAttacker. The natural enemy 7/8 now uses master's isOfOtherAlignment (0x45C640, 0x45B140) instead of its own copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DK II's enemy Imp check in 0x45BDF0 only asks whether the Imp can be attacked (creature flag 0x40 of +0x3EA, set in 0x45A8B0), not whether it is fleeing (0x100000), the same as for the targets of fighters that this branch keeps when they run away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # src/main/java/toniarts/openkeeper/game/controller/creature/CreatureState.java # src/test/java/toniarts/openkeeper/game/controller/creature/CreatureControllerTest.java
…able answers master needs Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…'s creature stub Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Master's tonihele#1414 and this branch both followed DK II's withdraw (0x4611D0). They now share one findWithdrawalTile: the lair and nowhere else when the creature has one (no route there and 0x4611D0 returns 0), else a heart corner two tiles off the heart's reference tile CRoom+0x27, else three tries at a random room's reference tile (bridges left out, 0x4C63D0), else the tiles away from the enemy or next to the creature. A keeper's creature that finds nowhere doesn't withdraw and doesn't run from the threat either. The withdraw is walked to its end, as on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r merge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch
added a commit
to scottyhutch/OpenKeeper
that referenced
this pull request
Nov 28, 2026
…master merged in) into fix/target-by-fight-style The withdraw is now the one tonihele#844 shares with master's tonihele#1414: a keeper's creature with a lair goes there or nowhere (0x4611D0), as this branch had it, and without one to a heart corner, a random room, then nearby tiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the Guard Room check on top of tonihele#844's withdrawal, and keep the enemy within reach in CreatureCallToArmsFightTest, as the target picking now drops a chased target it can't sense. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Still work in progress. Builds on #844. I've merged the current #844 and master into it.
Fixes #1374.
What was wrong
In OpenKeeper a fighting creature drops its target the moment the target starts to flee, and never picks a fleeing creature as a new target. In DK II heroes chase an Imp that withdraws for a few seconds, which is what spreads them round the heart's pillars on level 5 and keeps the Imps busy.
What DK II does
0x45E9F0): a creature picks its target again (0x45CB00) when it steps onto another tile or every 10 turns (an Imp every 4), and keeps its target when the pick finds nothing. It doesn't pick in the fight states.0x470E30): while the target is out of reach the creature drops it and picks again every turn, so it only chases on while that pick is the same creature. A creature that withdraws stays attackable (0x45F030only drops a target that is gone, off the map or not attackable).0x45F000) it counts the turns in +0x53D. After ticks per second x GOOD_CREATURES_CHASE_ENEMY_DURATION_SECONDS (variable 213, 3 s) for a hero, or EVIL_CREATURES_CHASE_ENEMY_DURATION_SECONDS (214, 7 s) for a keeper's creature, it gives up and goes back to what it was doing. +0x53B then holds the runaway,0x488930clears it after 60 turns, and meanwhile the target scans (0x45B140,0x45B500,0x45BAD0) skip creatures that withdraw.0x45CB00): after the pick, when the target is a worker, an Arch Pillar of an enemy heart in sight that is strictly nearer replaces it.0x45F030) swings on a later turn and only once the creature faces the target.0x4B2AE0turns it by its turn speed each turn (creature data +0x6A0, the field OpenKeeper read as unk3cc: a Giant turns half a circle a second, an Imp two).0x4D0320,0x4D0150) runs on a navigation grid that only the map tiles (0x44F370,0x44FC40), doors (0x4A66F0,0x4A6800) and rooms (0x454FD0) write to. Creatures only keep apart through the separation steering (0x4D2DF0,0x4D2B80), which OpenKeeper has now (Keep walking creatures apart like DK II's separation steering #917).Creatures that run away (#1374)
#1374 is the same rule this PR already brings in: on master a creature drops a target that starts to run (
getAttackTarget) and never picks one that runs (getNearestEnemy), so a scared creature is left alone next to its enemies.0x45BDF0) only asks for the "attackable" flag (bit 0x40 of +0x3EA), never the "fleeing" bit (0x100000 of the same field), and the fight state (0x45F030) keeps a target for as long as it is there and attackable. So a creature that runs is kept and picked like any other.0x470E30) counts the turns the target runs while out of reach in +0x53D and resets the count when it stops running (0x45F000). After ticks per second x variable 213 (3 s) for a hero, or variable 214 (7 s) for a keeper's creature, it gives up. +0x53B is then set, the target scans (0x45B140,0x45B500,0x45BAD0) skip creatures that run away, and0x488930clears it after 60 turns.0x45E1B0), so it never gives up.Change 2 below covers all of this (
AttackTarget.chaseStartTime,ChaseBackOff). I've addedCreatureAttackTargetTest.aTargetInReachThatRunsAwayIsKeptfor the one case the other tests didn't cover.Changes
getAttackTargetuses the DK II cadence for every target.AttackTargetremembers the tile it was picked on.AttackTargetremembers when the chase of a runaway started (counted only while it's out of reach). After the level's chase duration the creature gives up and gets aChaseBackOffcomponent, and for 60 turns fresh picks leave runaways out of reach alone.0x45E9F0doesn't pick in the fight states).turnToAttackTargethas turned it to the target at its turn speed.Creature.unk3ccis renamed toturnSpeed.CreatureAttackTargetTestnow lets the creature sense its target, because a chaser out of reach only keeps a target it picks again.I've dropped the earlier change that made withdrawing Imps and working Imps plan a path round the enemies' tiles. DK II doesn't do that (see above), and with the separation steering in, it made things worse: on level 7 the Imp deaths over 16 runs went from 39 without it to 66 with it, and on level 5 the heart fell in 3 of 10 runs with it and none without it.
Tests
DungeonHeartAttackTest: target picked again on another tile or after 10 turns, an Imp every 4 turns, a chaser picks every turn and stops when the target is out of sight, a fleeing worker is chased, a hero gives up after 3 s and backs off, a keeper's creature chases for 7 s, the back-off lasts 60 turns but a runaway in reach is still hit, a worker attacking a creature at the pillar doesn't draw it away, a creature turns at its turn speed, a fighter keeps the creature in reach.CreatureStateTest.fighterAttacksFromTheTurnAfterItArrivesOnceItFacesTheTarget.They don't need the DK2 files (checked in a checkout without
assets/Converted).Results
Headless runs of the current my-build (which has #917 and the walk speed and swing fixes), 3600 ticks, nobody playing keeper 3, with this branch as it was and without the path planning round enemies:
Two gaps are left, which is why this is still WIP:
0x45E8F0), but taking it out made level 7 worse.0x45F030calls0x45AA20on the one it swings at, and that one turns on the attacker unless its own target is a creature nobody else is attacking. So a hero hitting a pillar turns on an Imp that swings at it. That matches a DK II trace of level 5, where the heroes on a pillar turned on an Imp that attacked them 1 to 7 turns after it came. But with only that rule the Imps run off and never come back, the share drops to 0-10 % and the heart falls in all 6 runs. In DK II an Imp that withdraws goes straight back to the heroes (states 0xCA -> 1 -> 0xA -> 6 -> 8 -> 0xC7), and OpenKeeper's Imps don't do that yet. So I've kept that rule out of this PR until the Imps come back like they do in DK II.Last commit: Keep fighting the creature in reach instead of picking another
On level 7 a level 1 Giant fights three Goblins at keeper 3's portal. In DK II it stays on one Goblin until that one is knocked out, then takes the next. In OpenKeeper it picked again every 10 turns while it was hitting, and went for whichever Goblin was nearest at that moment.
The pick on a new tile or every 10 turns (
0x45E9F0) only runs outside a fight: it returns before the pick when the creature's state is in the fight class (CState_478050() == 0x16). A DK II run of level 7, logged once a turn, shows the Giant changing target only after a Goblin is knocked out or while chasing.CreatureController.getAttackTargetnow keeps a creature target that is in reach while the creature is in the FIGHT or MELEE_ATTACK state. Test:DungeonHeartAttackTest.fighterKeepsTheCreatureInReachItFightsWhenAnotherIsNearer.Newest commit: Don't withdraw from an enemy at one of our Guard Rooms
When a scared creature's back-off time runs out, DK II first asks whether the enemy creature it fights is in or near one of its keeper's Guard Rooms: inside the room's bounds widened by the level's guard room reporting distance, 7 tiles in the original levels (
0x460B50, called from the back-off state0x4602E0). If so the creature doesn't withdraw and stays in the fight. Neutral creatures and heroes never pass the test.BACK_OFF now asks
isEnemyAtOurGuardRoombefore it withdraws when the time is up. Not done: in that case DK II also weighs the two keepers' strength around the creature and can send for help from the Guard Room (0x4FAC40,0x4752B0).Tests in
CreatureBackOffTest:scaredCreatureDoesNotWithdrawFromAnEnemyAtItsGuardRoom,enemyIsAtOurGuardRoomWithinItsReportingDistanceOfTheRoomsBounds../gradlew buildpasses without the converted assets (1528 tests, 0 failures, 0 errors, 4 skipped).Built with help from Claude Code