From 29c08cc12abc5bed37fd5292dd2722bb5a69ae75 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:07 +0100 Subject: [PATCH 01/20] build: compile the WildlifeState and LandscapeState functions of #526 with /GL The nine /GL entries from #526 for the functions this PR carries (hasAdjacentCellWithField24Or25, isAttackStagingCandidateCell, floodFillZoneProximityFromCell, floodFillCasDisFromSignpost, updateSection1034Info, floodFillField13FromCell, floodFillField20FromCell, updateWildlife, updateTreeStage), plus main's getValueFrom0UpTo3ForTreeTypeAndTreeStage as in #526: updateTreeStage calls it, and LTCG must see both sides for the caller to match. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- cmake/compiler-flags-gl.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 5430b694de..c8c3795a69 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -280,6 +280,16 @@ 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/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 src/OpenSHC/Map/Units/UnitsState/acquireShootTarget.cpp src/OpenSHC/Map/Units/UnitsState/calculateUnitMovementSpeed.cpp src/OpenSHC/Map/Units/UnitsState/chooseHusbandAndWife.cpp From cc890adab140110a09edd633579aa071be6d1fc7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:26 +0100 Subject: [PATCH 02/20] reimplement: SHC_3BB0A8C1_0x004F2140 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 42 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/LandscapeState/createRock.cpp diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp new file mode 100644 index 0000000000..291637bee7 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -0,0 +1,42 @@ +#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) + { + // find a free rock slot + int _rockID; + for (_rockID = 1; _rockID < 4000; _rockID++) { + if (this->rocks[_rockID].one == 0) { + break; + } + if (_rockID >= 3999) { + return 0; + } + } + 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].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; + 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/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 766545d302..ab87fc03e7 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 | 0.0% | Pending +SHC_3BB0A8C1_0x004F2140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F2220 | 100.0% | Reimplemented From 66f36d49b1466fea6a7e820264f79584721480fc Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:26 +0100 Subject: [PATCH 03/20] reimplement: SHC_3BB0A8C1_0x004F3960 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/LandscapeState/updateTreeStage.cpp | 110 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp new file mode 100644 index 0000000000..9b0d5fb0b4 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -0,0 +1,110 @@ +#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_LandscapeState.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) + { + 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 ab87fc03e7..f3f0c8c6d4 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 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3960 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending From 5c6c9240a8794f36693083b770f9375653b7a88e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:26 +0100 Subject: [PATCH 04/20] reimplement: SHC_3BB0A8C1_0x0052D9D0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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 f3f0c8c6d4..4a32742bb3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49277,7 +49277,7 @@ SHC_3BB0A8C1_0x0052D720 | 0.0% | Pending 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 188e40c239ccb44a084db412802d234d910bf638 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:27 +0100 Subject: [PATCH 05/20] reimplement: SHC_3BB0A8C1_0x0052C570 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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 4a32742bb3..9df05277f8 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 | 0.0% | Pending -SHC_3BB0A8C1_0x0052C570 | 0.0% | Pending +SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C5D0 | 0.0% | Pending From c9b81968c84760f2a116d732169294330e8059ca Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:27 +0100 Subject: [PATCH 06/20] reimplement: SHC_3BB0A8C1_0x0052C810 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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 9df05277f8..f48b621903 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 6606d30bd638e66b8af452002ffb53ff61450939 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:28 +0100 Subject: [PATCH 07/20] reimplement: SHC_3BB0A8C1_0x0052D720 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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 f48b621903..934ade1181 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49273,7 +49273,7 @@ SHC_3BB0A8C1_0x0052D620 | 0.0% | Pending SHC_3BB0A8C1_0x0052D690 | 0.0% | Pending -SHC_3BB0A8C1_0x0052D720 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D780 | 0.0% | Pending From 2dde25795cf60adadbcdb7694c3de3a6fc98258a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:28 +0100 Subject: [PATCH 08/20] reimplement: SHC_3BB0A8C1_0x0052D620 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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..ba31ff8c20 --- /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 + BOOLEnum 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 TRUE; + } + } + return FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 934ade1181..eabed73d7d 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 0f802a530bf71aec2e2201c268ee472d2ff6dca3 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:29 +0100 Subject: [PATCH 09/20] reimplement: SHC_3BB0A8C1_0x0052D690 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../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 eabed73d7d..db19658874 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 | 100.0% | Reimplemented From bc2c9b0ae0552b8b34070c26a18d9d4727615277 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:29 +0100 Subject: [PATCH 10/20] reimplement: SHC_3BB0A8C1_0x0052BF40 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../WildlifeState/renderDebugDataMapData.cpp | 333 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp new file mode 100644 index 0000000000..914d97d89e --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -0,0 +1,333 @@ +#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 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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); + } + // render the squares + for (int line = 0; line < 41; line++) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + 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)( + 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; + } + if (this->DAT_DebugDataMapDataDisplayType == 0) { + int const areaColour = this->grid[column][row].separateAreaID & 7; + if (!this->grid[column][row].separateAreaID) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 { + 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) { + 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) { + 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) { + 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 { + 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); + } + } + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index db19658874..60fcf77b39 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 | 0.0% | Pending +SHC_3BB0A8C1_0x0052BF40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented From c2e02a9c08900ca64d3c1f70eccf660c92f57f6e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:30 +0100 Subject: [PATCH 11/20] reimplement: SHC_3BB0A8C1_0x0052E020 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../WildlifeState/updateSection1034Info.cpp | 52 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp new file mode 100644 index 0000000000..8470e2eb37 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -0,0 +1,52 @@ +#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() + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + // 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; + 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; + } + } + } + } + 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 60fcf77b39..2708b0449c 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 | 0.0% | Pending +SHC_3BB0A8C1_0x0052E020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052E120 | 0.0% | Pending From 4c78ece61d56755af243a351e3a3d35918753012 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:12:30 +0100 Subject: [PATCH 12/20] reimplement: SHC_3BB0A8C1_0x0052DF30 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/WildlifeState/updateWildlife.cpp | 53 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/WildlifeState/updateWildlife.cpp diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp new file mode 100644 index 0000000000..f1bd01b239 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -0,0 +1,53 @@ +#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() + { + 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 (this->grid[x][y].castlebuildings) { + this->grid[x][y].field_0x60 = this->grid[x][y].field_0x60 + 1; + } + } + } + } + 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 2708b0449c..217ed67cdc 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 | 0.0% | Pending +SHC_3BB0A8C1_0x0052DF30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending From b3774fb4ee89cb2fa7428e543f1afb58dafc9c69 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:28:11 +0100 Subject: [PATCH 13/20] style: apply the style guide to the eleven WildlifeState and LandscapeState functions The class's own .func.hpp as the first include (Map.func.hpp and duplicate includes dropped); countof instead of the grid, BFS queue, rock array and direction bounds (40, 39, 1600, 4000, 8); the BFS while loops as for loops; self-increments; TreeType names for the shrub range in updateTreeStage and LogicHelpers::L_TREE instead of 0x1000; the debug-view labels from string-literals.hpp; param_1/param_2 named cellX/cellY; BOOLEnum returns tested directly; unused usings dropped; namespace closing comments. Re-measured on 40cbb1cb7 with a full build and reccmp: all eleven stay at 100.0/100.0. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 39 +++++++++---------- .../Map/LandscapeState/updateTreeStage.cpp | 32 +++++++-------- .../floodFillCasDisFromSignpost.cpp | 30 +++++++------- .../floodFillField13FromCell.cpp | 24 ++++++------ .../floodFillField20FromCell.cpp | 24 ++++++------ .../floodFillZoneProximityFromCell.cpp | 24 ++++++------ .../hasAdjacentCellWithField24Or25.cpp | 19 +++++---- .../isAttackStagingCandidateCell.cpp | 14 +++---- .../WildlifeState/renderDebugDataMapData.cpp | 37 ++++++++---------- .../WildlifeState/updateSection1034Info.cpp | 30 +++++++------- .../Map/WildlifeState/updateWildlife.cpp | 21 +++++----- 11 files changed, 138 insertions(+), 156 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index 291637bee7..67c67e698c 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -1,4 +1,3 @@ -#include "../../Map.func.hpp" #include "../LandscapeState.func.hpp" #include "OpenSHC/Globals/DAT_CurrentRockID.hpp" @@ -13,30 +12,30 @@ namespace Map { int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) { // find a free rock slot - int _rockID; - for (_rockID = 1; _rockID < 4000; _rockID++) { - if (this->rocks[_rockID].one == 0) { + int rockID; + for (rockID = 1; rockID < countof(this->rocks); rockID++) { + if (this->rocks[rockID].one == 0) { break; } - if (_rockID >= 3999) { + if (rockID >= countof(this->rocks) - 1) { return 0; } } - 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].one = 1; - this->rocks[_rockID].type = (short)rockType; - this->rocks[_rockID].x = (ushort)x; - this->rocks[_rockID].tile + this->rocks[rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker++; + this->rocks[rockID].size = (short)size; + this->rocks[rockID].y = (ushort)y; + 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; - 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; + 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; } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index 9b0d5fb0b4..c8906c3f9c 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -1,10 +1,11 @@ -#include "../../Map.func.hpp" +#include "../LandscapeState.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/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Trees/TreeType.hpp" #include "OpenSHC/Map/Trees/TreeTypeShort.hpp" #include "OpenSHC/UI/Enums/DisplayElementID.hpp" #include "OpenSHC/UI/Enums/MenuViewType.hpp" @@ -21,12 +22,6 @@ 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) { @@ -43,7 +38,8 @@ namespace Map { return; } int const treeType = this->trees[treeID].treeType; - if (treeType >= 5 && treeType <= 19) { + // the shrubs and the apple tree do not advance their stage here + if (treeType >= Trees::TT_SHRUB_NEEDLE_PALM_A && treeType <= Trees::TT_SHRUB_PRICKLYPEAR) { return; } if (this->trees[treeID].zeroUpTo2 != 0) { @@ -58,12 +54,12 @@ namespace Map { if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { return; } - this->trees[treeID].stageTracker = this->trees[treeID].stageTracker + 1; + this->trees[treeID].stageTracker++; 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; + this->trees[treeID].stage++; MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage); if (this->trees[treeID].stage >= 6) { this->trees[treeID].state = 3; @@ -72,7 +68,7 @@ namespace Map { if (this->trees[treeID].stage < 4) { return; } - DAT_GameState::instance.mapAndTime.treeSpreadCounter = DAT_GameState::instance.mapAndTime.treeSpreadCounter + 1; + DAT_GameState::instance.mapAndTime.treeSpreadCounter++; if (DAT_GameState::instance.mapAndTime.treeSpreadCounter > DAT_GameState::instance.mapAndTime.treeSpreadInterval) { DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0; @@ -85,8 +81,7 @@ namespace Map { 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; + DAT_GameState::instance.mapAndTime.newOrganismsValue2++; if (!MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)( treeID, this->trees[treeID].treeType, this->trees[treeID].xPosition, this->trees[treeID].yPosition)) { return; @@ -96,15 +91,14 @@ namespace Map { 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.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] |= LogicHelpers::L_TREE; 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_GameState::instance.mapAndTime.newOrganisms++; DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp index 76ae410137..4eaa183d91 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -23,8 +21,8 @@ namespace Map { this->casDisRelated = 1; this->candidateIndex = 0; this->candidateIndex2 = 1; - for (int row = 0; row < 40; row++) { - for (int column = 0; column < 40; column++) { + for (int row = 0; row < countof(this->grid[0]); row++) { + for (int column = 0; column < countof(this->grid); column++) { this->grid[column][row].casDisRelated2 = 0; this->grid[column][row].field_0x74 = 0; } @@ -33,7 +31,7 @@ namespace Map { 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) { + for (; 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; @@ -41,34 +39,36 @@ namespace Map { break; } int const level = this->casDisRelated + 1; - for (int direction = 0; direction < 8; direction++) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); 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 + if (neighbourX > countof(this->grid) - 1 || neighbourY > countof(this->grid[0]) - 1 + || 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->grid[neighbourX][neighbourY].field_0x74++; 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++; + if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; } } - this->candidateIndex = this->candidateIndex + 1; - if (this->candidateIndex >= 1600) { + this->candidateIndex++; + if (this->candidateIndex >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex = 0; } } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp index a7bdb9dd5b..78a2b67027 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -16,7 +14,7 @@ namespace Map { this->DAT_Y10_Array_Section1034[0] = (short)cellY; this->candidateIndex = 0; this->grid[cellX][cellY].field_0x34 = strength; - while (this->candidateIndex != this->candidateIndex2) { + for (; 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; @@ -24,31 +22,33 @@ namespace Map { break; } int const level = this->casDisRelated - 1; - for (int direction = 0; direction < 8; direction++) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); 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 + if (neighbourX > countof(this->grid) - 1 || neighbourY > countof(this->grid[0]) - 1 + || 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++; + if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; } } - this->candidateIndex = this->candidateIndex + 1; - if (this->candidateIndex >= 1600) { + this->candidateIndex++; + if (this->candidateIndex >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex = 0; } } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp index 17b6c68200..2df52707e8 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -16,7 +14,7 @@ namespace Map { this->DAT_Y10_Array_Section1034[0] = (short)cellY; this->candidateIndex = 0; this->grid[cellX][cellY].field_0x50 = strength; - while (this->candidateIndex != this->candidateIndex2) { + for (; 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; @@ -24,31 +22,33 @@ namespace Map { break; } int const level = this->casDisRelated - 1; - for (int direction = 0; direction < 8; direction++) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); 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 + if (neighbourX > countof(this->grid) - 1 || neighbourY > countof(this->grid[0]) - 1 + || 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++; + if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; } } - this->candidateIndex = this->candidateIndex + 1; - if (this->candidateIndex >= 1600) { + this->candidateIndex++; + if (this->candidateIndex >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex = 0; } } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp index 4c77c3c940..1cf92454f0 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -16,7 +14,7 @@ namespace Map { this->DAT_Y10_Array_Section1034[0] = (short)cellY; this->candidateIndex = 0; this->grid[cellX][cellY].unknownNonZero01 = strength; - while (this->candidateIndex != this->candidateIndex2) { + for (; 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; @@ -24,14 +22,16 @@ namespace Map { break; } int const level = this->casDisRelated - 1; - for (int direction = 0; direction < 8; direction++) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); 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 + if (neighbourX > countof(this->grid) - 1 || neighbourY > countof(this->grid[0]) - 1 + || this->grid[neighbourX][neighbourY].firstMember <= 0 || this->grid[neighbourX][neighbourY].unclaimedArea > 10 || this->grid[neighbourX][neighbourY].unknownNonZero01 >= level) { continue; @@ -39,17 +39,17 @@ namespace Map { 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++; + if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; } } - this->candidateIndex = this->candidateIndex + 1; - if (this->candidateIndex >= 1600) { + this->candidateIndex++; + if (this->candidateIndex >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex = 0; } } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp index ba31ff8c20..46982d2f70 100644 --- a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp +++ b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -8,15 +6,16 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052D620 - BOOLEnum WildlifeState::hasAdjacentCellWithField24Or25(int param_1, int param_2) + BOOLEnum WildlifeState::hasAdjacentCellWithField24Or25(int cellX, int cellY) { // the four cardinal directions - for (int direction = 0; direction < 8; direction += 2) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); direction += 2) { uint const x - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + param_1; + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + cellX; uint const y - = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + param_2; - if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + cellY; + if (x <= countof(this->grid) - 1 && y <= countof(this->grid[0]) - 1 && this->grid[x][y].firstMember > 0 && (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0)) { return TRUE; } @@ -24,5 +23,5 @@ namespace Map { return FALSE; } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp index ed5d5721ef..9cd46a1bc0 100644 --- a/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp @@ -1,6 +1,4 @@ -#include "../../Map.func.hpp" - -#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "../WildlifeState.func.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" @@ -20,17 +18,19 @@ namespace Map { return FALSE; } // the four cardinal directions - for (int direction = 0; direction < 8; direction += 2) { + for (int direction = 0; + direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); 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) { + if (x <= countof(this->grid) - 1 && y <= countof(this->grid[0]) - 1 && this->grid[x][y].firstMember > 0 + && this->grid[x][y].unknownNonZero01 != 0) { return TRUE; } } return FALSE; } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp index 914d97d89e..a16cd7f21a 100644 --- a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -1,10 +1,10 @@ -#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/string-literals.hpp" #include "OpenSHC/Globals/COL_BLACK.hpp" #include "OpenSHC/Globals/COL_BLUE.hpp" @@ -23,55 +23,52 @@ 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 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); + s_Connect_005abbcc, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 1) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Chimps ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Chimps_005abbc0, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 2) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Farmland ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Farmland_005abbb4, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 3) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Humans ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Humans_005abba8, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 4) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Mankind ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Mankind_005abb9c, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 5) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Deer ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Deer_005abb94, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 6) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Route ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Route_005abb8c, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 7) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Panic ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Panic_005abb84, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } else if (this->DAT_DebugDataMapDataDisplayType == 8) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( - "Siege ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + s_Siege_005abb7c, 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); + s_Slink_005abb74, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } // render the squares - for (int line = 0; line < 41; line++) { + for (int line = 0; line < countof(this->grid) + 1; line++) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( x1, y + line * 10, x1 + 400, y + line * 10, COL_WHITE::instance.shortValue); } - for (int line = 0; line < 41; line++) { + for (int line = 0; line < countof(this->grid) + 1; line++) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( 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++) { + for (int row = 0; row < countof(this->grid[0]); row++) { + for (int column = 0; column < countof(this->grid); column++) { if (this->grid[column][row].firstMember <= 0) { continue; } @@ -329,5 +326,5 @@ namespace Map { } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp index 8470e2eb37..47e7c6024f 100644 --- a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -1,6 +1,5 @@ -#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" -#include "OpenSHC/Map/WildlifeState.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" @@ -8,8 +7,6 @@ namespace OpenSHC { namespace Map { - using Game::GameMode; - // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 void WildlifeState::updateSection1034Info() { @@ -19,34 +16,33 @@ namespace Map { // 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++) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); 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; + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(x, y)) { + this->grid[x][y].field_0x64++; } } } } - for (int y = 0; y < 40; y++) { - for (int x = 0; x < 40; x++) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); 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++) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); 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; + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)(x, y)) { + this->grid[x][y].field_0x6c++; } } } } -} -} +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp index f1bd01b239..737bd5241e 100644 --- a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -1,6 +1,5 @@ -#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" -#include "OpenSHC/Map/WildlifeState.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" @@ -8,33 +7,31 @@ namespace OpenSHC { namespace Map { - using Game::GameMode; - // FUNCTION: STRONGHOLDCRUSADER 0x0052DF30 void WildlifeState::updateWildlife() { if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { return; } - for (int y = 0; y < 40; y++) { - for (int x = 0; x < 40; x++) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); 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; + 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 (this->grid[x][y].castlebuildings) { - this->grid[x][y].field_0x60 = this->grid[x][y].field_0x60 + 1; + this->grid[x][y].field_0x60++; } } } } - for (int y = 0; y < 40; y++) { - for (int x = 0; x < 40; x++) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); 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) { @@ -49,5 +46,5 @@ namespace Map { } } -} -} +} // namespace Map +} // namespace OpenSHC From 71dd1395eb1417918d17360ba9ad4f49d1dbe694 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:53:21 +0100 Subject: [PATCH 14/20] review: pre-review pass for TheRedDaemon - updateSection1034Info leaves this PR: it only matches through a volatile read of its pass counter. Its status line goes back to main's, and its /GL entry goes too. - The /GL entries of hasAdjacentCellWithField24Or25, isAttackStagingCandidateCell, floodFillZoneProximityFromCell and floodFillCasDisFromSignpost are dropped: without updateSection1034Info they are not needed (all still 100%). - updateTreeStage stores Trees::TS_TO_BE_REMOVED instead of 3; floodFillCasDisFromSignpost divides by MC_MAP_SECTOR_SIZE; a comment restating createRock's loop is removed. Re-measured on 592a17d94 with a full build and reccmp: all ten functions 100.0/100.0. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- cmake/compiler-flags-gl.txt | 5 -- src/OpenSHC/Map/LandscapeState/createRock.cpp | 1 - .../Map/LandscapeState/updateTreeStage.cpp | 3 +- .../floodFillCasDisFromSignpost.cpp | 6 ++- .../WildlifeState/updateSection1034Info.cpp | 48 ------------------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 6 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 8fcb1eff56..20834d975e 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -280,11 +280,6 @@ 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/floodFillField13FromCell.cpp src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp src/OpenSHC/Map/WildlifeState/updateWildlife.cpp diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index 67c67e698c..c49ae407c8 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -11,7 +11,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F2140 int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) { - // find a free rock slot int rockID; for (rockID = 1; rockID < countof(this->rocks); rockID++) { if (this->rocks[rockID].one == 0) { diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index c8906c3f9c..35ae48e0ce 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -5,6 +5,7 @@ #include "OpenSHC/UI/DisplayElements.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Trees/TreeState.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" #include "OpenSHC/Map/Trees/TreeTypeShort.hpp" #include "OpenSHC/UI/Enums/DisplayElementID.hpp" @@ -62,7 +63,7 @@ namespace Map { this->trees[treeID].stage++; MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage); if (this->trees[treeID].stage >= 6) { - this->trees[treeID].state = 3; + this->trees[treeID].state = Trees::TS_TO_BE_REMOVED; return; } if (this->trees[treeID].stage < 4) { diff --git a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp index 4eaa183d91..4a873abc6e 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp @@ -1,5 +1,7 @@ #include "../WildlifeState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" @@ -13,11 +15,11 @@ namespace Map { int const x = DAT_GameState::instance.mapAndTime .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] .x - / 10; + / MC_MAP_SECTOR_SIZE; int const y = DAT_GameState::instance.mapAndTime .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] .y - / 10; + / MC_MAP_SECTOR_SIZE; this->casDisRelated = 1; this->candidateIndex = 0; this->candidateIndex2 = 1; diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp deleted file mode 100644 index 47e7c6024f..0000000000 --- a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "../WildlifeState.func.hpp" - -#include "OpenSHC/Game/GameMode.hpp" - -#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" - -namespace OpenSHC { -namespace Map { - - // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 - void WildlifeState::updateSection1034Info() - { - if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { - return; - } - // 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 < countof(this->grid[0]); y++) { - for (int x = 0; x < countof(this->grid); 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)) { - this->grid[x][y].field_0x64++; - } - } - } - } - for (int y = 0; y < countof(this->grid[0]); y++) { - for (int x = 0; x < countof(this->grid); 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 < countof(this->grid[0]); y++) { - for (int x = 0; x < countof(this->grid); x++) { - if (this->grid[x][y].unknownNonZero01 == 0 - && MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)(x, y)) { - this->grid[x][y].field_0x6c++; - } - } - } - } - -} // namespace Map -} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3b7f5ec532..06a80944bc 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 | 100.0% | Reimplemented +SHC_3BB0A8C1_0x0052E020 | 0.0% | Pending SHC_3BB0A8C1_0x0052E120 | 0.0% | Pending From 83cb7e6336e87bf1cf62a56994ea0bb8177ce72c Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:06:28 +0100 Subject: [PATCH 15/20] Rename TreeState to TreeStateEnum, TS_ to TSE_ TreeState.hpp/TreeStateShort.hpp become TreeStateEnum.hpp/TreeStateEnumShort.hpp, the types TreeStateEnum/TreeStateEnumShort, and the values TSE_UNUSED, TSE_SPAWNED, TSE_ALIVE, TSE_TO_BE_REMOVED and TSE_STATIC. Tree.hpp's state field and updateTreeStage follow. This frees the TS_ prefix for the TribeState enum in #555 (TS_FREE, TS_ACTIVE, TS_EMPTY). A rename only: updateTreeStage compiles and its quick_diff output is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/LandscapeState/updateTreeStage.cpp | 4 +-- src/OpenSHC/Map/Trees/Tree.hpp | 6 ++--- src/OpenSHC/Map/Trees/TreeState.hpp | 27 ------------------- src/OpenSHC/Map/Trees/TreeStateEnum.hpp | 27 +++++++++++++++++++ ...eStateShort.hpp => TreeStateEnumShort.hpp} | 8 +++--- 5 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 src/OpenSHC/Map/Trees/TreeState.hpp create mode 100644 src/OpenSHC/Map/Trees/TreeStateEnum.hpp rename src/OpenSHC/Map/Trees/{TreeStateShort.hpp => TreeStateEnumShort.hpp} (54%) diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index 35ae48e0ce..0e49448df8 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -5,7 +5,7 @@ #include "OpenSHC/UI/DisplayElements.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" -#include "OpenSHC/Map/Trees/TreeState.hpp" +#include "OpenSHC/Map/Trees/TreeStateEnum.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" #include "OpenSHC/Map/Trees/TreeTypeShort.hpp" #include "OpenSHC/UI/Enums/DisplayElementID.hpp" @@ -63,7 +63,7 @@ namespace Map { this->trees[treeID].stage++; MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage); if (this->trees[treeID].stage >= 6) { - this->trees[treeID].state = Trees::TS_TO_BE_REMOVED; + this->trees[treeID].state = Trees::TSE_TO_BE_REMOVED; return; } if (this->trees[treeID].stage < 4) { diff --git a/src/OpenSHC/Map/Trees/Tree.hpp b/src/OpenSHC/Map/Trees/Tree.hpp index 00ba53d2e8..ab58fbd1b1 100644 --- a/src/OpenSHC/Map/Trees/Tree.hpp +++ b/src/OpenSHC/Map/Trees/Tree.hpp @@ -8,7 +8,7 @@ #pragma once -#include "OpenSHC/Map/Trees/TreeStateShort.hpp" +#include "OpenSHC/Map/Trees/TreeStateEnumShort.hpp" #include "OpenSHC/Map/Trees/TreeTypeShort.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" @@ -16,7 +16,7 @@ namespace OpenSHC { namespace Map { namespace Trees { - using OpenSHC::Map::Trees::TreeStateShort; + using OpenSHC::Map::Trees::TreeStateEnumShort; using OpenSHC::Map::Trees::TreeTypeShort; using OpenSHC::WindowsHelper::Enums::BOOLEnum; @@ -38,7 +38,7 @@ namespace Map { BOOLEnum flag; // 0x00000038 length: 4 int animationFrame2Unk; // 0x0000003C length: 4 undefined1 padding_0x40[4]; // 0x00000040 length: 4 - TreeStateShort state; // 0x00000044 length: 2 + TreeStateEnumShort state; // 0x00000044 length: 2 TreeTypeShort treeType; // 0x00000046 length: 2 undefined1 padding_0x48[4]; // 0x00000048 length: 4 int uid; // 0x0000004C length: 4 diff --git a/src/OpenSHC/Map/Trees/TreeState.hpp b/src/OpenSHC/Map/Trees/TreeState.hpp deleted file mode 100644 index 8730df6ed0..0000000000 --- a/src/OpenSHC/Map/Trees/TreeState.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/** - THIS FILE IS AUTO GENERATED - Communicate changes to the dev team (e.g. via a Pull Request). - Changes get lost otherwise. - - path: 'OpenSHC/Map/Trees/TreeState.hpp' -*/ - -#pragma once - -namespace OpenSHC { -namespace Map { - namespace Trees { - typedef enum TreeState { - - TS_UNUSED = 0, // 0x00000000 - TS_SPAWNED = 1, // 0x00000001 - TS_ALIVE = 2, // 0x00000002 - TS_TO_BE_REMOVED = 3, // 0x00000003 - TS_STATIC = 4 // 0x00000004 - - } TreeState; - - static_assert_cpp98_obj(sizeof(TreeState) == 4, TreeState); - } // namespace Trees -} // namespace Map -} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Trees/TreeStateEnum.hpp b/src/OpenSHC/Map/Trees/TreeStateEnum.hpp new file mode 100644 index 0000000000..168c933a5b --- /dev/null +++ b/src/OpenSHC/Map/Trees/TreeStateEnum.hpp @@ -0,0 +1,27 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Trees/TreeStateEnum.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Trees { + typedef enum TreeStateEnum { + + TSE_UNUSED = 0, // 0x00000000 + TSE_SPAWNED = 1, // 0x00000001 + TSE_ALIVE = 2, // 0x00000002 + TSE_TO_BE_REMOVED = 3, // 0x00000003 + TSE_STATIC = 4 // 0x00000004 + + } TreeStateEnum; + + static_assert_cpp98_obj(sizeof(TreeStateEnum) == 4, TreeStateEnum); + } // namespace Trees +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Trees/TreeStateShort.hpp b/src/OpenSHC/Map/Trees/TreeStateEnumShort.hpp similarity index 54% rename from src/OpenSHC/Map/Trees/TreeStateShort.hpp rename to src/OpenSHC/Map/Trees/TreeStateEnumShort.hpp index b1b5c9cd16..346ccf4f9e 100644 --- a/src/OpenSHC/Map/Trees/TreeStateShort.hpp +++ b/src/OpenSHC/Map/Trees/TreeStateEnumShort.hpp @@ -3,19 +3,19 @@ Communicate changes to the dev team (e.g. via a Pull Request). Changes get lost otherwise. - path: 'OpenSHC/Map/Trees/TreeStateShort.hpp' + path: 'OpenSHC/Map/Trees/TreeStateEnumShort.hpp' */ #pragma once -#include "OpenSHC/Map/Trees/TreeState.hpp" +#include "OpenSHC/Map/Trees/TreeStateEnum.hpp" namespace OpenSHC { namespace Map { namespace Trees { - typedef short TreeStateShort; + typedef short TreeStateEnumShort; - static_assert_cpp98_obj(sizeof(TreeStateShort) == 2, TreeStateShort); + static_assert_cpp98_obj(sizeof(TreeStateEnumShort) == 2, TreeStateEnumShort); } // namespace Trees } // namespace Map } // namespace OpenSHC From 68ea361f04cc5a3675f7f47db0e08bcc8ddbf55d Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 00:47:42 +0100 Subject: [PATCH 16/20] review: drop redundant casts Every removed cast was checked one at a time: the file's /FA listing is identical without it and no new warning appears. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState/createRock.cpp | 15 +++++++-------- .../Map/LandscapeState/updateTreeStage.cpp | 2 +- .../WildlifeState/floodFillCasDisFromSignpost.cpp | 4 ++-- .../WildlifeState/floodFillField13FromCell.cpp | 8 ++++---- .../WildlifeState/floodFillField20FromCell.cpp | 8 ++++---- .../floodFillZoneProximityFromCell.cpp | 8 ++++---- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index c49ae407c8..ee5dc0ff34 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -22,15 +22,14 @@ namespace Map { } this->rocks[rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; DAT_GameCore::instance.uniqueGameObjectTracker++; - this->rocks[rockID].size = (short)size; - this->rocks[rockID].y = (ushort)y; + this->rocks[rockID].size = size; + this->rocks[rockID].y = y; 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; - this->rocks[rockID].unknownGMID = (short)DAT_OrganismDefinedData::instance.Rock_field0xe[rockType]; + this->rocks[rockID].type = rockType; + this->rocks[rockID].x = x; + this->rocks[rockID].tile = (short)x + DAT_ViewportRenderState::instance.translationMatrix[(short)y].addXgetTile; + this->rocks[rockID].orientation = orientation; + this->rocks[rockID].unknownGMID = 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/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index 0e49448df8..3f20ade24c 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -93,7 +93,7 @@ namespace Map { 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] |= LogicHelpers::L_TREE; - DAT_TileMapState::instance.OrganismLayer[DAT_PathFindingState::instance.ALG_ResultTile] = (short)newTreeID; + DAT_TileMapState::instance.OrganismLayer[DAT_PathFindingState::instance.ALG_ResultTile] = 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); diff --git a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp index 4a873abc6e..b2f24dd2ee 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp @@ -58,8 +58,8 @@ namespace Map { } this->grid[neighbourX][neighbourY].casDisRelated2 = level; this->grid[neighbourX][neighbourY].field_0x74++; - this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; - this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = neighbourY; this->candidateIndex2++; if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp index 78a2b67027..8e95777754 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp @@ -10,8 +10,8 @@ namespace Map { { this->candidateIndex2 = 1; this->casDisRelated = 1; - this->DAT_X10_Array_Section1034[0] = (short)cellX; - this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->DAT_X10_Array_Section1034[0] = cellX; + this->DAT_Y10_Array_Section1034[0] = cellY; this->candidateIndex = 0; this->grid[cellX][cellY].field_0x34 = strength; for (; this->candidateIndex != this->candidateIndex2;) { @@ -36,8 +36,8 @@ namespace Map { 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->DAT_X10_Array_Section1034[this->candidateIndex2] = neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = neighbourY; this->candidateIndex2++; if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp index 2df52707e8..196661ccf6 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp @@ -10,8 +10,8 @@ namespace Map { { this->candidateIndex2 = 1; this->casDisRelated = 1; - this->DAT_X10_Array_Section1034[0] = (short)cellX; - this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->DAT_X10_Array_Section1034[0] = cellX; + this->DAT_Y10_Array_Section1034[0] = cellY; this->candidateIndex = 0; this->grid[cellX][cellY].field_0x50 = strength; for (; this->candidateIndex != this->candidateIndex2;) { @@ -36,8 +36,8 @@ namespace Map { 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->DAT_X10_Array_Section1034[this->candidateIndex2] = neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = neighbourY; this->candidateIndex2++; if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; diff --git a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp index 1cf92454f0..145e7b800c 100644 --- a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp +++ b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp @@ -10,8 +10,8 @@ namespace Map { { this->candidateIndex2 = 1; this->casDisRelated = 1; - this->DAT_X10_Array_Section1034[0] = (short)cellX; - this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->DAT_X10_Array_Section1034[0] = cellX; + this->DAT_Y10_Array_Section1034[0] = cellY; this->candidateIndex = 0; this->grid[cellX][cellY].unknownNonZero01 = strength; for (; this->candidateIndex != this->candidateIndex2;) { @@ -37,8 +37,8 @@ namespace Map { 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->DAT_X10_Array_Section1034[this->candidateIndex2] = neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = neighbourY; this->candidateIndex2++; if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) { this->candidateIndex2 = 0; From 4524b11f49487d2e7bbcf0fff87e49fcd66898d8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 01:51:03 +0100 Subject: [PATCH 17/20] Tree::stageRelated2: undefined2 -> short updateTreeStage compares it as a signed word against the short stageRelated1 (0x4F39D7: cmp dx, word ptr [esi+0x90]; jl), so the (short) cast at the use site goes away. updateTreeStage is the only reimplemented user; it stays at 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp | 2 +- src/OpenSHC/Map/Trees/Tree.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index 3f20ade24c..ca4566daf3 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -46,7 +46,7 @@ namespace Map { if (this->trees[treeID].zeroUpTo2 != 0) { return; } - if (this->trees[treeID].stageRelated1 < (short)this->trees[treeID].stageRelated2) { + if (this->trees[treeID].stageRelated1 < this->trees[treeID].stageRelated2) { return; } if (!this->field_0x4) { diff --git a/src/OpenSHC/Map/Trees/Tree.hpp b/src/OpenSHC/Map/Trees/Tree.hpp index ab58fbd1b1..f6f58f8773 100644 --- a/src/OpenSHC/Map/Trees/Tree.hpp +++ b/src/OpenSHC/Map/Trees/Tree.hpp @@ -54,7 +54,7 @@ namespace Map { short param_6; // 0x0000006E length: 2 undefined1 padding_0x70[2]; // 0x00000070 length: 2 short stageRelated1; // 0x00000072 length: 2 - undefined2 stageRelated2; // 0x00000074 length: 2 + short stageRelated2; // 0x00000074 length: 2 short zeroUpTo2; // 0x00000076 length: 2 short treeAdultHoodStageRelatedVisual3; // 0x00000078 length: 2 undefined2 stageRelated4; // 0x0000007A length: 2 From 06338058a5208f1f098fb8cab1dd61e5f90df496 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 01:51:40 +0100 Subject: [PATCH 18/20] LandscapeState::createRock: type the parameters (undefined4, undefined4, int, undefined4, undefined4) becomes (int x, int y, RockType rockType, int size, int orientation). The original reads x and y as dwords (mov edi/ecx, dword ptr [esp+..]), so they are ints; short parameters make MSVC load words instead. rockType indexes the per-type tables. The tile is computed from the stored short fields, which drops the (short) casts, and the callback is called directly. createRock has no reimplemented callers; it stays at 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState.func.hpp | 4 +++- src/OpenSHC/Map/LandscapeState.hpp | 4 +++- src/OpenSHC/Map/LandscapeState/createRock.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState.func.hpp b/src/OpenSHC/Map/LandscapeState.func.hpp index 3166d49795..103a7f1272 100644 --- a/src/OpenSHC/Map/LandscapeState.func.hpp +++ b/src/OpenSHC/Map/LandscapeState.func.hpp @@ -5,6 +5,7 @@ #include "OpenSHC/Commands/MappersEnum.hpp" #include "OpenSHC/IO/PackagedFileMagicNum.hpp" #include "OpenSHC/Map/LandscapeState.hpp" +#include "OpenSHC/Map/Rocks/Enums/RockType.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { @@ -13,6 +14,7 @@ namespace Map { using OpenSHC::Commands::MappersEnum; using OpenSHC::IO::PackagedFileMagicNum; + using OpenSHC::Map::Rocks::Enums::RockType; using OpenSHC::Map::Trees::TreeType; using OpenSHC::WindowsHelper::Enums::BOOLEnum; @@ -51,7 +53,7 @@ namespace Map { &LandscapeState::setCurrentTimeOnSomeTrees) setCurrentTimeOnSomeTrees; - MACRO_FUNCTION_RESOLVER(int (LandscapeState::*)(undefined4, undefined4, int, undefined4, undefined4), false, + MACRO_FUNCTION_RESOLVER(int (LandscapeState::*)(int, int, RockType, int, int), false, Address::SHC_3BB0A8C1_0x004F2140, &LandscapeState::createRock) createRock; diff --git a/src/OpenSHC/Map/LandscapeState.hpp b/src/OpenSHC/Map/LandscapeState.hpp index 50d40b895f..d9d5304def 100644 --- a/src/OpenSHC/Map/LandscapeState.hpp +++ b/src/OpenSHC/Map/LandscapeState.hpp @@ -10,6 +10,7 @@ #include "OpenSHC/Commands/MappersEnum.hpp" #include "OpenSHC/IO/PackagedFileMagicNum.hpp" +#include "OpenSHC/Map/Rocks/Enums/RockType.hpp" #include "OpenSHC/Map/Rocks/Rock.hpp" #include "OpenSHC/Map/Trees/Tree.hpp" #include "OpenSHC/Map/Trees/TreeType.hpp" @@ -24,6 +25,7 @@ namespace Map { using OpenSHC::Commands::MappersEnum; using OpenSHC::IO::PackagedFileMagicNum; using OpenSHC::Map::WindState; + using OpenSHC::Map::Rocks::Enums::RockType; using OpenSHC::Map::Rocks::Rock; using OpenSHC::Map::Trees::Tree; using OpenSHC::Map::Trees::TreeType; @@ -73,7 +75,7 @@ namespace Map { void setCurrentTimeOnSomeTrees(); - int createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation); + int createRock(int x, int y, RockType rockType, int size, int orientation); void removeRock(int rockID); diff --git a/src/OpenSHC/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp index ee5dc0ff34..f22ad4c3a6 100644 --- a/src/OpenSHC/Map/LandscapeState/createRock.cpp +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -9,7 +9,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F2140 - int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) + int LandscapeState::createRock(int x, int y, RockType rockType, int size, int orientation) { int rockID; for (rockID = 1; rockID < countof(this->rocks); rockID++) { @@ -27,11 +27,12 @@ namespace Map { this->rocks[rockID].one = 1; this->rocks[rockID].type = rockType; this->rocks[rockID].x = x; - this->rocks[rockID].tile = (short)x + DAT_ViewportRenderState::instance.translationMatrix[(short)y].addXgetTile; + this->rocks[rockID].tile = this->rocks[rockID].x + + DAT_ViewportRenderState::instance.translationMatrix[this->rocks[rockID].y].addXgetTile; this->rocks[rockID].orientation = orientation; this->rocks[rockID].unknownGMID = DAT_OrganismDefinedData::instance.Rock_field0xe[rockType]; DAT_CurrentRockID::instance = rockID; - (*DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[rockID].type])(); + DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[rockID].type](); return rockID; } From 803c7b25964ef026bd24becc8fe4936c6502cdbe Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 01:51:48 +0100 Subject: [PATCH 19/20] Add the DebugDataMapDataDisplayType enum WildlifeState::DAT_DebugDataMapDataDisplayType selects which wildlife grid layer renderDebugDataMapData draws; each value 0 to 9 prints its own caption (Connect, Chimps, Farmland, Humans, Mankind, Deer, Route, Panic, Siege, Slink). The field becomes DebugDataMapDataDisplayTypeInt (int), so no user changes codegen; renderDebugDataMapData compares against the DDMDDT_ names and stays at 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Enums/DebugDataMapDataDisplayType.hpp | 32 +++++++++++++++ .../Enums/DebugDataMapDataDisplayTypeInt.hpp | 21 ++++++++++ src/OpenSHC/Map/WildlifeState.hpp | 4 +- .../WildlifeState/renderDebugDataMapData.cpp | 41 ++++++++++--------- 4 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 src/OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp create mode 100644 src/OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp diff --git a/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp b/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp new file mode 100644 index 0000000000..f4ad240c27 --- /dev/null +++ b/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp @@ -0,0 +1,32 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum DebugDataMapDataDisplayType { + + DDMDDT_CONNECT = 0, // 0x00000000 + DDMDDT_CHIMPS = 1, // 0x00000001 + DDMDDT_FARMLAND = 2, // 0x00000002 + DDMDDT_HUMANS = 3, // 0x00000003 + DDMDDT_MANKIND = 4, // 0x00000004 + DDMDDT_DEER = 5, // 0x00000005 + DDMDDT_ROUTE = 6, // 0x00000006 + DDMDDT_PANIC = 7, // 0x00000007 + DDMDDT_SIEGE = 8, // 0x00000008 + DDMDDT_SLINK = 9 // 0x00000009 + + } DebugDataMapDataDisplayType; + + static_assert_cpp98_obj(sizeof(DebugDataMapDataDisplayType) == 4, DebugDataMapDataDisplayType); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp b/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp new file mode 100644 index 0000000000..043a43cf07 --- /dev/null +++ b/src/OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp @@ -0,0 +1,21 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp' +*/ + +#pragma once + +#include "OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp" + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef int DebugDataMapDataDisplayTypeInt; + + static_assert_cpp98_obj(sizeof(DebugDataMapDataDisplayTypeInt) == 4, DebugDataMapDataDisplayTypeInt); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState.hpp b/src/OpenSHC/Map/WildlifeState.hpp index 2d2c1d06d2..7afeef92a9 100644 --- a/src/OpenSHC/Map/WildlifeState.hpp +++ b/src/OpenSHC/Map/WildlifeState.hpp @@ -8,12 +8,14 @@ #pragma once +#include "OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp" #include "OpenSHC/Map/Wildlife/WildlifeGridElement.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace Map { + using OpenSHC::Map::Enums::DebugDataMapDataDisplayTypeInt; using OpenSHC::Map::Wildlife::WildlifeGridElement; using OpenSHC::WindowsHelper::Enums::BOOLEnum; @@ -23,7 +25,7 @@ namespace Map { class WildlifeState { public: WildlifeGridElement grid[40][40]; // 0x00000000 length: 256000 - int DAT_DebugDataMapDataDisplayType; // 0x0003E800 length: 4 + DebugDataMapDataDisplayTypeInt DAT_DebugDataMapDataDisplayType; // 0x0003E800 length: 4 int casDisRelated; // 0x0003E804 length: 4 int candidateIndex; // 0x0003E808 length: 4 int candidateIndex2; // 0x0003E80C length: 4 diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp index a16cd7f21a..31fbdb4b0c 100644 --- a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Text/TextManager.func.hpp" #include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp" #include "OpenSHC/Text/TextAlignment.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/string-literals.hpp" @@ -27,34 +28,34 @@ namespace Map { void WildlifeState::renderDebugDataMapData(int x, int y, int width, int height) { int const x1 = x + 2; - if (this->DAT_DebugDataMapDataDisplayType == 0) { + if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_CONNECT) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Connect_005abbcc, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 1) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_CHIMPS) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Chimps_005abbc0, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_FARMLAND) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Farmland_005abbb4, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_HUMANS) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Humans_005abba8, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_MANKIND) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Mankind_005abb9c, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_DEER) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Deer_005abb94, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_ROUTE) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Route_005abb8c, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_PANIC) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Panic_005abb84, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_SIEGE) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Siege_005abb7c, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); - } else if (this->DAT_DebugDataMapDataDisplayType == 9) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_SLINK) { MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Slink_005abb74, x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); } @@ -72,7 +73,7 @@ namespace Map { if (this->grid[column][row].firstMember <= 0) { continue; } - if (this->DAT_DebugDataMapDataDisplayType == 0) { + if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_CONNECT) { int const areaColour = this->grid[column][row].separateAreaID & 7; if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, @@ -111,7 +112,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_CHIMPS) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -125,7 +126,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_FARMLAND) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -151,7 +152,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_HUMANS) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -165,7 +166,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_MANKIND) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -187,7 +188,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_DEER) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -221,7 +222,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_ROUTE) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -251,7 +252,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_PANIC) { if (!this->grid[column][row].separateAreaID) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -273,7 +274,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_SIEGE) { if (this->grid[column][row].field_0x60) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, @@ -303,7 +304,7 @@ namespace Map { 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) { + } else if (this->DAT_DebugDataMapDataDisplayType == Enums::DDMDDT_SLINK) { if (this->grid[column][row].field_0x74) { MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, From bb64bd5e39fc157de89247e955a5462c19943929 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 01:52:03 +0100 Subject: [PATCH 20/20] updateTreeStage: name the stage slot, set the flag with TRUE updateTrees draws one random slot (0 to 63) every eighth tick and passes it in; a tree advances only when the low six bits of its rng1 match, so the parameter is renamed from rng to stageSlot (also in the header) and a one-line comment explains the 0x3f mask. toggleUpdateSeparateAreaTileMap is a dirty flag (set to 1 by its writers, tested and cleared by updateSeparateAreaTileMap), so it is set with TRUE. Stays at 100%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/LandscapeState.hpp | 2 +- src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/LandscapeState.hpp b/src/OpenSHC/Map/LandscapeState.hpp index d9d5304def..55d119ae1e 100644 --- a/src/OpenSHC/Map/LandscapeState.hpp +++ b/src/OpenSHC/Map/LandscapeState.hpp @@ -111,7 +111,7 @@ namespace Map { void updateWind(); - void updateTreeStage(uint treeID, uint rng); + void updateTreeStage(uint treeID, uint stageSlot); int findTree(int playerID, uint unitXPosition, uint unitYPosition); diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp index ca4566daf3..265a139cf4 100644 --- a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -24,7 +24,7 @@ namespace OpenSHC { namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004F3960 - void LandscapeState::updateTreeStage(uint treeID, uint rng) + void LandscapeState::updateTreeStage(uint treeID, uint stageSlot) { if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { if (DAT_GameCore::instance.isTimeHalted) { @@ -35,7 +35,8 @@ namespace Map { return; } } - if ((this->trees[treeID].rng1 & 0x3fU) != rng) { + // updateTrees draws one random slot (0 to 63) every eighth tick; a tree only advances in its own slot + if ((this->trees[treeID].rng1 & 0x3fU) != stageSlot) { return; } int const treeType = this->trees[treeID].treeType; @@ -98,7 +99,7 @@ namespace Map { 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_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = TRUE; } } // namespace Map