From 169d263c1937a20e8e5b42ed7c0168ae8adf2050 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 13:56:12 +0100 Subject: [PATCH 01/51] Copy 16 functions from gynt's catch-all branches to reimpl/entities-projectiles-fire Their best match lives only on gynt's catch-all branches, which are ~2080 cpp files ahead of their merge base and 412 commits behind main. The cpp files are copied unchanged, without the headers of those branches: - gynt/reimpl/UI-DisplayElements-pr-development@fbc092e15 (16) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/calculateEntityDrawOffset.cpp | 49 ++ .../computeLineOfSightDistance.cpp | 375 ++++++++++ .../handleProjectileWallBounce.cpp | 412 +++++++++++ .../initializeProjectileVelocities.cpp | 249 +++++++ .../Map/Entities/EntityState/math_atan_1.cpp | 63 ++ .../EntityState/moveProjectileEntity.cpp | 167 +++++ .../processEntityHitBuildingOrUnit.cpp | 678 ++++++++++++++++++ .../Entities/EntityState/processSeaGulls.cpp | 287 ++++++++ .../EntityState/spawnProjectileEntity.cpp | 301 ++++++++ .../spawnProjectileImpactDebris.cpp | 341 +++++++++ .../Entities/EntityState/updateEntities.cpp | 302 ++++++++ .../updateProjectileHeightAndCollision.cpp | 35 + .../Map/Entities/IgniteFireAtMiniTile.cpp | 98 +++ .../Map/Entities/UpdateEntity_CowFlying.cpp | 51 ++ src/OpenSHC/Map/Entities/UpdateFireEntity.cpp | 243 +++++++ .../Map/Entities/UpdateFlag_1_2_4_Entity.cpp | 88 +++ 16 files changed, 3739 insertions(+) create mode 100644 src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp create mode 100644 src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp create mode 100644 src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp create mode 100644 src/OpenSHC/Map/Entities/UpdateFireEntity.cpp create mode 100644 src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp new file mode 100644 index 0000000000..074b5592e1 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -0,0 +1,49 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004036F0 + void EntityState::calculateEntityDrawOffset(int entityID) + { + uint _microYPart; + int _yOffset; + uint _microXPart; + int _xOffset; + _microXPart = (byte)this->entityArray[entityID].microX & 7; + _microYPart = (byte)this->entityArray[entityID].microY & 7; + if (DAT_TileMapState::instance.mapOrientation == 4) { + _microXPart = 7 - _microXPart; + _microYPart = 7 - _microYPart; + } else { + if (DAT_TileMapState::instance.mapOrientation == 2) { + _xOffset = (7 - _microXPart) * 0x10; + _yOffset = _microYPart * 2; + goto LAB_0040372e; + } + if (DAT_TileMapState::instance.mapOrientation == 6) { + _xOffset = _microXPart << 4; + _yOffset = (7 - _microYPart) * 2; + goto LAB_0040372e; + } + if (DAT_TileMapState::instance.mapOrientation) { + _xOffset = _microXPart << 4; + _yOffset = _microYPart * 2; + goto LAB_0040372e; + } + } + _xOffset = _microXPart * 2; + _yOffset = _microYPart << 4; + LAB_0040372e: + this->entityArray[entityID].x1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset].x; + this->entityArray[entityID].y1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset + 1].x; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp new file mode 100644 index 0000000000..ef24a1489c --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -0,0 +1,375 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402E20 + uint EntityState::computeLineOfSightDistance( + int x, int y, int height, int targetX, int targetY, int targetHeight, int param_7) + { + int iVar1; + int iVar2; + short sVar3; + bool bVar4; + bool bVar5; + int iVar6; + int iVar7; + uint uVar8; + int iVar9; + int iVar10; + int iVar11; + uint uVar12; + int iVar13; + int iVar14; + int* piVar15; + uint local_44; + uint local_40; + int local_3c; + int local_38; + uint local_30; + int local_1c; + iVar9 = y; + local_1c = -1; + uVar12 = 0; + local_44 = 100000; + local_30 = 0; + local_40 = 0; + bVar4 = true; + bVar5 = false; + if (targetHeight + 0x36 < height) { + uVar12 = 100; + local_40 = 100; + } + iVar6 = (int)(y + (y >> 0x1f & 7U)) >> 3; + iVar10 = (int)((x >> 0x1f & 7U) + x) >> 3; + iVar7 = DAT_ViewportRenderState::instance.translationMatrix[iVar6].addXgetTile + iVar10; + local_3c = x; + local_38 = y; + if ((DAT_TileMapState::instance.LogicLayer[iVar7] & 0x10000000U)) { + height = height + 10; + } + sVar3 = -1; + if (DAT_TileMapState::instance.BuildingLayer[iVar7] != 0) { + sVar3 = DAT_TileMapState::instance.BuildingLayer[iVar7]; + } + if (targetY < y) { + iVar7 = y - targetY; + } else { + iVar7 = targetY - y; + } + if (targetX < x) { + iVar11 = x - targetX; + } else { + iVar11 = targetX - x; + } + iVar1 = (uint)(x <= targetX) * 2 + -1; + iVar2 = (uint)(y <= targetY) * 2 + -1; + if (!iVar11) { + if (iVar7) { + if (0x1b < uVar12) { + uVar12 = 0x1c; + } + uVar8 = 0; + local_40 = uVar12 / 2; + local_44 = 0; + iVar9 = -1; + this->lineOfSightClearanceSteps = uVar12; + do { + local_38 = local_38 + iVar2; + iVar6 = iVar9; + if (((local_44 & 1)) && (!param_7)) { + iVar6 = DAT_ViewportRenderState::instance + .translationMatrix[(int)(local_38 + (local_38 >> 0x1f & 7U)) >> 3] + .addXgetTile + + iVar10; + if (!(DAT_TileMapState::instance.LogicLayer[iVar6] & 0x400300U)) { + bVar4 = false; + this->lineOfSightClearanceSteps = local_44; + } + if (!local_40) { + if (iVar9 == iVar6) { + if (bVar5) { + uVar12 = local_38 - y >> 0x1f; + iVar9 = ((local_38 - y ^ uVar12) - uVar12) * (targetHeight - height); + goto LAB_004033cf; + } + } else { + bVar5 = false; + if (((char)DAT_TileMapState::instance.LogicLayer[iVar6] < '\0') + || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar6] + && ((!bVar4 + || (!(DAT_TileMapState::instance.LogicLayer[iVar6] & 0x400200U))))))) { + bVar5 = true; + uVar8 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)(iVar6, 1); + uVar12 = local_38 - y >> 0x1f; + iVar9 = ((local_38 - y ^ uVar12) - uVar12) * (targetHeight - height); + LAB_004033cf: + if (iVar9 / iVar7 + height < (int)uVar8) { + return 0; + } + } + } + } else { + local_40 = local_40 - 1; + } + } + if ((x == targetX) && (local_38 == targetY)) { + return local_44; + } + local_44 = local_44 + 1; + iVar9 = iVar6; + if (999 < (int)local_44) { + return local_44; + } + } while (true); + } + } else { + if (!iVar7) { + if (0x1b < uVar12) { + uVar12 = 0x1c; + } + uVar8 = uVar12 / 2; + local_44 = 0; + this->lineOfSightClearanceSteps = uVar12; + while (true) { + local_3c = local_3c + iVar1; + if (((local_44 & 1)) && (!param_7)) { + iVar9 = ((int)(local_3c + (local_3c >> 0x1f & 7U)) >> 3) + + DAT_ViewportRenderState::instance.translationMatrix[iVar6].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[iVar9] & 0x400300U)) { + bVar4 = false; + this->lineOfSightClearanceSteps = local_44; + } + if (!uVar8) { + if (local_1c == iVar9) { + local_1c = iVar9; + if ((bVar5) + && (uVar12 = local_3c - x >> 0x1f, + (int)(((local_3c - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 + + height + < (int)local_30)) { + return 0; + } + } else { + bVar5 = false; + if (((char)DAT_TileMapState::instance.LogicLayer[iVar9] < '\0') + || ((local_1c = iVar9, + sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar9] + && ((!bVar4 + || (!(DAT_TileMapState::instance.LogicLayer[iVar9] + & 0x400200U))))))) { + bVar5 = true; + local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)(iVar9, 1); + uVar12 = local_3c - x >> 0x1f; + local_1c = iVar9; + if ((int)(((local_3c - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 + + height + < (int)local_30) { + return 0; + } + } + } + } else { + uVar8 = uVar8 - 1; + local_1c = iVar9; + } + } + if ((local_3c == targetX) && (y == targetY)) + break; + local_44 = local_44 + 1; + if (999 < (int)local_44) { + return local_44; + } + } + return local_44; + } + if (iVar7 <= iVar11) { + iVar7 = iVar7 * 2; + iVar6 = iVar7 - iVar11; + if ((targetHeight < height) && (uVar12)) { + uVar8 = targetX - x >> 0x1f; + iVar10 = (targetX - x ^ uVar8) - uVar8; + iVar10 = ((int)(iVar10 + (iVar10 >> 0x1f & 7U)) >> 3) + -1; + if (4 < iVar10) { + iVar10 = 4; + } + if (1 < iVar10) { + y = iVar10 + -1; + iVar10 = iVar1; + do { + local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)((((int)(targetX + (targetX >> 0x1f & 7U)) >> 3) - iVar10) + + DAT_ViewportRenderState::instance + .translationMatrix[(int)(targetY + (targetY >> 0x1f & 7U)) >> 3] + .addXgetTile, + 1); + if (targetHeight < (int)local_30) { + uVar12 = 0x1c; + } + iVar10 = iVar10 + iVar1; + y = y + -1; + } while (y); + } + } + local_40 = uVar12 / 2; + local_44 = 0; + iVar10 = x; + iVar14 = -1; + this->lineOfSightClearanceSteps = uVar12; + while (true) { + iVar10 = iVar10 + iVar1; + iVar13 = iVar7; + if (0 < iVar6) { + iVar9 = iVar9 + iVar2; + iVar13 = iVar7 + iVar11 * -2; + local_38 = iVar9; + } + iVar6 = iVar6 + iVar13; + iVar13 = iVar14; + if (((local_44 & 1)) && (!param_7)) { + iVar13 = ((int)(iVar10 + (iVar10 >> 0x1f & 7U)) >> 3) + + DAT_ViewportRenderState::instance + .translationMatrix[(int)(iVar9 + (iVar9 >> 0x1f & 7U)) >> 3] + .addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[iVar13] & 0x400300U)) { + bVar4 = false; + this->lineOfSightClearanceSteps = local_44; + } + if (!local_40) { + if (iVar14 == iVar13) { + if ((bVar5) + && (uVar12 = iVar10 - x >> 0x1f, + (int)(((iVar10 - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 + + height + < (int)local_30)) { + return 0; + } + } else { + bVar5 = false; + if (((char)DAT_TileMapState::instance.LogicLayer[iVar13] < '\0') + || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar13] + && ((!bVar4 + || (!(DAT_TileMapState::instance.LogicLayer[iVar13] & 0x400200U))))))) { + bVar5 = true; + local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)(iVar13, 1); + uVar12 = iVar10 - x >> 0x1f; + iVar9 = local_38; + if ((int)(((iVar10 - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 + + height + < (int)local_30) { + return 0; + } + } + } + } else { + local_40 = local_40 - 1; + } + } + if ((iVar10 == targetX) && (iVar9 == targetY)) + break; + local_44 = local_44 + 1; + iVar14 = iVar13; + if (999 < (int)local_44) { + return local_44; + } + } + return local_44; + } + iVar11 = iVar11 * 2; + iVar9 = iVar11 - iVar7; + if ((targetHeight < height) && (local_40)) { + uVar12 = targetY - y >> 0x1f; + iVar6 = (targetY - y ^ uVar12) - uVar12; + iVar6 = ((int)(iVar6 + (iVar6 >> 0x1f & 7U)) >> 3) + -1; + if (4 < iVar6) { + iVar6 = 4; + } + if (1 < iVar6) { + piVar15 = (int*)((int)DAT_ViewportRenderState::ptr + + (((int)(targetY + (targetY >> 0x1f & 7U)) >> 3) - iVar2) * 0xc + 0x188728); + iVar6 = iVar6 + -1; + do { + local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)(*piVar15 + ((int)(targetX + (targetX >> 0x1f & 7U)) >> 3), 1); + if (targetHeight < (int)local_30) { + local_40 = 0x1c; + } + piVar15 = piVar15 + iVar2 * -3; + iVar6 = iVar6 + -1; + } while (iVar6); + } + } + this->lineOfSightClearanceSteps = local_40; + local_40 = local_40 / 2; + local_44 = 0; + iVar6 = y; + iVar10 = -1; + do { + iVar6 = iVar6 + iVar2; + iVar14 = iVar11; + if (0 < iVar9) { + x = x + iVar1; + iVar14 = iVar11 + iVar7 * -2; + local_3c = x; + } + iVar9 = iVar9 + iVar14; + iVar14 = iVar10; + if (((local_44 & 1)) && (!param_7)) { + iVar14 = ((int)(x + (x >> 0x1f & 7U)) >> 3) + + DAT_ViewportRenderState::instance + .translationMatrix[(int)(iVar6 + (iVar6 >> 0x1f & 7U)) >> 3] + .addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[iVar14] & 0x400300U)) { + bVar4 = false; + this->lineOfSightClearanceSteps = local_44; + } + if (!local_40) { + if (iVar10 == iVar14) { + if ((bVar5) + && (uVar12 = iVar6 - y >> 0x1f, + (int)(((iVar6 - y ^ uVar12) - uVar12) * (targetHeight - height)) / iVar7 + + height + < (int)local_30)) { + return 0; + } + } else { + bVar5 = false; + if (((char)DAT_TileMapState::instance.LogicLayer[iVar14] < '\0') + || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar14] + && ((!bVar4 + || (!(DAT_TileMapState::instance.LogicLayer[iVar14] & 0x400200U))))))) { + bVar5 = true; + local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, + DAT_TileMapState::ptr)(iVar14, 1); + uVar12 = iVar6 - y >> 0x1f; + x = local_3c; + if ((int)(((iVar6 - y ^ uVar12) - uVar12) * (targetHeight - height)) / iVar7 + + height + < (int)local_30) { + return 0; + } + } + } + } else { + local_40 = local_40 - 1; + } + } + } while (((x != targetX) || (iVar6 != targetY)) + && (local_44 = local_44 + 1, iVar10 = iVar14, (int)local_44 < 1000)); + } + return local_44; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp new file mode 100644 index 0000000000..1c4b3dd2fd --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -0,0 +1,412 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + + // FUNCTION: STRONGHOLDCRUSADER 0x00403FF0 + void EntityState::handleProjectileWallBounce(int param_1) + { + word wVar1; + byte _bitFlag; + uint y; + undefined4 uVar2; + uint x; + uint uVar3; + short sVar4; + int iVar5; + uint uVar6; + short sVar7; + short sVar8; + int iVar9; + bool bVar10; + bool bVar11; + bool bVar12; + double fVar13; + double fVar14; + sVar4 = this->entityArray[param_1].microY; + y = (uint)sVar4; + sVar8 = this->entityArray[param_1].microX; + x = (uint)sVar8; + uVar3 = x & 7; + iVar5 = 0; + iVar9 = 0; + uVar6 = y & 7; + _bitFlag = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, + DAT_TileMapState::ptr)(x / 8, (int)((int)(y / 8))); + switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + switchD_0040405c_caseD_3c: + iVar9 = (int)this->entityArray[param_1].y_2; + LAB_004042e5: + iVar5 = (int)this->entityArray[param_1].x_2; + break; + case 0x3d: + uVar6 = 7 - uVar6; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 10) { + case 0: + case 8: + switchD_00404081_caseD_0: + uVar6 = 100; + break; + case 2: + switchD_00404081_caseD_2: + uVar3 = 100; + break; + case 10: + goto switchD_0040405c_caseD_3c; + } + switchD_00404081_caseD_4: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = uVar3 == uVar6; + } + goto LAB_0040408f; + case 0x3e: + uVar6 = 7 - uVar6; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 10) { + case 0: + case 8: + goto switchD_00404081_caseD_0; + case 2: + goto switchD_00404081_caseD_2; + default: + goto switchD_00404081_caseD_4; + case 10: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x3f: + uVar6 = 7 - uVar6; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 10) { + case 0: + case 2: + goto switchD_00404081_caseD_2; + default: + goto switchD_00404081_caseD_4; + case 8: + goto switchD_00404081_caseD_0; + case 10: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x41: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0x82) { + case 0: + case 2: + switchD_0040410f_caseD_0: + uVar6 = 100; + default: + switchD_0040410f_caseD_4: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = uVar3 == uVar6; + break; + case 0x80: + switchD_0040410f_caseD_80: + bVar12 = (100 < uVar6); + bVar11 = (int)(100 - uVar6) < 0; + bVar10 = uVar6 == 100; + break; + case 0x82: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x42: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0x82) { + case 0: + case 2: + goto switchD_0040410f_caseD_0; + default: + goto switchD_0040410f_caseD_4; + case 0x80: + goto switchD_0040410f_caseD_80; + case 0x82: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x43: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0x82) { + case 0: + case 0x80: + switchD_00404173_caseD_0: + uVar3 = 100; + default: + switchD_00404173_caseD_4: + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = uVar3 == uVar6; + break; + case 2: + switchD_00404173_caseD_2: + bVar12 = (uVar3 < 100); + bVar11 = (int)(uVar3 - 100) < 0; + bVar10 = uVar3 == 100; + break; + case 0x82: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x45: + uVar3 = 7 - uVar3; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0xa0) { + case 0: + case 0x80: + goto switchD_0040410f_caseD_0; + case 0x20: + goto switchD_0040410f_caseD_80; + default: + goto switchD_0040410f_caseD_4; + case 0xa0: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x46: + uVar3 = 7 - uVar3; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0xa0) { + case 0: + case 0x80: + goto switchD_0040410f_caseD_0; + case 0x20: + goto switchD_0040410f_caseD_80; + default: + goto switchD_0040410f_caseD_4; + case 0xa0: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x47: + uVar3 = 7 - uVar3; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0xa0) { + case 0: + case 0x20: + goto switchD_00404173_caseD_0; + default: + goto switchD_00404173_caseD_4; + case 0x80: + goto switchD_00404173_caseD_2; + case 0xa0: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x49: + iVar5 = -uVar3 + 7; + iVar9 = 7 - uVar6; + bVar12 = (iVar5 < iVar9); + bVar11 = iVar5 - iVar9 < 0; + bVar10 = false; + if (iVar5 == iVar9) { + switch (_bitFlag & 0x28) { + case 0: + case 0x20: + iVar5 = 100; + default: + bVar12 = (iVar5 < iVar9); + bVar11 = iVar5 - iVar9 < 0; + bVar10 = iVar5 == iVar9; + break; + case 8: + bVar12 = (iVar5 < 100); + bVar11 = (int)(-uVar3 + -0x5d) < 0; + bVar10 = iVar5 == 100; + break; + case 0x28: + goto switchD_0040405c_caseD_3c; + } + } + LAB_0040408f: + if (bVar10 || bVar12 != bVar11) { + iVar9 = this->entityArray[param_1].microY * 2 - (int)this->entityArray[param_1].y_2; + goto LAB_004042e5; + } + iVar9 = (int)this->entityArray[param_1].y_2; + iVar5 = this->entityArray[param_1].microX * 2 - (int)this->entityArray[param_1].x_2; + break; + case 0x4a: + uVar3 = 7 - uVar3; + uVar6 = 7 - uVar6; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0x28) { + case 0: + case 8: + goto switchD_00404081_caseD_0; + default: + goto switchD_00404081_caseD_4; + case 0x20: + goto switchD_00404081_caseD_2; + case 0x28: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + case 0x4b: + uVar3 = 7 - uVar3; + uVar6 = 7 - uVar6; + bVar12 = (uVar3 < uVar6); + bVar11 = (int)(uVar3 - uVar6) < 0; + bVar10 = false; + if (uVar3 == uVar6) { + switch (_bitFlag & 0x28) { + case 0: + case 8: + goto switchD_00404081_caseD_0; + default: + goto switchD_00404081_caseD_4; + case 0x20: + goto switchD_00404081_caseD_2; + case 0x28: + goto switchD_0040405c_caseD_3c; + } + } + goto LAB_0040408f; + default: + break; + } + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, + DAT_DirectionAlgorithmState::ptr)(x, (int)((int)(y)), iVar5, iVar9); + this->entityArray[param_1].orientation = DAT_DirectionAlgorithmState::instance.orientation; + sVar7 = (short)iVar9; + if (iVar9 < (int)y) { + this->entityArray[param_1].pathDeltaY = sVar4 - sVar7; + } else { + this->entityArray[param_1].pathDeltaY = sVar7 - sVar4; + } + sVar4 = (short)iVar5; + if (iVar5 < (int)x) { + this->entityArray[param_1].pathDeltaX = sVar8 - sVar4; + } else { + this->entityArray[param_1].pathDeltaX = sVar4 - sVar8; + } + sVar8 = this->entityArray[param_1].pathDeltaX; + this->entityArray[param_1].pathTargetX = sVar4; + this->entityArray[param_1].someMicroX = (ushort)((int)x <= iVar5) * 2 + -1; + this->entityArray[param_1].pathTargetY = sVar7; + this->entityArray[param_1].someMicroY = (ushort)((int)y <= iVar9) * 2 + -1; + if (!sVar8) { + if (this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathAxisCase = 0; + } else { + this->entityArray[param_1].pathAxisCase = 1; + } + } else { + sVar4 = this->entityArray[param_1].pathDeltaY; + if (!sVar4) { + this->entityArray[param_1].pathAxisCase = 2; + } else if (sVar8 < sVar4) { + this->entityArray[param_1].pathAxisCase = 3; + } else { + this->entityArray[param_1].pathAxisCase = 4; + } + } + sVar4 = this->entityArray[param_1].pathAxisCase; + if (sVar4 == 3) { + sVar4 = this->entityArray[param_1].pathDeltaY; + sVar8 = sVar8 * 2; + this->entityArray[param_1].pathErrorStepStraight = sVar8; + sVar7 = sVar8 + sVar4 * -2; + this->entityArray[param_1].pathError = sVar8 - sVar4; + } else { + if (sVar4 != 4) + goto LAB_0040440f; + sVar4 = this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathErrorStepStraight = sVar4; + sVar7 = sVar4 + sVar8 * -2; + this->entityArray[param_1].pathError = sVar4 - sVar8; + } + this->entityArray[param_1].pathErrorStepDiagonal = sVar7; + LAB_0040440f: + wVar1 = this->entityArray[param_1].graphicRotationUnk; + this->entityArray[param_1].startingAngle = wVar1; + if ((short)wVar1 < -0x50) { + this->entityArray[param_1].startingAngle = -0x50; + } + iVar9 = (int)this->entityArray[param_1].startingAngle; + this->entityArray[param_1].speedUnk = 0; + iVar5 = (int)this->entityArray[param_1].velocityUnk; + fVar13 = ((double)iVar9 * (double)3.1415926535) / (double)180.0; + sVar4 = this->entityArray[param_1].height; + sVar8 = (short)(iVar5 / 8); + this->entityArray[param_1].velocityUnk = sVar8; + this->entityArray[param_1].startingHeight = sVar4; + this->entityArray[param_1].travelledDistance = 0; + fVar14 = cos(fVar13); + this->entityArray[param_1].vCos = (float)((double)(int)sVar8 * fVar14); + fVar13 = sin((double)fVar13); + this->entityArray[param_1].vSin = (float)((double)(int)sVar8 * fVar13); + uVar2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar9); + sVar4 = this->entityArray[param_1].xPosition; + this->entityArray[param_1].rotationFrameIndex = (short)uVar2; + sVar8 = this->entityArray[param_1].yPosition; + this->entityArray[param_1].gmLookupValue = 0; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)sVar4, (int)((int)(sVar8)), DE::SHCDE::FX_ARROW_BOUNCE); + return; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp new file mode 100644 index 0000000000..176309d051 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -0,0 +1,249 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00403A20 + void EntityState::initializeProjectileVelocities( + int entityID, int x, int y, int height, int targetX, int targetY, int targetZ) + { + float fVar1; + short sVar2; + ushort uVar3; + EntityTypeShort EVar4; + short sVar5; + uint uVar6; + int iVar7; + undefined4 uVar8; + short sVar9; + short sVar10; + int iVar11; + double fVar12; + double fVar13; + sVar5 = (short)targetY; + if (targetY < y) { + this->entityArray[entityID].pathDeltaY = (short)y - sVar5; + } else { + this->entityArray[entityID].pathDeltaY = sVar5 - (short)y; + } + sVar10 = (short)targetX; + if (targetX < x) { + sVar9 = (short)x - sVar10; + } else { + sVar9 = sVar10 - (short)x; + } + sVar2 = this->entityArray[entityID].targetZ; + this->entityArray[entityID].pathDeltaX = sVar9; + sVar9 = this->entityArray[entityID].height; + if (sVar9 < sVar2) { + this->entityArray[entityID].pathDeltaZ = sVar2 - sVar9; + } else { + this->entityArray[entityID].pathDeltaZ = sVar9 - sVar2; + } + sVar9 = this->entityArray[entityID].pathDeltaX; + this->entityArray[entityID].pathTargetX = sVar10; + this->entityArray[entityID].pathTargetY = sVar5; + this->entityArray[entityID].someMicroX = (ushort)(x <= targetX) * 2 + -1; + this->entityArray[entityID].someMicroY = (ushort)(y <= targetY) * 2 + -1; + if (!sVar9) { + if (this->entityArray[entityID].pathDeltaY == 0) { + this->entityArray[entityID].pathAxisCase = 0; + } else { + this->entityArray[entityID].pathAxisCase = 1; + } + } else { + sVar5 = this->entityArray[entityID].pathDeltaY; + if (!sVar5) { + this->entityArray[entityID].pathAxisCase = 2; + } else if (sVar9 < sVar5) { + this->entityArray[entityID].pathAxisCase = 3; + } else { + this->entityArray[entityID].pathAxisCase = 4; + } + } + sVar5 = this->entityArray[entityID].pathAxisCase; + if (sVar5 == 3) { + sVar10 = sVar9 * 2; + sVar9 = this->entityArray[entityID].pathDeltaY; + this->entityArray[entityID].pathErrorStepStraight = sVar10; + sVar5 = this->entityArray[entityID].pathDeltaY; + this->entityArray[entityID].pathErrorStepDiagonal = sVar10 + sVar9 * -2; + LAB_00403b64: + this->entityArray[entityID].pathError = sVar10 - sVar5; + } else if (sVar5 == 4) { + sVar10 = this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathErrorStepStraight = sVar10; + sVar5 = this->entityArray[entityID].pathDeltaX; + this->entityArray[entityID].pathErrorStepDiagonal = sVar10 + sVar9 * -2; + goto LAB_00403b64; + } + iVar7 = DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType]; + if (!iVar7) { + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( + x, y, height, targetX, targetY, targetZ, 1); + sVar5 = (short)uVar6; + this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].totalFlightDistance = sVar5; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + sVar10 = this->entityArray[entityID].velocityUnk; + } else { + if (iVar7 == 1) { + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + iVar7 = this->entityArray[entityID].heightDifference; + sVar5 = (short)uVar6; + this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].totalFlightDistance = sVar5; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( + (int)(short)this->entityArray[entityID].entityType, + (double)((int)((int)this->entityArray[entityID].startingAngle)), (int)((int)(sVar5)), iVar7); + this->entityArray[entityID].velocityUnk = (short)iVar7; + goto LAB_00403f37; + } + if (iVar7 == 2) { + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + sVar5 = this->entityArray[entityID].height; + sVar10 = this->entityArray[entityID].targetZ; + sVar9 = (short)uVar6; + this->entityArray[entityID].field62_0x94 = sVar9; + this->entityArray[entityID].totalFlightDistance = sVar9; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + if (sVar10 < sVar5) { + this->entityArray[entityID].startingAngle = 3; + } + iVar7 = this->entityArray[entityID].heightDifference; + iVar11 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( + (int)(short)this->entityArray[entityID].entityType, + (double)((int)((int)this->entityArray[entityID].startingAngle)), (int)((int)(sVar9)), iVar7); + this->entityArray[entityID].velocityUnk = (short)iVar11; + if ((short)iVar11 < 1) { + EVar4 = this->entityArray[entityID].entityType; + this->entityArray[entityID].startingAngle = 0xf; + iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( + (int)(short)EVar4, 15.0, (int)((int)(sVar9)), iVar7); + this->entityArray[entityID].velocityUnk = (short)iVar7; + } + goto LAB_00403f37; + } + if (iVar7 == 3) { + uVar3 = (ushort)this->entityArray[entityID].rng_1; + this->entityArray[entityID].startingAngle = (uVar3 & 0xf) + 8; + this->entityArray[entityID].velocityUnk = (uVar3 & 7) + 0x15; + goto LAB_00403f37; + } + if (iVar7 == 4) { + uVar6 = this->entityArray[entityID].rng_1; + sVar5 = (short)((int)uVar6 % 0x14) + 0x10; + this->entityArray[entityID].startingAngle = sVar5; + if ((char)uVar6 < '\0') { + this->entityArray[entityID].startingAngle = -sVar5; + } + sVar5 = (short)(((int)uVar6 >> 8) % 0x14) + 0x10; + this->entityArray[entityID].velocityUnk = sVar5; + if (!(uVar6 & 0x8000)) { + return; + } + this->entityArray[entityID].velocityUnk = -sVar5; + return; + } + if (iVar7 == 5) { + iVar11 = this->entityArray[entityID].rng_1; + iVar7 = this->entityArray[entityID].rng_1; + this->entityArray[entityID].velocityUnk = 0; + this->entityArray[entityID].startingAngle = (byte)iVar11 & 7; + this->entityArray[entityID].graphicRotationUnk = (ushort)((uint)iVar7 >> 8) & 0x3f; + return; + } + if (iVar7 != 6) { + if (iVar7 == 7) { + return; + } + if (iVar7 == 10) { + return; + } + if (iVar7 == 8) { + sVar5 = this->entityArray[entityID].unitID_OR_seaGullID; + if (!sVar5) { + this->entityArray[entityID].startingAngle + = (short)(this->entityArray[entityID].rng_1 % 0x3c) + 8; + this->entityArray[entityID].velocityUnk + = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x23; + } else { + if (sVar5 == 4) { + this->entityArray[entityID].startingAngle + = (short)(this->entityArray[entityID].rng_1 % 0x1e) + 0xf; + sVar5 = ((byte)this->entityArray[entityID].rng_1 & 7) + 0xf; + } else { + iVar7 = this->entityArray[entityID].rng_1; + if (sVar5 == 5) { + this->entityArray[entityID].startingAngle = (short)(iVar7 % 0x1e) + 0x2d; + this->entityArray[entityID].velocityUnk + = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x23; + goto LAB_00403f37; + } + this->entityArray[entityID].startingAngle = (short)(iVar7 % 0x23) + 0x14; + sVar5 = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x19; + } + fVar1 = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; + this->entityArray[entityID].velocityUnk = sVar5; + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator = fVar1 * 0.75; + } + } else if (iVar7 == 9) { + this->entityArray[entityID].startingAngle = 0; + } + goto LAB_00403f37; + } + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( + x, y, height, targetX, targetY, targetZ, 1); + sVar5 = (short)uVar6; + this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].totalFlightDistance = sVar5; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + if (0x96 < sVar5) { + this->entityArray[entityID].velocityUnk = 0x7d; + } + sVar10 = this->entityArray[entityID].velocityUnk; + } + iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( + (int)(short)this->entityArray[entityID].entityType, (double)((int)((int)sVar10)), (int)((int)(sVar5)), + this->entityArray[entityID].heightDifference); + this->entityArray[entityID].startingAngle = (short)iVar7; + LAB_00403f37: + EVar4 = this->entityArray[entityID].entityType; + if ((((EVar4 == Map::Entities::ET_ARROW_AND_DEFAULT) + || (EVar4 == Map::Entities::ET_CROSSBOWARROW)) + && (height + 0x36 < targetZ)) + && (this->entityArray[entityID].rng_1 % 10 == 5)) { + this->entityArray[entityID].hasDoneEffectUnk = 1; + } + iVar11 = (int)this->entityArray[entityID].startingAngle; + this->entityArray[entityID].speedUnk = 0; + iVar7 = (int)this->entityArray[entityID].velocityUnk; + this->entityArray[entityID].travelledDistance = 0; + fVar12 = ((double)iVar11 * (double)3.1415926535) / (double)180.0; + fVar13 = cos(fVar12); + this->entityArray[entityID].vCos = (float)(fVar13 * (double)iVar7); + fVar12 = sin((double)fVar12); + this->entityArray[entityID].vSin = (float)(fVar12 * (double)iVar7); + uVar8 + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar11); + this->entityArray[entityID].rotationFrameIndex = (short)uVar8; + return; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp new file mode 100644 index 0000000000..a9efbea7ec --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp @@ -0,0 +1,63 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DOUBLE_00b941c0.hpp" + +#include "float.h" +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402C50 + int EntityState::math_atan_1(int entityType, double param_3, int param_4, int heightDifference) + { + double dVar1; + int iVar2; + int iVar3; + int iVar4; + double fVar5; + double fVar6; + fVar5 = (double)param_3 * (double)param_3; + fVar6 = (double)(param_4 * 4); + dVar1 = (double)(fVar5 / (fVar6 * (double)9.812)); + fVar5 = sqrt(((fVar5 * fVar5) / ((double)96.275344 * fVar6 * fVar6) + - ((fVar5 + fVar5) * (double)(heightDifference / 2)) / (fVar6 * fVar6 * (double)9.812)) + - (double)1.0); + fVar6 = (double)dVar1 - fVar5; + if (((double)DOUBLE_00b941c0::instance == fVar6) || (iVar2 = _isnan((double)fVar6), iVar2)) { + iVar2 = 1000; + } else { + fVar6 = atan((double)fVar6); + iVar2 = (long)((fVar6 * (double)180.0) / (double)3.1415926535 + (double)0.4999000132083893); + } + dVar1 = (double)fVar5 + dVar1; + if ((DOUBLE_00b941c0::instance == dVar1) || (iVar3 = _isnan(dVar1), iVar3)) { + iVar3 = 1000; + } else { + fVar5 = atan((double)dVar1); + iVar3 = (long)((fVar5 * (double)180.0) / (double)3.1415926535 + (double)0.4999000132083893); + } + iVar4 = iVar2; + if (iVar3 <= iVar2) { + iVar4 = iVar3; + } + if (iVar4 < -0x5a) { + iVar4 = iVar2; + if (iVar2 <= iVar3) { + iVar4 = iVar3; + } + if (iVar4 < -0x5a) { + return 0x2d; + } + } + if (0x5a < iVar4) { + return 0x2d; + } + return iVar4; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp new file mode 100644 index 0000000000..8c92e63349 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -0,0 +1,167 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + using Map::Entities::EntityType; + using WindowsHelper::Enums::BOOLEnum; + + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 Note that Ghidra is bad at x87 extended precision + instructions. This function likely does: float dx = vCos * speed * 0.25f; float dy = vSin * speed * + 0.25f; float t = vSin - gravityAccum; float slope = (height - (4.906f * t - t * t * velocity)) + / (distance - dx * t); float angle = atan(slope) * 180.0f / PI; + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004084A0 + BOOLEnum EntityState::moveProjectileEntity(int entityID) + { + short* psVar1; + short sVar2; + EntityTypeShort EVar3; + short sVar4; + int _dx; + int iVar5; + int iVar6; + int _height; + double _vSin; + double _dxRaw; + double _gravityConstantDiv2; + double _gravConstant_2; + double extraout_ST0; + double fVar7; + double extraout_ST1; + double extraout_ST1_00; + double fVar8; + int iVar9; + int local_10; + float _vCos; + float _speed; + float _accum_2; + int _entityID; + float _speed_2; + _entityID = entityID; + _speed = (float)this->entityArray[entityID].speedUnk; + _vCos = this->entityArray[entityID].vCos; + _vSin = (double)this->entityArray[entityID].vSin; + _height = (int)this->entityArray[entityID].height - (int)this->entityArray[entityID].startingHeight; + local_10 = 0; + if (this->entityArray[entityID].someCounter_OR_hitGround != 0) { + return FALSE; + } + if (this->entityArray[entityID].pathAxisCase == 0) { + this->entityArray[entityID].someCounter_OR_hitGround = 0x28; + } + _dxRaw = (double)_vCos * (double)_speed; + /* + 9.812 / 2 (gravity!) + */ + _gravityConstantDiv2 = (double)4.906; + _dx = (long)(_dxRaw * (double)0.25); + fVar7 = extraout_ST1; + iVar5 = (long)(_gravConstant_2 + _gravConstant_2); + if ((double)0 == _vSin) { + fVar7 = (double)(int)this->entityArray[entityID].startingAngle; + } else { + fVar8 = _vSin - (double)this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; + fVar7 = atan(((extraout_ST0 - (_gravityConstantDiv2 * fVar8 - fVar8 * fVar8 * extraout_ST1_00)) + / (fVar7 - _dxRaw * fVar8)) + * (double)3.0); + fVar7 = (fVar7 * (double)180.0) / (double)3.1415926535; + } + iVar6 = (long)(fVar7); + _accum_2 = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; + _speed_2 = (float)this->entityArray[entityID].speedUnk; + this->entityArray[entityID].graphicRotationUnk = (word)iVar6; + iVar6 = _dx - this->entityArray[entityID].travelledDistance; + this->entityArray[entityID].speedUnk = (int)(_accum_2 + _speed_2); + if (iVar6) { + local_10 = (iVar5 - _height) / iVar6; + } + sVar2 = this->entityArray[entityID].travelledDistance; + while (sVar2 < _dx) { + psVar1 = &this->entityArray[entityID].travelledDistance; + *psVar1 = *psVar1 + 1; + psVar1 = &this->entityArray[entityID].clearanceStepsRemaining; + *psVar1 = *psVar1 + -1; + if (entityID) { + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateEntityMicroMovement, this)(entityID); + if ((DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType] + != 9) + && (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType] + != 10)) { + _height = _height + local_10; + iVar9 = 1; + iVar6 = (long)((double)fVar7); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, + this)(entityID, (undefined4)((int)(_height)), iVar6, iVar9); + } + iVar6 = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); + if (!iVar6) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + entityID); + return TRUE; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); + if (this->entityArray[entityID].someCounter_OR_hitGround != 0) + break; + sVar2 = this->entityArray[entityID].travelledDistance; + } + EVar3 = this->entityArray[entityID].entityType; + (*(short*)&entityID) = (short)_dx; + this->entityArray[_entityID].travelledDistance = (short)entityID; + if (DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[(short)EVar3] == 9) { + sVar2 = this->entityArray[_entityID].height; + sVar4 = this->entityArray[_entityID].targetZ; + if (sVar2 < sVar4) { + this->entityArray[_entityID].height = sVar2 + 1; + return TRUE; + } + if ((sVar4 < sVar2) && (this->entityArray[_entityID].height = sVar2 + -8, (short)(sVar2 + -8) < 1)) { + iVar5 = (int)this->entityArray[_entityID].microY; + iVar6 = (int)this->entityArray[_entityID].microX; + this->entityArray[_entityID].someMicroY = 0; + this->entityArray[_entityID].someMicroX = 0; + this->entityArray[_entityID].height = 0; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( + 0, 0, 0, iVar6, iVar5, 0, iVar6, iVar5, 0, ((EntityType)0x1f), 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[_entityID].xPosition, + (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL_DIVE); + return TRUE; + } + } else { + if (DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[(short)EVar3] == 10) { + psVar1 = &this->entityArray[_entityID].height; + *psVar1 = *psVar1 + 1; + return TRUE; + } + iVar9 = 0; + iVar6 = (long)((double)fVar7); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + _entityID, (undefined4)((int)(iVar5)), iVar6, iVar9); + } + return TRUE; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp new file mode 100644 index 0000000000..32f6df2ea6 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -0,0 +1,678 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Commands::MappersEnum; + using DE::SHCDE::eSFX; + using Game::GameMode2; + using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; + using Map::Entities::EntityType; + using Map::Units::UnitType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00407190 + undefined4 EntityState::processEntityHitBuildingOrUnit(int entityID) + { + int* piVar1; + short* psVar2; + EntityTypeShort EVar3; + int uVar4; + short sVar5; + BuildingTypeShort BVar6; + short sVar7; + uint _y; + BOOLEnum BVar8; + int _buildingHealth; + int _entityOriginUnitID; + uint _x; + int iVar9; + int _randomNumber; + Point8IntXY* pPVar10; + int _someTile; + int iVar11; + uint _collateralDamageUnk; + int _randomNumber2; + uint _damageUnk; + int _buildingID; + EntityState* local_10; + int local_c; + int _tile; + uint local_4; + short _entityType; + short _entityType_2; + short _playerID; + short _yPosition; + short _xPosition; + local_10 = this; + _someTile = (int)this->entityArray[entityID].microX; + _buildingID = (int)this->entityArray[entityID].microY; + sVar7 = (short)((int)(_buildingID + (_buildingID >> 0x1f & 7U)) >> 3); + this->entityArray[entityID].yPosition = sVar7; + _y = (uint)sVar7; + sVar7 = (short)((int)(_someTile + (_someTile >> 0x1f & 7U)) >> 3); + this->entityArray[entityID].xPosition = sVar7; + _x = (uint)sVar7; + _entityType = this->entityArray[entityID].entityType; + _someTile = DAT_ViewportRenderState::instance.translationMatrix[_y].addXgetTile + _x; + local_c = 1; + this->entityArray[entityID].tile = _someTile; + if (_entityType == 0x1d) { + if ((((_x < 400) && (_y < 400)) && (*(char*)(_y * 400 + 0x21aec98 + _x) != '\0')) + && ((!(DAT_TileMapState::instance.LogicLayer[_someTile] & 0x30) + && (0 < this->entityArray[entityID].height)))) { + this->entityArray[entityID].nextEntityOnThisTileByID + = DAT_TileMapState::instance.EntityLayer[_someTile]; + DAT_TileMapState::instance.EntityLayer[_someTile] = (short)entityID; + return (undefined4)(1); + } + this->entityArray[entityID].tile = 0; + return (undefined4)(0); + } + if (((399 < _x) || (399 < _y)) || (*(char*)(_y * 400 + 0x21aec98 + _x) == '\0')) { + this->entityArray[entityID].logicalState = 3; + return (undefined4)(0); + } + if ((DAT_TileMapState::instance.LogicLayer[_someTile] & 0x30)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return (undefined4)(0); + } + _tile = _someTile * 2; + if ((int)_entityType - 10U < 6) { + DAT_TileMapState::instance.MiscDisplayLayer[_someTile] + = DAT_TileMapState::instance.MiscDisplayLayer[_someTile] | 0x1000; + EVar3 = this->entityArray[entityID].entityType; + if ((EVar3 == Map::Entities::ET_BRAZIER) + || (EVar3 == Map::Entities::ET_HEADS_ON_SPIKES)) { + _buildingID = this->entityArray[entityID].tile; + if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { + if ((DAT_TileMapState::instance.LogicLayer[_buildingID] & 0x100U)) { + if (DAT_TileMapState::instance.DamageLayer[_buildingID] == 0) { + this->entityArray[entityID].height + = (ushort)DAT_TileMapState::instance.HeightLayer[_buildingID]; + } else { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[_buildingID] + 0xf; + } + goto LAB_00408150; + } + } else { + switch (DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer[_buildingID]] + .buildingType) { + case Map::Buildings::BT_STONEKEEP: + case Map::Buildings::BT_STRONGHOLD: + case Map::Buildings::BT_KEEPFOUR: + case Map::Buildings::BT_KEEPFIVE: + case Map::Buildings::BT_GATEHOUSELARGE: + case Map::Buildings::BT_GATEHOUSESMALL: + case Map::Buildings::BT_TOWER1: + case Map::Buildings::BT_TOWER2: + case Map::Buildings::BT_TOWER3: + case Map::Buildings::BT_TOWER4: + case Map::Buildings::BT_TOWER5: + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, + DAT_TileMapState::ptr)(_buildingID); + this->entityArray[entityID].height = (short)_y; + goto LAB_00408150; + } + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_SIEGE_THAT) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::getBuildingCost, DAT_BuildingsState::ptr)( + Commands::M_MAPPER_BRAZIER, (int*)&local_10, (int*)&local_4); + piVar1 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .startResources + + 0xf; + *piVar1 = *piVar1 + local_4; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + } else { + _buildingID = this->entityArray[entityID].tile; + _y = DAT_TileMapState::instance.LogicLayer[_buildingID]; + if (!_y) { + if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( + entityID); + } + } else if (DAT_TileMapState::instance.DamageLayer[_buildingID] != 0) { + if (!(_y & 0x400000)) { + if (!(_y & 0x200)) { + this->entityArray[entityID].height + = (ushort)DAT_TileMapState::instance.HeightLayer[_buildingID]; + } else { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[_buildingID] + 10; + } + } else { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[_buildingID] + 0x14; + } + } + } + goto LAB_00408150; + } + uVar4 = (short)DAT_TileMapState::instance.UnitLayer[_someTile]; + if ((_entityType != 1) || (this->entityArray[entityID].rng_2 != 2)) { + if (((_entityType == 0x16) || (((_entityType == 3 || (_entityType == 2)) || (_entityType == 4)))) + || (0x50 < this->entityArray[entityID].velocityUnk)) { + while (_buildingID = (int)(short)uVar4, _buildingID) { + if ((this->entityArray[entityID].logicalState == 2) + && (BVar8 = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(_buildingID, entityID, 0), + BVar8)) { + if (this->entityArray[entityID].entityType != Map::Entities::ET_COW_FLYING) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( + entityID); + return (undefined4)(0); + } + _y = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(_someTile, 0); + this->entityArray[entityID].height = (short)_y; + goto LAB_004079b4; + } + uVar4 = DAT_UnitsState::instance.units[_buildingID].nextUnitOnTheSameTile; + } + } + EVar3 = this->entityArray[entityID].entityType; + if (((EVar3 == Map::Entities::ET_TREBUCHET) || (EVar3 == Map::Entities::ET_CATAPULT)) + || ((EVar3 == Map::Entities::ET_MANGONEL + || (0x50 < this->entityArray[entityID].velocityUnk)))) { + _buildingID = 1; + do { + uVar4 = DAT_TileMapState::instance + .UnitLayer[DAT_TileMapState::instance.directionTranslationMatrix + [this->entityArray[entityID].yPosition][_buildingID] + + _someTile]; + while (iVar11 = (int)(short)uVar4, iVar11) { + if (((DAT_UnitsState::instance.units[iVar11].field64_0x90 != 0) + && (this->entityArray[entityID].logicalState == 2)) + && (BVar8 = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(iVar11, entityID, 1), + BVar8)) { + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::markEntityDestroyed, local_10)(entityID); + return (undefined4)(0); + } + uVar4 = DAT_UnitsState::instance.units[iVar11].nextUnitOnTheSameTile; + } + _buildingID = _buildingID + 2; + } while (_buildingID < 8); + } + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD) { + local_4 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_someTile); + _buildingID = 0; + do { + iVar11 = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][_buildingID] + + _someTile; + uVar4 = (short)DAT_TileMapState::instance.UnitLayer[iVar11]; + while (iVar9 = (int)(short)uVar4, iVar9) { + _y = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(iVar11); + _x = (int)(local_4 - _y) >> 0x1f; + if (((int)((local_4 - _y ^ _x) - _x) < 0x78) + && (this->entityArray[entityID].logicalState == 2)) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(iVar9, entityID, 1); + } + uVar4 = DAT_UnitsState::instance.units[iVar9].nextUnitOnTheSameTile; + } + _buildingID = _buildingID + 1; + } while (_buildingID < 8); + pPVar10 = DAT_EntityDefinedData::instance.EntityBlastTileOffsets; + do { + _buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::computeTileAlongAxisOffset, + DAT_TileMapState::ptr)(_someTile, pPVar10->xOffset, (uint)((int)(pPVar10->yOffset))); + uVar4 = (short)DAT_TileMapState::instance.UnitLayer[_buildingID]; + while (iVar11 = (int)(short)uVar4, iVar11) { + _y = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_buildingID); + _x = (int)(local_4 - _y) >> 0x1f; + if (((int)((local_4 - _y ^ _x) - _x) < 0x78) + && (this->entityArray[entityID].logicalState == 2)) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(iVar11, entityID, 2); + } + uVar4 = DAT_UnitsState::instance.units[iVar11].nextUnitOnTheSameTile; + } + pPVar10 = pPVar10 + 1; + } while ((int)pPVar10 < 0x5b6e08); + } + if ((((this->entityArray[entityID].entityType == Map::Entities::ET_FIRE) + && (_buildingID = this->entityArray[entityID].tile, + (DAT_TileMapState::instance.LogicLayer[_buildingID] & 8) != 0)) + && (_buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(_buildingID), + _buildingID != 0)) + && (DAT_TileMapState::instance.pitchDitches[_buildingID].state == 1)) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, + (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].x * 8)), + (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].y * 8)), + (int)((int)((uint)DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[_buildingID].tile])), + 3); + DAT_TileMapState::instance.pitchDitches[_buildingID].state = 2; + } + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( + _someTile, 0); + _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); + if (((_buildingID) + && ((_buildingID = (int)(short)DAT_BuildingsState::instance.buildings[_buildingID].buildingType, + _buildingID == 0x3d || (_buildingID - 0x4aU < 5)))) + && ((this->entityArray[entityID].rng_1 & 4))) { + _y = _y + 0x14; + } + sVar7 = this->entityArray[entityID].height; + _buildingID = (int)sVar7; + if ((int)_y <= _buildingID) + goto LAB_00408150; + EVar3 = this->entityArray[entityID].entityType; + if (EVar3 == ((EntityType)0x20)) { + if (((_buildingID < (int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile]) + && (this->entityArray[entityID].someCounter_OR_hitGround = 1, + (DAT_TileMapState::instance.LogicLayer[_someTile] & 0x10000100U) == 0)) + && (((int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile] + < this->entityArray[entityID].startingHeight_2 + 0x32 + && ((MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile_Convenience)( + (int)this->entityArray[entityID].owner, + (int)((int)(this->entityArray[entityID].microX)), + (int)((int)(this->entityArray[entityID].microY)), + (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + - 8)), + 2), + (DAT_TileMapState::instance.LogicLayer[_someTile] & 8) != 0 + && (_buildingID + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(_someTile), + _buildingID != 0)))))) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, + (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].x * 8)), + (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].y * 8)), + (int)((int)((uint)DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[_buildingID].tile])), + 3); + if (DAT_TileMapState::instance.pitchDitches[_buildingID].state == 1) { + DAT_TileMapState::instance.pitchDitches[_buildingID].state = 2; + } + } + goto LAB_00408150; + } + if (EVar3 == ((EntityType)0x1b)) { + if (((_buildingID <= (int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile]) + && (this->entityArray[entityID].someCounter_OR_hitGround = 1, + (DAT_TileMapState::instance.LogicLayer[_someTile] & 0x40100001U) != 0)) + && (this->entityArray[entityID].unitID_OR_seaGullID == 0)) { + iVar11 = (int)this->entityArray[entityID].microY; + iVar9 = (int)this->entityArray[entityID].microX; + _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( + 1, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_MED_PLOP); + } + goto LAB_00408150; + } + if (EVar3 == ((EntityType)8)) { + _y = _buildingID - this->entityArray[entityID].targetZ; + _x = (int)_y >> 0x1f; + if (((int)((_y ^ _x) - _x) < 0x14) || (sVar7 < 9)) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } + goto LAB_00408150; + } + if (((EVar3 == Map::Entities::ET_ARROW_AND_DEFAULT) + || (EVar3 == Map::Entities::ET_CROSSBOWARROW)) + || ((EVar3 == Map::Entities::ET_BALLISTA + || ((EVar3 == Map::Entities::ET_SLINGER + || (EVar3 == Map::Entities::ET_FIRETHROWER)))))) { + if (this->entityArray[entityID].rng_2 == 2) { + _buildingID = 0; + do { + iVar11 = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][_buildingID] + + _someTile; + if (((DAT_TileMapState::instance.LogicLayer[iVar11] & 8)) + && (iVar11 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(iVar11), + iVar11 != 0)) + goto LAB_00407f73; + _buildingID = _buildingID + 1; + } while (_buildingID < 8); + } + _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); + if ((int)this->entityArray[entityID].travelledDistance + <= (int)this->entityArray[entityID].totalFlightDistance / 2) + goto LAB_00408150; + _y = DAT_TileMapState::instance.LogicLayer[_someTile]; + if ((_y & 0x40100001)) { + iVar11 = (int)this->entityArray[entityID].microY; + iVar9 = (int)this->entityArray[entityID].microX; + _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( + 1, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); + sVar7 = this->entityArray[entityID].yPosition; + sVar5 = this->entityArray[entityID].xPosition; + this->entityArray[entityID].logicalState = 3; + local_c = 0; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)sVar5, (int)((int)(sVar7)), DE::SHCDE::FX_LITTLE_PLOP); + goto LAB_00408150; + } + if ((!(_y & 0x10000100)) + && ((!_buildingID + || ((((BVar6 = DAT_BuildingsState::instance.buildings[_buildingID].buildingType, + BVar6 != Map::Buildings::BT_STONEKEEP && (BVar6 != Map::Buildings::BT_STRONGHOLD)) + && (BVar6 != Map::Buildings::BT_KEEPFOUR)) + && (BVar6 != Map::Buildings::BT_KEEPFIVE)))))) { + if (!(_y & 8)) { + if (!_buildingID) { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + } else { + _entityOriginUnitID = (int)this->entityArray[entityID].unitID_OR_seaGullID; + /* + if buildingtype is a tower (1 to 5) + */ + BVar6 = DAT_BuildingsState::instance.buildings[_buildingID].buildingType; + if (((0x49 < (short)BVar6) && ((short)BVar6 < 0x4f)) + || ((DAT_BuildingsState::instance.buildings[_buildingID].currentHealth == 0 + || ((_y & 0xf000000))))) + goto LAB_00408150; + if (DAT_UnitsState::instance.units[_entityOriginUnitID].unitType + == Map::Units::UT_S_FBALLISTA) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(_someTile, + (uint)((int)((int)this->entityArray[entityID].xPosition)), + (uint)((int)((int)this->entityArray[entityID].yPosition)), 10, 0, + (int)((int)(this->entityArray[entityID].owner)), FALSE, _entityOriginUnitID); + _buildingHealth = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getNonFarmFieldBuildingHealthAtTileOr1000, + DAT_TileMapState::ptr)(_someTile); + if (_buildingHealth < 50) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + (int)this->entityArray[entityID].owner, + (int)((int)(this->entityArray[entityID].xPosition * 8)), + (int)((int)(this->entityArray[entityID].yPosition * 8)), + (int)((int)((uint)DAT_TileMapState::instance + .HeightLayer[this->entityArray[entityID].tile])), + 3); + this->entityArray[entityID].someCounter_OR_hitGround = 1; + goto LAB_00408148; + } + } else { + if (this->entityArray[entityID].entityType == Map::Entities::ET_BALLISTA) { + _playerID = this->entityArray[entityID].owner; + _yPosition = this->entityArray[entityID].yPosition; + _xPosition = this->entityArray[entityID].xPosition; + _buildingID = 2; + } else { + _playerID = this->entityArray[entityID].owner; + _yPosition = this->entityArray[entityID].yPosition; + _xPosition = this->entityArray[entityID].xPosition; + _buildingID = 1; + } + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)_xPosition)), + (uint)((int)((int)_yPosition)), _buildingID, 0, (int)((int)(_playerID)), FALSE, + _entityOriginUnitID); + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } + } else { + if ((this->entityArray[entityID].rng_2 == 2) + && (iVar11 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(_someTile), + iVar11 != 0)) { + LAB_00407f73: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, + (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + (int)this->entityArray[entityID].owner, + (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].x * 8)), + (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].y * 8)), + (int)((int)((uint)DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[iVar11].tile])), + 3); + if (DAT_TileMapState::instance.pitchDitches[iVar11].state == 1) { + DAT_TileMapState::instance.pitchDitches[iVar11].state = 2; + } + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } + } else { + if (((this->entityArray[entityID].rotationFrameIndex < 3) + && (this->entityArray[entityID].startingAngle < 0)) + || ((this->entityArray[entityID].hasDoneEffectUnk != 0 + || (0 < this->entityArray[entityID].clearanceStepsRemaining)))) + goto LAB_00408150; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, local_10)( + entityID); + } + } else if (((EVar3 == Map::Entities::ET_TREBUCHET) + || (EVar3 == Map::Entities::ET_CATAPULT)) + || (EVar3 == Map::Entities::ET_MANGONEL)) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + _y = DAT_TileMapState::instance.LogicLayer[_someTile]; + _damageUnk = 10; + local_4 = _y & 0x40100001; + _collateralDamageUnk = 10; + if (local_4) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_ROCK_SPLASH); + } + _x = _y & 0x100; + if (((!_x) && (!(_y & 0x10000400))) + && (*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile) == 0)) { + psVar2 + = &DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field98_0xd2; + *psVar2 = *psVar2 + 1; + if (!(_y & 0x4a5014b1)) { + local_4 = _x; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, + (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_ROCK_HIT_GROUND); + _y = this->entityArray[entityID].rng_1 & 0x80000007; + this->entityArray[entityID].someCounter_OR_hitGround = 0x28; + local_c = 0; + if ((int)_y < 0) { + _y = (_y - 1 | 0xfffffff8) + 1; + } + if (_y != 0xfffffffb && -1 < (int)(_y + 5)) { + do { + _buildingID = (int)this->entityArray[entityID].microY; + iVar11 = (int)this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + local_10)(2, 0, 0, iVar11, _buildingID, + (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + + 2)), + (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, + ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50 + -0x28 + _buildingID, 8, + ((EntityType)0x1b), 0); + local_c = local_c + 1; + _y = this->entityArray[entityID].rng_1 & 0x80000007; + if ((int)_y < 0) { + _y = (_y - 1 | 0xfffffff8) + 1; + } + } while (local_c < (int)(_y + 5)); + } + } else if (local_4) { + _y = this->entityArray[entityID].rng_1 & 0x8000000f; + local_c = 0; + if ((int)_y < 0) { + _y = (_y - 1 | 0xfffffff0) + 1; + } + local_4 = 0; + if (_y != 0xfffffff6 && -1 < (int)(_y + 10)) { + do { + _buildingID = (int)this->entityArray[entityID].microY; + iVar11 = (int)this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + local_10)(1, 0, 0, iVar11, _buildingID, + (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + + 2)), + (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, + ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50 + -0x28 + _buildingID, 8, + ((EntityType)0x1b), 0); + local_c = local_c + 1; + _y = this->entityArray[entityID].rng_1 & 0x8000000f; + if ((int)_y < 0) { + _y = (_y - 1 | 0xfffffff0) + 1; + } + } while (local_c < (int)(_y + 10)); + } + iVar11 = (int)this->entityArray[entityID].microY; + iVar9 = (int)this->entityArray[entityID].microX; + _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( + 0, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); + } + } else { + local_4 = _x; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, local_10)( + entityID); + _entityType_2 = this->entityArray[entityID].entityType; + if (_entityType_2 == 3) { + _damageUnk = 60; + _collateralDamageUnk = 0x1e; + } else if (_entityType_2 == 2) { + _damageUnk = 20; + } else if (_entityType_2 == 4) { + _damageUnk = 5; + _collateralDamageUnk = 0; + } + _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); + if (!_buildingID) { + if ((local_4) + && (DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[(DAT_TileMapState::instance.WallOwnerLayer[_someTile] & 7) + 1])) { + _damageUnk = 0; + _collateralDamageUnk = 0; + } + } else if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[_buildingID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner]) { + _damageUnk = 0; + _collateralDamageUnk = 0; + } + if (_entityType_2 == 4) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, + (int)((int)(-this->entityArray[entityID].owner)), FALSE, + (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateral, + DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + (uint)((int)((int)this->entityArray[entityID].yPosition)), + (int)((int)(_collateralDamageUnk)), (int)((int)(-this->entityArray[entityID].owner)), 0, + (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); + } else { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, + (int)((int)(this->entityArray[entityID].owner)), FALSE, + (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateralThunk, + DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + (uint)((int)((int)this->entityArray[entityID].yPosition)), + (int)((int)(_collateralDamageUnk)), (int)((int)(this->entityArray[entityID].owner)), 0); + } + /* + woodhit_02.wav ? + */ + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_ROCK_HIT_WALL); + } + } else { + if (EVar3 != Map::Entities::ET_COW_FLYING) + goto LAB_00408150; + LAB_004079b4: + if (this->entityArray[entityID].hasDoneEffectUnk == 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), + DE::SHCDE::FX_COW_SPLAT); + this->entityArray[entityID].hasDoneEffectUnk = 1; + if (!(DAT_TileMapState::instance.LogicLayer[_someTile] & 0x401000b1U)) { + this->entityArray[entityID].someCounter_OR_hitGround = 0x28; + DAT_GameCore::instance.cowPoisonTrackerUnk = DAT_GameCore::instance.cowPoisonTrackerUnk + 500; + _randomNumber = (int)SEC_RNG::instance.currentNumber2 % 5 + -2; + if (_randomNumber < 8) { + _randomNumber2 = 8 - _randomNumber; + do { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + this)(0, (undefined4)((int)((int)this->entityArray[entityID].owner)), 0, + (int)((int)(this->entityArray[entityID].microX)), + (int)((int)(this->entityArray[entityID].microY)), + (int)((int)(this->entityArray[entityID].height)), 0, 0, 0, + Map::Entities::ET_COW_POISON_CLOUD, 0); + _randomNumber2 = _randomNumber2 + -1; + } while (_randomNumber2); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[entityID].xPosition, + (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_FLIES); + } else { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } + } + } + LAB_00408148: + local_c = 0; + LAB_00408150: + if (entityID) { + if (entityID < 25) { + this->entityArray[entityID].nextEntityOnThisTileByID + = (ushort)(byte)DAT_TileMapState::instance.EntityLayerLT25[_someTile]; + DAT_TileMapState::instance.EntityLayerLT25[_someTile] = (char)entityID; + return (undefined4)(local_c); + } + this->entityArray[entityID].nextEntityOnThisTileByID + = *(short*)((int)DAT_TileMapState::instance.EntityLayer + _tile); + *(short*)((int)DAT_TileMapState::instance.EntityLayer + _tile) = (short)entityID; + } + return (undefined4)(local_c); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp new file mode 100644 index 0000000000..60efb04727 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -0,0 +1,287 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00406900 + void EntityState::processSeaGulls(int seagullID) + { + short* psVar1; + short sVar2; + double dVar3; + short _newAngle; + short sVar5; + short _targetYPart1; + short sVar4; + uint _targetX; + uint _yDiff; + uint _newX; + BOOLEnum _newBounds; + int _oldMicroY; + int _oldMicroX; + uint _oldX; + BOOLEnum _oldBounds; + int _targetXPart2; + int _targetYPart2; + int iVar6; + uint uVar7; + int _microX; + uint _newY; + uint _oldY; + int iVar8; + uint uVar9; + int _newMicroY; + short _targetXPart1; + int _newMicroX; + int _entityID; + double fVar10; + double fVar11; + short _y; + short _yPosition; + sVar4 = this->seagullArray[seagullID].someCountDown; + _entityID = (int)this->seagullArray[seagullID].entityID; + if (sVar4) { + sVar4 = sVar4 + -1; + this->seagullArray[seagullID].someCountDown = sVar4; + if (sVar4) { + return; + } + _y = this->entityArray[_entityID].microY; + this->entityArray[_entityID].targetX = this->entityArray[_entityID].microX; + _yPosition = this->entityArray[_entityID].yPosition; + this->entityArray[_entityID].targetY = _y; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[_entityID].xPosition, (int)((int)(_yPosition)), + DE::SHCDE::FX_GULL_SURFACE); + } + _microX = (int)this->entityArray[_entityID].microX; + _targetX = _microX - this->entityArray[_entityID].targetX; + if (((int)((_targetX ^ (int)_targetX >> 0x1f) - ((int)_targetX >> 0x1f)) < 3) + && (_yDiff = (int)this->entityArray[_entityID].microY - (int)this->entityArray[_entityID].targetY, + (int)((_yDiff ^ (int)_yDiff >> 0x1f) - ((int)_yDiff >> 0x1f)) < 3)) { + if (((int)this->seagullArray[seagullID].randomNumber ^ this->entityArray[_entityID].rng_1 + ^ (int)SEC_RNG::instance.currentNumber2) + % 500 + == 123) { + _newMicroY + = (int)this->entityArray[_entityID].someMicroY + (int)this->entityArray[_entityID].microY; + _newMicroX = this->entityArray[_entityID].someMicroX + _microX; + _newY = _newMicroY / 8; + _newX = _newMicroX / 8; + _newBounds = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(_newX, _newY); + if (_newBounds) { + _oldMicroY = (int)this->entityArray[_entityID].microY; + _oldMicroX = (int)this->entityArray[_entityID].microX; + _oldY = _oldMicroY / 8; + _oldX = _oldMicroX / 8; + _oldBounds = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(_oldX, _oldY); + if (((_oldBounds) + && (( + DAT_TileMapState::instance.LogicLayer + [DAT_ViewportRenderState::instance.translationMatrix[_newY].addXgetTile + _newX] + & 1))) + && ((DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[_oldY].addXgetTile + + _oldX] + & 1))) { + this->seagullArray[seagullID].someCountDown = 160; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, + this)(_entityID, (int)((int)(this->entityArray[_entityID].microX)), + (int)((int)(this->entityArray[_entityID].microY)), 0xfa, _newMicroX, _newMicroY, 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[_entityID].xPosition, + (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL); + return; + } + } + } + sVar4 = this->seagullArray[seagullID].angle; + dVar3 = ((double)(sVar4 + -0xb4) * 3.1415926535) / 180.0; + _newAngle = this->seagullArray[seagullID].someAngle * 20 + sVar4; + this->seagullArray[seagullID].angle = _newAngle; + if (360 < _newAngle) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + if ((int)SEC_RNG::instance.currentNumber1 % 5 == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)this->entityArray[_entityID].xPosition, + (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL); + } + sVar4 = this->seagullArray[seagullID].field12_0x1a; + this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle + -360; + if (sVar4 < 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + 1; + } else if (0 < sVar4) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + -1; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 < 24) { + this->seagullArray[seagullID].unknownCounter_0x16 = 24; + } + if (80 < this->seagullArray[seagullID].unknownCounter_0x16) { + this->seagullArray[seagullID].unknownCounter_0x16 = 80; + } + this->seagullArray[seagullID].field12_0x1a = sVar4 + 1; + if ((short)(sVar4 + 1) >= 0x14) { + this->seagullArray[seagullID].field12_0x1a = -0x14; + } + } + sVar4 = this->seagullArray[seagullID].angle; + if (sVar4 < 0) { + this->seagullArray[seagullID].angle = sVar4 + 0x168; + sVar4 = this->seagullArray[seagullID].field12_0x1a; + if (sVar4 < 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + 1; + } else if (0 < sVar4) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + -1; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 < 0x18) { + this->seagullArray[seagullID].unknownCounter_0x16 = 0x18; + } + if (0x50 < this->seagullArray[seagullID].unknownCounter_0x16) { + this->seagullArray[seagullID].unknownCounter_0x16 = 0x50; + } + this->seagullArray[seagullID].field12_0x1a = sVar4 + 1; + if ((short)(sVar4 + 1) >= 0x14) { + this->seagullArray[seagullID].field12_0x1a = -0x14; + } + } + iVar8 = (int)this->seagullArray[seagullID].unknownCounter_0x16; + fVar10 = sin((double)dVar3); + _targetXPart2 = (long)(fVar10 * (double)iVar8); + fVar10 = cos((double)dVar3); + _targetYPart2 = (long)(fVar10 * (double)iVar8); + sVar4 = this->seagullArray[seagullID].angle_2; + sVar5 = this->seagullArray[seagullID].angleStep + sVar4; + this->seagullArray[seagullID].angle_2 = sVar5; + fVar10 = ((double)(sVar4 + -0xb4) * (double)3.1415926535) / (double)180.0; + if (sVar5 >= 0x168) { + this->seagullArray[seagullID].angle_2 = sVar5 + -0x168; + } + sVar4 = this->seagullArray[seagullID].angle_2; + if (sVar4 < 0) { + this->seagullArray[seagullID].angle_2 = sVar4 + 0x168; + } + iVar8 = (int)this->seagullArray[seagullID].numberBetween60And100; + fVar11 = sin(fVar10); + iVar6 = (long)(fVar11 * (double)iVar8); + _targetXPart1 = (short)iVar6 + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].x_2 = _targetXPart1; + fVar10 = cos((double)fVar10); + iVar8 = (long)(fVar10 * (double)iVar8); + _targetYPart1 = (short)iVar8; + _targetYPart1 = _targetYPart1 + this->seagullArray[seagullID].y; + this->seagullArray[seagullID].y_2 = _targetYPart1; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)( + _entityID, (int)((int)(this->entityArray[_entityID].microX)), + (int)((int)(this->entityArray[_entityID].microY)), + (int)((int)(this->entityArray[_entityID].height)), _targetXPart1 + _targetXPart2, + _targetYPart1 + _targetYPart2, (int)((int)(250))); + } + sVar4 = this->seagullArray[seagullID].x; + iVar8 = (int)sVar4; + uVar7 = iVar8 - this->seagullArray[seagullID].x_3; + uVar9 = (int)uVar7 >> 0x1f; + if (((1 < (int)((uVar7 ^ uVar9) - uVar9)) + || (uVar7 = (int)this->seagullArray[seagullID].y - (int)this->seagullArray[seagullID].y_3, + uVar9 = (int)uVar7 >> 0x1f, 1 < (int)((uVar7 ^ uVar9) - uVar9))) + && (sVar5 = this->seagullArray[seagullID].pathMajorLength, 0 < sVar5)) { + this->seagullArray[seagullID].pathStepDelay = this->seagullArray[seagullID].pathStepDelay + -1; + if (this->seagullArray[seagullID].pathStepDelay < 1) { + sVar2 = this->seagullArray[seagullID].pathAxisCase; + this->seagullArray[seagullID].pathStepDelay = 10; + this->seagullArray[seagullID].pathMajorLength = sVar5 + -1; + if (sVar2) { + if (sVar2 == 2) { + this->seagullArray[seagullID].x = this->seagullArray[seagullID].pathStepX + sVar4; + return; + } + if (sVar2 == 1) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + return; + } + if (sVar2 == 4) { + sVar5 = this->seagullArray[seagullID].pathError; + if (0 < sVar5) { + sVar2 = this->seagullArray[seagullID].pathStepX; + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + this->seagullArray[seagullID].x = sVar2 + sVar4; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + sVar5; + return; + } + sVar2 = this->seagullArray[seagullID].pathErrorStepStraight; + this->seagullArray[seagullID].x = this->entityArray[_entityID].someMicroX + sVar4; + this->seagullArray[seagullID].pathError = sVar2 + sVar5; + return; + } + if (sVar2 == 3) { + sVar5 = this->seagullArray[seagullID].pathError; + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + if (0 < sVar5) { + this->seagullArray[seagullID].x = this->seagullArray[seagullID].pathStepX + sVar4; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + sVar5; + return; + } + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepStraight + sVar5; + } + } + } + return; + } + sVar4 = this->seagullArray[seagullID].rngMax799_countdown; + if (0 < sVar4) { + this->seagullArray[seagullID].rngMax799_countdown = sVar4 + -1; + return; + } + _entityID = (int)this->seagullArray[seagullID].y; + this->seagullArray[seagullID].rngMax799_countdown = SEC_RNG::instance.currentNumber2 % 400 + 400; + MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::findFurthestSeaTile, DAT_PathFindingState::ptr)( + (int)((((ulonglong)((int)SEC_RNG::instance.currentNumber2 >> 0x1f) << 0x20) + | (uint)((uint)((int)((int)SEC_RNG::instance.currentNumber2 >> 4) % 200) + 400))), + (uint)((int)(iVar8 / 8)), _entityID / 8); + this->seagullArray[seagullID].x_3 = (short)DAT_PathFindingState::instance.ALG_ResultX * 8; + sVar4 = this->seagullArray[seagullID].x_3; + sVar2 = (short)DAT_PathFindingState::instance.ALG_ResultY * 8; + sVar5 = this->seagullArray[seagullID].x; + this->seagullArray[seagullID].y_3 = sVar2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)( + seagullID, (int)((int)(sVar5)), (int)((int)(this->seagullArray[seagullID].y)), (int)((int)(sVar4)), + (int)((int)(sVar2))); + this->seagullArray[seagullID].pathStepDelay = 10; + return; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp new file mode 100644 index 0000000000..aef49ccb50 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -0,0 +1,301 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00404AE0 + uint EntityState::spawnProjectileEntity(int unitID, undefined4 playerID1, uint ownerColorUnk, int microX, + int microY, int totalHeight, int targetX, int targetY, int targetZUnk, EntityType entityType, int param_11) + { + bool bVar1; + dword dVar2; + short* psVar3; + EntityTypeShort* pEVar4; + uint uVar5; + uint uVar6; + short sVar7; + uint entityID; + bVar1 = false; + if (((0x2b < (int)entityType) && ((int)entityType < 0x5b)) || (0x5e < (int)entityType)) { + return 0; + } + if (entityType == ~Map::Entities::ET_UNKNOWN) { + entityID = 0; + entityType = ((EntityType)8); + } else if (entityType - ((EntityType)0x28) < 8) { + entityID = 1; + psVar3 = &this->entityArray[1].logicalState; + do { + if (*psVar3 == 0) + break; + if (0x17 < (int)entityID) { + return 0; + } + entityID = entityID + 1; + psVar3 = psVar3 + 0x74; + } while ((int)entityID < 0x19); + } else { + entityID = this->every10Ticks; + if (this->every10Ticks < 3000) { + psVar3 = &this->entityArray[this->every10Ticks].logicalState; + do { + if (*psVar3 == 0) + break; + if (0xbb6 < (int)entityID) { + switch (entityType) { + case Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_CATAPULT: + case Map::Entities::ET_TREBUCHET: + case Map::Entities::ET_MANGONEL: + case Map::Entities::ET_CROSSBOWARROW: + case ((EntityType)8): + case Map::Entities::ET_COW_POISON_CLOUD: + case Map::Entities::ET_COW_FLYING: + case ((EntityType)0x18): + case ((EntityType)0x19): + case Map::Entities::EntityTypeInt__ET_EXPLOSION: + case Map::Entities::ET_SLINGER: + case Map::Entities::ET_FIRETHROWER: + case Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_FIRETHROWER_UNTARGETED: + case Map::Entities::ET_FIREBALLISTA: + case ((EntityType)0x5b): + case ((EntityType)0x5c): + case ((EntityType)0x5d): + case ((EntityType)0x5e): + this->maxEntityCount = 3000; + entityID = 0x19; + pEVar4 = &this->entityArray[0x19].entityType; + break; + default: + goto switchD_00404bac_caseD_5; + } + goto LAB_00404bc5; + } + entityID = entityID + 1; + psVar3 = psVar3 + 0x74; + } while ((int)entityID < 3000); + } + this->every10Ticks = entityID; + if (this->maxEntityCount <= (int)entityID) { + this->maxEntityCount = entityID + 1; + } + } + LAB_00404c16: + this->entityArray[entityID].rng_2 = 0; + if (entityType == ((EntityType)0x5b)) { + bVar1 = true; + this->entityArray[entityID].rng_2 = 1; + entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } else if (entityType == Map::Entities::ET_FIREBALLISTA) { + bVar1 = true; + this->entityArray[entityID].field90_0xd0 = 1; + entityType = Map::Entities::ET_BALLISTA; + } else { + if ((entityType == Map::Entities::ET_FIRETHROWER) + || (entityType == Map::Entities::ET_FIRETHROWER_UNTARGETED)) { + bVar1 = true; + } + if (entityType == ((EntityType)0x5c)) { + bVar1 = true; + this->entityArray[entityID].rng_2 = 1; + entityType = ((EntityType)0x18); + } else if (entityType == ((EntityType)0x5d)) { + bVar1 = true; + this->entityArray[entityID].rng_2 = 2; + entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } else if (entityType == ((EntityType)0x5e)) { + bVar1 = true; + this->entityArray[entityID].rng_2 = 2; + entityType = ((EntityType)0x18); + } else if (entityType == ((EntityType)0x1b)) { + targetX = targetX + -0xa0 + ((int)SEC_RNG::instance.currentNumber2 % 0x50) * 4; + targetY = targetY + -0xa0 + (((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50) * 4; + } else if (entityType == ((EntityType)0x20)) { + targetX = targetX + -0x18 + (int)SEC_RNG::instance.currentNumber2 % 0x30; + targetY = targetY + -0x18 + ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x30; + } + } + switch (entityType) { + case Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_CATAPULT: + case Map::Entities::ET_TREBUCHET: + case Map::Entities::ET_MANGONEL: + case Map::Entities::ET_CROSSBOWARROW: + case Map::Entities::ET_BALLISTA: + case Map::Entities::ET_COW_FLYING: + case ((EntityType)0x18): + case ((EntityType)0x19): + case ((EntityType)0x1b): + case ((EntityType)0x20): + case Map::Entities::ET_SLINGER: + case Map::Entities::ET_FIRETHROWER: + case Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_FIRETHROWER_UNTARGETED: + case Map::Entities::ET_FIREBALLISTA: + case ((EntityType)0x5b): + case ((EntityType)0x5c): + case ((EntityType)0x5d): + case ((EntityType)0x5e): + uVar5 = microX / 8; + uVar6 = microY / 8; + if (((399 < uVar5) || (399 < uVar6)) || (*(char*)(uVar6 * 400 + 0x21aec98 + uVar5) == '\0')) { + return 0; + } + uVar5 = targetX / 8; + uVar6 = targetY / 8; + if (399 < uVar5) { + return 0; + } + if (399 < uVar6) { + return 0; + } + if (*(char*)(uVar6 * 400 + 0x21aec98 + uVar5) == '\0') { + return 0; + } + } + if ((int)entityID < 0x19) { + this->entityArray[entityID].uid = 0; + } else { + this->entityArray[entityID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + } + dVar2 = DAT_GameCore::instance.mapTimeInTicks; + this->entityArray[entityID].unitID_OR_seaGullID = (short)unitID; + this->entityArray[entityID].targetX = (short)targetX; + this->entityArray[entityID].targetY = (short)targetY; + this->entityArray[entityID].targetZ = (short)targetZUnk; + this->entityArray[entityID].heightDifference = targetZUnk - totalHeight; + this->entityArray[entityID].field21_0x34 = dVar2; + this->entityArray[entityID].unitID = (short)param_11; + this->entityArray[entityID].owner = (short)playerID1; + this->entityArray[entityID].microX = (short)microX; + this->entityArray[entityID].x_2 = (short)microX; + this->entityArray[entityID].logicalState = 1; + this->entityArray[entityID].microY = (short)microY; + this->entityArray[entityID].y_2 = (short)microY; + sVar7 = (short)totalHeight; + this->entityArray[entityID].height = sVar7; + this->entityArray[entityID].startingHeight_2 = sVar7; + this->entityArray[entityID].height_2 = sVar7; + this->entityArray[entityID].startingHeight = sVar7; + this->entityArray[entityID].unkMinusOne = 0; + /* + sets DAT_TempBuildingOrientation + */ + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, + DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); + this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; + this->entityArray[entityID].colorUnk = 0; + if ((((entityType == Map::Entities::ET_FLAG_1) + || (entityType == Map::Entities::ET_FLAG_4)) + || (entityType == Map::Entities::ET_FLAG_2)) + || (entityType == Map::Entities::ET_FLAG_3)) { + this->entityArray[entityID].colorUnk = ownerColorUnk; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileEntityValues2, this)( + entityID, entityType); + if (this->entityArray[entityID].rng_2 != 0) { + this->entityArray[entityID].gmID = 0x91; + } + this->entityArray[entityID].field7_0x12 = 0; + this->entityArray[entityID].unknownAnimationFrameRelated = 0; + if (entityType == Map::Entities::ET_DUST_CLOUD) { + if (param_11 == 1) { + this->entityArray[entityID].unknownAnimationFrameRelated = 200; + } + LAB_00404efa: + this->entityArray[entityID].rng_1 = (int)SEC_RNG::instance.currentNumber2; + if (25 < (int)entityID) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + if (entityType == Map::Entities::ET_SEAGULLUnk) { + this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 100 + 120; + goto LAB_00404f8c; + } + if (entityType == ((EntityType)0x1f)) { + if (unitID) { + this->entityArray[entityID].unkOne_1 = 2; + } + goto LAB_00404f8c; + } + if (entityType != Map::Entities::ET_HEADS_ON_SPIKES) + goto LAB_00404f8c; + this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 500 + 300; + } else { + if (entityType != ((EntityType)8)) + goto LAB_00404efa; + ownerColorUnk = DAT_UnitsState::instance.units[unitID].fixedRng; + } + this->entityArray[entityID].rng_1 = ownerColorUnk; + LAB_00404f8c: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeProjectileVelocities, this)( + entityID, microX, microY, totalHeight, targetX, targetY, targetZUnk); + if (this->entityArray[entityID].entityType == ((EntityType)0x18)) { + this->entityArray[entityID].entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } + if (this->entityArray[entityID].entityType == ((EntityType)0x19)) { + this->entityArray[entityID].entityType = Map::Entities::ET_CROSSBOWARROW; + } + if (this->entityArray[entityID].entityType + == (Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT)) { + this->entityArray[entityID].entityType = Map::Entities::ET_SLINGER; + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_FIRETHROWER_UNTARGETED) { + this->entityArray[entityID].entityType = Map::Entities::ET_FIRETHROWER; + } + if (bVar1) { + this->entityArray[entityID].gmLookupValue = 1; + } + if (entityID) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); + uVar5 = DAT_CurrentEntityID::instance; + DAT_CurrentEntityID::instance = entityID; + ((void (*)())DAT_EntityDefinedData::instance + .EntityCallbacks[(short)this->entityArray[entityID].entityType])(); + DAT_CurrentEntityID::instance = uVar5; + } + return entityID; + LAB_00404bc5: + if (pEVar4[-1] == 0) + goto LAB_00404c16; + switch (*pEVar4) { + case Map::Entities::ET_FIRE: + case Map::Entities::ET_DUST_CLOUD: + case ((EntityType)0x1b): + case ((EntityType)0x1e): + case ((EntityType)0x1f): + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)(entityID); + goto LAB_00404c16; + default: + entityID = entityID + 1; + pEVar4 = pEVar4 + 0x74; + if (2999 < (int)entityID) { + switchD_00404bac_caseD_5: + this->every10Ticks = 2999; + return 0; + } + } + goto LAB_00404bc5; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp new file mode 100644 index 0000000000..8447560994 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -0,0 +1,341 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00405DA0 + void EntityState::spawnProjectileImpactDebris(int param_1) + { + byte bVar1; + uint microY; + uint microX; + uint uVar2; + int iVar3; + uint uVar4; + int iVar5; + int iVar6; + bool bVar7; + bool bVar8; + bool bVar9; + microY = (uint)this->entityArray[param_1].microY; + microX = (uint)this->entityArray[param_1].microX; + uVar2 = microX & 7; + iVar6 = 0; + iVar3 = 0; + uVar4 = microY & 7; + bVar1 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, DAT_TileMapState::ptr)( + (int)(microX + ((int)microX >> 0x1f & 7U)) >> 3, (int)((int)((microY + (microY >> 0x1f & 7U)) >> 3))); + switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + switchD_00405e0c_caseD_3c: + iVar3 = (int)this->entityArray[param_1].y_2; + break; + case 0x3d: + uVar4 = 7 - uVar4; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 10) { + case 0: + case 8: + switchD_00405e31_caseD_0: + uVar4 = 100; + break; + case 2: + switchD_00405e31_caseD_2: + uVar2 = 100; + break; + case 10: + goto switchD_00405e0c_caseD_3c; + } + switchD_00405e31_caseD_4: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = uVar2 == uVar4; + } + goto LAB_00405e3f; + case 0x3e: + uVar4 = 7 - uVar4; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 10) { + case 0: + case 8: + goto switchD_00405e31_caseD_0; + case 2: + goto switchD_00405e31_caseD_2; + default: + goto switchD_00405e31_caseD_4; + case 10: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x3f: + uVar4 = 7 - uVar4; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 10) { + case 0: + case 2: + goto switchD_00405e31_caseD_2; + default: + goto switchD_00405e31_caseD_4; + case 8: + goto switchD_00405e31_caseD_0; + case 10: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x41: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0x82) { + case 0: + case 2: + switchD_00405ebf_caseD_0: + uVar4 = 100; + default: + switchD_00405ebf_caseD_4: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = uVar2 == uVar4; + break; + case 0x80: + switchD_00405ebf_caseD_80: + bVar9 = (100 < uVar4); + bVar8 = (int)(100 - uVar4) < 0; + bVar7 = uVar4 == 100; + break; + case 0x82: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x42: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0x82) { + case 0: + case 2: + goto switchD_00405ebf_caseD_0; + default: + goto switchD_00405ebf_caseD_4; + case 0x80: + goto switchD_00405ebf_caseD_80; + case 0x82: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x43: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0x82) { + case 0: + case 0x80: + switchD_00405f23_caseD_0: + uVar2 = 100; + default: + switchD_00405f23_caseD_4: + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = uVar2 == uVar4; + break; + case 2: + switchD_00405f23_caseD_2: + bVar9 = (uVar2 < 100); + bVar8 = (int)(uVar2 - 100) < 0; + bVar7 = uVar2 == 100; + break; + case 0x82: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x45: + uVar2 = 7 - uVar2; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0xa0) { + case 0: + case 0x80: + goto switchD_00405ebf_caseD_0; + case 0x20: + goto switchD_00405ebf_caseD_80; + default: + goto switchD_00405ebf_caseD_4; + case 0xa0: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x46: + uVar2 = 7 - uVar2; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0xa0) { + case 0: + case 0x80: + goto switchD_00405ebf_caseD_0; + case 0x20: + goto switchD_00405ebf_caseD_80; + default: + goto switchD_00405ebf_caseD_4; + case 0xa0: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x47: + uVar2 = 7 - uVar2; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0xa0) { + case 0: + case 0x20: + goto switchD_00405f23_caseD_0; + default: + goto switchD_00405f23_caseD_4; + case 0x80: + goto switchD_00405f23_caseD_2; + case 0xa0: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x49: + iVar3 = -uVar2 + 7; + iVar6 = 7 - uVar4; + bVar9 = (iVar3 < iVar6); + bVar8 = iVar3 - iVar6 < 0; + bVar7 = false; + if (iVar3 == iVar6) { + switch (bVar1 & 0x28) { + case 0: + case 0x20: + iVar3 = 100; + default: + bVar9 = (iVar3 < iVar6); + bVar8 = iVar3 - iVar6 < 0; + bVar7 = iVar3 == iVar6; + break; + case 8: + bVar9 = (iVar3 < 100); + bVar8 = (int)(-uVar2 + -0x5d) < 0; + bVar7 = iVar3 == 100; + break; + case 0x28: + goto switchD_00405e0c_caseD_3c; + } + } + LAB_00405e3f: + if (!bVar7 && bVar9 == bVar8) { + iVar3 = (int)this->entityArray[param_1].y_2; + iVar6 = this->entityArray[param_1].microX * 2 - (int)this->entityArray[param_1].x_2; + goto switchD_00405e0c_caseD_10; + } + iVar3 = this->entityArray[param_1].microY * 2 - (int)this->entityArray[param_1].y_2; + break; + case 0x4a: + uVar2 = 7 - uVar2; + uVar4 = 7 - uVar4; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0x28) { + case 0: + case 8: + goto switchD_00405e31_caseD_0; + default: + goto switchD_00405e31_caseD_4; + case 0x20: + goto switchD_00405e31_caseD_2; + case 0x28: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + case 0x4b: + uVar2 = 7 - uVar2; + uVar4 = 7 - uVar4; + bVar9 = (uVar2 < uVar4); + bVar8 = (int)(uVar2 - uVar4) < 0; + bVar7 = false; + if (uVar2 == uVar4) { + switch (bVar1 & 0x28) { + case 0: + case 8: + goto switchD_00405e31_caseD_0; + default: + goto switchD_00405e31_caseD_4; + case 0x20: + goto switchD_00405e31_caseD_2; + case 0x28: + goto switchD_00405e0c_caseD_3c; + } + } + goto LAB_00405e3f; + default: + goto switchD_00405e0c_caseD_10; + } + iVar6 = (int)this->entityArray[param_1].x_2; + switchD_00405e0c_caseD_10: + iVar5 = 0; + uVar4 = this->entityArray[param_1].rng_1 & 0x80000007; + if ((int)uVar4 < 0) { + uVar4 = (uVar4 - 1 | 0xfffffff8) + 1; + } + if (uVar4 != 0xfffffffb && -1 < (int)(uVar4 + 5)) { + do { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, + (int)((int)(microX)), (int)((int)(microY)), (int)((int)(this->entityArray[param_1].height)), + iVar6, iVar3, 8, ((EntityType)0x1b), 0); + iVar5 = iVar5 + 1; + uVar4 = this->entityArray[param_1].rng_1 & 0x80000007; + if ((int)uVar4 < 0) { + uVar4 = (uVar4 - 1 | 0xfffffff8) + 1; + } + } while (iVar5 < (int)(uVar4 + 5)); + } + iVar3 = (int)this->entityArray[param_1].height; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, + (int)((int)(microX)), (int)((int)(microY)), iVar3, (int)((int)(microX + 1)), (int)((int)(microY + 1)), + iVar3, ((EntityType)0x1e), 0); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp new file mode 100644 index 0000000000..ffc9d54216 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -0,0 +1,302 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004087C0 + void EntityState::updateEntities() + { + word* pwVar1; + short sVar2; + int iVar3; + short* psVar4; + int local_4; + short _gmLookupValue; + if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 0) { + this->every10Ticks = 25; + } + this->totalEntityCount = 0; + DAT_CurrentEntityID::instance = 1; + local_4 = 0; + iVar3 = 0; + if (1 < this->maxEntityCount) { + do { + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 0) + goto LAB_00408d6d; + this->totalEntityCount = this->totalEntityCount + 1; + local_4 = DAT_CurrentEntityID::instance + 1; + psVar4 = &this->entityArray[DAT_CurrentEntityID::instance].logicalState; + /* + Switch entity state + */ + switch (*psVar4) { + case 1: + *psVar4 = 2; + break; + case 3: + goto switchD_0040884c_caseD_3; + case 4: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::activateProjectileEntity, this)( + DAT_CurrentEntityID::instance); + break; + case 5: + *psVar4 = 6; + break; + case 7: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + goto LAB_00408d6d; + case 8: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + } + if (DAT_CurrentEntityID::instance + == (int)this->entityArray[DAT_CurrentEntityID::instance].nextEntityOnThisTileByID) { + switchD_0040884c_caseD_3: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + DAT_CurrentEntityID::instance); + goto LAB_00408d6d; + } + if (this->entityArray[DAT_CurrentEntityID::instance].unkOne_1 + <= this->entityArray[DAT_CurrentEntityID::instance].field7_0x12) { + this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + 1; + this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 = 0; + } + this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 + = this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 6) + goto switchD_0040890b_caseD_9; + /* + Switch entity type + */ + switch (this->entityArray[DAT_CurrentEntityID::instance].entityType) { + case Map::Entities::ET_FIRE: + break; + case Map::Entities::ET_FLAG_1: + case Map::Entities::ET_FLAG_4: + case Map::Entities::ET_FLAG_2: + case Map::Entities::ET_FLAG_3: + case Map::Entities::ET_BRAZIER: + case Map::Entities::ET_HEADS_ON_SPIKES: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + break; + default: + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = (short)this->entityArray[DAT_CurrentEntityID::instance].orientation + -0x3c; + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = this->entityArray[DAT_CurrentEntityID::instance].screenDirection + + (short)DAT_TileMapState::instance.mapOrientation * -2; + psVar4 = &this->entityArray[DAT_CurrentEntityID::instance].screenDirection; + if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { + *psVar4 = *psVar4 + 0x10; + } + if ((((float)this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0) + && (_gmLookupValue = this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue, + _gmLookupValue != 0)) + && (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0)) { + if (_gmLookupValue == 3) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect1, this)( + this->entityArray[DAT_CurrentEntityID::instance].microX, + this->entityArray[DAT_CurrentEntityID::instance].microY, + (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].height)), + 6, (int)((int)(this->entityArray[DAT_CurrentEntityID::instance].gmID)), + this->entityArray[DAT_CurrentEntityID::instance].graphicType2); + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( + (int)this->entityArray[DAT_CurrentEntityID::instance].microX, + (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].microY)), + (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].height)), + 5, (int)((int)(_gmLookupValue))); + } + } + if (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::moveProjectileEntity, this)( + DAT_CurrentEntityID::instance); + } + break; + case Map::Entities::ET_DUST_CLOUD: + if (this->entityArray[DAT_CurrentEntityID::instance].unitID == 2) { + if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1)) { + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + DAT_CurrentEntityID::instance); + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated; + sVar2 = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + if (sVar2 < 0) { + if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + } + } else if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + } + sVar2 = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated; + if (sVar2 < 0) { + if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + } + } else if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + } + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, + this)(DAT_CurrentEntityID::instance); + } + } else if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + & 1)) { + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + DAT_CurrentEntityID::instance); + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + sVar2 = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (sVar2 < 0) { + if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + } + } else if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + } + sVar2 = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (sVar2 < 0) { + if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + } + } else if (iVar3 % (int)sVar2 == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, + this)(DAT_CurrentEntityID::instance); + } + break; + case Map::Entities::ET_COW_POISON_CLOUD: + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk < 0x1f) + goto LAB_00408c15; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - 1; + if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk < 1) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); + this->entityArray[DAT_CurrentEntityID::instance].startingAngle + = (byte)((char)SEC_RNG::instance.currentNumber2 >> 4) & 7; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + } + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk = 0; + switch (this->entityArray[DAT_CurrentEntityID::instance].startingAngle) { + case 0: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + break; + case 1: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + break; + case 2: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + break; + case 3: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + goto LAB_00408bf2; + case 4: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 5: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + LAB_00408bf2: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 6: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + break; + case 7: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); + LAB_00408c15: + this->entityArray[DAT_CurrentEntityID::instance].height + = DAT_TileMapState::instance + .HeightLayer[this->entityArray[DAT_CurrentEntityID::instance].tile] + + 0x14; + break; + case Map::Entities::EntityTypeInt__ET_EXPLOSION: + case ((EntityType)0x28): + case ((EntityType)0x29): + case ((EntityType)0x2a): + case ((EntityType)0x2b): + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + } + switchD_0040890b_caseD_9: + ((void (*)())DAT_EntityDefinedData::instance + .EntityCallbacks[(short)this->entityArray[DAT_CurrentEntityID::instance].entityType])(); + if (this->entityArray[DAT_CurrentEntityID::instance].entityType + == Map::Entities::ET_SEAGULLUnk) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processSeaGulls, this)( + (int)this->entityArray[DAT_CurrentEntityID::instance].unitID_OR_seaGullID); + } + LAB_00408d6d: + DAT_CurrentEntityID::instance = DAT_CurrentEntityID::instance + 1; + iVar3 = local_4; + } while ((int)DAT_CurrentEntityID::instance < this->maxEntityCount); + } + this->maxEntityCount = iVar3; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp new file mode 100644 index 0000000000..ad68513886 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -0,0 +1,35 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004081E0 + void EntityState::updateProjectileHeightAndCollision( + uint entityID, undefined4 param_2, int param_3, int param_4) + { + short sVar1; + undefined4 uVar2; + sVar1 = this->entityArray[entityID].startingHeight + (short)param_2; + this->entityArray[entityID].height = sVar1; + if ((sVar1 < 3) && (!param_4)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + entityID); + } + sVar1 = this->entityArray[entityID].height; + if (10000 < sVar1) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + } + uVar2 + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); + this->entityArray[entityID].rotationFrameIndex = (short)uVar2; + this->entityArray[entityID].height_2 = sVar1; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp new file mode 100644 index 0000000000..e62ba1cf8a --- /dev/null +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -0,0 +1,98 @@ +#include "../../Map.func.hpp" +#include "../Entities.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004052E0 + uint Entities::IgniteFireAtMiniTile( + int playerID, int miniTileX, int miniTileY, int tileHeightMin8, int two, int fireIntensity) + { + uint _y; + int _entityID; + uint _entityID_2; + uint _x; + int _tile; + int microY; + uint _randomJitter; + int microX; + short _buildingID; + _randomJitter = (uint)SEC_RNG::instance.currentNumber2; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + microX = miniTileX + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[_randomJitter & 0x3f][0]; + microY = miniTileY + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[_randomJitter & 0x3f][1]; + _x = microX / 8; + _y = microY / 8; + if (((399 < _x) || (399 < _y)) || (*(char*)(_y * 400 + 0x21aec98 + _x) == '\0')) { + return 0; + } + _tile = DAT_ViewportRenderState::instance.translationMatrix[_y].addXgetTile + _x; + if (!(DAT_TileMapState::instance.LogicLayer[_tile] & 0x10300131U)) { + _buildingID = DAT_TileMapState::instance.BuildingLayer[_tile]; + if (_buildingID) { + switch (DAT_BuildingsState::instance.buildings[_buildingID].buildingType) { + case Map::Buildings::BT_GATEHOUSELARGE: + case Map::Buildings::BT_GATEHOUSESMALL: + case Map::Buildings::BT_TOWER1: + case Map::Buildings::BT_TOWER2: + case Map::Buildings::BT_TOWER3: + case Map::Buildings::BT_TOWER4: + case Map::Buildings::BT_TOWER5: + goto switchD_0040539c_caseD_2d; + } + } + _entityID = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(_tile); + if (!_entityID) { + if (_buildingID) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( + (int)DAT_TileMapState::instance.BuildingLayer[_tile], playerID, fireIntensity); + } + if ((DAT_TileMapState::instance.LogicLayer[_tile] & 0x1000U)) { + MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)( + _tile, playerID); + } + _entityID_2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, 0, + Map::Entities::ET_FIRE, 0); + if ((2 < two) && (!(DAT_TileMapState::instance.RandomLayer[_tile] & 3))) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, + 0, (EntityType)((int)(26)), 0); + } + if (_entityID_2) { + DAT_EntityState::instance.entityArray[_entityID_2].fireParameter_0xb6 = (short)two; + DAT_EntityState::instance.entityArray[_entityID_2].fireIntensity = (short)fireIntensity; + } + return _entityID_2; + } + _buildingID = DAT_EntityState::instance.entityArray[_entityID].fireParameter_0xb6; + DAT_EntityState::instance.entityArray[_entityID].someTracker = 0; + if (_buildingID < two) { + DAT_EntityState::instance.entityArray[_entityID].fireParameter_0xb6 = (short)two; + } + DAT_EntityState::instance.entityArray[_entityID].unknownAnimationFrameRelated = 0; + } + switchD_0040539c_caseD_2d: + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp new file mode 100644 index 0000000000..38379f043d --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -0,0 +1,51 @@ +#include "../../Map.func.hpp" +#include "../Entities.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402180 + void Entities::UpdateEntity_CowFlying() + { + short* psVar1; + uint uVar2; + int iVar3; + uVar2 = DAT_CurrentEntityID::instance; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + if (0xb + < DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + } + iVar3 = (int)DAT_EntityState::instance.entityArray[uVar2].graphicType2RelatedOffset + + (int)DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated; + DAT_EntityState::instance.entityArray[uVar2].graphicType2 = iVar3; + DAT_EntityState::instance.entityArray[uVar2].imageID = (short)iVar3 + 0x11; + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + < 100) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 100; + } + if (120 < DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated) { + DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0x77; + } + psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; + *psVar1 = *psVar1 + -1; + if (DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround < 1) { + DAT_EntityState::instance.entityArray[uVar2].logicalState = 7; + } + iVar3 = DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated + -100; + DAT_EntityState::instance.entityArray[uVar2].graphicType2 = ((int)(iVar3 + (iVar3 >> 0x1f & 3U)) >> 2) + 0xc + + (int)DAT_EntityState::instance.entityArray[uVar2].graphicType2RelatedOffset; + DAT_EntityState::instance.entityArray[uVar2].imageID = 0; + } + if (DAT_EntityState::instance.entityArray[uVar2].orientation == 0x4c) { + DAT_EntityState::instance.entityArray[uVar2].orientation = 0x3c; + DAT_EntityState::instance.entityArray[uVar2].logicalState = 7; + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp new file mode 100644 index 0000000000..be838c73a0 --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp @@ -0,0 +1,243 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00405680 + void Entities::UpdateFireEntity() + { + short* psVar1; + uint _totalHeightAtTile; + uint uVar2; + int _entityOffset; + int iVar3; + int _y; + uint _heightDerivative; + int _x; + uint uVar4; + uint _height; + int _tile; + short _fireIntensity0; + short _0xb6; + int _entityTile; + short _height0; + short _playerID; + uVar2 = DAT_CurrentEntityID::instance; + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + if (_height0 == 5) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 8; + } else if (_height0 == 4) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 9; + } else if (_height0 == 3) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0xc; + } else if (_height0 == 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0xe; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0x10; + } + DAT_EntityState::instance.entityArray[uVar2].gmID = 0x76; + _height0 = DAT_EntityState::instance.entityArray[uVar2].someTracker; + if (_height0 < 0) { + DAT_EntityState::instance.entityArray[uVar2].unkMinusOne = 0x20; + psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someTracker; + *psVar1 = *psVar1 + 1; + iVar3 = 1; + LAB_00405715: + DAT_EntityState::instance.entityArray[uVar2].graphicType2 = iVar3; + } else { + if (!_height0) { + _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; + if (_height0 < 3) { + LAB_004058a7: + if (_height0 == 2) { + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames1 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } else { + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames2 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } + } else if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { + DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; + iVar3 + = (int)(char)DAT_EntityDefinedData::instance + .FireAnimationFrames5[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } else { + iVar3 + = (int)(char)DAT_EntityDefinedData::instance + .FireAnimationFrames3[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } + LAB_004058ca: + if (0 < iVar3) + goto LAB_00405715; + } else { + if (_height0 == 1) { + _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; + if (_height0 < 3) + goto LAB_004058a7; + if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { + DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames8 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } else { + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames7 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } + goto LAB_004058ca; + } + if (_height0 == 2) { + _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; + if (_height0 < 3) + goto LAB_004058a7; + if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { + DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames6 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } else { + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames4 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + } + goto LAB_004058ca; + } + } + DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0; + _height0 = DAT_EntityState::instance.entityArray[uVar2].someTracker; + if (!_height0) { + DAT_EntityState::instance.entityArray[uVar2].someTracker = 1; + } else if (_height0 == 1) { + psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; + *psVar1 = *psVar1 + 1; + if ((DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround == 6) + && (2 < DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6)) { + DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6 = 2; + } + psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; + *psVar1 = *psVar1 + 1; + if (8 < DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround) { + DAT_EntityState::instance.entityArray[uVar2].someTracker = 2; + } + if ((DAT_TileMapState::instance.BuildingLayer[DAT_EntityState::instance.entityArray[uVar2].tile] != 0) + && (iVar3 = MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingFlammabilityFactor, + DAT_BuildingsState::ptr)((int)DAT_TileMapState::instance + .BuildingLayer[DAT_EntityState::instance.entityArray[uVar2].tile]), + uVar2 = DAT_CurrentEntityID::instance, iVar3)) { + if (DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile]] + .fireDuration + == 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 + < 3) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 = 3; + } + DAT_EntityState::instance.entityArray[uVar2].someTracker = 1; + DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround = 0; + } + } + } else if (_height0 == 2) { + DAT_EntityState::instance.entityArray[uVar2].logicalState = 3; + } + } + _entityOffset = DAT_CurrentEntityID::instance * 0xe8; + if ((DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker != 0) + || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated != 1)) + goto LAB_00405b3d; + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field79_0xb8; + _tile = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile; + _height = (uint)DAT_TileMapState::instance.HeightLayer[_tile]; + if ((3 < _height0) + || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 < 2)) + goto LAB_00405b3d; + if (!_height0) { + _totalHeightAtTile = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + -1); + _heightDerivative = (int)(_height - _totalHeightAtTile) >> 0x1f; + if (0x18 < (int)((_height - _totalHeightAtTile ^ _heightDerivative) - _heightDerivative)) + goto LAB_00405b2a; + _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; + _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; + _y = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY; + _x = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + -8; + LAB_00405b18: + _playerID = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; + LAB_00405b22: + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)((int)_playerID, _x, _y, + (int)((int)(_height0)), (int)((int)(_0xb6 + -1)), (int)((int)(_fireIntensity0))); + } else { + if (_height0 == 1) { + uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + _tile + 1); + uVar4 = (int)(_height - uVar2) >> 0x1f; + if (0x18 < (int)((_height - uVar2 ^ uVar4) - uVar4)) + goto LAB_00405b2a; + _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; + _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; + _y = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY; + _playerID = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; + _x = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + 8; + goto LAB_00405b22; + } + if (_height0 == 2) { + uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + 1] + .addXgetTile); + uVar4 = (int)(_height - uVar2) >> 0x1f; + if ((int)((_height - uVar2 ^ uVar4) - uVar4) < 0x19) { + _fireIntensity0 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; + _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + _y = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + 8; + LAB_00405b09: + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; + _x = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX; + goto LAB_00405b18; + } + } else if ((_height0 == 3) + && (uVar2 + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + -1] + .addXgetTile), + uVar4 = (int)(_height - uVar2) >> 0x1f, (int)((_height - uVar2 ^ uVar4) - uVar4) < 0x19)) { + _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; + _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + _y = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + -8; + goto LAB_00405b09; + } + } + LAB_00405b2a: + _entityOffset = DAT_CurrentEntityID::instance * 0xe8; + psVar1 = &DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field79_0xb8; + *psVar1 = *psVar1 + 1; + LAB_00405b3d: + iVar3 = *(int*)(DAT_EntityState::instance.entityArray[0].unused_0x48 + _entityOffset + 4); + if (!(DAT_TileMapState::instance.LogicLayer[iVar3] & 0xba7001b1U)) { + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::processFireDamageToUnitsAtTile, DAT_EntityState::ptr)(iVar3, + (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0x2e + _entityOffset + -2), + (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0xe0 + _entityOffset + -8)); + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp new file mode 100644 index 0000000000..84ac0397b9 --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -0,0 +1,88 @@ +#include "../../Map.func.hpp" +#include "../Entities.func.hpp" + +#include "OpenSHC/AI/AIRecruitUnitChoice.hpp" +#include "OpenSHC/AI/AIRecruitUnitChoiceInt.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" + +namespace OpenSHC { +namespace Map { + + using AI::AIRecruitUnitChoice; + using AI::AIRecruitUnitChoiceInt; + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x00402900 + void Entities::UpdateFlag_1_2_4_Entity() + { + AIRecruitUnitChoiceInt AVar1; + uint uVar2; + int iVar3; + short sVar4; + short _owner; + uVar2 = DAT_CurrentEntityID::instance; + sVar4 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + _owner = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset; + if (DAT_LandscapeState::instance.wind.countdown + <= (int)((byte)DAT_EntityState::instance.entityArray[uVar2].yPosition & 0x1f)) { + sVar4 = (short)DAT_LandscapeState::instance.wind.value; + } + if (((DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) + && (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[_owner] == -1)) + && (DAT_GameSynchronyState::instance.currentAIArray[_owner] != 0)) { + if (DAT_GameState::instance.playerDataArray[_owner].aiBuildingDestroyChoiceTracker == 0) { + if (DAT_GameState::instance.playerDataArray[_owner].aiNervousActionsTracker == 0) { + AVar1 = DAT_GameState::instance.playerDataArray[_owner].aiRecruitUnitChoiceState; + sVar4 = 0; + if (AVar1 != AI::AIRUC_DEFENSIVE) { + sVar4 = (AVar1 != AI::AIRUC_RAIDING) + 1; + } + } else { + sVar4 = 3; + } + } else { + sVar4 = 3; + } + } + DAT_EntityState::instance.entityArray[uVar2].unkOne_1 = 3; + switch (DAT_EntityState::instance.entityArray[uVar2].someTracker) { + case 0: + iVar3 + = DAT_EntityDefinedData::instance + .FlagAnimationFrames1[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + break; + case 1: + iVar3 + = DAT_EntityDefinedData::instance + .FlagAnimationFrames2[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + break; + case 3: + DAT_EntityState::instance.entityArray[uVar2].unkOne_1 = 1; + /* falls through into case 2 */ + case 2: + iVar3 + = DAT_EntityDefinedData::instance + .FlagAnimationFrames3[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + break; + default: + return; + } + if (iVar3 < 1) { + DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0; + DAT_EntityState::instance.entityArray[uVar2].someTracker = sVar4; + } + DAT_EntityState::instance.entityArray[uVar2].graphicType2 + = DAT_EntityState::instance.entityArray[uVar2].graphicType2 + iVar3 + -1; + } + +} +} From 42b7a636f9e63e8154e2d8374425686d446de438 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:00 +0100 Subject: [PATCH 02/51] Fix compile errors against main's headers Renamed fields, globals and resolvers by address, enum-typed arguments, array fields indexed directly, clang-format. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Globals/DOUBLE_00b941c0.hpp | 19 +++ .../EntityState/calculateEntityDrawOffset.cpp | 6 +- .../computeLineOfSightDistance.cpp | 16 +-- .../initializeProjectileVelocities.cpp | 22 ++-- .../EntityState/moveProjectileEntity.cpp | 15 ++- .../processEntityHitBuildingOrUnit.cpp | 115 ++++++++---------- .../Entities/EntityState/processSeaGulls.cpp | 34 +++--- .../EntityState/spawnProjectileEntity.cpp | 25 ++-- .../Entities/EntityState/updateEntities.cpp | 54 ++++---- .../updateProjectileHeightAndCollision.cpp | 9 +- .../Map/Entities/IgniteFireAtMiniTile.cpp | 16 ++- src/OpenSHC/Map/Entities/UpdateFireEntity.cpp | 34 +++--- 12 files changed, 175 insertions(+), 190 deletions(-) create mode 100644 src/OpenSHC/Globals/DOUBLE_00b941c0.hpp diff --git a/src/OpenSHC/Globals/DOUBLE_00b941c0.hpp b/src/OpenSHC/Globals/DOUBLE_00b941c0.hpp new file mode 100644 index 0000000000..c80710d538 --- /dev/null +++ b/src/OpenSHC/Globals/DOUBLE_00b941c0.hpp @@ -0,0 +1,19 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Globals/DOUBLE_00b941c0.hpp' +*/ + +#pragma once + +// GLOBAL: STRONGHOLDCRUSADER 0x00B941C0 +// StructResolver::Instance::instance + +namespace OpenSHC { + +MACRO_STRUCT_RESOLVER(double, false, Address::SHC_3BB0A8C1_0x00B941C0) DOUBLE_00b941c0; +} // namespace OpenSHC + +MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B941C0); diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index 074b5592e1..7d23e642f1 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -40,8 +40,10 @@ namespace Map { _xOffset = _microXPart * 2; _yOffset = _microYPart << 4; LAB_0040372e: - this->entityArray[entityID].x1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset].x; - this->entityArray[entityID].y1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset + 1].x; + this->entityArray[entityID].x1 + = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset].x; + this->entityArray[entityID].y1 + = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset + 1].x; } } diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index ef24a1489c..76b6fcc378 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -107,8 +107,8 @@ namespace Map { && ((!bVar4 || (!(DAT_TileMapState::instance.LogicLayer[iVar6] & 0x400200U))))))) { bVar5 = true; - uVar8 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)(iVar6, 1); + uVar8 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar6, 1); uVar12 = local_38 - y >> 0x1f; iVar9 = ((local_38 - y ^ uVar12) - uVar12) * (targetHeight - height); LAB_004033cf: @@ -167,8 +167,8 @@ namespace Map { || (!(DAT_TileMapState::instance.LogicLayer[iVar9] & 0x400200U))))))) { bVar5 = true; - local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)(iVar9, 1); + local_30 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar9, 1); uVar12 = local_3c - x >> 0x1f; local_1c = iVar9; if ((int)(((local_3c - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 @@ -260,8 +260,8 @@ namespace Map { && ((!bVar4 || (!(DAT_TileMapState::instance.LogicLayer[iVar13] & 0x400200U))))))) { bVar5 = true; - local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)(iVar13, 1); + local_30 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar13, 1); uVar12 = iVar10 - x >> 0x1f; iVar9 = local_38; if ((int)(((iVar10 - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 @@ -349,8 +349,8 @@ namespace Map { && ((!bVar4 || (!(DAT_TileMapState::instance.LogicLayer[iVar14] & 0x400200U))))))) { bVar5 = true; - local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)(iVar14, 1); + local_30 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar14, 1); uVar12 = iVar6 - y >> 0x1f; x = local_3c; if ((int)(((iVar6 - y ^ uVar12) - uVar12) * (targetHeight - height)) / iVar7 diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index 176309d051..5c873ab29d 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -93,17 +93,17 @@ namespace Map { uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( x, y, height, targetX, targetY, targetZ, 1); sVar5 = (short)uVar6; - this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].field_0x94 = sVar5; this->entityArray[entityID].totalFlightDistance = sVar5; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; sVar10 = this->entityArray[entityID].velocityUnk; } else { if (iVar7 == 1) { - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, - this)(x, y, height, targetX, targetY, targetZ, 1); + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( + x, y, height, targetX, targetY, targetZ, 1); iVar7 = this->entityArray[entityID].heightDifference; sVar5 = (short)uVar6; - this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].field_0x94 = sVar5; this->entityArray[entityID].totalFlightDistance = sVar5; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( @@ -113,12 +113,12 @@ namespace Map { goto LAB_00403f37; } if (iVar7 == 2) { - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, - this)(x, y, height, targetX, targetY, targetZ, 1); + uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( + x, y, height, targetX, targetY, targetZ, 1); sVar5 = this->entityArray[entityID].height; sVar10 = this->entityArray[entityID].targetZ; sVar9 = (short)uVar6; - this->entityArray[entityID].field62_0x94 = sVar9; + this->entityArray[entityID].field_0x94 = sVar9; this->entityArray[entityID].totalFlightDistance = sVar9; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; if (sVar10 < sVar5) { @@ -209,7 +209,7 @@ namespace Map { uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( x, y, height, targetX, targetY, targetZ, 1); sVar5 = (short)uVar6; - this->entityArray[entityID].field62_0x94 = sVar5; + this->entityArray[entityID].field_0x94 = sVar5; this->entityArray[entityID].totalFlightDistance = sVar5; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; if (0x96 < sVar5) { @@ -223,8 +223,7 @@ namespace Map { this->entityArray[entityID].startingAngle = (short)iVar7; LAB_00403f37: EVar4 = this->entityArray[entityID].entityType; - if ((((EVar4 == Map::Entities::ET_ARROW_AND_DEFAULT) - || (EVar4 == Map::Entities::ET_CROSSBOWARROW)) + if ((((EVar4 == Map::Entities::ET_ARROW_AND_DEFAULT) || (EVar4 == Map::Entities::ET_CROSSBOWARROW)) && (height + 0x36 < targetZ)) && (this->entityArray[entityID].rng_1 % 10 == 5)) { this->entityArray[entityID].hasDoneEffectUnk = 1; @@ -238,8 +237,7 @@ namespace Map { this->entityArray[entityID].vCos = (float)(fVar13 * (double)iVar7); fVar12 = sin((double)fVar12); this->entityArray[entityID].vSin = (float)(fVar12 * (double)iVar7); - uVar8 - = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar11); + uVar8 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar11); this->entityArray[entityID].rotationFrameIndex = (short)uVar8; return; } diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp index 8c92e63349..f26aea54e4 100644 --- a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -97,8 +97,8 @@ namespace Map { psVar1 = &this->entityArray[entityID].clearanceStepsRemaining; *psVar1 = *psVar1 + -1; if (entityID) { - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + entityID); } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateEntityMicroMovement, this)(entityID); if ((DAT_EntityDefinedData::instance @@ -110,14 +110,13 @@ namespace Map { _height = _height + local_10; iVar9 = 1; iVar6 = (long)((double)fVar7); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, - this)(entityID, (undefined4)((int)(_height)), iVar6, iVar9); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + entityID, (undefined4)((int)(_height)), iVar6, iVar9); } - iVar6 = MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); + iVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + entityID); if (!iVar6) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); return TRUE; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index 32f6df2ea6..76df1a3046 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -110,8 +110,7 @@ namespace Map { DAT_TileMapState::instance.MiscDisplayLayer[_someTile] = DAT_TileMapState::instance.MiscDisplayLayer[_someTile] | 0x1000; EVar3 = this->entityArray[entityID].entityType; - if ((EVar3 == Map::Entities::ET_BRAZIER) - || (EVar3 == Map::Entities::ET_HEADS_ON_SPIKES)) { + if ((EVar3 == Map::Entities::ET_BRAZIER) || (EVar3 == Map::Entities::ET_HEADS_ON_SPIKES)) { _buildingID = this->entityArray[entityID].tile; if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { if ((DAT_TileMapState::instance.LogicLayer[_buildingID] & 0x100U)) { @@ -139,16 +138,15 @@ namespace Map { case Map::Buildings::BT_TOWER3: case Map::Buildings::BT_TOWER4: case Map::Buildings::BT_TOWER5: - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, - DAT_TileMapState::ptr)(_buildingID); + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + _buildingID); this->entityArray[entityID].height = (short)_y; goto LAB_00408150; } } if (DAT_GameCore::instance.gameMode_2 == Game::GM_SIEGE_THAT) { - MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::getBuildingCost, DAT_BuildingsState::ptr)( - Commands::M_MAPPER_BRAZIER, (int*)&local_10, (int*)&local_4); + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingCost, + DAT_BuildingsState::ptr)(Commands::M_MAPPER_BRAZIER, (int*)&local_10, (int*)&local_4); piVar1 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .startResources @@ -161,8 +159,7 @@ namespace Map { _y = DAT_TileMapState::instance.LogicLayer[_buildingID]; if (!_y) { if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); } } else if (DAT_TileMapState::instance.DamageLayer[_buildingID] != 0) { if (!(_y & 0x400000)) { @@ -191,12 +188,11 @@ namespace Map { DAT_UnitsState::ptr)(_buildingID, entityID, 0), BVar8)) { if (this->entityArray[entityID].entityType != Map::Entities::ET_COW_FLYING) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); return (undefined4)(0); } - _y = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(_someTile, 0); + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( + _someTile, 0); this->entityArray[entityID].height = (short)_y; goto LAB_004079b4; } @@ -205,8 +201,7 @@ namespace Map { } EVar3 = this->entityArray[entityID].entityType; if (((EVar3 == Map::Entities::ET_TREBUCHET) || (EVar3 == Map::Entities::ET_CATAPULT)) - || ((EVar3 == Map::Entities::ET_MANGONEL - || (0x50 < this->entityArray[entityID].velocityUnk)))) { + || ((EVar3 == Map::Entities::ET_MANGONEL || (0x50 < this->entityArray[entityID].velocityUnk)))) { _buildingID = 1; do { uVar4 = DAT_TileMapState::instance @@ -214,13 +209,13 @@ namespace Map { [this->entityArray[entityID].yPosition][_buildingID] + _someTile]; while (iVar11 = (int)(short)uVar4, iVar11) { - if (((DAT_UnitsState::instance.units[iVar11].field64_0x90 != 0) + if (((DAT_UnitsState::instance.units[iVar11].field_0x90 != 0) && (this->entityArray[entityID].logicalState == 2)) && (BVar8 = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, DAT_UnitsState::ptr)(iVar11, entityID, 1), BVar8)) { - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::markEntityDestroyed, local_10)(entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, local_10)( + entityID); return (undefined4)(0); } uVar4 = DAT_UnitsState::instance.units[iVar11].nextUnitOnTheSameTile; @@ -230,8 +225,8 @@ namespace Map { } } if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD) { - local_4 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_someTile); + local_4 + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_someTile); _buildingID = 0; do { iVar11 = DAT_TileMapState::instance @@ -239,8 +234,8 @@ namespace Map { + _someTile; uVar4 = (short)DAT_TileMapState::instance.UnitLayer[iVar11]; while (iVar9 = (int)(short)uVar4, iVar9) { - _y = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(iVar11); + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + iVar11); _x = (int)(local_4 - _y) >> 0x1f; if (((int)((local_4 - _y ^ _x) - _x) < 0x78) && (this->entityArray[entityID].logicalState == 2)) { @@ -257,8 +252,8 @@ namespace Map { DAT_TileMapState::ptr)(_someTile, pPVar10->xOffset, (uint)((int)(pPVar10->yOffset))); uVar4 = (short)DAT_TileMapState::instance.UnitLayer[_buildingID]; while (iVar11 = (int)(short)uVar4, iVar11) { - _y = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_buildingID); + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + _buildingID); _x = (int)(local_4 - _y) >> 0x1f; if (((int)((local_4 - _y ^ _x) - _x) < 0x78) && (this->entityArray[entityID].logicalState == 2)) { @@ -273,8 +268,8 @@ namespace Map { if ((((this->entityArray[entityID].entityType == Map::Entities::ET_FIRE) && (_buildingID = this->entityArray[entityID].tile, (DAT_TileMapState::instance.LogicLayer[_buildingID] & 8) != 0)) - && (_buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, - DAT_TileMapState::ptr)(_buildingID), + && (_buildingID = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(_buildingID), _buildingID != 0)) && (DAT_TileMapState::instance.pitchDitches[_buildingID].state == 1)) { MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, @@ -285,8 +280,7 @@ namespace Map { 3); DAT_TileMapState::instance.pitchDitches[_buildingID].state = 2; } - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( - _someTile, 0); + _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(_someTile, 0); _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); if (((_buildingID) && ((_buildingID = (int)(short)DAT_BuildingsState::instance.buildings[_buildingID].buildingType, @@ -313,8 +307,7 @@ namespace Map { - 8)), 2), (DAT_TileMapState::instance.LogicLayer[_someTile] & 8) != 0 - && (_buildingID - = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + && (_buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(_someTile), _buildingID != 0)))))) { MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( @@ -356,11 +349,9 @@ namespace Map { } goto LAB_00408150; } - if (((EVar3 == Map::Entities::ET_ARROW_AND_DEFAULT) - || (EVar3 == Map::Entities::ET_CROSSBOWARROW)) + if (((EVar3 == Map::Entities::ET_ARROW_AND_DEFAULT) || (EVar3 == Map::Entities::ET_CROSSBOWARROW)) || ((EVar3 == Map::Entities::ET_BALLISTA - || ((EVar3 == Map::Entities::ET_SLINGER - || (EVar3 == Map::Entities::ET_FIRETHROWER)))))) { + || ((EVar3 == Map::Entities::ET_SLINGER || (EVar3 == Map::Entities::ET_FIRETHROWER)))))) { if (this->entityArray[entityID].rng_2 == 2) { _buildingID = 0; do { @@ -415,8 +406,8 @@ namespace Map { goto LAB_00408150; if (DAT_UnitsState::instance.units[_entityOriginUnitID].unitType == Map::Units::UT_S_FBALLISTA) { - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, - DAT_TileMapState::ptr)(_someTile, + MACRO_CALL_MEMBER( + Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), (uint)((int)((int)this->entityArray[entityID].yPosition)), 10, 0, (int)((int)(this->entityArray[entityID].owner)), FALSE, _entityOriginUnitID); @@ -446,25 +437,23 @@ namespace Map { _xPosition = this->entityArray[entityID].xPosition; _buildingID = 1; } - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, - DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)_xPosition)), - (uint)((int)((int)_yPosition)), _buildingID, 0, (int)((int)(_playerID)), FALSE, - _entityOriginUnitID); + MACRO_CALL_MEMBER( + Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)(_someTile, + (uint)((int)((int)_xPosition)), (uint)((int)((int)_yPosition)), _buildingID, 0, + (int)((int)(_playerID)), FALSE, _entityOriginUnitID); } this->entityArray[entityID].someCounter_OR_hitGround = 1; } } else { if ((this->entityArray[entityID].rng_2 == 2) - && (iVar11 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, - DAT_TileMapState::ptr)(_someTile), + && (iVar11 = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(_someTile), iVar11 != 0)) { LAB_00407f73: MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( (int)this->entityArray[entityID].xPosition, - (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_IGNITE_PITCH); - MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( - (int)this->entityArray[entityID].owner, + (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].x * 8)), (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].y * 8)), (int)((int)((uint)DAT_TileMapState::instance @@ -482,11 +471,9 @@ namespace Map { || ((this->entityArray[entityID].hasDoneEffectUnk != 0 || (0 < this->entityArray[entityID].clearanceStepsRemaining)))) goto LAB_00408150; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, local_10)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, local_10)(entityID); } - } else if (((EVar3 == Map::Entities::ET_TREBUCHET) - || (EVar3 == Map::Entities::ET_CATAPULT)) + } else if (((EVar3 == Map::Entities::ET_TREBUCHET) || (EVar3 == Map::Entities::ET_CATAPULT)) || (EVar3 == Map::Entities::ET_MANGONEL)) { this->entityArray[entityID].someCounter_OR_hitGround = 1; _y = DAT_TileMapState::instance.LogicLayer[_someTile]; @@ -502,14 +489,13 @@ namespace Map { if (((!_x) && (!(_y & 0x10000400))) && (*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile) == 0)) { psVar2 - = &DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field98_0xd2; + = &DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2; *psVar2 = *psVar2 + 1; if (!(_y & 0x4a5014b1)) { local_4 = _x; MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( (int)this->entityArray[entityID].xPosition, - (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_ROCK_HIT_GROUND); + (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_ROCK_HIT_GROUND); _y = this->entityArray[entityID].rng_1 & 0x80000007; this->entityArray[entityID].someCounter_OR_hitGround = 0x28; local_c = 0; @@ -520,8 +506,8 @@ namespace Map { do { _buildingID = (int)this->entityArray[entityID].microY; iVar11 = (int)this->entityArray[entityID].microX; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, - local_10)(2, 0, 0, iVar11, _buildingID, + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)(2, + 0, 0, iVar11, _buildingID, (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2)), (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, @@ -545,8 +531,8 @@ namespace Map { do { _buildingID = (int)this->entityArray[entityID].microY; iVar11 = (int)this->entityArray[entityID].microX; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, - local_10)(1, 0, 0, iVar11, _buildingID, + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)(1, + 0, 0, iVar11, _buildingID, (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2)), (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, @@ -567,8 +553,7 @@ namespace Map { } } else { local_4 = _x; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, local_10)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, local_10)(entityID); _entityType_2 = this->entityArray[entityID].entityType; if (_entityType_2 == 3) { _damageUnk = 60; @@ -595,8 +580,8 @@ namespace Map { _collateralDamageUnk = 0; } if (_entityType_2 == 4) { - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, - DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + _someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, (int)((int)(-this->entityArray[entityID].owner)), FALSE, (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); @@ -606,8 +591,8 @@ namespace Map { (int)((int)(_collateralDamageUnk)), (int)((int)(-this->entityArray[entityID].owner)), 0, (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); } else { - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, - DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + _someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, (int)((int)(this->entityArray[entityID].owner)), FALSE, (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); @@ -639,8 +624,8 @@ namespace Map { if (_randomNumber < 8) { _randomNumber2 = 8 - _randomNumber; do { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, - this)(0, (undefined4)((int)((int)this->entityArray[entityID].owner)), 0, + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, + (undefined4)((int)((int)this->entityArray[entityID].owner)), 0, (int)((int)(this->entityArray[entityID].microX)), (int)((int)(this->entityArray[entityID].microY)), (int)((int)(this->entityArray[entityID].height)), 0, 0, 0, diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index 60efb04727..34b7988226 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -71,8 +71,7 @@ namespace Map { _yPosition = this->entityArray[_entityID].yPosition; this->entityArray[_entityID].targetY = _y; MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[_entityID].xPosition, (int)((int)(_yPosition)), - DE::SHCDE::FX_GULL_SURFACE); + (int)this->entityArray[_entityID].xPosition, (int)((int)(_yPosition)), DE::SHCDE::FX_GULL_SURFACE); } _microX = (int)this->entityArray[_entityID].microX; _targetX = _microX - this->entityArray[_entityID].targetX; @@ -88,8 +87,8 @@ namespace Map { _newMicroX = this->entityArray[_entityID].someMicroX + _microX; _newY = _newMicroY / 8; _newX = _newMicroX / 8; - _newBounds = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, - DAT_ViewportRenderState::ptr)(_newX, _newY); + _newBounds = MACRO_CALL_MEMBER( + Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)(_newX, _newY); if (_newBounds) { _oldMicroY = (int)this->entityArray[_entityID].microY; _oldMicroX = (int)this->entityArray[_entityID].microX; @@ -107,8 +106,8 @@ namespace Map { + _oldX] & 1))) { this->seagullArray[seagullID].someCountDown = 160; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, - this)(_entityID, (int)((int)(this->entityArray[_entityID].microX)), + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)( + _entityID, (int)((int)(this->entityArray[_entityID].microX)), (int)((int)(this->entityArray[_entityID].microY)), 0xfa, _newMicroX, _newMicroY, 0); MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( (int)this->entityArray[_entityID].xPosition, @@ -128,7 +127,7 @@ namespace Map { (int)this->entityArray[_entityID].xPosition, (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL); } - sVar4 = this->seagullArray[seagullID].field12_0x1a; + sVar4 = this->seagullArray[seagullID].field_0x1a; this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle + -360; if (sVar4 < 0) { this->seagullArray[seagullID].unknownCounter_0x16 @@ -143,15 +142,15 @@ namespace Map { if (80 < this->seagullArray[seagullID].unknownCounter_0x16) { this->seagullArray[seagullID].unknownCounter_0x16 = 80; } - this->seagullArray[seagullID].field12_0x1a = sVar4 + 1; + this->seagullArray[seagullID].field_0x1a = sVar4 + 1; if ((short)(sVar4 + 1) >= 0x14) { - this->seagullArray[seagullID].field12_0x1a = -0x14; + this->seagullArray[seagullID].field_0x1a = -0x14; } } sVar4 = this->seagullArray[seagullID].angle; if (sVar4 < 0) { this->seagullArray[seagullID].angle = sVar4 + 0x168; - sVar4 = this->seagullArray[seagullID].field12_0x1a; + sVar4 = this->seagullArray[seagullID].field_0x1a; if (sVar4 < 0) { this->seagullArray[seagullID].unknownCounter_0x16 = this->seagullArray[seagullID].unknownCounter_0x16 + 1; @@ -165,9 +164,9 @@ namespace Map { if (0x50 < this->seagullArray[seagullID].unknownCounter_0x16) { this->seagullArray[seagullID].unknownCounter_0x16 = 0x50; } - this->seagullArray[seagullID].field12_0x1a = sVar4 + 1; + this->seagullArray[seagullID].field_0x1a = sVar4 + 1; if ((short)(sVar4 + 1) >= 0x14) { - this->seagullArray[seagullID].field12_0x1a = -0x14; + this->seagullArray[seagullID].field_0x1a = -0x14; } } iVar8 = (int)this->seagullArray[seagullID].unknownCounter_0x16; @@ -196,8 +195,8 @@ namespace Map { _targetYPart1 = (short)iVar8; _targetYPart1 = _targetYPart1 + this->seagullArray[seagullID].y; this->seagullArray[seagullID].y_2 = _targetYPart1; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)( - _entityID, (int)((int)(this->entityArray[_entityID].microX)), + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)(_entityID, + (int)((int)(this->entityArray[_entityID].microX)), (int)((int)(this->entityArray[_entityID].microY)), (int)((int)(this->entityArray[_entityID].height)), _targetXPart1 + _targetXPart2, _targetYPart1 + _targetYPart2, (int)((int)(250))); @@ -265,8 +264,7 @@ namespace Map { } _entityID = (int)this->seagullArray[seagullID].y; this->seagullArray[seagullID].rngMax799_countdown = SEC_RNG::instance.currentNumber2 % 400 + 400; - MACRO_CALL_MEMBER( - Map::Navigation::PathFindingState_Func::findFurthestSeaTile, DAT_PathFindingState::ptr)( + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findFurthestSeaTile, DAT_PathFindingState::ptr)( (int)((((ulonglong)((int)SEC_RNG::instance.currentNumber2 >> 0x1f) << 0x20) | (uint)((uint)((int)((int)SEC_RNG::instance.currentNumber2 >> 4) % 200) + 400))), (uint)((int)(iVar8 / 8)), _entityID / 8); @@ -275,8 +273,8 @@ namespace Map { sVar2 = (short)DAT_PathFindingState::instance.ALG_ResultY * 8; sVar5 = this->seagullArray[seagullID].x; this->seagullArray[seagullID].y_3 = sVar2; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)( - seagullID, (int)((int)(sVar5)), (int)((int)(this->seagullArray[seagullID].y)), (int)((int)(sVar4)), + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)(seagullID, + (int)((int)(sVar5)), (int)((int)(this->seagullArray[seagullID].y)), (int)((int)(sVar4)), (int)((int)(sVar2))); this->seagullArray[seagullID].pathStepDelay = 10; return; diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp index aef49ccb50..cccff80249 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -50,9 +50,9 @@ namespace Map { psVar3 = psVar3 + 0x74; } while ((int)entityID < 0x19); } else { - entityID = this->every10Ticks; - if (this->every10Ticks < 3000) { - psVar3 = &this->entityArray[this->every10Ticks].logicalState; + entityID = this->everyTenTicks; + if (this->everyTenTicks < 3000) { + psVar3 = &this->entityArray[this->everyTenTicks].logicalState; do { if (*psVar3 == 0) break; @@ -91,7 +91,7 @@ namespace Map { psVar3 = psVar3 + 0x74; } while ((int)entityID < 3000); } - this->every10Ticks = entityID; + this->everyTenTicks = entityID; if (this->maxEntityCount <= (int)entityID) { this->maxEntityCount = entityID + 1; } @@ -104,7 +104,7 @@ namespace Map { entityType = Map::Entities::ET_ARROW_AND_DEFAULT; } else if (entityType == Map::Entities::ET_FIREBALLISTA) { bVar1 = true; - this->entityArray[entityID].field90_0xd0 = 1; + this->entityArray[entityID].field_0xd0 = 1; entityType = Map::Entities::ET_BALLISTA; } else { if ((entityType == Map::Entities::ET_FIRETHROWER) @@ -181,7 +181,7 @@ namespace Map { this->entityArray[entityID].targetY = (short)targetY; this->entityArray[entityID].targetZ = (short)targetZUnk; this->entityArray[entityID].heightDifference = targetZUnk - totalHeight; - this->entityArray[entityID].field21_0x34 = dVar2; + this->entityArray[entityID].field_0x34 = dVar2; this->entityArray[entityID].unitID = (short)param_11; this->entityArray[entityID].owner = (short)playerID1; this->entityArray[entityID].microX = (short)microX; @@ -202,18 +202,16 @@ namespace Map { DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; this->entityArray[entityID].colorUnk = 0; - if ((((entityType == Map::Entities::ET_FLAG_1) - || (entityType == Map::Entities::ET_FLAG_4)) + if ((((entityType == Map::Entities::ET_FLAG_1) || (entityType == Map::Entities::ET_FLAG_4)) || (entityType == Map::Entities::ET_FLAG_2)) || (entityType == Map::Entities::ET_FLAG_3)) { this->entityArray[entityID].colorUnk = ownerColorUnk; } - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileEntityValues2, this)( - entityID, entityType); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileEntityValues2, this)(entityID, entityType); if (this->entityArray[entityID].rng_2 != 0) { this->entityArray[entityID].gmID = 0x91; } - this->entityArray[entityID].field7_0x12 = 0; + this->entityArray[entityID].field_0x12 = 0; this->entityArray[entityID].unknownAnimationFrameRelated = 0; if (entityType == Map::Entities::ET_DUST_CLOUD) { if (param_11 == 1) { @@ -263,8 +261,7 @@ namespace Map { this->entityArray[entityID].gmLookupValue = 1; } if (entityID) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); uVar5 = DAT_CurrentEntityID::instance; DAT_CurrentEntityID::instance = entityID; @@ -289,7 +286,7 @@ namespace Map { pEVar4 = pEVar4 + 0x74; if (2999 < (int)entityID) { switchD_00404bac_caseD_5: - this->every10Ticks = 2999; + this->everyTenTicks = 2999; return 0; } } diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index ffc9d54216..fd937b11b3 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -26,7 +26,7 @@ namespace Map { int local_4; short _gmLookupValue; if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 0) { - this->every10Ticks = 25; + this->everyTenTicks = 25; } this->totalEntityCount = 0; DAT_CurrentEntityID::instance = 1; @@ -71,13 +71,13 @@ namespace Map { goto LAB_00408d6d; } if (this->entityArray[DAT_CurrentEntityID::instance].unkOne_1 - <= this->entityArray[DAT_CurrentEntityID::instance].field7_0x12) { + <= this->entityArray[DAT_CurrentEntityID::instance].field_0x12) { this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + 1; - this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 = 0; + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 = 0; } - this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 - = this->entityArray[DAT_CurrentEntityID::instance].field7_0x12 + 1; + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + = this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + 1; if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 6) goto switchD_0040890b_caseD_9; /* @@ -92,10 +92,10 @@ namespace Map { case Map::Entities::ET_FLAG_3: case Map::Entities::ET_BRAZIER: case Map::Entities::ET_HEADS_ON_SPIKES: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, - this)(DAT_CurrentEntityID::instance); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, - this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); break; default: this->entityArray[DAT_CurrentEntityID::instance].screenDirection @@ -134,9 +134,8 @@ namespace Map { case Map::Entities::ET_DUST_CLOUD: if (this->entityArray[DAT_CurrentEntityID::instance].unitID == 2) { if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1)) { - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( - DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); this->entityArray[DAT_CurrentEntityID::instance].height = this->entityArray[DAT_CurrentEntityID::instance].height + 1; iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance] @@ -163,17 +162,15 @@ namespace Map { this->entityArray[DAT_CurrentEntityID::instance].microY = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; } - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( - DAT_CurrentEntityID::instance); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); } } else if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1)) { - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( - DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); this->entityArray[DAT_CurrentEntityID::instance].height = this->entityArray[DAT_CurrentEntityID::instance].height + 1; sVar2 = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; @@ -198,10 +195,10 @@ namespace Map { this->entityArray[DAT_CurrentEntityID::instance].microY = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; } - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, - this)(DAT_CurrentEntityID::instance); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, - this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); } break; case Map::Entities::ET_COW_POISON_CLOUD: @@ -209,8 +206,8 @@ namespace Map { = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk < 0x1f) goto LAB_00408c15; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, - this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + DAT_CurrentEntityID::instance); if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk = this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - 1; @@ -263,8 +260,8 @@ namespace Map { this->entityArray[DAT_CurrentEntityID::instance].microY = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; } - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, - this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( DAT_CurrentEntityID::instance); LAB_00408c15: @@ -284,8 +281,7 @@ namespace Map { switchD_0040890b_caseD_9: ((void (*)())DAT_EntityDefinedData::instance .EntityCallbacks[(short)this->entityArray[DAT_CurrentEntityID::instance].entityType])(); - if (this->entityArray[DAT_CurrentEntityID::instance].entityType - == Map::Entities::ET_SEAGULLUnk) { + if (this->entityArray[DAT_CurrentEntityID::instance].entityType == Map::Entities::ET_SEAGULLUnk) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processSeaGulls, this)( (int)this->entityArray[DAT_CurrentEntityID::instance].unitID_OR_seaGullID); } diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp index ad68513886..5247625e6c 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -15,17 +15,14 @@ namespace Map { sVar1 = this->entityArray[entityID].startingHeight + (short)param_2; this->entityArray[entityID].height = sVar1; if ((sVar1 < 3) && (!param_4)) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( - entityID); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( - entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); } sVar1 = this->entityArray[entityID].height; if (10000 < sVar1) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); } - uVar2 - = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); + uVar2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); this->entityArray[entityID].rotationFrameIndex = (short)uVar2; this->entityArray[entityID].height_2 = sVar1; } diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index e62ba1cf8a..5c1a631a5b 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -57,25 +57,23 @@ namespace Map { goto switchD_0040539c_caseD_2d; } } - _entityID = MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(_tile); + _entityID = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)( + _tile); if (!_entityID) { if (_buildingID) { - MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( (int)DAT_TileMapState::instance.BuildingLayer[_tile], playerID, fireIntensity); } if ((DAT_TileMapState::instance.LogicLayer[_tile] & 0x1000U)) { - MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)( - _tile, playerID); + MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(_tile, playerID); } _entityID_2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, 0, Map::Entities::ET_FIRE, 0); if ((2 < two) && (!(DAT_TileMapState::instance.RandomLayer[_tile] & 3))) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, - DAT_EntityState::ptr)(0, (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, - 0, (EntityType)((int)(26)), 0); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, + (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, 0, + (EntityType)((int)(26)), 0); } if (_entityID_2) { DAT_EntityState::instance.entityArray[_entityID_2].fireParameter_0xb6 = (short)two; diff --git a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp index be838c73a0..0761318553 100644 --- a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp @@ -70,13 +70,11 @@ namespace Map { } } else if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; - iVar3 - = (int)(char)DAT_EntityDefinedData::instance - .FireAnimationFrames5[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames5 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; } else { - iVar3 - = (int)(char)DAT_EntityDefinedData::instance - .FireAnimationFrames3[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames3 + [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; } LAB_004058ca: if (0 < iVar3) @@ -155,15 +153,15 @@ namespace Map { if ((DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker != 0) || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated != 1)) goto LAB_00405b3d; - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field79_0xb8; + _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; _tile = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile; _height = (uint)DAT_TileMapState::instance.HeightLayer[_tile]; if ((3 < _height0) || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 < 2)) goto LAB_00405b3d; if (!_height0) { - _totalHeightAtTile = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + -1); + _totalHeightAtTile + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + -1); _heightDerivative = (int)(_height - _totalHeightAtTile) >> 0x1f; if (0x18 < (int)((_height - _totalHeightAtTile ^ _heightDerivative) - _heightDerivative)) goto LAB_00405b2a; @@ -175,12 +173,12 @@ namespace Map { LAB_00405b18: _playerID = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; LAB_00405b22: - MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)((int)_playerID, _x, _y, - (int)((int)(_height0)), (int)((int)(_0xb6 + -1)), (int)((int)(_fireIntensity0))); + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)((int)_playerID, _x, _y, (int)((int)(_height0)), + (int)((int)(_0xb6 + -1)), (int)((int)(_fireIntensity0))); } else { if (_height0 == 1) { - uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - _tile + 1); + uVar2 + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + 1); uVar4 = (int)(_height - uVar2) >> 0x1f; if (0x18 < (int)((_height - uVar2 ^ uVar4) - uVar4)) goto LAB_00405b2a; @@ -211,8 +209,7 @@ namespace Map { goto LAB_00405b18; } } else if ((_height0 == 3) - && (uVar2 - = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + && (uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + DAT_ViewportRenderState::instance .translationMatrix @@ -227,14 +224,13 @@ namespace Map { } LAB_00405b2a: _entityOffset = DAT_CurrentEntityID::instance * 0xe8; - psVar1 = &DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field79_0xb8; + psVar1 = &DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; *psVar1 = *psVar1 + 1; LAB_00405b3d: iVar3 = *(int*)(DAT_EntityState::instance.entityArray[0].unused_0x48 + _entityOffset + 4); if (!(DAT_TileMapState::instance.LogicLayer[iVar3] & 0xba7001b1U)) { - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::processFireDamageToUnitsAtTile, DAT_EntityState::ptr)(iVar3, - (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0x2e + _entityOffset + -2), + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processFireDamageToUnitsAtTile, DAT_EntityState::ptr)( + iVar3, (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0x2e + _entityOffset + -2), (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0xe0 + _entityOffset + -8)); } } From 10ebb3aebe5d2eecaa3cb9e6a44f5d0147d60e99 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:00 +0100 Subject: [PATCH 03/51] reimplement: status of 16 ported functions SHC_3BB0A8C1_0x00402180 12.2% UpdateEntity_CowFlying SHC_3BB0A8C1_0x00402900 47.3% UpdateFlag_1_2_4_Entity SHC_3BB0A8C1_0x00402C50 56.9% math_atan_1 SHC_3BB0A8C1_0x00402E20 8.2% computeLineOfSightDistance SHC_3BB0A8C1_0x004036F0 24.2% calculateEntityDrawOffset SHC_3BB0A8C1_0x00403A20 36.5% initializeProjectileVelocities SHC_3BB0A8C1_0x00403FF0 74.9% handleProjectileWallBounce SHC_3BB0A8C1_0x00404AE0 70.4% spawnProjectileEntity SHC_3BB0A8C1_0x004052E0 66.7% IgniteFireAtMiniTile SHC_3BB0A8C1_0x00405680 30.5% UpdateFireEntity SHC_3BB0A8C1_0x00405DA0 78.9% spawnProjectileImpactDebris SHC_3BB0A8C1_0x00406900 47.5% processSeaGulls SHC_3BB0A8C1_0x00407190 47.8% processEntityHitBuildingOrUnit SHC_3BB0A8C1_0x004081E0 60.0% updateProjectileHeightAndCollision SHC_3BB0A8C1_0x004084A0 50.4% moveProjectileEntity SHC_3BB0A8C1_0x004087C0 56.4% updateEntities Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- status/addresses-SHC-3BB0A8C1.txt | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 81b4e6a71e..2791b4f422 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -469,7 +469,7 @@ SHC_3BB0A8C1_0x00401EA0 | 0.0% | Pending SHC_3BB0A8C1_0x00401FF0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402180 | 0.0% | Pending +SHC_3BB0A8C1_0x00402180 | 12.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00402260 | 0.0% | Pending @@ -491,7 +491,7 @@ SHC_3BB0A8C1_0x00402730 | 0.0% | Pending SHC_3BB0A8C1_0x00402820 | 0.0% | Pending -SHC_3BB0A8C1_0x00402900 | 0.0% | Pending +SHC_3BB0A8C1_0x00402900 | 47.3% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00402A0C | 0.0% | Pending @@ -519,15 +519,15 @@ SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending SHC_3BB0A8C1_0x00402BD0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402C50 | 0.0% | Pending +SHC_3BB0A8C1_0x00402C50 | 56.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 0.0% | Pending +SHC_3BB0A8C1_0x00402E20 | 8.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00403200 | 0.0% | Pending -SHC_3BB0A8C1_0x004036F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004036F0 | 24.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00403790 | 100.0% | Pending @@ -543,9 +543,9 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 0.0% | Pending +SHC_3BB0A8C1_0x00403A20 | 36.5% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x00403FF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00403FF0 | 74.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004044E4 | 0.0% | Pending @@ -1183,7 +1183,7 @@ SHC_3BB0A8C1_0x00404A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00404A70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00404AE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00404AE0 | 70.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00404B70 | 0.0% | Pending @@ -1623,7 +1623,7 @@ SHC_3BB0A8C1_0x00405125 | 0.0% | Pending SHC_3BB0A8C1_0x00405130 | 100.0% | Reimplemented (counted: only the constant 0x10300131 is shown as an address label in ours) -SHC_3BB0A8C1_0x004052E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004052E0 | 66.7% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004054AC | 0.0% | Pending @@ -1699,7 +1699,7 @@ SHC_3BB0A8C1_0x004054D5 | 0.0% | Pending SHC_3BB0A8C1_0x004054E0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405680 | 0.0% | Pending +SHC_3BB0A8C1_0x00405680 | 30.5% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00405B70 | 100.0% | Reimplemented @@ -1707,7 +1707,7 @@ SHC_3BB0A8C1_0x00405C00 | 0.0% | Pending SHC_3BB0A8C1_0x00405CF0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405DA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00405DA0 | 78.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0040612C | 0.0% | Pending @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIsin, _CIcos, _ftol2_sse) differ) -SHC_3BB0A8C1_0x00406900 | 0.0% | Pending +SHC_3BB0A8C1_0x00406900 | 47.5% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 0.0% | Pending +SHC_3BB0A8C1_0x00407190 | 47.8% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00407570 | 0.0% | Pending @@ -2441,7 +2441,7 @@ SHC_3BB0A8C1_0x004081D4 | 0.0% | Pending SHC_3BB0A8C1_0x004081D5 | 0.0% | Pending -SHC_3BB0A8C1_0x004081E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004081E0 | 60.0% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00408250 | 100.0% | Reimplemented @@ -2449,11 +2449,11 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004084A0 | 50.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00408770 | 0.0% | Pending -SHC_3BB0A8C1_0x004087C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004087C0 | 56.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00408D90 | 0.0% | Pending From de335138568a5c96559d19bce40dbddfde135204 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 21:42:21 +0100 Subject: [PATCH 04/51] Entities: CowFlying, flag and projectile height fixed against the binary All three fix behaviour the decompiler output got wrong: - UpdateEntity_CowFlying 12.2 -> 90.5: the frame cap fires at >= 120 (Ghidra had > 120), the frame division is a division again, the airborne arm comes first and the counter is decremented through a pointer. Left: MSVC loads the graphic offset before the division and needs ebx for it. - updateProjectileHeightAndCollision 60.0 -> 79.5: a projectile above 10000 is destroyed and the function returns (Ghidra fell through and still wrote the rotation frame); the ground test reads the stored height. Left: the original keeps the height in edx across the rotation-frame call (LTCG). - UpdateFlag_1_2_4_Entity 47.3 -> 53.9: a frame <= 0 resets the animation and returns without adding to graphicType2; the locals are int (the original sign-extends), the AI tracker tests put the != 0 arms first. Left: the original re-reads someTracker for the switch and keeps 0 in edi. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../updateProjectileHeightAndCollision.cpp | 18 ++--- .../Map/Entities/UpdateEntity_CowFlying.cpp | 54 ++++++------- .../Map/Entities/UpdateFlag_1_2_4_Entity.cpp | 81 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 6 +- 4 files changed, 73 insertions(+), 86 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp index 5247625e6c..ac8e3047a9 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -10,21 +10,19 @@ namespace Map { void EntityState::updateProjectileHeightAndCollision( uint entityID, undefined4 param_2, int param_3, int param_4) { - short sVar1; - undefined4 uVar2; - sVar1 = this->entityArray[entityID].startingHeight + (short)param_2; - this->entityArray[entityID].height = sVar1; - if ((sVar1 < 3) && (!param_4)) { + this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + (short)param_2; + if (this->entityArray[entityID].height <= 2 && !param_4) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); } - sVar1 = this->entityArray[entityID].height; - if (10000 < sVar1) { + short const currentHeight = this->entityArray[entityID].height; + if (currentHeight > 10000) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return; } - uVar2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); - this->entityArray[entityID].rotationFrameIndex = (short)uVar2; - this->entityArray[entityID].height_2 = sVar1; + this->entityArray[entityID].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); + this->entityArray[entityID].height_2 = currentHeight; } } diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp index 38379f043d..9f931730d7 100644 --- a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -10,40 +10,36 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00402180 void Entities::UpdateEntity_CowFlying() { - short* psVar1; - uint uVar2; - int iVar3; - uVar2 = DAT_CurrentEntityID::instance; - if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { - if (0xb - < DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + uint const entityID = DAT_CurrentEntityID::instance; + if (DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround != 0) { + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated < 100) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 100; } - iVar3 = (int)DAT_EntityState::instance.entityArray[uVar2].graphicType2RelatedOffset - + (int)DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated; - DAT_EntityState::instance.entityArray[uVar2].graphicType2 = iVar3; - DAT_EntityState::instance.entityArray[uVar2].imageID = (short)iVar3 + 0x11; - } else { - if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated - < 100) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 100; + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 120) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 119; } - if (120 < DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated) { - DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0x77; + short* const counter = &DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround; + *counter = *counter - 1; + if (*counter <= 0) { + DAT_EntityState::instance.entityArray[entityID].logicalState = 7; } - psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; - *psVar1 = *psVar1 + -1; - if (DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround < 1) { - DAT_EntityState::instance.entityArray[uVar2].logicalState = 7; + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated - 100) / 4 + 0xc + + DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset; + DAT_EntityState::instance.entityArray[entityID].imageID = 0; + } else { + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 12) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 0; } - iVar3 = DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated + -100; - DAT_EntityState::instance.entityArray[uVar2].graphicType2 = ((int)(iVar3 + (iVar3 >> 0x1f & 3U)) >> 2) + 0xc - + (int)DAT_EntityState::instance.entityArray[uVar2].graphicType2RelatedOffset; - DAT_EntityState::instance.entityArray[uVar2].imageID = 0; + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset + + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated; + DAT_EntityState::instance.entityArray[entityID].imageID + = (short)(DAT_EntityState::instance.entityArray[entityID].graphicType2 + 0x11); } - if (DAT_EntityState::instance.entityArray[uVar2].orientation == 0x4c) { - DAT_EntityState::instance.entityArray[uVar2].orientation = 0x3c; - DAT_EntityState::instance.entityArray[uVar2].logicalState = 7; + if (DAT_EntityState::instance.entityArray[entityID].orientation == 0x4c) { + DAT_EntityState::instance.entityArray[entityID].orientation = 0x3c; + DAT_EntityState::instance.entityArray[entityID].logicalState = 7; } } diff --git a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp index 84ac0397b9..494cd3e5ca 100644 --- a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -22,66 +22,59 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00402900 void Entities::UpdateFlag_1_2_4_Entity() { - AIRecruitUnitChoiceInt AVar1; - uint uVar2; - int iVar3; - short sVar4; - short _owner; - uVar2 = DAT_CurrentEntityID::instance; - sVar4 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; - _owner = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 - = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset; - if (DAT_LandscapeState::instance.wind.countdown - <= (int)((byte)DAT_EntityState::instance.entityArray[uVar2].yPosition & 0x1f)) { - sVar4 = (short)DAT_LandscapeState::instance.wind.value; + uint const entityID = DAT_CurrentEntityID::instance; + int nextTracker = DAT_EntityState::instance.entityArray[entityID].someTracker; + int const owner = DAT_EntityState::instance.entityArray[entityID].owner; + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset; + if (((byte)DAT_EntityState::instance.entityArray[entityID].yPosition & 0x1f) + >= DAT_LandscapeState::instance.wind.countdown) { + nextTracker = DAT_LandscapeState::instance.wind.value; } - if (((DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) - && (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[_owner] == -1)) - && (DAT_GameSynchronyState::instance.currentAIArray[_owner] != 0)) { - if (DAT_GameState::instance.playerDataArray[_owner].aiBuildingDestroyChoiceTracker == 0) { - if (DAT_GameState::instance.playerDataArray[_owner].aiNervousActionsTracker == 0) { - AVar1 = DAT_GameState::instance.playerDataArray[_owner].aiRecruitUnitChoiceState; - sVar4 = 0; - if (AVar1 != AI::AIRUC_DEFENSIVE) { - sVar4 = (AVar1 != AI::AIRUC_RAIDING) + 1; - } - } else { - sVar4 = 3; - } + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentPlayerFullIDArray[owner] == -1 + && DAT_GameSynchronyState::instance.currentAIArray[owner] != 0) { + if (DAT_GameState::instance.playerDataArray[owner].aiBuildingDestroyChoiceTracker != 0) { + nextTracker = 3; + } else if (DAT_GameState::instance.playerDataArray[owner].aiNervousActionsTracker != 0) { + nextTracker = 3; } else { - sVar4 = 3; + AIRecruitUnitChoiceInt const recruitChoice + = DAT_GameState::instance.playerDataArray[owner].aiRecruitUnitChoiceState; + nextTracker = 0; + if (recruitChoice != AI::AIRUC_DEFENSIVE) { + nextTracker = (recruitChoice != AI::AIRUC_RAIDING) + 1; + } } } - DAT_EntityState::instance.entityArray[uVar2].unkOne_1 = 3; - switch (DAT_EntityState::instance.entityArray[uVar2].someTracker) { + DAT_EntityState::instance.entityArray[entityID].unkOne_1 = 3; + int frame; + switch (DAT_EntityState::instance.entityArray[entityID].someTracker) { case 0: - iVar3 - = DAT_EntityDefinedData::instance - .FlagAnimationFrames1[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance.FlagAnimationFrames1[DAT_EntityState::instance.entityArray[entityID] + .unknownAnimationFrameRelated]; break; case 1: - iVar3 - = DAT_EntityDefinedData::instance - .FlagAnimationFrames2[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance.FlagAnimationFrames2[DAT_EntityState::instance.entityArray[entityID] + .unknownAnimationFrameRelated]; break; case 3: - DAT_EntityState::instance.entityArray[uVar2].unkOne_1 = 1; + DAT_EntityState::instance.entityArray[entityID].unkOne_1 = 1; /* falls through into case 2 */ case 2: - iVar3 - = DAT_EntityDefinedData::instance - .FlagAnimationFrames3[DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance.FlagAnimationFrames3[DAT_EntityState::instance.entityArray[entityID] + .unknownAnimationFrameRelated]; break; default: return; } - if (iVar3 < 1) { - DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0; - DAT_EntityState::instance.entityArray[uVar2].someTracker = sVar4; + if (frame <= 0) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 0; + DAT_EntityState::instance.entityArray[entityID].someTracker = nextTracker; + return; } - DAT_EntityState::instance.entityArray[uVar2].graphicType2 - = DAT_EntityState::instance.entityArray[uVar2].graphicType2 + iVar3 + -1; + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = DAT_EntityState::instance.entityArray[entityID].graphicType2 + frame - 1; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2791b4f422..fd8392bc9b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -469,7 +469,7 @@ SHC_3BB0A8C1_0x00401EA0 | 0.0% | Pending SHC_3BB0A8C1_0x00401FF0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402180 | 12.2% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00402180 | 90.5% | Offset load scheduled before the division SHC_3BB0A8C1_0x00402260 | 0.0% | Pending @@ -491,7 +491,7 @@ SHC_3BB0A8C1_0x00402730 | 0.0% | Pending SHC_3BB0A8C1_0x00402820 | 0.0% | Pending -SHC_3BB0A8C1_0x00402900 | 47.3% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00402900 | 53.9% | Switch value re-read and zero register in the original SHC_3BB0A8C1_0x00402A0C | 0.0% | Pending @@ -2441,7 +2441,7 @@ SHC_3BB0A8C1_0x004081D4 | 0.0% | Pending SHC_3BB0A8C1_0x004081D5 | 0.0% | Pending -SHC_3BB0A8C1_0x004081E0 | 60.0% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004081E0 | 79.5% | edx kept across the call (LTCG) SHC_3BB0A8C1_0x00408250 | 100.0% | Reimplemented From 9bd7b11f0c5009d1878c2cc2714b5ba8ed900579 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 21:46:48 +0100 Subject: [PATCH 05/51] Entities: IgniteFireAtMiniTile and math_atan_1 - IgniteFireAtMiniTile 66.7 -> 71.7: the existing-fire update comes before the spawn path and returns 0 (the original lays it out first), the tower and gatehouse cases return directly, the fire-strength test reads `two > fireParameter_0xb6`, and the decompiler locals are named consts. Left: the parameter is loaded before the jitter table entry is added. - math_atan_1 56.9 -> 57.1: the 96.275344 constant multiplies the shared d * d. Left: the original reuses the dead parameter slots for the fild temporaries. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/EntityState/math_atan_1.cpp | 2 +- .../Map/Entities/IgniteFireAtMiniTile.cpp | 87 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 4 +- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp index a9efbea7ec..8db866930a 100644 --- a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp @@ -22,7 +22,7 @@ namespace Map { fVar5 = (double)param_3 * (double)param_3; fVar6 = (double)(param_4 * 4); dVar1 = (double)(fVar5 / (fVar6 * (double)9.812)); - fVar5 = sqrt(((fVar5 * fVar5) / ((double)96.275344 * fVar6 * fVar6) + fVar5 = sqrt(((fVar5 * fVar5) / ((double)96.275344 * (fVar6 * fVar6)) - ((fVar5 + fVar5) * (double)(heightDifference / 2)) / (fVar6 * fVar6 * (double)9.812)) - (double)1.0); fVar6 = (double)dVar1 - fVar5; diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index 5c1a631a5b..f3a79b1212 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -24,29 +24,20 @@ namespace Map { uint Entities::IgniteFireAtMiniTile( int playerID, int miniTileX, int miniTileY, int tileHeightMin8, int two, int fireIntensity) { - uint _y; - int _entityID; - uint _entityID_2; - uint _x; - int _tile; - int microY; - uint _randomJitter; - int microX; - short _buildingID; - _randomJitter = (uint)SEC_RNG::instance.currentNumber2; + uint const randomJitter = (uint)SEC_RNG::instance.currentNumber2; MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); - microX = miniTileX + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[_randomJitter & 0x3f][0]; - microY = miniTileY + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[_randomJitter & 0x3f][1]; - _x = microX / 8; - _y = microY / 8; - if (((399 < _x) || (399 < _y)) || (*(char*)(_y * 400 + 0x21aec98 + _x) == '\0')) { + int const microX = miniTileX + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][0]; + int const microY = miniTileY + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][1]; + uint const x = microX / 8; + uint const y = microY / 8; + if (x > 399 || y > 399 || *(char*)(y * 400 + 0x21aec98 + x) == '\0') { return 0; } - _tile = DAT_ViewportRenderState::instance.translationMatrix[_y].addXgetTile + _x; - if (!(DAT_TileMapState::instance.LogicLayer[_tile] & 0x10300131U)) { - _buildingID = DAT_TileMapState::instance.BuildingLayer[_tile]; - if (_buildingID) { - switch (DAT_BuildingsState::instance.buildings[_buildingID].buildingType) { + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x10300131U)) { + short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID) { + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { case Map::Buildings::BT_GATEHOUSELARGE: case Map::Buildings::BT_GATEHOUSESMALL: case Map::Buildings::BT_TOWER1: @@ -54,41 +45,39 @@ namespace Map { case Map::Buildings::BT_TOWER3: case Map::Buildings::BT_TOWER4: case Map::Buildings::BT_TOWER5: - goto switchD_0040539c_caseD_2d; + return 0; } } - _entityID = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)( - _tile); - if (!_entityID) { - if (_buildingID) { - MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( - (int)DAT_TileMapState::instance.BuildingLayer[_tile], playerID, fireIntensity); + int const fireID + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(tile); + if (fireID) { + DAT_EntityState::instance.entityArray[fireID].someTracker = 0; + if (two > DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6) { + DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6 = (short)two; } - if ((DAT_TileMapState::instance.LogicLayer[_tile] & 0x1000U)) { - MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(_tile, playerID); - } - _entityID_2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, - DAT_EntityState::ptr)(0, (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, 0, - Map::Entities::ET_FIRE, 0); - if ((2 < two) && (!(DAT_TileMapState::instance.RandomLayer[_tile] & 3))) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, - (undefined4)((int)(playerID)), 0, microX, microY, tileHeightMin8, 0, 0, 0, - (EntityType)((int)(26)), 0); - } - if (_entityID_2) { - DAT_EntityState::instance.entityArray[_entityID_2].fireParameter_0xb6 = (short)two; - DAT_EntityState::instance.entityArray[_entityID_2].fireIntensity = (short)fireIntensity; - } - return _entityID_2; + DAT_EntityState::instance.entityArray[fireID].unknownAnimationFrameRelated = 0; + return 0; + } + if (buildingID) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( + DAT_TileMapState::instance.BuildingLayer[tile], playerID, fireIntensity); + } + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x1000U) { + MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID); + } + uint const entityID + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( + 0, playerID, 0, microX, microY, tileHeightMin8, 0, 0, 0, Map::Entities::ET_FIRE, 0); + if (two > 2 && !(DAT_TileMapState::instance.RandomLayer[tile] & 3)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( + 0, playerID, 0, microX, microY, tileHeightMin8, 0, 0, 0, (EntityType)26, 0); } - _buildingID = DAT_EntityState::instance.entityArray[_entityID].fireParameter_0xb6; - DAT_EntityState::instance.entityArray[_entityID].someTracker = 0; - if (_buildingID < two) { - DAT_EntityState::instance.entityArray[_entityID].fireParameter_0xb6 = (short)two; + if (entityID) { + DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = (short)two; + DAT_EntityState::instance.entityArray[entityID].fireIntensity = (short)fireIntensity; } - DAT_EntityState::instance.entityArray[_entityID].unknownAnimationFrameRelated = 0; + return entityID; } - switchD_0040539c_caseD_2d: return 0; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fd8392bc9b..0bc20db334 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -519,7 +519,7 @@ SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending SHC_3BB0A8C1_0x00402BD0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402C50 | 56.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00402C50 | 57.1% | Parameter slots reused for fild temporaries SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) @@ -1623,7 +1623,7 @@ SHC_3BB0A8C1_0x00405125 | 0.0% | Pending SHC_3BB0A8C1_0x00405130 | 100.0% | Reimplemented (counted: only the constant 0x10300131 is shown as an address label in ours) -SHC_3BB0A8C1_0x004052E0 | 66.7% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004052E0 | 71.7% | Operand load order and register allocation SHC_3BB0A8C1_0x004054AC | 0.0% | Pending From d75b72a7a865c27d53c4dd9c05fe495dde0052bb Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:15:54 +0100 Subject: [PATCH 06/51] Entities: reimplement angleToRotationFrameIndex Maps an angle to one of nine rotation frames (0 at <= -50 through 8 at <= 90, with 4 for the middle band and above 90). The original splits on angle > 5 first and shares the return-4 block, which the nested if/else form reproduces. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/angleToRotationFrameIndex.cpp | 44 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp diff --git a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp new file mode 100644 index 0000000000..6bd91cdb7f --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp @@ -0,0 +1,44 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402BD0 + undefined4 EntityState::angleToRotationFrameIndex(int angle) + { + if (angle <= 5) { + if (angle <= -50) { + return 0; + } + if (angle <= -35) { + return 1; + } + if (angle <= -17) { + return 2; + } + if (angle <= -5) { + return 3; + } + } else { + if (angle <= 20) { + return 5; + } + if (angle <= 35) { + return 6; + } + if (angle <= 50) { + return 7; + } + if (angle <= 90) { + return 8; + } + } + return 4; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0bc20db334..4ed6e9c6d4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -517,7 +517,7 @@ SHC_3BB0A8C1_0x00402BC8 | 0.0% | Pending SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending -SHC_3BB0A8C1_0x00402BD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00402C50 | 57.1% | Parameter slots reused for fild temporaries From 55264180ff20c93564a45740d7ed49c716a0f2b2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:15:55 +0100 Subject: [PATCH 07/51] Entities: build updateProjectileHeightAndCollision with /GL The original stores the height it read before angleToRotationFrameIndex again after the call without reloading it (edx survives the call), which takes LTCG with the callee compiled with /GL too. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- cmake/compiler-flags-gl.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 6c541f7d8c..b2ff433662 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -264,3 +264,5 @@ src/OpenSHC/Map/Units/UpdateMinerIronFetcher.cpp src/OpenSHC/Map/Units/UpdateWorker_ConsiderTakingABreakUnk.cpp src/OpenSHC/Map/Units/UnitsState/isWorkplaceBuildingOnAdjacentTile.cpp src/OpenSHC/Map/Units/ConsiderHavingABreakNowUnk.cpp +src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp +src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp From cfcfdfad2f9214e1257c3470086245b4d2d45824 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:15:55 +0100 Subject: [PATCH 08/51] status: updateProjectileHeightAndCollision 100% under /GL Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4ed6e9c6d4..81d2990f7e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2441,7 +2441,7 @@ SHC_3BB0A8C1_0x004081D4 | 0.0% | Pending SHC_3BB0A8C1_0x004081D5 | 0.0% | Pending -SHC_3BB0A8C1_0x004081E0 | 79.5% | edx kept across the call (LTCG) +SHC_3BB0A8C1_0x004081E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00408250 | 100.0% | Reimplemented From 6200da3fb1bd11394334be7746cc40063322ca77 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:22:22 +0100 Subject: [PATCH 09/51] Entities: calculateEntityDrawOffset keeps one variable per axis 24.2 -> 98.0. The sub-tile x and y are each one variable that the orientation arms mirror and scale in place, as in the original, which keeps x in ecx and y in eax throughout. Orientations 2 and 6 mirror one axis and jump into the generic rotated arm's scaling, and orientation 4 mirrors both and falls into orientation 0's; the two labels are kept because the original shares those blocks (a fall-through switch instead compiles to a jump table). Left: the default arm's two scalings are emitted in the opposite order. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/calculateEntityDrawOffset.cpp | 41 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index 7d23e642f1..4114d45b7c 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -11,39 +11,32 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004036F0 void EntityState::calculateEntityDrawOffset(int entityID) { - uint _microYPart; - int _yOffset; - uint _microXPart; - int _xOffset; - _microXPart = (byte)this->entityArray[entityID].microX & 7; - _microYPart = (byte)this->entityArray[entityID].microY & 7; + uint x = (byte)this->entityArray[entityID].microX & 7; + uint y = (byte)this->entityArray[entityID].microY & 7; if (DAT_TileMapState::instance.mapOrientation == 4) { - _microXPart = 7 - _microXPart; - _microYPart = 7 - _microYPart; + x = 7 - x; + y = 7 - y; } else { if (DAT_TileMapState::instance.mapOrientation == 2) { - _xOffset = (7 - _microXPart) * 0x10; - _yOffset = _microYPart * 2; - goto LAB_0040372e; + x = 7 - x; + goto rotate; } if (DAT_TileMapState::instance.mapOrientation == 6) { - _xOffset = _microXPart << 4; - _yOffset = (7 - _microYPart) * 2; - goto LAB_0040372e; + y = 7 - y; + goto rotate; } if (DAT_TileMapState::instance.mapOrientation) { - _xOffset = _microXPart << 4; - _yOffset = _microYPart * 2; - goto LAB_0040372e; + rotate: + x = x << 4; + y = y * 2; + goto lookup; } } - _xOffset = _microXPart * 2; - _yOffset = _microYPart << 4; - LAB_0040372e: - this->entityArray[entityID].x1 - = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset].x; - this->entityArray[entityID].y1 - = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[_yOffset + _xOffset + 1].x; + y = y << 4; + x = x * 2; + lookup: + this->entityArray[entityID].x1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x].x; + this->entityArray[entityID].y1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x + 1].x; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 81d2990f7e..2756fe9b39 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -527,7 +527,7 @@ SHC_3BB0A8C1_0x00402E20 | 8.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00403200 | 0.0% | Pending -SHC_3BB0A8C1_0x004036F0 | 24.2% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004036F0 | 98.0% | Default arm scales x and y in the opposite order SHC_3BB0A8C1_0x00403790 | 100.0% | Pending From 36faa232eb44349649e7691b0236b641111d83dc Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:42:05 +0100 Subject: [PATCH 10/51] Entities: spawnProjectileEntity slot search rebuilt from the asm 70.4 -> 98.2. - Fix: the RNG is advanced for entity IDs from 25 up; Ghidra's `25 < entityID` skipped entity 25 (the original tests `cmp 0x19; jl`). - The three slot searches are plain for loops with the bounds the original tests, and the free-slot fallback (recycle fire/dust entities from slot 25) sits under the switch so the cases that allow it and the default share the one "everyTenTicks = 2999; return 0" exit, as in the original. The `entityType == -1` arm is the else, laid out last. - The original compares currentGameMode before clearing colorUnk and then ignores the result; an if/else storing the same value in both arms reproduces the dead compare (+13 quick_diff points on its own). - The dust-cloud / type-8 rng_1 block is written without gotos, and the tile-walkability checks read DAT_BinaryTileMap400x400 by name, y first. - Field store order hill-climbed against the original. Left: the 1 constant and entityID swap edi/ebp throughout. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/spawnProjectileEntity.cpp | 154 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 69 insertions(+), 87 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp index cccff80249..b3c951615c 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -9,7 +9,9 @@ #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" namespace OpenSHC { @@ -22,41 +24,32 @@ namespace Map { uint EntityState::spawnProjectileEntity(int unitID, undefined4 playerID1, uint ownerColorUnk, int microX, int microY, int totalHeight, int targetX, int targetY, int targetZUnk, EntityType entityType, int param_11) { - bool bVar1; + BOOL bVar1; dword dVar2; - short* psVar3; - EntityTypeShort* pEVar4; uint uVar5; uint uVar6; short sVar7; uint entityID; - bVar1 = false; + bVar1 = FALSE; if (((0x2b < (int)entityType) && ((int)entityType < 0x5b)) || (0x5e < (int)entityType)) { return 0; } - if (entityType == ~Map::Entities::ET_UNKNOWN) { - entityID = 0; - entityType = ((EntityType)8); - } else if (entityType - ((EntityType)0x28) < 8) { - entityID = 1; - psVar3 = &this->entityArray[1].logicalState; - do { - if (*psVar3 == 0) - break; - if (0x17 < (int)entityID) { - return 0; + if (entityType != ~Map::Entities::ET_UNKNOWN) { + if ((uint)(entityType - ((EntityType)0x28)) <= 7) { + for (entityID = 1; (int)entityID < 25; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { + break; + } + if ((int)entityID >= 24) { + return 0; + } } - entityID = entityID + 1; - psVar3 = psVar3 + 0x74; - } while ((int)entityID < 0x19); - } else { - entityID = this->everyTenTicks; - if (this->everyTenTicks < 3000) { - psVar3 = &this->entityArray[this->everyTenTicks].logicalState; - do { - if (*psVar3 == 0) + } else { + for (entityID = this->everyTenTicks; (int)entityID < 3000; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { break; - if (0xbb6 < (int)entityID) { + } + if ((int)entityID >= 2999) { switch (entityType) { case Map::Entities::ET_ARROW_AND_DEFAULT: case Map::Entities::ET_CATAPULT: @@ -79,48 +72,60 @@ namespace Map { case ((EntityType)0x5d): case ((EntityType)0x5e): this->maxEntityCount = 3000; - entityID = 0x19; - pEVar4 = &this->entityArray[0x19].entityType; - break; - default: - goto switchD_00404bac_caseD_5; + for (entityID = 25; (int)entityID < 3000; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { + goto found; + } + switch (this->entityArray[entityID].entityType) { + case Map::Entities::ET_FIRE: + case Map::Entities::ET_DUST_CLOUD: + case ((EntityType)0x1b): + case ((EntityType)0x1e): + case ((EntityType)0x1f): + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + entityID); + goto found; + } + } } - goto LAB_00404bc5; + this->everyTenTicks = 2999; + return 0; } - entityID = entityID + 1; - psVar3 = psVar3 + 0x74; - } while ((int)entityID < 3000); - } - this->everyTenTicks = entityID; - if (this->maxEntityCount <= (int)entityID) { - this->maxEntityCount = entityID + 1; + } + if ((int)entityID >= this->maxEntityCount) { + this->maxEntityCount = entityID + 1; + } + this->everyTenTicks = entityID; } + } else { + entityID = 0; + entityType = ((EntityType)8); } - LAB_00404c16: + found: this->entityArray[entityID].rng_2 = 0; if (entityType == ((EntityType)0x5b)) { - bVar1 = true; + bVar1 = TRUE; this->entityArray[entityID].rng_2 = 1; entityType = Map::Entities::ET_ARROW_AND_DEFAULT; } else if (entityType == Map::Entities::ET_FIREBALLISTA) { - bVar1 = true; + bVar1 = TRUE; this->entityArray[entityID].field_0xd0 = 1; entityType = Map::Entities::ET_BALLISTA; } else { if ((entityType == Map::Entities::ET_FIRETHROWER) || (entityType == Map::Entities::ET_FIRETHROWER_UNTARGETED)) { - bVar1 = true; + bVar1 = TRUE; } if (entityType == ((EntityType)0x5c)) { - bVar1 = true; + bVar1 = TRUE; this->entityArray[entityID].rng_2 = 1; entityType = ((EntityType)0x18); } else if (entityType == ((EntityType)0x5d)) { - bVar1 = true; + bVar1 = TRUE; this->entityArray[entityID].rng_2 = 2; entityType = Map::Entities::ET_ARROW_AND_DEFAULT; } else if (entityType == ((EntityType)0x5e)) { - bVar1 = true; + bVar1 = TRUE; this->entityArray[entityID].rng_2 = 2; entityType = ((EntityType)0x18); } else if (entityType == ((EntityType)0x1b)) { @@ -152,13 +157,13 @@ namespace Map { case ((EntityType)0x5c): case ((EntityType)0x5d): case ((EntityType)0x5e): - uVar5 = microX / 8; uVar6 = microY / 8; + uVar5 = microX / 8; if (((399 < uVar5) || (399 < uVar6)) || (*(char*)(uVar6 * 400 + 0x21aec98 + uVar5) == '\0')) { return 0; } - uVar5 = targetX / 8; uVar6 = targetY / 8; + uVar5 = targetX / 8; if (399 < uVar5) { return 0; } @@ -177,17 +182,17 @@ namespace Map { } dVar2 = DAT_GameCore::instance.mapTimeInTicks; this->entityArray[entityID].unitID_OR_seaGullID = (short)unitID; - this->entityArray[entityID].targetX = (short)targetX; this->entityArray[entityID].targetY = (short)targetY; this->entityArray[entityID].targetZ = (short)targetZUnk; - this->entityArray[entityID].heightDifference = targetZUnk - totalHeight; this->entityArray[entityID].field_0x34 = dVar2; this->entityArray[entityID].unitID = (short)param_11; this->entityArray[entityID].owner = (short)playerID1; this->entityArray[entityID].microX = (short)microX; + this->entityArray[entityID].heightDifference = targetZUnk - totalHeight; this->entityArray[entityID].x_2 = (short)microX; this->entityArray[entityID].logicalState = 1; this->entityArray[entityID].microY = (short)microY; + this->entityArray[entityID].targetX = (short)targetX; this->entityArray[entityID].y_2 = (short)microY; sVar7 = (short)totalHeight; this->entityArray[entityID].height = sVar7; @@ -201,7 +206,11 @@ namespace Map { MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; - this->entityArray[entityID].colorUnk = 0; + if (DAT_GameSynchronyState::instance.currentGameMode != 0) { + this->entityArray[entityID].colorUnk = 0; + } else { + this->entityArray[entityID].colorUnk = 0; + } if ((((entityType == Map::Entities::ET_FLAG_1) || (entityType == Map::Entities::ET_FLAG_4)) || (entityType == Map::Entities::ET_FLAG_2)) || (entityType == Map::Entities::ET_FLAG_3)) { @@ -217,31 +226,25 @@ namespace Map { if (param_11 == 1) { this->entityArray[entityID].unknownAnimationFrameRelated = 200; } - LAB_00404efa: + } + if (entityType == ((EntityType)8)) { + this->entityArray[entityID].rng_1 = DAT_UnitsState::instance.units[unitID].fixedRng; + } else { this->entityArray[entityID].rng_1 = (int)SEC_RNG::instance.currentNumber2; - if (25 < (int)entityID) { + if ((int)entityID >= 25) { MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); } if (entityType == Map::Entities::ET_SEAGULLUnk) { this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 100 + 120; - goto LAB_00404f8c; - } - if (entityType == ((EntityType)0x1f)) { + } else if (entityType == ((EntityType)0x1f)) { if (unitID) { this->entityArray[entityID].unkOne_1 = 2; } - goto LAB_00404f8c; + } else if (entityType == Map::Entities::ET_HEADS_ON_SPIKES) { + this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 500 + 300; + this->entityArray[entityID].rng_1 = ownerColorUnk; } - if (entityType != Map::Entities::ET_HEADS_ON_SPIKES) - goto LAB_00404f8c; - this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 500 + 300; - } else { - if (entityType != ((EntityType)8)) - goto LAB_00404efa; - ownerColorUnk = DAT_UnitsState::instance.units[unitID].fixedRng; } - this->entityArray[entityID].rng_1 = ownerColorUnk; - LAB_00404f8c: MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeProjectileVelocities, this)( entityID, microX, microY, totalHeight, targetX, targetY, targetZUnk); if (this->entityArray[entityID].entityType == ((EntityType)0x18)) { @@ -270,27 +273,6 @@ namespace Map { DAT_CurrentEntityID::instance = uVar5; } return entityID; - LAB_00404bc5: - if (pEVar4[-1] == 0) - goto LAB_00404c16; - switch (*pEVar4) { - case Map::Entities::ET_FIRE: - case Map::Entities::ET_DUST_CLOUD: - case ((EntityType)0x1b): - case ((EntityType)0x1e): - case ((EntityType)0x1f): - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)(entityID); - goto LAB_00404c16; - default: - entityID = entityID + 1; - pEVar4 = pEVar4 + 0x74; - if (2999 < (int)entityID) { - switchD_00404bac_caseD_5: - this->everyTenTicks = 2999; - return 0; - } - } - goto LAB_00404bc5; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2756fe9b39..5fe8ec596f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1183,7 +1183,7 @@ SHC_3BB0A8C1_0x00404A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00404A70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00404AE0 | 70.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00404AE0 | 98.2% | entityID and the constant 1 swap edi/ebp SHC_3BB0A8C1_0x00404B70 | 0.0% | Pending From ddd9175184369c947758712a01ee98c9ab023232 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:50:22 +0100 Subject: [PATCH 11/51] Entities: spawnProjectileImpactDebris rebuilt from the jump tables 78.9 -> 90.5. Ghidra had flattened the per-orientation wall checks into goto chains across shared blocks. Read back from the 13 jump tables, every mirrored orientation does the same thing: mirror the sub-tile x and/or y, and on a diagonal tie let the wall flags (one mask per quadrant) push x or y to 100, or fall back to the straight bounce; then reflect across x when x > y, else across y. The cases now say that directly, in place on x and y as the original keeps them, with the x = 100 arm first (which is what lets MSVC share the arms between cases as the original does) and the straight-bounce case last, reached from the both-walls arms. Left: the reflect-y arm is emitted inside the first case rather than after the straight case, so the two do not share the x_2 store. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../spawnProjectileImpactDebris.cpp | 444 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 214 insertions(+), 232 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp index 8447560994..1fc2975d0b 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -15,325 +15,307 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00405DA0 void EntityState::spawnProjectileImpactDebris(int param_1) { - byte bVar1; - uint microY; - uint microX; - uint uVar2; - int iVar3; - uint uVar4; - int iVar5; - int iVar6; - bool bVar7; - bool bVar8; - bool bVar9; - microY = (uint)this->entityArray[param_1].microY; - microX = (uint)this->entityArray[param_1].microX; - uVar2 = microX & 7; - iVar6 = 0; - iVar3 = 0; - uVar4 = microY & 7; - bVar1 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, DAT_TileMapState::ptr)( - (int)(microX + ((int)microX >> 0x1f & 7U)) >> 3, (int)((int)((microY + (microY >> 0x1f & 7U)) >> 3))); + int const microX = this->entityArray[param_1].microX; + int const microY = this->entityArray[param_1].microY; + int targetX = 0; + int targetY = 0; + int y = microY & 7; + int x = microX & 7; + uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, + DAT_TileMapState::ptr)(microX / 8, microY / 8); switch (this->entityArray[param_1].orientation) { - case 0x3c: - case 0x40: - case 0x44: - case 0x48: - switchD_00405e0c_caseD_3c: - iVar3 = (int)this->entityArray[param_1].y_2; - break; case 0x3d: - uVar4 = 7 - uVar4; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 10) { + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { case 0: case 8: - switchD_00405e31_caseD_0: - uVar4 = 100; + y = 100; break; case 2: - switchD_00405e31_caseD_2: - uVar2 = 100; + x = 100; break; - case 10: - goto switchD_00405e0c_caseD_3c; + case 0xa: + goto straight; } - switchD_00405e31_caseD_4: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = uVar2 == uVar4; } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x3e: - uVar4 = 7 - uVar4; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 10) { + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { case 0: case 8: - goto switchD_00405e31_caseD_0; + y = 100; + break; case 2: - goto switchD_00405e31_caseD_2; - default: - goto switchD_00405e31_caseD_4; - case 10: - goto switchD_00405e0c_caseD_3c; + x = 100; + break; + case 0xa: + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x3f: - uVar4 = 7 - uVar4; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 10) { + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { + case 8: + y = 100; + break; case 0: case 2: - goto switchD_00405e31_caseD_2; - default: - goto switchD_00405e31_caseD_4; - case 8: - goto switchD_00405e31_caseD_0; - case 10: - goto switchD_00405e0c_caseD_3c; + x = 100; + break; + case 0xa: + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x41: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0x82) { + if (x == y) { + switch (wallFlags & 0x82) { case 0: case 2: - switchD_00405ebf_caseD_0: - uVar4 = 100; - default: - switchD_00405ebf_caseD_4: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = uVar2 == uVar4; + y = 100; break; case 0x80: - switchD_00405ebf_caseD_80: - bVar9 = (100 < uVar4); - bVar8 = (int)(100 - uVar4) < 0; - bVar7 = uVar4 == 100; + x = 100; break; case 0x82: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x42: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0x82) { + if (x == y) { + switch (wallFlags & 0x82) { case 0: case 2: - goto switchD_00405ebf_caseD_0; - default: - goto switchD_00405ebf_caseD_4; + y = 100; + break; case 0x80: - goto switchD_00405ebf_caseD_80; + x = 100; + break; case 0x82: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x43: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0x82) { + if (x == y) { + switch (wallFlags & 0x82) { + case 2: + y = 100; + break; case 0: case 0x80: - switchD_00405f23_caseD_0: - uVar2 = 100; - default: - switchD_00405f23_caseD_4: - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = uVar2 == uVar4; - break; - case 2: - switchD_00405f23_caseD_2: - bVar9 = (uVar2 < 100); - bVar8 = (int)(uVar2 - 100) < 0; - bVar7 = uVar2 == 100; + x = 100; break; case 0x82: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x45: - uVar2 = 7 - uVar2; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0xa0) { + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { case 0: case 0x80: - goto switchD_00405ebf_caseD_0; + y = 100; + break; case 0x20: - goto switchD_00405ebf_caseD_80; - default: - goto switchD_00405ebf_caseD_4; + x = 100; + break; case 0xa0: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x46: - uVar2 = 7 - uVar2; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0xa0) { + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { case 0: case 0x80: - goto switchD_00405ebf_caseD_0; + y = 100; + break; case 0x20: - goto switchD_00405ebf_caseD_80; - default: - goto switchD_00405ebf_caseD_4; + x = 100; + break; case 0xa0: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x47: - uVar2 = 7 - uVar2; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0xa0) { + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { + case 0x80: + y = 100; + break; case 0: case 0x20: - goto switchD_00405f23_caseD_0; - default: - goto switchD_00405f23_caseD_4; - case 0x80: - goto switchD_00405f23_caseD_2; + x = 100; + break; case 0xa0: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x49: - iVar3 = -uVar2 + 7; - iVar6 = 7 - uVar4; - bVar9 = (iVar3 < iVar6); - bVar8 = iVar3 - iVar6 < 0; - bVar7 = false; - if (iVar3 == iVar6) { - switch (bVar1 & 0x28) { + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { + case 8: + y = 100; + break; case 0: case 0x20: - iVar3 = 100; - default: - bVar9 = (iVar3 < iVar6); - bVar8 = iVar3 - iVar6 < 0; - bVar7 = iVar3 == iVar6; - break; - case 8: - bVar9 = (iVar3 < 100); - bVar8 = (int)(-uVar2 + -0x5d) < 0; - bVar7 = iVar3 == 100; + x = 100; break; case 0x28: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - LAB_00405e3f: - if (!bVar7 && bVar9 == bVar8) { - iVar3 = (int)this->entityArray[param_1].y_2; - iVar6 = this->entityArray[param_1].microX * 2 - (int)this->entityArray[param_1].x_2; - goto switchD_00405e0c_caseD_10; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } - iVar3 = this->entityArray[param_1].microY * 2 - (int)this->entityArray[param_1].y_2; break; case 0x4a: - uVar2 = 7 - uVar2; - uVar4 = 7 - uVar4; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0x28) { + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { case 0: case 8: - goto switchD_00405e31_caseD_0; - default: - goto switchD_00405e31_caseD_4; + y = 100; + break; case 0x20: - goto switchD_00405e31_caseD_2; + x = 100; + break; case 0x28: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x4b: - uVar2 = 7 - uVar2; - uVar4 = 7 - uVar4; - bVar9 = (uVar2 < uVar4); - bVar8 = (int)(uVar2 - uVar4) < 0; - bVar7 = false; - if (uVar2 == uVar4) { - switch (bVar1 & 0x28) { + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { case 0: case 8: - goto switchD_00405e31_caseD_0; - default: - goto switchD_00405e31_caseD_4; + y = 100; + break; case 0x20: - goto switchD_00405e31_caseD_2; + x = 100; + break; case 0x28: - goto switchD_00405e0c_caseD_3c; + goto straight; } } - goto LAB_00405e3f; - default: - goto switchD_00405e0c_caseD_10; - } - iVar6 = (int)this->entityArray[param_1].x_2; - switchD_00405e0c_caseD_10: - iVar5 = 0; - uVar4 = this->entityArray[param_1].rng_1 & 0x80000007; - if ((int)uVar4 < 0) { - uVar4 = (uVar4 - 1 | 0xfffffff8) + 1; + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + break; } - if (uVar4 != 0xfffffffb && -1 < (int)(uVar4 + 5)) { - do { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, - (int)((int)(microX)), (int)((int)(microY)), (int)((int)(this->entityArray[param_1].height)), - iVar6, iVar3, 8, ((EntityType)0x1b), 0); - iVar5 = iVar5 + 1; - uVar4 = this->entityArray[param_1].rng_1 & 0x80000007; - if ((int)uVar4 < 0) { - uVar4 = (uVar4 - 1 | 0xfffffff8) + 1; - } - } while (iVar5 < (int)(uVar4 + 5)); + for (int i = 0; i < this->entityArray[param_1].rng_1 % 8 + 5; i++) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, microX, microY, + this->entityArray[param_1].height, targetX, targetY, 8, ((EntityType)0x1b), 0); } - iVar3 = (int)this->entityArray[param_1].height; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, - (int)((int)(microX)), (int)((int)(microY)), iVar3, (int)((int)(microX + 1)), (int)((int)(microY + 1)), - iVar3, ((EntityType)0x1e), 0); + int const height = this->entityArray[param_1].height; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( + 0, 0, 0, microX, microY, height, microX + 1, microY + 1, height, ((EntityType)0x1e), 0); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5fe8ec596f..7566cebf4a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1707,7 +1707,7 @@ SHC_3BB0A8C1_0x00405C00 | 0.0% | Pending SHC_3BB0A8C1_0x00405CF0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405DA0 | 78.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00405DA0 | 90.5% | Reflect-y arm laid out in the first case instead of after the straight case SHC_3BB0A8C1_0x0040612C | 0.0% | Pending From 196f701ef83e248bab56de3af2863a0c22cbfa4c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:02:21 +0100 Subject: [PATCH 12/51] types: Entity::speedUnk is a float Every access in the original is an x87 float op on it: moveProjectileEntity loads it with `fld dword` and accumulates it with `fadd`/`fstp`, updateEntities compares it with `fcomp dword`, and the two initialisers clear it with `fldz`/`fstp`. As an int, moveProjectileEntity's `speedUnk = (int)(accum + speed)` truncated the accumulated speed every tick, which the game never does. The casts that bridged the wrong type are dropped. moveProjectileEntity 50.4 -> 58.8, updateEntities 56.4 -> 57.1, initializeProjectileVelocities 36.5 -> 37.2. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/Entity.hpp | 2 +- .../Map/Entities/EntityState/moveProjectileEntity.cpp | 6 +++--- src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/Entities/Entity.hpp b/src/OpenSHC/Map/Entities/Entity.hpp index cfe58c5016..1cc724aedc 100644 --- a/src/OpenSHC/Map/Entities/Entity.hpp +++ b/src/OpenSHC/Map/Entities/Entity.hpp @@ -72,7 +72,7 @@ namespace Map { short pathError; // 0x00000072 length: 2 short pathAxisCase; // 0x00000074 length: 2 byte unused_0x76[2]; // 0x00000076 length: 2 - int speedUnk; // 0x00000078 length: 4 + float speedUnk; // 0x00000078 length: 4 float vCos; // 0x0000007C length: 4 float vSin; // 0x00000080 length: 4 short travelledDistance; // 0x00000084 length: 2 diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp index f26aea54e4..b9074286b4 100644 --- a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -53,7 +53,7 @@ namespace Map { int _entityID; float _speed_2; _entityID = entityID; - _speed = (float)this->entityArray[entityID].speedUnk; + _speed = this->entityArray[entityID].speedUnk; _vCos = this->entityArray[entityID].vCos; _vSin = (double)this->entityArray[entityID].vSin; _height = (int)this->entityArray[entityID].height - (int)this->entityArray[entityID].startingHeight; @@ -83,10 +83,10 @@ namespace Map { } iVar6 = (long)(fVar7); _accum_2 = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; - _speed_2 = (float)this->entityArray[entityID].speedUnk; + _speed_2 = this->entityArray[entityID].speedUnk; this->entityArray[entityID].graphicRotationUnk = (word)iVar6; iVar6 = _dx - this->entityArray[entityID].travelledDistance; - this->entityArray[entityID].speedUnk = (int)(_accum_2 + _speed_2); + this->entityArray[entityID].speedUnk = _accum_2 + _speed_2; if (iVar6) { local_10 = (iVar5 - _height) / iVar6; } diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index fd937b11b3..ef035b4c43 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -107,7 +107,7 @@ namespace Map { if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { *psVar4 = *psVar4 + 0x10; } - if ((((float)this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0) + if (((this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0) && (_gmLookupValue = this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue, _gmLookupValue != 0)) && (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0)) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7566cebf4a..58c58778b4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 36.5% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00403A20 | 37.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00403FF0 | 74.9% | Ported from gynt, asm differs @@ -2449,11 +2449,11 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 50.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004084A0 | 58.8% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00408770 | 0.0% | Pending -SHC_3BB0A8C1_0x004087C0 | 56.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004087C0 | 57.1% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00408D90 | 0.0% | Pending From f1dbf633524ed864aae69eacdc97db916165faf9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:02:22 +0100 Subject: [PATCH 13/51] Entities: handleProjectileWallBounce rebuilt from the jump tables 74.9 -> 88.2. - The wall-reflection switch is the same one spawnProjectileImpactDebris has (same 13 tables, same shared arms), written the same way. - Fix: the tile passed to the wall-flag lookup is microX / 8 divided signed, as the original does (cdq/sar); it was divided unsigned. - microX/microY are read once as ints instead of being kept twice, as a short and as an int. - someMicroX/Y are `cond ? 1 : -1`, the original's setle/lea pair. - The axis classification is an else-if chain whose first test is `deltaX == 0 && deltaY == 0`, as the original's re-test shows. - The bounce tail gives each value its own local, and reads the velocity field back after storing it, so the stored value is reused for both trig products as in the original rather than one converted double kept across the cos call. Left: the axis chain, where the original re-tests deltaX and reloads deltaY that we keep in registers, and the reflect-y arm's placement. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../handleProjectileWallBounce.cpp | 514 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 248 insertions(+), 268 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp index 1c4b3dd2fd..a89269d88b 100644 --- a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -21,390 +21,370 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00403FF0 void EntityState::handleProjectileWallBounce(int param_1) { - word wVar1; - byte _bitFlag; - uint y; - undefined4 uVar2; - uint x; - uint uVar3; short sVar4; int iVar5; - uint uVar6; short sVar7; short sVar8; int iVar9; - bool bVar10; - bool bVar11; - bool bVar12; - double fVar13; - double fVar14; - sVar4 = this->entityArray[param_1].microY; - y = (uint)sVar4; - sVar8 = this->entityArray[param_1].microX; - x = (uint)sVar8; - uVar3 = x & 7; + int const microY = this->entityArray[param_1].microY; + int const microX = this->entityArray[param_1].microX; + int subX = microX & 7; iVar5 = 0; iVar9 = 0; - uVar6 = y & 7; - _bitFlag = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, - DAT_TileMapState::ptr)(x / 8, (int)((int)(y / 8))); + int subY = microY & 7; + uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, + DAT_TileMapState::ptr)(microX / 8, microY / 8); switch (this->entityArray[param_1].orientation) { - case 0x3c: - case 0x40: - case 0x44: - case 0x48: - switchD_0040405c_caseD_3c: - iVar9 = (int)this->entityArray[param_1].y_2; - LAB_004042e5: - iVar5 = (int)this->entityArray[param_1].x_2; - break; case 0x3d: - uVar6 = 7 - uVar6; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 10) { + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { case 0: case 8: - switchD_00404081_caseD_0: - uVar6 = 100; + subY = 100; break; case 2: - switchD_00404081_caseD_2: - uVar3 = 100; + subX = 100; break; - case 10: - goto switchD_0040405c_caseD_3c; + case 0xa: + goto straight; } - switchD_00404081_caseD_4: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = uVar3 == uVar6; } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x3e: - uVar6 = 7 - uVar6; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 10) { + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { case 0: case 8: - goto switchD_00404081_caseD_0; + subY = 100; + break; case 2: - goto switchD_00404081_caseD_2; - default: - goto switchD_00404081_caseD_4; - case 10: - goto switchD_0040405c_caseD_3c; + subX = 100; + break; + case 0xa: + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x3f: - uVar6 = 7 - uVar6; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 10) { + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { + case 8: + subY = 100; + break; case 0: case 2: - goto switchD_00404081_caseD_2; - default: - goto switchD_00404081_caseD_4; - case 8: - goto switchD_00404081_caseD_0; - case 10: - goto switchD_0040405c_caseD_3c; + subX = 100; + break; + case 0xa: + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x41: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0x82) { + if (subX == subY) { + switch (wallFlags & 0x82) { case 0: case 2: - switchD_0040410f_caseD_0: - uVar6 = 100; - default: - switchD_0040410f_caseD_4: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = uVar3 == uVar6; + subY = 100; break; case 0x80: - switchD_0040410f_caseD_80: - bVar12 = (100 < uVar6); - bVar11 = (int)(100 - uVar6) < 0; - bVar10 = uVar6 == 100; + subX = 100; break; case 0x82: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x42: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0x82) { + if (subX == subY) { + switch (wallFlags & 0x82) { case 0: case 2: - goto switchD_0040410f_caseD_0; - default: - goto switchD_0040410f_caseD_4; + subY = 100; + break; case 0x80: - goto switchD_0040410f_caseD_80; + subX = 100; + break; case 0x82: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x43: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0x82) { + if (subX == subY) { + switch (wallFlags & 0x82) { + case 2: + subY = 100; + break; case 0: case 0x80: - switchD_00404173_caseD_0: - uVar3 = 100; - default: - switchD_00404173_caseD_4: - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = uVar3 == uVar6; - break; - case 2: - switchD_00404173_caseD_2: - bVar12 = (uVar3 < 100); - bVar11 = (int)(uVar3 - 100) < 0; - bVar10 = uVar3 == 100; + subX = 100; break; case 0x82: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x45: - uVar3 = 7 - uVar3; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0xa0) { + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { case 0: case 0x80: - goto switchD_0040410f_caseD_0; + subY = 100; + break; case 0x20: - goto switchD_0040410f_caseD_80; - default: - goto switchD_0040410f_caseD_4; + subX = 100; + break; case 0xa0: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x46: - uVar3 = 7 - uVar3; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0xa0) { + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { case 0: case 0x80: - goto switchD_0040410f_caseD_0; + subY = 100; + break; case 0x20: - goto switchD_0040410f_caseD_80; - default: - goto switchD_0040410f_caseD_4; + subX = 100; + break; case 0xa0: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x47: - uVar3 = 7 - uVar3; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0xa0) { + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { + case 0x80: + subY = 100; + break; case 0: case 0x20: - goto switchD_00404173_caseD_0; - default: - goto switchD_00404173_caseD_4; - case 0x80: - goto switchD_00404173_caseD_2; + subX = 100; + break; case 0xa0: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x49: - iVar5 = -uVar3 + 7; - iVar9 = 7 - uVar6; - bVar12 = (iVar5 < iVar9); - bVar11 = iVar5 - iVar9 < 0; - bVar10 = false; - if (iVar5 == iVar9) { - switch (_bitFlag & 0x28) { + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { + case 8: + subY = 100; + break; case 0: case 0x20: - iVar5 = 100; - default: - bVar12 = (iVar5 < iVar9); - bVar11 = iVar5 - iVar9 < 0; - bVar10 = iVar5 == iVar9; - break; - case 8: - bVar12 = (iVar5 < 100); - bVar11 = (int)(-uVar3 + -0x5d) < 0; - bVar10 = iVar5 == 100; + subX = 100; break; case 0x28: - goto switchD_0040405c_caseD_3c; + goto straight; } } - LAB_0040408f: - if (bVar10 || bVar12 != bVar11) { - iVar9 = this->entityArray[param_1].microY * 2 - (int)this->entityArray[param_1].y_2; - goto LAB_004042e5; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } - iVar9 = (int)this->entityArray[param_1].y_2; - iVar5 = this->entityArray[param_1].microX * 2 - (int)this->entityArray[param_1].x_2; break; case 0x4a: - uVar3 = 7 - uVar3; - uVar6 = 7 - uVar6; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0x28) { + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { case 0: case 8: - goto switchD_00404081_caseD_0; - default: - goto switchD_00404081_caseD_4; + subY = 100; + break; case 0x20: - goto switchD_00404081_caseD_2; + subX = 100; + break; case 0x28: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; case 0x4b: - uVar3 = 7 - uVar3; - uVar6 = 7 - uVar6; - bVar12 = (uVar3 < uVar6); - bVar11 = (int)(uVar3 - uVar6) < 0; - bVar10 = false; - if (uVar3 == uVar6) { - switch (_bitFlag & 0x28) { + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { case 0: case 8: - goto switchD_00404081_caseD_0; - default: - goto switchD_00404081_caseD_4; + subY = 100; + break; case 0x20: - goto switchD_00404081_caseD_2; + subX = 100; + break; case 0x28: - goto switchD_0040405c_caseD_3c; + goto straight; } } - goto LAB_0040408f; - default: + if (subX > subY) { + iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; + } else { + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + iVar5 = this->entityArray[param_1].x_2; + iVar9 = this->entityArray[param_1].y_2; break; } MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, - DAT_DirectionAlgorithmState::ptr)(x, (int)((int)(y)), iVar5, iVar9); + DAT_DirectionAlgorithmState::ptr)(microX, microY, iVar5, iVar9); this->entityArray[param_1].orientation = DAT_DirectionAlgorithmState::instance.orientation; - sVar7 = (short)iVar9; - if (iVar9 < (int)y) { - this->entityArray[param_1].pathDeltaY = sVar4 - sVar7; + if (microY > iVar9) { + this->entityArray[param_1].pathDeltaY = (short)(microY - iVar9); } else { - this->entityArray[param_1].pathDeltaY = sVar7 - sVar4; + this->entityArray[param_1].pathDeltaY = (short)(iVar9 - microY); } - sVar4 = (short)iVar5; - if (iVar5 < (int)x) { - this->entityArray[param_1].pathDeltaX = sVar8 - sVar4; + if (microX > iVar5) { + this->entityArray[param_1].pathDeltaX = (short)(microX - iVar5); } else { - this->entityArray[param_1].pathDeltaX = sVar4 - sVar8; + this->entityArray[param_1].pathDeltaX = (short)(iVar5 - microX); } sVar8 = this->entityArray[param_1].pathDeltaX; - this->entityArray[param_1].pathTargetX = sVar4; - this->entityArray[param_1].someMicroX = (ushort)((int)x <= iVar5) * 2 + -1; - this->entityArray[param_1].pathTargetY = sVar7; - this->entityArray[param_1].someMicroY = (ushort)((int)y <= iVar9) * 2 + -1; - if (!sVar8) { - if (this->entityArray[param_1].pathDeltaY == 0) { - this->entityArray[param_1].pathAxisCase = 0; - } else { - this->entityArray[param_1].pathAxisCase = 1; - } + this->entityArray[param_1].pathTargetX = (short)iVar5; + this->entityArray[param_1].someMicroX = microX <= iVar5 ? 1 : -1; + this->entityArray[param_1].pathTargetY = (short)iVar9; + this->entityArray[param_1].someMicroY = microY <= iVar9 ? 1 : -1; + if (sVar8 == 0 && this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathAxisCase = 0; + } else if (sVar8 == 0) { + this->entityArray[param_1].pathAxisCase = 1; + } else if (this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathAxisCase = 2; + } else if (this->entityArray[param_1].pathDeltaY > sVar8) { + this->entityArray[param_1].pathAxisCase = 3; } else { - sVar4 = this->entityArray[param_1].pathDeltaY; - if (!sVar4) { - this->entityArray[param_1].pathAxisCase = 2; - } else if (sVar8 < sVar4) { - this->entityArray[param_1].pathAxisCase = 3; - } else { - this->entityArray[param_1].pathAxisCase = 4; - } + this->entityArray[param_1].pathAxisCase = 4; } sVar4 = this->entityArray[param_1].pathAxisCase; if (sVar4 == 3) { - sVar4 = this->entityArray[param_1].pathDeltaY; - sVar8 = sVar8 * 2; - this->entityArray[param_1].pathErrorStepStraight = sVar8; - sVar7 = sVar8 + sVar4 * -2; - this->entityArray[param_1].pathError = sVar8 - sVar4; + int const deltaY = this->entityArray[param_1].pathDeltaY; + int const straight = sVar8 * 2; + this->entityArray[param_1].pathErrorStepStraight = straight; + sVar7 = straight - deltaY * 2; + this->entityArray[param_1].pathError = straight - deltaY; } else { if (sVar4 != 4) goto LAB_0040440f; - sVar4 = this->entityArray[param_1].pathDeltaY * 2; - this->entityArray[param_1].pathErrorStepStraight = sVar4; - sVar7 = sVar4 + sVar8 * -2; - this->entityArray[param_1].pathError = sVar4 - sVar8; + int const straight = this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathErrorStepStraight = straight; + sVar7 = straight - sVar8 * 2; + this->entityArray[param_1].pathError = straight - sVar8; } this->entityArray[param_1].pathErrorStepDiagonal = sVar7; LAB_0040440f: - wVar1 = this->entityArray[param_1].graphicRotationUnk; - this->entityArray[param_1].startingAngle = wVar1; - if ((short)wVar1 < -0x50) { - this->entityArray[param_1].startingAngle = -0x50; + word const rotation = this->entityArray[param_1].graphicRotationUnk; + this->entityArray[param_1].startingAngle = rotation; + if ((short)rotation < -80) { + this->entityArray[param_1].startingAngle = -80; } - iVar9 = (int)this->entityArray[param_1].startingAngle; + int const angle = this->entityArray[param_1].startingAngle; this->entityArray[param_1].speedUnk = 0; - iVar5 = (int)this->entityArray[param_1].velocityUnk; - fVar13 = ((double)iVar9 * (double)3.1415926535) / (double)180.0; - sVar4 = this->entityArray[param_1].height; - sVar8 = (short)(iVar5 / 8); - this->entityArray[param_1].velocityUnk = sVar8; - this->entityArray[param_1].startingHeight = sVar4; + double const radians = angle * 3.1415926535 / 180.0; + short const velocity = (short)(this->entityArray[param_1].velocityUnk / 8); + this->entityArray[param_1].velocityUnk = velocity; + this->entityArray[param_1].startingHeight = this->entityArray[param_1].height; this->entityArray[param_1].travelledDistance = 0; - fVar14 = cos(fVar13); - this->entityArray[param_1].vCos = (float)((double)(int)sVar8 * fVar14); - fVar13 = sin((double)fVar13); - this->entityArray[param_1].vSin = (float)((double)(int)sVar8 * fVar13); - uVar2 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar9); - sVar4 = this->entityArray[param_1].xPosition; - this->entityArray[param_1].rotationFrameIndex = (short)uVar2; - sVar8 = this->entityArray[param_1].yPosition; + this->entityArray[param_1].vCos = (float)(this->entityArray[param_1].velocityUnk * cos(radians)); + this->entityArray[param_1].vSin = (float)(this->entityArray[param_1].velocityUnk * sin(radians)); + this->entityArray[param_1].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); this->entityArray[param_1].gmLookupValue = 0; MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)sVar4, (int)((int)(sVar8)), DE::SHCDE::FX_ARROW_BOUNCE); - return; + this->entityArray[param_1].xPosition, this->entityArray[param_1].yPosition, DE::SHCDE::FX_ARROW_BOUNCE); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 58c58778b4..01a99a9f6a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -545,7 +545,7 @@ SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403A20 | 37.2% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x00403FF0 | 74.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00403FF0 | 88.2% | Axis chain keeps deltaX/deltaY in registers the original re-tests and reloads SHC_3BB0A8C1_0x004044E4 | 0.0% | Pending From ec832fddb2ea8f2f700c5e8e571a147c572838af Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:14:02 +0100 Subject: [PATCH 14/51] Entities: initializeProjectileVelocities path setup as the original 37.2 -> 62.1. The path setup is the same block handleProjectileWallBounce has, and gets the same treatment: - The three delta comparisons are written in the original's operand order (`y > targetY`, `x > targetX`, `height >= targetZ`), and so is the case-2 height test. - someMicroX/Y are `cond ? 1 : -1` (setle/lea). - The axis classification is the else-if chain led by `deltaX == 0 && deltaY == 0`. - The axis-case 3/4 error steps compute the doubled straight step once in a local and read the other delta from its field, without the label the decompiler shared the pathError store through. Left: allocation in the path setup (deltaX is spilled), and the curve dispatch's register assignment. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../initializeProjectileVelocities.cpp | 85 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index 5c873ab29d..9f00c9b8e0 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -30,62 +30,51 @@ namespace Map { int iVar11; double fVar12; double fVar13; - sVar5 = (short)targetY; - if (targetY < y) { - this->entityArray[entityID].pathDeltaY = (short)y - sVar5; + if (y > targetY) { + this->entityArray[entityID].pathDeltaY = y - targetY; } else { - this->entityArray[entityID].pathDeltaY = sVar5 - (short)y; + this->entityArray[entityID].pathDeltaY = targetY - y; } - sVar10 = (short)targetX; - if (targetX < x) { - sVar9 = (short)x - sVar10; + if (x > targetX) { + sVar9 = x - targetX; } else { - sVar9 = sVar10 - (short)x; + sVar9 = targetX - x; } - sVar2 = this->entityArray[entityID].targetZ; this->entityArray[entityID].pathDeltaX = sVar9; - sVar9 = this->entityArray[entityID].height; - if (sVar9 < sVar2) { - this->entityArray[entityID].pathDeltaZ = sVar2 - sVar9; + if (this->entityArray[entityID].height >= this->entityArray[entityID].targetZ) { + this->entityArray[entityID].pathDeltaZ + = this->entityArray[entityID].height - this->entityArray[entityID].targetZ; } else { - this->entityArray[entityID].pathDeltaZ = sVar9 - sVar2; + this->entityArray[entityID].pathDeltaZ + = this->entityArray[entityID].targetZ - this->entityArray[entityID].height; } sVar9 = this->entityArray[entityID].pathDeltaX; - this->entityArray[entityID].pathTargetX = sVar10; - this->entityArray[entityID].pathTargetY = sVar5; - this->entityArray[entityID].someMicroX = (ushort)(x <= targetX) * 2 + -1; - this->entityArray[entityID].someMicroY = (ushort)(y <= targetY) * 2 + -1; - if (!sVar9) { - if (this->entityArray[entityID].pathDeltaY == 0) { - this->entityArray[entityID].pathAxisCase = 0; - } else { - this->entityArray[entityID].pathAxisCase = 1; - } + this->entityArray[entityID].pathTargetX = (short)targetX; + this->entityArray[entityID].pathTargetY = (short)targetY; + this->entityArray[entityID].someMicroX = x <= targetX ? 1 : -1; + this->entityArray[entityID].someMicroY = y <= targetY ? 1 : -1; + if (sVar9 == 0 && this->entityArray[entityID].pathDeltaY == 0) { + this->entityArray[entityID].pathAxisCase = 0; + } else if (sVar9 == 0) { + this->entityArray[entityID].pathAxisCase = 1; + } else if (this->entityArray[entityID].pathDeltaY == 0) { + this->entityArray[entityID].pathAxisCase = 2; + } else if (this->entityArray[entityID].pathDeltaY > sVar9) { + this->entityArray[entityID].pathAxisCase = 3; } else { - sVar5 = this->entityArray[entityID].pathDeltaY; - if (!sVar5) { - this->entityArray[entityID].pathAxisCase = 2; - } else if (sVar9 < sVar5) { - this->entityArray[entityID].pathAxisCase = 3; - } else { - this->entityArray[entityID].pathAxisCase = 4; - } + this->entityArray[entityID].pathAxisCase = 4; } - sVar5 = this->entityArray[entityID].pathAxisCase; - if (sVar5 == 3) { - sVar10 = sVar9 * 2; - sVar9 = this->entityArray[entityID].pathDeltaY; - this->entityArray[entityID].pathErrorStepStraight = sVar10; - sVar5 = this->entityArray[entityID].pathDeltaY; - this->entityArray[entityID].pathErrorStepDiagonal = sVar10 + sVar9 * -2; - LAB_00403b64: - this->entityArray[entityID].pathError = sVar10 - sVar5; - } else if (sVar5 == 4) { - sVar10 = this->entityArray[entityID].pathDeltaY * 2; - this->entityArray[entityID].pathErrorStepStraight = sVar10; - sVar5 = this->entityArray[entityID].pathDeltaX; - this->entityArray[entityID].pathErrorStepDiagonal = sVar10 + sVar9 * -2; - goto LAB_00403b64; + if (this->entityArray[entityID].pathAxisCase == 3) { + short const straight = sVar9 * 2; + this->entityArray[entityID].pathErrorStepStraight = straight; + this->entityArray[entityID].pathErrorStepDiagonal + = straight - this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathError = straight - this->entityArray[entityID].pathDeltaY; + } else if (this->entityArray[entityID].pathAxisCase == 4) { + short const straight = this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathErrorStepStraight = straight; + this->entityArray[entityID].pathErrorStepDiagonal = straight - sVar9 * 2; + this->entityArray[entityID].pathError = straight - this->entityArray[entityID].pathDeltaX; } iVar7 = DAT_EntityDefinedData::instance .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType]; @@ -115,13 +104,11 @@ namespace Map { if (iVar7 == 2) { uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( x, y, height, targetX, targetY, targetZ, 1); - sVar5 = this->entityArray[entityID].height; - sVar10 = this->entityArray[entityID].targetZ; sVar9 = (short)uVar6; this->entityArray[entityID].field_0x94 = sVar9; this->entityArray[entityID].totalFlightDistance = sVar9; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - if (sVar10 < sVar5) { + if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { this->entityArray[entityID].startingAngle = 3; } iVar7 = this->entityArray[entityID].heightDifference; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 01a99a9f6a..39dc842e62 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 37.2% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00403A20 | 62.1% | deltaX spilled in the path setup; curve dispatch register assignment SHC_3BB0A8C1_0x00403FF0 | 88.2% | Axis chain keeps deltaX/deltaY in registers the original re-tests and reloads From 569841e81bd00308417e0fdb6f0e1ce3ecaa306f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:32:53 +0100 Subject: [PATCH 15/51] Entities: computeLineOfSightDistance rebuilt from the asm 8.2 -> 29.6. The decompiled body was rewritten from the original instruction stream: - One `clearance` counter (the original keeps it in a register in three branches and in a stack slot in the y-major one, which is what made Ghidra show two variables), clamped to 28 only for the straight cases. - `clear` and `blocked` are dword BOOLs, `building` an int read from the start tile, `lastHeight` one variable shared by the prescans and the walks. - The four walks (vertical, y-major, x-major, horizontal) are plain counted loops with the original's operand orders: `y > targetY`, `height > targetHeight + 54`, `dY > dX`, `abs(cur - start)`, and the LogicLayer value read once for both flag tests. - The prescans are `for (i = 1; i < n; i++)` over the rows/columns next to the target. Left: block layout. The original places the part of the first three walks after their first if/else at the end of the function, behind the horizontal walk; no source form tried (loop forms, branch orders, arm orders) reproduces that. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../computeLineOfSightDistance.cpp | 500 +++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 195 insertions(+), 307 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index 76b6fcc378..4056c931f4 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -6,6 +6,8 @@ #include "OpenSHC/Globals/DAT_TileMapState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include + namespace OpenSHC { namespace Map { namespace Entities { @@ -14,360 +16,246 @@ namespace Map { uint EntityState::computeLineOfSightDistance( int x, int y, int height, int targetX, int targetY, int targetHeight, int param_7) { - int iVar1; - int iVar2; - short sVar3; - bool bVar4; - bool bVar5; - int iVar6; - int iVar7; - uint uVar8; - int iVar9; - int iVar10; - int iVar11; - uint uVar12; - int iVar13; - int iVar14; - int* piVar15; - uint local_44; - uint local_40; - int local_3c; - int local_38; - uint local_30; - int local_1c; - iVar9 = y; - local_1c = -1; - uVar12 = 0; - local_44 = 100000; - local_30 = 0; - local_40 = 0; - bVar4 = true; - bVar5 = false; - if (targetHeight + 0x36 < height) { - uVar12 = 100; - local_40 = 100; + int lastTile = -1; + int building = -1; + int steps = 100000; + int lastHeight = 0; + int clearance = 0; + BOOL clear = TRUE; + BOOL blocked = FALSE; + if (height > targetHeight + 54) { + clearance = 100; } - iVar6 = (int)(y + (y >> 0x1f & 7U)) >> 3; - iVar10 = (int)((x >> 0x1f & 7U) + x) >> 3; - iVar7 = DAT_ViewportRenderState::instance.translationMatrix[iVar6].addXgetTile + iVar10; - local_3c = x; - local_38 = y; - if ((DAT_TileMapState::instance.LogicLayer[iVar7] & 0x10000000U)) { + int const tileY = y / 8; + int const tileX = x / 8; + int const startTile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX; + int curX = x; + int curY = y; + if (DAT_TileMapState::instance.LogicLayer[startTile] & 0x10000000) { height = height + 10; } - sVar3 = -1; - if (DAT_TileMapState::instance.BuildingLayer[iVar7] != 0) { - sVar3 = DAT_TileMapState::instance.BuildingLayer[iVar7]; + if (DAT_TileMapState::instance.BuildingLayer[startTile] != 0) { + building = DAT_TileMapState::instance.BuildingLayer[startTile]; } - if (targetY < y) { - iVar7 = y - targetY; + int dY; + if (y > targetY) { + dY = y - targetY; } else { - iVar7 = targetY - y; + dY = targetY - y; } - if (targetX < x) { - iVar11 = x - targetX; + int dX; + if (x > targetX) { + dX = x - targetX; } else { - iVar11 = targetX - x; + dX = targetX - x; } - iVar1 = (uint)(x <= targetX) * 2 + -1; - iVar2 = (uint)(y <= targetY) * 2 + -1; - if (!iVar11) { - if (iVar7) { - if (0x1b < uVar12) { - uVar12 = 0x1c; + int const stepX = x <= targetX ? 1 : -1; + int const stepY = y <= targetY ? 1 : -1; + if (dX == 0) { + if (dY != 0) { + if (clearance >= 28) { + clearance = 28; } - uVar8 = 0; - local_40 = uVar12 / 2; - local_44 = 0; - iVar9 = -1; - this->lineOfSightClearanceSteps = uVar12; - do { - local_38 = local_38 + iVar2; - iVar6 = iVar9; - if (((local_44 & 1)) && (!param_7)) { - iVar6 = DAT_ViewportRenderState::instance - .translationMatrix[(int)(local_38 + (local_38 >> 0x1f & 7U)) >> 3] - .addXgetTile - + iVar10; - if (!(DAT_TileMapState::instance.LogicLayer[iVar6] & 0x400300U)) { - bVar4 = false; - this->lineOfSightClearanceSteps = local_44; + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if ((steps & 1) && param_7 == 0) { + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile + tileX; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; } - if (!local_40) { - if (iVar9 == iVar6) { - if (bVar5) { - uVar12 = local_38 - y >> 0x1f; - iVar9 = ((local_38 - y ^ uVar12) - uVar12) * (targetHeight - height); - goto LAB_004033cf; - } - } else { - bVar5 = false; - if (((char)DAT_TileMapState::instance.LogicLayer[iVar6] < '\0') - || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar6] - && ((!bVar4 - || (!(DAT_TileMapState::instance.LogicLayer[iVar6] & 0x400200U))))))) { - bVar5 = true; - uVar8 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar6, 1); - uVar12 = local_38 - y >> 0x1f; - iVar9 = ((local_38 - y ^ uVar12) - uVar12) * (targetHeight - height); - LAB_004033cf: - if (iVar9 / iVar7 + height < (int)uVar8) { - return 0; - } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((char)flags < 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; } } - } else { - local_40 = local_40 - 1; + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; } + lastTile = tile; } - if ((x == targetX) && (local_38 == targetY)) { - return local_44; - } - local_44 = local_44 + 1; - iVar9 = iVar6; - if (999 < (int)local_44) { - return local_44; + if (x == targetX && curY == targetY) { + break; } - } while (true); + } } - } else { - if (!iVar7) { - if (0x1b < uVar12) { - uVar12 = 0x1c; + } else if (dY != 0) { + if (dY > dX) { + int const twoDX = dX * 2; + int error = twoDX - dY; + int const diagStep = twoDX - dY * 2; + if (height > targetHeight && clearance != 0) { + int n = abs(targetY - y) / 8 - 1; + if (n > 4) { + n = 4; + } + for (int i = 1; i < n; i++) { + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( + DAT_ViewportRenderState::instance.translationMatrix[targetY / 8 - stepY * i].addXgetTile + + targetX / 8, + 1); + if (lastHeight > targetHeight) { + clearance = 28; + } + } } - uVar8 = uVar12 / 2; - local_44 = 0; - this->lineOfSightClearanceSteps = uVar12; - while (true) { - local_3c = local_3c + iVar1; - if (((local_44 & 1)) && (!param_7)) { - iVar9 = ((int)(local_3c + (local_3c >> 0x1f & 7U)) >> 3) - + DAT_ViewportRenderState::instance.translationMatrix[iVar6].addXgetTile; - if (!(DAT_TileMapState::instance.LogicLayer[iVar9] & 0x400300U)) { - bVar4 = false; - this->lineOfSightClearanceSteps = local_44; + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if (error > 0) { + curX += stepX; + error += diagStep; + } else { + error += twoDX; + } + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; } - if (!uVar8) { - if (local_1c == iVar9) { - local_1c = iVar9; - if ((bVar5) - && (uVar12 = local_3c - x >> 0x1f, - (int)(((local_3c - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 - + height - < (int)local_30)) { + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((char)flags < 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { return 0; } - } else { - bVar5 = false; - if (((char)DAT_TileMapState::instance.LogicLayer[iVar9] < '\0') - || ((local_1c = iVar9, - sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar9] - && ((!bVar4 - || (!(DAT_TileMapState::instance.LogicLayer[iVar9] - & 0x400200U))))))) { - bVar5 = true; - local_30 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar9, 1); - uVar12 = local_3c - x >> 0x1f; - local_1c = iVar9; - if ((int)(((local_3c - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 - + height - < (int)local_30) { - return 0; - } - } } - } else { - uVar8 = uVar8 - 1; - local_1c = iVar9; + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; } + lastTile = tile; } - if ((local_3c == targetX) && (y == targetY)) + if (curX == targetX && curY == targetY) { break; - local_44 = local_44 + 1; - if (999 < (int)local_44) { - return local_44; } } - return local_44; - } - if (iVar7 <= iVar11) { - iVar7 = iVar7 * 2; - iVar6 = iVar7 - iVar11; - if ((targetHeight < height) && (uVar12)) { - uVar8 = targetX - x >> 0x1f; - iVar10 = (targetX - x ^ uVar8) - uVar8; - iVar10 = ((int)(iVar10 + (iVar10 >> 0x1f & 7U)) >> 3) + -1; - if (4 < iVar10) { - iVar10 = 4; + } else { + int const twoDY = dY * 2; + int const diagStep = twoDY - dX * 2; + int error = twoDY - dX; + if (height > targetHeight && clearance != 0) { + int n = abs(targetX - x) / 8 - 1; + if (n > 4) { + n = 4; } - if (1 < iVar10) { - y = iVar10 + -1; - iVar10 = iVar1; - do { - local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)((((int)(targetX + (targetX >> 0x1f & 7U)) >> 3) - iVar10) - + DAT_ViewportRenderState::instance - .translationMatrix[(int)(targetY + (targetY >> 0x1f & 7U)) >> 3] - .addXgetTile, - 1); - if (targetHeight < (int)local_30) { - uVar12 = 0x1c; - } - iVar10 = iVar10 + iVar1; - y = y + -1; - } while (y); + for (int i = 1; i < n; i++) { + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(targetX / 8 - stepX * i + + DAT_ViewportRenderState::instance.translationMatrix[targetY / 8].addXgetTile, + 1); + if (lastHeight > targetHeight) { + clearance = 28; + } } } - local_40 = uVar12 / 2; - local_44 = 0; - iVar10 = x; - iVar14 = -1; - this->lineOfSightClearanceSteps = uVar12; - while (true) { - iVar10 = iVar10 + iVar1; - iVar13 = iVar7; - if (0 < iVar6) { - iVar9 = iVar9 + iVar2; - iVar13 = iVar7 + iVar11 * -2; - local_38 = iVar9; + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + for (steps = 0; steps < 1000; steps++) { + curX += stepX; + if (error > 0) { + curY += stepY; + error += diagStep; + } else { + error += twoDY; } - iVar6 = iVar6 + iVar13; - iVar13 = iVar14; - if (((local_44 & 1)) && (!param_7)) { - iVar13 = ((int)(iVar10 + (iVar10 >> 0x1f & 7U)) >> 3) - + DAT_ViewportRenderState::instance - .translationMatrix[(int)(iVar9 + (iVar9 >> 0x1f & 7U)) >> 3] - .addXgetTile; - if (!(DAT_TileMapState::instance.LogicLayer[iVar13] & 0x400300U)) { - bVar4 = false; - this->lineOfSightClearanceSteps = local_44; + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; } - if (!local_40) { - if (iVar14 == iVar13) { - if ((bVar5) - && (uVar12 = iVar10 - x >> 0x1f, - (int)(((iVar10 - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 - + height - < (int)local_30)) { + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((char)flags < 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { return 0; } - } else { - bVar5 = false; - if (((char)DAT_TileMapState::instance.LogicLayer[iVar13] < '\0') - || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar13] - && ((!bVar4 - || (!(DAT_TileMapState::instance.LogicLayer[iVar13] & 0x400200U))))))) { - bVar5 = true; - local_30 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar13, 1); - uVar12 = iVar10 - x >> 0x1f; - iVar9 = local_38; - if ((int)(((iVar10 - x ^ uVar12) - uVar12) * (targetHeight - height)) / iVar11 - + height - < (int)local_30) { - return 0; - } - } } - } else { - local_40 = local_40 - 1; + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } + lastTile = tile; } - if ((iVar10 == targetX) && (iVar9 == targetY)) + if (curX == targetX && curY == targetY) { break; - local_44 = local_44 + 1; - iVar14 = iVar13; - if (999 < (int)local_44) { - return local_44; } } - return local_44; } - iVar11 = iVar11 * 2; - iVar9 = iVar11 - iVar7; - if ((targetHeight < height) && (local_40)) { - uVar12 = targetY - y >> 0x1f; - iVar6 = (targetY - y ^ uVar12) - uVar12; - iVar6 = ((int)(iVar6 + (iVar6 >> 0x1f & 7U)) >> 3) + -1; - if (4 < iVar6) { - iVar6 = 4; - } - if (1 < iVar6) { - piVar15 = (int*)((int)DAT_ViewportRenderState::ptr - + (((int)(targetY + (targetY >> 0x1f & 7U)) >> 3) - iVar2) * 0xc + 0x188728); - iVar6 = iVar6 + -1; - do { - local_30 = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, - DAT_TileMapState::ptr)(*piVar15 + ((int)(targetX + (targetX >> 0x1f & 7U)) >> 3), 1); - if (targetHeight < (int)local_30) { - local_40 = 0x1c; - } - piVar15 = piVar15 + iVar2 * -3; - iVar6 = iVar6 + -1; - } while (iVar6); - } + } else { + if (clearance >= 28) { + clearance = 28; } - this->lineOfSightClearanceSteps = local_40; - local_40 = local_40 / 2; - local_44 = 0; - iVar6 = y; - iVar10 = -1; - do { - iVar6 = iVar6 + iVar2; - iVar14 = iVar11; - if (0 < iVar9) { - x = x + iVar1; - iVar14 = iVar11 + iVar7 * -2; - local_3c = x; - } - iVar9 = iVar9 + iVar14; - iVar14 = iVar10; - if (((local_44 & 1)) && (!param_7)) { - iVar14 = ((int)(x + (x >> 0x1f & 7U)) >> 3) - + DAT_ViewportRenderState::instance - .translationMatrix[(int)(iVar6 + (iVar6 >> 0x1f & 7U)) >> 3] - .addXgetTile; - if (!(DAT_TileMapState::instance.LogicLayer[iVar14] & 0x400300U)) { - bVar4 = false; - this->lineOfSightClearanceSteps = local_44; + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + for (steps = 0; steps < 1000; steps++) { + curX += stepX; + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; } - if (!local_40) { - if (iVar10 == iVar14) { - if ((bVar5) - && (uVar12 = iVar6 - y >> 0x1f, - (int)(((iVar6 - y ^ uVar12) - uVar12) * (targetHeight - height)) / iVar7 - + height - < (int)local_30)) { + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((char)flags < 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { return 0; } - } else { - bVar5 = false; - if (((char)DAT_TileMapState::instance.LogicLayer[iVar14] < '\0') - || ((sVar3 != DAT_TileMapState::instance.BuildingLayer[iVar14] - && ((!bVar4 - || (!(DAT_TileMapState::instance.LogicLayer[iVar14] & 0x400200U))))))) { - bVar5 = true; - local_30 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(iVar14, 1); - uVar12 = iVar6 - y >> 0x1f; - x = local_3c; - if ((int)(((iVar6 - y ^ uVar12) - uVar12) * (targetHeight - height)) / iVar7 - + height - < (int)local_30) { - return 0; - } - } } - } else { - local_40 = local_40 - 1; + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } + lastTile = tile; + } + if (curX == targetX && y == targetY) { + break; } - } while (((x != targetX) || (iVar6 != targetY)) - && (local_44 = local_44 + 1, iVar10 = iVar14, (int)local_44 < 1000)); + } } - return local_44; + return steps; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 39dc842e62..966e8680bf 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 57.1% | Parameter slots reused for fild temporaries SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 8.2% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00402E20 | 29.6% | block layout: the original moves each walk's tail after the horizontal walk SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From bd303b9ec0face0306521248321248525eb13d09 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:36:49 +0100 Subject: [PATCH 16/51] Entities: math_atan_1 with the original's int scaling and min/max 57.1 -> 66.0. - The distance and height are scaled as ints before the conversion (`lea [eax*4]`, the signed `/ 2`), so the height term multiplies an int (`fimul`) instead of a converted double. - One `tangent` variable for both roots, as the original keeps both in the same stack slot. - The angle is `a < b ? a : b`, then the max on the `< -90` path. - `x == inf` with the global on the right, which gives the original's `fld; fucomp`. Left: the original writes the scaled ints back into the parameter slots, where ours uses a stack temp; the CRT calls and the rdata constants do not resolve in reccmp. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/EntityState/math_atan_1.cpp | 61 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp index 8db866930a..5c5d186fc7 100644 --- a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp @@ -13,49 +13,38 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00402C50 int EntityState::math_atan_1(int entityType, double param_3, int param_4, int heightDifference) { - double dVar1; - int iVar2; - int iVar3; - int iVar4; - double fVar5; - double fVar6; - fVar5 = (double)param_3 * (double)param_3; - fVar6 = (double)(param_4 * 4); - dVar1 = (double)(fVar5 / (fVar6 * (double)9.812)); - fVar5 = sqrt(((fVar5 * fVar5) / ((double)96.275344 * (fVar6 * fVar6)) - - ((fVar5 + fVar5) * (double)(heightDifference / 2)) / (fVar6 * fVar6 * (double)9.812)) - - (double)1.0); - fVar6 = (double)dVar1 - fVar5; - if (((double)DOUBLE_00b941c0::instance == fVar6) || (iVar2 = _isnan((double)fVar6), iVar2)) { - iVar2 = 1000; + double const v = param_3 * param_3; + param_4 = param_4 * 4; + heightDifference = heightDifference / 2; + double const d = param_4; + double const low = v / (d * 9.812); + double const root + = sqrt(v * v / (96.275344 * (d * d)) - (v + v) * heightDifference / (d * d * 9.812) - 1.0); + double tangent = low - root; + int angleLow; + if (tangent == DOUBLE_00b941c0::instance || _isnan(tangent)) { + angleLow = 1000; } else { - fVar6 = atan((double)fVar6); - iVar2 = (long)((fVar6 * (double)180.0) / (double)3.1415926535 + (double)0.4999000132083893); + angleLow = (long)(atan(tangent) * 180.0 / 3.1415926535 + 0.4999000132083893); } - dVar1 = (double)fVar5 + dVar1; - if ((DOUBLE_00b941c0::instance == dVar1) || (iVar3 = _isnan(dVar1), iVar3)) { - iVar3 = 1000; + tangent = root + low; + int angleHigh; + if (tangent == DOUBLE_00b941c0::instance || _isnan(tangent)) { + angleHigh = 1000; } else { - fVar5 = atan((double)dVar1); - iVar3 = (long)((fVar5 * (double)180.0) / (double)3.1415926535 + (double)0.4999000132083893); + angleHigh = (long)(atan(tangent) * 180.0 / 3.1415926535 + 0.4999000132083893); } - iVar4 = iVar2; - if (iVar3 <= iVar2) { - iVar4 = iVar3; - } - if (iVar4 < -0x5a) { - iVar4 = iVar2; - if (iVar2 <= iVar3) { - iVar4 = iVar3; - } - if (iVar4 < -0x5a) { - return 0x2d; + int angle = angleLow < angleHigh ? angleLow : angleHigh; + if (angle < -90) { + angle = angleLow > angleHigh ? angleLow : angleHigh; + if (angle < -90) { + return 45; } } - if (0x5a < iVar4) { - return 0x2d; + if (angle > 90) { + return 45; } - return iVar4; + return angle; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 966e8680bf..00e5a16bcd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -519,7 +519,7 @@ SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402C50 | 57.1% | Parameter slots reused for fild temporaries +SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param slots; CRT and rdata constants unresolved SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) From 5bcc8dfa1152ebef4458eb4740bbaadb2bf55b46 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:43:57 +0100 Subject: [PATCH 17/51] Entities: processSeaGulls rebuilt from the asm, angle wrap fixed 47.5 -> 78.1. - Bug fix: the circling angle wraps when it reaches 360 (`cmp ax, 0x168; jl`); the decompiled `360 < angle` let it sit at 360 for a tick. - The path step and the destination search swap places: the original tests `close to the destination || no path left` and lays the destination search out first, the path step after it. - `abs()` for the closeness tests, the int->double radius converted once per circle, declarations at first use, no decompiler copies of fields. - The pathAxisCase-4 straight step really adds entity.someMicroX (`[edi + 0x74]` with edi the entity), not the seagull's step; kept. Left: microY stays in a register between the closeness test and the dive target in ours, the original re-reads it, which costs one stack slot (frame 0x24 vs 0x20) and shifts the call arguments' registers. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Entities/EntityState/processSeaGulls.cpp | 352 +++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 145 insertions(+), 209 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index 34b7988226..5ef2a9339e 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -15,6 +15,7 @@ #include "OpenSHC/Globals/SEC_RNG.hpp" #include "math.h" +#include namespace OpenSHC { namespace Map { @@ -26,258 +27,193 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00406900 void EntityState::processSeaGulls(int seagullID) { - short* psVar1; - short sVar2; - double dVar3; - short _newAngle; - short sVar5; - short _targetYPart1; - short sVar4; - uint _targetX; - uint _yDiff; - uint _newX; - BOOLEnum _newBounds; - int _oldMicroY; - int _oldMicroX; - uint _oldX; - BOOLEnum _oldBounds; - int _targetXPart2; - int _targetYPart2; - int iVar6; - uint uVar7; - int _microX; - uint _newY; - uint _oldY; - int iVar8; - uint uVar9; - int _newMicroY; - short _targetXPart1; - int _newMicroX; - int _entityID; - double fVar10; - double fVar11; - short _y; - short _yPosition; - sVar4 = this->seagullArray[seagullID].someCountDown; - _entityID = (int)this->seagullArray[seagullID].entityID; - if (sVar4) { - sVar4 = sVar4 + -1; - this->seagullArray[seagullID].someCountDown = sVar4; - if (sVar4) { + int const entityID = this->seagullArray[seagullID].entityID; + if (this->seagullArray[seagullID].someCountDown != 0) { + this->seagullArray[seagullID].someCountDown = this->seagullArray[seagullID].someCountDown - 1; + if (this->seagullArray[seagullID].someCountDown != 0) { return; } - _y = this->entityArray[_entityID].microY; - this->entityArray[_entityID].targetX = this->entityArray[_entityID].microX; - _yPosition = this->entityArray[_entityID].yPosition; - this->entityArray[_entityID].targetY = _y; + this->entityArray[entityID].targetX = this->entityArray[entityID].microX; + this->entityArray[entityID].targetY = this->entityArray[entityID].microY; MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[_entityID].xPosition, (int)((int)(_yPosition)), DE::SHCDE::FX_GULL_SURFACE); + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL_SURFACE); } - _microX = (int)this->entityArray[_entityID].microX; - _targetX = _microX - this->entityArray[_entityID].targetX; - if (((int)((_targetX ^ (int)_targetX >> 0x1f) - ((int)_targetX >> 0x1f)) < 3) - && (_yDiff = (int)this->entityArray[_entityID].microY - (int)this->entityArray[_entityID].targetY, - (int)((_yDiff ^ (int)_yDiff >> 0x1f) - ((int)_yDiff >> 0x1f)) < 3)) { - if (((int)this->seagullArray[seagullID].randomNumber ^ this->entityArray[_entityID].rng_1 - ^ (int)SEC_RNG::instance.currentNumber2) + if (abs(this->entityArray[entityID].microX - this->entityArray[entityID].targetX) < 3 + && abs(this->entityArray[entityID].microY - this->entityArray[entityID].targetY) < 3) { + if ((this->seagullArray[seagullID].randomNumber ^ this->entityArray[entityID].rng_1 + ^ SEC_RNG::instance.currentNumber2) % 500 == 123) { - _newMicroY - = (int)this->entityArray[_entityID].someMicroY + (int)this->entityArray[_entityID].microY; - _newMicroX = this->entityArray[_entityID].someMicroX + _microX; - _newY = _newMicroY / 8; - _newX = _newMicroX / 8; - _newBounds = MACRO_CALL_MEMBER( - Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)(_newX, _newY); - if (_newBounds) { - _oldMicroY = (int)this->entityArray[_entityID].microY; - _oldMicroX = (int)this->entityArray[_entityID].microX; - _oldY = _oldMicroY / 8; - _oldX = _oldMicroX / 8; - _oldBounds = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, - DAT_ViewportRenderState::ptr)(_oldX, _oldY); - if (((_oldBounds) - && (( - DAT_TileMapState::instance.LogicLayer - [DAT_ViewportRenderState::instance.translationMatrix[_newY].addXgetTile + _newX] - & 1))) - && ((DAT_TileMapState::instance - .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[_oldY].addXgetTile - + _oldX] - & 1))) { + int const newMicroY = this->entityArray[entityID].someMicroY + this->entityArray[entityID].microY; + int const newMicroX = this->entityArray[entityID].someMicroX + this->entityArray[entityID].microX; + int const newY = newMicroY / 8; + int const newX = newMicroX / 8; + if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(newX, newY)) { + int const oldY = this->entityArray[entityID].microY / 8; + int const oldX = this->entityArray[entityID].microX / 8; + if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(oldX, oldY) + && (DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[newY].addXgetTile + + newX] + & 1) + && (DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[oldY].addXgetTile + + oldX] + & 1)) { this->seagullArray[seagullID].someCountDown = 160; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)( - _entityID, (int)((int)(this->entityArray[_entityID].microX)), - (int)((int)(this->entityArray[_entityID].microY)), 0xfa, _newMicroX, _newMicroY, 0); + entityID, this->entityArray[entityID].microX, this->entityArray[entityID].microY, 250, + newMicroX, newMicroY, 0); MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[_entityID].xPosition, - (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL); + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL); return; } } } - sVar4 = this->seagullArray[seagullID].angle; - dVar3 = ((double)(sVar4 + -0xb4) * 3.1415926535) / 180.0; - _newAngle = this->seagullArray[seagullID].someAngle * 20 + sVar4; - this->seagullArray[seagullID].angle = _newAngle; - if (360 < _newAngle) { + double const radians = (this->seagullArray[seagullID].angle - 180) * 3.1415926535 / 180.0; + this->seagullArray[seagullID].angle + = this->seagullArray[seagullID].someAngle * 20 + this->seagullArray[seagullID].angle; + if (this->seagullArray[seagullID].angle >= 360) { MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); - if ((int)SEC_RNG::instance.currentNumber1 % 5 == 1) { + if (SEC_RNG::instance.currentNumber1 % 5 == 1) { MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[_entityID].xPosition, - (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL); + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL); } - sVar4 = this->seagullArray[seagullID].field_0x1a; - this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle + -360; - if (sVar4 < 0) { + this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle - 360; + if (this->seagullArray[seagullID].field_0x1a < 0) { this->seagullArray[seagullID].unknownCounter_0x16 = this->seagullArray[seagullID].unknownCounter_0x16 + 1; - } else if (0 < sVar4) { + } else if (this->seagullArray[seagullID].field_0x1a > 0) { this->seagullArray[seagullID].unknownCounter_0x16 - = this->seagullArray[seagullID].unknownCounter_0x16 + -1; + = this->seagullArray[seagullID].unknownCounter_0x16 - 1; } if (this->seagullArray[seagullID].unknownCounter_0x16 < 24) { this->seagullArray[seagullID].unknownCounter_0x16 = 24; } - if (80 < this->seagullArray[seagullID].unknownCounter_0x16) { + if (this->seagullArray[seagullID].unknownCounter_0x16 > 80) { this->seagullArray[seagullID].unknownCounter_0x16 = 80; } - this->seagullArray[seagullID].field_0x1a = sVar4 + 1; - if ((short)(sVar4 + 1) >= 0x14) { - this->seagullArray[seagullID].field_0x1a = -0x14; + this->seagullArray[seagullID].field_0x1a = this->seagullArray[seagullID].field_0x1a + 1; + if (this->seagullArray[seagullID].field_0x1a >= 20) { + this->seagullArray[seagullID].field_0x1a = -20; } } - sVar4 = this->seagullArray[seagullID].angle; - if (sVar4 < 0) { - this->seagullArray[seagullID].angle = sVar4 + 0x168; - sVar4 = this->seagullArray[seagullID].field_0x1a; - if (sVar4 < 0) { + if (this->seagullArray[seagullID].angle < 0) { + this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle + 360; + if (this->seagullArray[seagullID].field_0x1a < 0) { this->seagullArray[seagullID].unknownCounter_0x16 = this->seagullArray[seagullID].unknownCounter_0x16 + 1; - } else if (0 < sVar4) { + } else if (this->seagullArray[seagullID].field_0x1a > 0) { this->seagullArray[seagullID].unknownCounter_0x16 - = this->seagullArray[seagullID].unknownCounter_0x16 + -1; + = this->seagullArray[seagullID].unknownCounter_0x16 - 1; } - if (this->seagullArray[seagullID].unknownCounter_0x16 < 0x18) { - this->seagullArray[seagullID].unknownCounter_0x16 = 0x18; + if (this->seagullArray[seagullID].unknownCounter_0x16 < 24) { + this->seagullArray[seagullID].unknownCounter_0x16 = 24; } - if (0x50 < this->seagullArray[seagullID].unknownCounter_0x16) { - this->seagullArray[seagullID].unknownCounter_0x16 = 0x50; + if (this->seagullArray[seagullID].unknownCounter_0x16 > 80) { + this->seagullArray[seagullID].unknownCounter_0x16 = 80; } - this->seagullArray[seagullID].field_0x1a = sVar4 + 1; - if ((short)(sVar4 + 1) >= 0x14) { - this->seagullArray[seagullID].field_0x1a = -0x14; + this->seagullArray[seagullID].field_0x1a = this->seagullArray[seagullID].field_0x1a + 1; + if (this->seagullArray[seagullID].field_0x1a >= 20) { + this->seagullArray[seagullID].field_0x1a = -20; } } - iVar8 = (int)this->seagullArray[seagullID].unknownCounter_0x16; - fVar10 = sin((double)dVar3); - _targetXPart2 = (long)(fVar10 * (double)iVar8); - fVar10 = cos((double)dVar3); - _targetYPart2 = (long)(fVar10 * (double)iVar8); - sVar4 = this->seagullArray[seagullID].angle_2; - sVar5 = this->seagullArray[seagullID].angleStep + sVar4; - this->seagullArray[seagullID].angle_2 = sVar5; - fVar10 = ((double)(sVar4 + -0xb4) * (double)3.1415926535) / (double)180.0; - if (sVar5 >= 0x168) { - this->seagullArray[seagullID].angle_2 = sVar5 + -0x168; + double const radius = this->seagullArray[seagullID].unknownCounter_0x16; + int const circleX = (long)(sin(radians) * radius); + int const circleY = (long)(cos(radians) * radius); + double const radians2 = (this->seagullArray[seagullID].angle_2 - 180) * 3.1415926535 / 180.0; + this->seagullArray[seagullID].angle_2 + = this->seagullArray[seagullID].angleStep + this->seagullArray[seagullID].angle_2; + if (this->seagullArray[seagullID].angle_2 >= 360) { + this->seagullArray[seagullID].angle_2 = this->seagullArray[seagullID].angle_2 - 360; } - sVar4 = this->seagullArray[seagullID].angle_2; - if (sVar4 < 0) { - this->seagullArray[seagullID].angle_2 = sVar4 + 0x168; + if (this->seagullArray[seagullID].angle_2 < 0) { + this->seagullArray[seagullID].angle_2 = this->seagullArray[seagullID].angle_2 + 360; } - iVar8 = (int)this->seagullArray[seagullID].numberBetween60And100; - fVar11 = sin(fVar10); - iVar6 = (long)(fVar11 * (double)iVar8); - _targetXPart1 = (short)iVar6 + this->seagullArray[seagullID].x; - this->seagullArray[seagullID].x_2 = _targetXPart1; - fVar10 = cos((double)fVar10); - iVar8 = (long)(fVar10 * (double)iVar8); - _targetYPart1 = (short)iVar8; - _targetYPart1 = _targetYPart1 + this->seagullArray[seagullID].y; - this->seagullArray[seagullID].y_2 = _targetYPart1; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)(_entityID, - (int)((int)(this->entityArray[_entityID].microX)), - (int)((int)(this->entityArray[_entityID].microY)), - (int)((int)(this->entityArray[_entityID].height)), _targetXPart1 + _targetXPart2, - _targetYPart1 + _targetYPart2, (int)((int)(250))); + double const radius2 = this->seagullArray[seagullID].numberBetween60And100; + this->seagullArray[seagullID].x_2 + = (short)(long)(sin(radians2) * radius2) + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].y_2 + = (short)(long)(cos(radians2) * radius2) + this->seagullArray[seagullID].y; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)(entityID, + this->entityArray[entityID].microX, this->entityArray[entityID].microY, + this->entityArray[entityID].height, this->seagullArray[seagullID].x_2 + circleX, + this->seagullArray[seagullID].y_2 + circleY, 250); } - sVar4 = this->seagullArray[seagullID].x; - iVar8 = (int)sVar4; - uVar7 = iVar8 - this->seagullArray[seagullID].x_3; - uVar9 = (int)uVar7 >> 0x1f; - if (((1 < (int)((uVar7 ^ uVar9) - uVar9)) - || (uVar7 = (int)this->seagullArray[seagullID].y - (int)this->seagullArray[seagullID].y_3, - uVar9 = (int)uVar7 >> 0x1f, 1 < (int)((uVar7 ^ uVar9) - uVar9))) - && (sVar5 = this->seagullArray[seagullID].pathMajorLength, 0 < sVar5)) { - this->seagullArray[seagullID].pathStepDelay = this->seagullArray[seagullID].pathStepDelay + -1; - if (this->seagullArray[seagullID].pathStepDelay < 1) { - sVar2 = this->seagullArray[seagullID].pathAxisCase; - this->seagullArray[seagullID].pathStepDelay = 10; - this->seagullArray[seagullID].pathMajorLength = sVar5 + -1; - if (sVar2) { - if (sVar2 == 2) { - this->seagullArray[seagullID].x = this->seagullArray[seagullID].pathStepX + sVar4; - return; - } - if (sVar2 == 1) { - this->seagullArray[seagullID].y - = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; - return; - } - if (sVar2 == 4) { - sVar5 = this->seagullArray[seagullID].pathError; - if (0 < sVar5) { - sVar2 = this->seagullArray[seagullID].pathStepX; - this->seagullArray[seagullID].y - = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; - this->seagullArray[seagullID].x = sVar2 + sVar4; - this->seagullArray[seagullID].pathError - = this->seagullArray[seagullID].pathErrorStepDiagonal + sVar5; - return; - } - sVar2 = this->seagullArray[seagullID].pathErrorStepStraight; - this->seagullArray[seagullID].x = this->entityArray[_entityID].someMicroX + sVar4; - this->seagullArray[seagullID].pathError = sVar2 + sVar5; - return; - } - if (sVar2 == 3) { - sVar5 = this->seagullArray[seagullID].pathError; - this->seagullArray[seagullID].y - = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; - if (0 < sVar5) { - this->seagullArray[seagullID].x = this->seagullArray[seagullID].pathStepX + sVar4; - this->seagullArray[seagullID].pathError - = this->seagullArray[seagullID].pathErrorStepDiagonal + sVar5; - return; - } - this->seagullArray[seagullID].pathError - = this->seagullArray[seagullID].pathErrorStepStraight + sVar5; - } - } + if ((abs(this->seagullArray[seagullID].x - this->seagullArray[seagullID].x_3) < 2 + && abs(this->seagullArray[seagullID].y - this->seagullArray[seagullID].y_3) < 2) + || this->seagullArray[seagullID].pathMajorLength <= 0) { + if (this->seagullArray[seagullID].rngMax799_countdown > 0) { + this->seagullArray[seagullID].rngMax799_countdown + = this->seagullArray[seagullID].rngMax799_countdown - 1; + return; } + this->seagullArray[seagullID].rngMax799_countdown = SEC_RNG::instance.currentNumber2 % 400 + 400; + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findFurthestSeaTile, + DAT_PathFindingState::ptr)((SEC_RNG::instance.currentNumber2 >> 4) % 200 + 400, + this->seagullArray[seagullID].x / 8, this->seagullArray[seagullID].y / 8); + this->seagullArray[seagullID].x_3 = (short)DAT_PathFindingState::instance.ALG_ResultX * 8; + this->seagullArray[seagullID].y_3 = (short)DAT_PathFindingState::instance.ALG_ResultY * 8; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)(seagullID, + this->seagullArray[seagullID].x, this->seagullArray[seagullID].y, this->seagullArray[seagullID].x_3, + this->seagullArray[seagullID].y_3); + this->seagullArray[seagullID].pathStepDelay = 10; return; } - sVar4 = this->seagullArray[seagullID].rngMax799_countdown; - if (0 < sVar4) { - this->seagullArray[seagullID].rngMax799_countdown = sVar4 + -1; + this->seagullArray[seagullID].pathStepDelay = this->seagullArray[seagullID].pathStepDelay - 1; + if (this->seagullArray[seagullID].pathStepDelay > 0) { return; } - _entityID = (int)this->seagullArray[seagullID].y; - this->seagullArray[seagullID].rngMax799_countdown = SEC_RNG::instance.currentNumber2 % 400 + 400; - MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findFurthestSeaTile, DAT_PathFindingState::ptr)( - (int)((((ulonglong)((int)SEC_RNG::instance.currentNumber2 >> 0x1f) << 0x20) - | (uint)((uint)((int)((int)SEC_RNG::instance.currentNumber2 >> 4) % 200) + 400))), - (uint)((int)(iVar8 / 8)), _entityID / 8); - this->seagullArray[seagullID].x_3 = (short)DAT_PathFindingState::instance.ALG_ResultX * 8; - sVar4 = this->seagullArray[seagullID].x_3; - sVar2 = (short)DAT_PathFindingState::instance.ALG_ResultY * 8; - sVar5 = this->seagullArray[seagullID].x; - this->seagullArray[seagullID].y_3 = sVar2; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)(seagullID, - (int)((int)(sVar5)), (int)((int)(this->seagullArray[seagullID].y)), (int)((int)(sVar4)), - (int)((int)(sVar2))); this->seagullArray[seagullID].pathStepDelay = 10; - return; + this->seagullArray[seagullID].pathMajorLength = this->seagullArray[seagullID].pathMajorLength - 1; + short const axisCase = this->seagullArray[seagullID].pathAxisCase; + if (axisCase == 0) { + return; + } + if (axisCase == 2) { + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + return; + } + if (axisCase == 1) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + return; + } + if (axisCase == 4) { + if (this->seagullArray[seagullID].pathError > 0) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + this->seagullArray[seagullID].pathError; + return; + } + this->seagullArray[seagullID].x + = this->entityArray[entityID].someMicroX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepStraight + this->seagullArray[seagullID].pathError; + return; + } + if (axisCase == 3) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + if (this->seagullArray[seagullID].pathError > 0) { + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + this->seagullArray[seagullID].pathError; + return; + } + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepStraight + this->seagullArray[seagullID].pathError; + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 00e5a16bcd..19a5e48c2a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIsin, _CIcos, _ftol2_sse) differ) -SHC_3BB0A8C1_0x00406900 | 47.5% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00406900 | 78.1% | microY kept in a register (orig re-reads), frame 0x24 vs 0x20 SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending From 377658c77c283408b30cca3c18b3c61bf1ad5622 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:46:24 +0100 Subject: [PATCH 18/51] Entities: UpdateFlag_1_2_4_Entity indexes by the current-entity global 53.9 -> 68.2. Indexing every access by DAT_CurrentEntityID::instance instead of a local copy makes MSVC re-read someTracker for the switch and add to graphicType2 in memory after the intermediate stores, as the original does, and share the default arm's epilogue. Left: the original keeps 0 in edi for the comparisons and the reset store; ours uses immediates. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/UpdateFlag_1_2_4_Entity.cpp | 40 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp index 494cd3e5ca..50a72a2821 100644 --- a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -22,12 +22,11 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00402900 void Entities::UpdateFlag_1_2_4_Entity() { - uint const entityID = DAT_CurrentEntityID::instance; - int nextTracker = DAT_EntityState::instance.entityArray[entityID].someTracker; - int const owner = DAT_EntityState::instance.entityArray[entityID].owner; - DAT_EntityState::instance.entityArray[entityID].graphicType2 - = DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset; - if (((byte)DAT_EntityState::instance.entityArray[entityID].yPosition & 0x1f) + int nextTracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + int const owner = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset; + if (((byte)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition & 0x1f) >= DAT_LandscapeState::instance.wind.countdown) { nextTracker = DAT_LandscapeState::instance.wind.value; } @@ -47,34 +46,37 @@ namespace Map { } } } - DAT_EntityState::instance.entityArray[entityID].unkOne_1 = 3; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkOne_1 = 3; int frame; - switch (DAT_EntityState::instance.entityArray[entityID].someTracker) { + switch (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker) { case 0: - frame = DAT_EntityDefinedData::instance.FlagAnimationFrames1[DAT_EntityState::instance.entityArray[entityID] - .unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; break; case 1: - frame = DAT_EntityDefinedData::instance.FlagAnimationFrames2[DAT_EntityState::instance.entityArray[entityID] - .unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; break; case 3: - DAT_EntityState::instance.entityArray[entityID].unkOne_1 = 1; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkOne_1 = 1; /* falls through into case 2 */ case 2: - frame = DAT_EntityDefinedData::instance.FlagAnimationFrames3[DAT_EntityState::instance.entityArray[entityID] - .unknownAnimationFrameRelated]; + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames3[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; break; default: return; } if (frame <= 0) { - DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 0; - DAT_EntityState::instance.entityArray[entityID].someTracker = nextTracker; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = nextTracker; return; } - DAT_EntityState::instance.entityArray[entityID].graphicType2 - = DAT_EntityState::instance.entityArray[entityID].graphicType2 + frame - 1; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + frame - 1; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 19a5e48c2a..23f53b0540 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -491,7 +491,7 @@ SHC_3BB0A8C1_0x00402730 | 0.0% | Pending SHC_3BB0A8C1_0x00402820 | 0.0% | Pending -SHC_3BB0A8C1_0x00402900 | 53.9% | Switch value re-read and zero register in the original +SHC_3BB0A8C1_0x00402900 | 68.2% | original keeps 0 in edi, ours uses immediates SHC_3BB0A8C1_0x00402A0C | 0.0% | Pending From 233f7024966d23729dd64b9ed3378a5959ff1776 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:51:46 +0100 Subject: [PATCH 19/51] Entities: IgniteFireAtMiniTile jitters its parameters in place 71.7 -> 91.3. - The random jitter is added to miniTileX/miniTileY themselves, which is what puts both coordinates in callee-saved registers before the offset table index is dead, as the original does. - The map bounds and the binary-tile-map test are two early returns; combined in one condition, MSVC moved the return block to the end. - `two >= 3`, so the 3 is shared with the RandomLayer mask in a register. - The binary tile map is read through its named field. Left: the original spills the tile after the tree check and keeps the height in ebx for both spawns; ours keeps the tile in ebx. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/IgniteFireAtMiniTile.cpp | 19 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index f3a79b1212..308392cfc7 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -26,11 +26,14 @@ namespace Map { { uint const randomJitter = (uint)SEC_RNG::instance.currentNumber2; MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); - int const microX = miniTileX + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][0]; - int const microY = miniTileY + DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][1]; - uint const x = microX / 8; - uint const y = microY / 8; - if (x > 399 || y > 399 || *(char*)(y * 400 + 0x21aec98 + x) == '\0') { + miniTileX += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][0]; + miniTileY += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][1]; + uint const x = miniTileX / 8; + uint const y = miniTileY / 8; + if (x > 399 || y > 399) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { return 0; } int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; @@ -67,10 +70,10 @@ namespace Map { } uint const entityID = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( - 0, playerID, 0, microX, microY, tileHeightMin8, 0, 0, 0, Map::Entities::ET_FIRE, 0); - if (two > 2 && !(DAT_TileMapState::instance.RandomLayer[tile] & 3)) { + 0, playerID, 0, miniTileX, miniTileY, tileHeightMin8, 0, 0, 0, Map::Entities::ET_FIRE, 0); + if (two >= 3 && !(DAT_TileMapState::instance.RandomLayer[tile] & 3)) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( - 0, playerID, 0, microX, microY, tileHeightMin8, 0, 0, 0, (EntityType)26, 0); + 0, playerID, 0, miniTileX, miniTileY, tileHeightMin8, 0, 0, 0, (EntityType)26, 0); } if (entityID) { DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = (short)two; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 23f53b0540..47a50bb927 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1623,7 +1623,7 @@ SHC_3BB0A8C1_0x00405125 | 0.0% | Pending SHC_3BB0A8C1_0x00405130 | 100.0% | Reimplemented (counted: only the constant 0x10300131 is shown as an address label in ours) -SHC_3BB0A8C1_0x004052E0 | 71.7% | Operand load order and register allocation +SHC_3BB0A8C1_0x004052E0 | 91.3% | orig spills the tile and keeps the height in ebx SHC_3BB0A8C1_0x004054AC | 0.0% | Pending From 60b0e3c60eb954b9780f8ffaf78cb835fdf97e19 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 00:57:28 +0100 Subject: [PATCH 20/51] Entities: moveProjectileEntity trajectory rebuilt from the FPU stack 58.8 -> 72.2. Ghidra lost track of the x87 stack in this function and decompiled the angle from uninitialised `extraout_ST*` values. Followed through the original's stack, the projectile's elapsed time (speedUnk), vCos and vSin are loaded once as doubles before the early return, and: distance = vCos * t, rise = vSin * t - t * t * 4.906 dx = (long)(distance / 4), targetHeight = (long)(2 * rise) angle = t != 0 ? atan((rise - rise(t - accumulator)) / (distance - vCos * (t - accumulator)) * 3) in degrees : startingAngle The `t != 0` test is on the elapsed time; the decompile showed vSin. The atan arm is the fall-through, as in the original. Left: ours converts (long)angle once and reuses it in the loop, the original calls _ftol again in every step. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/moveProjectileEntity.cpp | 174 +++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 69 insertions(+), 107 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp index b9074286b4..20744a97a4 100644 --- a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -28,136 +28,98 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004084A0 BOOLEnum EntityState::moveProjectileEntity(int entityID) { - short* psVar1; - short sVar2; - EntityTypeShort EVar3; - short sVar4; - int _dx; - int iVar5; - int iVar6; - int _height; - double _vSin; - double _dxRaw; - double _gravityConstantDiv2; - double _gravConstant_2; - double extraout_ST0; - double fVar7; - double extraout_ST1; - double extraout_ST1_00; - double fVar8; - int iVar9; - int local_10; - float _vCos; - float _speed; - float _accum_2; - int _entityID; - float _speed_2; - _entityID = entityID; - _speed = this->entityArray[entityID].speedUnk; - _vCos = this->entityArray[entityID].vCos; - _vSin = (double)this->entityArray[entityID].vSin; - _height = (int)this->entityArray[entityID].height - (int)this->entityArray[entityID].startingHeight; - local_10 = 0; + double const speed = this->entityArray[entityID].speedUnk; + double const vCos = this->entityArray[entityID].vCos; + double const vSin = this->entityArray[entityID].vSin; + int height = this->entityArray[entityID].height - this->entityArray[entityID].startingHeight; + int heightStep = 0; if (this->entityArray[entityID].someCounter_OR_hitGround != 0) { return FALSE; } if (this->entityArray[entityID].pathAxisCase == 0) { - this->entityArray[entityID].someCounter_OR_hitGround = 0x28; + this->entityArray[entityID].someCounter_OR_hitGround = 40; } - _dxRaw = (double)_vCos * (double)_speed; - /* - 9.812 / 2 (gravity!) - */ - _gravityConstantDiv2 = (double)4.906; - _dx = (long)(_dxRaw * (double)0.25); - fVar7 = extraout_ST1; - iVar5 = (long)(_gravConstant_2 + _gravConstant_2); - if ((double)0 == _vSin) { - fVar7 = (double)(int)this->entityArray[entityID].startingAngle; + double const distance = vCos * speed; + double const rise = vSin * speed - speed * speed * 4.906; + int const dx = (long)(distance * 0.25); + int const targetHeight = (long)(rise + rise); + double angle; + if (speed != 0) { + double const before = speed - this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; + angle = atan((rise - (vSin * before - before * before * 4.906)) / (distance - vCos * before) * 3.0) + * 180.0 / 3.1415926535; } else { - fVar8 = _vSin - (double)this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; - fVar7 = atan(((extraout_ST0 - (_gravityConstantDiv2 * fVar8 - fVar8 * fVar8 * extraout_ST1_00)) - / (fVar7 - _dxRaw * fVar8)) - * (double)3.0); - fVar7 = (fVar7 * (double)180.0) / (double)3.1415926535; + angle = this->entityArray[entityID].startingAngle; } - iVar6 = (long)(fVar7); - _accum_2 = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; - _speed_2 = this->entityArray[entityID].speedUnk; - this->entityArray[entityID].graphicRotationUnk = (word)iVar6; - iVar6 = _dx - this->entityArray[entityID].travelledDistance; - this->entityArray[entityID].speedUnk = _accum_2 + _speed_2; - if (iVar6) { - local_10 = (iVar5 - _height) / iVar6; + this->entityArray[entityID].graphicRotationUnk = (long)angle; + this->entityArray[entityID].speedUnk + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + this->entityArray[entityID].speedUnk; + int const remaining = dx - this->entityArray[entityID].travelledDistance; + if (remaining != 0) { + heightStep = (targetHeight - height) / remaining; } - sVar2 = this->entityArray[entityID].travelledDistance; - while (sVar2 < _dx) { - psVar1 = &this->entityArray[entityID].travelledDistance; - *psVar1 = *psVar1 + 1; - psVar1 = &this->entityArray[entityID].clearanceStepsRemaining; - *psVar1 = *psVar1 + -1; - if (entityID) { + while (this->entityArray[entityID].travelledDistance < dx) { + this->entityArray[entityID].travelledDistance = this->entityArray[entityID].travelledDistance + 1; + this->entityArray[entityID].clearanceStepsRemaining + = this->entityArray[entityID].clearanceStepsRemaining - 1; + if (entityID != 0) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( entityID); } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateEntityMicroMovement, this)(entityID); - if ((DAT_EntityDefinedData::instance - .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType] - != 9) - && (DAT_EntityDefinedData::instance - .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType] - != 10)) { - _height = _height + local_10; - iVar9 = 1; - iVar6 = (long)((double)fVar7); + if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + != 9 + && DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + != 10) { + height = height + heightStep; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( - entityID, (undefined4)((int)(_height)), iVar6, iVar9); + entityID, height, (long)angle, 1); } - iVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( - entityID); - if (!iVar6) { + if (!MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + entityID)) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); return TRUE; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); - if (this->entityArray[entityID].someCounter_OR_hitGround != 0) + if (this->entityArray[entityID].someCounter_OR_hitGround != 0) { break; - sVar2 = this->entityArray[entityID].travelledDistance; - } - EVar3 = this->entityArray[entityID].entityType; - (*(short*)&entityID) = (short)_dx; - this->entityArray[_entityID].travelledDistance = (short)entityID; - if (DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[(short)EVar3] == 9) { - sVar2 = this->entityArray[_entityID].height; - sVar4 = this->entityArray[_entityID].targetZ; - if (sVar2 < sVar4) { - this->entityArray[_entityID].height = sVar2 + 1; - return TRUE; } - if ((sVar4 < sVar2) && (this->entityArray[_entityID].height = sVar2 + -8, (short)(sVar2 + -8) < 1)) { - iVar5 = (int)this->entityArray[_entityID].microY; - iVar6 = (int)this->entityArray[_entityID].microX; - this->entityArray[_entityID].someMicroY = 0; - this->entityArray[_entityID].someMicroX = 0; - this->entityArray[_entityID].height = 0; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( - 0, 0, 0, iVar6, iVar5, 0, iVar6, iVar5, 0, ((EntityType)0x1f), 0); - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[_entityID].xPosition, - (int)((int)(this->entityArray[_entityID].yPosition)), DE::SHCDE::FX_GULL_DIVE); + } + this->entityArray[entityID].travelledDistance = dx; + if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + == 9) { + if (this->entityArray[entityID].height < this->entityArray[entityID].targetZ) { + this->entityArray[entityID].height = this->entityArray[entityID].height + 1; return TRUE; } - } else { - if (DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[(short)EVar3] == 10) { - psVar1 = &this->entityArray[_entityID].height; - *psVar1 = *psVar1 + 1; - return TRUE; + if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { + this->entityArray[entityID].height = this->entityArray[entityID].height - 8; + if (this->entityArray[entityID].height <= 0) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + this->entityArray[entityID].someMicroY = 0; + this->entityArray[entityID].someMicroX = 0; + this->entityArray[entityID].height = 0; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( + 0, 0, 0, microX, microY, 0, microX, microY, 0, ((EntityType)0x1f), 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL_DIVE); + } } - iVar9 = 0; - iVar6 = (long)((double)fVar7); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( - _entityID, (undefined4)((int)(iVar5)), iVar6, iVar9); + return TRUE; + } + if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + == 10) { + this->entityArray[entityID].height = this->entityArray[entityID].height + 1; + return TRUE; } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + entityID, targetHeight, (long)angle, 0); return TRUE; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47a50bb927..133f14f14d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2449,7 +2449,7 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 58.8% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004084A0 | 72.2% | (long)angle CSE'd into one inline fistp; orig calls _ftol per step SHC_3BB0A8C1_0x00408770 | 0.0% | Pending From d7c175c0a241189a29270ea692cde69f1063fb7e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 01:06:20 +0100 Subject: [PATCH 21/51] types: Entity.graphicRotationUnk is short, spawnEntityEffect1 takes int x/y graphicRotationUnk is decremented and tested `jg` against zero in updateEntities, and the decompile already cast every read to (short); as a word, `x - 1` compiled to an `add 0xffff` immediate where the original reuses its -1 register. moveProjectileEntity 72.2 -> 87.9 on this change alone, no other user moved. Every caller of spawnEntityEffect1 sign-extends x and y with movsx and pushes a dword, which is what an int parameter looks like; the callee only reads the low word. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/Entity.hpp | 2 +- src/OpenSHC/Map/Entities/EntityState.func.hpp | 2 +- src/OpenSHC/Map/Entities/EntityState.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/Entities/Entity.hpp b/src/OpenSHC/Map/Entities/Entity.hpp index 1cc724aedc..a10df8cd5f 100644 --- a/src/OpenSHC/Map/Entities/Entity.hpp +++ b/src/OpenSHC/Map/Entities/Entity.hpp @@ -85,7 +85,7 @@ namespace Map { short velocityUnk; // 0x00000096 length: 2 float _elapsedTimeOrGravityAccumulator; // 0x00000098 length: 4 short startingAngle; // 0x0000009C length: 2 - word graphicRotationUnk; // 0x0000009E length: 2 + short graphicRotationUnk; // 0x0000009E length: 2 short unitID; // 0x000000A0 length: 2 short unitID_OR_seaGullID; // 0x000000A2 length: 2 undefined1 padding_0xa4[2]; // 0x000000A4 length: 2 diff --git a/src/OpenSHC/Map/Entities/EntityState.func.hpp b/src/OpenSHC/Map/Entities/EntityState.func.hpp index 935bea9c9c..abb20b17c7 100644 --- a/src/OpenSHC/Map/Entities/EntityState.func.hpp +++ b/src/OpenSHC/Map/Entities/EntityState.func.hpp @@ -190,7 +190,7 @@ namespace Map { Address::SHC_3BB0A8C1_0x004082A0, &EntityState::spawnEntityEffect2) spawnEntityEffect2; - MACRO_FUNCTION_RESOLVER(uint (EntityState::*)(short, short, undefined4, undefined4, int, int), false, + MACRO_FUNCTION_RESOLVER(uint (EntityState::*)(int, int, undefined4, undefined4, int, int), false, Address::SHC_3BB0A8C1_0x004083A0, &EntityState::spawnEntityEffect1) spawnEntityEffect1; diff --git a/src/OpenSHC/Map/Entities/EntityState.hpp b/src/OpenSHC/Map/Entities/EntityState.hpp index 8ba0f1844f..82935f721b 100644 --- a/src/OpenSHC/Map/Entities/EntityState.hpp +++ b/src/OpenSHC/Map/Entities/EntityState.hpp @@ -142,7 +142,7 @@ namespace Map { undefined4 microX, undefined4 microY, undefined4 height, undefined4 entityType, int gmLookupValue); uint spawnEntityEffect1( - short x, short y, undefined4 height, undefined4 entityType, int graphicType1, int graphicType2); + int x, int y, undefined4 height, undefined4 entityType, int graphicType1, int graphicType2); BOOLEnum moveProjectileEntity(int entityID); From 970edc75fe6ec4a2f7daf70498bb6310eb348a36 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 01:06:40 +0100 Subject: [PATCH 22/51] Entities: updateEntities rebuilt from its jump tables 57.1 -> 100. The decompile jumped between the state switch, the type switch and the loop tail with gotos. Rebuilt from the three jump tables instead: the state cases in the original's layout order with `continue` for the arms that skip the rest of the loop body, the type cases grouped as the byte index table groups them, and the poison cloud's eight directions in table order so the two arms that end in `microY + 1` share one tail. `newMaxEntityCount = id + 1` comes before the total-count increment, as the original computes it from the id it already has in a register. `& 7U` keeps the direction mask at int width (`and ecx, 7`); with `& 7` MSVC narrowed it to a byte `and cl, 7` plus a movsx. moveProjectileEntity moves to 87.9 on the graphicRotationUnk type fix. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Entities/EntityState/updateEntities.cpp | 434 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 4 +- 2 files changed, 212 insertions(+), 226 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index ef035b4c43..85ff2a3a78 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -19,146 +19,88 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004087C0 void EntityState::updateEntities() { - word* pwVar1; - short sVar2; - int iVar3; - short* psVar4; - int local_4; - short _gmLookupValue; if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 0) { this->everyTenTicks = 25; } this->totalEntityCount = 0; - DAT_CurrentEntityID::instance = 1; - local_4 = 0; - iVar3 = 0; - if (1 < this->maxEntityCount) { - do { - if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 0) - goto LAB_00408d6d; - this->totalEntityCount = this->totalEntityCount + 1; - local_4 = DAT_CurrentEntityID::instance + 1; - psVar4 = &this->entityArray[DAT_CurrentEntityID::instance].logicalState; - /* - Switch entity state - */ - switch (*psVar4) { - case 1: - *psVar4 = 2; - break; - case 3: - goto switchD_0040884c_caseD_3; - case 4: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::activateProjectileEntity, this)( - DAT_CurrentEntityID::instance); - break; - case 5: - *psVar4 = 6; - break; - case 7: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( - DAT_CurrentEntityID::instance); - goto LAB_00408d6d; - case 8: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( - DAT_CurrentEntityID::instance); - } - if (DAT_CurrentEntityID::instance - == (int)this->entityArray[DAT_CurrentEntityID::instance].nextEntityOnThisTileByID) { - switchD_0040884c_caseD_3: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( - DAT_CurrentEntityID::instance); - goto LAB_00408d6d; - } - if (this->entityArray[DAT_CurrentEntityID::instance].unkOne_1 - <= this->entityArray[DAT_CurrentEntityID::instance].field_0x12) { - this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated - = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + 1; - this->entityArray[DAT_CurrentEntityID::instance].field_0x12 = 0; - } - this->entityArray[DAT_CurrentEntityID::instance].field_0x12 - = this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + 1; - if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 6) - goto switchD_0040890b_caseD_9; - /* - Switch entity type - */ + int newMaxEntityCount = 0; + for (DAT_CurrentEntityID::instance = 1; (int)DAT_CurrentEntityID::instance < this->maxEntityCount; + DAT_CurrentEntityID::instance = DAT_CurrentEntityID::instance + 1) { + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 0) { + continue; + } + newMaxEntityCount = DAT_CurrentEntityID::instance + 1; + this->totalEntityCount = this->totalEntityCount + 1; + switch (this->entityArray[DAT_CurrentEntityID::instance].logicalState) { + case 1: + this->entityArray[DAT_CurrentEntityID::instance].logicalState = 2; + break; + case 5: + this->entityArray[DAT_CurrentEntityID::instance].logicalState = 6; + break; + case 4: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::activateProjectileEntity, this)( + DAT_CurrentEntityID::instance); + break; + case 7: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + continue; + case 8: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + break; + case 3: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + DAT_CurrentEntityID::instance); + continue; + } + if (DAT_CurrentEntityID::instance + == this->entityArray[DAT_CurrentEntityID::instance].nextEntityOnThisTileByID) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + DAT_CurrentEntityID::instance); + continue; + } + if (this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + >= this->entityArray[DAT_CurrentEntityID::instance].unkOne_1) { + this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + 1; + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 = 0; + } + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + = this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState != 6) { switch (this->entityArray[DAT_CurrentEntityID::instance].entityType) { case Map::Entities::ET_FIRE: break; - case Map::Entities::ET_FLAG_1: - case Map::Entities::ET_FLAG_4: - case Map::Entities::ET_FLAG_2: - case Map::Entities::ET_FLAG_3: - case Map::Entities::ET_BRAZIER: - case Map::Entities::ET_HEADS_ON_SPIKES: - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( - DAT_CurrentEntityID::instance); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( - DAT_CurrentEntityID::instance); - break; - default: - this->entityArray[DAT_CurrentEntityID::instance].screenDirection - = (short)this->entityArray[DAT_CurrentEntityID::instance].orientation + -0x3c; - this->entityArray[DAT_CurrentEntityID::instance].screenDirection - = this->entityArray[DAT_CurrentEntityID::instance].screenDirection - + (short)DAT_TileMapState::instance.mapOrientation * -2; - psVar4 = &this->entityArray[DAT_CurrentEntityID::instance].screenDirection; - if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { - *psVar4 = *psVar4 + 0x10; - } - if (((this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0) - && (_gmLookupValue = this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue, - _gmLookupValue != 0)) - && (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0)) { - if (_gmLookupValue == 3) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect1, this)( - this->entityArray[DAT_CurrentEntityID::instance].microX, - this->entityArray[DAT_CurrentEntityID::instance].microY, - (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].height)), - 6, (int)((int)(this->entityArray[DAT_CurrentEntityID::instance].gmID)), - this->entityArray[DAT_CurrentEntityID::instance].graphicType2); - } else { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( - (int)this->entityArray[DAT_CurrentEntityID::instance].microX, - (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].microY)), - (undefined4)((int)((int)this->entityArray[DAT_CurrentEntityID::instance].height)), - 5, (int)((int)(_gmLookupValue))); - } - } - if (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::moveProjectileEntity, this)( - DAT_CurrentEntityID::instance); - } - break; case Map::Entities::ET_DUST_CLOUD: - if (this->entityArray[DAT_CurrentEntityID::instance].unitID == 2) { - if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1)) { + if (this->entityArray[DAT_CurrentEntityID::instance].unitID != 2) { + if (this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(DAT_CurrentEntityID::instance); this->entityArray[DAT_CurrentEntityID::instance].height = this->entityArray[DAT_CurrentEntityID::instance].height + 1; - iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance] - .unknownAnimationFrameRelated; - sVar2 = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; - if (sVar2 < 0) { - if (iVar3 % (int)sVar2 == 0) { + short const stepX = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + int const frameX + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepX < 0) { + if (frameX % stepX == 0) { this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; } - } else if (iVar3 % (int)sVar2 == 0) { + } else if (frameX % stepX == 0) { this->entityArray[DAT_CurrentEntityID::instance].microX = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; } - sVar2 = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; - iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance] - .unknownAnimationFrameRelated; - if (sVar2 < 0) { - if (iVar3 % (int)sVar2 == 0) { + short const stepY = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + int const frameY + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepY < 0) { + if (frameY % stepY == 0) { this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; } - } else if (iVar3 % (int)sVar2 == 0) { + } else if (frameY % stepY == 0) { this->entityArray[DAT_CurrentEntityID::instance].microY = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; } @@ -167,130 +109,174 @@ namespace Map { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( DAT_CurrentEntityID::instance); } - } else if ((this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated - & 1)) { + } else { + if (this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + int const frameX + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + short const stepX = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + if (stepX < 0) { + if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + } + } else if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + } + short const stepY = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + int const frameY + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepY < 0) { + if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + } + } else if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); + } + } + break; + case Map::Entities::EntityTypeInt__ET_EXPLOSION: + case Map::Entities::ET_GOLD_POPUP: + case Map::Entities::ET_POPULARITY_POPUP: + case Map::Entities::ET_TRADE_BUY_POPUP: + case Map::Entities::ET_TRADE_SELL_POPUP: + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + break; + case Map::Entities::ET_COW_POISON_CLOUD: + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk > 30) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(DAT_CurrentEntityID::instance); - this->entityArray[DAT_CurrentEntityID::instance].height - = this->entityArray[DAT_CurrentEntityID::instance].height + 1; - sVar2 = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; - iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; - if (sVar2 < 0) { - if (iVar3 % (int)sVar2 == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - 1; + if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk <= 0) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); + this->entityArray[DAT_CurrentEntityID::instance].startingAngle + = ((char)SEC_RNG::instance.currentNumber2 >> 4) & 7U; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); } - } else if (iVar3 % (int)sVar2 == 0) { + } + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk = 0; + switch (this->entityArray[DAT_CurrentEntityID::instance].startingAngle) { + case 0: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 4: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 2: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + break; + case 6: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + break; + case 7: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 1: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 5: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 3: this->entityArray[DAT_CurrentEntityID::instance].microX = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; - } - sVar2 = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; - iVar3 = (int)this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; - if (sVar2 < 0) { - if (iVar3 % (int)sVar2 == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; - } - } else if (iVar3 % (int)sVar2 == 0) { this->entityArray[DAT_CurrentEntityID::instance].microY = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( DAT_CurrentEntityID::instance); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( DAT_CurrentEntityID::instance); } + this->entityArray[DAT_CurrentEntityID::instance].height + = DAT_TileMapState::instance + .HeightLayer[this->entityArray[DAT_CurrentEntityID::instance].tile] + + 20; break; - case Map::Entities::ET_COW_POISON_CLOUD: - this->entityArray[DAT_CurrentEntityID::instance].velocityUnk - = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; - if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk < 0x1f) - goto LAB_00408c15; + case Map::Entities::ET_FLAG_1: + case Map::Entities::ET_FLAG_4: + case Map::Entities::ET_FLAG_2: + case Map::Entities::ET_FLAG_3: + case Map::Entities::ET_BRAZIER: + case Map::Entities::ET_HEADS_ON_SPIKES: MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( DAT_CurrentEntityID::instance); - if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { - this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - = this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - 1; - if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk < 1) { - this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); - this->entityArray[DAT_CurrentEntityID::instance].startingAngle - = (byte)((char)SEC_RNG::instance.currentNumber2 >> 4) & 7; - MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); - } - } - this->entityArray[DAT_CurrentEntityID::instance].velocityUnk = 0; - switch (this->entityArray[DAT_CurrentEntityID::instance].startingAngle) { - case 0: - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; - break; - case 1: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; - break; - case 2: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; - break; - case 3: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; - goto LAB_00408bf2; - case 4: - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; - break; - case 5: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; - LAB_00408bf2: - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; - break; - case 6: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; - break; - case 7: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + -1; - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + -1; - } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( DAT_CurrentEntityID::instance); - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( - DAT_CurrentEntityID::instance); - LAB_00408c15: - this->entityArray[DAT_CurrentEntityID::instance].height - = DAT_TileMapState::instance - .HeightLayer[this->entityArray[DAT_CurrentEntityID::instance].tile] - + 0x14; break; - case Map::Entities::EntityTypeInt__ET_EXPLOSION: - case ((EntityType)0x28): - case ((EntityType)0x29): - case ((EntityType)0x2a): - case ((EntityType)0x2b): - this->entityArray[DAT_CurrentEntityID::instance].height - = this->entityArray[DAT_CurrentEntityID::instance].height + 1; - } - switchD_0040890b_caseD_9: - ((void (*)())DAT_EntityDefinedData::instance - .EntityCallbacks[(short)this->entityArray[DAT_CurrentEntityID::instance].entityType])(); - if (this->entityArray[DAT_CurrentEntityID::instance].entityType == Map::Entities::ET_SEAGULLUnk) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processSeaGulls, this)( - (int)this->entityArray[DAT_CurrentEntityID::instance].unitID_OR_seaGullID); + default: + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = (short)this->entityArray[DAT_CurrentEntityID::instance].orientation - 60; + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = this->entityArray[DAT_CurrentEntityID::instance].screenDirection + - (short)DAT_TileMapState::instance.mapOrientation * 2; + if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = this->entityArray[DAT_CurrentEntityID::instance].screenDirection + 16; + } + if (this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0 + && this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 0 + && this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + if (this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 3) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( + this->entityArray[DAT_CurrentEntityID::instance].microX, + this->entityArray[DAT_CurrentEntityID::instance].microY, + this->entityArray[DAT_CurrentEntityID::instance].height, 5, + this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue); + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect1, this)( + this->entityArray[DAT_CurrentEntityID::instance].microX, + this->entityArray[DAT_CurrentEntityID::instance].microY, + this->entityArray[DAT_CurrentEntityID::instance].height, 6, + this->entityArray[DAT_CurrentEntityID::instance].gmID, + this->entityArray[DAT_CurrentEntityID::instance].graphicType2); + } + } + if (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::moveProjectileEntity, this)( + DAT_CurrentEntityID::instance); + } } - LAB_00408d6d: - DAT_CurrentEntityID::instance = DAT_CurrentEntityID::instance + 1; - iVar3 = local_4; - } while ((int)DAT_CurrentEntityID::instance < this->maxEntityCount); + } + ((void (*)())DAT_EntityDefinedData::instance + .EntityCallbacks[this->entityArray[DAT_CurrentEntityID::instance].entityType])(); + if (this->entityArray[DAT_CurrentEntityID::instance].entityType == Map::Entities::ET_SEAGULLUnk) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processSeaGulls, this)( + this->entityArray[DAT_CurrentEntityID::instance].unitID_OR_seaGullID); + } } - this->maxEntityCount = iVar3; + this->maxEntityCount = newMaxEntityCount; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 133f14f14d..7c5ac338e2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2449,11 +2449,11 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 72.2% | (long)angle CSE'd into one inline fistp; orig calls _ftol per step +SHC_3BB0A8C1_0x004084A0 | 87.9% | (long)angle CSE'd into one inline fistp; orig calls _ftol per step SHC_3BB0A8C1_0x00408770 | 0.0% | Pending -SHC_3BB0A8C1_0x004087C0 | 57.1% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004087C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00408D90 | 0.0% | Pending From ce2b1cc8016aa0323fc4ee1d626ef03acc1039a0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 01:12:08 +0100 Subject: [PATCH 23/51] Entities: moveProjectileEntity tail as an else-if chain with one return 87.9 -> 90.1. The curve-type 9 and 10 arms and the collision update share a single `return TRUE`, and the `height < targetZ` test is the if of an if/else with the `> targetZ` arm. With an early return per arm MSVC shared the constant 1 between the return value and `height + 1` (`add [..], ax`); the original adds the immediate. Left: the atan arm's x87 scheduling (same operand stack, different fxch order) and the rdata constants / CRT helpers reccmp does not resolve. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../EntityState/moveProjectileEntity.cpp | 16 ++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp index 20744a97a4..aaa0844b66 100644 --- a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -93,9 +93,7 @@ namespace Map { == 9) { if (this->entityArray[entityID].height < this->entityArray[entityID].targetZ) { this->entityArray[entityID].height = this->entityArray[entityID].height + 1; - return TRUE; - } - if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { + } else if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { this->entityArray[entityID].height = this->entityArray[entityID].height - 8; if (this->entityArray[entityID].height <= 0) { int const microY = this->entityArray[entityID].microY; @@ -110,16 +108,14 @@ namespace Map { DE::SHCDE::FX_GULL_DIVE); } } - return TRUE; - } - if (DAT_EntityDefinedData::instance - .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + } else if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] == 10) { this->entityArray[entityID].height = this->entityArray[entityID].height + 1; - return TRUE; + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + entityID, targetHeight, (long)angle, 0); } - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( - entityID, targetHeight, (long)angle, 0); return TRUE; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7c5ac338e2..7f7bb9aabd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2449,7 +2449,7 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 87.9% | (long)angle CSE'd into one inline fistp; orig calls _ftol per step +SHC_3BB0A8C1_0x004084A0 | 90.1% | atan arm x87 fxch scheduling; unresolved rdata constants and CRT calls SHC_3BB0A8C1_0x00408770 | 0.0% | Pending From 126b9eb6734bedf25c241803ea8d2d3645575842 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 01:30:52 +0100 Subject: [PATCH 24/51] Entities: processEntityHitBuildingOrUnit rebuilt from the asm 47.8 -> 72.7. Rewritten block by block from the original instead of restyling the decompile: named layers instead of raw addresses and `tile * 2` byte offsets, `/ 8` for the position, the bounds tests with the literals the asm compares against, the building-type jump table as a switch, and the hit types as one else-if chain in the original's test order. The original's `if (x) A; else B` layout decides most of the arm order (flags, brazier, water/ground, cow hit). Two gotos stay because the original shares the block: a unit hit by a flying cow jumps into the cow splat, and a pitch ditch found next to an arrow jumps into the ditch ignition. Left: the unit-hit loops are laid out after the fire-arrow arm where the original only moves their exit handlers there, and the register assignment in the rock arm. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processEntityHitBuildingOrUnit.cpp | 988 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 450 insertions(+), 540 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index 76df1a3046..bce3a17e62 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -17,6 +17,7 @@ #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" @@ -26,6 +27,8 @@ #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" +#include + namespace OpenSHC { namespace Map { namespace Entities { @@ -42,91 +45,60 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00407190 undefined4 EntityState::processEntityHitBuildingOrUnit(int entityID) { - int* piVar1; - short* psVar2; - EntityTypeShort EVar3; - int uVar4; - short sVar5; - BuildingTypeShort BVar6; - short sVar7; - uint _y; - BOOLEnum BVar8; - int _buildingHealth; - int _entityOriginUnitID; - uint _x; - int iVar9; - int _randomNumber; - Point8IntXY* pPVar10; - int _someTile; - int iVar11; - uint _collateralDamageUnk; - int _randomNumber2; - uint _damageUnk; - int _buildingID; - EntityState* local_10; - int local_c; - int _tile; - uint local_4; - short _entityType; - short _entityType_2; - short _playerID; - short _yPosition; - short _xPosition; - local_10 = this; - _someTile = (int)this->entityArray[entityID].microX; - _buildingID = (int)this->entityArray[entityID].microY; - sVar7 = (short)((int)(_buildingID + (_buildingID >> 0x1f & 7U)) >> 3); - this->entityArray[entityID].yPosition = sVar7; - _y = (uint)sVar7; - sVar7 = (short)((int)(_someTile + (_someTile >> 0x1f & 7U)) >> 3); - this->entityArray[entityID].xPosition = sVar7; - _x = (uint)sVar7; - _entityType = this->entityArray[entityID].entityType; - _someTile = DAT_ViewportRenderState::instance.translationMatrix[_y].addXgetTile + _x; - local_c = 1; - this->entityArray[entityID].tile = _someTile; - if (_entityType == 0x1d) { - if ((((_x < 400) && (_y < 400)) && (*(char*)(_y * 400 + 0x21aec98 + _x) != '\0')) - && ((!(DAT_TileMapState::instance.LogicLayer[_someTile] & 0x30) - && (0 < this->entityArray[entityID].height)))) { - this->entityArray[entityID].nextEntityOnThisTileByID - = DAT_TileMapState::instance.EntityLayer[_someTile]; - DAT_TileMapState::instance.EntityLayer[_someTile] = (short)entityID; - return (undefined4)(1); + this->entityArray[entityID].yPosition = this->entityArray[entityID].microY / 8; + this->entityArray[entityID].xPosition = this->entityArray[entityID].microX / 8; + uint const y = this->entityArray[entityID].yPosition; + uint const x = this->entityArray[entityID].xPosition; + short const entityType = this->entityArray[entityID].entityType; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int result = 1; + this->entityArray[entityID].tile = tile; + if (entityType == Map::Entities::ET_SEAGULLUnk) { + if (x <= 399 && y <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] != 0 + && !(DAT_TileMapState::instance.LogicLayer[tile] & 0x30) + && this->entityArray[entityID].height > 0) { + this->entityArray[entityID].nextEntityOnThisTileByID = DAT_TileMapState::instance.EntityLayer[tile]; + DAT_TileMapState::instance.EntityLayer[tile] = entityID; + return 1; } this->entityArray[entityID].tile = 0; - return (undefined4)(0); + return 0; } - if (((399 < _x) || (399 < _y)) || (*(char*)(_y * 400 + 0x21aec98 + _x) == '\0')) { + if (x > 399 || y > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { this->entityArray[entityID].logicalState = 3; - return (undefined4)(0); + return 0; } - if ((DAT_TileMapState::instance.LogicLayer[_someTile] & 0x30)) { + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x30) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); - return (undefined4)(0); + return 0; } - _tile = _someTile * 2; - if ((int)_entityType - 10U < 6) { - DAT_TileMapState::instance.MiscDisplayLayer[_someTile] - = DAT_TileMapState::instance.MiscDisplayLayer[_someTile] | 0x1000; - EVar3 = this->entityArray[entityID].entityType; - if ((EVar3 == Map::Entities::ET_BRAZIER) || (EVar3 == Map::Entities::ET_HEADS_ON_SPIKES)) { - _buildingID = this->entityArray[entityID].tile; - if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { - if ((DAT_TileMapState::instance.LogicLayer[_buildingID] & 0x100U)) { - if (DAT_TileMapState::instance.DamageLayer[_buildingID] == 0) { + if ((uint)(entityType - 10) <= 5) { + DAT_TileMapState::instance.MiscDisplayLayer[tile] + = DAT_TileMapState::instance.MiscDisplayLayer[tile] | 0x1000; + if (this->entityArray[entityID].entityType != Map::Entities::ET_BRAZIER + && this->entityArray[entityID].entityType != Map::Entities::ET_HEADS_ON_SPIKES) { + int const flagTile = this->entityArray[entityID].tile; + uint const flags = DAT_TileMapState::instance.LogicLayer[flagTile]; + if (flags != 0) { + if (DAT_TileMapState::instance.DamageLayer[flagTile] != 0) { + if (flags & 0x400000) { this->entityArray[entityID].height - = (ushort)DAT_TileMapState::instance.HeightLayer[_buildingID]; - } else { + = DAT_TileMapState::instance.HeightLayer[flagTile] + 20; + } else if (flags & 0x200) { this->entityArray[entityID].height - = DAT_TileMapState::instance.HeightLayer[_buildingID] + 0xf; + = DAT_TileMapState::instance.HeightLayer[flagTile] + 10; + } else { + this->entityArray[entityID].height = DAT_TileMapState::instance.HeightLayer[flagTile]; } - goto LAB_00408150; } - } else { - switch (DAT_BuildingsState::instance - .buildings[DAT_TileMapState::instance.BuildingLayer[_buildingID]] - .buildingType) { + } else if (DAT_TileMapState::instance.BuildingLayer[flagTile] == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + } + } else { + int const brazierTile = this->entityArray[entityID].tile; + short const building = DAT_TileMapState::instance.BuildingLayer[brazierTile]; + if (building != 0) { + switch (DAT_BuildingsState::instance.buildings[building].buildingType) { case Map::Buildings::BT_STONEKEEP: case Map::Buildings::BT_STRONGHOLD: case Map::Buildings::BT_KEEPFOUR: @@ -138,524 +110,462 @@ namespace Map { case Map::Buildings::BT_TOWER3: case Map::Buildings::BT_TOWER4: case Map::Buildings::BT_TOWER5: - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - _buildingID); - this->entityArray[entityID].height = (short)_y; - goto LAB_00408150; + this->entityArray[entityID].height = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(brazierTile); + goto linkEntity; } + } else if (DAT_TileMapState::instance.LogicLayer[brazierTile] & 0x100) { + if (DAT_TileMapState::instance.DamageLayer[brazierTile] != 0) { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[brazierTile] + 15; + } else { + this->entityArray[entityID].height = DAT_TileMapState::instance.HeightLayer[brazierTile]; + } + goto linkEntity; } if (DAT_GameCore::instance.gameMode_2 == Game::GM_SIEGE_THAT) { + int stone; + int gold; MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingCost, - DAT_BuildingsState::ptr)(Commands::M_MAPPER_BRAZIER, (int*)&local_10, (int*)&local_4); - piVar1 = DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .startResources - + 0xf; - *piVar1 = *piVar1 + local_4; + DAT_BuildingsState::ptr)(Commands::M_MAPPER_BRAZIER, &stone, &gold); + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .startResources[15] += gold; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); - } else { - _buildingID = this->entityArray[entityID].tile; - _y = DAT_TileMapState::instance.LogicLayer[_buildingID]; - if (!_y) { - if (DAT_TileMapState::instance.BuildingLayer[_buildingID] == 0) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); - } - } else if (DAT_TileMapState::instance.DamageLayer[_buildingID] != 0) { - if (!(_y & 0x400000)) { - if (!(_y & 0x200)) { - this->entityArray[entityID].height - = (ushort)DAT_TileMapState::instance.HeightLayer[_buildingID]; - } else { - this->entityArray[entityID].height - = DAT_TileMapState::instance.HeightLayer[_buildingID] + 10; - } - } else { - this->entityArray[entityID].height - = DAT_TileMapState::instance.HeightLayer[_buildingID] + 0x14; - } - } } - goto LAB_00408150; + goto linkEntity; } - uVar4 = (short)DAT_TileMapState::instance.UnitLayer[_someTile]; - if ((_entityType != 1) || (this->entityArray[entityID].rng_2 != 2)) { - if (((_entityType == 0x16) || (((_entityType == 3 || (_entityType == 2)) || (_entityType == 4)))) - || (0x50 < this->entityArray[entityID].velocityUnk)) { - while (_buildingID = (int)(short)uVar4, _buildingID) { - if ((this->entityArray[entityID].logicalState == 2) - && (BVar8 = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, - DAT_UnitsState::ptr)(_buildingID, entityID, 0), - BVar8)) { - if (this->entityArray[entityID].entityType != Map::Entities::ET_COW_FLYING) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); - return (undefined4)(0); + { + int unit = DAT_TileMapState::instance.UnitLayer[tile]; + if (entityType != Map::Entities::ET_ARROW_AND_DEFAULT || this->entityArray[entityID].rng_2 != 2) { + if (entityType == Map::Entities::ET_COW_POISON_CLOUD || entityType == Map::Entities::ET_TREBUCHET + || entityType == Map::Entities::ET_CATAPULT || entityType == Map::Entities::ET_MANGONEL + || this->entityArray[entityID].velocityUnk > 80) { + for (; unit != 0; unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (this->entityArray[entityID].logicalState == 2 + && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(unit, entityID, 0)) { + if (this->entityArray[entityID].entityType != Map::Entities::ET_COW_FLYING) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( + entityID); + return 0; + } + this->entityArray[entityID].height = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); + goto cowSplat; } - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( - _someTile, 0); - this->entityArray[entityID].height = (short)_y; - goto LAB_004079b4; } - uVar4 = DAT_UnitsState::instance.units[_buildingID].nextUnitOnTheSameTile; } - } - EVar3 = this->entityArray[entityID].entityType; - if (((EVar3 == Map::Entities::ET_TREBUCHET) || (EVar3 == Map::Entities::ET_CATAPULT)) - || ((EVar3 == Map::Entities::ET_MANGONEL || (0x50 < this->entityArray[entityID].velocityUnk)))) { - _buildingID = 1; - do { - uVar4 = DAT_TileMapState::instance - .UnitLayer[DAT_TileMapState::instance.directionTranslationMatrix - [this->entityArray[entityID].yPosition][_buildingID] - + _someTile]; - while (iVar11 = (int)(short)uVar4, iVar11) { - if (((DAT_UnitsState::instance.units[iVar11].field_0x90 != 0) - && (this->entityArray[entityID].logicalState == 2)) - && (BVar8 = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, - DAT_UnitsState::ptr)(iVar11, entityID, 1), - BVar8)) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, local_10)( - entityID); - return (undefined4)(0); + if (this->entityArray[entityID].entityType == Map::Entities::ET_TREBUCHET + || this->entityArray[entityID].entityType == Map::Entities::ET_CATAPULT + || this->entityArray[entityID].entityType == Map::Entities::ET_MANGONEL + || this->entityArray[entityID].velocityUnk > 80) { + for (int direction = 1; direction < 8; direction += 2) { + for (int neighbour = DAT_TileMapState::instance + .UnitLayer[DAT_TileMapState::instance.directionTranslationMatrix + [this->entityArray[entityID].yPosition][direction] + + tile]; + neighbour != 0; + neighbour = DAT_UnitsState::instance.units[neighbour].nextUnitOnTheSameTile) { + if (DAT_UnitsState::instance.units[neighbour].field_0x90 != 0 + && this->entityArray[entityID].logicalState == 2 + && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(neighbour, entityID, 1)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( + entityID); + return 0; + } } - uVar4 = DAT_UnitsState::instance.units[iVar11].nextUnitOnTheSameTile; } - _buildingID = _buildingID + 2; - } while (_buildingID < 8); + } } } if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD) { - local_4 - = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_someTile); - _buildingID = 0; - do { - iVar11 = DAT_TileMapState::instance - .directionTranslationMatrix[this->entityArray[entityID].yPosition][_buildingID] - + _someTile; - uVar4 = (short)DAT_TileMapState::instance.UnitLayer[iVar11]; - while (iVar9 = (int)(short)uVar4, iVar9) { - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - iVar11); - _x = (int)(local_4 - _y) >> 0x1f; - if (((int)((local_4 - _y ^ _x) - _x) < 0x78) - && (this->entityArray[entityID].logicalState == 2)) { + int const cloudHeight + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(tile); + for (int direction = 0; direction < 8; direction++) { + int const neighbourTile + = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][direction] + + tile; + for (int unit = DAT_TileMapState::instance.UnitLayer[neighbourTile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (abs(cloudHeight + - MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(neighbourTile)) + < 120 + && this->entityArray[entityID].logicalState == 2) { MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, - DAT_UnitsState::ptr)(iVar9, entityID, 1); + DAT_UnitsState::ptr)(unit, entityID, 1); } - uVar4 = DAT_UnitsState::instance.units[iVar9].nextUnitOnTheSameTile; } - _buildingID = _buildingID + 1; - } while (_buildingID < 8); - pPVar10 = DAT_EntityDefinedData::instance.EntityBlastTileOffsets; - do { - _buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::computeTileAlongAxisOffset, - DAT_TileMapState::ptr)(_someTile, pPVar10->xOffset, (uint)((int)(pPVar10->yOffset))); - uVar4 = (short)DAT_TileMapState::instance.UnitLayer[_buildingID]; - while (iVar11 = (int)(short)uVar4, iVar11) { - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - _buildingID); - _x = (int)(local_4 - _y) >> 0x1f; - if (((int)((local_4 - _y ^ _x) - _x) < 0x78) - && (this->entityArray[entityID].logicalState == 2)) { + } + for (int i = 0; i < 16; i++) { + int const blastTile = MACRO_CALL_MEMBER(Map::TileMapState_Func::computeTileAlongAxisOffset, + DAT_TileMapState::ptr)(tile, DAT_EntityDefinedData::instance.EntityBlastTileOffsets[i].xOffset, + DAT_EntityDefinedData::instance.EntityBlastTileOffsets[i].yOffset); + for (int unit = DAT_TileMapState::instance.UnitLayer[blastTile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (abs(cloudHeight + - MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(blastTile)) + < 120 + && this->entityArray[entityID].logicalState == 2) { MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, - DAT_UnitsState::ptr)(iVar11, entityID, 2); + DAT_UnitsState::ptr)(unit, entityID, 2); } - uVar4 = DAT_UnitsState::instance.units[iVar11].nextUnitOnTheSameTile; - } - pPVar10 = pPVar10 + 1; - } while ((int)pPVar10 < 0x5b6e08); - } - if ((((this->entityArray[entityID].entityType == Map::Entities::ET_FIRE) - && (_buildingID = this->entityArray[entityID].tile, - (DAT_TileMapState::instance.LogicLayer[_buildingID] & 8) != 0)) - && (_buildingID = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(_buildingID), - _buildingID != 0)) - && (DAT_TileMapState::instance.pitchDitches[_buildingID].state == 1)) { - MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, - (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].x * 8)), - (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].y * 8)), - (int)((int)((uint)DAT_TileMapState::instance - .HeightLayer[DAT_TileMapState::instance.pitchDitches[_buildingID].tile])), - 3); - DAT_TileMapState::instance.pitchDitches[_buildingID].state = 2; - } - _y = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(_someTile, 0); - _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); - if (((_buildingID) - && ((_buildingID = (int)(short)DAT_BuildingsState::instance.buildings[_buildingID].buildingType, - _buildingID == 0x3d || (_buildingID - 0x4aU < 5)))) - && ((this->entityArray[entityID].rng_1 & 4))) { - _y = _y + 0x14; - } - sVar7 = this->entityArray[entityID].height; - _buildingID = (int)sVar7; - if ((int)_y <= _buildingID) - goto LAB_00408150; - EVar3 = this->entityArray[entityID].entityType; - if (EVar3 == ((EntityType)0x20)) { - if (((_buildingID < (int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile]) - && (this->entityArray[entityID].someCounter_OR_hitGround = 1, - (DAT_TileMapState::instance.LogicLayer[_someTile] & 0x10000100U) == 0)) - && (((int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile] - < this->entityArray[entityID].startingHeight_2 + 0x32 - && ((MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile_Convenience)( - (int)this->entityArray[entityID].owner, - (int)((int)(this->entityArray[entityID].microX)), - (int)((int)(this->entityArray[entityID].microY)), - (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] - - 8)), - 2), - (DAT_TileMapState::instance.LogicLayer[_someTile] & 8) != 0 - && (_buildingID = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, - DAT_TileMapState::ptr)(_someTile), - _buildingID != 0)))))) { - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_IGNITE_PITCH); - MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, - (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].x * 8)), - (int)((int)(DAT_TileMapState::instance.pitchDitches[_buildingID].y * 8)), - (int)((int)((uint)DAT_TileMapState::instance - .HeightLayer[DAT_TileMapState::instance.pitchDitches[_buildingID].tile])), - 3); - if (DAT_TileMapState::instance.pitchDitches[_buildingID].state == 1) { - DAT_TileMapState::instance.pitchDitches[_buildingID].state = 2; } } - goto LAB_00408150; } - if (EVar3 == ((EntityType)0x1b)) { - if (((_buildingID <= (int)(uint)DAT_TileMapState::instance.DefaultHeightLayer[_someTile]) - && (this->entityArray[entityID].someCounter_OR_hitGround = 1, - (DAT_TileMapState::instance.LogicLayer[_someTile] & 0x40100001U) != 0)) - && (this->entityArray[entityID].unitID_OR_seaGullID == 0)) { - iVar11 = (int)this->entityArray[entityID].microY; - iVar9 = (int)this->entityArray[entityID].microX; - _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( - 1, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_MED_PLOP); + if (this->entityArray[entityID].entityType == Map::Entities::ET_FIRE + && (DAT_TileMapState::instance.LogicLayer[this->entityArray[entityID].tile] & 8)) { + int const ditch = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(this->entityArray[entityID].tile); + if (ditch != 0 && DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)(this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance.HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], 3); + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; } - goto LAB_00408150; } - if (EVar3 == ((EntityType)8)) { - _y = _buildingID - this->entityArray[entityID].targetZ; - _x = (int)_y >> 0x1f; - if (((int)((_y ^ _x) - _x) < 0x14) || (sVar7 < 9)) { - this->entityArray[entityID].someCounter_OR_hitGround = 1; - } - goto LAB_00408150; - } - if (((EVar3 == Map::Entities::ET_ARROW_AND_DEFAULT) || (EVar3 == Map::Entities::ET_CROSSBOWARROW)) - || ((EVar3 == Map::Entities::ET_BALLISTA - || ((EVar3 == Map::Entities::ET_SLINGER || (EVar3 == Map::Entities::ET_FIRETHROWER)))))) { - if (this->entityArray[entityID].rng_2 == 2) { - _buildingID = 0; - do { - iVar11 = DAT_TileMapState::instance - .directionTranslationMatrix[this->entityArray[entityID].yPosition][_buildingID] - + _someTile; - if (((DAT_TileMapState::instance.LogicLayer[iVar11] & 8)) - && (iVar11 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(iVar11), - iVar11 != 0)) - goto LAB_00407f73; - _buildingID = _buildingID + 1; - } while (_buildingID < 8); + { + int groundHeight; + groundHeight + = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); + int building; + building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (building != 0) { + int const buildingType = DAT_BuildingsState::instance.buildings[building].buildingType; + if ((buildingType == Map::Buildings::BT_TOWER + || (uint)(buildingType - Map::Buildings::BT_TOWER1) <= 4) + && (this->entityArray[entityID].rng_1 & 4)) { + groundHeight = groundHeight + 20; + } } - _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); - if ((int)this->entityArray[entityID].travelledDistance - <= (int)this->entityArray[entityID].totalFlightDistance / 2) - goto LAB_00408150; - _y = DAT_TileMapState::instance.LogicLayer[_someTile]; - if ((_y & 0x40100001)) { - iVar11 = (int)this->entityArray[entityID].microY; - iVar9 = (int)this->entityArray[entityID].microX; - _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( - 1, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); - sVar7 = this->entityArray[entityID].yPosition; - sVar5 = this->entityArray[entityID].xPosition; - this->entityArray[entityID].logicalState = 3; - local_c = 0; - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)sVar5, (int)((int)(sVar7)), DE::SHCDE::FX_LITTLE_PLOP); - goto LAB_00408150; + short height; + height = this->entityArray[entityID].height; + if (groundHeight <= height) { + goto linkEntity; } - if ((!(_y & 0x10000100)) - && ((!_buildingID - || ((((BVar6 = DAT_BuildingsState::instance.buildings[_buildingID].buildingType, - BVar6 != Map::Buildings::BT_STONEKEEP && (BVar6 != Map::Buildings::BT_STRONGHOLD)) - && (BVar6 != Map::Buildings::BT_KEEPFOUR)) - && (BVar6 != Map::Buildings::BT_KEEPFIVE)))))) { - if (!(_y & 8)) { - if (!_buildingID) { - this->entityArray[entityID].someCounter_OR_hitGround = 40; - } else { - _entityOriginUnitID = (int)this->entityArray[entityID].unitID_OR_seaGullID; - /* - if buildingtype is a tower (1 to 5) - */ - BVar6 = DAT_BuildingsState::instance.buildings[_buildingID].buildingType; - if (((0x49 < (short)BVar6) && ((short)BVar6 < 0x4f)) - || ((DAT_BuildingsState::instance.buildings[_buildingID].currentHealth == 0 - || ((_y & 0xf000000))))) - goto LAB_00408150; - if (DAT_UnitsState::instance.units[_entityOriginUnitID].unitType - == Map::Units::UT_S_FBALLISTA) { - MACRO_CALL_MEMBER( - Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)(_someTile, - (uint)((int)((int)this->entityArray[entityID].xPosition)), - (uint)((int)((int)this->entityArray[entityID].yPosition)), 10, 0, - (int)((int)(this->entityArray[entityID].owner)), FALSE, _entityOriginUnitID); - _buildingHealth = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getNonFarmFieldBuildingHealthAtTileOr1000, - DAT_TileMapState::ptr)(_someTile); - if (_buildingHealth < 50) { - MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( - (int)this->entityArray[entityID].owner, - (int)((int)(this->entityArray[entityID].xPosition * 8)), - (int)((int)(this->entityArray[entityID].yPosition * 8)), - (int)((int)((uint)DAT_TileMapState::instance - .HeightLayer[this->entityArray[entityID].tile])), + short hitType; + hitType = this->entityArray[entityID].entityType; + if (hitType == ((EntityType)0x20)) { + if (height < DAT_TileMapState::instance.DefaultHeightLayer[tile]) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x10000100) + && DAT_TileMapState::instance.DefaultHeightLayer[tile] + < this->entityArray[entityID].startingHeight_2 + 50) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile_Convenience)( + this->entityArray[entityID].owner, this->entityArray[entityID].microX, + this->entityArray[entityID].microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] - 8, 2); + if (DAT_TileMapState::instance.LogicLayer[tile] & 8) { + int const ditch = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(tile); + if (ditch != 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)(this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], 3); - this->entityArray[entityID].someCounter_OR_hitGround = 1; - goto LAB_00408148; - } - } else { - if (this->entityArray[entityID].entityType == Map::Entities::ET_BALLISTA) { - _playerID = this->entityArray[entityID].owner; - _yPosition = this->entityArray[entityID].yPosition; - _xPosition = this->entityArray[entityID].xPosition; - _buildingID = 2; - } else { - _playerID = this->entityArray[entityID].owner; - _yPosition = this->entityArray[entityID].yPosition; - _xPosition = this->entityArray[entityID].xPosition; - _buildingID = 1; + if (DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; + } } - MACRO_CALL_MEMBER( - Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)(_someTile, - (uint)((int)((int)_xPosition)), (uint)((int)((int)_yPosition)), _buildingID, 0, - (int)((int)(_playerID)), FALSE, _entityOriginUnitID); } - this->entityArray[entityID].someCounter_OR_hitGround = 1; } - } else { - if ((this->entityArray[entityID].rng_2 == 2) - && (iVar11 = MACRO_CALL_MEMBER( - Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(_someTile), - iVar11 != 0)) { - LAB_00407f73: + } + } else if (hitType == ((EntityType)0x1b)) { + if (height <= DAT_TileMapState::instance.DefaultHeightLayer[tile]) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + if ((DAT_TileMapState::instance.LogicLayer[tile] & 0x40100001) + && this->entityArray[entityID].unitID_OR_seaGullID == 0) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, 0, 0, + microX, microY, splashHeight, microX, microY, splashHeight, ((EntityType)0x1f), 0); MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, - (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_IGNITE_PITCH); - MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)((int)this->entityArray[entityID].owner, - (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].x * 8)), - (int)((int)(DAT_TileMapState::instance.pitchDitches[iVar11].y * 8)), - (int)((int)((uint)DAT_TileMapState::instance - .HeightLayer[DAT_TileMapState::instance.pitchDitches[iVar11].tile])), - 3); - if (DAT_TileMapState::instance.pitchDitches[iVar11].state == 1) { - DAT_TileMapState::instance.pitchDitches[iVar11].state = 2; - } + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_MED_PLOP); } + } + } else if (hitType == ((EntityType)8)) { + if (abs(height - this->entityArray[entityID].targetZ) < 20 || height <= 8) { this->entityArray[entityID].someCounter_OR_hitGround = 1; } - } else { - if (((this->entityArray[entityID].rotationFrameIndex < 3) - && (this->entityArray[entityID].startingAngle < 0)) - || ((this->entityArray[entityID].hasDoneEffectUnk != 0 - || (0 < this->entityArray[entityID].clearanceStepsRemaining)))) - goto LAB_00408150; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, local_10)(entityID); - } - } else if (((EVar3 == Map::Entities::ET_TREBUCHET) || (EVar3 == Map::Entities::ET_CATAPULT)) - || (EVar3 == Map::Entities::ET_MANGONEL)) { - this->entityArray[entityID].someCounter_OR_hitGround = 1; - _y = DAT_TileMapState::instance.LogicLayer[_someTile]; - _damageUnk = 10; - local_4 = _y & 0x40100001; - _collateralDamageUnk = 10; - if (local_4) { - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_ROCK_SPLASH); - } - _x = _y & 0x100; - if (((!_x) && (!(_y & 0x10000400))) - && (*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile) == 0)) { - psVar2 - = &DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2; - *psVar2 = *psVar2 + 1; - if (!(_y & 0x4a5014b1)) { - local_4 = _x; - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, - (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_ROCK_HIT_GROUND); - _y = this->entityArray[entityID].rng_1 & 0x80000007; - this->entityArray[entityID].someCounter_OR_hitGround = 0x28; - local_c = 0; - if ((int)_y < 0) { - _y = (_y - 1 | 0xfffffff8) + 1; - } - if (_y != 0xfffffffb && -1 < (int)(_y + 5)) { - do { - _buildingID = (int)this->entityArray[entityID].microY; - iVar11 = (int)this->entityArray[entityID].microX; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)(2, - 0, 0, iVar11, _buildingID, - (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] - + 2)), - (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, - ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50 + -0x28 + _buildingID, 8, - ((EntityType)0x1b), 0); - local_c = local_c + 1; - _y = this->entityArray[entityID].rng_1 & 0x80000007; - if ((int)_y < 0) { - _y = (_y - 1 | 0xfffffff8) + 1; + } else if (hitType == Map::Entities::ET_ARROW_AND_DEFAULT || hitType == Map::Entities::ET_CROSSBOWARROW + || hitType == Map::Entities::ET_BALLISTA || hitType == Map::Entities::ET_SLINGER + || hitType == Map::Entities::ET_FIRETHROWER) { + int ditch; + int building; + uint flags; + if (this->entityArray[entityID].rng_2 == 2) { + for (int direction = 0; direction < 8; direction++) { + int const neighbourTile + = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][direction] + + tile; + if (DAT_TileMapState::instance.LogicLayer[neighbourTile] & 8) { + ditch = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(neighbourTile); + if (ditch != 0) { + goto ignitePitch; } - } while (local_c < (int)(_y + 5)); - } - } else if (local_4) { - _y = this->entityArray[entityID].rng_1 & 0x8000000f; - local_c = 0; - if ((int)_y < 0) { - _y = (_y - 1 | 0xfffffff0) + 1; + } } - local_4 = 0; - if (_y != 0xfffffff6 && -1 < (int)(_y + 10)) { - do { - _buildingID = (int)this->entityArray[entityID].microY; - iVar11 = (int)this->entityArray[entityID].microX; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)(1, - 0, 0, iVar11, _buildingID, - (int)((int)(DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] - + 2)), - (int)SEC_RNG::instance.currentNumber2 % 0x50 + -0x28 + iVar11, - ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50 + -0x28 + _buildingID, 8, - ((EntityType)0x1b), 0); - local_c = local_c + 1; - _y = this->entityArray[entityID].rng_1 & 0x8000000f; - if ((int)_y < 0) { - _y = (_y - 1 | 0xfffffff0) + 1; + } + building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (this->entityArray[entityID].travelledDistance + > this->entityArray[entityID].totalFlightDistance / 2) { + flags = DAT_TileMapState::instance.LogicLayer[tile]; + if (flags & 0x40100001) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, 0, 0, + microX, microY, splashHeight, microX, microY, splashHeight, ((EntityType)0x1f), 0); + this->entityArray[entityID].logicalState = 3; + result = 0; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_LITTLE_PLOP); + } else if (!(flags & 0x10000100) + && (building == 0 + || (DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_STONEKEEP + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_STRONGHOLD + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_KEEPFOUR + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_KEEPFIVE))) { + if (flags & 8) { + if (this->entityArray[entityID].rng_2 == 2) { + ditch = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(tile); + if (ditch != 0) { + ignitePitch: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], + 3); + if (DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; + } + } + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + result = 0; + } else if (building == 0) { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + result = 0; + } else { + int const unitID = this->entityArray[entityID].unitID_OR_seaGullID; + int const buildingType = DAT_BuildingsState::instance.buildings[building].buildingType; + if ((buildingType < Map::Buildings::BT_TOWER1 + || buildingType > Map::Buildings::BT_TOWER5) + && DAT_BuildingsState::instance.buildings[building].currentHealth != 0 + && !(flags & 0xf000000)) { + if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_S_FBALLISTA) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 10, 0, + this->entityArray[entityID].owner, FALSE, unitID); + if (MACRO_CALL_MEMBER( + Map::TileMapState_Func::getNonFarmFieldBuildingHealthAtTileOr1000, + DAT_TileMapState::ptr)(tile) + < 50) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + this->entityArray[entityID].owner, + this->entityArray[entityID].xPosition * 8, + this->entityArray[entityID].yPosition * 8, + DAT_TileMapState::instance + .HeightLayer[this->entityArray[entityID].tile], + 3); + } + } else if (this->entityArray[entityID].entityType == Map::Entities::ET_BALLISTA) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 2, 0, + this->entityArray[entityID].owner, FALSE, unitID); + } else { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 1, 0, + this->entityArray[entityID].owner, FALSE, unitID); + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + result = 0; } - } while (local_c < (int)(_y + 10)); + } + } else if ((this->entityArray[entityID].rotationFrameIndex >= 3 + || this->entityArray[entityID].startingAngle >= 0) + && this->entityArray[entityID].hasDoneEffectUnk == 0 + && this->entityArray[entityID].clearanceStepsRemaining <= 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, this)( + entityID); + result = 0; } - iVar11 = (int)this->entityArray[entityID].microY; - iVar9 = (int)this->entityArray[entityID].microX; - _buildingID = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, local_10)( - 0, 0, 0, iVar9, iVar11, _buildingID, iVar9, iVar11, _buildingID, ((EntityType)0x1f), 0); } - } else { - local_4 = _x; - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, local_10)(entityID); - _entityType_2 = this->entityArray[entityID].entityType; - if (_entityType_2 == 3) { - _damageUnk = 60; - _collateralDamageUnk = 0x1e; - } else if (_entityType_2 == 2) { - _damageUnk = 20; - } else if (_entityType_2 == 4) { - _damageUnk = 5; - _collateralDamageUnk = 0; + } else if (hitType == Map::Entities::ET_TREBUCHET || hitType == Map::Entities::ET_CATAPULT + || hitType == Map::Entities::ET_MANGONEL) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + int damage = 10; + int collateral = 10; + uint const water = flags & 0x40100001; + if (water) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_SPLASH); } - _buildingID = (int)*(short*)((int)DAT_TileMapState::instance.BuildingLayer + _tile); - if (!_buildingID) { - if ((local_4) - && (DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner] - == DAT_GameState::instance.mapAndTime - .playerTeams[(DAT_TileMapState::instance.WallOwnerLayer[_someTile] & 7) + 1])) { - _damageUnk = 0; - _collateralDamageUnk = 0; + uint const wall = flags & 0x100; + if (!wall && !(flags & 0x10000400) && DAT_TileMapState::instance.BuildingLayer[tile] == 0) { + DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 + = DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 + + 1; + if (flags & 0x4a5014b1) { + if (water) { + for (int i = 0; i < this->entityArray[entityID].rng_1 % 16 + 10; i++) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, + 0, 0, microX, microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, + SEC_RNG::instance.currentNumber2 % 80 - 40 + microX, + (SEC_RNG::instance.currentNumber2 >> 8) % 80 - 40 + microY, 8, + ((EntityType)0x1b), 0); + } + { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, + 0, 0, microX, microY, splashHeight, microX, microY, splashHeight, + ((EntityType)0x1f), 0); + } + } + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_HIT_GROUND); + this->entityArray[entityID].someCounter_OR_hitGround = 40; + for (int i = 0; i < this->entityArray[entityID].rng_1 % 8 + 5; i++) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(2, 0, 0, + microX, microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, + SEC_RNG::instance.currentNumber2 % 80 - 40 + microX, + (SEC_RNG::instance.currentNumber2 >> 8) % 80 - 40 + microY, 8, ((EntityType)0x1b), + 0); + } } - } else if (DAT_GameState::instance.mapAndTime - .playerTeams[DAT_BuildingsState::instance.buildings[_buildingID].owner] - == DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner]) { - _damageUnk = 0; - _collateralDamageUnk = 0; - } - if (_entityType_2 == 4) { - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( - _someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), - (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, - (int)((int)(-this->entityArray[entityID].owner)), FALSE, - (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); - MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateral, - DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), - (uint)((int)((int)this->entityArray[entityID].yPosition)), - (int)((int)(_collateralDamageUnk)), (int)((int)(-this->entityArray[entityID].owner)), 0, - (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); } else { - MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( - _someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), - (uint)((int)((int)this->entityArray[entityID].yPosition)), (int)((int)(_damageUnk)), 0, - (int)((int)(this->entityArray[entityID].owner)), FALSE, - (int)((int)(this->entityArray[entityID].unitID_OR_seaGullID))); - MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateralThunk, - DAT_TileMapState::ptr)(_someTile, (uint)((int)((int)this->entityArray[entityID].xPosition)), - (uint)((int)((int)this->entityArray[entityID].yPosition)), - (int)((int)(_collateralDamageUnk)), (int)((int)(this->entityArray[entityID].owner)), 0); - } - /* - woodhit_02.wav ? - */ - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_ROCK_HIT_WALL); - } - } else { - if (EVar3 != Map::Entities::ET_COW_FLYING) - goto LAB_00408150; - LAB_004079b4: - if (this->entityArray[entityID].hasDoneEffectUnk == 0) { - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, (int)((int)(this->entityArray[entityID].yPosition)), - DE::SHCDE::FX_COW_SPLAT); - this->entityArray[entityID].hasDoneEffectUnk = 1; - if (!(DAT_TileMapState::instance.LogicLayer[_someTile] & 0x401000b1U)) { - this->entityArray[entityID].someCounter_OR_hitGround = 0x28; - DAT_GameCore::instance.cowPoisonTrackerUnk = DAT_GameCore::instance.cowPoisonTrackerUnk + 500; - _randomNumber = (int)SEC_RNG::instance.currentNumber2 % 5 + -2; - if (_randomNumber < 8) { - _randomNumber2 = 8 - _randomNumber; - do { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, - (undefined4)((int)((int)this->entityArray[entityID].owner)), 0, - (int)((int)(this->entityArray[entityID].microX)), - (int)((int)(this->entityArray[entityID].microY)), - (int)((int)(this->entityArray[entityID].height)), 0, 0, 0, - Map::Entities::ET_COW_POISON_CLOUD, 0); - _randomNumber2 = _randomNumber2 + -1; - } while (_randomNumber2); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, this)(entityID); + short const rockType = this->entityArray[entityID].entityType; + if (rockType == Map::Entities::ET_TREBUCHET) { + damage = 60; + collateral = 30; + } else if (rockType == Map::Entities::ET_CATAPULT) { + damage = 20; + } else if (rockType == Map::Entities::ET_MANGONEL) { + damage = 5; + collateral = 0; + } + int const building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (building != 0) { + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[building].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner]) { + damage = 0; + collateral = 0; + } + } else if (wall + && DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[(DAT_TileMapState::instance.WallOwnerLayer[tile] & 7) + 1]) { + damage = 0; + collateral = 0; + } + if (rockType == Map::Entities::ET_MANGONEL) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + tile, this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + damage, 0, -this->entityArray[entityID].owner, FALSE, + this->entityArray[entityID].unitID_OR_seaGullID); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateral, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, collateral, -this->entityArray[entityID].owner, + 0, this->entityArray[entityID].unitID_OR_seaGullID); + } else { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + tile, this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + damage, 0, this->entityArray[entityID].owner, FALSE, + this->entityArray[entityID].unitID_OR_seaGullID); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateralThunk, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, collateral, this->entityArray[entityID].owner, + 0); } MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)this->entityArray[entityID].xPosition, - (int)((int)(this->entityArray[entityID].yPosition)), DE::SHCDE::FX_FLIES); - } else { - this->entityArray[entityID].someCounter_OR_hitGround = 1; + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_HIT_WALL); + } + result = 0; + } else if (hitType == Map::Entities::ET_COW_FLYING) { + cowSplat: + if (this->entityArray[entityID].hasDoneEffectUnk == 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_COW_SPLAT); + this->entityArray[entityID].hasDoneEffectUnk = 1; + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x401000b1) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } else { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + DAT_GameCore::instance.cowPoisonTrackerUnk + = DAT_GameCore::instance.cowPoisonTrackerUnk + 500; + for (int i = SEC_RNG::instance.currentNumber2 % 5 - 2; i < 8; i++) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, this->entityArray[entityID].owner, 0, + this->entityArray[entityID].microX, this->entityArray[entityID].microY, + this->entityArray[entityID].height, 0, 0, 0, Map::Entities::ET_COW_POISON_CLOUD, 0); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_FLIES); + } } + result = 0; } } - LAB_00408148: - local_c = 0; - LAB_00408150: - if (entityID) { + linkEntity: + if (entityID != 0) { if (entityID < 25) { this->entityArray[entityID].nextEntityOnThisTileByID - = (ushort)(byte)DAT_TileMapState::instance.EntityLayerLT25[_someTile]; - DAT_TileMapState::instance.EntityLayerLT25[_someTile] = (char)entityID; - return (undefined4)(local_c); + = (byte)DAT_TileMapState::instance.EntityLayerLT25[tile]; + DAT_TileMapState::instance.EntityLayerLT25[tile] = (char)entityID; + return result; } - this->entityArray[entityID].nextEntityOnThisTileByID - = *(short*)((int)DAT_TileMapState::instance.EntityLayer + _tile); - *(short*)((int)DAT_TileMapState::instance.EntityLayer + _tile) = (short)entityID; + this->entityArray[entityID].nextEntityOnThisTileByID = DAT_TileMapState::instance.EntityLayer[tile]; + DAT_TileMapState::instance.EntityLayer[tile] = entityID; } - return (undefined4)(local_c); + return result; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7f7bb9aabd..edad96dabd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 47.8% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00407190 | 72.7% | unit-hit loops laid out after the fire-arrow arm; rock-arm register assignment SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From 1a946b4b7e56ea5c5ea9b2154751ff9d90c7e455 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 02:08:17 +0100 Subject: [PATCH 25/51] Entities: processEntityHitBuildingOrUnit position, bounds and rock flags 72.7 -> 78.4. - xPosition is computed before yPosition, and the entity type is read after the tile, so the early-exit paths stay out of edi and its push moves past them as in the original. - The out-of-map test is two early returns (range, then the binary map), which keeps the logicalState = 3 block inline. - A unit hit by a flying cow tests for the cow first. - The rock arm tests `flags & 0x40100001` and `flags & 0x100` twice rather than naming them: the original keeps those as spilled temps and gives the damage values the registers. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processEntityHitBuildingOrUnit.cpp | 34 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index bce3a17e62..4a0175044f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -45,12 +45,12 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00407190 undefined4 EntityState::processEntityHitBuildingOrUnit(int entityID) { - this->entityArray[entityID].yPosition = this->entityArray[entityID].microY / 8; this->entityArray[entityID].xPosition = this->entityArray[entityID].microX / 8; + this->entityArray[entityID].yPosition = this->entityArray[entityID].microY / 8; uint const y = this->entityArray[entityID].yPosition; uint const x = this->entityArray[entityID].xPosition; - short const entityType = this->entityArray[entityID].entityType; int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + short const entityType = this->entityArray[entityID].entityType; int result = 1; this->entityArray[entityID].tile = tile; if (entityType == Map::Entities::ET_SEAGULLUnk) { @@ -64,7 +64,11 @@ namespace Map { this->entityArray[entityID].tile = 0; return 0; } - if (x > 399 || y > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + if (x > 399 || y > 399) { + this->entityArray[entityID].logicalState = 3; + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { this->entityArray[entityID].logicalState = 3; return 0; } @@ -145,14 +149,13 @@ namespace Map { if (this->entityArray[entityID].logicalState == 2 && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, DAT_UnitsState::ptr)(unit, entityID, 0)) { - if (this->entityArray[entityID].entityType != Map::Entities::ET_COW_FLYING) { - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( - entityID); - return 0; + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_FLYING) { + this->entityArray[entityID].height = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); + goto cowSplat; } - this->entityArray[entityID].height = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); - goto cowSplat; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return 0; } } } @@ -427,19 +430,18 @@ namespace Map { uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; int damage = 10; int collateral = 10; - uint const water = flags & 0x40100001; - if (water) { + if (flags & 0x40100001) { MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, DE::SHCDE::FX_ROCK_SPLASH); } - uint const wall = flags & 0x100; - if (!wall && !(flags & 0x10000400) && DAT_TileMapState::instance.BuildingLayer[tile] == 0) { + if (!(flags & 0x100) && !(flags & 0x10000400) + && DAT_TileMapState::instance.BuildingLayer[tile] == 0) { DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 = DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 + 1; if (flags & 0x4a5014b1) { - if (water) { + if (flags & 0x40100001) { for (int i = 0; i < this->entityArray[entityID].rng_1 % 16 + 10; i++) { int const microY = this->entityArray[entityID].microY; int const microX = this->entityArray[entityID].microX; @@ -496,7 +498,7 @@ namespace Map { damage = 0; collateral = 0; } - } else if (wall + } else if ((flags & 0x100) && DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner] == DAT_GameState::instance.mapAndTime .playerTeams[(DAT_TileMapState::instance.WallOwnerLayer[tile] & 7) + 1]) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index edad96dabd..926026d304 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 72.7% | unit-hit loops laid out after the fire-arrow arm; rock-arm register assignment +SHC_3BB0A8C1_0x00407190 | 78.4% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From 679bd7188e2dc6004df58729e8566fe244b63582 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 02:18:27 +0100 Subject: [PATCH 26/51] Entities: UpdateFireEntity rebuilt from the asm 30.5 -> 85.3. - One frame value for every tracker state: the negative-tracker arm sets it to 1 and the shared `frame <= 0` test decides between the animation reset and the graphicType2 store, which is the single store the original jumps back to. - Each tracker arm tests `fireParameter >= 3` first, so the shared small-fire lookup is the copy MSVC places after the last arm. - The spread to the four neighbours is an if/else-if chain on the direction with an abs() height test, replacing the decompiler's gotos. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/UpdateFireEntity.cpp | 389 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 204 insertions(+), 187 deletions(-) diff --git a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp index 0761318553..7ecc18a744 100644 --- a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp @@ -12,226 +12,243 @@ #include "OpenSHC/Globals/DAT_TileMapState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include + namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00405680 void Entities::UpdateFireEntity() { - short* psVar1; - uint _totalHeightAtTile; - uint uVar2; - int _entityOffset; - int iVar3; - int _y; - uint _heightDerivative; - int _x; - uint uVar4; - uint _height; - int _tile; - short _fireIntensity0; - short _0xb6; - int _entityTile; - short _height0; - short _playerID; - uVar2 = DAT_CurrentEntityID::instance; - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; - if (_height0 == 5) { + short const fireParameter + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + if (fireParameter == 5) { DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 8; - } else if (_height0 == 4) { + } else if (fireParameter == 4) { DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 9; - } else if (_height0 == 3) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0xc; - } else if (_height0 == 2) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0xe; + } else if (fireParameter == 3) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 12; + } else if (fireParameter == 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 14; } else { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 0x10; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 16; } - DAT_EntityState::instance.entityArray[uVar2].gmID = 0x76; - _height0 = DAT_EntityState::instance.entityArray[uVar2].someTracker; - if (_height0 < 0) { - DAT_EntityState::instance.entityArray[uVar2].unkMinusOne = 0x20; - psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someTracker; - *psVar1 = *psVar1 + 1; - iVar3 = 1; - LAB_00405715: - DAT_EntityState::instance.entityArray[uVar2].graphicType2 = iVar3; - } else { - if (!_height0) { - _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; - if (_height0 < 3) { - LAB_004058a7: - if (_height0 == 2) { - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames1 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } else { - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames2 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } - } else if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { - DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames5 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x76; + short const tracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + int frame = 0; + if (tracker < 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 32; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker + 1; + frame = 1; + } else if (tracker == 0) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames3[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; } else { - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames3 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames5[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; } - LAB_004058ca: - if (0 < iVar3) - goto LAB_00405715; } else { - if (_height0 == 1) { - _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; - if (_height0 < 3) - goto LAB_004058a7; - if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { - DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames8 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } else { - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames7 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } - goto LAB_004058ca; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; } - if (_height0 == 2) { - _height0 = DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6; - if (_height0 < 3) - goto LAB_004058a7; - if (!(DAT_EntityState::instance.entityArray[uVar2].rng_1 & 0x80)) { - DAT_EntityState::instance.entityArray[uVar2].gmID = 0x90; - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames6 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } else { - iVar3 = (int)(char)DAT_EntityDefinedData::instance.FireAnimationFrames4 - [DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated]; - } - goto LAB_004058ca; + } + } else if (tracker == 1) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames7[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames8[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } + } else if (tracker == 2) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames4[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames6[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; } } - DAT_EntityState::instance.entityArray[uVar2].unknownAnimationFrameRelated = 0; - _height0 = DAT_EntityState::instance.entityArray[uVar2].someTracker; - if (!_height0) { - DAT_EntityState::instance.entityArray[uVar2].someTracker = 1; - } else if (_height0 == 1) { - psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; - *psVar1 = *psVar1 + 1; - if ((DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround == 6) - && (2 < DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6)) { - DAT_EntityState::instance.entityArray[uVar2].fireParameter_0xb6 = 2; + } + if (frame <= 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + short const state = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + if (state == 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 1; + } else if (state == 1) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 6 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 > 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 = 2; } - psVar1 = &DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround; - *psVar1 = *psVar1 + 1; - if (8 < DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround) { - DAT_EntityState::instance.entityArray[uVar2].someTracker = 2; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround > 8) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; } - if ((DAT_TileMapState::instance.BuildingLayer[DAT_EntityState::instance.entityArray[uVar2].tile] != 0) - && (iVar3 = MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingFlammabilityFactor, - DAT_BuildingsState::ptr)((int)DAT_TileMapState::instance - .BuildingLayer[DAT_EntityState::instance.entityArray[uVar2].tile]), - uVar2 = DAT_CurrentEntityID::instance, iVar3)) { + if (DAT_TileMapState::instance + .BuildingLayer[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile] + != 0 + && MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingFlammabilityFactor, + DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile])) { if (DAT_BuildingsState::instance .buildings[DAT_TileMapState::instance.BuildingLayer [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile]] .fireDuration - == 0) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; - } else { + != 0) { if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 < 3) { DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 = 3; } - DAT_EntityState::instance.entityArray[uVar2].someTracker = 1; - DAT_EntityState::instance.entityArray[uVar2].someCounter_OR_hitGround = 0; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 1; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = 0; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; } } - } else if (_height0 == 2) { - DAT_EntityState::instance.entityArray[uVar2].logicalState = 3; + } else if (state == 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 3; } - } - _entityOffset = DAT_CurrentEntityID::instance * 0xe8; - if ((DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker != 0) - || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated != 1)) - goto LAB_00405b3d; - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; - _tile = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile; - _height = (uint)DAT_TileMapState::instance.HeightLayer[_tile]; - if ((3 < _height0) - || (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 < 2)) - goto LAB_00405b3d; - if (!_height0) { - _totalHeightAtTile - = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + -1); - _heightDerivative = (int)(_height - _totalHeightAtTile) >> 0x1f; - if (0x18 < (int)((_height - _totalHeightAtTile ^ _heightDerivative) - _heightDerivative)) - goto LAB_00405b2a; - _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; - _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; - _y = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY; - _x = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + -8; - LAB_00405b18: - _playerID = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; - LAB_00405b22: - MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)((int)_playerID, _x, _y, (int)((int)(_height0)), - (int)((int)(_0xb6 + -1)), (int)((int)(_fireIntensity0))); } else { - if (_height0 == 1) { - uVar2 - = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(_tile + 1); - uVar4 = (int)(_height - uVar2) >> 0x1f; - if (0x18 < (int)((_height - uVar2 ^ uVar4) - uVar4)) - goto LAB_00405b2a; - _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; - _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; - _y = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY; - _playerID = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; - _x = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + 8; - goto LAB_00405b22; - } - if (_height0 == 2) { - uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition - + DAT_ViewportRenderState::instance - .translationMatrix - [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + 1] - .addXgetTile); - uVar4 = (int)(_height - uVar2) >> 0x1f; - if ((int)((_height - uVar2 ^ uVar4) - uVar4) < 0x19) { - _fireIntensity0 - = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; - _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; - _y = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + 8; - LAB_00405b09: - _height0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height; - _x = (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX; - goto LAB_00405b18; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 = frame; + } + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker == 0 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated == 1) { + short const direction = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; + int const tile = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile; + int const height = DAT_TileMapState::instance.HeightLayer[tile]; + if (direction < 4 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 > 1) { + if (direction == 0) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + tile - 1)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX - 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 1) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + tile + 1)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 2) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + + 1] + .addXgetTile)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 3) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + - 1] + .addXgetTile)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY - 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } } - } else if ((_height0 == 3) - && (uVar2 = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( - (int)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition - + DAT_ViewportRenderState::instance - .translationMatrix - [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + -1] - .addXgetTile), - uVar4 = (int)(_height - uVar2) >> 0x1f, (int)((_height - uVar2 ^ uVar4) - uVar4) < 0x19)) { - _fireIntensity0 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity; - _0xb6 = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; - _y = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + -8; - goto LAB_00405b09; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8 + 1; } } - LAB_00405b2a: - _entityOffset = DAT_CurrentEntityID::instance * 0xe8; - psVar1 = &DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; - *psVar1 = *psVar1 + 1; - LAB_00405b3d: - iVar3 = *(int*)(DAT_EntityState::instance.entityArray[0].unused_0x48 + _entityOffset + 4); - if (!(DAT_TileMapState::instance.LogicLayer[iVar3] & 0xba7001b1U)) { + if (!(DAT_TileMapState::instance + .LogicLayer[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile] + & 0xba7001b1)) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processFireDamageToUnitsAtTile, DAT_EntityState::ptr)( - iVar3, (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0x2e + _entityOffset + -2), - (int)*(short*)(DAT_EntityState::instance.entityArray[0].unused_0xe0 + _entityOffset + -8)); + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 926026d304..1b4d64f0cc 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1699,7 +1699,7 @@ SHC_3BB0A8C1_0x004054D5 | 0.0% | Pending SHC_3BB0A8C1_0x004054E0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405680 | 30.5% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00405680 | 85.3% | IgniteFireAtMiniTile argument scheduling picks different tail-merge points SHC_3BB0A8C1_0x00405B70 | 100.0% | Reimplemented From 2c44ef8478d8c4c72d1c0d27e5d8d55a965f7198 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 02:28:32 +0100 Subject: [PATCH 27/51] Entities: processSeaGulls steps x before y on the diagonal axis 78.1 -> 79.2. The original loads pathStepX first in the axisCase 4 diagonal arm, which is the order the source assigned the two fields in. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp | 4 ++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index 5ef2a9339e..562e4d1624 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -187,10 +187,10 @@ namespace Map { } if (axisCase == 4) { if (this->seagullArray[seagullID].pathError > 0) { - this->seagullArray[seagullID].y - = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; this->seagullArray[seagullID].x = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; this->seagullArray[seagullID].pathError = this->seagullArray[seagullID].pathErrorStepDiagonal + this->seagullArray[seagullID].pathError; return; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1b4d64f0cc..daf9280d65 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIsin, _CIcos, _ftol2_sse) differ) -SHC_3BB0A8C1_0x00406900 | 78.1% | microY kept in a register (orig re-reads), frame 0x24 vs 0x20 +SHC_3BB0A8C1_0x00406900 | 79.2% | microY kept across the RNG test where the original rereads it (frame 0x24 vs 0x20) SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending From fa8dfe974b56be36d0e414d4521341990581ec7d Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:47:45 +0100 Subject: [PATCH 28/51] Entities: computeLineOfSightDistance tests the blocking flag as bit 7 The original tests the LogicLayer blocking bit with `test al, al; js`, which is what `flags & 0x80` compiles to; `(char)flags < 0` gives `jl` (29.6 -> 35.3). The remaining gap is block layout: the original places the second half of three of the four loop bodies after the dY == 0 loop, where ours keeps each loop contiguous whatever the order of the branches in the source. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Entities/EntityState/computeLineOfSightDistance.cpp | 8 ++++---- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index 4056c931f4..3e0f5e9c75 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -72,7 +72,7 @@ namespace Map { } else if (lastTile != tile) { blocked = FALSE; uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((char)flags < 0 + if ((flags & 0x80) != 0 || (building != DAT_TileMapState::instance.BuildingLayer[tile] && (!clear || !(flags & 0x400200)))) { blocked = TRUE; @@ -135,7 +135,7 @@ namespace Map { } else if (lastTile != tile) { blocked = FALSE; uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((char)flags < 0 + if ((flags & 0x80) != 0 || (building != DAT_TileMapState::instance.BuildingLayer[tile] && (!clear || !(flags & 0x400200)))) { blocked = TRUE; @@ -195,7 +195,7 @@ namespace Map { } else if (lastTile != tile) { blocked = FALSE; uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((char)flags < 0 + if ((flags & 0x80) != 0 || (building != DAT_TileMapState::instance.BuildingLayer[tile] && (!clear || !(flags & 0x400200)))) { blocked = TRUE; @@ -235,7 +235,7 @@ namespace Map { } else if (lastTile != tile) { blocked = FALSE; uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((char)flags < 0 + if ((flags & 0x80) != 0 || (building != DAT_TileMapState::instance.BuildingLayer[tile] && (!clear || !(flags & 0x400200)))) { blocked = TRUE; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index daf9280d65..603cbeb022 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param s SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 29.6% | block layout: the original moves each walk's tail after the horizontal walk +SHC_3BB0A8C1_0x00402E20 | 35.3% | loop bodies split out of line in the original, ours contiguous SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From edb02fe9e9b384347fea3e6929a4472af0b6bef0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:56:31 +0100 Subject: [PATCH 29/51] Entities: initializeProjectileVelocities rebuilt from the asm The curve type dispatch is an if-chain over 0..10 with two shared tails; the gotos are gone and the locals the decompiler invented with them (62.1 -> 92.9): - pathDeltaX is stored in both arms like pathDeltaY, so the axis tests read the field instead of a spilled local - the bit tests on rng_1 are plain masks in 32-bit registers; the (byte) casts turned them into byte arithmetic - the line-of-sight distance is held as the int the callee returns - case 2 reads the entity type before storing the fallback angle What is left: case 4's first `% 20` becomes a magic multiply where the original keeps 20 in edi for both divisions, and case 1's computeVelocity call is tail-merged into case 2's. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../initializeProjectileVelocities.cpp | 289 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 123 insertions(+), 168 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index 9f00c9b8e0..f1a4fc7692 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -17,30 +17,16 @@ namespace Map { void EntityState::initializeProjectileVelocities( int entityID, int x, int y, int height, int targetX, int targetY, int targetZ) { - float fVar1; - short sVar2; - ushort uVar3; - EntityTypeShort EVar4; - short sVar5; - uint uVar6; - int iVar7; - undefined4 uVar8; - short sVar9; - short sVar10; - int iVar11; - double fVar12; - double fVar13; if (y > targetY) { this->entityArray[entityID].pathDeltaY = y - targetY; } else { this->entityArray[entityID].pathDeltaY = targetY - y; } if (x > targetX) { - sVar9 = x - targetX; + this->entityArray[entityID].pathDeltaX = x - targetX; } else { - sVar9 = targetX - x; + this->entityArray[entityID].pathDeltaX = targetX - x; } - this->entityArray[entityID].pathDeltaX = sVar9; if (this->entityArray[entityID].height >= this->entityArray[entityID].targetZ) { this->entityArray[entityID].pathDeltaZ = this->entityArray[entityID].height - this->entityArray[entityID].targetZ; @@ -48,185 +34,154 @@ namespace Map { this->entityArray[entityID].pathDeltaZ = this->entityArray[entityID].targetZ - this->entityArray[entityID].height; } - sVar9 = this->entityArray[entityID].pathDeltaX; this->entityArray[entityID].pathTargetX = (short)targetX; this->entityArray[entityID].pathTargetY = (short)targetY; this->entityArray[entityID].someMicroX = x <= targetX ? 1 : -1; this->entityArray[entityID].someMicroY = y <= targetY ? 1 : -1; - if (sVar9 == 0 && this->entityArray[entityID].pathDeltaY == 0) { + // which axis the Bresenham walk steps along + if (this->entityArray[entityID].pathDeltaX == 0 && this->entityArray[entityID].pathDeltaY == 0) { this->entityArray[entityID].pathAxisCase = 0; - } else if (sVar9 == 0) { + } else if (this->entityArray[entityID].pathDeltaX == 0) { this->entityArray[entityID].pathAxisCase = 1; } else if (this->entityArray[entityID].pathDeltaY == 0) { this->entityArray[entityID].pathAxisCase = 2; - } else if (this->entityArray[entityID].pathDeltaY > sVar9) { + } else if (this->entityArray[entityID].pathDeltaY > this->entityArray[entityID].pathDeltaX) { this->entityArray[entityID].pathAxisCase = 3; } else { this->entityArray[entityID].pathAxisCase = 4; } if (this->entityArray[entityID].pathAxisCase == 3) { - short const straight = sVar9 * 2; - this->entityArray[entityID].pathErrorStepStraight = straight; + this->entityArray[entityID].pathErrorStepStraight = this->entityArray[entityID].pathDeltaX * 2; this->entityArray[entityID].pathErrorStepDiagonal - = straight - this->entityArray[entityID].pathDeltaY * 2; - this->entityArray[entityID].pathError = straight - this->entityArray[entityID].pathDeltaY; + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathError + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaY; } else if (this->entityArray[entityID].pathAxisCase == 4) { - short const straight = this->entityArray[entityID].pathDeltaY * 2; - this->entityArray[entityID].pathErrorStepStraight = straight; - this->entityArray[entityID].pathErrorStepDiagonal = straight - sVar9 * 2; - this->entityArray[entityID].pathError = straight - this->entityArray[entityID].pathDeltaX; + this->entityArray[entityID].pathErrorStepStraight = this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathErrorStepDiagonal + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaX * 2; + this->entityArray[entityID].pathError + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaX; } - iVar7 = DAT_EntityDefinedData::instance - .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType]; - if (!iVar7) { - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( - x, y, height, targetX, targetY, targetZ, 1); - sVar5 = (short)uVar6; - this->entityArray[entityID].field_0x94 = sVar5; - this->entityArray[entityID].totalFlightDistance = sVar5; + int const curveType + = DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType]; + if (curveType == 0) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - sVar10 = this->entityArray[entityID].velocityUnk; - } else { - if (iVar7 == 1) { - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( - x, y, height, targetX, targetY, targetZ, 1); - iVar7 = this->entityArray[entityID].heightDifference; - sVar5 = (short)uVar6; - this->entityArray[entityID].field_0x94 = sVar5; - this->entityArray[entityID].totalFlightDistance = sVar5; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( - (int)(short)this->entityArray[entityID].entityType, - (double)((int)((int)this->entityArray[entityID].startingAngle)), (int)((int)(sVar5)), iVar7); - this->entityArray[entityID].velocityUnk = (short)iVar7; - goto LAB_00403f37; - } - if (iVar7 == 2) { - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( - x, y, height, targetX, targetY, targetZ, 1); - sVar9 = (short)uVar6; - this->entityArray[entityID].field_0x94 = sVar9; - this->entityArray[entityID].totalFlightDistance = sVar9; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { - this->entityArray[entityID].startingAngle = 3; - } - iVar7 = this->entityArray[entityID].heightDifference; - iVar11 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( - (int)(short)this->entityArray[entityID].entityType, - (double)((int)((int)this->entityArray[entityID].startingAngle)), (int)((int)(sVar9)), iVar7); - this->entityArray[entityID].velocityUnk = (short)iVar11; - if ((short)iVar11 < 1) { - EVar4 = this->entityArray[entityID].entityType; - this->entityArray[entityID].startingAngle = 0xf; - iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( - (int)(short)EVar4, 15.0, (int)((int)(sVar9)), iVar7); - this->entityArray[entityID].velocityUnk = (short)iVar7; - } - goto LAB_00403f37; - } - if (iVar7 == 3) { - uVar3 = (ushort)this->entityArray[entityID].rng_1; - this->entityArray[entityID].startingAngle = (uVar3 & 0xf) + 8; - this->entityArray[entityID].velocityUnk = (uVar3 & 7) + 0x15; - goto LAB_00403f37; + short const distance = (short)distanceRaw; + this->entityArray[entityID].startingAngle + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].velocityUnk, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 1) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + this->entityArray[entityID].velocityUnk = (short)MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].startingAngle, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 2) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + // from above, aim low first + if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { + this->entityArray[entityID].startingAngle = 3; } - if (iVar7 == 4) { - uVar6 = this->entityArray[entityID].rng_1; - sVar5 = (short)((int)uVar6 % 0x14) + 0x10; - this->entityArray[entityID].startingAngle = sVar5; - if ((char)uVar6 < '\0') { - this->entityArray[entityID].startingAngle = -sVar5; - } - sVar5 = (short)(((int)uVar6 >> 8) % 0x14) + 0x10; - this->entityArray[entityID].velocityUnk = sVar5; - if (!(uVar6 & 0x8000)) { - return; - } - this->entityArray[entityID].velocityUnk = -sVar5; - return; + int const heightDifference = this->entityArray[entityID].heightDifference; + this->entityArray[entityID].velocityUnk + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( + (short)this->entityArray[entityID].entityType, + (double)this->entityArray[entityID].startingAngle, distance, heightDifference); + if (this->entityArray[entityID].velocityUnk <= 0) { + int const type = (short)this->entityArray[entityID].entityType; + this->entityArray[entityID].startingAngle = 15; + this->entityArray[entityID].velocityUnk = (short)MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)(type, 15.0, distance, heightDifference); } - if (iVar7 == 5) { - iVar11 = this->entityArray[entityID].rng_1; - iVar7 = this->entityArray[entityID].rng_1; - this->entityArray[entityID].velocityUnk = 0; - this->entityArray[entityID].startingAngle = (byte)iVar11 & 7; - this->entityArray[entityID].graphicRotationUnk = (ushort)((uint)iVar7 >> 8) & 0x3f; - return; + } else if (curveType == 3) { + ushort const rng = (ushort)this->entityArray[entityID].rng_1; + this->entityArray[entityID].startingAngle = (rng & 0xf) + 8; + this->entityArray[entityID].velocityUnk = (rng & 7) + 0x15; + } else if (curveType == 4) { + int const rng = this->entityArray[entityID].rng_1; + this->entityArray[entityID].startingAngle = (short)(rng % 20 + 16); + if (rng & 0x80) { + this->entityArray[entityID].startingAngle = -this->entityArray[entityID].startingAngle; } - if (iVar7 != 6) { - if (iVar7 == 7) { - return; - } - if (iVar7 == 10) { - return; - } - if (iVar7 == 8) { - sVar5 = this->entityArray[entityID].unitID_OR_seaGullID; - if (!sVar5) { - this->entityArray[entityID].startingAngle - = (short)(this->entityArray[entityID].rng_1 % 0x3c) + 8; - this->entityArray[entityID].velocityUnk - = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x23; - } else { - if (sVar5 == 4) { - this->entityArray[entityID].startingAngle - = (short)(this->entityArray[entityID].rng_1 % 0x1e) + 0xf; - sVar5 = ((byte)this->entityArray[entityID].rng_1 & 7) + 0xf; - } else { - iVar7 = this->entityArray[entityID].rng_1; - if (sVar5 == 5) { - this->entityArray[entityID].startingAngle = (short)(iVar7 % 0x1e) + 0x2d; - this->entityArray[entityID].velocityUnk - = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x23; - goto LAB_00403f37; - } - this->entityArray[entityID].startingAngle = (short)(iVar7 % 0x23) + 0x14; - sVar5 = ((byte)this->entityArray[entityID].rng_1 & 7) + 0x19; - } - fVar1 = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; - this->entityArray[entityID].velocityUnk = sVar5; - this->entityArray[entityID]._elapsedTimeOrGravityAccumulator = fVar1 * 0.75; - } - } else if (iVar7 == 9) { - this->entityArray[entityID].startingAngle = 0; - } - goto LAB_00403f37; + this->entityArray[entityID].velocityUnk = (short)((rng >> 8) % 20 + 16); + if (rng & 0x8000) { + this->entityArray[entityID].velocityUnk = -this->entityArray[entityID].velocityUnk; } - uVar6 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, this)( - x, y, height, targetX, targetY, targetZ, 1); - sVar5 = (short)uVar6; - this->entityArray[entityID].field_0x94 = sVar5; - this->entityArray[entityID].totalFlightDistance = sVar5; + return; + } else if (curveType == 5) { + this->entityArray[entityID].velocityUnk = 0; + this->entityArray[entityID].startingAngle = this->entityArray[entityID].rng_1 & 7; + this->entityArray[entityID].graphicRotationUnk + = (short)((this->entityArray[entityID].rng_1 >> 8) & 0x3f); + return; + } else if (curveType == 6) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - if (0x96 < sVar5) { - this->entityArray[entityID].velocityUnk = 0x7d; + short const distance = (short)distanceRaw; + if (distance > 150) { + this->entityArray[entityID].velocityUnk = 125; + } + this->entityArray[entityID].startingAngle + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].velocityUnk, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 7 || curveType == 10) { + return; + } else if (curveType == 8) { + if (this->entityArray[entityID].unitID_OR_seaGullID == 0) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 60) + 8; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 0x23; + } else if (this->entityArray[entityID].unitID_OR_seaGullID == 4) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 30) + 15; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 15; + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator * 0.75; + } else if (this->entityArray[entityID].unitID_OR_seaGullID == 5) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 30) + 45; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 0x23; + } else { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 35) + 20; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 25; + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator * 0.75; } - sVar10 = this->entityArray[entityID].velocityUnk; + } else if (curveType == 9) { + this->entityArray[entityID].startingAngle = 0; } - iVar7 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( - (int)(short)this->entityArray[entityID].entityType, (double)((int)((int)sVar10)), (int)((int)(sVar5)), - this->entityArray[entityID].heightDifference); - this->entityArray[entityID].startingAngle = (short)iVar7; - LAB_00403f37: - EVar4 = this->entityArray[entityID].entityType; - if ((((EVar4 == Map::Entities::ET_ARROW_AND_DEFAULT) || (EVar4 == Map::Entities::ET_CROSSBOWARROW)) - && (height + 0x36 < targetZ)) - && (this->entityArray[entityID].rng_1 % 10 == 5)) { + if ((this->entityArray[entityID].entityType == Map::Entities::ET_ARROW_AND_DEFAULT + || this->entityArray[entityID].entityType == Map::Entities::ET_CROSSBOWARROW) + && height + 0x36 < targetZ && this->entityArray[entityID].rng_1 % 10 == 5) { this->entityArray[entityID].hasDoneEffectUnk = 1; } - iVar11 = (int)this->entityArray[entityID].startingAngle; + int const angle = this->entityArray[entityID].startingAngle; this->entityArray[entityID].speedUnk = 0; - iVar7 = (int)this->entityArray[entityID].velocityUnk; + int const velocity = this->entityArray[entityID].velocityUnk; this->entityArray[entityID].travelledDistance = 0; - fVar12 = ((double)iVar11 * (double)3.1415926535) / (double)180.0; - fVar13 = cos(fVar12); - this->entityArray[entityID].vCos = (float)(fVar13 * (double)iVar7); - fVar12 = sin((double)fVar12); - this->entityArray[entityID].vSin = (float)(fVar12 * (double)iVar7); - uVar8 = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(iVar11); - this->entityArray[entityID].rotationFrameIndex = (short)uVar8; - return; + double const radians = (double)angle * 3.1415926535 / 180.0; + this->entityArray[entityID].vCos = (float)(cos(radians) * (double)velocity); + this->entityArray[entityID].vSin = (float)(sin(radians) * (double)velocity); + this->entityArray[entityID].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 603cbeb022..0c7a9f4d2a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 62.1% | deltaX spilled in the path setup; curve dispatch register assignment +SHC_3BB0A8C1_0x00403A20 | 92.9% | case 4 divides by a magic multiply, case 1 call tail-merged into case 2 SHC_3BB0A8C1_0x00403FF0 | 88.2% | Axis chain keeps deltaX/deltaY in registers the original re-tests and reloads From ec5a3cffe3d4d4bcf9c71a82c89f3c1c95d35c74 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 13:11:41 +0100 Subject: [PATCH 30/51] Entities: processSeaGulls computes the new tile y before the new x Declaring newY before newMicroX matches the original's register assignment for the wander target. 79.2% -> 81.2%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index 562e4d1624..504bd8798a 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -46,8 +46,8 @@ namespace Map { % 500 == 123) { int const newMicroY = this->entityArray[entityID].someMicroY + this->entityArray[entityID].microY; - int const newMicroX = this->entityArray[entityID].someMicroX + this->entityArray[entityID].microX; int const newY = newMicroY / 8; + int const newMicroX = this->entityArray[entityID].someMicroX + this->entityArray[entityID].microX; int const newX = newMicroX / 8; if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)(newX, newY)) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0c7a9f4d2a..487e8b39bd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIsin, _CIcos, _ftol2_sse) differ) -SHC_3BB0A8C1_0x00406900 | 79.2% | microY kept across the RNG test where the original rereads it (frame 0x24 vs 0x20) +SHC_3BB0A8C1_0x00406900 | 81.2% | microY kept across the RNG test where the original rereads it (frame 0x24 vs 0x20) SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending From b88c8c8f1d29165dc978bedc3d1be158741d9b7c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 14:19:22 +0100 Subject: [PATCH 31/51] Entities: computeLineOfSightDistance computes the start tile x before y Declaring tileX ahead of tileY matches the original's register assignment in the prologue. 35.3% -> 36.8%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/EntityState/computeLineOfSightDistance.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index 3e0f5e9c75..b9f57c0bbd 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -26,8 +26,8 @@ namespace Map { if (height > targetHeight + 54) { clearance = 100; } - int const tileY = y / 8; int const tileX = x / 8; + int const tileY = y / 8; int const startTile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX; int curX = x; int curY = y; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 487e8b39bd..8f27bd1cc7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param s SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 35.3% | loop bodies split out of line in the original, ours contiguous +SHC_3BB0A8C1_0x00402E20 | 36.8% | loop bodies split out of line in the original, ours contiguous SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From 8bd846dd2d80b658b1a49d0682aa8f8a6280e984 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 14:19:31 +0100 Subject: [PATCH 32/51] Entities: processEntityHitBuildingOrUnit reads microX before microY Declaring the impact microX ahead of microY in the unit-hit arms matches the original's register assignment. 78.4% -> 79.8%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Entities/EntityState/processEntityHitBuildingOrUnit.cpp | 6 +++--- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index 4a0175044f..ba47be3403 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -453,10 +453,10 @@ namespace Map { ((EntityType)0x1b), 0); } { - int const microY = this->entityArray[entityID].microY; - int const microX = this->entityArray[entityID].microX; int const splashHeight = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, microX, microY, splashHeight, microX, microY, splashHeight, ((EntityType)0x1f), 0); @@ -468,8 +468,8 @@ namespace Map { DE::SHCDE::FX_ROCK_HIT_GROUND); this->entityArray[entityID].someCounter_OR_hitGround = 40; for (int i = 0; i < this->entityArray[entityID].rng_1 % 8 + 5; i++) { - int const microY = this->entityArray[entityID].microY; int const microX = this->entityArray[entityID].microX; + int const microY = this->entityArray[entityID].microY; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(2, 0, 0, microX, microY, DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8f27bd1cc7..5f71981342 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 78.4% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming +SHC_3BB0A8C1_0x00407190 | 79.8% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From 3508b2f56f35d4d85a7098f2368bd310b327aa08 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 18:39:16 +0100 Subject: [PATCH 33/51] Entities: spawnProjectileEntity stores targetY before the unit id Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp index b3c951615c..9be73583a0 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -181,8 +181,8 @@ namespace Map { DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; } dVar2 = DAT_GameCore::instance.mapTimeInTicks; - this->entityArray[entityID].unitID_OR_seaGullID = (short)unitID; this->entityArray[entityID].targetY = (short)targetY; + this->entityArray[entityID].unitID_OR_seaGullID = (short)unitID; this->entityArray[entityID].targetZ = (short)targetZUnk; this->entityArray[entityID].field_0x34 = dVar2; this->entityArray[entityID].unitID = (short)param_11; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5f71981342..fc6edb6b2c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1183,7 +1183,7 @@ SHC_3BB0A8C1_0x00404A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00404A70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00404AE0 | 98.2% | entityID and the constant 1 swap edi/ebp +SHC_3BB0A8C1_0x00404AE0 | 98.4% | entityID and the constant 1 swap edi/ebp; field-store scheduling (targetX before targetY measured worse) SHC_3BB0A8C1_0x00404B70 | 0.0% | Pending From ee259140dd22d1af735b49f4a7cac202b12d386e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 21:51:15 +0100 Subject: [PATCH 34/51] Entities: processEntityHitBuildingOrUnit reads the entity's microY before its microX Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index ba47be3403..2dc7a09e1e 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -468,8 +468,8 @@ namespace Map { DE::SHCDE::FX_ROCK_HIT_GROUND); this->entityArray[entityID].someCounter_OR_hitGround = 40; for (int i = 0; i < this->entityArray[entityID].rng_1 % 8 + 5; i++) { - int const microX = this->entityArray[entityID].microX; int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(2, 0, 0, microX, microY, DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fc6edb6b2c..bd0cf138e1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 79.8% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming +SHC_3BB0A8C1_0x00407190 | 80.0% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From e3ae2a632d47fda2c21785dfe02ec2ef72121f2c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 22:19:45 +0100 Subject: [PATCH 35/51] Entities: computeLineOfSightDistance tests for an exhausted clearance first Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../computeLineOfSightDistance.cpp | 131 ++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 72 insertions(+), 61 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index b9f57c0bbd..1f889fbbeb 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -67,23 +67,26 @@ namespace Map { clear = FALSE; this->lineOfSightClearanceSteps = steps; } - if (clearance != 0) { - clearance--; - } else if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; + if (clearance == 0) { + if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } } + } else if (blocked + && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; } - } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; + } else { + clearance--; } lastTile = tile; } @@ -130,23 +133,26 @@ namespace Map { clear = FALSE; this->lineOfSightClearanceSteps = steps; } - if (clearance != 0) { - clearance--; - } else if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; + if (clearance == 0) { + if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } } + } else if (blocked + && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; } - } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; + } else { + clearance--; } lastTile = tile; } @@ -190,23 +196,26 @@ namespace Map { clear = FALSE; this->lineOfSightClearanceSteps = steps; } - if (clearance != 0) { - clearance--; - } else if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; + if (clearance == 0) { + if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } } + } else if (blocked + && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } - } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; + } else { + clearance--; } lastTile = tile; } @@ -230,23 +239,25 @@ namespace Map { clear = FALSE; this->lineOfSightClearanceSteps = steps; } - if (clearance != 0) { - clearance--; - } else if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; + if (clearance == 0) { + if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } } + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } - } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; + } else { + clearance--; } lastTile = tile; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bd0cf138e1..5077158426 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param s SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 36.8% | loop bodies split out of line in the original, ours contiguous +SHC_3BB0A8C1_0x00402E20 | 37.1% | loop bodies split out of line in the original, ours contiguous SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From d0aab409ce1534f1f0df4666d08e348d3f82b7e7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 2 Dec 2026 16:25:05 +0100 Subject: [PATCH 36/51] Entities: follow main's entity headers - angleToRotationFrameIndex returns int, as main declares it. - Entity::unkMinusOne is blendStrength on main (spawnProjectileEntity, UpdateFireEntity). - spawnEntityEffect1/2 take an EntityType; updateEntities passes the entity types 5 and 6, which have no named constant yet. Every function keeps its match (3 at 100%, the other 14 unchanged). Co-Authored-By: Claude Opus 5.5 (1M context) --- .../EntityState/angleToRotationFrameIndex.cpp | 2 +- .../Entities/EntityState/spawnProjectileEntity.cpp | 2 +- .../Map/Entities/EntityState/updateEntities.cpp | 4 ++-- src/OpenSHC/Map/Entities/UpdateFireEntity.cpp | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp index 6bd91cdb7f..16b8aebd69 100644 --- a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp @@ -7,7 +7,7 @@ namespace Map { namespace Entities { // FUNCTION: STRONGHOLDCRUSADER 0x00402BD0 - undefined4 EntityState::angleToRotationFrameIndex(int angle) + int EntityState::angleToRotationFrameIndex(int angle) { if (angle <= 5) { if (angle <= -50) { diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp index 9be73583a0..f046c7b81d 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -199,7 +199,7 @@ namespace Map { this->entityArray[entityID].startingHeight_2 = sVar7; this->entityArray[entityID].height_2 = sVar7; this->entityArray[entityID].startingHeight = sVar7; - this->entityArray[entityID].unkMinusOne = 0; + this->entityArray[entityID].blendStrength = 0; /* sets DAT_TempBuildingOrientation */ diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index 85ff2a3a78..33512efc62 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -252,13 +252,13 @@ namespace Map { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( this->entityArray[DAT_CurrentEntityID::instance].microX, this->entityArray[DAT_CurrentEntityID::instance].microY, - this->entityArray[DAT_CurrentEntityID::instance].height, 5, + this->entityArray[DAT_CurrentEntityID::instance].height, (EntityType)5, this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue); } else { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect1, this)( this->entityArray[DAT_CurrentEntityID::instance].microX, this->entityArray[DAT_CurrentEntityID::instance].microY, - this->entityArray[DAT_CurrentEntityID::instance].height, 6, + this->entityArray[DAT_CurrentEntityID::instance].height, (EntityType)6, this->entityArray[DAT_CurrentEntityID::instance].gmID, this->entityArray[DAT_CurrentEntityID::instance].graphicType2); } diff --git a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp index 7ecc18a744..e923db68bf 100644 --- a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp @@ -23,21 +23,21 @@ namespace Map { short const fireParameter = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; if (fireParameter == 5) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 8; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 8; } else if (fireParameter == 4) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 9; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 9; } else if (fireParameter == 3) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 12; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 12; } else if (fireParameter == 2) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 14; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 14; } else { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 16; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 16; } DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x76; short const tracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; int frame = 0; if (tracker < 0) { - DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkMinusOne = 32; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 32; DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker + 1; frame = 1; From 05918840fa661b6dbfa22e23a46884dd3a386fa8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 23:37:30 +0100 Subject: [PATCH 37/51] reimplement: SHC_3BB0A8C1_0x004052E0 100% Reimplemented Pass the buildingID local to lightUpBuilding, and give IgniteFireAtMiniTile sight of getFireEntityIDAtTile: the original rematerialises buildingID from BuildingLayer after that call, which it can only do when it knows the callee leaves the layer alone. Measured 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS=ON (function-visibility.txt: IgniteFireAtMiniTile -> getFireEntityIDAtTile); the file is also in compiler-flags-gl.txt, where it measures 94.2%. getFireEntityIDAtTile is deliberately not added to compiler-flags-gl.txt: with it there, /GL gives IgniteFireAtMiniTile 100% too, but lightUpBuilding drops from 100% to 56%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- cmake/compiler-flags-gl.txt | 1 + cmake/function-visibility.txt | 2 ++ src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index f37be4a652..d32d982224 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -453,3 +453,4 @@ src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp src/OpenSHC/Map/Units/UpdateHealer.cpp src/OpenSHC/Map/Units/UpdateSpearman.cpp +src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp diff --git a/cmake/function-visibility.txt b/cmake/function-visibility.txt index b5531cf747..6a941bb236 100644 --- a/cmake/function-visibility.txt +++ b/cmake/function-visibility.txt @@ -360,3 +360,5 @@ OpenSHC::Map::Units::UpdateFireBallista OpenSHC::Map::Units::UnitsState::deselectUnit OpenSHC::Map::Units::UpdateHorseArcher OpenSHC::Map::Units::UnitsState::hasUnitReachedDestination +OpenSHC::Map::Entities::IgniteFireAtMiniTile + OpenSHC::Map::Entities::EntityState::getFireEntityIDAtTile diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index 308392cfc7..65e6c18824 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -63,7 +63,7 @@ namespace Map { } if (buildingID) { MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( - DAT_TileMapState::instance.BuildingLayer[tile], playerID, fireIntensity); + buildingID, playerID, fireIntensity); } if (DAT_TileMapState::instance.LogicLayer[tile] & 0x1000U) { MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID); diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 63b8cfbf75..ebfea78afc 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1623,7 +1623,7 @@ SHC_3BB0A8C1_0x00405125 | 0.0% | Pending SHC_3BB0A8C1_0x00405130 | 100.0% | Reimplemented (counted: only the constant 0x10300131 is shown as an address label in ours) -SHC_3BB0A8C1_0x004052E0 | 91.3% | orig spills the tile and keeps the height in ebx +SHC_3BB0A8C1_0x004052E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004054AC | 0.0% | Pending From deb67f688484b238dfa6c548f00fdd34946673dd Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 00:31:49 +0100 Subject: [PATCH 38/51] reimplement: SHC_3BB0A8C1_0x00405DA0 100% Reimplemented Straight-wall case moved to the top of the switch and the inner wall-flag arms reordered (the arm holding case 0 second), so the cross-jumped arms and the reflect-y block land where the original has them. Visibility-unit build mode, both resolver sets on: reccmp 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../spawnProjectileImpactDebris.cpp | 64 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp index 1fc2975d0b..28cf5ad4a0 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -24,17 +24,25 @@ namespace Map { uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, DAT_TileMapState::ptr)(microX / 8, microY / 8); switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + break; case 0x3d: y = 7 - y; if (x == y) { switch (wallFlags & 0xa) { + case 2: + x = 100; + break; case 0: case 8: y = 100; break; - case 2: - x = 100; - break; case 0xa: goto straight; } @@ -51,13 +59,13 @@ namespace Map { y = 7 - y; if (x == y) { switch (wallFlags & 0xa) { + case 2: + x = 100; + break; case 0: case 8: y = 100; break; - case 2: - x = 100; - break; case 0xa: goto straight; } @@ -96,13 +104,13 @@ namespace Map { case 0x41: if (x == y) { switch (wallFlags & 0x82) { + case 0x80: + x = 100; + break; case 0: case 2: y = 100; break; - case 0x80: - x = 100; - break; case 0x82: goto straight; } @@ -118,13 +126,13 @@ namespace Map { case 0x42: if (x == y) { switch (wallFlags & 0x82) { + case 0x80: + x = 100; + break; case 0: case 2: y = 100; break; - case 0x80: - x = 100; - break; case 0x82: goto straight; } @@ -163,13 +171,13 @@ namespace Map { x = 7 - x; if (x == y) { switch (wallFlags & 0xa0) { + case 0x20: + x = 100; + break; case 0: case 0x80: y = 100; break; - case 0x20: - x = 100; - break; case 0xa0: goto straight; } @@ -186,13 +194,13 @@ namespace Map { x = 7 - x; if (x == y) { switch (wallFlags & 0xa0) { + case 0x20: + x = 100; + break; case 0: case 0x80: y = 100; break; - case 0x20: - x = 100; - break; case 0xa0: goto straight; } @@ -257,13 +265,13 @@ namespace Map { y = 7 - y; if (x == y) { switch (wallFlags & 0x28) { + case 0x20: + x = 100; + break; case 0: case 8: y = 100; break; - case 0x20: - x = 100; - break; case 0x28: goto straight; } @@ -281,13 +289,13 @@ namespace Map { y = 7 - y; if (x == y) { switch (wallFlags & 0x28) { + case 0x20: + x = 100; + break; case 0: case 8: y = 100; break; - case 0x20: - x = 100; - break; case 0x28: goto straight; } @@ -300,14 +308,6 @@ namespace Map { targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; - case 0x3c: - case 0x40: - case 0x44: - case 0x48: - straight: - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].y_2; - break; } for (int i = 0; i < this->entityArray[param_1].rng_1 % 8 + 5; i++) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, microX, microY, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ebfea78afc..a981716b7b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -1707,7 +1707,7 @@ SHC_3BB0A8C1_0x00405C00 | 0.0% | Pending SHC_3BB0A8C1_0x00405CF0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405DA0 | 90.5% | Reflect-y arm laid out in the first case instead of after the straight case +SHC_3BB0A8C1_0x00405DA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0040612C | 0.0% | Pending From 8c1157b00695ff3113e62346d47ef279049532ed Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 00:31:50 +0100 Subject: [PATCH 39/51] reimplement: SHC_3BB0A8C1_0x00403FF0 100% Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) Same switch-arm order as spawnProjectileImpactDebris; the axis chain and the Bresenham steps read pathDeltaX/pathDeltaY from the entity instead of a short local, which gives the original's re-tests and reloads. reccmp 99.7%, the rest is the unresolved rdata constants and the CRT cos/sin names. Visibility-unit build mode, both resolver sets on. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../handleProjectileWallBounce.cpp | 226 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 109 insertions(+), 119 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp index a89269d88b..05b3b4d608 100644 --- a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -21,64 +21,67 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00403FF0 void EntityState::handleProjectileWallBounce(int param_1) { - short sVar4; - int iVar5; - short sVar7; - short sVar8; - int iVar9; int const microY = this->entityArray[param_1].microY; int const microX = this->entityArray[param_1].microX; int subX = microX & 7; - iVar5 = 0; - iVar9 = 0; + int targetX = 0; + int targetY = 0; int subY = microY & 7; uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, DAT_TileMapState::ptr)(microX / 8, microY / 8); switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + break; case 0x3d: subY = 7 - subY; if (subX == subY) { switch (wallFlags & 0xa) { + case 2: + subX = 100; + break; case 0: case 8: subY = 100; break; - case 2: - subX = 100; - break; case 0xa: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x3e: subY = 7 - subY; if (subX == subY) { switch (wallFlags & 0xa) { + case 2: + subX = 100; + break; case 0: case 8: subY = 100; break; - case 2: - subX = 100; - break; case 0xa: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x3f: @@ -97,55 +100,55 @@ namespace Map { } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x41: if (subX == subY) { switch (wallFlags & 0x82) { + case 0x80: + subX = 100; + break; case 0: case 2: subY = 100; break; - case 0x80: - subX = 100; - break; case 0x82: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x42: if (subX == subY) { switch (wallFlags & 0x82) { + case 0x80: + subX = 100; + break; case 0: case 2: subY = 100; break; - case 0x80: - subX = 100; - break; case 0x82: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x43: @@ -163,57 +166,57 @@ namespace Map { } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x45: subX = 7 - subX; if (subX == subY) { switch (wallFlags & 0xa0) { + case 0x20: + subX = 100; + break; case 0: case 0x80: subY = 100; break; - case 0x20: - subX = 100; - break; case 0xa0: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x46: subX = 7 - subX; if (subX == subY) { switch (wallFlags & 0xa0) { + case 0x20: + subX = 100; + break; case 0: case 0x80: subY = 100; break; - case 0x20: - subX = 100; - break; case 0xa0: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x47: @@ -232,11 +235,11 @@ namespace Map { } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x49: @@ -256,11 +259,11 @@ namespace Map { } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x4a: @@ -268,23 +271,23 @@ namespace Map { subY = 7 - subY; if (subX == subY) { switch (wallFlags & 0x28) { + case 0x20: + subX = 100; + break; case 0: case 8: subY = 100; break; - case 0x20: - subX = 100; - break; case 0x28: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; case 0x4b: @@ -292,80 +295,67 @@ namespace Map { subY = 7 - subY; if (subX == subY) { switch (wallFlags & 0x28) { + case 0x20: + subX = 100; + break; case 0: case 8: subY = 100; break; - case 0x20: - subX = 100; - break; case 0x28: goto straight; } } if (subX > subY) { - iVar5 = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; } else { - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; } break; - case 0x3c: - case 0x40: - case 0x44: - case 0x48: - straight: - iVar5 = this->entityArray[param_1].x_2; - iVar9 = this->entityArray[param_1].y_2; - break; } MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, - DAT_DirectionAlgorithmState::ptr)(microX, microY, iVar5, iVar9); + DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); this->entityArray[param_1].orientation = DAT_DirectionAlgorithmState::instance.orientation; - if (microY > iVar9) { - this->entityArray[param_1].pathDeltaY = (short)(microY - iVar9); + if (microY > targetY) { + this->entityArray[param_1].pathDeltaY = (short)(microY - targetY); } else { - this->entityArray[param_1].pathDeltaY = (short)(iVar9 - microY); + this->entityArray[param_1].pathDeltaY = (short)(targetY - microY); } - if (microX > iVar5) { - this->entityArray[param_1].pathDeltaX = (short)(microX - iVar5); + if (microX > targetX) { + this->entityArray[param_1].pathDeltaX = (short)(microX - targetX); } else { - this->entityArray[param_1].pathDeltaX = (short)(iVar5 - microX); + this->entityArray[param_1].pathDeltaX = (short)(targetX - microX); } - sVar8 = this->entityArray[param_1].pathDeltaX; - this->entityArray[param_1].pathTargetX = (short)iVar5; - this->entityArray[param_1].someMicroX = microX <= iVar5 ? 1 : -1; - this->entityArray[param_1].pathTargetY = (short)iVar9; - this->entityArray[param_1].someMicroY = microY <= iVar9 ? 1 : -1; - if (sVar8 == 0 && this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathTargetX = (short)targetX; + this->entityArray[param_1].someMicroX = microX <= targetX ? 1 : -1; + this->entityArray[param_1].pathTargetY = (short)targetY; + this->entityArray[param_1].someMicroY = microY <= targetY ? 1 : -1; + if (this->entityArray[param_1].pathDeltaX == 0 && this->entityArray[param_1].pathDeltaY == 0) { this->entityArray[param_1].pathAxisCase = 0; - } else if (sVar8 == 0) { + } else if (this->entityArray[param_1].pathDeltaX == 0) { this->entityArray[param_1].pathAxisCase = 1; } else if (this->entityArray[param_1].pathDeltaY == 0) { this->entityArray[param_1].pathAxisCase = 2; - } else if (this->entityArray[param_1].pathDeltaY > sVar8) { + } else if (this->entityArray[param_1].pathDeltaY > this->entityArray[param_1].pathDeltaX) { this->entityArray[param_1].pathAxisCase = 3; } else { this->entityArray[param_1].pathAxisCase = 4; } - sVar4 = this->entityArray[param_1].pathAxisCase; - if (sVar4 == 3) { - int const deltaY = this->entityArray[param_1].pathDeltaY; - int const straight = sVar8 * 2; - this->entityArray[param_1].pathErrorStepStraight = straight; - sVar7 = straight - deltaY * 2; - this->entityArray[param_1].pathError = straight - deltaY; - } else { - if (sVar4 != 4) - goto LAB_0040440f; - int const straight = this->entityArray[param_1].pathDeltaY * 2; - this->entityArray[param_1].pathErrorStepStraight = straight; - sVar7 = straight - sVar8 * 2; - this->entityArray[param_1].pathError = straight - sVar8; + if (this->entityArray[param_1].pathAxisCase == 3) { + this->entityArray[param_1].pathErrorStepStraight = this->entityArray[param_1].pathDeltaX * 2; + this->entityArray[param_1].pathErrorStepDiagonal + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathError + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaY; + } else if (this->entityArray[param_1].pathAxisCase == 4) { + this->entityArray[param_1].pathErrorStepStraight = this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathErrorStepDiagonal + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaX * 2; + this->entityArray[param_1].pathError + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaX; } - this->entityArray[param_1].pathErrorStepDiagonal = sVar7; - LAB_0040440f: word const rotation = this->entityArray[param_1].graphicRotationUnk; this->entityArray[param_1].startingAngle = rotation; if ((short)rotation < -80) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a981716b7b..93634638f0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -545,7 +545,7 @@ SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403A20 | 92.9% | case 4 divides by a magic multiply, case 1 call tail-merged into case 2 -SHC_3BB0A8C1_0x00403FF0 | 88.2% | Axis chain keeps deltaX/deltaY in registers the original re-tests and reloads +SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) SHC_3BB0A8C1_0x004044E4 | 0.0% | Pending From 69624a23627da55cfe1d0bd254788d397591c749 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 00:34:42 +0100 Subject: [PATCH 40/51] reimplement: SHC_3BB0A8C1_0x00403A20 100% Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) Case 4 reads rng_1 from the entity for the modulo, so both % 20 stay idiv against edi as in the original instead of a magic multiply, and vCos/vSin read velocityUnk from the entity so the int-to-double temp shares the y parameter slot. reccmp 98.5%, the rest is the unresolved rdata constants and the CRT cos/sin names. Visibility-unit build mode, both resolver sets on. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../EntityState/initializeProjectileVelocities.cpp | 14 ++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index f1a4fc7692..b3062f084f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -115,13 +115,12 @@ namespace Map { this->entityArray[entityID].startingAngle = (rng & 0xf) + 8; this->entityArray[entityID].velocityUnk = (rng & 7) + 0x15; } else if (curveType == 4) { - int const rng = this->entityArray[entityID].rng_1; - this->entityArray[entityID].startingAngle = (short)(rng % 20 + 16); - if (rng & 0x80) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 20 + 16); + if (this->entityArray[entityID].rng_1 & 0x80) { this->entityArray[entityID].startingAngle = -this->entityArray[entityID].startingAngle; } - this->entityArray[entityID].velocityUnk = (short)((rng >> 8) % 20 + 16); - if (rng & 0x8000) { + this->entityArray[entityID].velocityUnk = (short)((this->entityArray[entityID].rng_1 >> 8) % 20 + 16); + if (this->entityArray[entityID].rng_1 & 0x8000) { this->entityArray[entityID].velocityUnk = -this->entityArray[entityID].velocityUnk; } return; @@ -175,11 +174,10 @@ namespace Map { } int const angle = this->entityArray[entityID].startingAngle; this->entityArray[entityID].speedUnk = 0; - int const velocity = this->entityArray[entityID].velocityUnk; this->entityArray[entityID].travelledDistance = 0; double const radians = (double)angle * 3.1415926535 / 180.0; - this->entityArray[entityID].vCos = (float)(cos(radians) * (double)velocity); - this->entityArray[entityID].vSin = (float)(sin(radians) * (double)velocity); + this->entityArray[entityID].vCos = (float)(cos(radians) * (double)this->entityArray[entityID].velocityUnk); + this->entityArray[entityID].vSin = (float)(sin(radians) * (double)this->entityArray[entityID].velocityUnk); this->entityArray[entityID].rotationFrameIndex = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 93634638f0..2663cf7a11 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 92.9% | case 4 divides by a magic multiply, case 1 call tail-merged into case 2 +SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) From 506a560b65f86c440d488879e7b25d3c7c0919de Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 00:42:04 +0100 Subject: [PATCH 41/51] reimplement: SHC_3BB0A8C1_0x00402180 100% Reimplemented The entity index local is int, not uint; with it the graphicType2RelatedOffset load is scheduled after the division and needs no ebx. Visibility-unit build mode, both resolver sets on: reccmp 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp index 9f931730d7..a55b80959d 100644 --- a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -10,7 +10,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00402180 void Entities::UpdateEntity_CowFlying() { - uint const entityID = DAT_CurrentEntityID::instance; + int const entityID = DAT_CurrentEntityID::instance; if (DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround != 0) { if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated < 100) { DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 100; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2663cf7a11..93b89776aa 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -469,7 +469,7 @@ SHC_3BB0A8C1_0x00401EA0 | 0.0% | Pending SHC_3BB0A8C1_0x00401FF0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402180 | 90.5% | Offset load scheduled before the division +SHC_3BB0A8C1_0x00402180 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00402260 | 0.0% | Pending From 19f8b63f57b78107c73558b4258cbcc4486a3a30 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 08:34:10 +0100 Subject: [PATCH 42/51] reimplement: SHC_3BB0A8C1_0x004036F0 100% Reimplemented The unrotated arm doubles x first, as a shift (x << 1), then shifts y; the original computes x*2 before y<<4 there. tuple_dump showed the IL already held y<<4 first, so the order is the source's, not the scheduler's. Measured with both resolver sets, full build + reccmp. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Entities/EntityState/calculateEntityDrawOffset.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index 4114d45b7c..9302030f8b 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -32,8 +32,8 @@ namespace Map { goto lookup; } } + x = x << 1; y = y << 4; - x = x * 2; lookup: this->entityArray[entityID].x1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x].x; this->entityArray[entityID].y1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x + 1].x; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 93b89776aa..c4da587b2a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -527,7 +527,7 @@ SHC_3BB0A8C1_0x00402E20 | 37.1% | loop bodies split out of line in the original, SHC_3BB0A8C1_0x00403200 | 0.0% | Pending -SHC_3BB0A8C1_0x004036F0 | 98.0% | Default arm scales x and y in the opposite order +SHC_3BB0A8C1_0x004036F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403790 | 100.0% | Pending From 93c7619632dfbaebf593858503beab23a1295914 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:10:10 +0100 Subject: [PATCH 43/51] reimplement: SHC_3BB0A8C1_0x00407190 80.8% entityType cached in ebp after the field re-read; rock-arm register naming The unit-hit test reads the entity's type from the field for its first compare. With the local there, MSVC threads the rng_2 != 2 edge past the type tests (it knows type == 1), so FgCodeMotion pulled the cloud code up and pushed both unit loops after the fire-arrow arm. Reading the field keeps the original's inline layout. The field and the local hold the same value here: nothing writes entityType on this path. Measured with both resolver sets, full build + reccmp. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Entities/EntityState/processEntityHitBuildingOrUnit.cpp | 6 +++--- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index 2dc7a09e1e..097ea626e8 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -142,9 +142,9 @@ namespace Map { { int unit = DAT_TileMapState::instance.UnitLayer[tile]; if (entityType != Map::Entities::ET_ARROW_AND_DEFAULT || this->entityArray[entityID].rng_2 != 2) { - if (entityType == Map::Entities::ET_COW_POISON_CLOUD || entityType == Map::Entities::ET_TREBUCHET - || entityType == Map::Entities::ET_CATAPULT || entityType == Map::Entities::ET_MANGONEL - || this->entityArray[entityID].velocityUnk > 80) { + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD + || entityType == Map::Entities::ET_TREBUCHET || entityType == Map::Entities::ET_CATAPULT + || entityType == Map::Entities::ET_MANGONEL || this->entityArray[entityID].velocityUnk > 80) { for (; unit != 0; unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { if (this->entityArray[entityID].logicalState == 2 && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c4da587b2a..70989136ab 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 80.0% | unit-hit loops laid out after the fire-arrow arm; rock-arm register naming +SHC_3BB0A8C1_0x00407190 | 80.8% | entityType cached in ebp after the field re-read; rock-arm register naming SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From e0cb24e5b8ef66b4bf5b2bf68ef073bd74a1d3a2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 14:00:34 +0100 Subject: [PATCH 44/51] reimplement: SHC_3BB0A8C1_0x00406900 87.3% newY takes ebp where the original keeps newMicroX; microY CSE kept in a register One radians variable reused for both angles, as the original's shared [esp+0x1c] slot shows: frame 0x24 -> 0x20. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp | 8 ++++---- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index 504bd8798a..e3b67afed8 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -74,7 +74,7 @@ namespace Map { } } } - double const radians = (this->seagullArray[seagullID].angle - 180) * 3.1415926535 / 180.0; + double radians = (this->seagullArray[seagullID].angle - 180) * 3.1415926535 / 180.0; this->seagullArray[seagullID].angle = this->seagullArray[seagullID].someAngle * 20 + this->seagullArray[seagullID].angle; if (this->seagullArray[seagullID].angle >= 360) { @@ -126,7 +126,7 @@ namespace Map { double const radius = this->seagullArray[seagullID].unknownCounter_0x16; int const circleX = (long)(sin(radians) * radius); int const circleY = (long)(cos(radians) * radius); - double const radians2 = (this->seagullArray[seagullID].angle_2 - 180) * 3.1415926535 / 180.0; + radians = (this->seagullArray[seagullID].angle_2 - 180) * 3.1415926535 / 180.0; this->seagullArray[seagullID].angle_2 = this->seagullArray[seagullID].angleStep + this->seagullArray[seagullID].angle_2; if (this->seagullArray[seagullID].angle_2 >= 360) { @@ -137,9 +137,9 @@ namespace Map { } double const radius2 = this->seagullArray[seagullID].numberBetween60And100; this->seagullArray[seagullID].x_2 - = (short)(long)(sin(radians2) * radius2) + this->seagullArray[seagullID].x; + = (short)(long)(sin(radians) * radius2) + this->seagullArray[seagullID].x; this->seagullArray[seagullID].y_2 - = (short)(long)(cos(radians2) * radius2) + this->seagullArray[seagullID].y; + = (short)(long)(cos(radians) * radius2) + this->seagullArray[seagullID].y; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)(entityID, this->entityArray[entityID].microX, this->entityArray[entityID].microY, this->entityArray[entityID].height, this->seagullArray[seagullID].x_2 + circleX, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 70989136ab..87c9f5c440 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIsin, _CIcos, _ftol2_sse) differ) -SHC_3BB0A8C1_0x00406900 | 81.2% | microY kept across the RNG test where the original rereads it (frame 0x24 vs 0x20) +SHC_3BB0A8C1_0x00406900 | 87.3% | newY takes ebp where the original keeps newMicroX; microY CSE kept in a register SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending From daf0c69ff04659bf7e86c37f2e03691a72d208af Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 14:41:22 +0100 Subject: [PATCH 45/51] reimplement: SHC_3BB0A8C1_0x00402E20 57.8% loop layout matches; height enregistered and clearance in esi instead of ebp Set-up chain first, then a mode dispatch to the four loops. Jump threading removes the dispatch after DFO has placed the loops after all preludes, which gives the original's heads-first, bodies-after-returns layout. Clearance arms flipped so clearance-- falls through. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../computeLineOfSightDistance.cpp | 302 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 155 insertions(+), 149 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp index 1f889fbbeb..3d3f1e226e 100644 --- a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -26,11 +26,11 @@ namespace Map { if (height > targetHeight + 54) { clearance = 100; } + int curX = x; + int curY = y; int const tileX = x / 8; int const tileY = y / 8; int const startTile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX; - int curX = x; - int curY = y; if (DAT_TileMapState::instance.LogicLayer[startTile] & 0x10000000) { height = height + 10; } @@ -51,6 +51,11 @@ namespace Map { } int const stepX = x <= targetX ? 1 : -1; int const stepY = y <= targetY ? 1 : -1; + int twoD; + int error; + int diagStep; + // Set-up and stepping are two separate dispatches; mode picks the stepping loop. + int mode; if (dX == 0) { if (dY != 0) { if (clearance >= 28) { @@ -58,48 +63,15 @@ namespace Map { } this->lineOfSightClearanceSteps = clearance; clearance = clearance / 2; - for (steps = 0; steps < 1000; steps++) { - curY += stepY; - if ((steps & 1) && param_7 == 0) { - int const tile - = DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile + tileX; - if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { - clear = FALSE; - this->lineOfSightClearanceSteps = steps; - } - if (clearance == 0) { - if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; - } - } - } else if (blocked - && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; - } - } else { - clearance--; - } - lastTile = tile; - } - if (x == targetX && curY == targetY) { - break; - } - } + mode = 0; + } else { + mode = 4; } } else if (dY != 0) { if (dY > dX) { - int const twoDX = dX * 2; - int error = twoDX - dY; - int const diagStep = twoDX - dY * 2; + twoD = dX * 2; + error = twoD - dY; + diagStep = twoD - dY * 2; if (height > targetHeight && clearance != 0) { int n = abs(targetY - y) / 8 - 1; if (n > 4) { @@ -118,52 +90,11 @@ namespace Map { } this->lineOfSightClearanceSteps = clearance; clearance = clearance / 2; - for (steps = 0; steps < 1000; steps++) { - curY += stepY; - if (error > 0) { - curX += stepX; - error += diagStep; - } else { - error += twoDX; - } - if ((steps & 1) && param_7 == 0) { - int const tile - = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; - if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { - clear = FALSE; - this->lineOfSightClearanceSteps = steps; - } - if (clearance == 0) { - if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; - } - } - } else if (blocked - && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { - return 0; - } - } else { - clearance--; - } - lastTile = tile; - } - if (curX == targetX && curY == targetY) { - break; - } - } + mode = 1; } else { - int const twoDY = dY * 2; - int const diagStep = twoDY - dX * 2; - int error = twoDY - dX; + twoD = dY * 2; + diagStep = twoD - dX * 2; + error = twoD - dX; if (height > targetHeight && clearance != 0) { int n = abs(targetX - x) / 8 - 1; if (n > 4) { @@ -181,48 +112,7 @@ namespace Map { } this->lineOfSightClearanceSteps = clearance; clearance = clearance / 2; - for (steps = 0; steps < 1000; steps++) { - curX += stepX; - if (error > 0) { - curY += stepY; - error += diagStep; - } else { - error += twoDY; - } - if ((steps & 1) && param_7 == 0) { - int const tile - = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; - if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { - clear = FALSE; - this->lineOfSightClearanceSteps = steps; - } - if (clearance == 0) { - if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; - } - } - } else if (blocked - && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; - } - } else { - clearance--; - } - lastTile = tile; - } - if (curX == targetX && curY == targetY) { - break; - } - } + mode = 2; } } else { if (clearance >= 28) { @@ -230,6 +120,10 @@ namespace Map { } this->lineOfSightClearanceSteps = clearance; clearance = clearance / 2; + mode = 3; + } + + if (mode == 3) { for (steps = 0; steps < 1000; steps++) { curX += stepX; if ((steps & 1) && param_7 == 0) { @@ -239,25 +133,23 @@ namespace Map { clear = FALSE; this->lineOfSightClearanceSteps = steps; } - if (clearance == 0) { - if (lastTile != tile) { - blocked = FALSE; - uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; - if ((flags & 0x80) != 0 - || (building != DAT_TileMapState::instance.BuildingLayer[tile] - && (!clear || !(flags & 0x400200)))) { - blocked = TRUE; - lastHeight = MACRO_CALL_MEMBER( - Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); - if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; - } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } - } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { - return 0; } - } else { - clearance--; + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; } lastTile = tile; } @@ -265,10 +157,124 @@ namespace Map { break; } } + } else if (mode == 0) { + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if ((steps & 1) && param_7 == 0) { + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile + tileX; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (x == targetX && curY == targetY) { + break; + } + } + } else if (mode == 2) { + for (steps = 0; steps < 1000; steps++) { + curX += stepX; + if (error > 0) { + curY += stepY; + error += diagStep; + } else { + error += twoD; + } + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (curX == targetX && curY == targetY) { + break; + } + } + } else if (mode == 1) { + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if (error > 0) { + curX += stepX; + error += diagStep; + } else { + error += twoD; + } + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (curX == targetX && curY == targetY) { + break; + } + } } return steps; } - } -} -} + } // namespace Entities +} // namespace Map +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 87c9f5c440..742e4ce3d4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param s SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CItan, _CIsqrt) differ) -SHC_3BB0A8C1_0x00402E20 | 37.1% | loop bodies split out of line in the original, ours contiguous +SHC_3BB0A8C1_0x00402E20 | 57.8% | loop layout matches; height enregistered and clearance in esi instead of ebp SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From 4cb0a6fca1e6b72f2afc9a4a0b397a30457a69d2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 04:42:31 +0100 Subject: [PATCH 46/51] status: SHC_3BB0A8C1_0x004084A0 93.1% after the main merge moveProjectileEntity gains from main's _ftol2_sse, 180.0 and pi rows (90.1 -> 93.1). Operand-order and declaration-order variants of the atan argument all stay at quick_diff 0.9544; the remaining gaps are the x87 order, a loop-top pad that depends on the function's address, and four constants (0x59e898 4.906, 0x59e890 0.25, 0x59e880 3.0, 0x57ee10 __CIatan) that need float-literals.csv rows; with them it reads 94.8. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5ac9a3bdc2..01ac0a8f9d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2449,7 +2449,7 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 90.1% | atan arm x87 fxch scheduling; unresolved rdata constants and CRT calls +SHC_3BB0A8C1_0x004084A0 | 93.1% | x87 operand order in the atan argument; loop-top alignment pad from the function address; 4.906, 0.25, 3.0 and __CIatan need float-literals.csv rows (94.8 with them) SHC_3BB0A8C1_0x00408770 | 0.0% | Pending From 2971ce9b9933b5f0f49c7b261569b2ed1cb632bc Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 04:42:31 +0100 Subject: [PATCH 47/51] reimplement: SHC_3BB0A8C1_0x00406900 90.8% microY read through a reference The original reloads microY for newMicroY instead of keeping the value from the abs() test; a read through a reference is not merged with the direct one (cheat sheet). newMicroX is computed first, as the original loads someMicroX before dividing newMicroY. 90.0 -> 90.8; newY still takes ebp where the original keeps newMicroX. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp | 5 +++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp index e3b67afed8..509fd382be 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -45,9 +45,10 @@ namespace Map { ^ SEC_RNG::instance.currentNumber2) % 500 == 123) { - int const newMicroY = this->entityArray[entityID].someMicroY + this->entityArray[entityID].microY; - int const newY = newMicroY / 8; int const newMicroX = this->entityArray[entityID].someMicroX + this->entityArray[entityID].microX; + short const& microYRef = this->entityArray[entityID].microY; + int const newMicroY = this->entityArray[entityID].someMicroY + microYRef; + int const newY = newMicroY / 8; int const newX = newMicroX / 8; if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)(newX, newY)) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 01ac0a8f9d..b538770bea 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00406900 | 87.3% | newY takes ebp where the original keeps newMicroX; microY CSE kept in a register +SHC_3BB0A8C1_0x00406900 | 90.8% | newY takes ebp where the original spills it and keeps newMicroX in ebp; the microY reload comes from reading it through a reference SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending From 234af6c99e1162da0bfbe633489096325efdda6f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 04:57:35 +0100 Subject: [PATCH 48/51] reimplement: SHC_3BB0A8C1_0x00407190 84.2% entityType switch, no cached local The original reads entityType at the seagull test and keeps it in ecx only up to a switch on the flag, brazier and heads-on-spikes types (add eax, -0xa; cmp eax, 5 is a switch range check); later tests re-read the field. Without the long-lived local, this and tile get ebx and ebp as in the original and edi is no longer saved in the prologue. 80.8 -> 84.2. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processEntityHitBuildingOrUnit.cpp | 20 +++++++++++++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp index 097ea626e8..0113db724f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -50,10 +50,9 @@ namespace Map { uint const y = this->entityArray[entityID].yPosition; uint const x = this->entityArray[entityID].xPosition; int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; - short const entityType = this->entityArray[entityID].entityType; int result = 1; this->entityArray[entityID].tile = tile; - if (entityType == Map::Entities::ET_SEAGULLUnk) { + if (this->entityArray[entityID].entityType == Map::Entities::ET_SEAGULLUnk) { if (x <= 399 && y <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] != 0 && !(DAT_TileMapState::instance.LogicLayer[tile] & 0x30) && this->entityArray[entityID].height > 0) { @@ -76,7 +75,13 @@ namespace Map { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); return 0; } - if ((uint)(entityType - 10) <= 5) { + switch (this->entityArray[entityID].entityType) { + case Map::Entities::ET_FLAG_1: + case Map::Entities::ET_FLAG_4: + case Map::Entities::ET_FLAG_2: + case Map::Entities::ET_FLAG_3: + case Map::Entities::ET_BRAZIER: + case Map::Entities::ET_HEADS_ON_SPIKES: DAT_TileMapState::instance.MiscDisplayLayer[tile] = DAT_TileMapState::instance.MiscDisplayLayer[tile] | 0x1000; if (this->entityArray[entityID].entityType != Map::Entities::ET_BRAZIER @@ -141,10 +146,13 @@ namespace Map { } { int unit = DAT_TileMapState::instance.UnitLayer[tile]; - if (entityType != Map::Entities::ET_ARROW_AND_DEFAULT || this->entityArray[entityID].rng_2 != 2) { + if (this->entityArray[entityID].entityType != Map::Entities::ET_ARROW_AND_DEFAULT + || this->entityArray[entityID].rng_2 != 2) { if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD - || entityType == Map::Entities::ET_TREBUCHET || entityType == Map::Entities::ET_CATAPULT - || entityType == Map::Entities::ET_MANGONEL || this->entityArray[entityID].velocityUnk > 80) { + || this->entityArray[entityID].entityType == Map::Entities::ET_TREBUCHET + || this->entityArray[entityID].entityType == Map::Entities::ET_CATAPULT + || this->entityArray[entityID].entityType == Map::Entities::ET_MANGONEL + || this->entityArray[entityID].velocityUnk > 80) { for (; unit != 0; unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { if (this->entityArray[entityID].logicalState == 2 && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b538770bea..1e27e9bf28 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 80.8% | entityType cached in ebp after the field re-read; rock-arm register naming +SHC_3BB0A8C1_0x00407190 | 84.2% | register rotation in the height arms (the original keeps both plain HeightLayer stores, we tail-merge them); unit-loop entry jumps SHC_3BB0A8C1_0x00407570 | 0.0% | Pending From 5c73e5e6d5e3845c186056e6eb06b84106d56812 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 04:59:06 +0100 Subject: [PATCH 49/51] status: SHC_3BB0A8C1_0x00402C50 72.6% after the main merge math_atan_1 gains from main's _CIsqrt, _ftol2_sse, 9.812, 180.0 and pi rows (66.0 -> 72.6); with rows for 0x59e860 96.275344, 0x59e858 1.0, 0x59e840 0.4999, 0x57ecf1 _isnan and 0x57ee10 __CIatan it reads 79.2. Expression, declaration and local-vs-parameter variants all leave the spill slots unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1e27e9bf28..7076b4291b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -519,7 +519,7 @@ SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402C50 | 66.0% | scaled ints spilled to a temp, not the param slots; CRT and rdata constants unresolved +SHC_3BB0A8C1_0x00402C50 | 72.6% | the original spills param_4 * 4 and heightDifference / 2 into their own parameter slots (fild/fimul from [ebp+0x14]/[ebp+0x18]), we use a temp; 96.275344, 1.0, 0.4999 and __isnan/__CIatan need float-literals.csv rows (79.2 with them) SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented From b6ee8ebbf1a73ca2dd08243381374a77bf53c34c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 06:23:02 +0100 Subject: [PATCH 50/51] status: SHC_3BB0A8C1_0x00402E20 57.8%, dispatch rewrite measured Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7076b4291b..bce30e3288 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -523,7 +523,7 @@ SHC_3BB0A8C1_0x00402C50 | 72.6% | the original spills param_4 * 4 and heightDiff SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402E20 | 57.8% | loop layout matches; height enregistered and clearance in esi instead of ebp +SHC_3BB0A8C1_0x00402E20 | 57.8% | frame/register allocation: the original keeps clearance in ebp and adds 10 to height in its parameter slot, ours keeps height in ebp; slot order differs (slot_map: ours 19 slots, original 17). The separate set-up/stepping dispatch is right: inlining each stepping loop into its set-up branch drops to 32.6, because the original lays the loop bodies out in dispatch order 3, 0, 2, 1 SHC_3BB0A8C1_0x00403200 | 0.0% | Pending From 01749f01f4a72e5042e88c47e1fd72a78587fba0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 10:25:46 +0100 Subject: [PATCH 51/51] status: math_atan_1 79.2%, moveProjectileEntity 94.8% with the float-literal rows Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bce30e3288..706b969265 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -519,7 +519,7 @@ SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402C50 | 72.6% | the original spills param_4 * 4 and heightDifference / 2 into their own parameter slots (fild/fimul from [ebp+0x14]/[ebp+0x18]), we use a temp; 96.275344, 1.0, 0.4999 and __isnan/__CIatan need float-literals.csv rows (79.2 with them) +SHC_3BB0A8C1_0x00402C50 | 79.2% | the original spills param_4 * 4 and heightDifference / 2 into their own parameter slots (fild/fimul from [ebp+0x14]/[ebp+0x18]), we use a temp SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented @@ -2449,7 +2449,7 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 93.1% | x87 operand order in the atan argument; loop-top alignment pad from the function address; 4.906, 0.25, 3.0 and __CIatan need float-literals.csv rows (94.8 with them) +SHC_3BB0A8C1_0x004084A0 | 94.8% | x87 operand order in the atan argument; loop-top alignment pad from the function address SHC_3BB0A8C1_0x00408770 | 0.0% | Pending