From dcf747c01ad362379da2906e6d4444c336d99f4c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 23:31:37 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x005307B0 100.0% Reimplemented Units::UpdateSiegeTent, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; the file's commits there: 609ef6d1ab, the 69.44% import, then his 2fe31a8a07, 8d684a961f at 69.44%, 974c32fcf3's clang-format, and c933f79ff5, his PR 286 merged into that branch, which took this file's body from reimpl/Wilps-2026-10-18). It reads a true 100.0 / 100.0. The statements are his; what the text needed is where two of them stand. 1. The ULS_TRANSITIONING store stands in front of the `fixedRng & 2` test, as in the original (0x005307FA, the test at 0x00530803). The draft wrote it in both arms so that the type stays a branch, and the compiler then placed the merged store behind the test. Written once in front of the if, the type becomes a branch-free select (sbb) unless the arms hold more than the one store: so the state_2 store, behind the keep reads in the draft, is written in both arms behind the type store. The compiler merges the two copies into the one store behind the join (0x0053082C) and keeps the branches (0x0053080B / 0x00530816). 2. The names of this tree: field_0x3bc; the keep's entry as playerDataArray[1].buildingEntryInfos[BEIE_KEEP] (yEntry 0x0115F888 and xEntry 0x0115F884 are read in that order, hence the two locals); state_2's 6 as US_FIRE_WEAPONUnk (changeUnitType, 0x0053E6C0, copies state_2 into the new engine's state). 3. The `frame >= 4` test after `& 3` is never true, but the original compares and stores it (0x005307D1), so it stays, with a fixme comment; `(fixedRng + 1) & 3` in parentheses, `animationCycleNumber++`, const locals. Measured with real builds of the units stack's head 6e3de74062 (the headers this file includes are the same there as on main 0e4a83b5d2; its one callee, calculatePreferredRelativeOrientation, is reimplemented in neither), the whole build list plus this file and its /GL line, BUILD_OK each: UpdateSiegeTent 100.0 raw / 100.0 normalised, no diff entry, 345 functions; none of the other 344 reads differently. The text before the review's text fixes (the two enum names, the comments, const locals) read the same. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 1 + src/OpenSHC/Map/Units/UpdateSiegeTent.cpp | 62 +++++++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/UpdateSiegeTent.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 18dce0ff70..160b129100 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -137,3 +137,4 @@ src/OpenSHC/Map/Units/UpdateQuarryMason.cpp src/OpenSHC/Map/Units/UpdateDrunkard.cpp src/OpenSHC/Map/Units/UpdateInnkeeper.cpp src/OpenSHC/Map/Units/UpdateMerchant.cpp +src/OpenSHC/Map/Units/UpdateSiegeTent.cpp diff --git a/src/OpenSHC/Map/Units/UpdateSiegeTent.cpp b/src/OpenSHC/Map/Units/UpdateSiegeTent.cpp new file mode 100644 index 0000000000..d60488a2d2 --- /dev/null +++ b/src/OpenSHC/Map/Units/UpdateSiegeTent.cpp @@ -0,0 +1,62 @@ +#include "../Units.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentUnitSlotID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x005307B0 + void Units::UpdateSiegeTent() + { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x30_animRelated = 0; + int const frame = (DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].fixedRng + 1) & 3; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = frame; + // fixme: never true after the & 3, but the original compares and stores it + if (frame >= 4) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].gfxNumber = 2; + } + // the tent turns into a siege engine after 500 ticks + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber++; + if (DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].animationCycleNumber <= 500) { + return; + } + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].logicalState + = OpenSHC::Map::Units::ULS_TRANSITIONING; + // state_2 is stored in both arms: one store after the if turns the type store into a select + if ((DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].fixedRng & 2) != 0) { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].unitTypeToChangeInto + = OpenSHC::Map::Units::UT_S_TREBUCHET; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state_2 + = OpenSHC::Map::Units::States::US_FIRE_WEAPONUnk; + } else { + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].unitTypeToChangeInto + = OpenSHC::Map::Units::UT_S_CATAPULT; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].state_2 + = OpenSHC::Map::Units::States::US_FIRE_WEAPONUnk; + } + // face the keep of player 1 (y is read before x) + int const keepY = DAT_GameState::instance.playerDataArray[1] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .yEntry; + int const keepX = DAT_GameState::instance.playerDataArray[1] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .xEntry; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::calculatePreferredRelativeOrientation, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].x, + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].y, keepX, keepY); + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].facingDirection + = DAT_DirectionAlgorithmState::instance.orientation; + DAT_UnitsState::instance.units[DAT_CurrentUnitSlotID::instance].field_0x3bc = 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e8a6864d03..07d4d3b270 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49631,7 +49631,7 @@ SHC_3BB0A8C1_0x00530720 | 0.0% | Pending SHC_3BB0A8C1_0x00530760 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005307B0 | 0.0% | Pending +SHC_3BB0A8C1_0x005307B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00530880 | 100.0% | Reimplemented