Skip to content

Pick the enemy to attack by fight style and natural enemy - #1265

Draft
scottyhutch wants to merge 139 commits into
tonihele:masterfrom
scottyhutch:fix/target-by-fight-style
Draft

scottyhutch wants to merge 139 commits into
tonihele:masterfrom
scottyhutch:fix/target-by-fight-style

Conversation

@scottyhutch

@scottyhutch scottyhutch commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #871.

A creature picks the nearest enemy it senses (one already attacking it first), whatever its fight style. In DK II the fight style decides: Goblins, Salamanders and Rogues (Flankers) and Warlocks and Dark Elves (Support) go for an enemy a Troll or Bile Demon already holds, and Mistresses, Vampires and Dark Angels (Blitzers) go past the front line for the enemy's casters.

What DK II does

The target pick (0x45CB00) first takes the nearest creature already attacking it. Only when there is none does it scan all enemies with the scan for its fight style (creature data +0x67E): 0x45B800 for Blitzers, 0x45B140 for Blockers, 0x45BAD0 for Flankers and 0x45B500 for Support (non-fighters use 0x45BDF0, see #840). Each scan keeps the enemy with the lowest score:

  • The score starts as the squared distance. Against a natural enemy it is 7/8 of that (0x45C640, also in every scan and in the "attacking me" pick): a good creature (IS_GOOD) against an evil one (IS_EVIL), and an evil creature against a good one.
  • The fight style then adds a number of times the creature's sight squared (data +0x77B, 4 tiles for every creature, so 16 tiles squared):
    • Blitzer: 1 for every target that isn't a Support creature.
    • Blocker: nothing, it takes the nearest.
    • Flanker: the number of Blitzers and Blockers already attacking the target (0x45B420). With none of those, 8 plus the number of Support creatures attacking it (0x45B490). With nobody on it, 17.
    • Support: the number of Blitzers and Blockers attacking the target, 9 with none.
  • The two counters look at the target's lists of attackers (+0x504 and +0x514). In the EXE both calls are mov ecx, esi with ESI the candidate.

So a Flanker or Support creature prefers a target one Blocker holds over a free one up to about 16 tiles nearer, and a Blitzer takes a Warlock 5 tiles away over a Knight 3 tiles away.

What changed

  • CreatureController.getNearestEnemy compares scores instead of distances. The "attacking me" pick uses the squared distance with the natural enemy factor, as 0x45CB00 does.
  • getTargetDistance: the squared distance, 7/8 of it for a natural enemy.
  • getFightStyleScore: the fight style term. It counts the attackers from the AttackTarget components, the same way hasRoomForAttacker does, so there's no new component.
  • CombatCreatureFixtures.fighter gives its creatures a sight of 4 tiles.
  • CreatureAttackTargetTest's level info now returns the creature data, because the pick looks up the target's flags.
  • Near an enemy heart the pick follows 0x45CB00 for every creature: the best enemy creature, and only when that is a worker (or there is none) the nearest Arch Pillar if it is strictly nearer, so a tie keeps the worker. A creature fighting a target in reach keeps it, a heart's pillar too, because the fight state only picks when it has no target and between swings it just waits (0x45F030, 0x48C9B0). Before, a creature hitting the heart left it for any fighter that came into sight.
  • A creature that starts a swing or a cast at another creature makes that one turn on it if it is fighting, unless its own target is a creature that nobody else attacks (0x45F030 calls 0x45AA20). So a hero hitting the heart turns on an Imp that swings at it.
  • A creature casting at a heart from out of melee reach picks its target again on every turn its spell is still recharging, and keeps the heart when the pick finds nothing (0x45F030 calls 0x45CB00 while 0x48C800 says the spell isn't ready). So a hero casting at the heart from further away turns on a defender that comes into sight while it waits.
  • A support creature (fight style 4, creature data +0x67E) picks its target again on every turn of the fight state that isn't in the middle of a swing or a cast, and takes the old target back when the pick finds nothing (0x45F030 calls 0x45CB00). DK II leaves out only a creature with a set attack target (+0x3E6 flag 4 with +0x3F9), which OpenKeeper doesn't have. So a support hero hitting the heart turns on a defender that comes into sight, where a Blocker waits for its next swing.
  • A creature with a lair withdraws to it (0x4611D0 goes to the object in creature +0x3B7 before it looks at the heart). Like DK II, it goes there and nowhere else: when the lair can't be reached the withdraw fails and the creature stays in its fight or back-off, the heart isn't tried after it (this came with merging the current Imps withdraw as soon as a hero picks them as its target #844, where a withdraw that finds nowhere no longer walks to a random point).
  • The lair withdraw remembers the tile the creature left and when, as every withdraw does at the end of 0x4611D0. Imps withdraw as soon as a hero picks them as its target #844 now walks a creature other than an Imp back to that tile once it has over three quarters of its health, within 500 ticks (0x4773D0).

Not in this PR

  • Creeping targets: DK II multiplies the distance by a level-scaled percentage (data +0x760) for a creature that is creeping (+0x3E6 flag 0x1000).
  • The sight and hearing checks: DK II uses the data sight and hearing (not scaled by level) and the distance after the 7/8. OpenKeeper keeps its own sensing.
  • In DK II the Blitzer's scan doesn't skip creatures that run away during the back-off after a given-up chase (no +0x53B check in 0x45B800). WIP: Chase creatures that run away, as DK II does, without getting Imps killed #871 applies the back-off to every style.
  • DK II counts the attackers in the target's lists, which a creature joins when it engages (0x45A550). OpenKeeper counts the AttackTarget components, which are set when the target is picked.

Tests

In CreatureCombatTest:

  • naturalEnemyIsPreferredOverASlightlyNearerOne: a keeper's creature takes a good creature 2.1 tiles away over another 2 tiles away.
  • flankersAndSupportGoForTheEnemyABlockerHolds: a Flanker and a Support creature each take an enemy 3 tiles away that a Blocker attacks over a free one 1 tile away.
  • blitzerGoesPastAFighterForASupportCreature: a Blitzer takes a Support creature 3 tiles away over a Blocker 1 tile away.

In DungeonHeartAttackTest:

  • creatureHittingTheHeartKeepsItWhileItFights, workerAsNearAsThePillarComesBeforeTheHeart, creatureHittingTheHeartTurnsOnAWorkerThatSwingsAtIt and creatureFightingACreatureNoOneElseAttacksKeepsItWhenAnotherSwingsAtIt.
  • creatureCastingAtTheHeartPicksAgainWhileItsSpellRecharges: with its spell ready it keeps the heart, while the spell recharges it takes the defender in sight.
  • supportCreaturePicksAgainOnEveryTurnOfTheFightBetweenSwings: in the middle of a swing at the pillar it keeps the heart. Between swings a Blocker keeps the heart and the support creature takes the defender in sight, and keeps the heart when it sees nobody.
  • creatureHittingTheHeartPicksItsTargetAgainEveryTenTurns is now creatureOnItsWayToTheHeartPicksItsTargetAgainEveryTenTurns, since that creature isn't in reach yet.

In CreatureControllerTest, creatureWithALairWithdrawsToIt: it walks to its lair and remembers the tile it left, and with the lair out of reach it doesn't withdraw at all.

The three CreatureCombatTest tests fail on #871 and pass with this change. They don't need the DK II files (run in a checkout without assets/Converted). ./gradlew build passes (1539 tests, 0 failures).

Built with help from Claude Code

scottyhutch and others added 30 commits October 28, 2026 13:10
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>
scottyhutch and others added 3 commits November 20, 2026 19:02
…rawing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-style

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scottyhutch added a commit to scottyhutch/OpenKeeper that referenced this pull request Nov 21, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P55VempAatH4iFU1KdjdoA

# Conflicts:
#	src/main/java/toniarts/openkeeper/game/controller/creature/CreatureController.java
#	src/test/java/toniarts/openkeeper/game/controller/creature/CreatureAttackTargetTest.java
scottyhutch and others added 2 commits November 24, 2026 22:26
…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>
scottyhutch and others added 7 commits November 25, 2026 11:33
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>
…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>
scottyhutch and others added 15 commits November 28, 2026 00:13
…-style

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>
…-style

# Conflicts:
#	src/test/java/toniarts/openkeeper/game/controller/creature/CreatureControllerTest.java
#	src/test/java/toniarts/openkeeper/game/controller/creature/CreatureTurncoatAllegianceTest.java
# 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>
…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>
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