From 0cb22d2324ecf13868e43689f86cae780fb3cd11 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 13:56:14 +0100 Subject: [PATCH 01/43] Copy 11 functions from gynt's catch-all branches to reimpl/landscape-wildlife-development 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 (11) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 48 +++ src/OpenSHC/Map/LandscapeState/createTree.cpp | 186 ++++++++++ .../spawnCrowFromNearbyTree.cpp | 157 +++++++++ .../Map/LandscapeState/updateTreeStage.cpp | 115 +++++++ .../buildRallyPointPathForTribe.cpp | 247 +++++++++++++ ...findAndSetNewRallyPointForDeerAndLions.cpp | 216 ++++++++++++ .../WildlifeState/renderDebugDataMapData.cpp | 226 ++++++++++++ .../Map/WildlifeState/updateNofFpoints.cpp | 267 ++++++++++++++ .../WildlifeState/updateSection1034Info.cpp | 85 +++++ .../Map/WildlifeState/updateWildlife.cpp | 88 +++++ .../Map/WildlifeState/updateWildlifeGrid.cpp | 325 ++++++++++++++++++ 11 files changed, 1960 insertions(+) create mode 100644 src/OpenSHC/Map/LandscapeState/createRock.cpp create mode 100644 src/OpenSHC/Map/LandscapeState/createTree.cpp create mode 100644 src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp create mode 100644 src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/updateWildlife.cpp create mode 100644 src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp new file mode 100644 index 0000000000..1f11a840bb --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -0,0 +1,48 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentRockID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F2140 + int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) + { + short* _pRock; + int _rockID; + _rockID = 1; + /* + the while loop finds the spot to write this tree data + */ + _pRock = &this->rocks[1].one; + do { + if (*_pRock == 0) + break; + if (3999 < _rockID) { + return 0; + } + _rockID = _rockID + 1; + _pRock = _pRock + 0x10; + } while (_rockID < 4000); + this->rocks[_rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + this->rocks[_rockID].size = (short)size; + this->rocks[_rockID].y = (ushort)y; + this->rocks[_rockID].x = (ushort)x; + this->rocks[_rockID].one = 1; + this->rocks[_rockID].type = (short)rockType; + this->rocks[_rockID].tile + = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; + this->rocks[_rockID].orientation = (short)orientation; + this->rocks[_rockID].unknownGMID = (short)DAT_OrganismDefinedData::instance.Rock_field0xe[rockType]; + DAT_CurrentRockID::instance = _rockID; + (*DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[_rockID].type])(); + return _rockID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/createTree.cpp b/src/OpenSHC/Map/LandscapeState/createTree.cpp new file mode 100644 index 0000000000..17372578a9 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/createTree.cpp @@ -0,0 +1,186 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTreeID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" + +namespace OpenSHC { +namespace Map { + using Map::Trees::TreeTypeShort; + + + // FUNCTION: STRONGHOLDCRUSADER 0x004F1CE0 + int LandscapeState::createTree(undefined4 x, undefined4 y, TreeType treeType, undefined4 size, + int stageRelatedValue, undefined4 param_6, int stage) + { + undefined2 uVar1; + short sVar2; + undefined4 uVar3; + Tree* _ptrState; + uint uVar4; + uint _tile; + int _treeID; + /* + *** Find a free tree slot *** + */ + _treeID = 1; + _ptrState = &this->trees[1]; + do { + if (!_ptrState->state) + break; + if (1999 < _treeID) { + return 0; + } + _treeID = _treeID + 1; + _ptrState = _ptrState + 0x4e; + } while (_treeID < 2000); + /* + *** Increment the max tree count on this map *** + */ + if (this->maxTreeCount <= _treeID) { + this->maxTreeCount = _treeID + 1; + } + /* + *** Assign uid to tree *** + */ + this->trees[_treeID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + /* + *** Set initial state of tree *** + */ + if (((int)treeType < 0x10) || (0x13 < (int)treeType)) { + this->trees[_treeID].state = 1; + } else { + this->trees[_treeID].state = 4; + } + /* + *** Set (initial) values for tree *** + */ + this->trees[_treeID].size = (short)size; + this->trees[_treeID].xPosition = (ushort)x; + this->trees[_treeID].yPosition = (ushort)y; + this->trees[_treeID].treeType = (TreeTypeShort)treeType; + _tile + = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; + this->trees[_treeID].microX = (ushort)x * 8 + 3; + this->trees[_treeID].microY = (ushort)y * 8 + 3; + this->trees[_treeID].tile = _tile; + this->trees[_treeID].rng1 = DAT_TileMapState::instance.RandomLayer[_tile] & 0x7ff; + this->trees[_treeID].appleTreeColorVariation = stageRelatedValue; + this->trees[_treeID].param_6 = (short)param_6; + this->trees[_treeID].treeTypeBasedValue1 + = (short)DAT_OrganismDefinedData::instance.TreeTypeBasedValueMapping[treeType]; + uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated1[treeType][stage]; + this->trees[_treeID].stageRelated4 = uVar1; + this->trees[_treeID].treeAdultHoodStageRelatedVisual3 = uVar1; + uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated2[treeType][stage]; + this->trees[_treeID].stageRelated2 = uVar1; + this->trees[_treeID].stageRelated1 = uVar1; + sVar2 = this->trees[_treeID].treeTypeBasedValue1; + this->trees[_treeID].gmOriginX + = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originX; + this->trees[_treeID].gmOriginY + = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originY; + this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field28_0x854[treeType]; + this->trees[_treeID].zero = 0; + this->trees[_treeID].animationFrameIndex = (byte)DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f; + this->trees[_treeID].one = 1; + this->trees[_treeID].stage = stage; + this->trees[_treeID].stageTracker = DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][stage]; + DAT_CurrentTreeID::instance = _treeID; + /* + *** Set tree type dependent values *** + */ + switch (treeType) { + case ((TreeType)1): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (0xe < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 4; + break; + } + if (0xc < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 6; + break; + } + if (10 < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 1; + break; + } + if (uVar4 < 9) + break; + goto LAB_004f1fb5; + case ((TreeType)2): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (8 < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 8; + } + break; + case ((TreeType)3): + this->trees[_treeID].appleTreeColorVariation = _treeID % 9; + break; + case ((TreeType)4): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (uVar4 < 0xf) { + if (uVar4 < 0xd) { + if (uVar4 < 0xb) { + if (8 < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 0; + } + } else { + this->trees[_treeID].appleTreeColorVariation = 1; + } + } else { + this->trees[_treeID].appleTreeColorVariation = 6; + } + } else { + this->trees[_treeID].appleTreeColorVariation = 4; + } + if (this->trees[_treeID].appleTreeColorVariation < 9) + break; + goto LAB_004f1fb5; + case ((TreeType)5): + case ((TreeType)10): + case ((TreeType)0x10): + case ((TreeType)0x11): + case ((TreeType)0x12): + case ((TreeType)0x13): + this->trees[_treeID].stage = 4; + LAB_004f1fb5: + this->trees[_treeID].appleTreeColorVariation = 0; + break; + case ((TreeType)6): + this->trees[_treeID].appleTreeColorVariation = 3; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)7): + this->trees[_treeID].appleTreeColorVariation = 4; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)8): + this->trees[_treeID].appleTreeColorVariation = 7; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)9): + this->trees[_treeID].appleTreeColorVariation = 8; + this->trees[_treeID].stage = 4; + } + uVar3 = this->field0_0x0; + this->field0_0x0 = 0; + /* + *** Update the tree state *** + */ + (*DAT_OrganismDefinedData::instance.UpdateTree[(short)this->trees[_treeID].treeType])(); + this->field0_0x0 = uVar3; + return _treeID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp new file mode 100644 index 0000000000..4f3d484d9f --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp @@ -0,0 +1,157 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/Player/PlayerData.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using DE::SHCDE::eSFX; + using Game::Player::PlayerData; + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3150 + void LandscapeState::spawnCrowFromNearbyTree(int unitID) + { + int _treeID; + uint uVar2; + uint uVar3; + int iVar5; + PlayerData* _pKeep; + uint uVar6; + int iVar7; + int iVar8; + int local_2c; + int _microY; + int _microX; + int local_1c; + int local_c; + bool bVar1 = false; + for (local_c = 0; local_c < 8; local_c++) { + int _y = (int)DAT_UnitsState::instance.units[unitID].y; + if ((((DAT_TileMapState::instance + .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[_y][local_c] + + DAT_UnitsState::instance.units[unitID].tile] + != 0) + && (_treeID = (int)DAT_TileMapState::instance + .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[_y][local_c] + + DAT_UnitsState::instance.units[unitID].tile], + _treeID < this->maxTreeCount)) + && (this->trees[_treeID].state == 2)) + && ((this->trees[_treeID].unknownDistanceRelatedToCrow != 0 + && (this->trees[_treeID].rng200till300 == 0)))) { + int _playerID = (int)DAT_UnitsState::instance.units[unitID].owner; + _microX = 0; + _microY = 0; + local_2c = 10000; + local_1c = 3; + _pKeep = &DAT_GameState::instance.playerDataArray[1]; + do { + if ((local_1c + -2 != _playerID) && ((_pKeep->keep).id)) { + iVar5 = (_pKeep->keep).xEntry; + iVar8 = (_pKeep->keep).yEntry; + uVar2 = DAT_UnitsState::instance.units[unitID].x - iVar5; + uVar6 = (int)uVar2 >> 0x1f; + uVar3 = _y - iVar8; + iVar7 = (uVar2 ^ uVar6) - uVar6; + uVar2 = (int)uVar3 >> 0x1f; + int iVar4 = (uVar3 ^ uVar2) - uVar2; + if (iVar4 < iVar7) { + iVar4 = iVar7; + } + if (iVar4 < local_2c) { + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + iVar5; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + iVar8; + local_2c = iVar4; + } + } + if ((local_1c + -1 != _playerID) && (_pKeep[1].keep.id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[1].keep.xEntry; + uVar6 = (int)uVar2 >> 0x1f; + uVar3 = _y - _pKeep[1].keep.yEntry; + iVar8 = (uVar2 ^ uVar6) - uVar6; + uVar2 = (int)uVar3 >> 0x1f; + iVar5 = (uVar3 ^ uVar2) - uVar2; + if (iVar5 < iVar8) { + iVar5 = iVar8; + } + if (iVar5 < local_2c) { + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[1].keep.xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[1].keep.yEntry; + local_2c = iVar5; + } + } + if ((local_1c != _playerID) && (_pKeep[2].keep.id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[2].keep.xEntry; + uVar6 = (int)uVar2 >> 0x1f; + uVar3 = _y - _pKeep[2].keep.yEntry; + iVar8 = (uVar2 ^ uVar6) - uVar6; + uVar2 = (int)uVar3 >> 0x1f; + iVar5 = (uVar3 ^ uVar2) - uVar2; + if (iVar5 < iVar8) { + iVar5 = iVar8; + } + if (iVar5 < local_2c) { + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[2].keep.xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[2].keep.yEntry; + local_2c = iVar5; + } + } + if ((local_1c + 1 != _playerID) && (_pKeep[3].keep.id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[3].keep.xEntry; + uVar6 = (int)uVar2 >> 0x1f; + uVar3 = _y - _pKeep[3].keep.yEntry; + iVar8 = (uVar2 ^ uVar6) - uVar6; + uVar2 = (int)uVar3 >> 0x1f; + iVar5 = (uVar3 ^ uVar2) - uVar2; + if (iVar5 < iVar8) { + iVar5 = iVar8; + } + if (iVar5 < local_2c) { + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[3].keep.xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[3].keep.yEntry; + local_2c = iVar5; + } + } + iVar5 = local_1c + 2; + _pKeep = _pKeep + 4; + local_1c = local_1c + 4; + } while (iVar5 < 9); + if (local_2c == 10000) { + _microX = DAT_UnitsState::instance.units[unitID].x + -0x32 + + (int)SEC_RNG::instance.currentNumber2 % 100; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 100 + -0x32 + _y; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, + (undefined4)((int)((int)DAT_UnitsState::instance.units[unitID].owner)), 0, + (int)((int)((short)this->trees[_treeID].xPosition * 8)), + (int)((int)((short)this->trees[_treeID].yPosition * 8)), + (int)((int)(DAT_TileMapState::instance.HeightLayer[this->trees[_treeID].tile] + 0x1e)), _microX * 8, + _microY * 8, 0xfa, Map::Entities::EntityTypeInt__ET_CROW, 0); + this->trees[_treeID].rng200till300 = SEC_RNG::instance.currentNumber2 % 100 + 200; + if (!bVar1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + (int)(short)this->trees[_treeID].xPosition, (int)((int)((short)this->trees[_treeID].yPosition)), + DE::SHCDE::FX_CROW); + bVar1 = true; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp new file mode 100644 index 0000000000..7f0d7fbd26 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -0,0 +1,115 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + using Map::Trees::TreeTypeShort; + using UI::Enums::DisplayElementID; + using UI::Enums::MenuViewType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3960 + void LandscapeState::updateTreeStage(uint treeID, uint rng) + { + int* piVar1; + BOOLEnum BVar2; + int _stage; + int iVar3; + undefined4 size; + int _treeID; + int _treeType; + TreeTypeShort _treeType_2; + if ((((DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) + || ((!DAT_GameCore::instance.isTimeHalted + && (BVar2 = MACRO_CALL(UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( + UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO), + !BVar2)))) + && (((this->trees[treeID].rng1 & 0x3fU) == rng + && (((_treeType = (int)(short)this->trees[treeID].treeType, _treeType < 5 || (0x13 < _treeType)) + && (this->trees[treeID].zeroUpTo2 == 0)))))) + && ((((short)this->trees[treeID].stageRelated2 <= (short)this->trees[treeID].stageRelated1 + && (this->field1_0x4)) + && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_MAP_EDITOR_LANDSCAPING)))) { + piVar1 = &this->trees[treeID].stageTracker; + *piVar1 = *piVar1 + 1; + iVar3 = this->trees[treeID].stage; + if (DAT_OrganismDefinedData::instance.TreeStageLevels[_treeType][iVar3 + 1] + <= this->trees[treeID].stageTracker) { + _stage = iVar3 + 1; + this->trees[treeID].stage = _stage; + MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, _stage); + iVar3 = this->trees[treeID].stage; + if (5 < iVar3) { + this->trees[treeID].state = 3; + } + if (3 < iVar3) { + DAT_GameState::instance.mapAndTime.treeSpreadCounter + = DAT_GameState::instance.mapAndTime.treeSpreadCounter + 1; + if (DAT_GameState::instance.mapAndTime.treeSpreadInterval + < DAT_GameState::instance.mapAndTime.treeSpreadCounter) { + DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0; + _treeType_2 = this->trees[treeID].treeType; + this->trees[treeID].stage = 5; + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[(short)_treeType_2][5]; + } + /* + set spreadcounter to lowest value for tree type? + */ + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[(short)this->trees[treeID].treeType][3]; + this->trees[treeID].stage = 3; + DAT_GameState::instance.mapAndTime.newOrganismsValue2 + = DAT_GameState::instance.mapAndTime.newOrganismsValue2 + 1; + iVar3 = MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)(treeID, + (int)((int)((short)this->trees[treeID].treeType)), + (uint)((int)((int)(short)this->trees[treeID].xPosition)), + (uint)((int)((int)(short)this->trees[treeID].yPosition))); + if (iVar3) { + size = MACRO_CALL_MEMBER( + Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, this)( + (int)(short)this->trees[treeID].treeType, 0); + _treeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, this)( + DAT_PathFindingState::instance.ALG_ResultX, + (undefined4)((int)(DAT_PathFindingState::instance.ALG_ResultY)), + (TreeType)(short)this->trees[treeID].treeType, (undefined4)((int)(size)), 0, 0, 0); + iVar3 = DAT_PathFindingState::instance.ALG_ResultTile; + DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] + = DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] + | 0x1000; + DAT_TileMapState::instance.OrganismLayer[iVar3] = (short)_treeID; + MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, + DAT_TileMapState::ptr)(_treeID, 0); + MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + (int)(short)this->trees[_treeID].yPosition, (int)((int)(this->trees[_treeID].tile))); + DAT_GameState::instance.mapAndTime.newOrganisms + = DAT_GameState::instance.mapAndTime.newOrganisms + 1; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp new file mode 100644 index 0000000000..340dab6437 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -0,0 +1,247 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using WindowsHelper::Enums::BOOLEnum; + + /* + Takes a tribe index (param_1) and builds a rally point path for that tribe. First BFS-floods field20_0x50 + outward from the tribe's unit position (derived from selectionTargetUnitID), restricted to cells in the same + separateAreaID. Then greedily traces a path from the start cell by always stepping to the highest-scoring + unvisited neighbour, recording each step as a rally point in the tribe's rallyPointArray. Returns 1 on success, + 0 if the start cell has no field20_0x50 value (unreachable or unscored area). renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 + BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) + { + short* psVar1; + short sVar2; + int iVar3; + int* piVar4; + int iVar5; + int* piVar6; + uint uVar7; + int iVar8; + uint uVar9; + int iVar10; + uint uVar11; + int iVar12; + int local_1c; + int local_14; + int local_10; + sVar2 = DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID; + iVar5 = (int)DAT_UnitsState::instance.units[sVar2].x / 10; + local_1c = (int)DAT_UnitsState::instance.units[sVar2].y / 10; + this->casDisRelated = param_2; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + if (this->grid[iVar5][local_1c].field20_0x50 != 0) { + piVar4 = &this->grid[0][0].field15_0x3c; + iVar12 = 0x28; + do { + iVar3 = 0x28; + piVar6 = piVar4; + do { + piVar6[-1] = 0; + *piVar6 = 0; + piVar6 = piVar6 + 0x640; + iVar3 = iVar3 + -1; + } while (iVar3); + piVar4 = piVar4 + 0x28; + iVar12 = iVar12 + -1; + } while (iVar12); + this->DAT_Y10_Array_Section1034[0] = (short)local_1c; + this->DAT_X10_Array_Section1034[0] = (short)iVar5; + this->grid[iVar5][local_1c].casDisRelated2 = this->grid[iVar5][local_1c].field20_0x50; + iVar12 = this->grid[iVar5][local_1c].separateAreaID; + if (this->candidateIndex != this->candidateIndex2) { + do { + iVar3 = (int)this->DAT_Y10_Array_Section1034[this->candidateIndex]; + iVar8 = (int)this->DAT_X10_Array_Section1034[this->candidateIndex]; + piVar4 = &DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[0].int_.yOffset; + do { + uVar9 = *piVar4 + iVar3; + uVar7 = ((Point8IntXY*)(piVar4 + -1))->xOffset + iVar8; + if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember + && iVar12 == this->grid[uVar7][uVar9].separateAreaID + && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && this->grid[uVar7][uVar9].casDisRelated2 == 0) { + this->grid[uVar7][uVar9].casDisRelated2 = iVar10; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (0x63f < this->candidateIndex2) { + this->candidateIndex2 = 0; + } + } + uVar9 = piVar4[2] + iVar3; + uVar7 = piVar4[1] + iVar8; + if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember + && iVar12 == this->grid[uVar7][uVar9].separateAreaID + && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && this->grid[uVar7][uVar9].casDisRelated2 == 0) { + this->grid[uVar7][uVar9].casDisRelated2 = iVar10; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (0x63f < this->candidateIndex2) { + this->candidateIndex2 = 0; + } + } + uVar9 = piVar4[4] + iVar3; + uVar7 = piVar4[3] + iVar8; + if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember + && iVar12 == this->grid[uVar7][uVar9].separateAreaID + && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && this->grid[uVar7][uVar9].casDisRelated2 == 0) { + this->grid[uVar7][uVar9].casDisRelated2 = iVar10; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (0x63f < this->candidateIndex2) { + this->candidateIndex2 = 0; + } + } + uVar9 = piVar4[6] + iVar3; + uVar7 = piVar4[5] + iVar8; + if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember + && iVar12 == this->grid[uVar7][uVar9].separateAreaID + && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && this->grid[uVar7][uVar9].casDisRelated2 == 0) { + this->grid[uVar7][uVar9].casDisRelated2 = iVar10; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (0x63f < this->candidateIndex2) { + this->candidateIndex2 = 0; + } + } + piVar4 = piVar4 + 8; + } while ((int)piVar4 < 0xb4908c); + this->candidateIndex = this->candidateIndex + 1; + if (0x63f < this->candidateIndex) { + this->candidateIndex = 0; + } + } while (this->candidateIndex != this->candidateIndex2); + } + uVar7 = (uint)(byte)SEC_RNG::instance.currentNumber2; + DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; + DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; + this->grid[iVar5][local_1c].field15_0x3c = 1; + this->grid[iVar5][local_1c].casDisRelated2 = 0; + while (true) { + local_14 = -1; + local_10 = 2; + iVar12 = (uVar7 & 7) - 7; + iVar3 = (uVar7 & 7) * 8 + 8; + do { + iVar8 = iVar12 + 7; + iVar10 = iVar3 + -8; + if (7 < iVar8) { + iVar8 = iVar12 + -1; + iVar10 = iVar3 + -72; + } + uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) + + iVar5; + uVar11 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) + + local_1c; + if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember + && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 != 0 && (param_2 < iVar10))) { + this->grid[uVar9][uVar11].casDisRelated2 = 0; + param_2 = iVar10; + local_14 = iVar8; + } + iVar8 = iVar3; + iVar10 = iVar12 + 8; + if (7 < iVar12 + 8) { + iVar8 = iVar3 + -0x40; + iVar10 = iVar12; + } + uVar11 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8 + 4) + + local_1c; + uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8) + + iVar5; + if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember + && (iVar8 = this->grid[uVar9][uVar11].casDisRelated2, iVar8 && (param_2 < iVar8))) { + this->grid[uVar9][uVar11].casDisRelated2 = 0; + param_2 = iVar8; + local_14 = iVar10; + } + iVar8 = iVar12 + 9; + iVar10 = iVar3 + 8; + if (7 < iVar8) { + iVar8 = iVar12 + 1; + iVar10 = iVar3 + -0x38; + } + uVar11 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) + + local_1c; + uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) + + iVar5; + if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember + && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 != 0 && (param_2 < iVar10))) { + this->grid[uVar9][uVar11].casDisRelated2 = 0; + param_2 = iVar10; + local_14 = iVar8; + } + iVar8 = iVar12 + 10; + iVar10 = iVar3 + 0x10; + if (7 < iVar8) { + iVar8 = iVar12 + 2; + iVar10 = iVar3 + -0x30; + } + uVar11 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) + + local_1c; + uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) + + iVar5; + if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember + && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 && (param_2 < iVar10))) { + this->grid[uVar9][uVar11].casDisRelated2 = 0; + param_2 = iVar10; + local_14 = iVar8; + } + iVar3 = iVar3 + 0x20; + iVar12 = iVar12 + 4; + local_10 = local_10 + -1; + } while (local_10); + if (local_14 < 0) + break; + iVar5 = iVar5 + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[local_14].int_.xOffset; + local_1c = local_1c + + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_14 * 8 + + 4); + this->grid[iVar5][local_1c].field15_0x3c = 1; + uVar9 = iVar5 * 10 + 5; + uVar11 = local_1c * 10 + 5; + if (uVar9 < 400 && uVar11 < 400 && *(char*)(uVar11 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar9) != '\0') { + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] + = (short)iVar5 * 10 + 5; + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] + = (short)local_1c * 10 + 5; + psVar1 = &DAT_TribesState::instance.tribes[param_1].rallyPointCount; + *psVar1 = *psVar1 + 1; + } + } + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp new file mode 100644 index 0000000000..72ee6aadae --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -0,0 +1,216 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using AI::Tribes::AITribeType; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 + void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) + { + short* psVar1; + short sVar2; + short sVar3; + int* piVar4; + uint _randomDirection; + int iVar5; + uint uVar6; + int iVar7; + int iVar8; + int* piVar9; + uint uVar10; + int _x10; + int iVar11; + int _y10; + int local_18; + int local_c; + int _count; + int _currentArea; + uint _destinationY; + uint _destinationX; + sVar2 = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + _x10 = (int)DAT_UnitsState::instance.units[sVar2].x / 10; + _y10 = (int)DAT_UnitsState::instance.units[sVar2].y / 10; + this->casDisRelated = always2or3or5; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + piVar9 = &this->grid[0][0].field15_0x3c; + iVar11 = 0x28; + do { + iVar5 = 0x28; + piVar4 = piVar9; + do { + piVar4[-1] = 0; + *piVar4 = 0; + piVar4 = piVar4 + 0x640; + iVar5 = iVar5 + -1; + } while (iVar5); + piVar9 = piVar9 + 0x28; + iVar11 = iVar11 + -1; + } while (iVar11); + this->DAT_Y10_Array_Section1034[0] = (short)_y10; + this->DAT_X10_Array_Section1034[0] = (short)_x10; + _currentArea = this->grid[_x10][_y10].separateAreaID; + this->grid[_x10][_y10].casDisRelated2 = always2or3or5; + if (this->candidateIndex != this->candidateIndex2) { + do { + sVar2 = this->DAT_X10_Array_Section1034[this->candidateIndex]; + sVar3 = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[sVar2][sVar3].casDisRelated2; + if (this->casDisRelated < 2) + break; + iVar11 = this->casDisRelated + -1; + piVar9 = &DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[0].int_.yOffset; + do { + uVar10 = *piVar9 + (int)sVar3; + uVar6 = ((Point8IntXY*)(piVar9 + -1))->xOffset + (int)sVar2; + if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember + && _currentArea == this->grid[uVar6][uVar10].separateAreaID) { + if (!always0or1) { + if (this->grid[uVar6][uVar10].field13_0x34 == 0) { + if (DAT_TribesState::instance.tribes[tribeID].tribeType + == (AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_SPEARMEN)) { + _count = this->grid[uVar6][uVar10].deerCount; + goto LAB_0052cc5e; + } + LAB_0052cc66: + if (this->grid[uVar6][uVar10].casDisRelated2 < iVar11) { + this->grid[uVar6][uVar10].casDisRelated2 = iVar11; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar6; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar10; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (1600 < this->candidateIndex2) { + this->candidateIndex2 = 0; + } + } + } + } else if (this->grid[uVar6][uVar10].unstalkedUnitCount == 0) { + _count = this->grid[uVar6][uVar10].buildingTiles; + LAB_0052cc5e: + if ((!_count) && (this->grid[uVar6][uVar10].lionCount == 0)) + goto LAB_0052cc66; + } + } + piVar9 = piVar9 + 2; + } while ((int)piVar9 < 0xb4908c); + this->candidateIndex = this->candidateIndex + 1; + if (1600 < this->candidateIndex) { + this->candidateIndex = 0; + } + } while (this->candidateIndex != this->candidateIndex2); + } + _randomDirection = (uint)(byte)SEC_RNG::instance.currentNumber2; + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; + DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; + this->grid[_x10][_y10].field15_0x3c = 1; + this->grid[_x10][_y10].casDisRelated2 = 0; + while (true) { + local_18 = -1; + local_c = 2; + iVar11 = (_randomDirection & 7) * 8 + 8; + iVar5 = (_randomDirection & 7) - 7; + do { + iVar8 = iVar5 + 7; + iVar7 = iVar11 + -8; + if (7 < iVar8) { + iVar8 = iVar5 + -1; + iVar7 = iVar11 + -0x48; + } + uVar6 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; + uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) + + _y10; + if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember + && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 != 0 && (iVar7 < always2or3or5))) { + this->grid[uVar6][uVar10].casDisRelated2 = 0; + always2or3or5 = iVar7; + local_18 = iVar8; + } + iVar8 = iVar11; + iVar7 = iVar5 + 8; + if (7 < iVar5 + 8) { + iVar8 = iVar11 + -0x40; + iVar7 = iVar5; + } + uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8 + 4) + + _y10; + uVar6 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8) + _x10; + if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember + && (iVar8 = this->grid[uVar6][uVar10].casDisRelated2, iVar8 && (iVar8 < always2or3or5))) { + this->grid[uVar6][uVar10].casDisRelated2 = 0; + always2or3or5 = iVar8; + local_18 = iVar7; + } + iVar8 = iVar5 + 9; + iVar7 = iVar11 + 8; + if (7 < iVar8) { + iVar8 = iVar5 + 1; + iVar7 = iVar11 + -0x38; + } + uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) + + _y10; + uVar6 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; + if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember + && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 != 0 && (iVar7 < always2or3or5))) { + this->grid[uVar6][uVar10].casDisRelated2 = 0; + always2or3or5 = iVar7; + local_18 = iVar8; + } + iVar8 = iVar5 + 10; + iVar7 = iVar11 + 0x10; + if (7 < iVar8) { + iVar8 = iVar5 + 2; + iVar7 = iVar11 + -0x30; + } + uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) + + _y10; + uVar6 + = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; + if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember + && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 && (iVar7 < always2or3or5))) { + this->grid[uVar6][uVar10].casDisRelated2 = 0; + always2or3or5 = iVar7; + local_18 = iVar8; + } + iVar11 = iVar11 + 0x20; + iVar5 = iVar5 + 4; + local_c = local_c + -1; + } while (local_c); + if (local_18 < 0) + break; + _x10 = _x10 + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[local_18].int_.xOffset; + _y10 = _y10 + + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_18 * 8 + 4); + this->grid[_x10][_y10].field15_0x3c = 1; + _destinationY = _y10 * 10 + 5; + uVar6 = _x10 * 10 + 5; + if (uVar6 < 400 && _destinationY < 400 && *(char*)(_destinationY * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar6) != '\0') { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, + DAT_PathFindingState::ptr)(_currentArea, uVar6, _destinationY); + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][0] + = (short)DAT_PathFindingState::instance.climbX; + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][1] + = (short)DAT_PathFindingState::instance.climbY; + psVar1 = &DAT_TribesState::instance.tribes[tribeID].rallyPointCount; + *psVar1 = *psVar1 + 1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp new file mode 100644 index 0000000000..028e457124 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -0,0 +1,226 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/COL_BLUE.hpp" +#include "OpenSHC/Globals/COL_BRIGHT_YELLOW.hpp" +#include "OpenSHC/Globals/COL_DARK_CYAN_GREY.hpp" +#include "OpenSHC/Globals/COL_DARK_GREEN.hpp" +#include "OpenSHC/Globals/COL_LIME.hpp" +#include "OpenSHC/Globals/COL_MODERATE_GREEN.hpp" +#include "OpenSHC/Globals/COL_RED.hpp" +#include "OpenSHC/Globals/COL_VERY_DARK_GREY.hpp" +#include "OpenSHC/Globals/COL_VIVID_BLUE.hpp" +#include "OpenSHC/Globals/COL_WHITE.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace Map { + + using Text::TextAlignment; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052BF40 + void WildlifeState::renderDebugDataMapData(int x, int y, int width, int height) + { + int iVar2; + int iVar4; + int iVar8; + char* textAddress; + int x1 = x + 2; + if (!this->DAT_DebugDataMapDataDisplayType) { + textAddress = "Connect "; + } else if (this->DAT_DebugDataMapDataDisplayType == 1) { + textAddress = "Chimps "; + } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + textAddress = "Farmland "; + } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + textAddress = "Humans "; + } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + textAddress = "Mankind "; + } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + textAddress = "Deer "; + } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + textAddress = "Route "; + } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + textAddress = "Panic "; + } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + textAddress = "Siege "; + } else { + if (this->DAT_DebugDataMapDataDisplayType != 9) + goto LAB_0052c0db; + textAddress = "Slink "; + } + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textAddress, x + 0x1a6, y + 4, Text::TTA_LEFT, 0xffffff, 0x11, FALSE, 0); + LAB_0052c0db: + /* + render the squares + */ + int iVar7 = 41; + int iVar6 = y; + do { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x1, iVar6, x + 0x192, iVar6, (ushort)(COL_WHITE::instance.shortValue)); + iVar6 = iVar6 + 10; + iVar7 = iVar7 + -1; + } while (iVar7); + iVar7 = 41; + iVar6 = x1; + do { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + iVar6, y, iVar6, y + 400, (ushort)(COL_WHITE::instance.shortValue)); + iVar6 = iVar6 + 10; + iVar7 = iVar7 + -1; + iVar8 = 0; + } while (iVar7); + do { + for (iVar6 = 0; iVar6 < 40; iVar6++) { + if (0 < this->grid[iVar6][iVar8].firstMember) { + undefined2 uVar5 = COL_BLUE::instance.shortValue; + if (!this->DAT_DebugDataMapDataDisplayType) { + uint uVar1 = this->grid[iVar6][iVar8].separateAreaID; + uint uVar3 = uVar1 & 7; + if (!uVar1 || (uVar5 = COL_RED::instance.shortValue, uVar3 == 1) + || (uVar5 = COL_BRIGHT_YELLOW::instance.shortValue, + uVar3 == 2 + || ((uVar5 = COL_MODERATE_GREEN::instance.shortValue, + uVar3 == 3 || (uVar5 = COL_WHITE::instance.shortValue, uVar3 == 4)))) + || (uVar5 = COL_DARK_CYAN_GREY::instance.shortValue, uVar3 == 5)) + goto LAB_0052c526; + if (uVar3 == 6) { + LAB_0052c51f: + uVar5 = COL_LIME::instance.shortValue; + goto LAB_0052c526; + } + iVar2 = y + iVar8 * 10; + iVar4 = x1 + iVar6 * 10; + uVar5 = COL_VERY_DARK_GREY::instance.shortValue; + if (uVar3 == 7) { + uVar5 = COL_VIVID_BLUE::instance.shortValue; + } + } else { + if (this->DAT_DebugDataMapDataDisplayType == 1) { + if (this->grid[iVar6][iVar8].separateAreaID != 0) { + iVar7 = this->grid[iVar6][iVar8].chimps; + uVar5 = COL_RED::instance.shortValue; + joined_r0x0052c335: + iVar2 = y + iVar8 * 10; + iVar4 = x1 + iVar6 * 10; + if (!iVar7) { + uVar5 = COL_LIME::instance.shortValue; + } + goto LAB_0052c533; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + if (this->grid[iVar6][iVar8].separateAreaID != 0 + && (uVar5 = COL_DARK_GREEN::instance.shortValue, + this->grid[iVar6][iVar8].farmFieldTiles == 0) + && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].rabbitCount == 0) + && (uVar5 = COL_WHITE::instance.shortValue, + this->grid[iVar6][iVar8].field15_0x3c == 0)) { + iVar7 = this->grid[iVar6][iVar8].field20_0x50; + uVar5 = COL_DARK_CYAN_GREY::instance.shortValue; + goto joined_r0x0052c335; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + if (this->grid[iVar6][iVar8].separateAreaID != 0) { + iVar7 = this->grid[iVar6][iVar8].unstalkedUnitCount; + uVar5 = COL_RED::instance.shortValue; + goto joined_r0x0052c335; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + if ((this->grid[iVar6][iVar8].separateAreaID != 0) + && (uVar5 = COL_RED::instance.shortValue, + this->grid[iVar6][iVar8].unstalkedUnitCount == 0)) { + iVar7 = this->grid[iVar6][iVar8].buildingTiles; + joined_r0x0052c3aa: + if (!iVar7) { + iVar7 = this->grid[iVar6][iVar8].field13_0x34; + uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; + goto joined_r0x0052c335; + } + } + } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + if (this->grid[iVar6][iVar8].separateAreaID != 0 + && (uVar5 = COL_RED::instance.shortValue, + this->grid[iVar6][iVar8].unstalkedUnitCount == 0) + && this->grid[iVar6][iVar8].buildingTiles == 0 + && (uVar5 = COL_BLACK::instance.shortValue, + this->grid[iVar6][iVar8].lionCount == 0 + && (this->grid[iVar6][iVar8].camelCount == 0))) { + iVar7 = this->grid[iVar6][iVar8].deerCount; + uVar5 = COL_MODERATE_GREEN::instance.shortValue; + goto joined_r0x0052c3aa; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + if (this->grid[iVar6][iVar8].separateAreaID != 0 + && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].deerCount == 0) + && (uVar5 = COL_VIVID_BLUE::instance.shortValue, + this->grid[iVar6][iVar8].lionCount == 0) + && (uVar5 = COL_WHITE::instance.shortValue, + this->grid[iVar6][iVar8].field15_0x3c == 0)) { + iVar7 = this->grid[iVar6][iVar8].casDisRelated2; + uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; + joined_r0x0052c46b: + if (!iVar7) { + iVar7 = this->grid[iVar6][iVar8].field13_0x34; + uVar5 = COL_BLACK::instance.shortValue; + goto joined_r0x0052c335; + } + } + } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + if ((this->grid[iVar6][iVar8].separateAreaID != 0) + && (uVar5 = COL_WHITE::instance.shortValue, + this->grid[iVar6][iVar8].field18_0x48 == 0)) { + iVar7 = this->grid[iVar6][iVar8].deerCount; + uVar5 = COL_RED::instance.shortValue; + goto joined_r0x0052c46b; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + uVar5 = COL_WHITE::instance.shortValue; + if (this->grid[iVar6][iVar8].field24_0x60 == 0 + && (uVar5 = COL_BLACK::instance.shortValue, this->grid[iVar6][iVar8].field25_0x64 == 0) + && (uVar5 = COL_BRIGHT_YELLOW::instance.shortValue, + this->grid[iVar6][iVar8].castlebuildings == 0 + && ((uVar5 = COL_BLUE::instance.shortValue, + this->grid[iVar6][iVar8].separateAreaID != 0 + && (uVar5 = COL_VIVID_BLUE::instance.shortValue, + this->grid[iVar6][iVar8].unknownNonZero01 == 0))))) { + iVar7 = this->grid[iVar6][iVar8].field27_0x6c; + uVar5 = COL_RED::instance.shortValue; + goto joined_r0x0052c335; + } + } else { + if (this->DAT_DebugDataMapDataDisplayType != 9) + continue; + uVar5 = COL_RED::instance.shortValue; + if (this->grid[iVar6][iVar8].field29_0x74 == 0 + && (uVar5 = COL_VIVID_BLUE::instance.shortValue, + this->grid[iVar6][iVar8].unknownNonZero01 == 0) + && (uVar5 = COL_BLUE::instance.shortValue, + this->grid[iVar6][iVar8].separateAreaID != 0)) + goto LAB_0052c51f; + } + LAB_0052c526: + iVar4 = x1 + iVar6 * 10; + iVar2 = y + iVar8 * 10; + } + LAB_0052c533: + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + iVar4 + 1, iVar2 + 1, iVar4 + 9, iVar2 + 9, (ushort)(uVar5)); + } + } + iVar8 = iVar8 + 1; + if (40 < iVar8) {} + } while (true); + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp new file mode 100644 index 0000000000..48a86a4c83 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -0,0 +1,267 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052E120 + void WildlifeState::updateNofFpoints() + { + uint uVar1; + ushort uVar2; + bool bVar3; + short* psVar4; + WildlifeGridElement* piVar5; + int iVar5; + uint uVar6; + int iVar7; + short sVar8; + short (*src)[8]; + uint local_10; + int local_c; + WildlifeGridElement* local_4; + uint _someY; + ushort _separateAreaID; + /* + has nothing to do with mercrecruitable + */ + uVar6 = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field128056_0x469d4] + .x; + _someY = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field128056_0x469d4] + .y; + if (uVar6 <= 0x18f && _someY <= 0x18f && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[_someY * 400 + uVar6] != '\0' + && (_separateAreaID = DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[_someY].addXgetTile + + uVar6], + DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY)) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillCasDisFromSignpost, this)(); + DAT_TroopValueState::instance.attackInfo.nof_fpoints = 0; + psVar4 = DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[0] + 2; + do { + psVar4[1] = 0; + *psVar4 = 0; + psVar4[-1] = 0; + (*(short (*)[8])(psVar4 + -2))[0] = 0; + psVar4 = psVar4 + 8; + } while ((int)psVar4 < 0x1784940); + sVar8 = 5; + local_c = 2000; + local_4 = &this->grid[0][0]; + local_10 = 60; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints; + do { + uVar6 = 0xf; + piVar5 = local_4; + do { + if ((piVar5->field27_0x6c) && (0 < piVar5->firstMember)) { + uVar1 = uVar6 - 10; + uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + + local_10) + - 10]; + if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)piVar5->field28_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)piVar5->casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 0x32 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; + } + } + if (piVar5[40].field27_0x6c != 0 && 0 < piVar5[40].firstMember + && (uVar2 = DAT_TileMapState::instance.PathConnectionLayer + [*(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + + local_10) + + uVar6], + _separateAreaID == uVar2) + && uVar6 <= 0x18f && local_10 <= 0x12b4 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar6] != '\0') { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar6; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)piVar5[40].field28_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)piVar5[40].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 0x32 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; + } + if ((piVar5[80].field27_0x6c != 0) && (0 < piVar5[80].firstMember)) { + uVar1 = uVar6 + 10; + uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + + local_10) + + 10]; + if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)piVar5[80].field28_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)piVar5[80].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 0x32 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; + } + } + if ((piVar5[120].field27_0x6c != 0) && (0 < piVar5[120].firstMember)) { + uVar1 = uVar6 + 0x14; + uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + + local_10) + + 0x14]; + if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)piVar5[120].field28_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)piVar5[120].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 0x32 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; + } + } + if ((piVar5[160].field27_0x6c != 0) && (0 < piVar5[160].firstMember)) { + uVar1 = uVar6 + 0x1e; + uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + + local_10) + + 0x1e]; + if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)piVar5[160].field28_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)piVar5[160].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 0x32 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; + } + } + uVar6 = uVar6 + 0x32; + piVar5 = piVar5 + 200; + } while ((int)uVar6 < 0x19f); + local_c = local_c + 4000; + local_10 = local_10 + 0x78; + local_4 = local_4 + 1; + sVar8 = sVar8 + 10; + } while ((int)local_10 < 0x12fc); + do { + bVar3 = false; + iVar7 = 0; + if (iVar5 == 1 || iVar5 + -1 < 0) {} + src = DAT_TroopValueState::instance.attackInfo.nof_fpointsArray; + do { + if (src[1][6] < (*src)[6]) { + bVar3 = true; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + (void*)((int)(src)), + (void*)((int)(DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy))); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)( + 0x10, (void*)((int)(src + 1)), (void*)((int)(src))); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(0x10, + (void*)((int)(DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy)), + (void*)((int)(src + 1))); + iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints; + } + iVar7 = iVar7 + 1; + src = src + 1; + } while (iVar7 < iVar5 + -1); + } while (bVar3); + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp new file mode 100644 index 0000000000..b255d31100 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -0,0 +1,85 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 + void WildlifeState::updateSection1034Info() + { + int iVar1; + int iVar2; + WildlifeGridElement* piVar3; + int* piVar5; + WildlifeGridElement* piVar4; + int iVar6; + int* piVar7; + int local_4; + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + for (local_4 = 0; local_4 < 0x14; local_4++) { + iVar2 = 0; + piVar3 = &this->grid[0][0]; + do { + iVar6 = 0; + piVar4 = piVar3; + do { + piVar4->unknownNonZero01 = 0; + piVar4->field27_0x6c = 0; + if ((piVar4->castlebuildings) + && (iVar1 = MACRO_CALL_MEMBER( + Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(iVar6, iVar2), + iVar1 != 0)) { + piVar4->field25_0x64 = piVar4->field25_0x64 + 1; + } + iVar6 = iVar6 + 1; + piVar4 = piVar4 + 0x640; + } while (iVar6 < 0x28); + iVar2 = iVar2 + 1; + piVar3 = piVar3 + 0x28; + } while (iVar2 < 0x28); + } + iVar2 = 0; + piVar5 = &this->grid[0][0].field25_0x64; + do { + iVar6 = 0; + piVar7 = piVar5; + do { + if ((piVar7[-1] != 0) || (*piVar7 != 0)) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillUnknownNonZero01FromCell, this)( + iVar6, iVar2, 6); + } + iVar6 = iVar6 + 1; + piVar7 = piVar7 + 0x640; + } while (iVar6 < 0x28); + iVar2 = iVar2 + 1; + piVar5 = piVar5 + 0x28; + } while (iVar2 < 0x28); + iVar2 = 0; + piVar5 = &this->grid[0][0].field27_0x6c; + do { + iVar6 = 0; + piVar7 = piVar5; + do { + if ((piVar7[-1] == 0) + && (iVar1 = MACRO_CALL_MEMBER( + Map::WildlifeState_Func::isSuitableWildlifeSpawnCell, this)(iVar6, iVar2), + iVar1 != 0)) { + *piVar7 = *piVar7 + 1; + } + iVar6 = iVar6 + 1; + piVar7 = piVar7 + 0x640; + } while (iVar6 < 0x28); + iVar2 = iVar2 + 1; + piVar5 = piVar5 + 0x28; + } while (iVar2 < 0x28); + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp new file mode 100644 index 0000000000..5075fd8e98 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -0,0 +1,88 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052DF30 + void WildlifeState::updateWildlife() + { + WildlifeGridElement* piVar1; + WildlifeGridElement* piVar2; + int iVar3; + WildlifeGridElement* piVar4; + WildlifeGridElement* piVar5; + int iVar6; + int iVar7; + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + piVar1 = &this->grid[0][0]; + iVar3 = 0x28; + piVar5 = piVar1; + iVar6 = iVar3; + while (true) { + do { + piVar5->field13_0x34 = 0; + piVar5->field20_0x50 = 0; + piVar5->field24_0x60 = 0; + piVar5->field25_0x64 = 0; + piVar5->field28_0x70 = piVar5->field28_0x70 / 100; + if (piVar5->chimps) { + if (piVar5->keeps) { + piVar5->field24_0x60 = 1; + } + if (piVar5->castlebuildings) { + piVar5->field24_0x60 = piVar5->field24_0x60 + 1; + } + } + piVar5 = piVar5 + 0x640; + iVar6 = iVar6 + -1; + } while (iVar6); + piVar1 = piVar1 + 0x28; + iVar3 = iVar3 + -1; + if (!iVar3) + break; + iVar6 = 0x28; + piVar5 = piVar1; + } + piVar4 = &this->grid[0][0]; + iVar3 = 0; + do { + iVar6 = 0; + piVar2 = piVar4; + do { + if (!piVar2->unstalkedUnitCount) { + if (piVar2->buildingTiles) { + iVar7 = 2; + goto LAB_0052dfdf; + } + if (piVar2->lionCount) { + iVar7 = 3; + goto LAB_0052dfdf; + } + } else { + iVar7 = 2; + LAB_0052dfdf: + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)( + iVar6, iVar3, iVar7); + } + if (piVar2->farmFieldTiles) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)( + iVar6, iVar3, 6); + } + iVar6 = iVar6 + 1; + piVar2 = piVar2 + 0x640; + } while (iVar6 < 0x28); + iVar3 = iVar3 + 1; + piVar4 = piVar4 + 0x28; + } while (iVar3 < 0x28); + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp new file mode 100644 index 0000000000..40ff6ef777 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -0,0 +1,325 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Trees/TreeType.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; + using Map::Trees::TreeType; + using Map::Trees::TreeTypeShort; + using Map::Units::UnitType; + using Map::Units::UnitTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052BA10 + void WildlifeState::updateWildlifeGrid(int _y10) + { + int* piVar1; + BuildingTypeShort* pBVar2; + TreeTypeShort TVar3; + BuildingTypeShort BVar4; + UnitTypeShort UVar5; + uint uVar6; + WildlifeGridElement* pWVar7; + int iVar8; + uint uVar9; + int _areaID; + int _unitID; + int iVar10; + int _tile; + int _sepAreaID; + int local_35c; + int local_358; + int local_354; + int local_348; + int local_344; + int local_340; + int local_33c; + int local_338; + int local_334; + int local_330; + int local_32c; + int local_320[200]; + int _x10; + local_348 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] != -1) { + local_348 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[1].campground.tileEntry]; + } + local_344 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[2] != -1) { + local_344 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[2].campground.tileEntry]; + } + local_340 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[3] != -1) { + local_340 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[3].campground.tileEntry]; + } + local_33c = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[4] != -1) { + local_33c = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[4].campground.tileEntry]; + } + local_338 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[5] != -1) { + local_338 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[5].campground.tileEntry]; + } + local_334 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[6] != -1) { + local_334 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[6].campground.tileEntry]; + } + local_330 = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[7] != -1) { + local_330 = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[7].campground.tileEntry]; + } + local_32c = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[8] != -1) { + local_32c = (int)(short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[8].campground.tileEntry]; + } + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + local_35c = 0; + do { + _x10 = local_35c / 10; + pWVar7 = this->grid[_x10] + _y10; + pWVar7->firstMember = 0; + this->grid[_x10][_y10].separateAreaID = 0; + this->grid[_x10][_y10].unclaimedArea = 0; + this->grid[_x10][_y10].buildingTiles = 0; + this->grid[_x10][_y10].keeps = 0; + this->grid[_x10][_y10].wallTiles = 0; + this->grid[_x10][_y10].trees = 0; + this->grid[_x10][_y10].unitCount = 0; + this->grid[_x10][_y10].unstalkedUnitCount = 0; + this->grid[_x10][_y10].stalkedUnitCount = 0; + this->grid[_x10][_y10].camelCount = 0; + this->grid[_x10][_y10].lionCount = 0; + this->grid[_x10][_y10].deerCount = 0; + this->grid[_x10][_y10].rabbitCount = 0; + this->grid[_x10][_y10].marshTiles = 0; + this->grid[_x10][_y10].rockyTiles = 0; + this->grid[_x10][_y10].field18_0x48 = 0; + this->grid[_x10][_y10].farmFieldTiles = 0; + this->grid[_x10][_y10].chimps = 0; + this->grid[_x10][_y10].castlebuildings = 0; + this->grid[_x10][_y10].field28_0x70 = 0; + iVar8 = 0; + do { + local_320[iVar8 * 2] = -1; + local_320[iVar8 * 2 + 1] = 0; + iVar8 = iVar8 + 1; + } while (iVar8 < 100); + local_354 = 0; + do { + uVar9 = local_354 + _y10 * 10; + local_358 = 0; + do { + if ((uint)(local_358 + local_35c) < 400 && uVar9 < 400 + && *(char*)(uVar9 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + local_358 + local_35c) != '\0') { + pWVar7->firstMember = pWVar7->firstMember + 1; + _tile = DAT_ViewportRenderState::instance.translationMatrix[uVar9].addXgetTile + local_358 + + local_35c; + _areaID = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[_tile]; + if (!_areaID) { + this->grid[_x10][_y10].unclaimedArea = this->grid[_x10][_y10].unclaimedArea + 1; + } + iVar8 = 0; + do { + if (local_320[iVar8 * 2] == _areaID) { + local_320[iVar8 * 2 + 1] = local_320[iVar8 * 2 + 1] + 1; + break; + } + if (local_320[iVar8 * 2] == -1) { + local_320[iVar8 * 2] = _areaID; + local_320[iVar8 * 2 + 1] = 1; + break; + } + iVar8 = iVar8 + 1; + } while (iVar8 < 100); + if (_areaID) { + if (_areaID == local_348) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_344) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_340) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_33c) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_338) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_334) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_330) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + if (_areaID == local_32c) { + this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; + } + } + this->grid[_x10][_y10].field28_0x70 = this->grid[_x10][_y10].field28_0x70 + + (uint)DAT_TileMapState::instance.HeightLayer[_tile]; + uVar6 = DAT_TileMapState::instance.LogicLayer[_tile]; + if ((uVar6 & 0x100)) { + this->grid[_x10][_y10].wallTiles = this->grid[_x10][_y10].wallTiles + 1; + this->grid[_x10][_y10].castlebuildings = this->grid[_x10][_y10].castlebuildings + 1; + } + if ((uVar6 & 0x20000000)) { + this->grid[_x10][_y10].marshTiles = this->grid[_x10][_y10].marshTiles + 1; + } + if ((uVar6 & 0x20000)) { + this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; + } + if ((char)uVar6 < '\0') { + this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; + } + if ((uVar6 & 0x40000)) { + this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; + } + if ((uVar6 & 0x1000000)) { + this->grid[_x10][_y10].farmFieldTiles = this->grid[_x10][_y10].farmFieldTiles + 1; + } + if ((uVar6 & 0x2000000)) { + this->grid[_x10][_y10].farmFieldTiles = this->grid[_x10][_y10].farmFieldTiles + 1; + } + if ((int)DAT_TileMapState::instance.OrganismLayer[_tile] - 1U < 1999 + && ((TVar3 = DAT_LandscapeState::instance + .trees[DAT_TileMapState::instance.OrganismLayer[_tile]] + .treeType, + TVar3 == ((TreeType)1) || (TVar3 == ((TreeType)2))) + || ((TVar3 == ((TreeType)3) || (TVar3 == ((TreeType)4)))))) { + this->grid[_x10][_y10].trees = this->grid[_x10][_y10].trees + 1; + } + if (DAT_TileMapState::instance.BuildingLayer[_tile] != 0) { + pBVar2 = &DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer[_tile]] + .buildingType; + BVar4 = *pBVar2; + if (BVar4 == Map::Buildings::BT_MANORHOUSE) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_STONEKEEP) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_STRONGHOLD) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_KEEPFOUR) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_KEEPFIVE) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_CAMPGROUND) { + this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; + } else if (BVar4 == Map::Buildings::BT_GATEHOUSELARGE + || BVar4 == Map::Buildings::BT_GATEHOUSESMALL + || BVar4 == Map::Buildings::BT_WOODGATE1 || BVar4 == Map::Buildings::BT_WOODGATE2 + || BVar4 == Map::Buildings::BT_DRAWBRIDGE || BVar4 == Map::Buildings::BT_TOWER1 + || BVar4 == Map::Buildings::BT_TOWER2 || BVar4 == Map::Buildings::BT_TOWER3 + || BVar4 == Map::Buildings::BT_TOWER4 || BVar4 == Map::Buildings::BT_TOWER5) { + this->grid[_x10][_y10].castlebuildings = this->grid[_x10][_y10].castlebuildings + 1; + } + if (*pBVar2 != Map::Buildings::BT_SIGNPOST) { + this->grid[_x10][_y10].buildingTiles = this->grid[_x10][_y10].buildingTiles + 1; + } + } + _unitID = (int)(short)DAT_TileMapState::instance.UnitLayer[_tile]; + if (_unitID) { + this->grid[_x10][_y10].unitCount = this->grid[_x10][_y10].unitCount + 1; + if (DAT_UnitsState::instance.units[_unitID].isStalked == 0) { + this->grid[_x10][_y10].unstalkedUnitCount + = this->grid[_x10][_y10].unstalkedUnitCount + 1; + LAB_0052be68: + this->grid[_x10][_y10].field18_0x48 = this->grid[_x10][_y10].field18_0x48 + 1; + } else { + this->grid[_x10][_y10].stalkedUnitCount + = this->grid[_x10][_y10].stalkedUnitCount + 1; + UVar5 = DAT_UnitsState::instance.units[_unitID].unitType; + if (UVar5 == Map::Units::UT_ANTELOPESHDEER) { + this->grid[_x10][_y10].deerCount = this->grid[_x10][_y10].deerCount + 1; + if (DAT_TribesState::instance + .tribes[DAT_UnitsState::instance.units[_unitID].tribeID] + .predatorNearby + != 0) + goto LAB_0052be68; + } else if (UVar5 == Map::Units::UT_RABBIT) { + this->grid[_x10][_y10].rabbitCount = this->grid[_x10][_y10].rabbitCount + 1; + } else if (UVar5 == Map::Units::UT_CAMELSHBEAR) { + this->grid[_x10][_y10].camelCount = this->grid[_x10][_y10].camelCount + 1; + } else if (UVar5 == Map::Units::UT_LIONSHWOLF) { + this->grid[_x10][_y10].lionCount = this->grid[_x10][_y10].lionCount + 1; + } + } + } + } + local_358 = local_358 + 1; + } while (local_358 < 10); + local_354 = local_354 + 1; + } while (local_354 < 10); + _sepAreaID = 0; + iVar8 = 0; + iVar10 = 0; + do { + if (local_320[iVar10 * 2] == -1) + break; + if (iVar8 < local_320[iVar10 * 2 + 1]) { + _sepAreaID = local_320[iVar10 * 2]; + iVar8 = local_320[iVar10 * 2 + 1]; + } + if (local_320[iVar10 * 2 + 2] == -1) + break; + if (iVar8 < local_320[iVar10 * 2 + 3]) { + _sepAreaID = local_320[iVar10 * 2 + 2]; + iVar8 = local_320[iVar10 * 2 + 3]; + } + if (local_320[iVar10 * 2 + 4] == -1) + break; + if (iVar8 < local_320[iVar10 * 2 + 5]) { + _sepAreaID = local_320[iVar10 * 2 + 4]; + iVar8 = local_320[iVar10 * 2 + 5]; + } + if (local_320[iVar10 * 2 + 6] == -1) + break; + if (iVar8 < local_320[iVar10 * 2 + 7]) { + _sepAreaID = local_320[iVar10 * 2 + 6]; + iVar8 = local_320[iVar10 * 2 + 7]; + } + if (local_320[iVar10 * 2 + 8] == -1) + break; + if (iVar8 < local_320[iVar10 * 2 + 9]) { + _sepAreaID = local_320[iVar10 * 2 + 8]; + iVar8 = local_320[iVar10 * 2 + 9]; + } + iVar10 = iVar10 + 5; + } while (iVar10 < 100); + this->grid[_x10][_y10].separateAreaID = _sepAreaID; + local_35c = local_35c + 10; + } while (local_35c < 400); + } + } + +} +} From 61c578ef24df267b1d7d395b3e17bb35c6c85a46 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:01 +0100 Subject: [PATCH 02/43] 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/Map/LandscapeState/createTree.cpp | 12 ++-- .../spawnCrowFromNearbyTree.cpp | 53 ++++++++++------ .../Map/LandscapeState/updateTreeStage.cpp | 11 ++-- .../buildRallyPointPathForTribe.cpp | 22 ++++--- ...findAndSetNewRallyPointForDeerAndLions.cpp | 13 ++-- .../WildlifeState/renderDebugDataMapData.cpp | 23 +++---- .../Map/WildlifeState/updateNofFpoints.cpp | 30 ++++----- .../WildlifeState/updateSection1034Info.cpp | 14 ++--- .../Map/WildlifeState/updateWildlife.cpp | 20 +++--- .../Map/WildlifeState/updateWildlifeGrid.cpp | 61 ++++++++++++------- 10 files changed, 146 insertions(+), 113 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createTree.cpp b/src/OpenSHC/Map/LandscapeState/createTree.cpp index 17372578a9..9e65e8ef49 100644 --- a/src/OpenSHC/Map/LandscapeState/createTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/createTree.cpp @@ -1,19 +1,19 @@ #include "../../Map.func.hpp" #include "../LandscapeState.func.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" + #include "OpenSHC/Globals/DAT_CurrentTreeID.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" #include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" -#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" namespace OpenSHC { namespace Map { using Map::Trees::TreeTypeShort; - // FUNCTION: STRONGHOLDCRUSADER 0x004F1CE0 int LandscapeState::createTree(undefined4 x, undefined4 y, TreeType treeType, undefined4 size, int stageRelatedValue, undefined4 param_6, int stage) @@ -86,7 +86,7 @@ namespace Map { = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originX; this->trees[_treeID].gmOriginY = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originY; - this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field28_0x854[treeType]; + this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field_0x854[treeType]; this->trees[_treeID].zero = 0; this->trees[_treeID].animationFrameIndex = (byte)DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f; this->trees[_treeID].one = 1; @@ -172,13 +172,13 @@ namespace Map { this->trees[_treeID].appleTreeColorVariation = 8; this->trees[_treeID].stage = 4; } - uVar3 = this->field0_0x0; - this->field0_0x0 = 0; + uVar3 = this->field_0x0; + this->field_0x0 = 0; /* *** Update the tree state *** */ (*DAT_OrganismDefinedData::instance.UpdateTree[(short)this->trees[_treeID].treeType])(); - this->field0_0x0 = uVar3; + this->field_0x0 = uVar3; return _treeID; } diff --git a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp index 4f3d484d9f..378e66f410 100644 --- a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp @@ -5,6 +5,7 @@ #include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Random/RNG.func.hpp" #include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Game/Player/PlayerData.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" @@ -59,9 +60,10 @@ namespace Map { local_1c = 3; _pKeep = &DAT_GameState::instance.playerDataArray[1]; do { - if ((local_1c + -2 != _playerID) && ((_pKeep->keep).id)) { - iVar5 = (_pKeep->keep).xEntry; - iVar8 = (_pKeep->keep).yEntry; + if ((local_1c + -2 != _playerID) + && ((_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).id)) { + iVar5 = (_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).xEntry; + iVar8 = (_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).yEntry; uVar2 = DAT_UnitsState::instance.units[unitID].x - iVar5; uVar6 = (int)uVar2 >> 0x1f; uVar3 = _y - iVar8; @@ -77,10 +79,12 @@ namespace Map { local_2c = iVar4; } } - if ((local_1c + -1 != _playerID) && (_pKeep[1].keep.id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[1].keep.xEntry; + if ((local_1c + -1 != _playerID) + && (_pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x + - _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[1].keep.yEntry; + uVar3 = _y - _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; iVar8 = (uVar2 ^ uVar6) - uVar6; uVar2 = (int)uVar3 >> 0x1f; iVar5 = (uVar3 ^ uVar2) - uVar2; @@ -88,15 +92,19 @@ namespace Map { iVar5 = iVar8; } if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[1].keep.xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[1].keep.yEntry; + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + + _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + + _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; local_2c = iVar5; } } - if ((local_1c != _playerID) && (_pKeep[2].keep.id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[2].keep.xEntry; + if ((local_1c != _playerID) + && (_pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x + - _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[2].keep.yEntry; + uVar3 = _y - _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; iVar8 = (uVar2 ^ uVar6) - uVar6; uVar2 = (int)uVar3 >> 0x1f; iVar5 = (uVar3 ^ uVar2) - uVar2; @@ -104,15 +112,19 @@ namespace Map { iVar5 = iVar8; } if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[2].keep.xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[2].keep.yEntry; + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + + _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + + _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; local_2c = iVar5; } } - if ((local_1c + 1 != _playerID) && (_pKeep[3].keep.id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - _pKeep[3].keep.xEntry; + if ((local_1c + 1 != _playerID) + && (_pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { + uVar2 = (int)DAT_UnitsState::instance.units[unitID].x + - _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[3].keep.yEntry; + uVar3 = _y - _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; iVar8 = (uVar2 ^ uVar6) - uVar6; uVar2 = (int)uVar3 >> 0x1f; iVar5 = (uVar3 ^ uVar2) - uVar2; @@ -120,8 +132,10 @@ namespace Map { iVar5 = iVar8; } if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + _pKeep[3].keep.xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + _pKeep[3].keep.yEntry; + _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + + _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; + _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + + _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; local_2c = iVar5; } } @@ -135,8 +149,7 @@ namespace Map { _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 100 + -0x32 + _y; MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); } - MACRO_CALL_MEMBER( - Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, (undefined4)((int)((int)DAT_UnitsState::instance.units[unitID].owner)), 0, (int)((int)((short)this->trees[_treeID].xPosition * 8)), (int)((int)((short)this->trees[_treeID].yPosition * 8)), diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index 7f0d7fbd26..a6322c5b3d 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -46,7 +46,7 @@ namespace Map { && (((_treeType = (int)(short)this->trees[treeID].treeType, _treeType < 5 || (0x13 < _treeType)) && (this->trees[treeID].zeroUpTo2 == 0)))))) && ((((short)this->trees[treeID].stageRelated2 <= (short)this->trees[treeID].stageRelated1 - && (this->field1_0x4)) + && (this->field_0x4)) && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_MAP_EDITOR_LANDSCAPING)))) { piVar1 = &this->trees[treeID].stageTracker; *piVar1 = *piVar1 + 1; @@ -84,9 +84,8 @@ namespace Map { (uint)((int)((int)(short)this->trees[treeID].xPosition)), (uint)((int)((int)(short)this->trees[treeID].yPosition))); if (iVar3) { - size = MACRO_CALL_MEMBER( - Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, this)( - (int)(short)this->trees[treeID].treeType, 0); + size = MACRO_CALL_MEMBER(Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, + this)((int)(short)this->trees[treeID].treeType, 0); _treeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, this)( DAT_PathFindingState::instance.ALG_ResultX, (undefined4)((int)(DAT_PathFindingState::instance.ALG_ResultY)), @@ -96,8 +95,8 @@ namespace Map { = DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] | 0x1000; DAT_TileMapState::instance.OrganismLayer[iVar3] = (short)_treeID; - MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, - DAT_TileMapState::ptr)(_treeID, 0); + MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)( + _treeID, 0); MACRO_CALL_MEMBER( Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)( diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 340dab6437..81b1d75dcd 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -45,8 +45,8 @@ namespace Map { this->casDisRelated = param_2; this->candidateIndex = 0; this->candidateIndex2 = 1; - if (this->grid[iVar5][local_1c].field20_0x50 != 0) { - piVar4 = &this->grid[0][0].field15_0x3c; + if (this->grid[iVar5][local_1c].field_0x50 != 0) { + piVar4 = &this->grid[0][0].field_0x3c; iVar12 = 0x28; do { iVar3 = 0x28; @@ -62,7 +62,7 @@ namespace Map { } while (iVar12); this->DAT_Y10_Array_Section1034[0] = (short)local_1c; this->DAT_X10_Array_Section1034[0] = (short)iVar5; - this->grid[iVar5][local_1c].casDisRelated2 = this->grid[iVar5][local_1c].field20_0x50; + this->grid[iVar5][local_1c].casDisRelated2 = this->grid[iVar5][local_1c].field_0x50; iVar12 = this->grid[iVar5][local_1c].separateAreaID; if (this->candidateIndex != this->candidateIndex2) { do { @@ -74,7 +74,7 @@ namespace Map { uVar7 = ((Point8IntXY*)(piVar4 + -1))->xOffset + iVar8; if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) && this->grid[uVar7][uVar9].casDisRelated2 == 0) { this->grid[uVar7][uVar9].casDisRelated2 = iVar10; this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; @@ -88,7 +88,7 @@ namespace Map { uVar7 = piVar4[1] + iVar8; if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) && this->grid[uVar7][uVar9].casDisRelated2 == 0) { this->grid[uVar7][uVar9].casDisRelated2 = iVar10; this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; @@ -102,7 +102,7 @@ namespace Map { uVar7 = piVar4[3] + iVar8; if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) && this->grid[uVar7][uVar9].casDisRelated2 == 0) { this->grid[uVar7][uVar9].casDisRelated2 = iVar10; this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; @@ -116,7 +116,7 @@ namespace Map { uVar7 = piVar4[5] + iVar8; if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field20_0x50, 0 < iVar10) + && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) && this->grid[uVar7][uVar9].casDisRelated2 == 0) { this->grid[uVar7][uVar9].casDisRelated2 = iVar10; this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; @@ -137,7 +137,7 @@ namespace Map { uVar7 = (uint)(byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; - this->grid[iVar5][local_1c].field15_0x3c = 1; + this->grid[iVar5][local_1c].field_0x3c = 1; this->grid[iVar5][local_1c].casDisRelated2 = 0; while (true) { local_14 = -1; @@ -224,10 +224,12 @@ namespace Map { local_1c = local_1c + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_14 * 8 + 4); - this->grid[iVar5][local_1c].field15_0x3c = 1; + this->grid[iVar5][local_1c].field_0x3c = 1; uVar9 = iVar5 * 10 + 5; uVar11 = local_1c * 10 + 5; - if (uVar9 < 400 && uVar11 < 400 && *(char*)(uVar11 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar9) != '\0') { + if (uVar9 < 400 && uVar11 < 400 + && *(char*)(uVar11 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar9) + != '\0') { DAT_TribesState::instance.tribes[param_1] .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] = (short)iVar5 * 10 + 5; diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index 72ee6aadae..8ae0b1aa19 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -45,7 +45,7 @@ namespace Map { this->casDisRelated = always2or3or5; this->candidateIndex = 0; this->candidateIndex2 = 1; - piVar9 = &this->grid[0][0].field15_0x3c; + piVar9 = &this->grid[0][0].field_0x3c; iVar11 = 0x28; do { iVar5 = 0x28; @@ -78,7 +78,7 @@ namespace Map { if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember && _currentArea == this->grid[uVar6][uVar10].separateAreaID) { if (!always0or1) { - if (this->grid[uVar6][uVar10].field13_0x34 == 0) { + if (this->grid[uVar6][uVar10].field_0x34 == 0) { if (DAT_TribesState::instance.tribes[tribeID].tribeType == (AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_SPEARMEN)) { _count = this->grid[uVar6][uVar10].deerCount; @@ -113,7 +113,7 @@ namespace Map { _randomDirection = (uint)(byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; - this->grid[_x10][_y10].field15_0x3c = 1; + this->grid[_x10][_y10].field_0x3c = 1; this->grid[_x10][_y10].casDisRelated2 = 0; while (true) { local_18 = -1; @@ -194,10 +194,13 @@ namespace Map { _x10 = _x10 + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[local_18].int_.xOffset; _y10 = _y10 + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_18 * 8 + 4); - this->grid[_x10][_y10].field15_0x3c = 1; + this->grid[_x10][_y10].field_0x3c = 1; _destinationY = _y10 * 10 + 5; uVar6 = _x10 * 10 + 5; - if (uVar6 < 400 && _destinationY < 400 && *(char*)(_destinationY * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar6) != '\0') { + if (uVar6 < 400 && _destinationY < 400 + && *(char*)(_destinationY * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + + uVar6) + != '\0') { MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, DAT_PathFindingState::ptr)(_currentArea, uVar6, _destinationY); DAT_TribesState::instance.tribes[tribeID] diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp index 028e457124..48fef0679d 100644 --- a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -123,9 +123,8 @@ namespace Map { && (uVar5 = COL_DARK_GREEN::instance.shortValue, this->grid[iVar6][iVar8].farmFieldTiles == 0) && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].rabbitCount == 0) - && (uVar5 = COL_WHITE::instance.shortValue, - this->grid[iVar6][iVar8].field15_0x3c == 0)) { - iVar7 = this->grid[iVar6][iVar8].field20_0x50; + && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x3c == 0)) { + iVar7 = this->grid[iVar6][iVar8].field_0x50; uVar5 = COL_DARK_CYAN_GREY::instance.shortValue; goto joined_r0x0052c335; } @@ -142,7 +141,7 @@ namespace Map { iVar7 = this->grid[iVar6][iVar8].buildingTiles; joined_r0x0052c3aa: if (!iVar7) { - iVar7 = this->grid[iVar6][iVar8].field13_0x34; + iVar7 = this->grid[iVar6][iVar8].field_0x34; uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; goto joined_r0x0052c335; } @@ -164,36 +163,34 @@ namespace Map { && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].deerCount == 0) && (uVar5 = COL_VIVID_BLUE::instance.shortValue, this->grid[iVar6][iVar8].lionCount == 0) - && (uVar5 = COL_WHITE::instance.shortValue, - this->grid[iVar6][iVar8].field15_0x3c == 0)) { + && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x3c == 0)) { iVar7 = this->grid[iVar6][iVar8].casDisRelated2; uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; joined_r0x0052c46b: if (!iVar7) { - iVar7 = this->grid[iVar6][iVar8].field13_0x34; + iVar7 = this->grid[iVar6][iVar8].field_0x34; uVar5 = COL_BLACK::instance.shortValue; goto joined_r0x0052c335; } } } else if (this->DAT_DebugDataMapDataDisplayType == 7) { if ((this->grid[iVar6][iVar8].separateAreaID != 0) - && (uVar5 = COL_WHITE::instance.shortValue, - this->grid[iVar6][iVar8].field18_0x48 == 0)) { + && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x48 == 0)) { iVar7 = this->grid[iVar6][iVar8].deerCount; uVar5 = COL_RED::instance.shortValue; goto joined_r0x0052c46b; } } else if (this->DAT_DebugDataMapDataDisplayType == 8) { uVar5 = COL_WHITE::instance.shortValue; - if (this->grid[iVar6][iVar8].field24_0x60 == 0 - && (uVar5 = COL_BLACK::instance.shortValue, this->grid[iVar6][iVar8].field25_0x64 == 0) + if (this->grid[iVar6][iVar8].field_0x60 == 0 + && (uVar5 = COL_BLACK::instance.shortValue, this->grid[iVar6][iVar8].field_0x64 == 0) && (uVar5 = COL_BRIGHT_YELLOW::instance.shortValue, this->grid[iVar6][iVar8].castlebuildings == 0 && ((uVar5 = COL_BLUE::instance.shortValue, this->grid[iVar6][iVar8].separateAreaID != 0 && (uVar5 = COL_VIVID_BLUE::instance.shortValue, this->grid[iVar6][iVar8].unknownNonZero01 == 0))))) { - iVar7 = this->grid[iVar6][iVar8].field27_0x6c; + iVar7 = this->grid[iVar6][iVar8].field_0x6c; uVar5 = COL_RED::instance.shortValue; goto joined_r0x0052c335; } @@ -201,7 +198,7 @@ namespace Map { if (this->DAT_DebugDataMapDataDisplayType != 9) continue; uVar5 = COL_RED::instance.shortValue; - if (this->grid[iVar6][iVar8].field29_0x74 == 0 + if (this->grid[iVar6][iVar8].field_0x74 == 0 && (uVar5 = COL_VIVID_BLUE::instance.shortValue, this->grid[iVar6][iVar8].unknownNonZero01 == 0) && (uVar5 = COL_BLUE::instance.shortValue, diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp index 48a86a4c83..90cfdfef40 100644 --- a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -38,12 +38,13 @@ namespace Map { has nothing to do with mercrecruitable */ uVar6 = DAT_GameState::instance.mapAndTime - .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field128056_0x469d4] + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] .x; _someY = DAT_GameState::instance.mapAndTime - .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field128056_0x469d4] + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] .y; - if (uVar6 <= 0x18f && _someY <= 0x18f && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[_someY * 400 + uVar6] != '\0' + if (uVar6 <= 0x18f && _someY <= 0x18f + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[_someY * 400 + uVar6] != '\0' && (_separateAreaID = DAT_TileMapState::instance .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[_someY].addXgetTile + uVar6], @@ -67,7 +68,7 @@ namespace Map { uVar6 = 0xf; piVar5 = local_4; do { - if ((piVar5->field27_0x6c) && (0 < piVar5->firstMember)) { + if ((piVar5->field_0x6c) && (0 < piVar5->firstMember)) { uVar1 = uVar6 - 10; uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile @@ -84,7 +85,7 @@ namespace Map { .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5->field28_0x70; + = (short)piVar5->field_0x70; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] = (short)piVar5->casDisRelated2; @@ -100,13 +101,14 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; } } - if (piVar5[40].field27_0x6c != 0 && 0 < piVar5[40].firstMember + if (piVar5[40].field_0x6c != 0 && 0 < piVar5[40].firstMember && (uVar2 = DAT_TileMapState::instance.PathConnectionLayer [*(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile + local_10) + uVar6], _separateAreaID == uVar2) - && uVar6 <= 0x18f && local_10 <= 0x12b4 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar6] != '\0') { + && uVar6 <= 0x18f && local_10 <= 0x12b4 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar6] != '\0') { DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar6; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; @@ -116,7 +118,7 @@ namespace Map { .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[40].field28_0x70; + = (short)piVar5[40].field_0x70; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] = (short)piVar5[40].casDisRelated2; @@ -131,7 +133,7 @@ namespace Map { iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; } - if ((piVar5[80].field27_0x6c != 0) && (0 < piVar5[80].firstMember)) { + if ((piVar5[80].field_0x6c != 0) && (0 < piVar5[80].firstMember)) { uVar1 = uVar6 + 10; uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile @@ -148,7 +150,7 @@ namespace Map { .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[80].field28_0x70; + = (short)piVar5[80].field_0x70; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] = (short)piVar5[80].casDisRelated2; @@ -164,7 +166,7 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; } } - if ((piVar5[120].field27_0x6c != 0) && (0 < piVar5[120].firstMember)) { + if ((piVar5[120].field_0x6c != 0) && (0 < piVar5[120].firstMember)) { uVar1 = uVar6 + 0x14; uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile @@ -181,7 +183,7 @@ namespace Map { .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[120].field28_0x70; + = (short)piVar5[120].field_0x70; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] = (short)piVar5[120].casDisRelated2; @@ -197,7 +199,7 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; } } - if ((piVar5[160].field27_0x6c != 0) && (0 < piVar5[160].firstMember)) { + if ((piVar5[160].field_0x6c != 0) && (0 < piVar5[160].firstMember)) { uVar1 = uVar6 + 0x1e; uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile @@ -214,7 +216,7 @@ namespace Map { .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[160].field28_0x70; + = (short)piVar5[160].field_0x70; DAT_TroopValueState::instance.attackInfo .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] = (short)piVar5[160].casDisRelated2; diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp index b255d31100..8bc9a6c371 100644 --- a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -30,12 +30,12 @@ namespace Map { piVar4 = piVar3; do { piVar4->unknownNonZero01 = 0; - piVar4->field27_0x6c = 0; + piVar4->field_0x6c = 0; if ((piVar4->castlebuildings) && (iVar1 = MACRO_CALL_MEMBER( Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(iVar6, iVar2), iVar1 != 0)) { - piVar4->field25_0x64 = piVar4->field25_0x64 + 1; + piVar4->field_0x64 = piVar4->field_0x64 + 1; } iVar6 = iVar6 + 1; piVar4 = piVar4 + 0x640; @@ -45,13 +45,13 @@ namespace Map { } while (iVar2 < 0x28); } iVar2 = 0; - piVar5 = &this->grid[0][0].field25_0x64; + piVar5 = &this->grid[0][0].field_0x64; do { iVar6 = 0; piVar7 = piVar5; do { if ((piVar7[-1] != 0) || (*piVar7 != 0)) { - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillUnknownNonZero01FromCell, this)( + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillZoneProximityFromCell, this)( iVar6, iVar2, 6); } iVar6 = iVar6 + 1; @@ -61,14 +61,14 @@ namespace Map { piVar5 = piVar5 + 0x28; } while (iVar2 < 0x28); iVar2 = 0; - piVar5 = &this->grid[0][0].field27_0x6c; + piVar5 = &this->grid[0][0].field_0x6c; do { iVar6 = 0; piVar7 = piVar5; do { if ((piVar7[-1] == 0) - && (iVar1 = MACRO_CALL_MEMBER( - Map::WildlifeState_Func::isSuitableWildlifeSpawnCell, this)(iVar6, iVar2), + && (iVar1 = MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)( + iVar6, iVar2), iVar1 != 0)) { *piVar7 = *piVar7 + 1; } diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp index 5075fd8e98..8bcc0d6501 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -27,17 +27,17 @@ namespace Map { iVar6 = iVar3; while (true) { do { - piVar5->field13_0x34 = 0; - piVar5->field20_0x50 = 0; - piVar5->field24_0x60 = 0; - piVar5->field25_0x64 = 0; - piVar5->field28_0x70 = piVar5->field28_0x70 / 100; + piVar5->field_0x34 = 0; + piVar5->field_0x50 = 0; + piVar5->field_0x60 = 0; + piVar5->field_0x64 = 0; + piVar5->field_0x70 = piVar5->field_0x70 / 100; if (piVar5->chimps) { if (piVar5->keeps) { - piVar5->field24_0x60 = 1; + piVar5->field_0x60 = 1; } if (piVar5->castlebuildings) { - piVar5->field24_0x60 = piVar5->field24_0x60 + 1; + piVar5->field_0x60 = piVar5->field_0x60 + 1; } } piVar5 = piVar5 + 0x640; @@ -68,12 +68,10 @@ namespace Map { } else { iVar7 = 2; LAB_0052dfdf: - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)( - iVar6, iVar3, iVar7); + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(iVar6, iVar3, iVar7); } if (piVar2->farmFieldTiles) { - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)( - iVar6, iVar3, 6); + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)(iVar6, iVar3, 6); } iVar6 = iVar6 + 1; piVar2 = piVar2 + 0x640; diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp index 40ff6ef777..437510125b 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -2,6 +2,7 @@ #include "../WildlifeState.func.hpp" #include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" @@ -61,43 +62,59 @@ namespace Map { int _x10; local_348 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] != -1) { - local_348 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[1].campground.tileEntry]; + local_348 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[1] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_344 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[2] != -1) { - local_344 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[2].campground.tileEntry]; + local_344 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[2] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_340 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[3] != -1) { - local_340 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[3].campground.tileEntry]; + local_340 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[3] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_33c = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[4] != -1) { - local_33c = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[4].campground.tileEntry]; + local_33c + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[4] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_338 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[5] != -1) { - local_338 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[5].campground.tileEntry]; + local_338 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[5] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_334 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[6] != -1) { - local_334 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[6].campground.tileEntry]; + local_334 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[6] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_330 = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[7] != -1) { - local_330 = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[7].campground.tileEntry]; + local_330 + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[7] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } local_32c = -1; if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[8] != -1) { - local_32c = (int)(short)DAT_TileMapState::instance - .PathConnectionLayer[DAT_GameState::instance.playerDataArray[8].campground.tileEntry]; + local_32c + = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[8] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; } if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { local_35c = 0; @@ -120,11 +137,11 @@ namespace Map { this->grid[_x10][_y10].rabbitCount = 0; this->grid[_x10][_y10].marshTiles = 0; this->grid[_x10][_y10].rockyTiles = 0; - this->grid[_x10][_y10].field18_0x48 = 0; + this->grid[_x10][_y10].field_0x48 = 0; this->grid[_x10][_y10].farmFieldTiles = 0; this->grid[_x10][_y10].chimps = 0; this->grid[_x10][_y10].castlebuildings = 0; - this->grid[_x10][_y10].field28_0x70 = 0; + this->grid[_x10][_y10].field_0x70 = 0; iVar8 = 0; do { local_320[iVar8 * 2] = -1; @@ -137,7 +154,9 @@ namespace Map { local_358 = 0; do { if ((uint)(local_358 + local_35c) < 400 && uVar9 < 400 - && *(char*)(uVar9 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + local_358 + local_35c) != '\0') { + && *(char*)(uVar9 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + + local_358 + local_35c) + != '\0') { pWVar7->firstMember = pWVar7->firstMember + 1; _tile = DAT_ViewportRenderState::instance.translationMatrix[uVar9].addXgetTile + local_358 + local_35c; @@ -184,7 +203,7 @@ namespace Map { this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; } } - this->grid[_x10][_y10].field28_0x70 = this->grid[_x10][_y10].field28_0x70 + this->grid[_x10][_y10].field_0x70 = this->grid[_x10][_y10].field_0x70 + (uint)DAT_TileMapState::instance.HeightLayer[_tile]; uVar6 = DAT_TileMapState::instance.LogicLayer[_tile]; if ((uVar6 & 0x100)) { @@ -253,7 +272,7 @@ namespace Map { this->grid[_x10][_y10].unstalkedUnitCount = this->grid[_x10][_y10].unstalkedUnitCount + 1; LAB_0052be68: - this->grid[_x10][_y10].field18_0x48 = this->grid[_x10][_y10].field18_0x48 + 1; + this->grid[_x10][_y10].field_0x48 = this->grid[_x10][_y10].field_0x48 + 1; } else { this->grid[_x10][_y10].stalkedUnitCount = this->grid[_x10][_y10].stalkedUnitCount + 1; From 02c766272391218d90094e686063a3f15c848938 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:01 +0100 Subject: [PATCH 03/43] reimplement: status of 11 ported functions SHC_3BB0A8C1_0x004F1CE0 56.6% createTree SHC_3BB0A8C1_0x004F2140 64.1% createRock SHC_3BB0A8C1_0x004F3150 23.4% spawnCrowFromNearbyTree SHC_3BB0A8C1_0x004F3960 54.1% updateTreeStage SHC_3BB0A8C1_0x0052BA10 57.3% updateWildlifeGrid SHC_3BB0A8C1_0x0052BF40 16.0% renderDebugDataMapData SHC_3BB0A8C1_0x0052CAB0 44.7% findAndSetNewRallyPointForDeerAndLions SHC_3BB0A8C1_0x0052CFE0 42.2% buildRallyPointPathForTribe SHC_3BB0A8C1_0x0052DF30 28.9% updateWildlife SHC_3BB0A8C1_0x0052E020 67.4% updateSection1034Info SHC_3BB0A8C1_0x0052E120 8.8% updateNofFpoints Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- status/addresses-SHC-3BB0A8C1.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 81b4e6a71e..dfe2d5e149 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38317,7 +38317,7 @@ SHC_3BB0A8C1_0x004F1C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F1C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F1CE0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F1CE0 | 56.6% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004F1FDC | 0.0% | Pending @@ -38383,7 +38383,7 @@ SHC_3BB0A8C1_0x004F2070 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F20E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2140 | 0.0% | Pending +SHC_3BB0A8C1_0x004F2140 | 64.1% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004F2220 | 100.0% | Reimplemented @@ -38571,7 +38571,7 @@ SHC_3BB0A8C1_0x004F3080 | 0.0% | Pending SHC_3BB0A8C1_0x004F30D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F3150 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3150 | 23.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004F3180 | 0.0% | Pending @@ -38593,7 +38593,7 @@ SHC_3BB0A8C1_0x004F3900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3960 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3960 | 54.1% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending @@ -49235,13 +49235,13 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 0.0% | Pending +SHC_3BB0A8C1_0x0052BA10 | 57.3% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending SHC_3BB0A8C1_0x0052BEA0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052BF40 | 0.0% | Pending +SHC_3BB0A8C1_0x0052BF40 | 16.0% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052C570 | 0.0% | Pending @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 0.0% | Pending SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052CAB0 | 44.7% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052CFE0 | 42.2% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending @@ -49291,15 +49291,15 @@ SHC_3BB0A8C1_0x0052DDF0 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052DF30 | 0.0% | Pending +SHC_3BB0A8C1_0x0052DF30 | 28.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052E020 | 0.0% | Pending +SHC_3BB0A8C1_0x0052E020 | 67.4% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x0052E120 | 0.0% | Pending +SHC_3BB0A8C1_0x0052E120 | 8.8% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From e8d11cb672df9066b4f214cbc746cf767f0041fa Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 21:50:53 +0100 Subject: [PATCH 04/43] Wildlife: updateNofFpoints and updateWildlife as plain grid loops - updateNofFpoints 8.8 -> 61.0: one 40x40 grid scan (x, y = 10 * cell + 5) instead of Ghidra's five specialised unrolled copies; MSVC unrolls the plain loop 5x like the original and strength-reduces `y <= 399` to the same `y * 12 <= 0x12b4` test. The path area is read as a signed short and the bubble sort is a for loop inside do/while(swapped). Left: register allocation for the column and row counters. - updateWildlife 28.9 -> 50.3: both passes are plain 40x40 loops and the flood-fill choice is an else-if chain. Left: the original keeps `this` in ecx across the flood-fill calls (LTCG) where we spill it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/WildlifeState/updateNofFpoints.cpp | 327 +++++------------- .../Map/WildlifeState/updateWildlife.cpp | 95 ++--- status/addresses-SHC-3BB0A8C1.txt | 4 +- 3 files changed, 117 insertions(+), 309 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp index 90cfdfef40..49ac7cb712 100644 --- a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -19,250 +19,91 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052E120 void WildlifeState::updateNofFpoints() { - uint uVar1; - ushort uVar2; - bool bVar3; - short* psVar4; - WildlifeGridElement* piVar5; - int iVar5; - uint uVar6; - int iVar7; - short sVar8; - short (*src)[8]; - uint local_10; - int local_c; - WildlifeGridElement* local_4; - uint _someY; - ushort _separateAreaID; - /* - has nothing to do with mercrecruitable - */ - uVar6 = DAT_GameState::instance.mapAndTime - .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] - .x; - _someY = DAT_GameState::instance.mapAndTime - .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] - .y; - if (uVar6 <= 0x18f && _someY <= 0x18f - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[_someY * 400 + uVar6] != '\0' - && (_separateAreaID = DAT_TileMapState::instance - .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[_someY].addXgetTile - + uVar6], - DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY)) { - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillCasDisFromSignpost, this)(); - DAT_TroopValueState::instance.attackInfo.nof_fpoints = 0; - psVar4 = DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[0] + 2; - do { - psVar4[1] = 0; - *psVar4 = 0; - psVar4[-1] = 0; - (*(short (*)[8])(psVar4 + -2))[0] = 0; - psVar4 = psVar4 + 8; - } while ((int)psVar4 < 0x1784940); - sVar8 = 5; - local_c = 2000; - local_4 = &this->grid[0][0]; - local_10 = 60; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints; - do { - uVar6 = 0xf; - piVar5 = local_4; - do { - if ((piVar5->field_0x6c) && (0 < piVar5->firstMember)) { - uVar1 = uVar6 - 10; - uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 - + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile - + local_10) - - 10]; - if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { - DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5->field_0x70; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - = (short)piVar5->casDisRelated2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] - = (DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - + 4) - * 0x32 - - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; - DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; - } - } - if (piVar5[40].field_0x6c != 0 && 0 < piVar5[40].firstMember - && (uVar2 = DAT_TileMapState::instance.PathConnectionLayer - [*(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile - + local_10) - + uVar6], - _separateAreaID == uVar2) - && uVar6 <= 0x18f && local_10 <= 0x12b4 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar6] != '\0') { - DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar6; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[40].field_0x70; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - = (short)piVar5[40].casDisRelated2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] - = (DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - + 4) - * 0x32 - - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; - DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; - } - if ((piVar5[80].field_0x6c != 0) && (0 < piVar5[80].firstMember)) { - uVar1 = uVar6 + 10; - uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 - + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile - + local_10) - + 10]; - if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { - DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[80].field_0x70; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - = (short)piVar5[80].casDisRelated2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] - = (DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - + 4) - * 0x32 - - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; - DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; - } - } - if ((piVar5[120].field_0x6c != 0) && (0 < piVar5[120].firstMember)) { - uVar1 = uVar6 + 0x14; - uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 - + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile - + local_10) - + 0x14]; - if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { - DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[120].field_0x70; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - = (short)piVar5[120].casDisRelated2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] - = (DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - + 4) - * 0x32 - - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; - DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; - } - } - if ((piVar5[160].field_0x6c != 0) && (0 < piVar5[160].firstMember)) { - uVar1 = uVar6 + 0x1e; - uVar2 = DAT_TileMapState::instance.PathConnectionLayer[uVar6 - + *(int*)((int)&DAT_ViewportRenderState::instance.translationMatrix[0].addXgetTile - + local_10) - + 0x1e]; - if (_separateAreaID == uVar2 && uVar1 <= 0x18f && local_10 <= 0x12b4 - && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[local_c + uVar1] != '\0') { - DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[iVar5][0] = (short)uVar1; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = sVar8; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = uVar2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] - = (short)piVar5[160].field_0x70; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - = (short)piVar5[160].casDisRelated2; - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] - = (DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] - + 4) - * 0x32 - - DAT_TroopValueState::instance.attackInfo - .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; - DAT_TroopValueState::instance.attackInfo.nof_fpoints = iVar5; - } - } - uVar6 = uVar6 + 0x32; - piVar5 = piVar5 + 200; - } while ((int)uVar6 < 0x19f); - local_c = local_c + 4000; - local_10 = local_10 + 0x78; - local_4 = local_4 + 1; - sVar8 = sVar8 + 10; - } while ((int)local_10 < 0x12fc); - do { - bVar3 = false; - iVar7 = 0; - if (iVar5 == 1 || iVar5 + -1 < 0) {} - src = DAT_TroopValueState::instance.attackInfo.nof_fpointsArray; - do { - if (src[1][6] < (*src)[6]) { - bVar3 = true; - MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, - (void*)((int)(src)), - (void*)((int)(DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy))); - MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)( - 0x10, (void*)((int)(src + 1)), (void*)((int)(src))); - MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(0x10, - (void*)((int)(DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy)), - (void*)((int)(src + 1))); - iVar5 = DAT_TroopValueState::instance.attackInfo.nof_fpoints; - } - iVar7 = iVar7 + 1; - src = src + 1; - } while (iVar7 < iVar5 + -1); - } while (bVar3); + uint const signX = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .x; + uint const signY = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .y; + if (signX > 399 || signY > 399) { + return; } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[signY * 400 + signX] == '\0') { + return; + } + int const separateAreaID + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[signY].addXgetTile + signX]; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillCasDisFromSignpost, this)(); + DAT_TroopValueState::instance.attackInfo.nof_fpoints = 0; + for (int i = 0; i < 50; i++) { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][3] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][2] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][1] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][0] = 0; + } + for (int gridY = 0; gridY < 40; gridY++) { + uint const y = gridY * 10 + 5; + for (int gridX = 0; gridX < 40; gridX++) { + uint const x = gridX * 10 + 5; + if (!this->grid[gridX][gridY].field_0x6c || this->grid[gridX][gridY].firstMember <= 0) { + continue; + } + int const areaID + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (separateAreaID != areaID || x > 399 || y > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == '\0') { + continue; + } + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][0] = (short)x; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = (short)y; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = (short)areaID; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)this->grid[gridX][gridY].field_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)this->grid[gridX][gridY].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 50 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + DAT_TroopValueState::instance.attackInfo.nof_fpoints + = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + } + } + bool swapped; + do { + swapped = false; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.nof_fpoints - 1; i++) { + if (DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1][6] + < DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][6]) { + swapped = true; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i], + DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1], + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i]); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1]); + } + } + } while (swapped); } } diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp index 8bcc0d6501..f1bd01b239 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -13,72 +13,39 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052DF30 void WildlifeState::updateWildlife() { - WildlifeGridElement* piVar1; - WildlifeGridElement* piVar2; - int iVar3; - WildlifeGridElement* piVar4; - WildlifeGridElement* piVar5; - int iVar6; - int iVar7; - if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { - piVar1 = &this->grid[0][0]; - iVar3 = 0x28; - piVar5 = piVar1; - iVar6 = iVar3; - while (true) { - do { - piVar5->field_0x34 = 0; - piVar5->field_0x50 = 0; - piVar5->field_0x60 = 0; - piVar5->field_0x64 = 0; - piVar5->field_0x70 = piVar5->field_0x70 / 100; - if (piVar5->chimps) { - if (piVar5->keeps) { - piVar5->field_0x60 = 1; - } - if (piVar5->castlebuildings) { - piVar5->field_0x60 = piVar5->field_0x60 + 1; - } - } - piVar5 = piVar5 + 0x640; - iVar6 = iVar6 + -1; - } while (iVar6); - piVar1 = piVar1 + 0x28; - iVar3 = iVar3 + -1; - if (!iVar3) - break; - iVar6 = 0x28; - piVar5 = piVar1; - } - piVar4 = &this->grid[0][0]; - iVar3 = 0; - do { - iVar6 = 0; - piVar2 = piVar4; - do { - if (!piVar2->unstalkedUnitCount) { - if (piVar2->buildingTiles) { - iVar7 = 2; - goto LAB_0052dfdf; - } - if (piVar2->lionCount) { - iVar7 = 3; - goto LAB_0052dfdf; - } - } else { - iVar7 = 2; - LAB_0052dfdf: - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(iVar6, iVar3, iVar7); + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + this->grid[x][y].field_0x34 = 0; + this->grid[x][y].field_0x50 = 0; + this->grid[x][y].field_0x60 = 0; + this->grid[x][y].field_0x64 = 0; + this->grid[x][y].field_0x70 = this->grid[x][y].field_0x70 / 100; + if (this->grid[x][y].chimps) { + if (this->grid[x][y].keeps) { + this->grid[x][y].field_0x60 = 1; } - if (piVar2->farmFieldTiles) { - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)(iVar6, iVar3, 6); + if (this->grid[x][y].castlebuildings) { + this->grid[x][y].field_0x60 = this->grid[x][y].field_0x60 + 1; } - iVar6 = iVar6 + 1; - piVar2 = piVar2 + 0x640; - } while (iVar6 < 0x28); - iVar3 = iVar3 + 1; - piVar4 = piVar4 + 0x28; - } while (iVar3 < 0x28); + } + } + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + if (this->grid[x][y].unstalkedUnitCount) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 2); + } else if (this->grid[x][y].buildingTiles) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 2); + } else if (this->grid[x][y].lionCount) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 3); + } + if (this->grid[x][y].farmFieldTiles) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)(x, y, 6); + } + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index dfe2d5e149..061d06eb0f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49291,7 +49291,7 @@ SHC_3BB0A8C1_0x0052DDF0 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052DF30 | 28.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052DF30 | 50.3% | this kept in ecx across calls (LTCG) SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending @@ -49299,7 +49299,7 @@ SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending SHC_3BB0A8C1_0x0052E020 | 67.4% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x0052E120 | 8.8% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052E120 | 61.0% | Register allocation of the grid counters SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From fbf05619cf96f249fa45fb5247f512664a6fac51 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 21:53:48 +0100 Subject: [PATCH 05/43] LandscapeState: updateTreeStage and createRock follow the binary Both fix behaviour carried over from the decompiler output: - updateTreeStage 54.1 -> 85.7: a tree reaching stage 6 dies and returns (Ghidra also ran the spread code for it), and a spread past the interval resets the tree to stage 5 and returns instead of falling through to re-seed at stage 3. getValueFrom0UpTo3ForTreeTypeAndTreeStage and createTree are called on the global DAT_LandscapeState like the original, and the one big condition is split into early returns. Left: edx kept across the size call (LTCG). - createRock (64.1, unchanged): the slot search gives up at rockID >= 3999 like the original; with Ghidra's `3999 <` test a full table fell out of the loop at 4000 and wrote past the array. Left: which register holds 1. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 18 +-- .../Map/LandscapeState/updateTreeStage.cpp | 150 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 4 +- 3 files changed, 81 insertions(+), 91 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index 1f11a840bb..fe98ec449a 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -12,22 +12,16 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F2140 int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) { - short* _pRock; + // find a free rock slot int _rockID; - _rockID = 1; - /* - the while loop finds the spot to write this tree data - */ - _pRock = &this->rocks[1].one; - do { - if (*_pRock == 0) + for (_rockID = 1; _rockID < 4000; _rockID++) { + if (this->rocks[_rockID].one == 0) { break; - if (3999 < _rockID) { + } + if (_rockID >= 3999) { return 0; } - _rockID = _rockID + 1; - _pRock = _pRock + 0x10; - } while (_rockID < 4000); + } this->rocks[_rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; this->rocks[_rockID].size = (short)size; diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index a6322c5b3d..9b0d5fb0b4 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -13,6 +13,7 @@ #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" #include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -29,85 +30,80 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F3960 void LandscapeState::updateTreeStage(uint treeID, uint rng) { - int* piVar1; - BOOLEnum BVar2; - int _stage; - int iVar3; - undefined4 size; - int _treeID; - int _treeType; - TreeTypeShort _treeType_2; - if ((((DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) - || ((!DAT_GameCore::instance.isTimeHalted - && (BVar2 = MACRO_CALL(UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( - UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO), - !BVar2)))) - && (((this->trees[treeID].rng1 & 0x3fU) == rng - && (((_treeType = (int)(short)this->trees[treeID].treeType, _treeType < 5 || (0x13 < _treeType)) - && (this->trees[treeID].zeroUpTo2 == 0)))))) - && ((((short)this->trees[treeID].stageRelated2 <= (short)this->trees[treeID].stageRelated1 - && (this->field_0x4)) - && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_MAP_EDITOR_LANDSCAPING)))) { - piVar1 = &this->trees[treeID].stageTracker; - *piVar1 = *piVar1 + 1; - iVar3 = this->trees[treeID].stage; - if (DAT_OrganismDefinedData::instance.TreeStageLevels[_treeType][iVar3 + 1] - <= this->trees[treeID].stageTracker) { - _stage = iVar3 + 1; - this->trees[treeID].stage = _stage; - MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, _stage); - iVar3 = this->trees[treeID].stage; - if (5 < iVar3) { - this->trees[treeID].state = 3; - } - if (3 < iVar3) { - DAT_GameState::instance.mapAndTime.treeSpreadCounter - = DAT_GameState::instance.mapAndTime.treeSpreadCounter + 1; - if (DAT_GameState::instance.mapAndTime.treeSpreadInterval - < DAT_GameState::instance.mapAndTime.treeSpreadCounter) { - DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0; - _treeType_2 = this->trees[treeID].treeType; - this->trees[treeID].stage = 5; - this->trees[treeID].stageTracker - = DAT_OrganismDefinedData::instance.TreeStageLevels[(short)_treeType_2][5]; - } - /* - set spreadcounter to lowest value for tree type? - */ - this->trees[treeID].stageTracker - = DAT_OrganismDefinedData::instance.TreeStageLevels[(short)this->trees[treeID].treeType][3]; - this->trees[treeID].stage = 3; - DAT_GameState::instance.mapAndTime.newOrganismsValue2 - = DAT_GameState::instance.mapAndTime.newOrganismsValue2 + 1; - iVar3 = MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)(treeID, - (int)((int)((short)this->trees[treeID].treeType)), - (uint)((int)((int)(short)this->trees[treeID].xPosition)), - (uint)((int)((int)(short)this->trees[treeID].yPosition))); - if (iVar3) { - size = MACRO_CALL_MEMBER(Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, - this)((int)(short)this->trees[treeID].treeType, 0); - _treeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, this)( - DAT_PathFindingState::instance.ALG_ResultX, - (undefined4)((int)(DAT_PathFindingState::instance.ALG_ResultY)), - (TreeType)(short)this->trees[treeID].treeType, (undefined4)((int)(size)), 0, 0, 0); - iVar3 = DAT_PathFindingState::instance.ALG_ResultTile; - DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] - = DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] - | 0x1000; - DAT_TileMapState::instance.OrganismLayer[iVar3] = (short)_treeID; - MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)( - _treeID, 0); - MACRO_CALL_MEMBER( - Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, - DAT_PathFindingState::ptr)( - (int)(short)this->trees[_treeID].yPosition, (int)((int)(this->trees[_treeID].tile))); - DAT_GameState::instance.mapAndTime.newOrganisms - = DAT_GameState::instance.mapAndTime.newOrganisms + 1; - DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; - } - } + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + if (DAT_GameCore::instance.isTimeHalted) { + return; } + if (MACRO_CALL(UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( + UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO)) { + return; + } + } + if ((this->trees[treeID].rng1 & 0x3fU) != rng) { + return; + } + int const treeType = this->trees[treeID].treeType; + if (treeType >= 5 && treeType <= 19) { + return; + } + if (this->trees[treeID].zeroUpTo2 != 0) { + return; + } + if (this->trees[treeID].stageRelated1 < (short)this->trees[treeID].stageRelated2) { + return; + } + if (!this->field_0x4) { + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + return; + } + this->trees[treeID].stageTracker = this->trees[treeID].stageTracker + 1; + if (this->trees[treeID].stageTracker + < DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][this->trees[treeID].stage + 1]) { + return; + } + this->trees[treeID].stage = this->trees[treeID].stage + 1; + MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage); + if (this->trees[treeID].stage >= 6) { + this->trees[treeID].state = 3; + return; + } + if (this->trees[treeID].stage < 4) { + return; + } + DAT_GameState::instance.mapAndTime.treeSpreadCounter = DAT_GameState::instance.mapAndTime.treeSpreadCounter + 1; + if (DAT_GameState::instance.mapAndTime.treeSpreadCounter + > DAT_GameState::instance.mapAndTime.treeSpreadInterval) { + DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0; + this->trees[treeID].stage = 5; + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][5]; + return; + } + // set the spread counter to the lowest value for the tree type + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][3]; + this->trees[treeID].stage = 3; + DAT_GameState::instance.mapAndTime.newOrganismsValue2 + = DAT_GameState::instance.mapAndTime.newOrganismsValue2 + 1; + if (!MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)( + treeID, this->trees[treeID].treeType, this->trees[treeID].xPosition, this->trees[treeID].yPosition)) { + return; } + int const size = MACRO_CALL_MEMBER(Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, + DAT_LandscapeState::ptr)(this->trees[treeID].treeType, 0); + int const newTreeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, DAT_LandscapeState::ptr)( + DAT_PathFindingState::instance.ALG_ResultX, DAT_PathFindingState::instance.ALG_ResultY, + (TreeType)this->trees[treeID].treeType, size, 0, 0, 0); + DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] + = DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] | 0x1000; + DAT_TileMapState::instance.OrganismLayer[DAT_PathFindingState::instance.ALG_ResultTile] = (short)newTreeID; + MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)(newTreeID, 0); + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(this->trees[newTreeID].yPosition, this->trees[newTreeID].tile); + DAT_GameState::instance.mapAndTime.newOrganisms = DAT_GameState::instance.mapAndTime.newOrganisms + 1; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 061d06eb0f..98a06a9c88 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38383,7 +38383,7 @@ SHC_3BB0A8C1_0x004F2070 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F20E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2140 | 64.1% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004F2140 | 64.1% | Register holding the constant 1 SHC_3BB0A8C1_0x004F2220 | 100.0% | Reimplemented @@ -38593,7 +38593,7 @@ SHC_3BB0A8C1_0x004F3900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3960 | 54.1% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004F3960 | 85.7% | edx kept across a call (LTCG) SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending From e32e5d8335e98bef920d7937e386dd51ce05efb4 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:13:47 +0100 Subject: [PATCH 06/43] LandscapeState: spawnCrowFromNearbyTree as plain loops 23.4 -> 98.3. Ghidra's four unrolled copies of the keep search are one `for` over players 1..8, which MSVC unrolls 4x itself. The distance is max(|dx|, |dy|) written as a ternary over abs(); the if-form costs half the match. The "sound played" flag is a BOOL (the original stores a dword). Left: two register choices for the tree-layer index and the owner. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../spawnCrowFromNearbyTree.cpp | 192 ++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 135 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp index 378e66f410..6cf5045f13 100644 --- a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp @@ -26,143 +26,67 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F3150 void LandscapeState::spawnCrowFromNearbyTree(int unitID) { - int _treeID; - uint uVar2; - uint uVar3; - int iVar5; - PlayerData* _pKeep; - uint uVar6; - int iVar7; - int iVar8; - int local_2c; - int _microY; - int _microX; - int local_1c; - int local_c; - bool bVar1 = false; - for (local_c = 0; local_c < 8; local_c++) { - int _y = (int)DAT_UnitsState::instance.units[unitID].y; - if ((((DAT_TileMapState::instance - .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[_y][local_c] - + DAT_UnitsState::instance.units[unitID].tile] - != 0) - && (_treeID = (int)DAT_TileMapState::instance - .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[_y][local_c] - + DAT_UnitsState::instance.units[unitID].tile], - _treeID < this->maxTreeCount)) - && (this->trees[_treeID].state == 2)) - && ((this->trees[_treeID].unknownDistanceRelatedToCrow != 0 - && (this->trees[_treeID].rng200till300 == 0)))) { - int _playerID = (int)DAT_UnitsState::instance.units[unitID].owner; - _microX = 0; - _microY = 0; - local_2c = 10000; - local_1c = 3; - _pKeep = &DAT_GameState::instance.playerDataArray[1]; - do { - if ((local_1c + -2 != _playerID) - && ((_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).id)) { - iVar5 = (_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).xEntry; - iVar8 = (_pKeep->buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]).yEntry; - uVar2 = DAT_UnitsState::instance.units[unitID].x - iVar5; - uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - iVar8; - iVar7 = (uVar2 ^ uVar6) - uVar6; - uVar2 = (int)uVar3 >> 0x1f; - int iVar4 = (uVar3 ^ uVar2) - uVar2; - if (iVar4 < iVar7) { - iVar4 = iVar7; - } - if (iVar4 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 + iVar5; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 + iVar8; - local_2c = iVar4; - } - } - if ((local_1c + -1 != _playerID) - && (_pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - - _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - iVar8 = (uVar2 ^ uVar6) - uVar6; - uVar2 = (int)uVar3 >> 0x1f; - iVar5 = (uVar3 ^ uVar2) - uVar2; - if (iVar5 < iVar8) { - iVar5 = iVar8; - } - if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 - + _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 - + _pKeep[1].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - local_2c = iVar5; - } - } - if ((local_1c != _playerID) - && (_pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - - _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - iVar8 = (uVar2 ^ uVar6) - uVar6; - uVar2 = (int)uVar3 >> 0x1f; - iVar5 = (uVar3 ^ uVar2) - uVar2; - if (iVar5 < iVar8) { - iVar5 = iVar8; - } - if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 - + _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 - + _pKeep[2].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - local_2c = iVar5; - } - } - if ((local_1c + 1 != _playerID) - && (_pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].id != 0)) { - uVar2 = (int)DAT_UnitsState::instance.units[unitID].x - - _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - uVar6 = (int)uVar2 >> 0x1f; - uVar3 = _y - _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - iVar8 = (uVar2 ^ uVar6) - uVar6; - uVar2 = (int)uVar3 >> 0x1f; - iVar5 = (uVar3 ^ uVar2) - uVar2; - if (iVar5 < iVar8) { - iVar5 = iVar8; - } - if (iVar5 < local_2c) { - _microX = (int)SEC_RNG::instance.currentNumber2 % 5 + -2 - + _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].xEntry; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 5 + -2 - + _pKeep[3].buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP].yEntry; - local_2c = iVar5; - } - } - iVar5 = local_1c + 2; - _pKeep = _pKeep + 4; - local_1c = local_1c + 4; - } while (iVar5 < 9); - if (local_2c == 10000) { - _microX = DAT_UnitsState::instance.units[unitID].x + -0x32 - + (int)SEC_RNG::instance.currentNumber2 % 100; - _microY = ((int)SEC_RNG::instance.currentNumber2 >> 8) % 100 + -0x32 + _y; - MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + BOOL playedSound = FALSE; + for (int direction = 0; direction < 8; direction++) { + int const y = DAT_UnitsState::instance.units[unitID].y; + short const treeID = DAT_TileMapState::instance + .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[y][direction] + + DAT_UnitsState::instance.units[unitID].tile]; + if (treeID == 0 || treeID >= this->maxTreeCount) { + continue; + } + if (this->trees[treeID].state != 2 || this->trees[treeID].unknownDistanceRelatedToCrow == 0 + || this->trees[treeID].rng200till300 != 0) { + continue; + } + int const playerID = DAT_UnitsState::instance.units[unitID].owner; + int targetX = 0; + int targetY = 0; + int closestDistance = 10000; + for (int keepPlayerID = 1; keepPlayerID < 9; keepPlayerID++) { + if (keepPlayerID == playerID + || !DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id) { + continue; } - MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, - (undefined4)((int)((int)DAT_UnitsState::instance.units[unitID].owner)), 0, - (int)((int)((short)this->trees[_treeID].xPosition * 8)), - (int)((int)((short)this->trees[_treeID].yPosition * 8)), - (int)((int)(DAT_TileMapState::instance.HeightLayer[this->trees[_treeID].tile] + 0x1e)), _microX * 8, - _microY * 8, 0xfa, Map::Entities::EntityTypeInt__ET_CROW, 0); - this->trees[_treeID].rng200till300 = SEC_RNG::instance.currentNumber2 % 100 + 200; - if (!bVar1) { - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - (int)(short)this->trees[_treeID].xPosition, (int)((int)((short)this->trees[_treeID].yPosition)), - DE::SHCDE::FX_CROW); - bVar1 = true; + int const distanceX = abs(DAT_UnitsState::instance.units[unitID].x + - DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .xEntry); + int const distanceY = abs(y + - DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .yEntry); + int const distance = distanceX > distanceY ? distanceX : distanceY; + if (distance < closestDistance) { + targetX = SEC_RNG::instance.currentNumber2 % 5 - 2 + + DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .xEntry; + targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 5 - 2 + + DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .yEntry; + closestDistance = distance; } } + if (closestDistance == 10000) { + targetX = DAT_UnitsState::instance.units[unitID].x - 50 + SEC_RNG::instance.currentNumber2 % 100; + targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 100 - 50 + y; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, + DAT_UnitsState::instance.units[unitID].owner, 0, this->trees[treeID].xPosition * 8, + this->trees[treeID].yPosition * 8, + DAT_TileMapState::instance.HeightLayer[this->trees[treeID].tile] + 30, targetX * 8, targetY * 8, 250, + Map::Entities::EntityTypeInt__ET_CROW, 0); + this->trees[treeID].rng200till300 = SEC_RNG::instance.currentNumber2 % 100 + 200; + if (!playedSound) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->trees[treeID].xPosition, this->trees[treeID].yPosition, DE::SHCDE::FX_CROW); + playedSound = TRUE; + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 98a06a9c88..46669de0b9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38571,7 +38571,7 @@ SHC_3BB0A8C1_0x004F3080 | 0.0% | Pending SHC_3BB0A8C1_0x004F30D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F3150 | 23.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004F3150 | 98.3% | Register allocation of two loads SHC_3BB0A8C1_0x004F3180 | 0.0% | Pending From 828ff6231a6a4cc663bf51abb21245d5ccee011e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:18:20 +0100 Subject: [PATCH 07/43] Wildlife: rebuild renderDebugDataMapData, end the row loop 16.0 -> 48.9 (normalized 55.4). Fixes a hang: the copied body ended its row loop with `if (40 < iVar8) {}` inside `while (true)`, so the debug map never returned. It is now two plain 40x40 loops like the original. Rebuilt from the binary rather than Ghidra's goto web: - each display type calls renderTextToScreen in its own arm, as the original pushes the full argument list per arm - each display type is an if/else-if chain that picks one ushort colour; the original tail-merges the shared endings (type 5 into type 4, type 7 into type 6) - the grid lines are two plain 41-step loops Left: register allocation. The original keeps y in ebp and x + 2 in ebx for the whole function, where we reload y from the stack. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../WildlifeState/renderDebugDataMapData.cpp | 349 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 177 insertions(+), 174 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp index 48fef0679d..e2e35c775d 100644 --- a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -29,194 +29,197 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052BF40 void WildlifeState::renderDebugDataMapData(int x, int y, int width, int height) { - int iVar2; - int iVar4; - int iVar8; - char* textAddress; - int x1 = x + 2; - if (!this->DAT_DebugDataMapDataDisplayType) { - textAddress = "Connect "; + int const x1 = x + 2; + if (this->DAT_DebugDataMapDataDisplayType == 0) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Connect ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 1) { - textAddress = "Chimps "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Chimps ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 2) { - textAddress = "Farmland "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Farmland ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 3) { - textAddress = "Humans "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Humans ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 4) { - textAddress = "Mankind "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Mankind ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 5) { - textAddress = "Deer "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Deer ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 6) { - textAddress = "Route "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Route ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 7) { - textAddress = "Panic "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Panic ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 8) { - textAddress = "Siege "; - } else { - if (this->DAT_DebugDataMapDataDisplayType != 9) - goto LAB_0052c0db; - textAddress = "Slink "; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Siege ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 9) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Slink ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } - MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - textAddress, x + 0x1a6, y + 4, Text::TTA_LEFT, 0xffffff, 0x11, FALSE, 0); - LAB_0052c0db: - /* - render the squares - */ - int iVar7 = 41; - int iVar6 = y; - do { + // render the squares + for (int line = 0; line < 41; line++) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x1, iVar6, x + 0x192, iVar6, (ushort)(COL_WHITE::instance.shortValue)); - iVar6 = iVar6 + 10; - iVar7 = iVar7 + -1; - } while (iVar7); - iVar7 = 41; - iVar6 = x1; - do { + x1, y + line * 10, x1 + 400, y + line * 10, COL_WHITE::instance.shortValue); + } + for (int line = 0; line < 41; line++) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - iVar6, y, iVar6, y + 400, (ushort)(COL_WHITE::instance.shortValue)); - iVar6 = iVar6 + 10; - iVar7 = iVar7 + -1; - iVar8 = 0; - } while (iVar7); - do { - for (iVar6 = 0; iVar6 < 40; iVar6++) { - if (0 < this->grid[iVar6][iVar8].firstMember) { - undefined2 uVar5 = COL_BLUE::instance.shortValue; - if (!this->DAT_DebugDataMapDataDisplayType) { - uint uVar1 = this->grid[iVar6][iVar8].separateAreaID; - uint uVar3 = uVar1 & 7; - if (!uVar1 || (uVar5 = COL_RED::instance.shortValue, uVar3 == 1) - || (uVar5 = COL_BRIGHT_YELLOW::instance.shortValue, - uVar3 == 2 - || ((uVar5 = COL_MODERATE_GREEN::instance.shortValue, - uVar3 == 3 || (uVar5 = COL_WHITE::instance.shortValue, uVar3 == 4)))) - || (uVar5 = COL_DARK_CYAN_GREY::instance.shortValue, uVar3 == 5)) - goto LAB_0052c526; - if (uVar3 == 6) { - LAB_0052c51f: - uVar5 = COL_LIME::instance.shortValue; - goto LAB_0052c526; - } - iVar2 = y + iVar8 * 10; - iVar4 = x1 + iVar6 * 10; - uVar5 = COL_VERY_DARK_GREY::instance.shortValue; - if (uVar3 == 7) { - uVar5 = COL_VIVID_BLUE::instance.shortValue; - } + x1 + line * 10, y, x1 + line * 10, y + 400, COL_WHITE::instance.shortValue); + } + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + if (this->grid[column][row].firstMember <= 0) { + continue; + } + int colour; + if (this->DAT_DebugDataMapDataDisplayType == 0) { + int const areaColour = this->grid[column][row].separateAreaID & 7; + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (areaColour == 1) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (areaColour == 2) { + colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + } else if (areaColour == 3) { + colour = (ushort)COL_MODERATE_GREEN::instance.shortValue; + } else if (areaColour == 4) { + colour = (ushort)COL_WHITE::instance.shortValue; + } else if (areaColour == 5) { + colour = (ushort)COL_DARK_CYAN_GREY::instance.shortValue; + } else if (areaColour == 6) { + colour = (ushort)COL_LIME::instance.shortValue; + } else if (areaColour == 7) { + colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + } else { + colour = (ushort)COL_VERY_DARK_GREY::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 1) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].chimps) { + colour = (ushort)COL_RED::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].farmFieldTiles) { + colour = (ushort)COL_DARK_GREEN::instance.shortValue; + } else if (this->grid[column][row].rabbitCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].field_0x3c) { + colour = (ushort)COL_WHITE::instance.shortValue; + } else if (this->grid[column][row].field_0x50) { + colour = (ushort)COL_DARK_CYAN_GREY::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].unstalkedUnitCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].unstalkedUnitCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].buildingTiles) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].field_0x34) { + colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; } else { - if (this->DAT_DebugDataMapDataDisplayType == 1) { - if (this->grid[iVar6][iVar8].separateAreaID != 0) { - iVar7 = this->grid[iVar6][iVar8].chimps; - uVar5 = COL_RED::instance.shortValue; - joined_r0x0052c335: - iVar2 = y + iVar8 * 10; - iVar4 = x1 + iVar6 * 10; - if (!iVar7) { - uVar5 = COL_LIME::instance.shortValue; - } - goto LAB_0052c533; - } - } else if (this->DAT_DebugDataMapDataDisplayType == 2) { - if (this->grid[iVar6][iVar8].separateAreaID != 0 - && (uVar5 = COL_DARK_GREEN::instance.shortValue, - this->grid[iVar6][iVar8].farmFieldTiles == 0) - && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].rabbitCount == 0) - && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x3c == 0)) { - iVar7 = this->grid[iVar6][iVar8].field_0x50; - uVar5 = COL_DARK_CYAN_GREY::instance.shortValue; - goto joined_r0x0052c335; - } - } else if (this->DAT_DebugDataMapDataDisplayType == 3) { - if (this->grid[iVar6][iVar8].separateAreaID != 0) { - iVar7 = this->grid[iVar6][iVar8].unstalkedUnitCount; - uVar5 = COL_RED::instance.shortValue; - goto joined_r0x0052c335; - } - } else if (this->DAT_DebugDataMapDataDisplayType == 4) { - if ((this->grid[iVar6][iVar8].separateAreaID != 0) - && (uVar5 = COL_RED::instance.shortValue, - this->grid[iVar6][iVar8].unstalkedUnitCount == 0)) { - iVar7 = this->grid[iVar6][iVar8].buildingTiles; - joined_r0x0052c3aa: - if (!iVar7) { - iVar7 = this->grid[iVar6][iVar8].field_0x34; - uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; - goto joined_r0x0052c335; - } - } - } else if (this->DAT_DebugDataMapDataDisplayType == 5) { - if (this->grid[iVar6][iVar8].separateAreaID != 0 - && (uVar5 = COL_RED::instance.shortValue, - this->grid[iVar6][iVar8].unstalkedUnitCount == 0) - && this->grid[iVar6][iVar8].buildingTiles == 0 - && (uVar5 = COL_BLACK::instance.shortValue, - this->grid[iVar6][iVar8].lionCount == 0 - && (this->grid[iVar6][iVar8].camelCount == 0))) { - iVar7 = this->grid[iVar6][iVar8].deerCount; - uVar5 = COL_MODERATE_GREEN::instance.shortValue; - goto joined_r0x0052c3aa; - } - } else if (this->DAT_DebugDataMapDataDisplayType == 6) { - if (this->grid[iVar6][iVar8].separateAreaID != 0 - && (uVar5 = COL_RED::instance.shortValue, this->grid[iVar6][iVar8].deerCount == 0) - && (uVar5 = COL_VIVID_BLUE::instance.shortValue, - this->grid[iVar6][iVar8].lionCount == 0) - && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x3c == 0)) { - iVar7 = this->grid[iVar6][iVar8].casDisRelated2; - uVar5 = COL_BRIGHT_YELLOW::instance.shortValue; - joined_r0x0052c46b: - if (!iVar7) { - iVar7 = this->grid[iVar6][iVar8].field_0x34; - uVar5 = COL_BLACK::instance.shortValue; - goto joined_r0x0052c335; - } - } - } else if (this->DAT_DebugDataMapDataDisplayType == 7) { - if ((this->grid[iVar6][iVar8].separateAreaID != 0) - && (uVar5 = COL_WHITE::instance.shortValue, this->grid[iVar6][iVar8].field_0x48 == 0)) { - iVar7 = this->grid[iVar6][iVar8].deerCount; - uVar5 = COL_RED::instance.shortValue; - goto joined_r0x0052c46b; - } - } else if (this->DAT_DebugDataMapDataDisplayType == 8) { - uVar5 = COL_WHITE::instance.shortValue; - if (this->grid[iVar6][iVar8].field_0x60 == 0 - && (uVar5 = COL_BLACK::instance.shortValue, this->grid[iVar6][iVar8].field_0x64 == 0) - && (uVar5 = COL_BRIGHT_YELLOW::instance.shortValue, - this->grid[iVar6][iVar8].castlebuildings == 0 - && ((uVar5 = COL_BLUE::instance.shortValue, - this->grid[iVar6][iVar8].separateAreaID != 0 - && (uVar5 = COL_VIVID_BLUE::instance.shortValue, - this->grid[iVar6][iVar8].unknownNonZero01 == 0))))) { - iVar7 = this->grid[iVar6][iVar8].field_0x6c; - uVar5 = COL_RED::instance.shortValue; - goto joined_r0x0052c335; - } - } else { - if (this->DAT_DebugDataMapDataDisplayType != 9) - continue; - uVar5 = COL_RED::instance.shortValue; - if (this->grid[iVar6][iVar8].field_0x74 == 0 - && (uVar5 = COL_VIVID_BLUE::instance.shortValue, - this->grid[iVar6][iVar8].unknownNonZero01 == 0) - && (uVar5 = COL_BLUE::instance.shortValue, - this->grid[iVar6][iVar8].separateAreaID != 0)) - goto LAB_0052c51f; - } - LAB_0052c526: - iVar4 = x1 + iVar6 * 10; - iVar2 = y + iVar8 * 10; + colour = (ushort)COL_LIME::instance.shortValue; } - LAB_0052c533: - MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( - iVar4 + 1, iVar2 + 1, iVar4 + 9, iVar2 + 9, (ushort)(uVar5)); + } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].unstalkedUnitCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].buildingTiles) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].lionCount) { + colour = (ushort)COL_BLACK::instance.shortValue; + } else if (this->grid[column][row].camelCount) { + colour = (ushort)COL_BLACK::instance.shortValue; + } else if (this->grid[column][row].deerCount) { + colour = (ushort)COL_MODERATE_GREEN::instance.shortValue; + } else if (this->grid[column][row].field_0x34) { + colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].deerCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].lionCount) { + colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + } else if (this->grid[column][row].field_0x3c) { + colour = (ushort)COL_WHITE::instance.shortValue; + } else if (this->grid[column][row].casDisRelated2) { + colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + } else if (this->grid[column][row].field_0x34) { + colour = (ushort)COL_BLACK::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].field_0x48) { + colour = (ushort)COL_WHITE::instance.shortValue; + } else if (this->grid[column][row].deerCount) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].field_0x34) { + colour = (ushort)COL_BLACK::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + if (this->grid[column][row].field_0x60) { + colour = (ushort)COL_WHITE::instance.shortValue; + } else if (this->grid[column][row].field_0x64) { + colour = (ushort)COL_BLACK::instance.shortValue; + } else if (this->grid[column][row].castlebuildings) { + colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + } else if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else if (this->grid[column][row].unknownNonZero01) { + colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + } else if (this->grid[column][row].field_0x6c) { + colour = (ushort)COL_RED::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else if (this->DAT_DebugDataMapDataDisplayType == 9) { + if (this->grid[column][row].field_0x74) { + colour = (ushort)COL_RED::instance.shortValue; + } else if (this->grid[column][row].unknownNonZero01) { + colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + } else if (!this->grid[column][row].separateAreaID) { + colour = (ushort)COL_BLUE::instance.shortValue; + } else { + colour = (ushort)COL_LIME::instance.shortValue; + } + } else { + continue; } + int const boxX = x1 + column * 10; + int const boxY = y + row * 10; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + boxX + 1, boxY + 1, boxX + 9, boxY + 9, colour); } - iVar8 = iVar8 + 1; - if (40 < iVar8) {} - } while (true); + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 46669de0b9..537b3e5a38 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49241,7 +49241,7 @@ SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending SHC_3BB0A8C1_0x0052BEA0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052BF40 | 16.0% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052BF40 | 48.9% | Register allocation (y and x+2 held all function in the original) SHC_3BB0A8C1_0x0052C570 | 0.0% | Pending From 91892c4fefb0e1908402c347f6929af7c8511267 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:23:58 +0100 Subject: [PATCH 08/43] Wildlife: buildRallyPointPathForTribe as plain direction loops 42.2 -> 69.4. Both direction scans are one `for` over the eight clockwise offsets instead of Ghidra's four unrolled, specialised copies. MSVC unrolls them 4x itself. The walk starts at a random direction and wraps with `if (direction >= 8)`, matching the original's `cmp 8; jl`. What reccmp rewarded, though quick_diff ranked it lower: - the grid bounds as `<= 39`, which the original tests with `cmp 0x27; ja` - the candidate x read before y, and the neighbour x computed before y - the unit index read inline from the tribe - the chosen cell cleared before param_2 takes its distance Left: the original keeps the best direction and the walk position in other stack slots and registers. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../buildRallyPointPathForTribe.cpp | 292 +++++------------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 82 insertions(+), 212 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 81b1d75dcd..7d838a4716 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -24,225 +24,95 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) { - short* psVar1; - short sVar2; - int iVar3; - int* piVar4; - int iVar5; - int* piVar6; - uint uVar7; - int iVar8; - uint uVar9; - int iVar10; - uint uVar11; - int iVar12; - int local_1c; - int local_14; - int local_10; - sVar2 = DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID; - iVar5 = (int)DAT_UnitsState::instance.units[sVar2].x / 10; - local_1c = (int)DAT_UnitsState::instance.units[sVar2].y / 10; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; this->casDisRelated = param_2; this->candidateIndex = 0; this->candidateIndex2 = 1; - if (this->grid[iVar5][local_1c].field_0x50 != 0) { - piVar4 = &this->grid[0][0].field_0x3c; - iVar12 = 0x28; - do { - iVar3 = 0x28; - piVar6 = piVar4; - do { - piVar6[-1] = 0; - *piVar6 = 0; - piVar6 = piVar6 + 0x640; - iVar3 = iVar3 + -1; - } while (iVar3); - piVar4 = piVar4 + 0x28; - iVar12 = iVar12 + -1; - } while (iVar12); - this->DAT_Y10_Array_Section1034[0] = (short)local_1c; - this->DAT_X10_Array_Section1034[0] = (short)iVar5; - this->grid[iVar5][local_1c].casDisRelated2 = this->grid[iVar5][local_1c].field_0x50; - iVar12 = this->grid[iVar5][local_1c].separateAreaID; - if (this->candidateIndex != this->candidateIndex2) { - do { - iVar3 = (int)this->DAT_Y10_Array_Section1034[this->candidateIndex]; - iVar8 = (int)this->DAT_X10_Array_Section1034[this->candidateIndex]; - piVar4 = &DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[0].int_.yOffset; - do { - uVar9 = *piVar4 + iVar3; - uVar7 = ((Point8IntXY*)(piVar4 + -1))->xOffset + iVar8; - if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember - && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) - && this->grid[uVar7][uVar9].casDisRelated2 == 0) { - this->grid[uVar7][uVar9].casDisRelated2 = iVar10; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; - this->candidateIndex2 = this->candidateIndex2 + 1; - if (0x63f < this->candidateIndex2) { - this->candidateIndex2 = 0; - } - } - uVar9 = piVar4[2] + iVar3; - uVar7 = piVar4[1] + iVar8; - if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember - && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) - && this->grid[uVar7][uVar9].casDisRelated2 == 0) { - this->grid[uVar7][uVar9].casDisRelated2 = iVar10; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; - this->candidateIndex2 = this->candidateIndex2 + 1; - if (0x63f < this->candidateIndex2) { - this->candidateIndex2 = 0; - } - } - uVar9 = piVar4[4] + iVar3; - uVar7 = piVar4[3] + iVar8; - if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember - && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) - && this->grid[uVar7][uVar9].casDisRelated2 == 0) { - this->grid[uVar7][uVar9].casDisRelated2 = iVar10; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; - this->candidateIndex2 = this->candidateIndex2 + 1; - if (0x63f < this->candidateIndex2) { - this->candidateIndex2 = 0; - } - } - uVar9 = piVar4[6] + iVar3; - uVar7 = piVar4[5] + iVar8; - if (uVar7 < 0x28 && uVar9 < 0x28 && 0 < this->grid[uVar7][uVar9].firstMember - && iVar12 == this->grid[uVar7][uVar9].separateAreaID - && (iVar10 = this->grid[uVar7][uVar9].field_0x50, 0 < iVar10) - && this->grid[uVar7][uVar9].casDisRelated2 == 0) { - this->grid[uVar7][uVar9].casDisRelated2 = iVar10; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar7; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar9; - this->candidateIndex2 = this->candidateIndex2 + 1; - if (0x63f < this->candidateIndex2) { - this->candidateIndex2 = 0; - } - } - piVar4 = piVar4 + 8; - } while ((int)piVar4 < 0xb4908c); - this->candidateIndex = this->candidateIndex + 1; - if (0x63f < this->candidateIndex) { - this->candidateIndex = 0; - } - } while (this->candidateIndex != this->candidateIndex2); + if (this->grid[x][y].field_0x50 == 0) { + return FALSE; + } + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x3c = 0; } - uVar7 = (uint)(byte)SEC_RNG::instance.currentNumber2; - DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; - DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; - this->grid[iVar5][local_1c].field_0x3c = 1; - this->grid[iVar5][local_1c].casDisRelated2 = 0; - while (true) { - local_14 = -1; - local_10 = 2; - iVar12 = (uVar7 & 7) - 7; - iVar3 = (uVar7 & 7) * 8 + 8; - do { - iVar8 = iVar12 + 7; - iVar10 = iVar3 + -8; - if (7 < iVar8) { - iVar8 = iVar12 + -1; - iVar10 = iVar3 + -72; - } - uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) - + iVar5; - uVar11 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) - + local_1c; - if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember - && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 != 0 && (param_2 < iVar10))) { - this->grid[uVar9][uVar11].casDisRelated2 = 0; - param_2 = iVar10; - local_14 = iVar8; - } - iVar8 = iVar3; - iVar10 = iVar12 + 8; - if (7 < iVar12 + 8) { - iVar8 = iVar3 + -0x40; - iVar10 = iVar12; - } - uVar11 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8 + 4) - + local_1c; - uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8) - + iVar5; - if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember - && (iVar8 = this->grid[uVar9][uVar11].casDisRelated2, iVar8 && (param_2 < iVar8))) { - this->grid[uVar9][uVar11].casDisRelated2 = 0; - param_2 = iVar8; - local_14 = iVar10; - } - iVar8 = iVar12 + 9; - iVar10 = iVar3 + 8; - if (7 < iVar8) { - iVar8 = iVar12 + 1; - iVar10 = iVar3 + -0x38; - } - uVar11 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) - + local_1c; - uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) - + iVar5; - if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember - && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 != 0 && (param_2 < iVar10))) { - this->grid[uVar9][uVar11].casDisRelated2 = 0; - param_2 = iVar10; - local_14 = iVar8; - } - iVar8 = iVar12 + 10; - iVar10 = iVar3 + 0x10; - if (7 < iVar8) { - iVar8 = iVar12 + 2; - iVar10 = iVar3 + -0x30; - } - uVar11 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10 + 4) - + local_1c; - uVar9 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar10) - + iVar5; - if (uVar9 < 0x28 && uVar11 < 0x28 && 0 < this->grid[uVar9][uVar11].firstMember - && (iVar10 = this->grid[uVar9][uVar11].casDisRelated2, iVar10 && (param_2 < iVar10))) { - this->grid[uVar9][uVar11].casDisRelated2 = 0; - param_2 = iVar10; - local_14 = iVar8; + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + this->grid[x][y].casDisRelated2 = this->grid[x][y].field_0x50; + int const areaID = this->grid[x][y].separateAreaID; + while (this->candidateIndex != this->candidateIndex2) { + int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + candidateX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + candidateY; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && areaID == this->grid[neighbourX][neighbourY].separateAreaID + && this->grid[neighbourX][neighbourY].field_0x50 > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 == 0) { + this->grid[neighbourX][neighbourY].casDisRelated2 = this->grid[neighbourX][neighbourY].field_0x50; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; } - iVar3 = iVar3 + 0x20; - iVar12 = iVar12 + 4; - local_10 = local_10 + -1; - } while (local_10); - if (local_14 < 0) - break; - iVar5 = iVar5 - + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[local_14].int_.xOffset; - local_1c = local_1c - + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_14 * 8 - + 4); - this->grid[iVar5][local_1c].field_0x3c = 1; - uVar9 = iVar5 * 10 + 5; - uVar11 = local_1c * 10 + 5; - if (uVar9 < 400 && uVar11 < 400 - && *(char*)(uVar11 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 + uVar9) - != '\0') { - DAT_TribesState::instance.tribes[param_1] - .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] - = (short)iVar5 * 10 + 5; - DAT_TribesState::instance.tribes[param_1] - .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] - = (short)local_1c * 10 + 5; - psVar1 = &DAT_TribesState::instance.tribes[param_1].rallyPointCount; - *psVar1 = *psVar1 + 1; } } - return TRUE; + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + uint const rng = (byte)SEC_RNG::instance.currentNumber2; + DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; + DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; + this->grid[x][y].field_0x3c = 1; + this->grid[x][y].casDisRelated2 = 0; + while (true) { + int bestDirection = -1; + for (int k = 0; k < 8; k++) { + int direction = (rng & 7) + k; + if (direction >= 8) { + direction = direction - 8; + } + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + x; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + y; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 > param_2) { + int const distance = this->grid[neighbourX][neighbourY].casDisRelated2; + this->grid[neighbourX][neighbourY].casDisRelated2 = 0; + param_2 = distance; + bestDirection = direction; + } + } + if (bestDirection < 0) { + return TRUE; + } + x = x + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + y = y + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[x][y].field_0x3c = 1; + uint const tileX = x * 10 + 5; + uint const tileY = y * 10 + 5; + if (tileX < 400 && tileY < 400 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] = (short)x * 10 + 5; + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] = (short)y * 10 + 5; + DAT_TribesState::instance.tribes[param_1].rallyPointCount + = DAT_TribesState::instance.tribes[param_1].rallyPointCount + 1; + } } - return FALSE; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 537b3e5a38..d19cf80a61 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 42.2% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052CFE0 | 69.4% | Stack-slot and register allocation in the walk SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending From 23e7c409c35a54f822eed2aee2ad670757e12a62 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:27:24 +0100 Subject: [PATCH 09/43] Wildlife: rebuild findAndSetNewRallyPointForDeerAndLions 44.7 -> 71.5. Built the same way as buildRallyPointPathForTribe: plain direction loops instead of Ghidra's specialised copies, the walk wrapping with `direction >= 8`, and the bound literals the original compares against (`<= 39`, `<= 399`, `bestDirection <= -1`, `casDisRelated <= 1`). Fixes an off-by-one: Ghidra wrapped both candidate indexes at `1600 <`, so index 1600 was used once and the code wrote one short past each 1600-entry coordinate array. The original wraps at `>= 1600` (`cmp 0x640; jl`). Tribe type 13 has no AITribeType name; it is compared as a literal. buildRallyPointPathForTribe 69.4 -> 69.7 with the same tile and best-direction literals. Left: register and stack-slot allocation in both functions. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../buildRallyPointPathForTribe.cpp | 4 +- ...findAndSetNewRallyPointForDeerAndLions.cpp | 265 ++++++------------ status/addresses-SHC-3BB0A8C1.txt | 4 +- 3 files changed, 95 insertions(+), 178 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 7d838a4716..9be45fda0e 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -95,7 +95,7 @@ namespace Map { bestDirection = direction; } } - if (bestDirection < 0) { + if (bestDirection <= -1) { return TRUE; } x = x + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; @@ -103,7 +103,7 @@ namespace Map { this->grid[x][y].field_0x3c = 1; uint const tileX = x * 10 + 5; uint const tileY = y * 10 + 5; - if (tileX < 400 && tileY < 400 + if (tileX <= 399 && tileY <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { DAT_TribesState::instance.tribes[param_1] .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] = (short)x * 10 + 5; diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index 8ae0b1aa19..81eef293e6 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -19,198 +19,115 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) { - short* psVar1; - short sVar2; - short sVar3; - int* piVar4; - uint _randomDirection; - int iVar5; - uint uVar6; - int iVar7; - int iVar8; - int* piVar9; - uint uVar10; - int _x10; - int iVar11; - int _y10; - int local_18; - int local_c; - int _count; - int _currentArea; - uint _destinationY; - uint _destinationX; - sVar2 = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; - _x10 = (int)DAT_UnitsState::instance.units[sVar2].x / 10; - _y10 = (int)DAT_UnitsState::instance.units[sVar2].y / 10; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; this->casDisRelated = always2or3or5; this->candidateIndex = 0; this->candidateIndex2 = 1; - piVar9 = &this->grid[0][0].field_0x3c; - iVar11 = 0x28; - do { - iVar5 = 0x28; - piVar4 = piVar9; - do { - piVar4[-1] = 0; - *piVar4 = 0; - piVar4 = piVar4 + 0x640; - iVar5 = iVar5 + -1; - } while (iVar5); - piVar9 = piVar9 + 0x28; - iVar11 = iVar11 + -1; - } while (iVar11); - this->DAT_Y10_Array_Section1034[0] = (short)_y10; - this->DAT_X10_Array_Section1034[0] = (short)_x10; - _currentArea = this->grid[_x10][_y10].separateAreaID; - this->grid[_x10][_y10].casDisRelated2 = always2or3or5; - if (this->candidateIndex != this->candidateIndex2) { - do { - sVar2 = this->DAT_X10_Array_Section1034[this->candidateIndex]; - sVar3 = this->DAT_Y10_Array_Section1034[this->candidateIndex]; - this->casDisRelated = this->grid[sVar2][sVar3].casDisRelated2; - if (this->casDisRelated < 2) - break; - iVar11 = this->casDisRelated + -1; - piVar9 = &DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[0].int_.yOffset; - do { - uVar10 = *piVar9 + (int)sVar3; - uVar6 = ((Point8IntXY*)(piVar9 + -1))->xOffset + (int)sVar2; - if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember - && _currentArea == this->grid[uVar6][uVar10].separateAreaID) { - if (!always0or1) { - if (this->grid[uVar6][uVar10].field_0x34 == 0) { - if (DAT_TribesState::instance.tribes[tribeID].tribeType - == (AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_SPEARMEN)) { - _count = this->grid[uVar6][uVar10].deerCount; - goto LAB_0052cc5e; - } - LAB_0052cc66: - if (this->grid[uVar6][uVar10].casDisRelated2 < iVar11) { - this->grid[uVar6][uVar10].casDisRelated2 = iVar11; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)uVar6; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)uVar10; - this->candidateIndex2 = this->candidateIndex2 + 1; - if (1600 < this->candidateIndex2) { - this->candidateIndex2 = 0; - } - } - } - } else if (this->grid[uVar6][uVar10].unstalkedUnitCount == 0) { - _count = this->grid[uVar6][uVar10].buildingTiles; - LAB_0052cc5e: - if ((!_count) && (this->grid[uVar6][uVar10].lionCount == 0)) - goto LAB_0052cc66; - } + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x3c = 0; + } + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + int const areaID = this->grid[x][y].separateAreaID; + this->grid[x][y].casDisRelated2 = always2or3or5; + while (this->candidateIndex != this->candidateIndex2) { + int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[candidateX][candidateY].casDisRelated2; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + candidateX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + candidateY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || areaID != this->grid[neighbourX][neighbourY].separateAreaID) { + continue; + } + if (!always0or1) { + if (this->grid[neighbourX][neighbourY].field_0x34 != 0) { + continue; + } + // 13: the wildlife tribe + if (DAT_TribesState::instance.tribes[tribeID].tribeType == 13 + && (this->grid[neighbourX][neighbourY].deerCount != 0 + || this->grid[neighbourX][neighbourY].lionCount != 0)) { + continue; + } + } else if (this->grid[neighbourX][neighbourY].unstalkedUnitCount != 0 + || this->grid[neighbourX][neighbourY].buildingTiles != 0 + || this->grid[neighbourX][neighbourY].lionCount != 0) { + continue; + } + if (this->grid[neighbourX][neighbourY].casDisRelated2 < level) { + this->grid[neighbourX][neighbourY].casDisRelated2 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; } - piVar9 = piVar9 + 2; - } while ((int)piVar9 < 0xb4908c); - this->candidateIndex = this->candidateIndex + 1; - if (1600 < this->candidateIndex) { - this->candidateIndex = 0; } - } while (this->candidateIndex != this->candidateIndex2); + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } } - _randomDirection = (uint)(byte)SEC_RNG::instance.currentNumber2; + uint const rng = (byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; - this->grid[_x10][_y10].field_0x3c = 1; - this->grid[_x10][_y10].casDisRelated2 = 0; + this->grid[x][y].field_0x3c = 1; + this->grid[x][y].casDisRelated2 = 0; while (true) { - local_18 = -1; - local_c = 2; - iVar11 = (_randomDirection & 7) * 8 + 8; - iVar5 = (_randomDirection & 7) - 7; - do { - iVar8 = iVar5 + 7; - iVar7 = iVar11 + -8; - if (7 < iVar8) { - iVar8 = iVar5 + -1; - iVar7 = iVar11 + -0x48; + int bestDirection = -1; + for (int k = 0; k < 8; k++) { + int direction = (rng & 7) + k; + if (direction >= 8) { + direction = direction - 8; } - uVar6 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; - uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) - + _y10; - if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember - && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 != 0 && (iVar7 < always2or3or5))) { - this->grid[uVar6][uVar10].casDisRelated2 = 0; - always2or3or5 = iVar7; - local_18 = iVar8; + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + x; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + y; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 < always2or3or5) { + int const distance = this->grid[neighbourX][neighbourY].casDisRelated2; + this->grid[neighbourX][neighbourY].casDisRelated2 = 0; + always2or3or5 = distance; + bestDirection = direction; } - iVar8 = iVar11; - iVar7 = iVar5 + 8; - if (7 < iVar5 + 8) { - iVar8 = iVar11 + -0x40; - iVar7 = iVar5; - } - uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8 + 4) - + _y10; - uVar6 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar8) + _x10; - if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember - && (iVar8 = this->grid[uVar6][uVar10].casDisRelated2, iVar8 && (iVar8 < always2or3or5))) { - this->grid[uVar6][uVar10].casDisRelated2 = 0; - always2or3or5 = iVar8; - local_18 = iVar7; - } - iVar8 = iVar5 + 9; - iVar7 = iVar11 + 8; - if (7 < iVar8) { - iVar8 = iVar5 + 1; - iVar7 = iVar11 + -0x38; - } - uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) - + _y10; - uVar6 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; - if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember - && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 != 0 && (iVar7 < always2or3or5))) { - this->grid[uVar6][uVar10].casDisRelated2 = 0; - always2or3or5 = iVar7; - local_18 = iVar8; - } - iVar8 = iVar5 + 10; - iVar7 = iVar11 + 0x10; - if (7 < iVar8) { - iVar8 = iVar5 + 2; - iVar7 = iVar11 + -0x30; - } - uVar10 = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7 + 4) - + _y10; - uVar6 - = *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + iVar7) + _x10; - if (uVar6 < 0x28 && uVar10 < 0x28 && 0 < this->grid[uVar6][uVar10].firstMember - && (iVar7 = this->grid[uVar6][uVar10].casDisRelated2, iVar7 && (iVar7 < always2or3or5))) { - this->grid[uVar6][uVar10].casDisRelated2 = 0; - always2or3or5 = iVar7; - local_18 = iVar8; - } - iVar11 = iVar11 + 0x20; - iVar5 = iVar5 + 4; - local_c = local_c + -1; - } while (local_c); - if (local_18 < 0) - break; - _x10 = _x10 + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[local_18].int_.xOffset; - _y10 = _y10 - + *(int*)((int)DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix + local_18 * 8 + 4); - this->grid[_x10][_y10].field_0x3c = 1; - _destinationY = _y10 * 10 + 5; - uVar6 = _x10 * 10 + 5; - if (uVar6 < 400 && _destinationY < 400 - && *(char*)(_destinationY * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 - + uVar6) - != '\0') { + } + if (bestDirection <= -1) { + return; + } + x = x + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + y = y + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[x][y].field_0x3c = 1; + uint const tileY = y * 10 + 5; + uint const tileX = x * 10 + 5; + if (tileX <= 399 && tileY <= 399 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, - DAT_PathFindingState::ptr)(_currentArea, uVar6, _destinationY); + DAT_PathFindingState::ptr)(areaID, tileX, tileY); DAT_TribesState::instance.tribes[tribeID] .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][0] = (short)DAT_PathFindingState::instance.climbX; DAT_TribesState::instance.tribes[tribeID] .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][1] = (short)DAT_PathFindingState::instance.climbY; - psVar1 = &DAT_TribesState::instance.tribes[tribeID].rallyPointCount; - *psVar1 = *psVar1 + 1; + DAT_TribesState::instance.tribes[tribeID].rallyPointCount + = DAT_TribesState::instance.tribes[tribeID].rallyPointCount + 1; } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d19cf80a61..604afe4964 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 0.0% | Pending SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 44.7% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052CAB0 | 71.5% | Register and stack-slot allocation SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 69.4% | Stack-slot and register allocation in the walk +SHC_3BB0A8C1_0x0052CFE0 | 69.7% | Stack-slot and register allocation in the walk SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending From 6f3fde905374072b5b6aac26d7618ab9bb6b2faf Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:31:49 +0100 Subject: [PATCH 10/43] LandscapeState: createTree slot search and switch follow the binary 56.6 -> 89.1. Fixes two bugs in the free-slot search copied from Ghidra: `_ptrState + 0x4e` stepped 78 trees at a time (the original adds 0x9c bytes, one tree), and the search gave up at `1999 <` instead of the original's `>= 1999`. It is now an indexed loop like createRock. Matching changes: - the state test spelled `type >= 16 && type <= 19` as a switch, so MSVC branches like the original instead of emitting sbb - the apple-colour variation is a signed int compared against the literals the original uses (>= 15, >= 13, >= 11, <= 8) - the stage-4 group is last in the switch, as in the original's layout, and types 1 and 4 jump into its shared `= 0` block (the goto is kept because the original shares that block) - the frame index is a plain `RandomLayer & 0x1f`, which MSVC narrows to the byte load the original has Left: register choice for the tile arithmetic and parameter loads. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/LandscapeState/createTree.cpp | 102 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createTree.cpp b/src/OpenSHC/Map/LandscapeState/createTree.cpp index 9e65e8ef49..4a8550dc3a 100644 --- a/src/OpenSHC/Map/LandscapeState/createTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/createTree.cpp @@ -19,30 +19,25 @@ namespace Map { int stageRelatedValue, undefined4 param_6, int stage) { undefined2 uVar1; - short sVar2; undefined4 uVar3; - Tree* _ptrState; - uint uVar4; + int uVar4; uint _tile; - int _treeID; /* *** Find a free tree slot *** */ - _treeID = 1; - _ptrState = &this->trees[1]; - do { - if (!_ptrState->state) + int _treeID; + for (_treeID = 1; _treeID < 2000; _treeID++) { + if (!this->trees[_treeID].state) { break; - if (1999 < _treeID) { + } + if (_treeID >= 1999) { return 0; } - _treeID = _treeID + 1; - _ptrState = _ptrState + 0x4e; - } while (_treeID < 2000); + } /* *** Increment the max tree count on this map *** */ - if (this->maxTreeCount <= _treeID) { + if (_treeID >= this->maxTreeCount) { this->maxTreeCount = _treeID + 1; } /* @@ -53,10 +48,15 @@ namespace Map { /* *** Set initial state of tree *** */ - if (((int)treeType < 0x10) || (0x13 < (int)treeType)) { - this->trees[_treeID].state = 1; - } else { + switch (treeType) { + case (TreeType)16: + case (TreeType)17: + case (TreeType)18: + case (TreeType)19: this->trees[_treeID].state = 4; + break; + default: + this->trees[_treeID].state = 1; } /* *** Set (initial) values for tree *** @@ -81,14 +81,15 @@ namespace Map { uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated2[treeType][stage]; this->trees[_treeID].stageRelated2 = uVar1; this->trees[_treeID].stageRelated1 = uVar1; - sVar2 = this->trees[_treeID].treeTypeBasedValue1; - this->trees[_treeID].gmOriginX - = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originX; - this->trees[_treeID].gmOriginY - = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[sVar2].originY; + this->trees[_treeID].gmOriginX = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1] + .originX; + this->trees[_treeID].gmOriginY = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1] + .originY; this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field_0x854[treeType]; this->trees[_treeID].zero = 0; - this->trees[_treeID].animationFrameIndex = (byte)DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f; + this->trees[_treeID].animationFrameIndex = DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f; this->trees[_treeID].one = 1; this->trees[_treeID].stage = stage; this->trees[_treeID].stageTracker = DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][stage]; @@ -100,21 +101,22 @@ namespace Map { case ((TreeType)1): uVar4 = this->trees[_treeID].rng1 & 0xf; this->trees[_treeID].appleTreeColorVariation = uVar4; - if (0xe < uVar4) { + if (uVar4 >= 15) { this->trees[_treeID].appleTreeColorVariation = 4; break; } - if (0xc < uVar4) { + if (uVar4 >= 13) { this->trees[_treeID].appleTreeColorVariation = 6; break; } - if (10 < uVar4) { + if (uVar4 >= 11) { this->trees[_treeID].appleTreeColorVariation = 1; break; } - if (uVar4 < 9) + if (uVar4 <= 8) { break; - goto LAB_004f1fb5; + } + goto noColourVariation; case ((TreeType)2): uVar4 = this->trees[_treeID].rng1 & 0xf; this->trees[_treeID].appleTreeColorVariation = uVar4; @@ -128,34 +130,19 @@ namespace Map { case ((TreeType)4): uVar4 = this->trees[_treeID].rng1 & 0xf; this->trees[_treeID].appleTreeColorVariation = uVar4; - if (uVar4 < 0xf) { - if (uVar4 < 0xd) { - if (uVar4 < 0xb) { - if (8 < uVar4) { - this->trees[_treeID].appleTreeColorVariation = 0; - } - } else { - this->trees[_treeID].appleTreeColorVariation = 1; - } - } else { - this->trees[_treeID].appleTreeColorVariation = 6; - } - } else { + if (uVar4 >= 15) { this->trees[_treeID].appleTreeColorVariation = 4; + } else if (uVar4 >= 13) { + this->trees[_treeID].appleTreeColorVariation = 6; + } else if (uVar4 >= 11) { + this->trees[_treeID].appleTreeColorVariation = 1; + } else if (uVar4 > 8) { + this->trees[_treeID].appleTreeColorVariation = 0; } - if (this->trees[_treeID].appleTreeColorVariation < 9) + if (this->trees[_treeID].appleTreeColorVariation <= 8) { break; - goto LAB_004f1fb5; - case ((TreeType)5): - case ((TreeType)10): - case ((TreeType)0x10): - case ((TreeType)0x11): - case ((TreeType)0x12): - case ((TreeType)0x13): - this->trees[_treeID].stage = 4; - LAB_004f1fb5: - this->trees[_treeID].appleTreeColorVariation = 0; - break; + } + goto noColourVariation; case ((TreeType)6): this->trees[_treeID].appleTreeColorVariation = 3; this->trees[_treeID].stage = 4; @@ -171,6 +158,17 @@ namespace Map { case ((TreeType)9): this->trees[_treeID].appleTreeColorVariation = 8; this->trees[_treeID].stage = 4; + break; + case ((TreeType)5): + case ((TreeType)10): + case ((TreeType)0x10): + case ((TreeType)0x11): + case ((TreeType)0x12): + case ((TreeType)0x13): + this->trees[_treeID].stage = 4; + noColourVariation: + this->trees[_treeID].appleTreeColorVariation = 0; + break; } uVar3 = this->field_0x0; this->field_0x0 = 0; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 604afe4964..7f8a2e7eb7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38317,7 +38317,7 @@ SHC_3BB0A8C1_0x004F1C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F1C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F1CE0 | 56.6% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004F1CE0 | 89.1% | Register allocation of tile arithmetic and parameter loads SHC_3BB0A8C1_0x004F1FDC | 0.0% | Pending From 36912ae89a70ece96727aba9d0624d158a7f9a2c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:35:00 +0100 Subject: [PATCH 11/43] Wildlife: updateWildlifeGrid as plain loops over named arrays 57.3 -> 67.6. The eight campground area IDs are an int[8] filled by a loop (MSVC unrolls and constant-folds it like the original), and the chimp test is a loop over that array. The area tally is an int[100][2], and the best-area search is one plain loop instead of Ghidra's five copies. The grid element is addressed by name rather than through a pointer. The bounds use the original's literals (`> 399`), the tree test is `treeID > 0 && treeID < 2000`, and `(char)logic < 0` is `logic & 0x80`. Left: MSVC strength-reduces `tileY * 400` and the translation-matrix index into three extra stack slots (frame 0x368 against the original's 0x35c), where the original recomputes them per tile. Moving or inlining tileY did not change that. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/WildlifeState/updateWildlifeGrid.cpp | 481 +++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 187 insertions(+), 296 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp index 437510125b..9e98d85798 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -33,310 +33,201 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052BA10 void WildlifeState::updateWildlifeGrid(int _y10) { - int* piVar1; - BuildingTypeShort* pBVar2; - TreeTypeShort TVar3; - BuildingTypeShort BVar4; - UnitTypeShort UVar5; - uint uVar6; - WildlifeGridElement* pWVar7; - int iVar8; - uint uVar9; - int _areaID; - int _unitID; - int iVar10; - int _tile; - int _sepAreaID; - int local_35c; - int local_358; - int local_354; - int local_348; - int local_344; - int local_340; - int local_33c; - int local_338; - int local_334; - int local_330; - int local_32c; - int local_320[200]; - int _x10; - local_348 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] != -1) { - local_348 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[1] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; + int const tileY10 = _y10 * 10; + int campgroundAreaIDs[8]; + for (int k = 0; k < 8; k++) { + campgroundAreaIDs[k] = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[k + 1] != -1) { + campgroundAreaIDs[k] + = (short) + DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[k + 1] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; + } } - local_344 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[2] != -1) { - local_344 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[2] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; } - local_340 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[3] != -1) { - local_340 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[3] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - local_33c = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[4] != -1) { - local_33c - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[4] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - local_338 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[5] != -1) { - local_338 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[5] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - local_334 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[6] != -1) { - local_334 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[6] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - local_330 = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[7] != -1) { - local_330 - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[7] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - local_32c = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[8] != -1) { - local_32c - = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[8] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] - .tileEntry]; - } - if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { - local_35c = 0; - do { - _x10 = local_35c / 10; - pWVar7 = this->grid[_x10] + _y10; - pWVar7->firstMember = 0; - this->grid[_x10][_y10].separateAreaID = 0; - this->grid[_x10][_y10].unclaimedArea = 0; - this->grid[_x10][_y10].buildingTiles = 0; - this->grid[_x10][_y10].keeps = 0; - this->grid[_x10][_y10].wallTiles = 0; - this->grid[_x10][_y10].trees = 0; - this->grid[_x10][_y10].unitCount = 0; - this->grid[_x10][_y10].unstalkedUnitCount = 0; - this->grid[_x10][_y10].stalkedUnitCount = 0; - this->grid[_x10][_y10].camelCount = 0; - this->grid[_x10][_y10].lionCount = 0; - this->grid[_x10][_y10].deerCount = 0; - this->grid[_x10][_y10].rabbitCount = 0; - this->grid[_x10][_y10].marshTiles = 0; - this->grid[_x10][_y10].rockyTiles = 0; - this->grid[_x10][_y10].field_0x48 = 0; - this->grid[_x10][_y10].farmFieldTiles = 0; - this->grid[_x10][_y10].chimps = 0; - this->grid[_x10][_y10].castlebuildings = 0; - this->grid[_x10][_y10].field_0x70 = 0; - iVar8 = 0; - do { - local_320[iVar8 * 2] = -1; - local_320[iVar8 * 2 + 1] = 0; - iVar8 = iVar8 + 1; - } while (iVar8 < 100); - local_354 = 0; - do { - uVar9 = local_354 + _y10 * 10; - local_358 = 0; - do { - if ((uint)(local_358 + local_35c) < 400 && uVar9 < 400 - && *(char*)(uVar9 * 400 + (int)DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400 - + local_358 + local_35c) - != '\0') { - pWVar7->firstMember = pWVar7->firstMember + 1; - _tile = DAT_ViewportRenderState::instance.translationMatrix[uVar9].addXgetTile + local_358 - + local_35c; - _areaID = (int)(short)DAT_TileMapState::instance.PathConnectionLayer[_tile]; - if (!_areaID) { - this->grid[_x10][_y10].unclaimedArea = this->grid[_x10][_y10].unclaimedArea + 1; - } - iVar8 = 0; - do { - if (local_320[iVar8 * 2] == _areaID) { - local_320[iVar8 * 2 + 1] = local_320[iVar8 * 2 + 1] + 1; - break; - } - if (local_320[iVar8 * 2] == -1) { - local_320[iVar8 * 2] = _areaID; - local_320[iVar8 * 2 + 1] = 1; - break; - } - iVar8 = iVar8 + 1; - } while (iVar8 < 100); - if (_areaID) { - if (_areaID == local_348) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_344) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_340) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_33c) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_338) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_334) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_330) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - if (_areaID == local_32c) { - this->grid[_x10][_y10].chimps = this->grid[_x10][_y10].chimps + 1; - } - } - this->grid[_x10][_y10].field_0x70 = this->grid[_x10][_y10].field_0x70 - + (uint)DAT_TileMapState::instance.HeightLayer[_tile]; - uVar6 = DAT_TileMapState::instance.LogicLayer[_tile]; - if ((uVar6 & 0x100)) { - this->grid[_x10][_y10].wallTiles = this->grid[_x10][_y10].wallTiles + 1; - this->grid[_x10][_y10].castlebuildings = this->grid[_x10][_y10].castlebuildings + 1; - } - if ((uVar6 & 0x20000000)) { - this->grid[_x10][_y10].marshTiles = this->grid[_x10][_y10].marshTiles + 1; - } - if ((uVar6 & 0x20000)) { - this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; - } - if ((char)uVar6 < '\0') { - this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; - } - if ((uVar6 & 0x40000)) { - this->grid[_x10][_y10].rockyTiles = this->grid[_x10][_y10].rockyTiles + 1; - } - if ((uVar6 & 0x1000000)) { - this->grid[_x10][_y10].farmFieldTiles = this->grid[_x10][_y10].farmFieldTiles + 1; - } - if ((uVar6 & 0x2000000)) { - this->grid[_x10][_y10].farmFieldTiles = this->grid[_x10][_y10].farmFieldTiles + 1; - } - if ((int)DAT_TileMapState::instance.OrganismLayer[_tile] - 1U < 1999 - && ((TVar3 = DAT_LandscapeState::instance - .trees[DAT_TileMapState::instance.OrganismLayer[_tile]] - .treeType, - TVar3 == ((TreeType)1) || (TVar3 == ((TreeType)2))) - || ((TVar3 == ((TreeType)3) || (TVar3 == ((TreeType)4)))))) { - this->grid[_x10][_y10].trees = this->grid[_x10][_y10].trees + 1; - } - if (DAT_TileMapState::instance.BuildingLayer[_tile] != 0) { - pBVar2 = &DAT_BuildingsState::instance - .buildings[DAT_TileMapState::instance.BuildingLayer[_tile]] - .buildingType; - BVar4 = *pBVar2; - if (BVar4 == Map::Buildings::BT_MANORHOUSE) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_STONEKEEP) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_STRONGHOLD) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_KEEPFOUR) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_KEEPFIVE) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_CAMPGROUND) { - this->grid[_x10][_y10].keeps = this->grid[_x10][_y10].keeps + 1; - } else if (BVar4 == Map::Buildings::BT_GATEHOUSELARGE - || BVar4 == Map::Buildings::BT_GATEHOUSESMALL - || BVar4 == Map::Buildings::BT_WOODGATE1 || BVar4 == Map::Buildings::BT_WOODGATE2 - || BVar4 == Map::Buildings::BT_DRAWBRIDGE || BVar4 == Map::Buildings::BT_TOWER1 - || BVar4 == Map::Buildings::BT_TOWER2 || BVar4 == Map::Buildings::BT_TOWER3 - || BVar4 == Map::Buildings::BT_TOWER4 || BVar4 == Map::Buildings::BT_TOWER5) { - this->grid[_x10][_y10].castlebuildings = this->grid[_x10][_y10].castlebuildings + 1; - } - if (*pBVar2 != Map::Buildings::BT_SIGNPOST) { - this->grid[_x10][_y10].buildingTiles = this->grid[_x10][_y10].buildingTiles + 1; - } - } - _unitID = (int)(short)DAT_TileMapState::instance.UnitLayer[_tile]; - if (_unitID) { - this->grid[_x10][_y10].unitCount = this->grid[_x10][_y10].unitCount + 1; - if (DAT_UnitsState::instance.units[_unitID].isStalked == 0) { - this->grid[_x10][_y10].unstalkedUnitCount - = this->grid[_x10][_y10].unstalkedUnitCount + 1; - LAB_0052be68: - this->grid[_x10][_y10].field_0x48 = this->grid[_x10][_y10].field_0x48 + 1; - } else { - this->grid[_x10][_y10].stalkedUnitCount - = this->grid[_x10][_y10].stalkedUnitCount + 1; - UVar5 = DAT_UnitsState::instance.units[_unitID].unitType; - if (UVar5 == Map::Units::UT_ANTELOPESHDEER) { - this->grid[_x10][_y10].deerCount = this->grid[_x10][_y10].deerCount + 1; - if (DAT_TribesState::instance - .tribes[DAT_UnitsState::instance.units[_unitID].tribeID] - .predatorNearby - != 0) - goto LAB_0052be68; - } else if (UVar5 == Map::Units::UT_RABBIT) { - this->grid[_x10][_y10].rabbitCount = this->grid[_x10][_y10].rabbitCount + 1; - } else if (UVar5 == Map::Units::UT_CAMELSHBEAR) { - this->grid[_x10][_y10].camelCount = this->grid[_x10][_y10].camelCount + 1; - } else if (UVar5 == Map::Units::UT_LIONSHWOLF) { - this->grid[_x10][_y10].lionCount = this->grid[_x10][_y10].lionCount + 1; - } - } + for (int x = 0; x < 400; x += 10) { + int const gridX = x / 10; + this->grid[gridX][_y10].firstMember = 0; + this->grid[gridX][_y10].separateAreaID = 0; + this->grid[gridX][_y10].unclaimedArea = 0; + this->grid[gridX][_y10].buildingTiles = 0; + this->grid[gridX][_y10].keeps = 0; + this->grid[gridX][_y10].wallTiles = 0; + this->grid[gridX][_y10].trees = 0; + this->grid[gridX][_y10].unitCount = 0; + this->grid[gridX][_y10].unstalkedUnitCount = 0; + this->grid[gridX][_y10].stalkedUnitCount = 0; + this->grid[gridX][_y10].camelCount = 0; + this->grid[gridX][_y10].lionCount = 0; + this->grid[gridX][_y10].deerCount = 0; + this->grid[gridX][_y10].rabbitCount = 0; + this->grid[gridX][_y10].marshTiles = 0; + this->grid[gridX][_y10].rockyTiles = 0; + this->grid[gridX][_y10].field_0x48 = 0; + this->grid[gridX][_y10].farmFieldTiles = 0; + this->grid[gridX][_y10].chimps = 0; + this->grid[gridX][_y10].castlebuildings = 0; + this->grid[gridX][_y10].field_0x70 = 0; + int areaCounts[100][2]; + for (int k = 0; k < 100; k++) { + areaCounts[k][0] = -1; + areaCounts[k][1] = 0; + } + for (int dy = 0; dy < 10; dy++) { + uint const tileY = dy + tileY10; + for (int dx = 0; dx < 10; dx++) { + uint const tileX = dx + x; + if (tileX > 399 || tileY > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] == '\0') { + continue; + } + this->grid[gridX][_y10].firstMember = this->grid[gridX][_y10].firstMember + 1; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + dx + x; + int const areaID = (short)DAT_TileMapState::instance.PathConnectionLayer[tile]; + if (areaID == 0) { + this->grid[gridX][_y10].unclaimedArea = this->grid[gridX][_y10].unclaimedArea + 1; + } + for (int k = 0; k < 100; k++) { + if (areaCounts[k][0] == areaID) { + areaCounts[k][1] = areaCounts[k][1] + 1; + break; + } + if (areaCounts[k][0] == -1) { + areaCounts[k][0] = areaID; + areaCounts[k][1] = 1; + break; + } + } + if (areaID != 0) { + for (int k = 0; k < 8; k++) { + if (areaID == campgroundAreaIDs[k]) { + this->grid[gridX][_y10].chimps = this->grid[gridX][_y10].chimps + 1; } } - local_358 = local_358 + 1; - } while (local_358 < 10); - local_354 = local_354 + 1; - } while (local_354 < 10); - _sepAreaID = 0; - iVar8 = 0; - iVar10 = 0; - do { - if (local_320[iVar10 * 2] == -1) - break; - if (iVar8 < local_320[iVar10 * 2 + 1]) { - _sepAreaID = local_320[iVar10 * 2]; - iVar8 = local_320[iVar10 * 2 + 1]; } - if (local_320[iVar10 * 2 + 2] == -1) - break; - if (iVar8 < local_320[iVar10 * 2 + 3]) { - _sepAreaID = local_320[iVar10 * 2 + 2]; - iVar8 = local_320[iVar10 * 2 + 3]; + this->grid[gridX][_y10].field_0x70 + = this->grid[gridX][_y10].field_0x70 + DAT_TileMapState::instance.HeightLayer[tile]; + uint const logic = DAT_TileMapState::instance.LogicLayer[tile]; + if (logic & 0x100) { + this->grid[gridX][_y10].wallTiles = this->grid[gridX][_y10].wallTiles + 1; + this->grid[gridX][_y10].castlebuildings = this->grid[gridX][_y10].castlebuildings + 1; + } + if (logic & 0x20000000) { + this->grid[gridX][_y10].marshTiles = this->grid[gridX][_y10].marshTiles + 1; + } + if (logic & 0x20000) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; + } + if (logic & 0x80) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; + } + if (logic & 0x40000) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; } - if (local_320[iVar10 * 2 + 4] == -1) - break; - if (iVar8 < local_320[iVar10 * 2 + 5]) { - _sepAreaID = local_320[iVar10 * 2 + 4]; - iVar8 = local_320[iVar10 * 2 + 5]; + if (logic & 0x1000000) { + this->grid[gridX][_y10].farmFieldTiles = this->grid[gridX][_y10].farmFieldTiles + 1; } - if (local_320[iVar10 * 2 + 6] == -1) - break; - if (iVar8 < local_320[iVar10 * 2 + 7]) { - _sepAreaID = local_320[iVar10 * 2 + 6]; - iVar8 = local_320[iVar10 * 2 + 7]; + if (logic & 0x2000000) { + this->grid[gridX][_y10].farmFieldTiles = this->grid[gridX][_y10].farmFieldTiles + 1; } - if (local_320[iVar10 * 2 + 8] == -1) - break; - if (iVar8 < local_320[iVar10 * 2 + 9]) { - _sepAreaID = local_320[iVar10 * 2 + 8]; - iVar8 = local_320[iVar10 * 2 + 9]; + int const treeID = DAT_TileMapState::instance.OrganismLayer[tile]; + if (treeID > 0 && treeID < 2000) { + TreeTypeShort const treeType = DAT_LandscapeState::instance.trees[treeID].treeType; + if (treeType == (TreeType)1 || treeType == (TreeType)2 || treeType == (TreeType)3 + || treeType == (TreeType)4) { + this->grid[gridX][_y10].trees = this->grid[gridX][_y10].trees + 1; + } + } + int const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_MANORHOUSE) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_STONEKEEP) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_STRONGHOLD) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_KEEPFOUR) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_KEEPFIVE) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_CAMPGROUND) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_GATEHOUSELARGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_GATEHOUSESMALL + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_WOODGATE1 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_WOODGATE2 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_DRAWBRIDGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER1 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER2 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER3 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER4 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER5) { + this->grid[gridX][_y10].castlebuildings = this->grid[gridX][_y10].castlebuildings + 1; + } + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + != Map::Buildings::BT_SIGNPOST) { + this->grid[gridX][_y10].buildingTiles = this->grid[gridX][_y10].buildingTiles + 1; + } + } + int const unitID = DAT_TileMapState::instance.UnitLayer[tile]; + if (unitID == 0) { + continue; + } + this->grid[gridX][_y10].unitCount = this->grid[gridX][_y10].unitCount + 1; + if (DAT_UnitsState::instance.units[unitID].isStalked == 0) { + this->grid[gridX][_y10].unstalkedUnitCount = this->grid[gridX][_y10].unstalkedUnitCount + 1; + this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; + continue; + } + this->grid[gridX][_y10].stalkedUnitCount = this->grid[gridX][_y10].stalkedUnitCount + 1; + UnitTypeShort const unitType = DAT_UnitsState::instance.units[unitID].unitType; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + this->grid[gridX][_y10].deerCount = this->grid[gridX][_y10].deerCount + 1; + if (DAT_TribesState::instance.tribes[DAT_UnitsState::instance.units[unitID].tribeID] + .predatorNearby + != 0) { + this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; + } + } else if (unitType == Map::Units::UT_RABBIT) { + this->grid[gridX][_y10].rabbitCount = this->grid[gridX][_y10].rabbitCount + 1; + } else if (unitType == Map::Units::UT_CAMELSHBEAR) { + this->grid[gridX][_y10].camelCount = this->grid[gridX][_y10].camelCount + 1; + } else if (unitType == Map::Units::UT_LIONSHWOLF) { + this->grid[gridX][_y10].lionCount = this->grid[gridX][_y10].lionCount + 1; } - iVar10 = iVar10 + 5; - } while (iVar10 < 100); - this->grid[_x10][_y10].separateAreaID = _sepAreaID; - local_35c = local_35c + 10; - } while (local_35c < 400); + } + } + int separateAreaID = 0; + int bestCount = 0; + for (int k = 0; k < 100; k++) { + if (areaCounts[k][0] == -1) { + break; + } + if (areaCounts[k][1] > bestCount) { + separateAreaID = areaCounts[k][0]; + bestCount = areaCounts[k][1]; + } + } + this->grid[gridX][_y10].separateAreaID = separateAreaID; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7f8a2e7eb7..54fd9c369a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49235,7 +49235,7 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 57.3% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052BA10 | 67.6% | Strength-reduced tileY*400 adds three stack slots SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending From e3274b4706ae4779ccdcc44f19b82d9d0c1d97cd Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:39:42 +0100 Subject: [PATCH 12/43] LandscapeState: createRock store order reaches 100% 64.1 -> 100. The field stores are reordered (one and type before x), which lets the constant 1 from the slot search stay in edx and moves the edi push past the early return, as in the original. Found by hill-climbing the order of the independent stores with quick_diff. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index fe98ec449a..291637bee7 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -26,9 +26,9 @@ namespace Map { DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; this->rocks[_rockID].size = (short)size; this->rocks[_rockID].y = (ushort)y; - this->rocks[_rockID].x = (ushort)x; this->rocks[_rockID].one = 1; this->rocks[_rockID].type = (short)rockType; + this->rocks[_rockID].x = (ushort)x; this->rocks[_rockID].tile = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; this->rocks[_rockID].orientation = (short)orientation; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 54fd9c369a..cdc8e83d23 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38383,7 +38383,7 @@ SHC_3BB0A8C1_0x004F2070 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F20E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2140 | 64.1% | Register holding the constant 1 +SHC_3BB0A8C1_0x004F2140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F2220 | 100.0% | Reimplemented From 4d1bc2145ba0e3db84c08f7288ff0525e0f55723 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:51:57 +0100 Subject: [PATCH 13/43] types: AttackInfo::nof_fpointsArray holds 100 entries updateNofFpoints (0x0052E120) clears 0x640 bytes from 0x17842FC, i.e. 100 eight-short entries, and the 800 bytes of padding after the declared [50][8] array are its second half: nofFpointsArrayCopy starts exactly 1600 bytes in. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/AttackInfo.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/AttackInfo.hpp b/src/OpenSHC/Map/AttackInfo.hpp index feb6d8f08a..5e8def0009 100644 --- a/src/OpenSHC/Map/AttackInfo.hpp +++ b/src/OpenSHC/Map/AttackInfo.hpp @@ -85,8 +85,7 @@ namespace Map { BOOLEnum attackAlarmPlayed; // 0x00020F9C length: 4 int someCounter1; // 0x00020FA0 length: 4 undefined1 padding_0x20fa4[4]; // 0x00020FA4 length: 4 - short nof_fpointsArray[50][8]; // 0x00020FA8 length: 800 - undefined1 padding_0x212c8[800]; // 0x000212C8 length: 800 + short nof_fpointsArray[100][8]; // 0x00020FA8 length: 1600 short nof_fpointsArrayCopy[8]; // 0x000215E8 length: 16 undefined1 padding_0x215f8[1600]; // 0x000215F8 length: 1600 int nof_fpoints; // 0x00021C38 length: 4 From b52870bffad65cb73ac9a9986f4d1cb4de509231 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:51:58 +0100 Subject: [PATCH 14/43] Wildlife: updateNofFpoints clears all 100 fpoint entries The original's clear loop covers the whole 100-entry array; ours stopped at 50. Left: the original keeps `this` in ecx across floodFillCasDisFromSignpost (an LTCG build), which needs that callee reimplemented and listed for /GL. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp index 49ac7cb712..35cff357a7 100644 --- a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -39,7 +39,7 @@ namespace Map { } MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillCasDisFromSignpost, this)(); DAT_TroopValueState::instance.attackInfo.nof_fpoints = 0; - for (int i = 0; i < 50; i++) { + for (int i = 0; i < 100; i++) { DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][3] = 0; DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][2] = 0; DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][1] = 0; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index cdc8e83d23..7b7a7f0199 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49299,7 +49299,7 @@ SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending SHC_3BB0A8C1_0x0052E020 | 67.4% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x0052E120 | 61.0% | Register allocation of the grid counters +SHC_3BB0A8C1_0x0052E120 | 61.3% | LTCG: this kept in ecx across floodFillCasDisFromSignpost SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From 4d2ab6f4baa3a0cffabb4b54d946a68014db1fd5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:51:58 +0100 Subject: [PATCH 15/43] LandscapeState: createTree stores yPosition after treeType 89.1 -> 89.6, from hill-climbing the order of the independent field stores. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/LandscapeState/createTree.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createTree.cpp b/src/OpenSHC/Map/LandscapeState/createTree.cpp index 4a8550dc3a..9eb91c327c 100644 --- a/src/OpenSHC/Map/LandscapeState/createTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/createTree.cpp @@ -63,7 +63,6 @@ namespace Map { */ this->trees[_treeID].size = (short)size; this->trees[_treeID].xPosition = (ushort)x; - this->trees[_treeID].yPosition = (ushort)y; this->trees[_treeID].treeType = (TreeTypeShort)treeType; _tile = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; @@ -73,6 +72,7 @@ namespace Map { this->trees[_treeID].rng1 = DAT_TileMapState::instance.RandomLayer[_tile] & 0x7ff; this->trees[_treeID].appleTreeColorVariation = stageRelatedValue; this->trees[_treeID].param_6 = (short)param_6; + this->trees[_treeID].yPosition = (ushort)y; this->trees[_treeID].treeTypeBasedValue1 = (short)DAT_OrganismDefinedData::instance.TreeTypeBasedValueMapping[treeType]; uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated1[treeType][stage]; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7b7a7f0199..04245bb988 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38317,7 +38317,7 @@ SHC_3BB0A8C1_0x004F1C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F1C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F1CE0 | 89.1% | Register allocation of tile arithmetic and parameter loads +SHC_3BB0A8C1_0x004F1CE0 | 89.6% | Register allocation of tile arithmetic and parameter loads SHC_3BB0A8C1_0x004F1FDC | 0.0% | Pending From 4623340d1e5b91b8eded67c4a0a9983bd9ff0724 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:51:59 +0100 Subject: [PATCH 16/43] Wildlife: updateSection1034Info walks the grid, not past it 67.4 -> 69.8. Ghidra's first loop advanced a WildlifeGridElement pointer by 0x640 elements (0x3e800 bytes) per x step and 0x28 elements per y step, where the original steps one grid column (0x1900 bytes) and one element (0xa0); everything after the first cell was written far outside the grid. All three passes are now plain x/y loops over this->grid. Left: the original keeps `this` in ecx across its three callees (an LTCG build), which needs them reimplemented and listed for /GL. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../WildlifeState/updateSection1034Info.cpp | 93 ++++++------------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 30 insertions(+), 65 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp index 8bc9a6c371..cfba74d1ff 100644 --- a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -13,71 +13,36 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 void WildlifeState::updateSection1034Info() { - int iVar1; - int iVar2; - WildlifeGridElement* piVar3; - int* piVar5; - WildlifeGridElement* piVar4; - int iVar6; - int* piVar7; - int local_4; - if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { - for (local_4 = 0; local_4 < 0x14; local_4++) { - iVar2 = 0; - piVar3 = &this->grid[0][0]; - do { - iVar6 = 0; - piVar4 = piVar3; - do { - piVar4->unknownNonZero01 = 0; - piVar4->field_0x6c = 0; - if ((piVar4->castlebuildings) - && (iVar1 = MACRO_CALL_MEMBER( - Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(iVar6, iVar2), - iVar1 != 0)) { - piVar4->field_0x64 = piVar4->field_0x64 + 1; - } - iVar6 = iVar6 + 1; - piVar4 = piVar4 + 0x640; - } while (iVar6 < 0x28); - iVar2 = iVar2 + 1; - piVar3 = piVar3 + 0x28; - } while (iVar2 < 0x28); - } - iVar2 = 0; - piVar5 = &this->grid[0][0].field_0x64; - do { - iVar6 = 0; - piVar7 = piVar5; - do { - if ((piVar7[-1] != 0) || (*piVar7 != 0)) { - MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillZoneProximityFromCell, this)( - iVar6, iVar2, 6); - } - iVar6 = iVar6 + 1; - piVar7 = piVar7 + 0x640; - } while (iVar6 < 0x28); - iVar2 = iVar2 + 1; - piVar5 = piVar5 + 0x28; - } while (iVar2 < 0x28); - iVar2 = 0; - piVar5 = &this->grid[0][0].field_0x6c; - do { - iVar6 = 0; - piVar7 = piVar5; - do { - if ((piVar7[-1] == 0) - && (iVar1 = MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)( - iVar6, iVar2), - iVar1 != 0)) { - *piVar7 = *piVar7 + 1; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + for (int pass = 0; pass < 20; pass++) { + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + this->grid[x][y].unknownNonZero01 = 0; + this->grid[x][y].field_0x6c = 0; + if (this->grid[x][y].castlebuildings != 0 + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(x, y) + != 0) { + this->grid[x][y].field_0x64 = this->grid[x][y].field_0x64 + 1; } - iVar6 = iVar6 + 1; - piVar7 = piVar7 + 0x640; - } while (iVar6 < 0x28); - iVar2 = iVar2 + 1; - piVar5 = piVar5 + 0x28; - } while (iVar2 < 0x28); + } + } + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + if (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillZoneProximityFromCell, this)(x, y, 6); + } + } + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + if (this->grid[x][y].unknownNonZero01 == 0 + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)(x, y) != 0) { + this->grid[x][y].field_0x6c = this->grid[x][y].field_0x6c + 1; + } + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 04245bb988..2e43ade277 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49297,7 +49297,7 @@ SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052E020 | 67.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0052E020 | 69.8% | LTCG: this kept in ecx across the three callees SHC_3BB0A8C1_0x0052E120 | 61.3% | LTCG: this kept in ecx across floodFillCasDisFromSignpost From 49f1235c5f61da7a531c3ef7d73662d96fe0abd1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:18 +0100 Subject: [PATCH 17/43] Wildlife: reimplement hasAdjacentCellWithField24Or25 Tests the four cardinal neighbours (every second entry of clockwiseCardinalTranslationMatrix) for an occupied cell with field_0x60 or field_0x64 set. Called by updateSection1034Info. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../hasAdjacentCellWithField24Or25.cpp | 28 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp diff --git a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp new file mode 100644 index 0000000000..5d02a53dae --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp @@ -0,0 +1,28 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D620 + undefined4 WildlifeState::hasAdjacentCellWithField24Or25(int param_1, int param_2) + { + // the four cardinal directions + for (int direction = 0; direction < 8; direction += 2) { + uint const x + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + param_1; + uint const y + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + param_2; + if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 + && (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0)) { + return 1; + } + } + return 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2e43ade277..f63788d7f5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49269,7 +49269,7 @@ SHC_3BB0A8C1_0x0052D100 | 0.0% | Pending SHC_3BB0A8C1_0x0052D3C0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052D620 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D620 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D690 | 0.0% | Pending From c1303a1ab9f1a9ca1ec4c9a52f17ffe96cf0fc6c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:18 +0100 Subject: [PATCH 18/43] Wildlife: reimplement isAttackStagingCandidateCell A cell qualifies when it has at most 8 unclaimed tiles, at most 4 trees and at least 50 tiles, and a cardinal neighbour has unknownNonZero01 set. The three guards are separate early returns, which places the shared return block where the original has it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../isAttackStagingCandidateCell.cpp | 36 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp diff --git a/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp new file mode 100644 index 0000000000..ed5d5721ef --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp @@ -0,0 +1,36 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D690 + BOOLEnum WildlifeState::isAttackStagingCandidateCell(int cellX, int cellY) + { + if (this->grid[cellX][cellY].unclaimedArea > 8) { + return FALSE; + } + if (this->grid[cellX][cellY].trees > 4) { + return FALSE; + } + if (this->grid[cellX][cellY].firstMember < 50) { + return FALSE; + } + // the four cardinal directions + for (int direction = 0; direction < 8; direction += 2) { + uint const x + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + cellX; + uint const y + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + cellY; + if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 && this->grid[x][y].unknownNonZero01 != 0) { + return TRUE; + } + } + return FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f63788d7f5..991c63f111 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49271,7 +49271,7 @@ SHC_3BB0A8C1_0x0052D3C0 | 0.0% | Pending SHC_3BB0A8C1_0x0052D620 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052D690 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D720 | 0.0% | Pending From ccef45b146311b011b0b9517f7bbdcceaaa412ee Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:19 +0100 Subject: [PATCH 19/43] Wildlife: reimplement floodFillZoneProximityFromCell Breadth-first fill of unknownNonZero01 outwards from one cell, losing one level per step and skipping cells with more than 10 unclaimed tiles, through the same 1600-entry ring queue the rally-point search uses. The candidate coordinates are written back into the cellX/cellY parameters, which puts them in the parameter's stack slot as in the original. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../floodFillZoneProximityFromCell.cpp | 55 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp diff --git a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp new file mode 100644 index 0000000000..4c77c3c940 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp @@ -0,0 +1,55 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D720 + void WildlifeState::floodFillZoneProximityFromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].unknownNonZero01 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].unknownNonZero01; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].unclaimedArea > 10 + || this->grid[neighbourX][neighbourY].unknownNonZero01 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].unknownNonZero01 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 991c63f111..3efc180409 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49273,7 +49273,7 @@ SHC_3BB0A8C1_0x0052D620 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D690 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052D720 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D780 | 0.0% | Pending From 1a970faa8e5ad0e5fdb4d9ec4fcce2e1fcabb341 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:19 +0100 Subject: [PATCH 20/43] Wildlife: reimplement floodFillCasDisFromSignpost Clears casDisRelated2 and field_0x74 over the grid, then fills casDisRelated2 outwards from the attack signpost's cell, up to 100 steps, through cells of the same separate area that have no unknownNonZero01, counting each visit in field_0x74. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../floodFillCasDisFromSignpost.cpp | 74 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp diff --git a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp new file mode 100644 index 0000000000..76ae410137 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp @@ -0,0 +1,74 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D9D0 + void WildlifeState::floodFillCasDisFromSignpost() + { + int const x = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .x + / 10; + int const y = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .y + / 10; + this->casDisRelated = 1; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x74 = 0; + } + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + int const areaID = this->grid[x][y].separateAreaID; + this->grid[x][y].casDisRelated2 = 1; + while (this->candidateIndex != this->candidateIndex2) { + int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[candidateX][candidateY].casDisRelated2; + if (this->casDisRelated >= 100) { + break; + } + int const level = this->casDisRelated + 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + candidateX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + candidateY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || areaID != this->grid[neighbourX][neighbourY].separateAreaID + || this->grid[neighbourX][neighbourY].unknownNonZero01 != 0 + || this->grid[neighbourX][neighbourY].casDisRelated2 != 0) { + continue; + } + this->grid[neighbourX][neighbourY].casDisRelated2 = level; + this->grid[neighbourX][neighbourY].field_0x74 = this->grid[neighbourX][neighbourY].field_0x74 + 1; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3efc180409..cba2aadda5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49277,7 +49277,7 @@ SHC_3BB0A8C1_0x0052D720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D780 | 0.0% | Pending -SHC_3BB0A8C1_0x0052D9D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D9D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052DA40 | 0.0% | Pending From 8b1e1296c9169733dcad5ebdd097b08c91ca1c64 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:32 +0100 Subject: [PATCH 21/43] Wildlife: build updateSection1034Info, updateNofFpoints and callees with /GL The original keeps `this` in ecx across hasAdjacentCellWithField24Or25, isAttackStagingCandidateCell, floodFillZoneProximityFromCell and floodFillCasDisFromSignpost, which LTCG only allows when the callees are 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 6c541f7d8c..6731216649 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -264,3 +264,9 @@ 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/WildlifeState/hasAdjacentCellWithField24Or25.cpp +src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp +src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp +src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp +src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp From fd845353aa0e29c4caec8a8e6cdc46166a956481 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 22:57:33 +0100 Subject: [PATCH 22/43] status: updateSection1034Info 94.0, updateNofFpoints 67.0 under /GL Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- 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 cba2aadda5..169f56386a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49297,9 +49297,9 @@ SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052E020 | 69.8% | LTCG: this kept in ecx across the three callees +SHC_3BB0A8C1_0x0052E020 | 94.0% | Outer 20-pass loop counts down; original counts up in a stack slot -SHC_3BB0A8C1_0x0052E120 | 61.3% | LTCG: this kept in ecx across floodFillCasDisFromSignpost +SHC_3BB0A8C1_0x0052E120 | 67.0% | Register allocation of the grid scan SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From 13b3ae610e4efc068b7328ba73010357a8b66493 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:02:17 +0100 Subject: [PATCH 23/43] Wildlife: updateNofFpoints scans with a y induction variable 67.0 -> 79.0 (under /GL). The tile y coordinate is stepped in the outer loop's header and the loop ends on `y < 405`, the bound the original tests (as y*12 < 0x12fc); with y derived from gridY MSVC kept a separate 40-count and could not test the y bound through the translation-matrix offset as the original does. x and y are signed ints compared through (uint), and the swap flag is a BOOL, which the original keeps in a dword register. Left: the binary-map base folded into the y*400 induction variable and register naming in the five unrolled cell copies. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp | 13 ++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp index 35cff357a7..ba7277ffac 100644 --- a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -45,17 +45,16 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][1] = 0; DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][0] = 0; } - for (int gridY = 0; gridY < 40; gridY++) { - uint const y = gridY * 10 + 5; + for (int gridY = 0, y = 5; y < 405; gridY++, y += 10) { for (int gridX = 0; gridX < 40; gridX++) { - uint const x = gridX * 10 + 5; + int const x = gridX * 10 + 5; if (!this->grid[gridX][gridY].field_0x6c || this->grid[gridX][gridY].firstMember <= 0) { continue; } int const areaID = (short)DAT_TileMapState::instance .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; - if (separateAreaID != areaID || x > 399 || y > 399 + if (separateAreaID != areaID || (uint)x > 399 || (uint)y > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == '\0') { continue; } @@ -85,13 +84,13 @@ namespace Map { = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; } } - bool swapped; + BOOL swapped; do { - swapped = false; + swapped = FALSE; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.nof_fpoints - 1; i++) { if (DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1][6] < DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][6]) { - swapped = true; + swapped = TRUE; MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i], DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy); diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 169f56386a..7424bb1623 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49299,7 +49299,7 @@ SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending SHC_3BB0A8C1_0x0052E020 | 94.0% | Outer 20-pass loop counts down; original counts up in a stack slot -SHC_3BB0A8C1_0x0052E120 | 67.0% | Register allocation of the grid scan +SHC_3BB0A8C1_0x0052E120 | 79.0% | Binary-map base folded into the y*400 induction variable; register naming SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From c5d880cbd32f7127252d3302db517bdbb0beefe9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:04:22 +0100 Subject: [PATCH 24/43] Wildlife: reimplement floodFillField13FromCell The same breadth-first fill as floodFillZoneProximityFromCell, on field_0x34 and without the unclaimed-tile limit. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../floodFillField13FromCell.cpp | 54 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp new file mode 100644 index 0000000000..a7bdb9dd5b --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp @@ -0,0 +1,54 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052C570 + void WildlifeState::floodFillField13FromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].field_0x34 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].field_0x34; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].field_0x34 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].field_0x34 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7424bb1623..f815dab8af 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49243,7 +49243,7 @@ SHC_3BB0A8C1_0x0052BEA0 | 0.0% | Pending SHC_3BB0A8C1_0x0052BF40 | 48.9% | Register allocation (y and x+2 held all function in the original) -SHC_3BB0A8C1_0x0052C570 | 0.0% | Pending +SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C5D0 | 0.0% | Pending From f21ddcafe4a56a15c521053e81440e74f587d113 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:04:23 +0100 Subject: [PATCH 25/43] Wildlife: reimplement floodFillField20FromCell The same breadth-first fill as floodFillField13FromCell, on field_0x50. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../floodFillField20FromCell.cpp | 54 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp new file mode 100644 index 0000000000..17b6c68200 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp @@ -0,0 +1,54 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052C810 + void WildlifeState::floodFillField20FromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].field_0x50 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].field_0x50; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].field_0x50 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].field_0x50 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f815dab8af..51f9a6a6bf 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49247,7 +49247,7 @@ SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C5D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052C810 | 0.0% | Pending +SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending From 39e3627af25ed03b6c40c39d50edee2e54073660 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:04:23 +0100 Subject: [PATCH 26/43] Wildlife: build updateWildlife and its two flood fills with /GL The original keeps `this` in ecx across floodFillField13FromCell and floodFillField20FromCell, which takes LTCG with both callees compiled with /GL. updateWildlife goes from 50.3 to 100 with no source change. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- cmake/compiler-flags-gl.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 6731216649..1026c484d5 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -270,3 +270,6 @@ src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp +src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp +src/OpenSHC/Map/WildlifeState/updateWildlife.cpp From 10ec5088177f65149338c13b577070c5eb01f324 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:04:23 +0100 Subject: [PATCH 27/43] status: updateWildlife 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 51f9a6a6bf..693f0ff4e4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49291,7 +49291,7 @@ SHC_3BB0A8C1_0x0052DDF0 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052DF30 | 50.3% | this kept in ecx across calls (LTCG) +SHC_3BB0A8C1_0x0052DF30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending From a9712dd401ae08d3e6900fb71ea33096038f4d68 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:08:01 +0100 Subject: [PATCH 28/43] LandscapeState: build updateTreeStage and its tree-size callee with /GL The original pushes the tree type it loaded before getValueFrom0UpTo3ForTreeTypeAndTreeStage again after the call, without reloading it; LTCG knows the callee leaves edx alone. With both listed, updateTreeStage goes from 85.7 to 100. 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 1026c484d5..ec3113f43d 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -273,3 +273,5 @@ src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp src/OpenSHC/Map/WildlifeState/updateWildlife.cpp +src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp +src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp From 9e14d1ea76a2d783296a495721e4b0adacdd859f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 23:08:02 +0100 Subject: [PATCH 29/43] status: updateTreeStage 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 693f0ff4e4..5451605328 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38593,7 +38593,7 @@ SHC_3BB0A8C1_0x004F3900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3960 | 85.7% | edx kept across a call (LTCG) +SHC_3BB0A8C1_0x004F3960 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending From 94652a06e5a46b9fb691bb22895c0166b9adafdc Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 11:20:44 +0100 Subject: [PATCH 30/43] Wildlife: updateWildlifeGrid unit arms in the original's layout The original tests isStalked and lays the unstalked counts out last, so the deer arm's field_0x48 increment cross-jumps into that arm's copy; an if/else on isStalked != 0 reproduces it. Walking the tile row directly instead of through a dy offset gives the original's single induction variable for it (67.6 -> 74.2). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/WildlifeState/updateWildlifeGrid.cpp | 39 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp index 9e98d85798..09e0798ce9 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -76,8 +76,7 @@ namespace Map { areaCounts[k][0] = -1; areaCounts[k][1] = 0; } - for (int dy = 0; dy < 10; dy++) { - uint const tileY = dy + tileY10; + for (uint tileY = tileY10; tileY < (uint)tileY10 + 10; tileY++) { for (int dx = 0; dx < 10; dx++) { uint const tileX = dx + x; if (tileX > 399 || tileY > 399 @@ -193,26 +192,26 @@ namespace Map { continue; } this->grid[gridX][_y10].unitCount = this->grid[gridX][_y10].unitCount + 1; - if (DAT_UnitsState::instance.units[unitID].isStalked == 0) { + if (DAT_UnitsState::instance.units[unitID].isStalked != 0) { + this->grid[gridX][_y10].stalkedUnitCount = this->grid[gridX][_y10].stalkedUnitCount + 1; + UnitTypeShort const unitType = DAT_UnitsState::instance.units[unitID].unitType; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + this->grid[gridX][_y10].deerCount = this->grid[gridX][_y10].deerCount + 1; + if (DAT_TribesState::instance.tribes[DAT_UnitsState::instance.units[unitID].tribeID] + .predatorNearby + != 0) { + this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; + } + } else if (unitType == Map::Units::UT_RABBIT) { + this->grid[gridX][_y10].rabbitCount = this->grid[gridX][_y10].rabbitCount + 1; + } else if (unitType == Map::Units::UT_CAMELSHBEAR) { + this->grid[gridX][_y10].camelCount = this->grid[gridX][_y10].camelCount + 1; + } else if (unitType == Map::Units::UT_LIONSHWOLF) { + this->grid[gridX][_y10].lionCount = this->grid[gridX][_y10].lionCount + 1; + } + } else { this->grid[gridX][_y10].unstalkedUnitCount = this->grid[gridX][_y10].unstalkedUnitCount + 1; this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; - continue; - } - this->grid[gridX][_y10].stalkedUnitCount = this->grid[gridX][_y10].stalkedUnitCount + 1; - UnitTypeShort const unitType = DAT_UnitsState::instance.units[unitID].unitType; - if (unitType == Map::Units::UT_ANTELOPESHDEER) { - this->grid[gridX][_y10].deerCount = this->grid[gridX][_y10].deerCount + 1; - if (DAT_TribesState::instance.tribes[DAT_UnitsState::instance.units[unitID].tribeID] - .predatorNearby - != 0) { - this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; - } - } else if (unitType == Map::Units::UT_RABBIT) { - this->grid[gridX][_y10].rabbitCount = this->grid[gridX][_y10].rabbitCount + 1; - } else if (unitType == Map::Units::UT_CAMELSHBEAR) { - this->grid[gridX][_y10].camelCount = this->grid[gridX][_y10].camelCount + 1; - } else if (unitType == Map::Units::UT_LIONSHWOLF) { - this->grid[gridX][_y10].lionCount = this->grid[gridX][_y10].lionCount + 1; } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5451605328..f16852aa90 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49235,7 +49235,7 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 67.6% | Strength-reduced tileY*400 adds three stack slots +SHC_3BB0A8C1_0x0052BA10 | 74.2% | Strength-reduced tileY*400 and *12 row offsets the original recomputes per tile SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending From b4fbd64fab8cfb1816c87001b086f05209572842 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 11:25:08 +0100 Subject: [PATCH 31/43] Wildlife: rally point search tests the lion count last in both arms Both neighbour filters end in the same lionCount test in the original, which MSVC shares between the arms and lays out inline ahead of the enqueue. Testing deer and lions one at a time, and the lion count on its own after unstalked units and buildings, reproduces it (71.5 -> 75.8). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- ...findAndSetNewRallyPointForDeerAndLions.cpp | 21 ++++++++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index 81eef293e6..ea74eceed7 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -58,15 +58,22 @@ namespace Map { continue; } // 13: the wildlife tribe - if (DAT_TribesState::instance.tribes[tribeID].tribeType == 13 - && (this->grid[neighbourX][neighbourY].deerCount != 0 - || this->grid[neighbourX][neighbourY].lionCount != 0)) { + if (DAT_TribesState::instance.tribes[tribeID].tribeType == 13) { + if (this->grid[neighbourX][neighbourY].deerCount != 0) { + continue; + } + if (this->grid[neighbourX][neighbourY].lionCount != 0) { + continue; + } + } + } else { + if (this->grid[neighbourX][neighbourY].unstalkedUnitCount != 0 + || this->grid[neighbourX][neighbourY].buildingTiles != 0) { + continue; + } + if (this->grid[neighbourX][neighbourY].lionCount != 0) { continue; } - } else if (this->grid[neighbourX][neighbourY].unstalkedUnitCount != 0 - || this->grid[neighbourX][neighbourY].buildingTiles != 0 - || this->grid[neighbourX][neighbourY].lionCount != 0) { - continue; } if (this->grid[neighbourX][neighbourY].casDisRelated2 < level) { this->grid[neighbourX][neighbourY].casDisRelated2 = level; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f16852aa90..efa699493b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 71.5% | Register and stack-slot allocation +SHC_3BB0A8C1_0x0052CAB0 | 75.8% | x and y swap registers; x stays in a stack slot in the walk SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending From d2a5f60f9248094940d850ba345fc84ca9a4107c Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 14:39:06 +0100 Subject: [PATCH 32/43] Wildlife: renderDebugDataMapData draws the box in every colour arm The original calls drawColorBox once per colour arm instead of picking a colour and drawing once: MSVC hoists the shared coordinate arithmetic above each chain's last branch and cross-jumps the identical call tails, which is where its eight extra lea runs come from. 48.9% -> 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../WildlifeState/renderDebugDataMapData.cpp | 235 +++++++++++++----- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 172 insertions(+), 65 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp index e2e35c775d..914d97d89e 100644 --- a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -75,149 +75,256 @@ namespace Map { if (this->grid[column][row].firstMember <= 0) { continue; } - int colour; if (this->DAT_DebugDataMapDataDisplayType == 0) { int const areaColour = this->grid[column][row].separateAreaID & 7; if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (areaColour == 1) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (areaColour == 2) { - colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); } else if (areaColour == 3) { - colour = (ushort)COL_MODERATE_GREEN::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_MODERATE_GREEN::instance.shortValue); } else if (areaColour == 4) { - colour = (ushort)COL_WHITE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); } else if (areaColour == 5) { - colour = (ushort)COL_DARK_CYAN_GREY::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_CYAN_GREY::instance.shortValue); } else if (areaColour == 6) { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } else if (areaColour == 7) { - colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); } else { - colour = (ushort)COL_VERY_DARK_GREY::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VERY_DARK_GREY::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 1) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].chimps) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 2) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].farmFieldTiles) { - colour = (ushort)COL_DARK_GREEN::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_GREEN::instance.shortValue); } else if (this->grid[column][row].rabbitCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].field_0x3c) { - colour = (ushort)COL_WHITE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); } else if (this->grid[column][row].field_0x50) { - colour = (ushort)COL_DARK_CYAN_GREY::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_CYAN_GREY::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 3) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].unstalkedUnitCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 4) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].unstalkedUnitCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].buildingTiles) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].field_0x34) { - colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 5) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].unstalkedUnitCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].buildingTiles) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].lionCount) { - colour = (ushort)COL_BLACK::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); } else if (this->grid[column][row].camelCount) { - colour = (ushort)COL_BLACK::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); } else if (this->grid[column][row].deerCount) { - colour = (ushort)COL_MODERATE_GREEN::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_MODERATE_GREEN::instance.shortValue); } else if (this->grid[column][row].field_0x34) { - colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 6) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].deerCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].lionCount) { - colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); } else if (this->grid[column][row].field_0x3c) { - colour = (ushort)COL_WHITE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); } else if (this->grid[column][row].casDisRelated2) { - colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); } else if (this->grid[column][row].field_0x34) { - colour = (ushort)COL_BLACK::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 7) { if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].field_0x48) { - colour = (ushort)COL_WHITE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); } else if (this->grid[column][row].deerCount) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].field_0x34) { - colour = (ushort)COL_BLACK::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 8) { if (this->grid[column][row].field_0x60) { - colour = (ushort)COL_WHITE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); } else if (this->grid[column][row].field_0x64) { - colour = (ushort)COL_BLACK::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); } else if (this->grid[column][row].castlebuildings) { - colour = (ushort)COL_BRIGHT_YELLOW::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); } else if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else if (this->grid[column][row].unknownNonZero01) { - colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); } else if (this->grid[column][row].field_0x6c) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } } else if (this->DAT_DebugDataMapDataDisplayType == 9) { if (this->grid[column][row].field_0x74) { - colour = (ushort)COL_RED::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); } else if (this->grid[column][row].unknownNonZero01) { - colour = (ushort)COL_VIVID_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); } else if (!this->grid[column][row].separateAreaID) { - colour = (ushort)COL_BLUE::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); } else { - colour = (ushort)COL_LIME::instance.shortValue; + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); } - } else { - continue; } - int const boxX = x1 + column * 10; - int const boxY = y + row * 10; - MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( - boxX + 1, boxY + 1, boxX + 9, boxY + 9, colour); } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index efa699493b..1a963adc78 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49241,7 +49241,7 @@ SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending SHC_3BB0A8C1_0x0052BEA0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052BF40 | 48.9% | Register allocation (y and x+2 held all function in the original) +SHC_3BB0A8C1_0x0052BF40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented From c8fde8bfd558133475d1bfb24e7ffe58b663c5fc Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 21:39:37 +0100 Subject: [PATCH 33/43] Wildlife: buildRallyPointPathForTribe reads the tribe's y before its x Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 9be45fda0e..45564ba1d1 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -24,8 +24,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) { - int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; this->casDisRelated = param_2; this->candidateIndex = 0; this->candidateIndex2 = 1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1a963adc78..a58ea63176 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 69.7% | Stack-slot and register allocation in the walk +SHC_3BB0A8C1_0x0052CFE0 | 70.6% | Stack-slot and register allocation in the walk SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending From 73fe525ad1a254794061e51bef1eac5cfba08fc7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 21:41:25 +0100 Subject: [PATCH 34/43] Wildlife: findAndSetNewRallyPointForDeerAndLions reads the tribe's y before its x Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index ea74eceed7..00a093d6cb 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -19,8 +19,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) { - int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; this->casDisRelated = always2or3or5; this->candidateIndex = 0; this->candidateIndex2 = 1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a58ea63176..7dc5302be8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 75.8% | x and y swap registers; x stays in a stack slot in the walk +SHC_3BB0A8C1_0x0052CAB0 | 77.0% | Stack-slot and register allocation in the search loops SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending From 3047d59d03516494f20bd952a26140bbdbf396a1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 2 Dec 2026 17:42:08 +0100 Subject: [PATCH 35/43] Landscape/Wildlife: adapt sources to main's headers - WildlifeState::hasAdjacentCellWithField24Or25 returns BOOLEnum on main (TRUE/FALSE, same code). - Tree::unknownDistanceRelatedToCrow is hasCrow on main. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp | 2 +- .../Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp index 6cf5045f13..4be201989b 100644 --- a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp +++ b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp @@ -35,7 +35,7 @@ namespace Map { if (treeID == 0 || treeID >= this->maxTreeCount) { continue; } - if (this->trees[treeID].state != 2 || this->trees[treeID].unknownDistanceRelatedToCrow == 0 + if (this->trees[treeID].state != 2 || this->trees[treeID].hasCrow == 0 || this->trees[treeID].rng200till300 != 0) { continue; } diff --git a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp index 5d02a53dae..ba31ff8c20 100644 --- a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp +++ b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp @@ -8,7 +8,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052D620 - undefined4 WildlifeState::hasAdjacentCellWithField24Or25(int param_1, int param_2) + BOOLEnum WildlifeState::hasAdjacentCellWithField24Or25(int param_1, int param_2) { // the four cardinal directions for (int direction = 0; direction < 8; direction += 2) { @@ -18,10 +18,10 @@ namespace Map { = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + param_2; if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 && (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0)) { - return 1; + return TRUE; } } - return 0; + return FALSE; } } From 20b6e50e7de4846ed8a9d4126a034c362481f80a Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 23:46:23 +0100 Subject: [PATCH 36/43] status: updateNofFpoints measures 77.5% after the merge with main Full build plus reccmp with both resolver sets enabled, /GL build (the file stays in compiler-flags-gl.txt). Building updateSection1034Info, updateNofFpoints, updateWildlife and updateTreeStage as function-visibility wrapper units instead measured identical to /GL for all four, so the /GL entries are kept and function-visibility.txt is not changed. 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 4dfd826b80..8533939fe0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49299,7 +49299,7 @@ SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending SHC_3BB0A8C1_0x0052E020 | 94.0% | Outer 20-pass loop counts down; original counts up in a stack slot -SHC_3BB0A8C1_0x0052E120 | 79.0% | Binary-map base folded into the y*400 induction variable; register naming +SHC_3BB0A8C1_0x0052E120 | 77.5% | Binary-map base folded into the y*400 induction variable; register naming SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending From 9b623d52b1fb6696fdd8814a30a899331d2ffa5f Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 08:59:30 +0100 Subject: [PATCH 37/43] reimplement: SHC_3BB0A8C1_0x0052E020 100.00% Reimplemented The pass counter is advanced through a volatile read (pass = *(int volatile*)&pass + 1). With a plain pass++ MSVC sees the counter unused in the body and reverses the loop into a count-down in its stack slot; the original counts up (load, add, cmp 20, store). Build mode: /GL (unchanged), measured with its /GL callees. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp | 4 +++- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp index cfba74d1ff..8470e2eb37 100644 --- a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -16,7 +16,9 @@ namespace Map { if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { return; } - for (int pass = 0; pass < 20; pass++) { + // the volatile read keeps the pass counter counting up in its stack slot; a plain `pass++` lets MSVC + // reverse the unused counter into a count-down loop, which the original does not do + for (int pass = 0; pass < 20; pass = *(int volatile*)&pass + 1) { for (int y = 0; y < 40; y++) { for (int x = 0; x < 40; x++) { this->grid[x][y].unknownNonZero01 = 0; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8533939fe0..63a4f4168f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49297,7 +49297,7 @@ SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052E020 | 94.0% | Outer 20-pass loop counts down; original counts up in a stack slot +SHC_3BB0A8C1_0x0052E020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052E120 | 77.5% | Binary-map base folded into the y*400 induction variable; register naming From 71461c2c71a14861a2486df89b357752f4a584e1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:29:04 +0100 Subject: [PATCH 38/43] reimplement: SHC_3BB0A8C1_0x0052CFE0 94.58% Stack slot layout differs buildRallyPointPathForTribe: 70.6% -> 94.6%. The unit's x is read before y (the original loads unit.x first, into ebx), and the greedy walk moves copies walkX/walkY of the start cell (declared y then x) instead of x/y themselves; the original reloads x/y from their slots and copies them (mov eax, ebx; mov [esp+0x10], ebp) before the walk. tileY is computed before tileX. Remaining: stack slot colouring of the BFS locals and the param_2 copy (mov eax,[esp+0x34] .. mov [esp+0x34],eax) whose scheduling we do not reproduce. Non-GL build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../buildRallyPointPathForTribe.cpp | 32 ++++++++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 45564ba1d1..13ac3ba02e 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -24,8 +24,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) { - int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; this->casDisRelated = param_2; this->candidateIndex = 0; this->candidateIndex2 = 1; @@ -70,11 +70,13 @@ namespace Map { this->candidateIndex = 0; } } + int walkY = y; + int walkX = x; uint const rng = (byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; - this->grid[x][y].field_0x3c = 1; - this->grid[x][y].casDisRelated2 = 0; + this->grid[walkX][walkY].field_0x3c = 1; + this->grid[walkX][walkY].casDisRelated2 = 0; while (true) { int bestDirection = -1; for (int k = 0; k < 8; k++) { @@ -83,9 +85,11 @@ namespace Map { direction = direction - 8; } uint const neighbourX - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + x; + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + walkX; uint const neighbourY - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + y; + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + walkY; if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 && this->grid[neighbourX][neighbourY].casDisRelated2 > param_2) { @@ -98,17 +102,21 @@ namespace Map { if (bestDirection <= -1) { return TRUE; } - x = x + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; - y = y + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; - this->grid[x][y].field_0x3c = 1; - uint const tileX = x * 10 + 5; - uint const tileY = y * 10 + 5; + walkX = walkX + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + walkY = walkY + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[walkX][walkY].field_0x3c = 1; + uint const tileY = walkY * 10 + 5; + uint const tileX = walkX * 10 + 5; if (tileX <= 399 && tileY <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { DAT_TribesState::instance.tribes[param_1] - .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] = (short)x * 10 + 5; + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] + = (short)walkX * 10 + 5; DAT_TribesState::instance.tribes[param_1] - .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] = (short)y * 10 + 5; + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] + = (short)walkY * 10 + 5; DAT_TribesState::instance.tribes[param_1].rallyPointCount = DAT_TribesState::instance.tribes[param_1].rallyPointCount + 1; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 63a4f4168f..147b8a54d2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 70.6% | Stack-slot and register allocation in the walk +SHC_3BB0A8C1_0x0052CFE0 | 94.6% | Stack slot layout differs SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending From f35c83b3e4ab1a2279a1abfe2327ad03f6ec6c05 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:29:18 +0100 Subject: [PATCH 39/43] reimplement: SHC_3BB0A8C1_0x0052CAB0 88.62% Stack slot layout differs findAndSetNewRallyPointForDeerAndLions: 77.0% -> 88.6%. Same shape as buildRallyPointPathForTribe: x is read before y, and the walk uses copies walkX/walkY plus a threshold copy of always2or3or5 (the original reloads the parameter and stores it back to its home before the walk). Remaining: stack slot colouring of the walk locals and the threshold copy scheduled before the RNG read. Non-GL build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...findAndSetNewRallyPointForDeerAndLions.cpp | 31 ++++++++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index 00a093d6cb..cc42170d0a 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -19,8 +19,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) { - int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; this->casDisRelated = always2or3or5; this->candidateIndex = 0; this->candidateIndex2 = 1; @@ -90,11 +90,14 @@ namespace Map { this->candidateIndex = 0; } } + int walkY = y; + int walkX = x; + int threshold = always2or3or5; uint const rng = (byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; - this->grid[x][y].field_0x3c = 1; - this->grid[x][y].casDisRelated2 = 0; + this->grid[walkX][walkY].field_0x3c = 1; + this->grid[walkX][walkY].casDisRelated2 = 0; while (true) { int bestDirection = -1; for (int k = 0; k < 8; k++) { @@ -103,26 +106,30 @@ namespace Map { direction = direction - 8; } uint const neighbourX - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + x; + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + walkX; uint const neighbourY - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + y; + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + walkY; if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 - && this->grid[neighbourX][neighbourY].casDisRelated2 < always2or3or5) { + && this->grid[neighbourX][neighbourY].casDisRelated2 < threshold) { int const distance = this->grid[neighbourX][neighbourY].casDisRelated2; this->grid[neighbourX][neighbourY].casDisRelated2 = 0; - always2or3or5 = distance; + threshold = distance; bestDirection = direction; } } if (bestDirection <= -1) { return; } - x = x + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; - y = y + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; - this->grid[x][y].field_0x3c = 1; - uint const tileY = y * 10 + 5; - uint const tileX = x * 10 + 5; + walkX = walkX + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + walkY = walkY + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[walkX][walkY].field_0x3c = 1; + uint const tileX = walkX * 10 + 5; + uint const tileY = walkY * 10 + 5; if (tileX <= 399 && tileY <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 147b8a54d2..2f9261ac0e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 77.0% | Stack-slot and register allocation in the search loops +SHC_3BB0A8C1_0x0052CAB0 | 88.6% | Stack slot layout differs SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending From 10217ac053efcd54c27107f7fb63e7f00249148d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:29:24 +0100 Subject: [PATCH 40/43] reimplement: SHC_3BB0A8C1_0x0052BA10 87.47% ebx/ebp swap tile vs zero updateWildlifeGrid: 74.2% -> 87.5%. campgroundAreaIDs is indexed by player ID 1..8 with slot 0 unused (the original's frame is 0x35c with the array one dword higher), and the tile rows run over dy 0..9 with tileY = row + tileY10, where row is read through a volatile so MSVC does not strength-reduce tileY*400 and translationMatrix[tileY] across the dy loop (the original recomputes both per tile). Remaining: a clean ebx/ebp 2-cycle between tile and the shared zero constant (reg_scores --whyreg: tile takes ebx at a cost-0 tie). Non-GL build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/WildlifeState/updateWildlifeGrid.cpp | 24 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp index 09e0798ce9..1a0cd30ecb 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -34,13 +34,14 @@ namespace Map { void WildlifeState::updateWildlifeGrid(int _y10) { int const tileY10 = _y10 * 10; - int campgroundAreaIDs[8]; - for (int k = 0; k < 8; k++) { - campgroundAreaIDs[k] = -1; - if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[k + 1] != -1) { - campgroundAreaIDs[k] - = (short) - DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance.playerDataArray[k + 1] + // indexed by player ID, slot 0 unused + int campgroundAreaIDs[9]; + for (int playerID = 1; playerID < 9; playerID++) { + campgroundAreaIDs[playerID] = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1) { + campgroundAreaIDs[playerID] + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[playerID] .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] .tileEntry]; } @@ -76,7 +77,10 @@ namespace Map { areaCounts[k][0] = -1; areaCounts[k][1] = 0; } - for (uint tileY = tileY10; tileY < (uint)tileY10 + 10; tileY++) { + for (int dy = 0; dy < 10; dy++) { + // the volatile read keeps the row from being strength-reduced across the dy loop, as in the original + int const row = *(int volatile*)&dy; + uint const tileY = row + tileY10; for (int dx = 0; dx < 10; dx++) { uint const tileX = dx + x; if (tileX > 399 || tileY > 399 @@ -101,8 +105,8 @@ namespace Map { } } if (areaID != 0) { - for (int k = 0; k < 8; k++) { - if (areaID == campgroundAreaIDs[k]) { + for (int playerID = 1; playerID < 9; playerID++) { + if (areaID == campgroundAreaIDs[playerID]) { this->grid[gridX][_y10].chimps = this->grid[gridX][_y10].chimps + 1; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2f9261ac0e..db99cdc516 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49235,7 +49235,7 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 74.2% | Strength-reduced tileY*400 and *12 row offsets the original recomputes per tile +SHC_3BB0A8C1_0x0052BA10 | 87.5% | ebx/ebp swap tile vs zero SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending From 1171023f88a690c2c148b5aabac687ef818e2c12 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:46:56 +0100 Subject: [PATCH 41/43] reimplement: SHC_3BB0A8C1_0x0052CFE0 97.95% param_2 copy scheduling buildRallyPointPathForTribe: 94.6% -> 98.0%. One pair of cell coordinates (cellX/cellY, function scope) serves both the flood fill's current cell and the walk position, instead of separate candidate and walk locals. slot_probe.py shows why: sharing one element gives cellY weight 12 and the first local colour, so it takes the lowest slot and the cell pointer, areaID and x fall into the original's slots. Remaining: the original's reload/store of param_2 before the walk and an esi/edi zero constant, both scheduling. Non-GL build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../buildRallyPointPathForTribe.cpp | 38 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp index 13ac3ba02e..15fb10ae23 100644 --- a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -24,6 +24,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) { + // one pair of cell coordinates serves both the flood fill and the walk, as in the original: its stack + // slots are shared that way + int cellY; + int cellX; int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; this->casDisRelated = param_2; @@ -43,15 +47,15 @@ namespace Map { this->grid[x][y].casDisRelated2 = this->grid[x][y].field_0x50; int const areaID = this->grid[x][y].separateAreaID; while (this->candidateIndex != this->candidateIndex2) { - int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; - int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; for (int direction = 0; direction < 8; direction++) { uint const neighbourX = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset - + candidateX; + + cellX; uint const neighbourY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset - + candidateY; + + cellY; if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 && areaID == this->grid[neighbourX][neighbourY].separateAreaID && this->grid[neighbourX][neighbourY].field_0x50 > 0 @@ -70,13 +74,13 @@ namespace Map { this->candidateIndex = 0; } } - int walkY = y; - int walkX = x; + cellY = y; + cellX = x; uint const rng = (byte)SEC_RNG::instance.currentNumber2; DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; - this->grid[walkX][walkY].field_0x3c = 1; - this->grid[walkX][walkY].casDisRelated2 = 0; + this->grid[cellX][cellY].field_0x3c = 1; + this->grid[cellX][cellY].casDisRelated2 = 0; while (true) { int bestDirection = -1; for (int k = 0; k < 8; k++) { @@ -86,10 +90,10 @@ namespace Map { } uint const neighbourX = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset - + walkX; + + cellX; uint const neighbourY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset - + walkY; + + cellY; if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 && this->grid[neighbourX][neighbourY].casDisRelated2 > param_2) { @@ -102,21 +106,21 @@ namespace Map { if (bestDirection <= -1) { return TRUE; } - walkX = walkX + cellX = cellX + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; - walkY = walkY + cellY = cellY + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; - this->grid[walkX][walkY].field_0x3c = 1; - uint const tileY = walkY * 10 + 5; - uint const tileX = walkX * 10 + 5; + this->grid[cellX][cellY].field_0x3c = 1; + uint const tileY = cellY * 10 + 5; + uint const tileX = cellX * 10 + 5; if (tileX <= 399 && tileY <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { DAT_TribesState::instance.tribes[param_1] .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] - = (short)walkX * 10 + 5; + = (short)cellX * 10 + 5; DAT_TribesState::instance.tribes[param_1] .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] - = (short)walkY * 10 + 5; + = (short)cellY * 10 + 5; DAT_TribesState::instance.tribes[param_1].rallyPointCount = DAT_TribesState::instance.tribes[param_1].rallyPointCount + 1; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index db99cdc516..4a0461e3e1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 94.6% | Stack slot layout differs +SHC_3BB0A8C1_0x0052CFE0 | 98.0% | param_2 copy scheduling SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending From ca81410a2f5d3d7a86597f0a897daead818da7ba Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:46:58 +0100 Subject: [PATCH 42/43] reimplement: SHC_3BB0A8C1_0x0052CAB0 96.11% x/cell slot swap findAndSetNewRallyPointForDeerAndLions: 88.6% -> 96.1%. Same shared cellX/cellY pair as buildRallyPointPathForTribe, and the threshold copy of always2or3or5 is taken after the RNG read, as the original reloads the parameter after the movzx. Remaining: x and the start-cell pointer swap stack slots (0x14/0x1c), and tileX/tileY register order at the end of the walk. Non-GL build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...findAndSetNewRallyPointForDeerAndLions.cpp | 38 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp index cc42170d0a..03b00f4fba 100644 --- a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -19,6 +19,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) { + // one pair of cell coordinates serves both the flood fill and the walk, as in the original: its stack + // slots are shared that way + int cellY; + int cellX; int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; this->casDisRelated = always2or3or5; @@ -35,9 +39,9 @@ namespace Map { int const areaID = this->grid[x][y].separateAreaID; this->grid[x][y].casDisRelated2 = always2or3or5; while (this->candidateIndex != this->candidateIndex2) { - int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; - int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; - this->casDisRelated = this->grid[candidateX][candidateY].casDisRelated2; + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].casDisRelated2; if (this->casDisRelated <= 1) { break; } @@ -45,10 +49,10 @@ namespace Map { for (int direction = 0; direction < 8; direction++) { uint const neighbourX = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset - + candidateX; + + cellX; uint const neighbourY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset - + candidateY; + + cellY; if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 || areaID != this->grid[neighbourX][neighbourY].separateAreaID) { continue; @@ -90,14 +94,14 @@ namespace Map { this->candidateIndex = 0; } } - int walkY = y; - int walkX = x; - int threshold = always2or3or5; + cellY = y; + cellX = x; uint const rng = (byte)SEC_RNG::instance.currentNumber2; + int threshold = always2or3or5; DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; - this->grid[walkX][walkY].field_0x3c = 1; - this->grid[walkX][walkY].casDisRelated2 = 0; + this->grid[cellX][cellY].field_0x3c = 1; + this->grid[cellX][cellY].casDisRelated2 = 0; while (true) { int bestDirection = -1; for (int k = 0; k < 8; k++) { @@ -107,10 +111,10 @@ namespace Map { } uint const neighbourX = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset - + walkX; + + cellX; uint const neighbourY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset - + walkY; + + cellY; if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 && this->grid[neighbourX][neighbourY].casDisRelated2 < threshold) { @@ -123,13 +127,13 @@ namespace Map { if (bestDirection <= -1) { return; } - walkX = walkX + cellX = cellX + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; - walkY = walkY + cellY = cellY + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; - this->grid[walkX][walkY].field_0x3c = 1; - uint const tileX = walkX * 10 + 5; - uint const tileY = walkY * 10 + 5; + this->grid[cellX][cellY].field_0x3c = 1; + uint const tileX = cellX * 10 + 5; + uint const tileY = cellY * 10 + 5; if (tileX <= 399 && tileY <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4a0461e3e1..54b4e54261 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49251,7 +49251,7 @@ SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 88.6% | Stack slot layout differs +SHC_3BB0A8C1_0x0052CAB0 | 96.1% | x/cell slot swap SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending From e7cffbfe65d1c6368b58830fb31859fdecac7736 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 06:10:33 +0100 Subject: [PATCH 43/43] updateNofFpoints: signed bounds check on x and y (86.6%) Writing the check as x < 0 || x > 399 instead of (uint)x > 399 lets the compiler reuse x for the bound test instead of recomputing it. Also refresh the remarks of createTree and updateWildlifeGrid with the measured blockers. SHC_3BB0A8C1_0x0052E120 | 86.6% | Binary-map base folded into the y*400 induction variable; this kept in esi across the flood-fill call Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp index ba7277ffac..fd1f651569 100644 --- a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -54,7 +54,7 @@ namespace Map { int const areaID = (short)DAT_TileMapState::instance .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; - if (separateAreaID != areaID || (uint)x > 399 || (uint)y > 399 + if (separateAreaID != areaID || x < 0 || x > 399 || y < 0 || y > 399 || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == '\0') { continue; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fcbba5267a..5511b10064 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38317,7 +38317,7 @@ SHC_3BB0A8C1_0x004F1C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F1C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F1CE0 | 89.6% | Register allocation of tile arithmetic and parameter loads +SHC_3BB0A8C1_0x004F1CE0 | 89.6% | Tile sum computed straight into edi; the original builds it in ebx and copies, which shifts the jump table SHC_3BB0A8C1_0x004F1FDC | 0.0% | Pending @@ -49235,7 +49235,7 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 87.5% | ebx/ebp swap tile vs zero +SHC_3BB0A8C1_0x0052BA10 | 87.5% | ebx/ebp swap between the shared zero constant and tile (tile is colored first and takes ebx on the tie) SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending @@ -49299,7 +49299,7 @@ SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending SHC_3BB0A8C1_0x0052E020 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052E120 | 77.5% | Binary-map base folded into the y*400 induction variable; register naming +SHC_3BB0A8C1_0x0052E120 | 86.6% | Binary-map base folded into the y*400 induction variable; this kept in esi across the flood-fill call SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending