Skip to content

Reimplement UpdatePitchman and UpdateEngineer from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on - #514

Merged
gynt merged 6 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-D-visibility-100
Nov 29, 2026
Merged

gynt merged 6 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-D-visibility-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Two more Map::Units update functions from gynt's units branch reimpl/map-units-updatefunctions (his draft #204). Both read 100.0% raw and normalised when the build uses main's function-visibility option, and 94.1% and 81.8% in the default build. Each one has to see the bodies of some callees and must not see one that main's /GL list shows it. One /GL list can't say both; cmake/function-visibility.txt can. Each commit cites the draft it builds on and credits gynt as co-author. One header commit adds enum names that UpdateEngineer uses (see Header changes).

Function Address Before Default build Option on
Units::UpdatePitchman 0x00551980 gynt's draft 49.22% (3cc1249; 43.99% at 6401342) 94.1% 100.0%
Units::UpdateEngineer 0x00564250 gynt's draft 36.79% (20c9a72; 31.91% at 01f37c5) 81.8% 100.0%

The status lines carry the default build's number, as main's numbers are default builds, with the remark 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on.

The option and the two entries

  • What the option does. -DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON (cmake: optional wrapper units built from function-visibility.txt #399, off by default) runs cmake/function-visibility-units.py over cmake/function-visibility.txt, the file gynt chose for these edges on 2026-11-12. A line at the left margin names a caller; the indented lines under it name the callees whose bodies that caller must see when it is compiled. Callers and callees joined by entries form one group, each group becomes one wrapper .cpp that #includes its members, the wrappers build without /GL, and their members leave the /GL list. A callee that no entry joins to a caller stays opaque to it.
  • Why these two need it. Both keep values in registers across calls whose bodies they must see: the unit helpers, and Reimplement 47 UnitsState functions at 100% and restyle 28 more #378's setupUnitSharingTileIDs, setupUnitSharingCurrentTilePosition and commitUnitLocation behind UpdatePitchman's commitUnitLocation. But both treat BuildingsState::updateBuildingSignpostCounter as opaque: the original reads the slot and loads this again behind it (UpdatePitchman at 0x00551C2F and 0x00551C45, UpdateEngineer at 0x00565A31 and 0x00565A3B). With that body visible our compiler does neither. Main's /GL list has the counter because UpdateBadBuildingGallows and UpdateBadBuildingDungeon need its body (their entries on main say so). UpdateEngineer also reads the slot again behind getStorageBuildingForResourceTypeAndAmount (0x0056580F), which our compiler skips once the lookup and its helper getBuildingStorageTypeForResourceType are both visible. With the option on, the counter and the lookup stay in the wrappers of their own callers, and each unit's wrapper holds the callees its entry names.
  • The entries (a commit of their own after the units), callees in address order:
    • UpdatePitchman, 10: setupUnitSharingTileIDs, IncrementAndOptionalUpdateAVValueRelated, ConsiderHavingABreakNowUnk (reached through UpdateWorker_ConsiderTakingABreakUnk, which returns its result), SetStateToFreetimeWalking, ComputeGoodsProduced, checkIfCitizenUnitIsAliveBasedOnState, hasUnitReachedDestination, setupUnitSharingCurrentTilePosition, UpdateWorker_ConsiderTakingABreakUnk, commitUnitLocation.
    • UpdateEngineer, 8: xyAreValid, isAIPlayer, getBuildingResourceAmountByUid, makeUnitStopWalkingByClearingPathProgressState, sitDownIfStanding, hasUnitReachedDestination, changeDestinationByAmount, deselectUnit.
    • Each edge is measured as cmake: function-visibility.txt entries for the /GL callers of #416, #433 and #438 #491's were: the unit compiled with the callee files in its unit, against the unit alone (quick_diff). A callee is listed when leaving it out of the unit's callee closure (without the counter) lowers the ratio, and the listed set reads what the whole closure reads: UpdatePitchman 0.5695 alone, 1.0000 with its 10; UpdateEngineer 0.4314 alone, 1.0000 with its 8. The cmake commit's message gives what each left-out callee reads.
  • /GL lines for both units and for Rendering/ViewportRenderState/xyAreValid.cpp, a callee UpdateEngineer has to see (100% on main, on no list until now). They serve the default build; with the option on, the wrappers replace them.

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp (a86aceb03) with --resolve-wrapped-calls --ignore-security-cookie.
  • Small builds (two) of main e3646a8 with this branch's head: 294 sources (main's /GL list, the fade countdown's users, the two units with their callee closures, and every file of a manifest group that touches them), 304 functions, every listed file's resolver on, BUILD_OK both.
    • Option off, the default build: UpdatePitchman 94.1% / 81.7%, UpdateEngineer 81.8% / 75.8%.
    • Option on: both 100.0% raw and normalised, with no differing line.
    • In both builds UpdateBadBuildingGallows, UpdateBadBuildingDungeon, UpdateIronMine, UpdateInnkeeper, the counter, getBuildingResourceAmountByUid and xyAreValid read 100.0%.
  • Full builds (two): every file of main with all function and data resolvers on, 2,913 files and 2,931 functions, 0 failures, with the option off and on, each against main's build in the same mode: main 655adce for off (main e3646a8 adds only Reimplement 4 functions at 100%: loadMenuElement, checkSkirmishGameDefeat, UpdateAppleTree, Skirmish_SortAIOpponentOrder #510's four new files to it), main e3646a8 for on. Nothing on main reads lower in either mode.
  • Checks: a local lint finds nothing to change and gives 0 errors and 83 notes, all of the kinds below.
  • Not run in game.

What got them to 100%

Both started from gynt's drafts and went through our development branches. The statements are his; what the text needed is how they are arranged.

  • UpdatePitchman: every access reads the unit through DAT_CurrentUnitSlotID::instance (the draft's local copy of the slot is gone: the original keeps the global in a register and loads it again only behind a call that may change it). The twelve state blocks are one if / else-if chain whose arms fall out of it, so the compiler keeps the later of two identical tails, as the original has. The working path is the fall-through behind setDestinationForUnit (je at 0x00551B88) and behind setWorkplaceBuildingEntryAsTarget (je at 0x00551F4A), and three more branches go the original's way round.
  • UpdateEngineer: state 0 tests the rally point first (0x00564383), compares the moat with -1 (0x005644FB) and ends in a chain with two equal arms, as the original branches on the distance (0x0056460A .. 0x00564620). The dig states keep the dig tile's x and y in int locals across xyAreValid (0x00564A87, 0x00564A8E). In the oil pot state the compiler keeps the incremented worker count in ebx by itself (0x005654F0), and the stores come in the original's order. One store of the draft is gone: it stored the storage building into animationFrame and read it back from there, where the original keeps it in edi and stores it only to horseOriginStablesBuildingIndexUnk (0x0056580D, 0x00565821).
  • In both, the states use UnitState's names where main has one (UpdatePitchman its own states through state.pitchMan, as UpdateWheatFarmer does; UpdateEngineer US_CLIMBING_LADDER for 104). UpdateEngineer's orientation tests use CD_UNSPECIFIED, its moat flag is OpenSHC::Map::LogicHelpers::L_MOAT, its aiUnitBehaviourType tests use AIUBT_ENGINEERING and AIUBT_HARASS_SIEGE, and its other states, its instruction type 25 and its projectile type 8 use the names of the header commit. engineerManningSiegeStateRef_checkType is set to -2 in both, as main's UpdateMerchant and UpdateCageDog write it. The fade countdown has no (char) casts: it is a char in main's header.

Kept as they are

Header changes

One commit of its own, before the units, adds the names UpdateEngineer needs instead of casting numbers to the enums. New enumerators only; no value or type changes. 105 and 124 take the names gynt gave them in #293; the rest take main's _UNKNOWN_<n> form.

  • UnitState: US_UNKNOWN_10, US_UNKNOWN_13, US_UNKNOWN_14, US_UNKNOWN_15, US_UNKNOWN_16, US_RALLYING (105) and US_DIG_MOAT (124). UpdateEngineer's state switch (cmp eax, 0x7d at 0x00564331, byte table 0x00565F88, jump table 0x00565F1C) gives each an arm of its own: 10 at 0x00565B54, 13 at 0x00565931, 14 at 0x00565A0A, 15 at 0x00565AA8, 16 at 0x00565C86, 105 at 0x00564654 and 124 at 0x00564A37. It stores them into Unit::state (mov word ptr [reg + 0x138880C]): 10 at 0x005648F1 and 0x00565AEA, 13 at 0x00565925, 105 at 0x0056439E, 0x00564F62 and 0x0056527E, 124 at 0x005644AB (the dig-moat order) and 0x00564A37; and into Unit::cachedState: 14 at 0x005659E5, 15 at 0x00565708, 105 at 0x0056547B. 105 is the walk to the rally point or the assembly tile.
  • UnitInstructionType: UIT_UNKNOWN_25. Unit::targetingType is compared with 25 at 0x00565762 and set to 25 at 0x00565AE1.
  • EntityType: ET_UNKNOWN_8, the projectile type UpdateEngineer passes to UnitsState::shootProjectile (push 8 at 0x00565C4C).

Proposed, not changed here

  • DAT_UnitHasBecomeIdle is an undefined4 that only ever holds 0 or 1: a BOOLEnum candidate.
  • findNearestFriendlyMoatTileForDigging is declared BOOLEnum, but it returns a moat index, -1 for none.
  • advanceMoatDigProgress and removeMoat are declared BOOLEnum, and UpdateEngineer compares their results with 1, as UpdatePikeman does (Reimplement UpdatePriest, UpdateMerchantHorse and UpdatePikeman from gynt's units branch, under /GL (100%) #512).
  • getRequiredEngineerCountForSiegeBuilding returns undefined4, hence the (int) in front of its result.
  • ALG_MoatXResult and ALG_MoatYResult as int in TileMapState.hpp, and the (char) fields above as char, would let casts go here and in the unit functions on main.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 4 commits November 28, 2026 21:36
…ateEngineer uses

Names for the values UpdateEngineer (0x00564250) uses and main's enums don't name yet, so its text needs no casts
to the enums. They take main's <PREFIX>_UNKNOWN_<n> form, except 105 and 124, which take the names gynt gave them in
his PR 293: US_RALLYING and US_DIG_MOAT. New enumerators only; no value or type changes.

- UnitState 10, 13, 14, 15, 16, 105 and 124: the state switch at 0x00564331 (cmp eax, 0x7d; byte table
  0x00565F88, jump table 0x00565F1C) gives each an arm of its own: 10 at 0x00565B54, 13 at 0x00565931, 14 at
  0x00565A0A, 15 at 0x00565AA8, 16 at 0x00565C86, 105 at 0x00564654 and 124 at 0x00564A37. The function stores them
  into Unit::state (mov word ptr [reg + 0x138880C]): 10 at 0x005648F1 and 0x00565AEA, 13 at 0x00565925, 105 at
  0x0056439E, 0x00564F62 and 0x0056527E, 124 at 0x005644AB (behind the dig-moat order, UIT_DIG_MOAT) and 0x00564A37;
  and into Unit::cachedState ([reg + 0x138880E]): 14 at 0x005659E5, 15 at 0x00565708, 105 at 0x0056547B.
  105 is the walk to the rally point or the assembly tile.
- UnitInstructionType 25 (UIT_UNKNOWN_25): Unit::targetingType ([reg + 0x13888E8]) is compared with 25 at
  0x00565762 and set to 25 at 0x00565AE1.
- EntityType 8 (ET_UNKNOWN_8): the projectile type UpdateEngineer passes to UnitsState::shootProjectile (push 8 at
  0x00565C4C).

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

Units::UpdatePitchman, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his
commits on the file: 6401342 at 43.99%, 3cc1249 at 49.22%, then 974c32f's clang-format), through the forms
on our development branches. The text reads a true 100.0 / 100.0 when updateBuildingSignpostCounter is not visible
to it, which is how the original was built (see the end), and main's function-visibility manifest can say so: with
OPENSHC_FUNCTION_VISIBILITY_UNITS on and this unit's entry (a commit of its own after the units), it reads 100.0 /
100.0 with no callee hidden by hand. With the option off, the default, the counter's /GL line shows it the body
and it reads 94.1 / 81.7. The statements are his; what the text needed is how they are arranged.

1. Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy of the slot is
   gone. The original keeps the global itself in a register and loads it again only behind a call that may change
   it, which a local copy never does.
2. The twelve state blocks are one if / else-if chain whose arms fall out of it, instead of separate
   `if (state == X) { ...; return; }` blocks (with returning blocks the compiler keeps the earlier of two identical
   tails, with arms that fall out of a chain the later one, as the original has).
3. The working path as the fall-through, in two places: behind setDestinationForUnit (je at 0x00551B88 to the
   US_DISAPPEAR exit) and behind setWorkplaceBuildingEntryAsTarget (je at 0x00551F4A to the ULS_REMOVE exit), each
   `if (call) { rest } else { exit }` where the draft had an early exit.
4. Three more branches the original's way round: one early exit turned into the last exit of its block, and two
   if / else with their arms exchanged (each negates one condition and exchanges the two blocks).
5. The fade countdown without `(char)` casts (a char in main's header); the calls that
   return BOOLEnum tested by truthiness; the pitchman's own states by their names in UnitState_PitchMan (through
   `state.pitchMan`, as UpdateWheatFarmer does), the shared states and the resting state 5, which has no entry
   there, by the generic names; the destination numbers by their enum names.

Visibility. The original reads the slot and loads `this` again behind the working state's first
updateBuildingSignpostCounter call (0x00551C22; slot at 0x00551C2F, `mov ecx` at 0x00551C45); with that callee
visible our compiler does neither. Behind commitUnitLocation (0x00552035) the original keeps the unit pointer in
esi; ours does too now that commitUnitLocation's callee setupUnitSharingCurrentTilePosition and its callee
setupUnitSharingTileIDs are visible (both on the /GL list since PR 378). UpdateBadBuildingGallows and
UpdateBadBuildingDungeon need the counter's body (main's manifest says so), and this unit must not see it; one /GL
list cannot say both, the manifest can: the counter stays in Gallows' and Dungeon's wrapper, and this unit's
wrapper holds every callee it names.

Measured with real builds of main e3646a8 with this branch: 294 sources (main's /GL list, the fade
countdown's users, the two units of this branch with their callee closures and every file of a manifest group
that touches them), 304 functions, every resolver of the list on, BUILD_OK each:
- option off, the default build: 94.1 / 81.7;
- option on, with this unit's entry (the manifest commit after the units): 100.0 / 100.0, no diff entry.
On an earlier tree (main 8e1e77f with PR 378's earlier head) the option alone, with no entry for this unit,
read 53.0 / 43.9: its callees in the units wrapper are opaque to it. The status line carries the default build's number.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ION_VISIBILITY_UNITS on)

Units::UpdateEngineer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his
commits on the file: 01f37c5 at 31.91%, e3244b8 at 36.74%, 20c9a72 at 36.79%, then 974c32f's
clang-format), through the forms on our development branches. The text reads a true 100.0 / 100.0 when two
callees are not visible to it, which is how the original was built (see the end); in the default build,
where this tree's /GL list shows it both, it reads 81.8 / 75.8. The statements are his; what the text needed
is how they are arranged. One store of the draft is gone (item 9).

1. State 0, the rally point first: `if (goToRallyPoint != 0) { ...; return; }` in front of the moat tests
   (0x00564383), with one `someCount27++; return;` behind `if (findFreeEngineerAssemblyTile(...)) { set the
   destination }`.
2. State 0, moats: `moat > -1` (cmp -1 / jle at 0x005644FB). FILL_MOAT's two failures are two arms,
   `if (setXYBasedOnMoatID(moat, 2, ...) == 0) { fail } else { if (setDestinationForUnit(...)) { ...; return; }
   fail }`, and the first arm is written `targetingType = 3; someCountDown -= 20;`: the original computes the unit
   pointer in front of the countdown and stores through it behind (0x00564576 .. 0x00564592), which also keeps
   the moat in edi (0x005644F9). The second arm joins DIG_MOAT's failure through eax (0x005645E8 to 0x005644C0),
   the compiler's own merge.
3. State 0's last choice as a chain with two equal arms: `resourceToDeposit != 0` -> sit down, `distance > 400`
   -> idle, `distance > 96` -> state 2, else -> state 2. The original loads the distance into a register and
   branches (movzx at 0x0056460A, cmp ax at 0x00564611, one `state = 2` at 0x00564620), as the soldiers' chains
   do; a two-way if / else compiles to setle. With the branch back, the function's constant 1 sits in edx as in
   the original.
4. State 105: one `someCount27++; return;` behind `if (reached) { if (find...) { set the destination } else {
   facingDirection = 4; } }`. The compiler copies that tail itself (0x005646D8 and 0x005646F9); written twice,
   it merged one copy with the rally block's.
5. The walk states: movementSpeed as `resourceToDeposit != 0 ? 2 : 1` (setne and a 32-bit add at 0x005647A9 /
   0x005647AC, and at 0x0056495E).
6. The two dig states: the dig tile's x and y as int locals in front of xyAreValid, used for the check and for
   the tile (movsx edi / ebp at 0x00564A87 / 0x00564A8E, kept across the call; the orientation call reads the
   fields again); in the dig state, the unit on the tile as an int local in front of its test (movsx at
   0x00564B71).
7. State 2 and the idle state: the idle flag set and tested in two statements (0x00564E74 / 0x00564E80);
   `state = 105; someCount27++;` in that order (the unit pointer is computed in front of the add and the
   store stands behind it, 0x00564F4C .. 0x00564F62 and 0x0056526C .. 0x0056527E); in the idle state, the manned
   engine's index as an int local behind the targeting test (movsx at 0x00565202, 32-bit compare at 0x00565209);
   in state 2 the draft's early return, `if (!isAIPlayer(units[slot].owner)) { return; }`. In the idle state the
   rest stands inside
   `if (DAT_UnitHasBecomeIdle != 0) { ... }`: a unit that is not idle goes to the state's last test instead of
   returning (je at 0x00565133 to 0x00565287). That test cannot hold there, the two moat targeting types set the
   flag just above, so what happens is the same.
8. Walking to a siege building: the engineer count compared signed, `employeeCount < (int)getRequired...()`
   (jge at 0x0056535A), and both entry distances as `<= 1` (cmp 1 / jg at 0x0056537D and 0x0056539B).
9. The oil pot (state 9): the carrying arm first (0x005654B2); no local for the worker slot, the call passes
   `currentEmployeeCount` and the compiler keeps the incremented value in ebx across hasUnitReachedDestination
   by itself (0x005654F0); `workerUID[0] = uid;` in front of `field_0x3c4 = 1;` (0x0056567F .. 0x0056568C) and
   `workerID[0] = slot;` in front of the frame statement (0x005656A7 / 0x005656AE); `animationCycleNumber = 0;`
   at the start of both arms of the uid test (the original stores it between the compare and the jump,
   0x005656D0); the pitch test as the original's chain, `pitch <= 0` -> fetch, `engineerUnitID != 0` -> roam,
   `pitch < 9` -> fetch (0x005656D8, 0x005656E2, 0x00565729).
   Fetching pitch (state 12): the storage building in an int local. **The draft also stored it into
   animationFrame and read it back from there; the original keeps it in edi and stores it only to
   horseOriginStablesBuildingIndexUnk (0x0056580D, 0x00565821).** The failed access test is the else arm, out of
   line as in the original (je at 0x0056582F to 0x005658DB).
10. The fade state's end as `if (isDisappearingUnk != 0) { ...; return; } else { commitUnitLocation(...);
    return; }`: the commit arm stands out of line.
11. The fade countdown without `(char)` casts (a char in main's header); the moat flag as
    OpenSHC::Map::LogicHelpers::L_MOAT; aiUnitBehaviourType against AIUBT_ENGINEERING / AIUBT_HARASS_SIEGE; the
    orientation against CD_UNSPECIFIED; state 104 by UnitState's US_CLIMBING_LADDER; the states 10, 13 .. 16, 105
    and 124, the instruction type 25 and the projectile type 8 by the names the header commit before this one
    adds; the siege-state check type set to -2, as main's UpdateMerchant writes it.
12. What stays as it looks: states 14 and 15 keep a body each, because the original has two arms (0x00565A0A,
    0x00565AA8) and one shared arm loses the match; `moat > -1` stays, as the original compares with -1; and the
    two isAIPlayer calls, clearOrDeselectUnitFromSelection and the pitch storage lookup read the unit's owner
    again instead of the `owner` local, which loses the match there.

Headers this file runs into (not changed here): findNearestFriendlyMoatTileForDigging is declared BOOLEnum but
returns a moat index, -1 for none; advanceMoatDigProgress and removeMoat are declared BOOLEnum and the original
compares them with 1; getRequiredEngineerCountForSiegeBuilding returns undefined4, hence the `(int)`.

Visibility. The original keeps the unit pointer across xyAreValid (0x00564AB8) and across isAIPlayer
(0x00564ECC, 0x005651DA), so xyAreValid gets a /GL line here (isAIPlayer has one already). Two callees it does not see through:
- updateBuildingSignpostCounter: it loads `this` again in front of the second call (0x00565A31) and reads the
  slot again behind it (0x00565A3B); with that callee visible our compiler does neither and gives the target
  building and the slot each other's registers for the whole function;
- getStorageBuildingForResourceTypeAndAmount: it reads the slot again behind the call (0x0056580F). Ours does
  that only while the lookup's own helper getBuildingStorageTypeForResourceType is not visible (or the lookup
  itself is not); with both on the /GL list the compiler knows the lookup writes nothing and keeps the pointer.

With OPENSHC_FUNCTION_VISIBILITY_UNITS on, main's manifest says it: this unit's entry (the manifest commit after
the units) names the callees it needs and neither of those two, which stay in the wrappers of their own callers.

Measured with real builds of main e3646a8 with this branch: 294 sources (main's /GL list, the fade
countdown's users, the two units of this branch with their callee closures and every file of a manifest group
that touches them), 304 functions, every resolver of the list on, BUILD_OK each:
- option off, the default build: 81.8 / 75.8; xyAreValid and isAIPlayer 100.0;
- option on, with this unit's entry (the manifest commit after the units): 100.0 / 100.0, no diff entry;
  xyAreValid 100.0. getBuildingResourceAmountByUid is main's plain function here, with no header body.
On an earlier tree, with the two callees' /GL lines taken off a local list, it read 100.0 / 100.0 too. The status line carries the default build's number.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ngineer

The two units sit on cmake/compiler-flags-gl.txt (the commits before) and get an entry each, at their addresses,
their callees in address order. No entry names BuildingsState::updateBuildingSignpostCounter: the original
treats it as opaque in these units (it reads the slot and loads `this` again behind it), while
UpdateBadBuildingGallows and UpdateBadBuildingDungeon need its body (their entries say so). With
OPENSHC_FUNCTION_VISIBILITY_UNITS on, the counter stays in their wrapper and the units' wrapper holds the callees
listed here, which is what a single /GL list cannot say.

Each edge is measured as sourcehold#491's were: the unit's file compiled with the callee files in its unit, against the unit
alone, quick_diff on an earlier stack (main 8e1e77f merged in) with every function resolver that has a .cpp and
every struct resolver on. The callees tried are the unit's whole callee closure without the counter. A callee is
listed when leaving it out of that set lowers the ratio; the listed set reads what the whole set reads.
UpdateEngineer's edges were measured with getBuildingResourceAmountByUid marked `inline`; it reads the same with
the getter plain, as it is on main and here, and the real builds below are of the plain getter.

- UpdatePitchman: 0.5695 alone, 1.0000 with its 10 listed callees (the whole set of 22 reads 1.0000).
  Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.6217, IncrementAndOptionalUpdateAVValueRelated 0.7404,
  hasUnitReachedDestination 0.7954, SetStateToFreetimeWalking 0.8317, ConsiderHavingABreakNowUnk and
  UpdateWorker_ConsiderTakingABreakUnk 0.9604 each, ComputeGoodsProduced 0.9652, and each of sourcehold#378's
  setupUnitSharingTileIDs, setupUnitSharingCurrentTilePosition and commitUnitLocation 0.9961.
- UpdateEngineer: 0.4314 alone, 1.0000 with its 8 (the whole set of 21, its /GL callees without the counter and
  without the storage lookup and its helper, reads 1.0000). Left out, hasUnitReachedDestination reads 0.5912,
  isAIPlayer 0.9442, sitDownIfStanding 0.9596, xyAreValid 0.9740, deselectUnit 0.9758,
  getBuildingResourceAmountByUid 0.9941, makeUnitStopWalkingByClearingPathProgressState 0.9953,
  changeDestinationByAmount 0.9976.
Neither needs the storage lookup (getStorageBuildingForResourceTypeAndAmount) or its helper, and UpdateEngineer
must not see them (it reads the slot again behind the lookup, 0x0056580F), so they stay in the wrapper of their
own callers.

Real builds, main e3646a8 with this branch, BUILD_OK each:
- narrow, 294 sources (main's /GL list, the fade countdown's users, the two units with their callee closures and
  every file of a manifest group that touches them), 304 functions, every resolver of the list on:
  option off, UpdatePitchman 94.1 / 81.7 and UpdateEngineer 81.8 / 75.8; option on, both 100.0 / 100.0 with no
  diff entry. UpdateBadBuildingGallows, UpdateBadBuildingDungeon, UpdateIronMine, UpdateInnkeeper, the counter,
  the getter and xyAreValid read 100.0 in both.
- full, on this branch before the header commit and the review fixes (the enum names, -2 for 254, comments,
  `int const`, this entry moved to its address), which leave both units' quick_diff listings and every generated
  wrapper unchanged; 2,913 sources (every file of main but the 12 that don't compile there, resolvers off for those), every
  function and data resolver on, 2,931 functions, 0 failed:
  option off against main 655adce's build (2,925 functions; main e3646a8 adds only PR 510's four files):
  average 99.53 against 99.54; UpdatePitchman 94.1 / 81.7, UpdateEngineer 81.8 / 75.8; nothing on main reads
  lower; UI::Menu::Constructor_Menu 98.4 -> 100.0 and handleMenuItems 97.9 -> 100.0 (they follow where functions
  land in the image); PR 510's four as on main;
  option on against main e3646a8's build (2,929 functions): average 99.46 against 99.46; both units 100.0 /
  100.0; nothing on main reads lower; UpdateMinerIronFetcher 98.0 -> 100.0, as in the earlier tree's build.
On an earlier tree (main 8e1e77f with PR 378's earlier head), the option on with no entry for the unit read
UpdatePitchman 53.0 / 43.9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 28, 2026
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

4 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 2 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
23 Prefer if-else over ternary 4
Where

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/Map/Units/UpdateEngineer.cpp:254 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Units/UpdateEngineer.cpp:257 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Units/UpdateEngineer.cpp:338 — ternary; the guide prefers extending the if-else chain
  • src/OpenSHC/Map/Units/UpdateEngineer.cpp:341 — ternary; the guide prefers extending the if-else chain

gynt added a commit that referenced this pull request Nov 29, 2026
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
gynt previously approved these changes Nov 29, 2026
@gynt
gynt added this pull request to the merge queue Nov 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 29, 2026
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 29, 2026
Merged via the queue into sourcehold:main with commit 10486fe Nov 29, 2026
4 checks passed
gynt added a commit to gynt/OpenSHC that referenced this pull request Dec 2, 2026
…Ladderman, UpdateTunneler and UpdateFireThrower from gynt's units branch, under /GL (100%) (sourcehold#516)

* reimplement: SHC_3BB0A8C1_0x005477C0 100.0% Reimplemented

Units::UpdateChild at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft
PR 204; his commits on the file: 06ebdf6 at 25.50% and the style commit 948147d at 27.32%, then
974c32f's clang-format), through the forms on our development branches. The statements are his; what the text
needed is how they are arranged and where three values live. Nothing behaves differently from the draft.

1. The fifteen "stay at home while enemies are around" tests as nested ifs with an early return in each arm:
   `if (mode != skirmish) { if (sumOfTotalEnemyUnitsCount != 0) {go home} } else if (someCount46 == 0) {go home}`.
   A combined condition compiles to setcc, where the original branches (0x0054792C .. 0x00547954 and fourteen
   more). The draft's polarity was already the original's.
2. One function-level `int i;` for every loop, and one `short random;` for the RNG value in states 15, 16 and 18.
   The compiler orders its stack slots by use count: the original keeps the loop counter in one slot
   ([esp + 0x10] at 0x0054823A, 0x005487BB and 0x00548B56) and the RNG value in one ([esp + 0x1c] at 0x00548744
   and 0x00548A3A); with a variable per loop and per state the slots come out in another order.
3. `random` is a short because the original divides it with idiv (state 15: idiv esi at 0x00548A47 and
   0x00548A5B). `v % 7` of an int variable compiles to a multiply by the inverse; of a short (promoted) or of a
   global read it divides. For the same reason state 0 switches on `SEC_RNG::instance.currentNumber2 % 25`
   (cdq / idiv at 0x0054795F / 0x00547965). State 18 takes its two offsets from `random` too: the original loads
   the lord's coordinates in front of each division and keeps the lord in a stack slot (0x00548D2C).
4. State 0's switch cases end in `break;` and the one nextRandomNumber2() after the switch serves them all (the
   original's cases end in their own jumps to it, 0x005479A4 .. 0x00547AA3; a call and a return in each case
   gave other epilogues).
5. The states after state 16 as one else-if chain without the returns that closed them, the alive check, the
   disappear state and the fallback in its final else. States 14 and 15 then jump forward into state 18's
   `destinationNeeded = 1; return` (0x005489BF, 0x00548AF5 -> 0x00548DF4) as in the original, which keeps the
   later copy of a tail the states share; with the returns the compiler kept the first.
6. Smaller arrangements: state 16's `found` flag set to FALSE in front of the destination test ([esp + 0x20] at
   0x00548759), its gfxNumber written in both arms of the frame test, the play rounds stored to this child and
   then copied to the other one (lea eax, [edx + 1] at 0x00547DBB and 0x005482EA), and state 18's three stores
   in the original's order (129, 1, 16 at 0x00548CFC .. 0x00548D0E).
7. The fade countdown without its `(char)` casts: the field is a char in main's Unit.hpp.

On main, this round's text pass: the BOOLEnum computeLadderClimbPath tested by truthiness; `(UnitState)10` and 13
to 16 as US_UNKNOWN_10 to US_UNKNOWN_16 (17 and 18 have no name yet); the `(char)` casts on the seven
Frames_Shared_UnitClimbingUp reads dropped (char in main's AnimationFrameData.hpp); `const` on owner and the home,
other, offset and leader locals; the comments on the shared loop counter, the shared random value and the five
ternaries say why without addresses; one comment on the two sign tests of the fade step; the worker-list comment
reworded; after the review, the five random updateTickTracker stores in one form without a cast, `found` as a
BOOLEnum local, and the counter's comment says that state 17 reads it after its search loop. The quick_diff listing
is the same before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 47.3 / 46.5 in both: it has no entry in cmake/function-visibility.txt, so
the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an
entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x005521D0 100.0% Reimplemented

Units::UpdateWheatFarmer at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft
PR 204; his commits on the file: 94a6fd5 at 39.73% and the style commit 98423cb at 24.52%), through the forms
on our development branches. The statements are his; what the text needed is how they are arranged:

1. The "walk to the next tile" tail (changeDestinationByAmount(slot, 1) and the two tile stores) is written out
   at the end of each of the four states that reach it, each with its own return, instead of once behind the
   else-if chain. The original has one physical copy in state 4 (0x0055265D) and the others join it at
   different depths: state 1 jumps to its start, state 7 behind its own push (0x005529EE to 0x0055265F), the
   store state behind its own two pushes (0x00552D90 to 0x00552666). Joins at different depths are separate
   copies in the source that the compiler merged.
2. What stands behind the chain is `if (DAT_UnitHasBecomeIdle != 0) { state = 110; }`, shared by the two death
   animations (state 111 and the alive check): both end in `gfx = frame + N;` and fall out of the chain. The
   original's join stands behind the alive check's block (0x00552EC1) and state 111 jumps forward into it
   (0x00552E5B). With one idle test per block the compiler kept the first block's copy.
3. The two walk ternaries as `index < size ? walking : arrived` (setge / and -0x80 / add 0x81).
4. State 8: the DamageLayer store written first (the tile index is loaded in front of the unit's stores).
5. Taking goods to the store: the walk tail in the if of a successful setDestinationForUnit, the failure
   behind it.

On main, this round's text pass: the BOOLEnum isFarmTileReadyForWheatStageChange tested by truthiness (four
places); the shared states by their UnitState names (US_DISAPPEAR, US_UNKNOWN_121, US_UNKNOWN_108, US_DEATH_01),
with US_DISAPPEAR stored through state.generic as the file's other shared states; the farm's grow state stored
through state.generic without a cast, as main's UpdateHopsFarmer does; the `(short)` casts on
`farmerDestinationTile - addXgetTile` and on DirectionAlgorithmState's orientation dropped; the `(char)` casts on
the six frame-table reads dropped; `const` on the locals; one comment on `idle` (read once: with two global reads
the listing changes); the two ternary comments without addresses; after the review, the two lookups of the wheat
store under one name (`storage`, as main's UpdateHopsFarmer and UpdateDairyFarmer name it), and a comment on the second read of the workplace (with `farm` instead, the listing changes). The
quick_diff listing is the same before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 37.8 / 35.9 in the narrow build and 37.7 / 35.9 in the full one: it has no
entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode
(main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x0055C7B0 100.0% Reimplemented

Units::UpdateCrossbowman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft
PR 204; his commits on the file: 43f68e4 at 31.63% and the style commit 21fe19a at 40.98%), through the forms
on our development branches. The statements are his; what the text needed is how they are arranged:

1. Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is
   gone.
2. State 0's end is one if / else chain with a single return behind it: the shoot-or-not code stands in the
   first arm and behind the second acquireShootTarget. The original keeps the later copy (0x0055C978) and the
   first arm jumps forward into it (0x0055C921). With early returns our compiler keeps the first copy.
3. The move states' and the appear state's walk-speed block in the original's form: the delayed arm first, the
   sheet store in every arm, one arm per reason to stand still.
4. Gathering at the rally point: `((int)mapTimeInTicks + slot) % 40`, the state store written in front of the
   counter.
5. `int building = targetID_OR_targetBuildingID;` in front of the switch (movsx ebx at 0x0055C833, between the
   switch's compare and its jump).
6. The wall-attack state in the form that matched in UpdateFireThrower; the damage is
   `!isGateOrTower ? 4 : 2` (sete at 0x0055CE00).
7. The shoot target as an int local where the original sign-extends it once and tests the register; the aim
   compare is `target >= 0`.
8. The idle state's two frame tables: the `(fixedRng & 1) != 0` arm first.
9. Three height sums as `terrain + building`. quick_diff cannot see this (it folds every displacement).
10. The fade countdown is stepped with -- on the char field (a char in main's Unit.hpp).

On main, this round's text pass: the BOOLEnum moveUnitToBehaviorTarget tested by truthiness (two places);
`LogicLayer & 256` as LogicHelpers::L_WALL_OR_GATEHOUSE and the `(short)` on BuildingLayer dropped;
`(UnitState)105` and 104 as US_RALLYING and US_CLIMBING_LADDER (123 has no name yet); the BOOLEnum array read as
`!IsGateOrTowerArray[...]` instead of `== FALSE`; the `(char)` casts on the 17 frame-table reads dropped; `const`
on the locals; the two ternary comments without addresses, one comment on `building` (read before the switch) and
one on `damage`; the TODO on the AttackInfo blocks dropped (main models them now); after the review, comments on
the `> 432` arm that can never be true, on the walk-speed arms that store the same values, and on the owner read in
the wall attack (with `owner` instead, the listing changes). The quick_diff listing is the same before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 62.5 / 53.6 in both: it has no entry in cmake/function-visibility.txt, so
the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an
entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x00563910 100.0% Reimplemented

Units::UpdateLadderman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR
204; his commits on the file: 01cf3a2 at 22.89%, afda7ec at 37.19% and the style commit 3631a97 at
37.35%), through the forms on our development branches. The statements are his; what the text needed is how they
are arranged:

1. The walk-speed block, three times (move to destination, appear, walking to the wall), as the original lays
   it out: the delayed arm first and the sheet store in every arm:
       if (delay != 0) { sheet = 1; if (delay > 70) { speed = -1; f30 = 0; } else { speed = 0; } }
       else if (runUp != 0) { sheet = 1; speed = 0; }
       else if (isMatchingSpeed != false) { sheet = 1; speed = 0; }    (move state only)
       else { sheet = 1; speed = 1; }
   Two arms with the same stores give the original's `jne A; cmp; je B; A: ...`: the compiler merges them. One
   arm on || does not (the compiler lays the arms out as for &&).
2. Every access through the global slot (no unitID local): the slot's register is ecx as in the original.
3. The fade countdown is stepped with -- on the field, a char in main's Unit.hpp. The original holds -1 in eax (or
   eax, -1 at 0x005639E4) for the substate store (0x005639E7) and this add (0x005639FE); with the field as an
   unsigned char our compiler added 255 as its own immediate.

On main, this round's text pass: `(UnitState)105` and `case 105` as US_RALLYING (103 has no name yet; the using
goes); the `(short)` on DirectionAlgorithmState's orientation and the `(char)` casts on the six frame-table reads
dropped; `const` on owner and tile; the ternary comment without its address. The quick_diff listing is the same
before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 47.2 / 34.9 in both: it has no entry in cmake/function-visibility.txt, so
the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an
entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x0054E6C0 100.0% Reimplemented

Units::UpdateTunneler, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his
commits on the file: 192307c at 35.44%, 5a1c78e at 42.20%, then 6565c1b and 974c32f for the build and
clang-format), through the forms on our development branches. It reads a true 100.0 / 100.0. The statements are
his; what the text needed is how they are arranged.

1. One copy of the removal tail. State 9's failed setDestinationForUnit and the collapse state end in the same
   six statements (rubble flag, destroyBuilding of the workplace, two toggles, cycle = 0, REMOVE). The original
   has them once, in the collapse state (0x0054EFEB), and state 9 jumps there (je at 0x0054ED95). Written twice
   the compiler merges the copies into that same code, but the second copy still takes its turn while the
   argument registers are handed out: they go eax, ecx, edx in rotation, and the original's run from 0x0054ED73
   to 0x0054EF2A has no gap (ecx edx eax / ecx / edx eax ecx / edx / eax ecx edx eax) where that copy's argument
   would stand. So state 9 says `goto removeTunnelAndUnit;`. With it the finished arm's argument is in ecx
   (0x0054EDD9) and its rubble flag is stored behind the push (0x0054EDE6), the two height calls take y / x /
   tile in edx / eax / ecx (0x0054EE45, 0x0054EE6A), the slot behind them is in edx (0x0054EE8D), and the damage
   call's four are in eax / ecx / edx / eax (0x0054EF09). The same text with the tail written out in state 9
   reads 98.2 / 80.0 in the same build. The collapse block's `int tile` is declared without a value and set in the
   next line: a jump must not pass an initialiser.
2. `int building = 0;` once at the top, and the states that need a building assign to it. With several
   definitions the variable keeps its home on the stack as in the original (store at 0x0054E702, read on the wall
   path at 0x0054F2DA).
3. The entry: `calculatedOwnerPlayerIndex = owner;` goes through the slot global and the isSelectable test
   through the local unitID. The original has the store in front of the compare (0x0054E6F5, 0x0054E6FB); with
   one index expression in both, the compiler moves the compare up.
4. The gathering state (105): one `someCount29++;` behind `if (reached) { if (find...) { set the destination }
   else { facingDirection = 4; } }`. The compiler copies that tail itself (0x0054E884 and 0x0054E8A6).
5. The move state: one arm per reason to stand still, the run arm last, and the sheet store in every arm (it
   stands between the compare and its jump at 0x0054E917 .. 0x0054E923).
6. Tunneling and collapse: the tunnel frame test is `>= 24` (cmp cx, 0x18 / jl at 0x0054EE38); the collapse
   state's damage arm comes first, `if (frame < 65) { damage } else { collapse }`, and the collapse tests
   `BuildingLayer[tile] != 0` first.
7. The wall attack's end has UpdateArabianArcher's arrangement (destroyed wall, the AI's give-up tests, one
   `cycle = 0` end).
8. The chain's last arms: `else if (checkIfCitizenUnitIsAliveBasedOnState(slot)) { death animation } else {
   disappear }` (je at 0x0054F70D to 0x0054F786).
9. Two conditional expressions where the original has no branch (setg at 0x0054E7DF, sbb at 0x0054F316); the
   fade countdown without `(char)` casts (a char in main's Unit.hpp).
10. Names: the tunneler's own states (UnitState_Tunneler, through state.tunneler) where its enum has the value;
    the states every unit shares keep the generic names (105 is US_RALLYING on main).

On main, this round's text pass: `(UnitState)105` as US_RALLYING (the using goes); the `(short)` casts on
`targetedBuildingTile - addXgetTile` and the `(char)` casts on the 12 frame-table reads dropped; `const` on unitID,
owner, state and the other locals; the comments on unitID, on the shared building variable, on the two ternaries
and on the goto without addresses or scores; the TODO on the AttackInfo blocks dropped (main models them now);
after the review, the states every unit shares stored through state.generic, as main's unit functions store them,
and comments on the owner read in the wall attack and the tribe read in the move state (each changes the listing
when replaced). The quick_diff listing is the same before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 59.6 / 56.3 in both: it has no entry in cmake/function-visibility.txt, so
the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an
entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x005769F0 100.0% Reimplemented

Units::UpdateFireThrower at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft
PR 204; his commits on the file: 0297f00 at 42.34% and the style commit 141a491 at 47.02%), through the forms
on our development branches. The statements are his; what the text needed is how they are arranged:

1. State 0's end: the shoot-or-not code (`if (state != MOVE) { state = RELOAD; ifOnADefensive...(slot); }
   return;`) written out behind each of the two acquireShootTarget calls; the original joins the two copies
   through a pointer to the state (lea at 0x00576B3C and 0x00576BA2, the join at 0x00576BA8). The cases 105,
   2 / MOVE / 123 and APPEAR are no longer nested in an if block.
2. The wall-attack state: one `cycle = 0` end behind an if / else; a failed moveUnitToBehaviorTarget only
   stores the state (the original computes the unit's offset twice there, 0x005770A5 and 0x005770AB); the two
   give-up tests each compute the danger and the tolerance themselves, the wall arm first.
3. Both walk-speed blocks in the original's form (the delayed arm first, the sheet store in every arm).
4. The fade countdown is stepped with -- on the char field (a char in main's Unit.hpp); it
   shares the -1 register with the substate store (or ecx, -1 at 0x00576A7B).
5. Gathering at the keep: `((int)mapTimeInTicks + slot) % 40` (cdq / idiv at 0x00576C21), `<= 160`, the state
   store written in front of the counter.
6. The shoot target as an int local where the original sign-extends it once and tests the register (the group
   leader's shot, the reload state); the building's half size as `widthOrHeight / 2`.
7. Three compares turned round again: aim `target >= 0`, fire `target > -1`, sit down `<= 400`.
8. Three height sums as `terrain + building`. quick_diff cannot see this (it folds every displacement); reccmp
   read 99.5 / 88.2 before it.

On main, this round's text pass: the BOOLEnum getKeepLocationForAIUnit and moveUnitToBehaviorTarget tested by
truthiness (four places); `(UnitState)105` and 104 as US_RALLYING and US_CLIMBING_LADDER (123 has no name yet); the
`(int)` on widthOrHeight dropped (an int on main); the `(char)` casts on the 12 frame-table reads dropped; `const`
on the locals; comments without addresses on the ternaries, on `building`, `damage` and the target coordinates; the
TODO on the AttackInfo blocks dropped (main models them now); after the review, `> 11 * 11` for the squared throw
distance, and comments on the `> 432` arm that can never be true, the owner read in the wall attack, the second
`frame > 0` test and the fire state's `> -1` (each changes the listing when replaced). The quick_diff listing is
the same before and after.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised):
a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this
round with their callee closures, every file of a function-visibility group that touches them) and a full build of
every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with
OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the
option off in both. With it on it reads 64.0 / 60.6 in both: it has no entry in cmake/function-visibility.txt, so
the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an
entry, reads 72.0 / 68.9 there for the same reason).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* status: UpdateDairyFarmer 93.9% and UpdateEngineer 85.0% in the default build

Both read higher with OPENSHC_FUNCTION_VISIBILITY_UNITS off since sourcehold#238 put more
UnitsState files under /GL (for UpdateDairyFarmer, CheckUnitProductionPaused).
Measured in this branch's full builds and in builds of main 859c1fe made the
same way, both modes:

- UpdateDairyFarmer 0x00554500: 85.2% -> 93.9% / 90.0% (normalised) off,
  100.0% / 100.0% on (unchanged).
- UpdateEngineer 0x00564250: 81.8% -> 85.0% / 79.6% off, 100.0% / 100.0% on
  (unchanged).

UpdatePitchman 0x00551980 still reads 94.1% off and keeps its line.

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

---------

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Opus 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.

2 participants