From 7d32ea7cd4d131b812bd3886b6808efcab30b706 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 09:06:14 +0100 Subject: [PATCH 1/2] trySpawnAdditionalWildlifeForTribe: test predatorNearby for non-zero again The original tests the tribe's predatorNearby with `cmp word ptr [eax + ecx + 0x2a0], 0` and `jne` (0x005260D3, 0x005260E0). gynt's first version had `!= 0` and read 100%. 374411da4e (2026-11-09) wrote `> 0`, because the field is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to `ja`, the function's one differing instruction in a full build (98.7% raw, 95.2% normalised). `!= 0` is the same test on a ushort and gives the original's `jne`; a one-line comment says why. The tick counter's `field_0x288 = field_0x288 + 1` is `++field_0x288`, as the style fixer writes it (the same listing). No other change. Measured: a real build (main's /GL list and the two files of this branch, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without them. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Units/TribesState/trySpawnAdditionalWildlifeForTribe.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Units/TribesState/trySpawnAdditionalWildlifeForTribe.cpp b/src/OpenSHC/Map/Units/TribesState/trySpawnAdditionalWildlifeForTribe.cpp index 340215f6bf..bb8e5040ad 100644 --- a/src/OpenSHC/Map/Units/TribesState/trySpawnAdditionalWildlifeForTribe.cpp +++ b/src/OpenSHC/Map/Units/TribesState/trySpawnAdditionalWildlifeForTribe.cpp @@ -26,7 +26,8 @@ namespace Map { if (tribeID <= 0) { return FALSE; } - if (this->tribes[tribeID].predatorNearby > 0) { + // A scare tick counter (0..800), not a flag: the original tests it for non-zero (> 0 loses the match) + if (this->tribes[tribeID].predatorNearby != 0) { return FALSE; } if (DAT_GameCore::instance.missionNumber1to20 == 38 && unitType == Map::Units::UT_CAMELSHBEAR) { @@ -44,7 +45,7 @@ namespace Map { int const _spawnX = DAT_UnitsState::instance.units[_unitID].x; int const _spawnY = DAT_UnitsState::instance.units[_unitID].y; int const _spawnHeight = DAT_UnitsState::instance.units[_unitID].terrainOrClimbHeight; - this->tribes[tribeID].field_0x288 = this->tribes[tribeID].field_0x288 + 1; + ++this->tribes[tribeID].field_0x288; if (this->tribes[tribeID].field_0x288 < spawnIntervalTicks) { return FALSE; } From 479d0feef03ced8568dd26bb565f7521b428d458 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 09:06:14 +0100 Subject: [PATCH 2/2] updateAnimalHerdBehaviorState: test predatorNearby for non-zero again The original tests the tribe's predatorNearby with `cmp word ptr [eax + 0x2a0], 0` and `jne` (0x005235AA, 0x005235B6). gynt's first version had `== 0` (then `!= 0`) and read 100%. 374411da4e (2026-11-09) wrote `> 0`, because the field is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to `ja`, the function's one differing instruction in a full build (98.0% raw, 95.2% normalised). `!= 0` is the same test on a ushort and gives the original's `jne`; a one-line comment says why. The unit loop is a `for` now, as the style guide asks. Its index still steps in the body, right after the call, as the original's `add esi, 1` at 0x005235D4 does (stepped in the loop's header, the match is lost), and it is written `++unitSelectionIndex`, as the style fixer writes it. No other change. Measured: a real build (main's /GL list and the two files of this branch, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without them. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Units/TribesState/updateAnimalHerdBehaviorState.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/Units/TribesState/updateAnimalHerdBehaviorState.cpp b/src/OpenSHC/Map/Units/TribesState/updateAnimalHerdBehaviorState.cpp index bc2a4cd3df..90597f0426 100644 --- a/src/OpenSHC/Map/Units/TribesState/updateAnimalHerdBehaviorState.cpp +++ b/src/OpenSHC/Map/Units/TribesState/updateAnimalHerdBehaviorState.cpp @@ -11,14 +11,15 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00523590 void TribesState::updateAnimalHerdBehaviorState(int tribeID) { - if (tribeID <= 0 || this->tribes[tribeID].predatorNearby > 0) { + // A scare tick counter (0..800), not a flag: the original tests it for non-zero (> 0 loses the match) + if (tribeID <= 0 || this->tribes[tribeID].predatorNearby != 0) { return; } - int unitSelectionIndex = 0; - while (unitSelectionIndex < this->tribes[tribeID].size) { + for (int unitSelectionIndex = 0; unitSelectionIndex < this->tribes[tribeID].size;) { int const unitID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getUnitIDForIndexInTribe, this)( tribeID, unitSelectionIndex); - unitSelectionIndex = unitSelectionIndex + 1; + // Stepped here, right after the call (in the loop's header, the match is lost). + ++unitSelectionIndex; if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_NORMAL && !DAT_UnitsState::instance.units[unitID].dying && DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue == 2) {