From 70ba2f3472e60f8654a3b22eb3db2fb85e4a046a Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:42 +0100 Subject: [PATCH 01/18] reimplement: SHC_3BB0A8C1_0x00530760 100.0% Reimplemented DetachLadderman, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). Taken unchanged (the build fix 43a17dfac had nothing to rename here). What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/DetachLadderman.cpp | 25 +++++++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/DetachLadderman.cpp diff --git a/src/OpenSHC/Map/Units/DetachLadderman.cpp b/src/OpenSHC/Map/Units/DetachLadderman.cpp new file mode 100644 index 0000000000..b3926cf1a5 --- /dev/null +++ b/src/OpenSHC/Map/Units/DetachLadderman.cpp @@ -0,0 +1,25 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00530760 + void Units::DetachLadderman(int unitID) + { + int tile = DAT_UnitsState::instance.units[unitID].tile; + DAT_TileMapState::instance.LogicLayer[tile] &= ~OpenSHC::Map::LogicHelpers::L_CLIMBABLE; + DAT_UnitsState::instance.units[unitID].wallDataID = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[unitID].y, tile); + DAT_UnitsState::instance.units[unitID].laddermanIsInPosition = 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ae4d052731..3fd92d213c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49629,7 +49629,7 @@ SHC_3BB0A8C1_0x00530690 | 0.0% | Pending SHC_3BB0A8C1_0x00530720 | 0.0% | Pending -SHC_3BB0A8C1_0x00530760 | 0.0% | Pending +SHC_3BB0A8C1_0x00530760 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005307B0 | 0.0% | Pending From d84f6afcfbd738b4ae6d201f01a6dfe20db74dcc Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:42 +0100 Subject: [PATCH 02/18] reimplement: SHC_3BB0A8C1_0x0051BE20 100.0% Reimplemented FindFirstOpponentWithKeep, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17dfac follows main's headers: PlayerData::keep becomes buildingEntryInfos[BEIE_KEEP], with BuildingEntryInfoEnum.hpp included; nothing else changed. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/FindFirstOpponentWithKeep.cpp | 33 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/FindFirstOpponentWithKeep.cpp diff --git a/src/OpenSHC/Map/Units/FindFirstOpponentWithKeep.cpp b/src/OpenSHC/Map/Units/FindFirstOpponentWithKeep.cpp new file mode 100644 index 0000000000..c294a1431f --- /dev/null +++ b/src/OpenSHC/Map/Units/FindFirstOpponentWithKeep.cpp @@ -0,0 +1,33 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/MapType2.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BE20 + int Units::FindFirstOpponentWithKeep() + { + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_SIEGE) { + return 1; + } + for (int playerID = 2; playerID < 6; ++playerID) { + if (DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id + > 0) { + return playerID; + } + } + return 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3fd92d213c..b507ea9bbc 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45911,7 +45911,7 @@ SHC_3BB0A8C1_0x0051BD10 | 0.0% | Pending SHC_3BB0A8C1_0x0051BDE0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051BE20 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BE20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BE60 | 0.0% | Pending From b3b565163449a4dd493ad08f73ef7b60c36d1dfd Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:42 +0100 Subject: [PATCH 03/18] reimplement: SHC_3BB0A8C1_0x00530B40 100.0% Reimplemented IncrementAndOptionalUpdateAVValueRelated, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). Taken unchanged (the build fix 43a17dfac had nothing to rename here). What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- ...crementAndOptionalUpdateAVValueRelated.cpp | 39 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp diff --git a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp new file mode 100644 index 0000000000..bc28818016 --- /dev/null +++ b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp @@ -0,0 +1,39 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00530B40 + void Units::IncrementAndOptionalUpdateAVValueRelated(int unitID, BOOLEnum updateAV) + { + // workTimer, workRelatedA, workRelatedB and workRelatedC are four timers, working is the current index + (&DAT_UnitsState::instance.units[unitID].workTimer)[DAT_UnitsState::instance.units[unitID].working] += 1; + int count = 0; + if (updateAV == FALSE) { + return; + } + DAT_UnitsState::instance.units[unitID].av = 0; + for (int i = 0; i < 4; ++i) { + DAT_UnitsState::instance.units[unitID].av += (&DAT_UnitsState::instance.units[unitID].workTimer)[i]; + if ((&DAT_UnitsState::instance.units[unitID].workTimer)[i] > 0) { + ++count; + } + } + if (count > 0) { + DAT_UnitsState::instance.units[unitID].av /= count; + } + DAT_UnitsState::instance.units[unitID].working += 1; + if (DAT_UnitsState::instance.units[unitID].working >= 4) { + DAT_UnitsState::instance.units[unitID].working = 0; + } + (&DAT_UnitsState::instance.units[unitID].workTimer)[DAT_UnitsState::instance.units[unitID].working] = 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b507ea9bbc..d8588348a3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49643,7 +49643,7 @@ SHC_3BB0A8C1_0x005309E0 | 0.0% | Pending SHC_3BB0A8C1_0x00530A90 | 0.0% | Pending -SHC_3BB0A8C1_0x00530B40 | 0.0% | Pending +SHC_3BB0A8C1_0x00530B40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530C40 | 0.0% | Pending From 404df96760dc6879002ae6edf0f81c225d963b59 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:43 +0100 Subject: [PATCH 04/18] reimplement: SHC_3BB0A8C1_0x00530EB0 100.0% Reimplemented PlayStockpileIsFullWarning, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). Taken unchanged (the build fix 43a17dfac had nothing to rename here). What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/PlayStockpileIsFullWarning.cpp | 39 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp diff --git a/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp new file mode 100644 index 0000000000..b30e31bbff --- /dev/null +++ b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp @@ -0,0 +1,39 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/BOOLEnum_00ee0fd8.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DWORD_00ee0fd4.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00530EB0 + uint Units::PlayStockpileIsFullWarning() + { + // guard of the function-local static holding the last warning time + if ((BOOLEnum_00ee0fd8::instance & 1) == 0) { + BOOLEnum_00ee0fd8::instance = (BOOLEnum)(BOOLEnum_00ee0fd8::instance | 1); + DWORD_00ee0fd4::instance = timeGetTime() - 60000; + } + uint elapsed = timeGetTime() - DWORD_00ee0fd4::instance; + if (elapsed > 60000) { + // "The stockpile is full my lord" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning11_wav_005abbf0); + DWORD now = timeGetTime(); + // the original returns whatever is left in eax (a void function in the source) + elapsed = SEC_RNG::instance.currentNumber2 / 5000; + DWORD_00ee0fd4::instance = now - SEC_RNG::instance.currentNumber2 % 5000; + } + return elapsed; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d8588348a3..34bc49c194 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49655,7 +49655,7 @@ SHC_3BB0A8C1_0x00530D70 | 0.0% | Pending SHC_3BB0A8C1_0x00530E00 | 0.0% | Pending -SHC_3BB0A8C1_0x00530EB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00530EB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530F20 | 0.0% | Pending From 2efa75fb90f31e8664550cb106c0be40d182a658 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:43 +0100 Subject: [PATCH 05/18] reimplement: SHC_3BB0A8C1_0x00549B30 100.0% Reimplemented SetRestingForUnit, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17dfac follows main's headers: Unit::field166_0x2fe becomes field_0x2fe; nothing else changed. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/SetRestingForUnit.cpp | 73 +++++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/SetRestingForUnit.cpp diff --git a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp new file mode 100644 index 0000000000..0ba01ef3ec --- /dev/null +++ b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp @@ -0,0 +1,73 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::Pathfinding::DestinationNeededEnum; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00549B30 + BOOLEnum Units::SetRestingForUnit(int unitID) + { + DAT_UnitsState::instance.units[unitID].idle += 1; + BOOLEnum restedEnough = FALSE; + if (DAT_UnitsState::instance.units[unitID].idle > DAT_UnitsState::instance.units[unitID].target) { + restedEnough = TRUE; + } + if (DAT_UnitsState::instance.units[unitID].destinationNeeded + != OpenSHC::Map::Units::Pathfinding::DNE_DESTINATION_HAS_BEEN_SET) { + DAT_UnitsState::instance.units[unitID].destinationNeeded + = OpenSHC::Map::Units::Pathfinding::DNE_DESTINATION_HAS_BEEN_SET; + int building + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::pickARandomPositiveFearFactorBuilding, + DAT_BuildingsState::ptr)(DAT_UnitsState::instance.units[unitID].owner); + if (building != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::setDestinationForUnit, DAT_UnitsState::ptr)( + unitID, DAT_BuildingsState::instance.buildings[building].buildingEntryX, + DAT_BuildingsState::instance.buildings[building].buildingEntryY, 0); + } else { + // No positive fear factor building available, resume normal state + DAT_UnitsState::instance.units[unitID].state.generic + = DAT_UnitsState::instance.units[unitID].cachedState; + DAT_UnitsState::instance.units[unitID].destinationNeeded = (DestinationNeededEnum)2; + } + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::hasUnitReachedDestination, DAT_UnitsState::ptr)( + unitID) + != FALSE) { + if (restedEnough != FALSE) { + if (DAT_UnitsState::instance.units[unitID].idle > DAT_UnitsState::instance.units[unitID].target) { + DAT_UnitsState::instance.units[unitID].banked + = DAT_UnitsState::instance.units[unitID].idle - DAT_UnitsState::instance.units[unitID].target; + } + DAT_UnitsState::instance.units[unitID].field_0x2fe = 0; + DAT_UnitsState::instance.units[unitID].state.generic + = DAT_UnitsState::instance.units[unitID].cachedState; + DAT_UnitsState::instance.units[unitID].destinationNeeded = (DestinationNeededEnum)2; + return TRUE; + } + if (DAT_UnitsState::instance.units[unitID].unitTypeSpecificRestingState > 0 + && DAT_UnitsState::instance.units[unitID].field_0x2fe == 0) { + DAT_UnitsState::instance.units[unitID].animationCycleNumber = 0; + DAT_UnitsState::instance.units[unitID].state.generic + = DAT_UnitsState::instance.units[unitID].unitTypeSpecificRestingState; + DAT_UnitsState::instance.units[unitID].field_0x2fe = 1; + return FALSE; + } + DAT_UnitsState::instance.units[unitID].destinationNeeded + = OpenSHC::Map::Units::Pathfinding::DNE_DESTINATION_NEEDED; + DAT_UnitsState::instance.units[unitID].field_0x2fe = 0; + } + return TRUE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 34bc49c194..162d89f377 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -61407,7 +61407,7 @@ SHC_3BB0A8C1_0x00549B20 | 0.0% | Pending SHC_3BB0A8C1_0x00549B24 | 0.0% | Pending -SHC_3BB0A8C1_0x00549B30 | 0.0% | Pending +SHC_3BB0A8C1_0x00549B30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00549C70 | 0.0% | Pending From f856c3916bf88b98ea8dbbeaaf705993b90b6128 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:43 +0100 Subject: [PATCH 06/18] reimplement: SHC_3BB0A8C1_0x00530CF0 100.0% Reimplemented SetStateToFreetimeWalking, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32fcf (2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17dfac follows main's headers: Unit::field166_0x2fe becomes field_0x2fe, and the function returns BOOLEnum as main's Units.hpp declares it (with BOOLEnum.hpp included); nothing else changed. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/SetStateToFreetimeWalking.cpp | 35 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp diff --git a/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp new file mode 100644 index 0000000000..0a5c795891 --- /dev/null +++ b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp @@ -0,0 +1,35 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::States::UnitState; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00530CF0 + BOOLEnum Units::SetStateToFreetimeWalking(int unitID, int shouldFindNewGoodThing, int param_3) + { + if (DAT_UnitsState::instance.units[unitID].field_0x2fe != 1) { + return 0; + } + DAT_UnitsState::instance.units[unitID].idle += 1; + if (shouldFindNewGoodThing == 0) { + return 0; + } + DAT_UnitsState::instance.units[unitID].substate += 1; + DAT_UnitsState::instance.units[unitID].animationCycleNumber = 0; + if (DAT_UnitsState::instance.units[unitID].substate >= param_3) { + DAT_UnitsState::instance.units[unitID].substate = 0; + } + // resting + DAT_UnitsState::instance.units[unitID].state.generic = (UnitState)121; + return 1; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 162d89f377..e87ca49302 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49647,7 +49647,7 @@ SHC_3BB0A8C1_0x00530B40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530C40 | 0.0% | Pending -SHC_3BB0A8C1_0x00530CF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00530CF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530D50 | 100.0% | Reimplemented From e8d4b3f8c8789e0fe14428edc82044d03719f524 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:44 +0100 Subject: [PATCH 07/18] reimplement: SHC_3BB0A8C1_0x00530D70 100.0% Reimplemented ComputeGoodsProduced, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 78.0% (idiv vs magic division); the file was last changed in c933f79ff (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (#286)"). The body is Wilps's, from reimpl/Wilps-2026-10-18, which gynt adopted in d914edf6b and merged in c933f79ff (#286). Taken unchanged (the build fix 43a17dfac had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/ComputeGoodsProduced.cpp | 43 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp diff --git a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp new file mode 100644 index 0000000000..a5c2970536 --- /dev/null +++ b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp @@ -0,0 +1,43 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + /* + example: goodsCount = 3, boost = TRUE for apple farm */ + + // FUNCTION: STRONGHOLDCRUSADER 0x00530D70 + int Units::ComputeGoodsProduced(int unitID, int goodsCount, BOOLEnum boost) + { + int productivity = DAT_GameState::instance.playerDataArray[DAT_UnitsState::instance.units[unitID].owner] + .fearFactorProductivityUnk; + DAT_UnitsState::instance.units[unitID].productivityDiv100 = 0; + // Lowered productivity means more breaks, not fewer goods. + if (productivity <= 100) { + productivity = 100; + } + // Skirmish modes boost productivity by 50. + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY && boost != FALSE) { + productivity += 50; + } + // Fractional bonus goods are kept as a percentage and added next time. + int bonusPercentage + = (productivity - 100) * goodsCount * 100 / 100 + DAT_UnitsState::instance.units[unitID].productivityMod100; + // held in a variable: the original computes quotient and remainder with one idiv + int divisor = 100; + DAT_UnitsState::instance.units[unitID].productivityDiv100 = (short)(bonusPercentage / divisor); + DAT_UnitsState::instance.units[unitID].productivityMod100 = (short)(bonusPercentage % divisor); + return DAT_UnitsState::instance.units[unitID].productivityDiv100 + goodsCount; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e87ca49302..bbd1bd7bc9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49651,7 +49651,7 @@ SHC_3BB0A8C1_0x00530CF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530D50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00530D70 | 0.0% | Pending +SHC_3BB0A8C1_0x00530D70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530E00 | 0.0% | Pending From dadf997d3af83fcba258b58e6d4956b9d5e7ed25 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:44 +0100 Subject: [PATCH 08/18] reimplement: SHC_3BB0A8C1_0x00530F20 100.0% Reimplemented PlayArmoryIsFullWarning, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 80.4% (loop precheck scheduling); the file was last changed in c933f79ff (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (#286)"). The body is Wilps's, from reimpl/Wilps-2026-10-18, which gynt adopted in d914edf6b and merged in c933f79ff (#286). Taken unchanged (the build fix 43a17dfac had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/PlayArmoryIsFullWarning.cpp | 47 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp diff --git a/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp new file mode 100644 index 0000000000..ab9b45cc72 --- /dev/null +++ b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp @@ -0,0 +1,47 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/BOOLEnum_00ee0fe0.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DWORD_00ee0fdc.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00530F20 + void Units::PlayArmoryIsFullWarning() + { + // guard of the function-local static holding the last warning time + if ((BOOLEnum_00ee0fe0::instance & 1) == 0) { + BOOLEnum_00ee0fe0::instance = (BOOLEnum)(BOOLEnum_00ee0fe0::instance | 1); + DWORD_00ee0fdc::instance = timeGetTime() - 60000; + } + if (timeGetTime() - DWORD_00ee0fdc::instance <= 60000) { + return; + } + int currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; + for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { + if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL + && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_ARMORY + && DAT_BuildingsState::instance.buildings[i].owner == currentPlayer) { + // "The armory is full my lord" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning12_wav_005abc08); + DWORD_00ee0fdc::instance = timeGetTime() - SEC_RNG::instance.currentNumber2 % 5000; + return; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bbd1bd7bc9..93989e59f1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49657,7 +49657,7 @@ SHC_3BB0A8C1_0x00530E00 | 0.0% | Pending SHC_3BB0A8C1_0x00530EB0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00530F20 | 0.0% | Pending +SHC_3BB0A8C1_0x00530F20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530FD0 | 100.0% | Reimplemented From fcdd14b9f446a5f0efa85de6ed4795ade32cc1d8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:44 +0100 Subject: [PATCH 09/18] reimplement: SHC_3BB0A8C1_0x00530E00 100.0% Reimplemented WarnIfPlayersGranaryIsFull, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 80.4% (loop precheck scheduling); the file was last changed in c933f79ff (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (#286)"). The body is Wilps's, from reimpl/Wilps-2026-10-18, which gynt adopted in d914edf6b and merged in c933f79ff (#286). Taken unchanged (the build fix 43a17dfac had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/WarnIfPlayersGranaryIsFull.cpp | 47 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp diff --git a/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp new file mode 100644 index 0000000000..461c47e21c --- /dev/null +++ b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp @@ -0,0 +1,47 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/BOOLEnum_00ee0fd0.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DWORD_00ee0fcc.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00530E00 + void Units::WarnIfPlayersGranaryIsFull() + { + // guard of the function-local static holding the last warning time + if ((BOOLEnum_00ee0fd0::instance & 1) == 0) { + BOOLEnum_00ee0fd0::instance = (BOOLEnum)(BOOLEnum_00ee0fd0::instance | 1); + DWORD_00ee0fcc::instance = timeGetTime() - 60000; + } + if (timeGetTime() - DWORD_00ee0fcc::instance <= 60000) { + return; + } + int currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; + for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { + if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL + && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_GRANARY + && DAT_BuildingsState::instance.buildings[i].owner == currentPlayer) { + // "The granary is full my lord" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning10_wav_005abbd8); + DWORD_00ee0fcc::instance = timeGetTime() - SEC_RNG::instance.currentNumber2 % 5000; + return; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 93989e59f1..279696c4c8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49653,7 +49653,7 @@ SHC_3BB0A8C1_0x00530D50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530D70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00530E00 | 0.0% | Pending +SHC_3BB0A8C1_0x00530E00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530EB0 | 100.0% | Reimplemented From 3d161dd283c45fa77ab67d30c0ad9cd32dc55240 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:45 +0100 Subject: [PATCH 10/18] reimplement: SHC_3BB0A8C1_0x005309E0 100.0% Reimplemented UpdateBurningAnimal1, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 0.0% (Pending); the file was last changed in c933f79ff (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (#286)"). It was first reimplemented in 7abe46bf2 ("reimplement UpdateBurningAnimal1 100%") and tidied by gynt in bef36ebe9. Taken unchanged (the build fix 43a17dfac had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/UpdateBurningAnimal1.cpp | 54 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp new file mode 100644 index 0000000000..cc54ff4f86 --- /dev/null +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp @@ -0,0 +1,54 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_CurrentUnitSlotID.hpp" +#include "OpenSHC/Globals/DAT_UnitHasBecomeIdle.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::Map::Units::States::UnitState; + + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 */ + + // FUNCTION: STRONGHOLDCRUSADER 0x005309E0 + void Units::UpdateBurningAnimal1() + { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].stateBasedSpeed = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].owner = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].calculatedOwnerPlayerIndex = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].dying = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].isSelected = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationSpeed = 3; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].disappearFadeAlphaCountdown = 8; + if (DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic + == OpenSHC::Map::Units::States::US_IDLEUnk) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic = 2; + return; + } + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; + int const _animationCycle + = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; + if (21 <= _animationCycle) { + DAT_UnitHasBecomeIdle::instance = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState + = OpenSHC::Map::Units::ULS_REMOVE; + return; + } + bool const _unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = _animationCycle + 1; + if (_unitHadBecomeIdle) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState + = OpenSHC::Map::Units::ULS_REMOVE; + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 279696c4c8..fd02b87a5b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49639,7 +49639,7 @@ SHC_3BB0A8C1_0x005308F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530990 | 0.0% | Pending -SHC_3BB0A8C1_0x005309E0 | 0.0% | Pending +SHC_3BB0A8C1_0x005309E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530A90 | 0.0% | Pending From 34730e0dd310d38edcf2a8466d1ff23d8e88fa17 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 10 Nov 2026 07:38:45 +0100 Subject: [PATCH 11/18] reimplement: SHC_3BB0A8C1_0x00530A90 100.0% Reimplemented UpdateBurningAnimal2, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a296 (his draft #204), where its status line reads 0.0% (Pending); the file was last changed in c933f79ff (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (#286)"). It was first reimplemented in c4fba5a72 ("reimplement UpdateBurningAnimal2 100%") and tidied by gynt in bef36ebe9. Taken unchanged (the build fix 43a17dfac had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top follows in our own commits. Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/UpdateBurningAnimal2.cpp | 54 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp new file mode 100644 index 0000000000..0daeb41e0e --- /dev/null +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp @@ -0,0 +1,54 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_CurrentUnitSlotID.hpp" +#include "OpenSHC/Globals/DAT_UnitHasBecomeIdle.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::Map::Units::States::UnitState; + + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 */ + + // FUNCTION: STRONGHOLDCRUSADER 0x00530A90 + void Units::UpdateBurningAnimal2() + { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].stateBasedSpeed = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].owner = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].calculatedOwnerPlayerIndex = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].dying = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].isSelected = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationSpeed = 3; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].disappearFadeAlphaCountdown = 8; + if (DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic + == OpenSHC::Map::Units::States::US_IDLEUnk) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic = 2; + return; + } + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; + int const _animationCycle + = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; + if (17 <= _animationCycle) { + DAT_UnitHasBecomeIdle::instance = 1; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState + = OpenSHC::Map::Units::ULS_REMOVE; + return; + } + bool const _unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = _animationCycle + 1; + if (_unitHadBecomeIdle) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState + = OpenSHC::Map::Units::ULS_REMOVE; + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fd02b87a5b..71487e0aee 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49641,7 +49641,7 @@ SHC_3BB0A8C1_0x00530990 | 0.0% | Pending SHC_3BB0A8C1_0x005309E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00530A90 | 0.0% | Pending +SHC_3BB0A8C1_0x00530A90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530B40 | 100.0% | Reimplemented From a1eb68f74e742ab6171a23a11c24c18cea003653 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 07:41:38 +0100 Subject: [PATCH 12/18] units round 1: truth tests for the flags, and no unused using declarations openshc-pr-fix.py's mechanical pass over the eleven files: boost, updateAV and restedEnough are tested for truth instead of against FALSE, and UpdateBurningAnimal1 and 2 lose their unused using declarations (UnitLogicState, UnitState). quick_diff is the same for all eleven. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp | 2 +- .../Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp | 2 +- src/OpenSHC/Map/Units/SetRestingForUnit.cpp | 2 +- src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp | 3 --- src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp | 3 --- 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp index a5c2970536..f84e321a5b 100644 --- a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp +++ b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp @@ -26,7 +26,7 @@ namespace Map { productivity = 100; } // Skirmish modes boost productivity by 50. - if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY && boost != FALSE) { + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY && boost) { productivity += 50; } // Fractional bonus goods are kept as a percentage and added next time. diff --git a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp index bc28818016..0e2efd2c54 100644 --- a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp +++ b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp @@ -15,7 +15,7 @@ namespace Map { // workTimer, workRelatedA, workRelatedB and workRelatedC are four timers, working is the current index (&DAT_UnitsState::instance.units[unitID].workTimer)[DAT_UnitsState::instance.units[unitID].working] += 1; int count = 0; - if (updateAV == FALSE) { + if (!updateAV) { return; } DAT_UnitsState::instance.units[unitID].av = 0; diff --git a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp index 0ba01ef3ec..4fa8a8768d 100644 --- a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp +++ b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp @@ -43,7 +43,7 @@ namespace Map { if (MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::hasUnitReachedDestination, DAT_UnitsState::ptr)( unitID) != FALSE) { - if (restedEnough != FALSE) { + if (restedEnough) { if (DAT_UnitsState::instance.units[unitID].idle > DAT_UnitsState::instance.units[unitID].target) { DAT_UnitsState::instance.units[unitID].banked = DAT_UnitsState::instance.units[unitID].idle - DAT_UnitsState::instance.units[unitID].target; diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp index cc54ff4f86..90941fb4f0 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp @@ -10,9 +10,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Units::UnitLogicState; - using OpenSHC::Map::Units::States::UnitState; - /* decompilerscript: committed: 2025-01-30 21:57:43.216000 */ diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp index 0daeb41e0e..b4e4d07a3f 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp @@ -10,9 +10,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Units::UnitLogicState; - using OpenSHC::Map::Units::States::UnitState; - /* decompilerscript: committed: 2025-01-30 21:57:43.216000 */ From c9bd78b7e2689a2e6aec6822ab9096d5eec48540 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 07:43:56 +0100 Subject: [PATCH 13/18] header: DestinationNeededEnum gets DNE_UNKNOWN_2 Units::SetRestingForUnit (0x00549B30) stores 2 in a unit's destinationNeeded twice (mov word ptr [esi + 0x13888C0], 2 at 0x00549BB7 and 0x00549C09: the units array at 0x0138854C plus the field's 0x374), when no building is found and when the unit has rested enough. The enum has no value between DNE_DESTINATION_NEEDED (1) and DNE_FLETCHER_SPECIFIC_COUNTDOWN (5); named in the DNE_UNKNOWN_ form. Used in place of (DestinationNeededEnum)2; code generation is the same. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp b/src/OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp index d677966f4b..c2608bb07b 100644 --- a/src/OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp +++ b/src/OpenSHC/Map/Units/Pathfinding/DestinationNeededEnum.hpp @@ -16,6 +16,7 @@ namespace Map { DNE_DESTINATION_HAS_BEEN_SET = 0, // 0x00000000 DNE_DESTINATION_NEEDED = 1, // 0x00000001 + DNE_UNKNOWN_2 = 2, // 0x00000002 DNE_FLETCHER_SPECIFIC_COUNTDOWN = 5, // 0x00000005 DNE_OX_SPECIFIC_COUNTDOWN = 20 // 0x00000014 From 24ce8dbc23eef944a152116421e65e6cc66643e6 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 07:43:56 +0100 Subject: [PATCH 14/18] header: UnitState gets US_UNKNOWN_121 Units::SetStateToFreetimeWalking (0x00530CF0) and Units::ConsiderHavingABreakNowUnk (0x00530C40) put a unit into state 121, the resting state (mov word ptr [ecx + 0x138880C], 0x79 at 0x00530D43 and 0x00530CD2: the units array at 0x0138854C plus state at 0x2C0). The enum goes from US_STONE_DEATH_03 (116) to US_APPEAR (122); named in the US_UNKNOWN_ form. Used in place of (UnitState)121; code generation is the same. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/States/UnitState.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenSHC/Map/Units/States/UnitState.hpp b/src/OpenSHC/Map/Units/States/UnitState.hpp index 00a1426a16..562b39d3c7 100644 --- a/src/OpenSHC/Map/Units/States/UnitState.hpp +++ b/src/OpenSHC/Map/Units/States/UnitState.hpp @@ -37,6 +37,7 @@ namespace Map { US_STONE_DEATH_01 = 114, // 0x00000072 US_STONE_DEATH_02 = 115, // 0x00000073 US_STONE_DEATH_03 = 116, // 0x00000074 + US_UNKNOWN_121 = 121, // 0x00000079 US_APPEAR = 122, // 0x0000007A US_DIG = 125, // 0x0000007D US_ASSASSIN_THROWING_HOOK = 126, // 0x0000007E From 85955cba816345fd1f3b3b289027c44e3261220c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 07:44:33 +0100 Subject: [PATCH 15/18] header: Unit's four work timers are one array, workTimers[4] Unit::workTimer, workRelatedA, workRelatedB and workRelatedC (+0x2E8 to +0x2F4) are one int[4] indexed by Unit::working (0 to 3): Units::IncrementAndOptionalUpdateAVValueRelated (0x00530B40) adds 1 to the current one with add dword ptr [eax*4 + 0x1388834], 1 at 0x00530B5C (eax holding unitID * 292 plus working, in dwords; the units array is at 0x0138854C), sums all four into av and clears the next one the same way. Nothing on main uses the four names, and on this branch only that function does. This round's style commit then indexes workTimers there; code generation is the same. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/Unit.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/Units/Unit.hpp b/src/OpenSHC/Map/Units/Unit.hpp index 94585f49bd..f89213d6ce 100644 --- a/src/OpenSHC/Map/Units/Unit.hpp +++ b/src/OpenSHC/Map/Units/Unit.hpp @@ -175,10 +175,7 @@ namespace Map { short topSpeedDelayIndex; // 0x000002E0 length: 2 short movementDistance; // 0x000002E2 length: 2 int tribeUID; // 0x000002E4 length: 4 - int workTimer; // 0x000002E8 length: 4 - int workRelatedA; // 0x000002EC length: 4 - int workRelatedB; // 0x000002F0 length: 4 - int workRelatedC; // 0x000002F4 length: 4 + int workTimers[4]; // 0x000002E8 length: 16 int av; // 0x000002F8 length: 4 short working; // 0x000002FC length: 2 short field_0x2fe; // 0x000002FE length: 2 From 5f50460b42c3e626e5ad2a229c723ea080ccb467 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 07:52:02 +0100 Subject: [PATCH 16/18] units round 1: enum names, the work-timer array, names and measured comments - SetRestingForUnit stores DNE_UNKNOWN_2 and SetStateToFreetimeWalking US_UNKNOWN_121 (header commits) in place of the casts; SetRestingForUnit tests hasUnitReachedDestination for truth, and SetStateToFreetimeWalking returns FALSE / TRUE and calls its third parameter substateCount (the count of substates it wraps around). - IncrementAndOptionalUpdateAVValueRelated indexes workTimers (header commit) instead of (&workTimer)[i], with countof for the four; its count stays zeroed before the early return (after it: quick_diff 0.9811 -> 0.9057). - ComputeGoodsProduced keeps its divisor variable (a literal 100: quick_diff 0.9737 -> 0.7561) and its * 100 / 100 (without: 0.4058), each with a one-line comment, and its plate comment is a // line in the body. - UpdateBurningAnimal1 and 2 lose the imported plate comment, store US_STATE_2Unk for 2, and name their two locals without the leading underscore, the animation bound on the right of the comparison. - const for the locals assigned once (tile, currentPlayer twice, bonusPercentage, now), and PlayStockpileIsFullWarning's comment on its return value says what the code does. quick_diff is the same for all eleven. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp | 9 ++++----- src/OpenSHC/Map/Units/DetachLadderman.cpp | 2 +- ...IncrementAndOptionalUpdateAVValueRelated.cpp | 16 +++++++++------- .../Map/Units/PlayArmoryIsFullWarning.cpp | 2 +- .../Map/Units/PlayStockpileIsFullWarning.cpp | 4 ++-- src/OpenSHC/Map/Units/SetRestingForUnit.cpp | 10 +++++----- .../Map/Units/SetStateToFreetimeWalking.cpp | 13 ++++++------- src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp | 17 +++++++---------- src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp | 17 +++++++---------- .../Map/Units/WarnIfPlayersGranaryIsFull.cpp | 2 +- 10 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp index f84e321a5b..f127bafb74 100644 --- a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp +++ b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp @@ -12,12 +12,10 @@ namespace Map { using OpenSHC::WindowsHelper::Enums::BOOLEnum; - /* - example: goodsCount = 3, boost = TRUE for apple farm */ - // FUNCTION: STRONGHOLDCRUSADER 0x00530D70 int Units::ComputeGoodsProduced(int unitID, int goodsCount, BOOLEnum boost) { + // an apple farm, for example, passes goodsCount 3 and boost TRUE int productivity = DAT_GameState::instance.playerDataArray[DAT_UnitsState::instance.units[unitID].owner] .fearFactorProductivityUnk; DAT_UnitsState::instance.units[unitID].productivityDiv100 = 0; @@ -30,9 +28,10 @@ namespace Map { productivity += 50; } // Fractional bonus goods are kept as a percentage and added next time. - int bonusPercentage + // the original multiplies by 100 and divides by 100 again (without: quick_diff 0.9737 -> 0.4058) + int const bonusPercentage = (productivity - 100) * goodsCount * 100 / 100 + DAT_UnitsState::instance.units[unitID].productivityMod100; - // held in a variable: the original computes quotient and remainder with one idiv + // a variable, so one idiv gives quotient and remainder (a literal 100: quick_diff 0.9737 -> 0.7561) int divisor = 100; DAT_UnitsState::instance.units[unitID].productivityDiv100 = (short)(bonusPercentage / divisor); DAT_UnitsState::instance.units[unitID].productivityMod100 = (short)(bonusPercentage % divisor); diff --git a/src/OpenSHC/Map/Units/DetachLadderman.cpp b/src/OpenSHC/Map/Units/DetachLadderman.cpp index b3926cf1a5..35a5d598d2 100644 --- a/src/OpenSHC/Map/Units/DetachLadderman.cpp +++ b/src/OpenSHC/Map/Units/DetachLadderman.cpp @@ -13,7 +13,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00530760 void Units::DetachLadderman(int unitID) { - int tile = DAT_UnitsState::instance.units[unitID].tile; + int const tile = DAT_UnitsState::instance.units[unitID].tile; DAT_TileMapState::instance.LogicLayer[tile] &= ~OpenSHC::Map::LogicHelpers::L_CLIMBABLE; DAT_UnitsState::instance.units[unitID].wallDataID = 0; MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, diff --git a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp index 0e2efd2c54..22a29c2b24 100644 --- a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp +++ b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp @@ -12,16 +12,17 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00530B40 void Units::IncrementAndOptionalUpdateAVValueRelated(int unitID, BOOLEnum updateAV) { - // workTimer, workRelatedA, workRelatedB and workRelatedC are four timers, working is the current index - (&DAT_UnitsState::instance.units[unitID].workTimer)[DAT_UnitsState::instance.units[unitID].working] += 1; + // four work timers; working is the current one + DAT_UnitsState::instance.units[unitID].workTimers[DAT_UnitsState::instance.units[unitID].working] += 1; + // zeroed before the early return, as the original does (after it: quick_diff 0.9811 -> 0.9057) int count = 0; if (!updateAV) { return; } DAT_UnitsState::instance.units[unitID].av = 0; - for (int i = 0; i < 4; ++i) { - DAT_UnitsState::instance.units[unitID].av += (&DAT_UnitsState::instance.units[unitID].workTimer)[i]; - if ((&DAT_UnitsState::instance.units[unitID].workTimer)[i] > 0) { + for (int i = 0; i < countof(DAT_UnitsState::instance.units[unitID].workTimers); ++i) { + DAT_UnitsState::instance.units[unitID].av += DAT_UnitsState::instance.units[unitID].workTimers[i]; + if (DAT_UnitsState::instance.units[unitID].workTimers[i] > 0) { ++count; } } @@ -29,10 +30,11 @@ namespace Map { DAT_UnitsState::instance.units[unitID].av /= count; } DAT_UnitsState::instance.units[unitID].working += 1; - if (DAT_UnitsState::instance.units[unitID].working >= 4) { + if (DAT_UnitsState::instance.units[unitID].working + >= countof(DAT_UnitsState::instance.units[unitID].workTimers)) { DAT_UnitsState::instance.units[unitID].working = 0; } - (&DAT_UnitsState::instance.units[unitID].workTimer)[DAT_UnitsState::instance.units[unitID].working] = 0; + DAT_UnitsState::instance.units[unitID].workTimers[DAT_UnitsState::instance.units[unitID].working] = 0; } } diff --git a/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp index ab9b45cc72..d5ce5882b6 100644 --- a/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp +++ b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp @@ -29,7 +29,7 @@ namespace Map { if (timeGetTime() - DWORD_00ee0fdc::instance <= 60000) { return; } - int currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; + int const currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_ARMORY diff --git a/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp index b30e31bbff..361b33f98a 100644 --- a/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp +++ b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp @@ -27,8 +27,8 @@ namespace Map { // "The stockpile is full my lord" MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( s_placement_warning11_wav_005abbf0); - DWORD now = timeGetTime(); - // the original returns whatever is left in eax (a void function in the source) + DWORD const now = timeGetTime(); + // the original returns what its last division leaves in eax elapsed = SEC_RNG::instance.currentNumber2 / 5000; DWORD_00ee0fd4::instance = now - SEC_RNG::instance.currentNumber2 % 5000; } diff --git a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp index 4fa8a8768d..94fc14fbd0 100644 --- a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp +++ b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp @@ -11,7 +11,6 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Units::Pathfinding::DestinationNeededEnum; using OpenSHC::WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x00549B30 @@ -37,12 +36,12 @@ namespace Map { // No positive fear factor building available, resume normal state DAT_UnitsState::instance.units[unitID].state.generic = DAT_UnitsState::instance.units[unitID].cachedState; - DAT_UnitsState::instance.units[unitID].destinationNeeded = (DestinationNeededEnum)2; + DAT_UnitsState::instance.units[unitID].destinationNeeded + = OpenSHC::Map::Units::Pathfinding::DNE_UNKNOWN_2; } } if (MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::hasUnitReachedDestination, DAT_UnitsState::ptr)( - unitID) - != FALSE) { + unitID)) { if (restedEnough) { if (DAT_UnitsState::instance.units[unitID].idle > DAT_UnitsState::instance.units[unitID].target) { DAT_UnitsState::instance.units[unitID].banked @@ -51,7 +50,8 @@ namespace Map { DAT_UnitsState::instance.units[unitID].field_0x2fe = 0; DAT_UnitsState::instance.units[unitID].state.generic = DAT_UnitsState::instance.units[unitID].cachedState; - DAT_UnitsState::instance.units[unitID].destinationNeeded = (DestinationNeededEnum)2; + DAT_UnitsState::instance.units[unitID].destinationNeeded + = OpenSHC::Map::Units::Pathfinding::DNE_UNKNOWN_2; return TRUE; } if (DAT_UnitsState::instance.units[unitID].unitTypeSpecificRestingState > 0 diff --git a/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp index 0a5c795891..536e5b62c6 100644 --- a/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp +++ b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp @@ -8,27 +8,26 @@ namespace OpenSHC { namespace Map { - using OpenSHC::Map::Units::States::UnitState; using OpenSHC::WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x00530CF0 - BOOLEnum Units::SetStateToFreetimeWalking(int unitID, int shouldFindNewGoodThing, int param_3) + BOOLEnum Units::SetStateToFreetimeWalking(int unitID, int shouldFindNewGoodThing, int substateCount) { if (DAT_UnitsState::instance.units[unitID].field_0x2fe != 1) { - return 0; + return FALSE; } DAT_UnitsState::instance.units[unitID].idle += 1; if (shouldFindNewGoodThing == 0) { - return 0; + return FALSE; } DAT_UnitsState::instance.units[unitID].substate += 1; DAT_UnitsState::instance.units[unitID].animationCycleNumber = 0; - if (DAT_UnitsState::instance.units[unitID].substate >= param_3) { + if (DAT_UnitsState::instance.units[unitID].substate >= substateCount) { DAT_UnitsState::instance.units[unitID].substate = 0; } // resting - DAT_UnitsState::instance.units[unitID].state.generic = (UnitState)121; - return 1; + DAT_UnitsState::instance.units[unitID].state.generic = OpenSHC::Map::Units::States::US_UNKNOWN_121; + return TRUE; } } diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp index 90941fb4f0..042d5998ef 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp @@ -10,9 +10,6 @@ namespace OpenSHC { namespace Map { - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 */ - // FUNCTION: STRONGHOLDCRUSADER 0x005309E0 void Units::UpdateBurningAnimal1() { @@ -28,21 +25,21 @@ namespace Map { DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber = 0; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = 1; - DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic = 2; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic + = OpenSHC::Map::Units::States::US_STATE_2Unk; return; } DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; - int const _animationCycle - = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; - if (21 <= _animationCycle) { + int const animationCycle = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; + if (animationCycle >= 21) { DAT_UnitHasBecomeIdle::instance = 1; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState = OpenSHC::Map::Units::ULS_REMOVE; return; } - bool const _unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; - DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = _animationCycle + 1; - if (_unitHadBecomeIdle) { + bool const unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = animationCycle + 1; + if (unitHadBecomeIdle) { DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState = OpenSHC::Map::Units::ULS_REMOVE; } diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp index b4e4d07a3f..d582714d07 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp @@ -10,9 +10,6 @@ namespace OpenSHC { namespace Map { - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 */ - // FUNCTION: STRONGHOLDCRUSADER 0x00530A90 void Units::UpdateBurningAnimal2() { @@ -28,21 +25,21 @@ namespace Map { DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber = 0; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = 1; - DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic = 2; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state.generic + = OpenSHC::Map::Units::States::US_STATE_2Unk; return; } DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; - int const _animationCycle - = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; - if (17 <= _animationCycle) { + int const animationCycle = DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber; + if (animationCycle >= 17) { DAT_UnitHasBecomeIdle::instance = 1; DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState = OpenSHC::Map::Units::ULS_REMOVE; return; } - bool const _unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; - DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = _animationCycle + 1; - if (_unitHadBecomeIdle) { + bool const unitHadBecomeIdle = DAT_UnitHasBecomeIdle::instance != 0; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = animationCycle + 1; + if (unitHadBecomeIdle) { DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState = OpenSHC::Map::Units::ULS_REMOVE; } diff --git a/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp index 461c47e21c..47a0725a1b 100644 --- a/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp +++ b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp @@ -29,7 +29,7 @@ namespace Map { if (timeGetTime() - DWORD_00ee0fcc::instance <= 60000) { return; } - int currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; + int const currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_GRANARY From e9cbc5954e83774224ddc3bf9d5112496204a2ec Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 08:20:05 +0100 Subject: [PATCH 17/18] header: PlayStockpileIsFullWarning returns nothing Units::PlayStockpileIsFullWarning (0x00530EB0) was declared to return uint, but nothing uses a result: no file on main calls it, the six callers in the decompilation throw eax away, and its two siblings, PlayArmoryIsFullWarning and WarnIfPlayersGranaryIsFull, are void. What eax holds at its end is the quotient of the last % 5000. It is void in Units.hpp and in its resolver's signature in Units.func.hpp. With the body written like its siblings, quick_diff output is identical. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/Units.func.hpp | 2 +- src/OpenSHC/Map/Units.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Units.func.hpp b/src/OpenSHC/Map/Units.func.hpp index 23bda24c5a..a791f210c4 100644 --- a/src/OpenSHC/Map/Units.func.hpp +++ b/src/OpenSHC/Map/Units.func.hpp @@ -63,7 +63,7 @@ namespace Map { WarnIfPlayersGranaryIsFull; MACRO_FUNCTION_RESOLVER( - uint(__cdecl*)(), false, Address::SHC_3BB0A8C1_0x00530EB0, &OpenSHC::Map::Units::PlayStockpileIsFullWarning) + void(__cdecl*)(), false, Address::SHC_3BB0A8C1_0x00530EB0, &OpenSHC::Map::Units::PlayStockpileIsFullWarning) PlayStockpileIsFullWarning; MACRO_FUNCTION_RESOLVER( diff --git a/src/OpenSHC/Map/Units.hpp b/src/OpenSHC/Map/Units.hpp index 68f03cb8a9..a6708a1215 100644 --- a/src/OpenSHC/Map/Units.hpp +++ b/src/OpenSHC/Map/Units.hpp @@ -39,7 +39,7 @@ namespace Map { void __cdecl WarnIfPlayersGranaryIsFull(); - uint __cdecl PlayStockpileIsFullWarning(); + void __cdecl PlayStockpileIsFullWarning(); void __cdecl PlayArmoryIsFullWarning(); From 68987e7b7c6e2d5167ec1a4f9c31379aec6ce921 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 08:20:05 +0100 Subject: [PATCH 18/18] units round 1: the review's points - PlayStockpileIsFullWarning is written like its two siblings: void, an early return, and no quotient kept for eax. - The three warnings' static guards use main's form (`!(guard & TRUE)`, `guard |= TRUE`), as in PlayJokeVideoBasedOnCurrentTimeAndPlayTime, so their BOOLEnum casts, usings and includes go. - buildingID for the building loops and SetRestingForUnit's building, activeTimerCount for the count of active timers, and a truth test for shouldFindNewGoodThing. - ComputeGoodsProduced drops its (short) casts (the fields are short) and its plate example, and its boost comment says every mode but solitary. - SetRestingForUnit says why idle is tested against target twice. - IncrementAndOptionalUpdateAVValueRelated loses a comment that repeated what the array says. - A blank line before the namespaces close in both BurningAnimal files, as in the other nine. quick_diff output is identical for all 11 files, with -s. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/ComputeGoodsProduced.cpp | 7 +++--- ...crementAndOptionalUpdateAVValueRelated.cpp | 9 +++---- .../Map/Units/PlayArmoryIsFullWarning.cpp | 15 +++++------ .../Map/Units/PlayStockpileIsFullWarning.cpp | 25 +++++++------------ src/OpenSHC/Map/Units/SetRestingForUnit.cpp | 9 ++++--- .../Map/Units/SetStateToFreetimeWalking.cpp | 2 +- .../Map/Units/UpdateBurningAnimal1.cpp | 1 + .../Map/Units/UpdateBurningAnimal2.cpp | 1 + .../Map/Units/WarnIfPlayersGranaryIsFull.cpp | 16 ++++++------ 9 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp index f127bafb74..510934ce5d 100644 --- a/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp +++ b/src/OpenSHC/Map/Units/ComputeGoodsProduced.cpp @@ -15,7 +15,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00530D70 int Units::ComputeGoodsProduced(int unitID, int goodsCount, BOOLEnum boost) { - // an apple farm, for example, passes goodsCount 3 and boost TRUE int productivity = DAT_GameState::instance.playerDataArray[DAT_UnitsState::instance.units[unitID].owner] .fearFactorProductivityUnk; DAT_UnitsState::instance.units[unitID].productivityDiv100 = 0; @@ -23,7 +22,7 @@ namespace Map { if (productivity <= 100) { productivity = 100; } - // Skirmish modes boost productivity by 50. + // Every mode but solitary boosts productivity by 50. if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY && boost) { productivity += 50; } @@ -33,8 +32,8 @@ namespace Map { = (productivity - 100) * goodsCount * 100 / 100 + DAT_UnitsState::instance.units[unitID].productivityMod100; // a variable, so one idiv gives quotient and remainder (a literal 100: quick_diff 0.9737 -> 0.7561) int divisor = 100; - DAT_UnitsState::instance.units[unitID].productivityDiv100 = (short)(bonusPercentage / divisor); - DAT_UnitsState::instance.units[unitID].productivityMod100 = (short)(bonusPercentage % divisor); + DAT_UnitsState::instance.units[unitID].productivityDiv100 = bonusPercentage / divisor; + DAT_UnitsState::instance.units[unitID].productivityMod100 = bonusPercentage % divisor; return DAT_UnitsState::instance.units[unitID].productivityDiv100 + goodsCount; } diff --git a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp index 22a29c2b24..9ed25c3140 100644 --- a/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp +++ b/src/OpenSHC/Map/Units/IncrementAndOptionalUpdateAVValueRelated.cpp @@ -12,10 +12,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00530B40 void Units::IncrementAndOptionalUpdateAVValueRelated(int unitID, BOOLEnum updateAV) { - // four work timers; working is the current one DAT_UnitsState::instance.units[unitID].workTimers[DAT_UnitsState::instance.units[unitID].working] += 1; // zeroed before the early return, as the original does (after it: quick_diff 0.9811 -> 0.9057) - int count = 0; + int activeTimerCount = 0; if (!updateAV) { return; } @@ -23,11 +22,11 @@ namespace Map { for (int i = 0; i < countof(DAT_UnitsState::instance.units[unitID].workTimers); ++i) { DAT_UnitsState::instance.units[unitID].av += DAT_UnitsState::instance.units[unitID].workTimers[i]; if (DAT_UnitsState::instance.units[unitID].workTimers[i] > 0) { - ++count; + ++activeTimerCount; } } - if (count > 0) { - DAT_UnitsState::instance.units[unitID].av /= count; + if (activeTimerCount > 0) { + DAT_UnitsState::instance.units[unitID].av /= activeTimerCount; } DAT_UnitsState::instance.units[unitID].working += 1; if (DAT_UnitsState::instance.units[unitID].working diff --git a/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp index d5ce5882b6..23c9938818 100644 --- a/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp +++ b/src/OpenSHC/Map/Units/PlayArmoryIsFullWarning.cpp @@ -3,7 +3,6 @@ #include "OpenSHC/Audio/SFX/SFXState.func.hpp" #include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/BOOLEnum_00ee0fe0.hpp" @@ -16,24 +15,22 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00530F20 void Units::PlayArmoryIsFullWarning() { // guard of the function-local static holding the last warning time - if ((BOOLEnum_00ee0fe0::instance & 1) == 0) { - BOOLEnum_00ee0fe0::instance = (BOOLEnum)(BOOLEnum_00ee0fe0::instance | 1); + if (!(BOOLEnum_00ee0fe0::instance & TRUE)) { + BOOLEnum_00ee0fe0::instance |= TRUE; DWORD_00ee0fdc::instance = timeGetTime() - 60000; } if (timeGetTime() - DWORD_00ee0fdc::instance <= 60000) { return; } int const currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; - for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { - if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL - && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_ARMORY - && DAT_BuildingsState::instance.buildings[i].owner == currentPlayer) { + for (int buildingID = 1; buildingID < DAT_BuildingsState::instance.maxBuildingsCount; ++buildingID) { + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL + && DAT_BuildingsState::instance.buildings[buildingID].buildingType == OpenSHC::Map::Buildings::BT_ARMORY + && DAT_BuildingsState::instance.buildings[buildingID].owner == currentPlayer) { // "The armory is full my lord" MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( s_placement_warning12_wav_005abc08); diff --git a/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp index 361b33f98a..2b1aa27f73 100644 --- a/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp +++ b/src/OpenSHC/Map/Units/PlayStockpileIsFullWarning.cpp @@ -1,7 +1,6 @@ #include "../Units.func.hpp" #include "OpenSHC/Audio/SFX/SFXState.func.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/BOOLEnum_00ee0fd8.hpp" @@ -12,27 +11,21 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00530EB0 - uint Units::PlayStockpileIsFullWarning() + void Units::PlayStockpileIsFullWarning() { // guard of the function-local static holding the last warning time - if ((BOOLEnum_00ee0fd8::instance & 1) == 0) { - BOOLEnum_00ee0fd8::instance = (BOOLEnum)(BOOLEnum_00ee0fd8::instance | 1); + if (!(BOOLEnum_00ee0fd8::instance & TRUE)) { + BOOLEnum_00ee0fd8::instance |= TRUE; DWORD_00ee0fd4::instance = timeGetTime() - 60000; } - uint elapsed = timeGetTime() - DWORD_00ee0fd4::instance; - if (elapsed > 60000) { - // "The stockpile is full my lord" - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( - s_placement_warning11_wav_005abbf0); - DWORD const now = timeGetTime(); - // the original returns what its last division leaves in eax - elapsed = SEC_RNG::instance.currentNumber2 / 5000; - DWORD_00ee0fd4::instance = now - SEC_RNG::instance.currentNumber2 % 5000; + if (timeGetTime() - DWORD_00ee0fd4::instance <= 60000) { + return; } - return elapsed; + // "The stockpile is full my lord" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning11_wav_005abbf0); + DWORD_00ee0fd4::instance = timeGetTime() - SEC_RNG::instance.currentNumber2 % 5000; } } diff --git a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp index 94fc14fbd0..247c647aed 100644 --- a/src/OpenSHC/Map/Units/SetRestingForUnit.cpp +++ b/src/OpenSHC/Map/Units/SetRestingForUnit.cpp @@ -25,13 +25,13 @@ namespace Map { != OpenSHC::Map::Units::Pathfinding::DNE_DESTINATION_HAS_BEEN_SET) { DAT_UnitsState::instance.units[unitID].destinationNeeded = OpenSHC::Map::Units::Pathfinding::DNE_DESTINATION_HAS_BEEN_SET; - int building + int const buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::pickARandomPositiveFearFactorBuilding, DAT_BuildingsState::ptr)(DAT_UnitsState::instance.units[unitID].owner); - if (building != 0) { + if (buildingID != 0) { MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::setDestinationForUnit, DAT_UnitsState::ptr)( - unitID, DAT_BuildingsState::instance.buildings[building].buildingEntryX, - DAT_BuildingsState::instance.buildings[building].buildingEntryY, 0); + unitID, DAT_BuildingsState::instance.buildings[buildingID].buildingEntryX, + DAT_BuildingsState::instance.buildings[buildingID].buildingEntryY, 0); } else { // No positive fear factor building available, resume normal state DAT_UnitsState::instance.units[unitID].state.generic @@ -43,6 +43,7 @@ namespace Map { if (MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::hasUnitReachedDestination, DAT_UnitsState::ptr)( unitID)) { if (restedEnough) { + // idle against target again, as the original tests it twice if (DAT_UnitsState::instance.units[unitID].idle > DAT_UnitsState::instance.units[unitID].target) { DAT_UnitsState::instance.units[unitID].banked = DAT_UnitsState::instance.units[unitID].idle - DAT_UnitsState::instance.units[unitID].target; diff --git a/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp index 536e5b62c6..1703191931 100644 --- a/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp +++ b/src/OpenSHC/Map/Units/SetStateToFreetimeWalking.cpp @@ -17,7 +17,7 @@ namespace Map { return FALSE; } DAT_UnitsState::instance.units[unitID].idle += 1; - if (shouldFindNewGoodThing == 0) { + if (!shouldFindNewGoodThing) { return FALSE; } DAT_UnitsState::instance.units[unitID].substate += 1; diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp index 042d5998ef..4aff89eeb7 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal1.cpp @@ -44,5 +44,6 @@ namespace Map { = OpenSHC::Map::Units::ULS_REMOVE; } } + } } diff --git a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp index d582714d07..10004b90eb 100644 --- a/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp +++ b/src/OpenSHC/Map/Units/UpdateBurningAnimal2.cpp @@ -44,5 +44,6 @@ namespace Map { = OpenSHC::Map::Units::ULS_REMOVE; } } + } } diff --git a/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp index 47a0725a1b..1c24ba9e7c 100644 --- a/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp +++ b/src/OpenSHC/Map/Units/WarnIfPlayersGranaryIsFull.cpp @@ -3,7 +3,6 @@ #include "OpenSHC/Audio/SFX/SFXState.func.hpp" #include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/BOOLEnum_00ee0fd0.hpp" @@ -16,24 +15,23 @@ namespace OpenSHC { namespace Map { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x00530E00 void Units::WarnIfPlayersGranaryIsFull() { // guard of the function-local static holding the last warning time - if ((BOOLEnum_00ee0fd0::instance & 1) == 0) { - BOOLEnum_00ee0fd0::instance = (BOOLEnum)(BOOLEnum_00ee0fd0::instance | 1); + if (!(BOOLEnum_00ee0fd0::instance & TRUE)) { + BOOLEnum_00ee0fd0::instance |= TRUE; DWORD_00ee0fcc::instance = timeGetTime() - 60000; } if (timeGetTime() - DWORD_00ee0fcc::instance <= 60000) { return; } int const currentPlayer = DAT_GameSynchronyState::instance.currentPlayerSlotID; - for (int i = 1; i < DAT_BuildingsState::instance.maxBuildingsCount; ++i) { - if (DAT_BuildingsState::instance.buildings[i].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL - && DAT_BuildingsState::instance.buildings[i].buildingType == OpenSHC::Map::Buildings::BT_GRANARY - && DAT_BuildingsState::instance.buildings[i].owner == currentPlayer) { + for (int buildingID = 1; buildingID < DAT_BuildingsState::instance.maxBuildingsCount; ++buildingID) { + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_NORMAL + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GRANARY + && DAT_BuildingsState::instance.buildings[buildingID].owner == currentPlayer) { // "The granary is full my lord" MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( s_placement_warning10_wav_005abbd8);