From 8fb650c60f74cf65d57d635920e7b642071ce200 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:19 +0100 Subject: [PATCH 01/94] headers: add globals DAT_ARRAY_00b4c7cc and INT_ARRAY_00b4d0f0 placeSiegeTentsAndAssignEngineers reads the per-player MappersEnum[9] array at 0x00B4C7CC and the int[9] array at 0x00B4D0F0. Main has no header for either, so this adds both (resolver false, as generated) and their two Address enum entries. Taken unchanged from the draft branch of #275. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp | 23 ++++++++++++++++++++++ src/OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp | 19 ++++++++++++++++++ src/precomp/addresses-SHC-3BB0A8C1.hpp | 6 ++++++ 3 files changed, 48 insertions(+) create mode 100644 src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp create mode 100644 src/OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp diff --git a/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp b/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp new file mode 100644 index 0000000000..c487b2677d --- /dev/null +++ b/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp @@ -0,0 +1,23 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp' +*/ + +#pragma once + +#include "OpenSHC/Commands/MappersEnum.hpp" + +// GLOBAL: STRONGHOLDCRUSADER 0x00B4C7CC +// StructResolver::Instance::instance + +namespace OpenSHC { + +using OpenSHC::Commands::MappersEnum; + +MACRO_STRUCT_RESOLVER(MappersEnum[9], false, Address::SHC_3BB0A8C1_0x00B4C7CC) DAT_ARRAY_00b4c7cc; +} // namespace OpenSHC + +MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B4C7CC); diff --git a/src/OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp b/src/OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp new file mode 100644 index 0000000000..05fb69d05b --- /dev/null +++ b/src/OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp @@ -0,0 +1,19 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp' +*/ + +#pragma once + +// GLOBAL: STRONGHOLDCRUSADER 0x00B4D0F0 +// StructResolver::Instance::instance + +namespace OpenSHC { + +MACRO_STRUCT_RESOLVER(int[9], false, Address::SHC_3BB0A8C1_0x00B4D0F0) INT_ARRAY_00b4d0f0; +} // namespace OpenSHC + +MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B4D0F0); diff --git a/src/precomp/addresses-SHC-3BB0A8C1.hpp b/src/precomp/addresses-SHC-3BB0A8C1.hpp index 6c94c19d52..367cbcc9e7 100644 --- a/src/precomp/addresses-SHC-3BB0A8C1.hpp +++ b/src/precomp/addresses-SHC-3BB0A8C1.hpp @@ -94535,6 +94535,12 @@ enum { // label: DAT_AttackWaveDurationPerAttacker // location: SHC_3BB0A8C1_0x00B4C754 = 0x00B4C754, + // label: DAT_ARRAY_00b4c7cc + // location: + // type: OpenSHC/Commands/MappersEnum[9] + SHC_3BB0A8C1_0x00B4C7CC = 0x00B4C7CC, + // type: /int[9] + SHC_3BB0A8C1_0x00B4D0F0 = 0x00B4D0F0, // type: /pointer SHC_3BB0A8C1_0x00B4D138 = 0x00B4D138, // label: DAT_UnitSelectionDefinedData From 25cfbb9c3591f70feadf17a9cdd3ccaadfeaa68e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:20 +0100 Subject: [PATCH 02/94] cmake: add /GL entries for the TroopValueState functions from #275 The same 13 entries the draft #275 uses: the callers and callees that need /GL on both sides so MSVC omits the repeated mov ecx, this. setWhetherTribeContainsAnyUnits is already reimplemented on main; it is listed because addUnitToTribe calls it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- cmake/compiler-flags-gl.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 5430b694de..5efb0e0af6 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -451,3 +451,16 @@ src/OpenSHC/Map/Units/UpdateJester.cpp src/OpenSHC/Map/Units/UpdateSlave.cpp src/OpenSHC/Map/Units/UpdateHealer.cpp src/OpenSHC/Map/Units/UpdateSpearman.cpp +src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp +src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp +src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp +src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp +src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp +src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp +src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp +src/OpenSHC/Map/Units/TribesState/setWhetherTribeContainsAnyUnits.cpp +src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp +src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp +src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp +src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp +src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp From 5f57f8d6ae5866a289e0b1f8914710c62439ab9b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:36 +0100 Subject: [PATCH 03/94] reimplement: SHC_3BB0A8C1_0x0051BC70 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/addUnitToNewTribe.cpp | 48 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp new file mode 100644 index 0000000000..e010957f7f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp @@ -0,0 +1,48 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BC70 + void TroopValueState::addUnitToNewTribe(int unitID, int attackWave, AITribeType tribeType, int playerID) + { + int tribeID; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + tribeID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribeForPlayer, DAT_TribesState::ptr)( + playerID); + } else { + int wavePlayerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; + if (!wavePlayerID) { + wavePlayerID = 2; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + wavePlayerID = 2; + } + tribeID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)( + wavePlayerID, 0); + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_6; + } + DAT_TribesState::instance.tribes[tribeID].tribeType = tribeType; + DAT_TribesState::instance.tribes[tribeID].attackWave = attackWave; + DAT_TribesState::instance.tribes[tribeID].attackInfo_someCounter1 = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)(unitID, tribeID); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 766545d302..9b59ac1bb0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45905,7 +45905,7 @@ SHC_3BB0A8C1_0x0051BA30 | 0.0% | Pending SHC_3BB0A8C1_0x0051BA90 | 0.0% | Pending -SHC_3BB0A8C1_0x0051BC70 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BC70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BD10 | 0.0% | Pending From 43df72f9bc185901f399274acbf3d28b6b34d807 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:37 +0100 Subject: [PATCH 04/94] reimplement: SHC_3BB0A8C1_0x0051D690 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../advanceAttackWaveStaging.cpp | 39 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp b/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp new file mode 100644 index 0000000000..abb1030056 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp @@ -0,0 +1,39 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D690 + void TroopValueState::advanceAttackWaveStaging(int attackID) + { + DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed = FALSE; + DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_PREPARING_SIEGE; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 0; + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::nof_fpoints_locationFinder, DAT_GameState::ptr)(); + ++DAT_TroopValueState::instance.attackInfo.someCounter1; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 2, 100000, Map::Units::STBT_0x3fb); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3fe, Map::Units::STBT_5, 0, 50); + if (DAT_TroopValueState::instance.attackInfo.casDis >= DAT_AttackInfoDefinedData::instance + .AICasDisThreshold[DAT_TroopValueState::instance.attackInfo.attacker]) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_5); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_5, Map::Units::STBT_1, 0, 40); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9b59ac1bb0..ae474e6d83 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46163,7 +46163,7 @@ SHC_3BB0A8C1_0x0051D5E0 | 0.0% | Pending SHC_3BB0A8C1_0x0051D680 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051D690 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D730 | 0.0% | Pending From 3c93ff8744e50955c5ee0fcd891a311d87f7ec46 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:37 +0100 Subject: [PATCH 05/94] reimplement: SHC_3BB0A8C1_0x00520F70 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../aiControlNonSkirmishUnitMovement.cpp | 119 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/aiControlNonSkirmishUnitMovement.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/aiControlNonSkirmishUnitMovement.cpp b/src/OpenSHC/Map/Units/TroopValueState/aiControlNonSkirmishUnitMovement.cpp new file mode 100644 index 0000000000..0c81f94995 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/aiControlNonSkirmishUnitMovement.cpp @@ -0,0 +1,119 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Audio/mss/SoundSystem.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Enums/AttackWaveStateInt.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00520F70 + void TroopValueState::aiControlNonSkirmishUnitMovement() + { + MACRO_CALL_MEMBER(TroopValueState_Func::decrementTileMap1104, this)(); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_EDITOR + || DAT_GameCore::instance.gameMode_2 == Game::GM_SKIRMISH_AND_MULTIPLAYER + || DAT_GameCore::instance.gameMode_2 == Game::GM_SIEGE_THAT) { + return; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .id + <= 0) { + MACRO_CALL_MEMBER(TroopValueState_Func::updateAttackInfoTick, this)(); + return; + } + MACRO_CALL_MEMBER(TroopValueState_Func::recountAttackTroopValue, this)(FALSE); + MACRO_CALL_MEMBER(TroopValueState_Func::computeAttackWaveTroopComposition, this)(); + if (DAT_TroopValueState::instance.attackInfo.aiTroops == 0) { + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle = 0; + } + int const holdBackTimer + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks; + if (holdBackTimer != -1000) { + if (holdBackTimer == 0) { + BOOLEnum waveComplete = TRUE; + for (int wave = 0; wave < countof(DAT_TroopValueState::instance.attackInfo.nof_tribes); ++wave) { + if (DAT_TroopValueState::instance.attackInfo.nof_tribes[wave] != 0 + && DAT_TroopValueState::instance.attackInfo.value3Array01[wave] != Map::Enums::AWS_ENDED) { + waveComplete = FALSE; + break; + } + } + if (waveComplete) { + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks = 600; + } + } else if (holdBackTimer > 0) { + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks = holdBackTimer - 1; + if (holdBackTimer - 1 == 0) { + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks = -1000; + } + } else if (holdBackTimer < 0) { + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks = holdBackTimer + 1; + } + } + DAT_TroopValueState::instance.attackInfo.value3Array01[0] = Map::Enums::AWS_GATHERING; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[0] = 0; + for (int wave = 1; wave < countof(DAT_TroopValueState::instance.attackInfo.nof_tribes); ++wave) { + DAT_TroopValueState::instance.attackInfo.attacker + = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[wave]; + if (DAT_TroopValueState::instance.attackInfo.attacker == 1) { + continue; + } + if (DAT_TroopValueState::instance.attackInfo.attacker <= 0 + && !MACRO_CALL_MEMBER(TroopValueState_Func::searchTribeWithProperties, this)(wave)) { + continue; + } + DAT_GameState::instance.playerDataArray[DAT_TroopValueState::instance.attackInfo.attacker] + .attackedPlayerID = 1; + if (DAT_TroopValueState::instance.attackInfo.nof_tribes[wave] != 0) { + DAT_TroopValueState::instance.attackInfo.index = wave; + int const waveAge = ++DAT_TroopValueState::instance.attackInfo.someIntArray2[wave - 1]; + if (DAT_TroopValueState::instance.attackInfo.lowTroopValueRelated && waveAge > 10 + && DAT_TroopValueState::instance.attackInfo.value3Array01[wave] != Map::Enums::AWS_ENDED) { + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[wave] = 0; + DAT_TroopValueState::instance.attackInfo.value3Array01[wave] = Map::Enums::AWS_ENDED; + MACRO_CALL_MEMBER( + Audio::MSS::SoundSystem_Func::handleBattleEndMusicTransition, DAT_SoundSystemState::ptr)(); + } + Map::Enums::AttackWaveStateInt const waveState + = DAT_TroopValueState::instance.attackInfo.value3Array01[wave]; + if (waveState == Map::Enums::AWS_GATHERING) { + MACRO_CALL_MEMBER(TroopValueState_Func::initializeOrAdvanceAttackWave, this)(wave); + } else if (waveState == Map::Enums::AWS_ADVANCING) { + MACRO_CALL_MEMBER(TroopValueState_Func::advanceAttackWaveStaging, this)(wave); + } else if (waveState == Map::Enums::AWS_PREPARING_SIEGE) { + MACRO_CALL_MEMBER(TroopValueState_Func::updateInProgressAttackWave, this)(wave); + } else if (waveState == Map::Enums::AWS_ASSIGNING_TARGETS) { + MACRO_CALL_MEMBER(TroopValueState_Func::executeAttackWaveTargetAssignment, this)(wave); + } else if (waveState == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { + MACRO_CALL_MEMBER(TroopValueState_Func::executeDelayedAttackWaveTargetAssignment, this)(wave); + } else if (waveState == Map::Enums::AWS_5Unk) { + } else if (waveState == Map::Enums::AWS_ENDED) { + MACRO_CALL_MEMBER(TroopValueState_Func::updateActiveAttackWaveState, this)(wave); + } + } else { + DAT_TroopValueState::instance.attackInfo.value3Array01[wave] = Map::Enums::AWS_GATHERING; + } + DAT_TroopValueState::instance.attackInfo.nof_tribes[wave] = 0; + DAT_TroopValueState::instance.attackInfo.unknownByteArray02[wave] = 0; + } + DAT_TroopValueState::instance.attackInfo.attackWaveSweepActive = 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ae474e6d83..6c68cb708b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46377,7 +46377,7 @@ SHC_3BB0A8C1_0x005205A0 | 0.0% | Pending SHC_3BB0A8C1_0x00520CD0 | 0.0% | Pending -SHC_3BB0A8C1_0x00520F70 | 0.0% | Pending +SHC_3BB0A8C1_0x00520F70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00521180 | 100.0% | Reimplemented From ec5b06bf88bf53ffa6b3a6d3bebf7f7614ae2132 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:38 +0100 Subject: [PATCH 06/94] reimplement: SHC_3BB0A8C1_0x005202B0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/aiRecomputeAttacks.cpp | 81 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp new file mode 100644 index 0000000000..e010b5dc2c --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp @@ -0,0 +1,81 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Util/Timing/Stopwatch.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnknownStopwatch.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x005202B0 + void TroopValueState::aiRecomputeAttacks(int retryCount, int attackID) + { + int const playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + MACRO_CALL_MEMBER(Util::Timing::Stopwatch_Func::start, DAT_UnknownStopwatch::ptr)(); + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].currentPlayerID_OR_attackedPlayerID_OR_one + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TileMapState::instance.AIZoneLayer), 0, DAT_TileMapState::instance.AIZoneLayer); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TileMapState::instance.AIInfoLayer), 0, DAT_TileMapState::instance.AIInfoLayer); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recountAttackTroopValue, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::computeAttackWaveTroopComposition, this)(); + int const defaultSignpostTile = DAT_GameState::instance.mapAndTime.signpostEntryData[0].tile; + int signpostTile + = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackID]] + .tile; + if (signpostTile <= 0) { + DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackID] = 0; + signpostTile = defaultSignpostTile; + } + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeAIZoneLayer, DAT_PathFindingState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, 1, + DAT_TileMapState::instance.PathConnectionLayer[signpostTile]); + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::updateWalkLayerAndAIPathCostLayer, + DAT_PathFindingState::ptr)(60, 0, 0, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackZoneSearch, this)(attackID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recomputeTargetedBuildingTilesArray, this)( + DAT_TroopValueState::instance.attackInfo.attacker); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recomputeAttackInfo, this)( + DAT_TroopValueState::instance.attackInfo.attacker, + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::computeSiegeSpotScores, this)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + DAT_TroopValueState::instance.attackInfo.attacker); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setScale3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setTown2, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailablePeopleValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableLordValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setGate2, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setWide3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setMoat3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableHighValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableArcherValueSlots, this)(TRUE); + if (DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle <= 0) { + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::calculateAttackVectorsToCampFireOfPlayer, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle = 1; + } + ++DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle; + if (1 < DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle) { + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle = 0; + } + MACRO_CALL_MEMBER(Util::Timing::Stopwatch_Func::stop, DAT_UnknownStopwatch::ptr)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6c68cb708b..fd8ab6a92e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46369,7 +46369,7 @@ SHC_3BB0A8C1_0x0051FF90 | 0.0% | Pending SHC_3BB0A8C1_0x005200A0 | 0.0% | Pending -SHC_3BB0A8C1_0x005202B0 | 0.0% | Pending +SHC_3BB0A8C1_0x005202B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00520450 | 0.0% | Pending From 4497e1794de2b75b5cb9c51b676a2b5a226f7042 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:38 +0100 Subject: [PATCH 07/94] reimplement: SHC_3BB0A8C1_0x005200A0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/aiRecomputeAttacks2.cpp | 104 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp new file mode 100644 index 0000000000..51e82433ce --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp @@ -0,0 +1,104 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Util/Timing/Stopwatch.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnknownStopwatch.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x005200A0 + void TroopValueState::aiRecomputeAttacks2(BOOLEnum scanTentPoints, int attackID) + { + int const playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + BOOLEnum canKeepReachSignpost = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::canKeepReachSignpostZone, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, playerID, attackID); + MACRO_CALL_MEMBER(Util::Timing::Stopwatch_Func::start, DAT_UnknownStopwatch::ptr)(); + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].currentPlayerID_OR_attackedPlayerID_OR_one + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TileMapState::instance.AIZoneLayer), 0, DAT_TileMapState::instance.AIZoneLayer); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TileMapState::instance.AIInfoLayer), 0, DAT_TileMapState::instance.AIInfoLayer); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recountAttackTroopValue, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::computeAttackWaveTroopComposition, this)(); + int const _defaultSignpostTile = DAT_GameState::instance.mapAndTime.signpostEntryData[0].tile; + DAT_TroopValueState::instance.attackInfo.field127625_0x42744 = 0; + int _signpostTile + = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackID]] + .tile; + if (_signpostTile <= 0) { + DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackID] = 0; + _signpostTile = _defaultSignpostTile; + } + int const zone = DAT_TileMapState::instance.PathConnectionLayer[_signpostTile]; + if (canKeepReachSignpost) { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeAIZoneLayer, + DAT_PathFindingState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, 1, zone); + } else { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeAIZoneLayer, + DAT_PathFindingState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, 0, zone); + } + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::updateWalkLayerAndAIPathCostLayer, + DAT_PathFindingState::ptr)(90, 0, 0, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackZoneSearch, this)(attackID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recomputeTargetedBuildingTilesArray, this)( + DAT_TroopValueState::instance.attackInfo.attacker); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recomputeAttackInfo, this)( + DAT_TroopValueState::instance.attackInfo.attacker, + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::computeSiegeSpotScores, this)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + DAT_TroopValueState::instance.attackInfo.attacker); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setScale3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setTown2, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailablePeopleValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableLordValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setGate2, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setWide3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setMoat3, this)(TRUE, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableHighValueSlots, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::countAvailableArcherValueSlots, this)(TRUE); + if (DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle <= 0) { + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::calculateAttackVectorsToCampFireOfPlayer, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle = 1; + } + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle++; + if (1 < DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle) { + DAT_TroopValueState::instance.attackInfo.attackVectorRecomputeThrottle = 0; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::expandAIZoneLayerStage1, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::expandAIZoneLayerStage2, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::expandAIZoneLayerStage3, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::clearAIInfoLayerOutsideStartZone, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::scanForArcherPoints, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::pruneStaleArcherPoints, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::scanForSupportPoints, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::pruneStaleSupportPoints, this)(); + if (scanTentPoints) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::scanForSiegeTentPoints, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::pruneStaleTentPoints, this)(); + } + MACRO_CALL_MEMBER(Util::Timing::Stopwatch_Func::stop, DAT_UnknownStopwatch::ptr)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fd8ab6a92e..c1717dc14d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46367,7 +46367,7 @@ SHC_3BB0A8C1_0x0051FE80 | 0.0% | Pending SHC_3BB0A8C1_0x0051FF90 | 0.0% | Pending -SHC_3BB0A8C1_0x005200A0 | 0.0% | Pending +SHC_3BB0A8C1_0x005200A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005202B0 | 100.0% | Reimplemented From 53f1737b9379f6997781999b9d0a793e2a77ec51 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:38 +0100 Subject: [PATCH 08/94] reimplement: SHC_3BB0A8C1_0x00518870 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../applyTribeBehaviorTypes.cpp | 42 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp b/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp new file mode 100644 index 0000000000..74500340c8 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp @@ -0,0 +1,42 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::Units::SomeTribeBehaviorType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00518870 + void TroopValueState::applyTribeBehaviorTypes( + SomeTribeBehaviorType tribeBehaviorType, SomeTribeBehaviorType tribeBehaviorType2, int off1, int off2) + { + int assignedCount = 0; + DAT_TroopValueState::instance.attackInfo.unknownTribeCounterRelated = assignedCount; + for (int index = 0; index < DAT_TroopValueState::instance.attackInfo.tribeIDArraySize; ++index) { + int const tribeID = DAT_TroopValueState::instance.attackInfo.tribeIDArray[index]; + if (11 <= DAT_TroopValueState::instance.attackInfo.tribeRelatedArrayValue0UpTo12[index]) { + if (tribeBehaviorType2 != 0) { + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = tribeBehaviorType2; + } + } else { + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = (index + 1) * off2 + off1; + short const someCounter1 = DAT_TroopValueState::instance.attackInfo.someCounter1; + DAT_TribesState::instance.tribes[tribeID].someCounter1 = assignedCount; + ++assignedCount; + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = tribeBehaviorType; + DAT_TribesState::instance.tribes[tribeID].attackInfo_someCounter1 = someCounter1; + DAT_TroopValueState::instance.attackInfo.unknownTribeCounterRelated = assignedCount; + } + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c1717dc14d..b4dc6b7a5c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45751,7 +45751,7 @@ SHC_3BB0A8C1_0x005185C0 | 0.0% | Pending SHC_3BB0A8C1_0x00518690 | 0.0% | Pending -SHC_3BB0A8C1_0x00518870 | 0.0% | Pending +SHC_3BB0A8C1_0x00518870 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005188A0 | 0.0% | Pending From c6cf0cb358ad940b594d7a6d51b8eec182c6fb91 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:39 +0100 Subject: [PATCH 09/94] reimplement: SHC_3BB0A8C1_0x00518A10 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../assignBehaviorTypeAndLinkSupportTribe.cpp | 85 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp new file mode 100644 index 0000000000..6a05eb9cd2 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp @@ -0,0 +1,85 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" + +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00518A10 + void TroopValueState::assignBehaviorTypeAndLinkSupportTribe(int attackWave, int playerID, + SomeTribeBehaviorType behaviorType, undefined4 updateLimitBase, undefined4 updateLimitStep) + { + if (playerID <= 0) { + playerID = 2; + } + for (int _tribeID = 1; _tribeID < countof(DAT_TribesState::instance.tribes); ++_tribeID) { + if (DAT_TribesState::instance.tribes[_tribeID].owner == playerID) { + DAT_TribesState::instance.tribes[_tribeID].tribeID = 0; + } + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.tribeIDArraySize; ++i) { + int _tribeID = DAT_TroopValueState::instance.attackInfo.tribeIDArray[i]; + // The original stops at the first tribe that is too far along or still linked; it does not skip it. + if (11 <= DAT_TroopValueState::instance.attackInfo.tribeRelatedArrayValue0UpTo12[i]) { + return; + } + int _supportTribeID = (int)DAT_TribesState::instance.tribes[_tribeID].supportTribeID; + if (_supportTribeID + && DAT_TribesState::instance.tribes[_tribeID].uid2 + == DAT_TribesState::instance.tribes[_supportTribeID].uid) { + return; + } + // The original stores the update limit first, and both searches jump straight to the link. + DAT_TribesState::instance.tribes[_tribeID].someUpdateUpperLimit + = ((short)i + 1) * (short)updateLimitStep + (short)updateLimitBase; + DAT_TribesState::instance.tribes[_tribeID].tribeBehaviorType = (undefined2)behaviorType; + DAT_TribesState::instance.tribes[_tribeID].attackInfo_someCounter1 + = (short)DAT_TroopValueState::instance.attackInfo.someCounter1; + DAT_TribesState::instance.tribes[_tribeID].unknownAttackRelatedUpdateCounter = 0; + for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); + ++_supportTribeID) { + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 0 + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 3 + && DAT_TribesState::instance.tribes[_supportTribeID].owner + == DAT_TribesState::instance.tribes[_tribeID].owner + && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 + && (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_CATAPULT + || (DAT_TribesState::instance.tribes[_supportTribeID].tribeType + == AI::Tribes::AITT_TREBUCHET))) { + goto link; + } + } + for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); + ++_supportTribeID) { + if (DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] + == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { + break; + } + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 0 + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 3 + && DAT_TribesState::instance.tribes[_supportTribeID].owner + == DAT_TribesState::instance.tribes[_tribeID].owner + && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 + && (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_ARCHERS + || (DAT_TribesState::instance.tribes[_supportTribeID].tribeType + == AI::Tribes::AITT_CROSSBOWMEN))) { + goto link; + } + } + continue; + link: + DAT_TribesState::instance.tribes[_tribeID].supportTribeID = (short)_supportTribeID; + DAT_TribesState::instance.tribes[_tribeID].uid2 = DAT_TribesState::instance.tribes[_supportTribeID].uid; + DAT_TribesState::instance.tribes[_supportTribeID].tribeID = (short)_tribeID; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b4dc6b7a5c..cd31615875 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45757,7 +45757,7 @@ SHC_3BB0A8C1_0x005188A0 | 0.0% | Pending SHC_3BB0A8C1_0x00518930 | 0.0% | Pending -SHC_3BB0A8C1_0x00518A10 | 0.0% | Pending +SHC_3BB0A8C1_0x00518A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00518BB0 | 0.0% | Pending From 169edc1835b9cbfe8597a39824f8f2f0f9a0b3a2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:39 +0100 Subject: [PATCH 10/94] reimplement: SHC_3BB0A8C1_0x0051CCB0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...acemenAndKnightsNotFromPlayer1ToTribes.cpp | 132 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp new file mode 100644 index 0000000000..26f794f1a1 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp @@ -0,0 +1,132 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051CCB0 + void TroopValueState::assignMacemenAndKnightsNotFromPlayer1ToTribes() + { + int const playerID = DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID; + int macemenCount = 0; + int knightCount = 0; + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; unitID++) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_INVISIBLE + || !MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[unitID].owner)) { + continue; + } + if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_MACE) { + macemenCount++; + } else if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_KNIGHT) { + knightCount++; + } else { + continue; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::removeUnitFromTribe, DAT_TribesState::ptr)( + unitID, DAT_UnitsState::instance.units[unitID].tribeID); + } + int macemenLimit; + if (macemenCount > 40) { + macemenLimit = 10; + } else if (macemenCount > 20) { + macemenLimit = 8; + } else { + macemenLimit = 5; + } + int knightLimit; + if (knightCount > 18) { + knightLimit = 6; + } else if (knightCount > 12) { + knightLimit = 4; + } else { + knightLimit = 2; + } + if (macemenCount <= 0) { + DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 0; + } else if (macemenCount <= macemenLimit) { + DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 1; + } else { + DAT_TroopValueState::instance.attackInfo.macemenTribeCount = macemenCount / macemenLimit + 1; + if (DAT_TroopValueState::instance.attackInfo.macemenTribeCount > 100) { + DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 100; + } + } + if (knightCount <= 0) { + DAT_TroopValueState::instance.attackInfo.knightTribeCount = 0; + } else if (knightCount <= knightLimit) { + DAT_TroopValueState::instance.attackInfo.knightTribeCount = 1; + } else { + DAT_TroopValueState::instance.attackInfo.knightTribeCount = knightCount / knightLimit + 1; + if (DAT_TroopValueState::instance.attackInfo.knightTribeCount > 100) { + DAT_TroopValueState::instance.attackInfo.knightTribeCount = 100; + } + } + int macemenUnitID = 0; + int tribeIndex; + for (tribeIndex = 0; tribeIndex < DAT_TroopValueState::instance.attackInfo.macemenTribeCount; + tribeIndex++) { + int const tribeID + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(playerID, 0); + DAT_TroopValueState::instance.attackInfo.macemenTribeArray[tribeIndex] = tribeID; + DAT_TribesState::instance.tribes[tribeID].tribeType = AI::Tribes::AITT_MACEMEN; + for (int assigned = 0; assigned < macemenLimit;) { + macemenUnitID++; + if (DAT_UnitsState::instance.units[macemenUnitID].logicalState != Map::Units::ULS_INVISIBLE + && MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[macemenUnitID].owner) + && DAT_UnitsState::instance.units[macemenUnitID].unitType == Map::Units::UT_E_MACE) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( + macemenUnitID, tribeID); + macemenCount--; + if (macemenCount <= 0) { + break; + } + assigned++; + } + } + if (macemenCount <= 0) { + break; + } + } + int knightUnitID = 0; + for (tribeIndex = 0; tribeIndex < DAT_TroopValueState::instance.attackInfo.knightTribeCount; tribeIndex++) { + int const tribeID + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(playerID, 0); + DAT_TroopValueState::instance.attackInfo.knightTribeArray[tribeIndex] = tribeID; + DAT_TribesState::instance.tribes[tribeID].tribeType = AI::Tribes::AITT_KNIGHTS; + for (int assigned = 0; assigned < knightLimit;) { + knightUnitID++; + if (DAT_UnitsState::instance.units[knightUnitID].logicalState != Map::Units::ULS_INVISIBLE + && MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[knightUnitID].owner) + && DAT_UnitsState::instance.units[knightUnitID].unitType == Map::Units::UT_E_KNIGHT) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( + knightUnitID, tribeID); + knightCount--; + if (knightCount <= 0) { + return; + } + assigned++; + } + } + if (knightCount <= 0) { + break; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index cd31615875..d1f3c8ce15 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46139,7 +46139,7 @@ SHC_3BB0A8C1_0x0051CBD0 | 0.0% | Pending SHC_3BB0A8C1_0x0051CC00 | 0.0% | Pending -SHC_3BB0A8C1_0x0051CCB0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051CCB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CE50 | 0.0% | Pending From dd2d453cb76c039f25104bd8514dc3eb6517ac71 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:40 +0100 Subject: [PATCH 11/94] reimplement: SHC_3BB0A8C1_0x0051B190 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../assignTribeToSupportPoint.cpp | 42 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp new file mode 100644 index 0000000000..544e0062e0 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp @@ -0,0 +1,42 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B190 + int TroopValueState::assignTribeToSupportPoint(int x, int y, int tribeID) + { + int const pointIndex = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findSupportPointIndex, + DAT_PathFindingState::ptr)(200, x, y, tribeID); + if (pointIndex) { + short const oldPointIndex = DAT_TribesState::instance.tribes[tribeID].supportPointIndex; + DAT_TribesState::instance.tribes[tribeID].oldSupportPointIndex = oldPointIndex; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[oldPointIndex].tribeID = 0; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[oldPointIndex].tribeUID = 0; + DAT_TribesState::instance.tribes[tribeID].supportPointIndex = pointIndex; + int const pointY = DAT_TroopValueState::instance.attackInfo.supportPointsArray[pointIndex].y; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[pointIndex].tribeUID + = DAT_TribesState::instance.tribes[tribeID].uid; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[pointIndex].tribeID = tribeID; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[pointIndex].three = 3; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + DAT_TroopValueState::instance.attackInfo.supportPointsArray[pointIndex].x, pointY, 0, 0, + Map::Units::Instructions::UMSE_0); + return pointIndex; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d1f3c8ce15..df76164370 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45865,7 +45865,7 @@ SHC_3BB0A8C1_0x0051B110 | 0.0% | Pending SHC_3BB0A8C1_0x0051B120 | 0.0% | Pending -SHC_3BB0A8C1_0x0051B190 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B190 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B240 | 0.0% | Pending From 7aed594481c0095c6d173c70ece4db4e64509a82 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:40 +0100 Subject: [PATCH 12/94] reimplement: SHC_3BB0A8C1_0x00519690 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../buildRallyPointsFromSiegeUnits.cpp | 64 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp b/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp new file mode 100644 index 0000000000..19587e162a --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp @@ -0,0 +1,64 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00519690 + void TroopValueState::buildRallyPointsFromSiegeUnits(int tribeID) + { + DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; + for (int siegeTribeID = 1; siegeTribeID < countof(DAT_TribesState::instance.tribes); ++siegeTribeID) { + if (!DAT_TribesState::instance.tribes[siegeTribeID].tribeState) { + continue; + } + BOOLEnum const fullIDIsMinus1 + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::isFullIDEqualsToMinus1, DAT_GameState::ptr)( + DAT_TribesState::instance.tribes[siegeTribeID].owner); + if (!fullIDIsMinus1) { + continue; + } + if (DAT_TribesState::instance.tribes[siegeTribeID].tribeType != AI::Tribes::AITT_CATAPULT + && DAT_TribesState::instance.tribes[siegeTribeID].tribeType != AI::Tribes::AITT_TREBUCHET) { + continue; + } + int const unitID = DAT_TribesState::instance.tribes[siegeTribeID].selectionTargetUnitID; + if (DAT_UnitsState::instance.units[unitID].stoneAmmunition <= 0) { + continue; + } + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeNextRallyPointDestination, + DAT_PathFindingState::ptr)( + -1, DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y); + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][0] + = DAT_PathFindingState::instance.ALG_ResultX; + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][1] + = DAT_PathFindingState::instance.ALG_ResultY; + ++DAT_TribesState::instance.tribes[tribeID].rallyPointCount; + } + if (DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex < 0) { + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; + } + if (DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex + >= DAT_TribesState::instance.tribes[tribeID].rallyPointCount) { + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index df76164370..593bdba78d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45765,7 +45765,7 @@ SHC_3BB0A8C1_0x00518C50 | 0.0% | Pending SHC_3BB0A8C1_0x00519310 | 0.0% | Pending -SHC_3BB0A8C1_0x00519690 | 0.0% | Pending +SHC_3BB0A8C1_0x00519690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519790 | 0.0% | Pending From 18b0f63f01854a3b750ab5a0af19c869e004898f Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:41 +0100 Subject: [PATCH 13/94] reimplement: SHC_3BB0A8C1_0x0051AB60 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...calculateArch2ClosestToTribeTargetUnit.cpp | 58 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp new file mode 100644 index 0000000000..7ec2573cf8 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp @@ -0,0 +1,58 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AB60 + int TroopValueState::calculateArch2ClosestToTribeTargetUnit(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int minDistance = 1000; + int bestIndex = -1; + int i = 0; + if (0 < DAT_TroopValueState::instance.attackInfo.arch2) { + for (; i < DAT_TroopValueState::instance.attackInfo.arch2; ++i) { + if (DAT_BuildingsState::instance + .buildings[DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[i].buildingID] + .unknownCounterTo10000_0x2b4 + >= 9999 + || DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[i].unitID) { + continue; + } + int const fromYPosition = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[i].tile2]; + int const fromXPosition = DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[bestIndex].unitID = unitID; + return DAT_TroopValueState::instance.attackInfo.arch2ValuesArray[bestIndex].tile2; + } + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 593bdba78d..d96498e0fb 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45835,7 +45835,7 @@ SHC_3BB0A8C1_0x0051AA40 | 0.0% | Pending SHC_3BB0A8C1_0x0051AB10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051AB60 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AB60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051ABB0 | 0.0% | Pending From acd0914ab9b3e00bccd1c5cc3e60634652b1b2bd Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:41 +0100 Subject: [PATCH 14/94] reimplement: SHC_3BB0A8C1_0x0051A9F0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...alculateHigh2ClostestToTribeTargetUnit.cpp | 59 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp new file mode 100644 index 0000000000..f0858b391a --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp @@ -0,0 +1,59 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A9F0 + int TroopValueState::calculateHigh2ClostestToTribeTargetUnit(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int minDistance = 1000; + int bestIndex = -1; + int i = 0; + if (0 < DAT_TroopValueState::instance.attackInfo.high2) { + for (; i < DAT_TroopValueState::instance.attackInfo.high2; ++i) { + if (DAT_BuildingsState::instance + .buildings[DAT_TroopValueState::instance.attackInfo.high2ValuesArray[i].buildingID] + .unknownCounterTo10000_0x2b4 + >= 9999 + || DAT_TroopValueState::instance.attackInfo.high2ValuesArray[i].unitID != 0) { + continue; + } + int const fromYPosition = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.high2ValuesArray[i].tile2]; + int const fromXPosition = DAT_TroopValueState::instance.attackInfo.high2ValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.high2ValuesArray[i].tile; + bestIndex = i; + } + } + if (bestIndex <= -1) { + return 0; + } + DAT_TroopValueState::instance.attackInfo.high2ValuesArray[bestIndex].unitID = unitID; + return DAT_TroopValueState::instance.attackInfo.high2ValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d96498e0fb..d4d63b6b65 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45829,7 +45829,7 @@ SHC_3BB0A8C1_0x0051A920 | 0.0% | Pending SHC_3BB0A8C1_0x0051A9A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A9F0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A9F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AA40 | 0.0% | Pending From cdef502f8b08d6f2124b971f3511aa71c606a0a9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:41 +0100 Subject: [PATCH 15/94] reimplement: SHC_3BB0A8C1_0x0051A780 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../calculateTile2MoatValueClosestToUnit.cpp | 56 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp new file mode 100644 index 0000000000..4ddea32d03 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp @@ -0,0 +1,56 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A780 + int TroopValueState::calculateTile2MoatValueClosestToUnit(int unitID) + { + int const owner = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 100000; + int bestIndex = -1; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moat2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].score >= 5999 + || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].unitID != 0) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + int const distance = DAT_DirectionAlgorithmState::instance.distanceHigh + + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].score * 8; + DAT_DirectionAlgorithmState::instance.distanceHigh = distance; + if (distance < minDistance) { + minDistance = distance; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[bestIndex].unitID + = unitID; + return DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d4d63b6b65..f8eb8bbc33 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45821,7 +45821,7 @@ SHC_3BB0A8C1_0x0051A630 | 0.0% | Pending SHC_3BB0A8C1_0x0051A720 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A780 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A780 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A8A0 | 0.0% | Pending From 0df274b9ac66b9bc84f2cf521fadca2374b39080 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:42 +0100 Subject: [PATCH 16/94] reimplement: SHC_3BB0A8C1_0x0051A140 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../calculateTile2PeoplValueClosestToUnit.cpp | 52 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp new file mode 100644 index 0000000000..837966ce7c --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp @@ -0,0 +1,52 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A140 + int TroopValueState::calculateTile2PeoplValueClosestToUnit(int unitID) + { + int minDistance = 1000; + int bestIndex = -1; + int i = 0; + if (0 < DAT_TroopValueState::instance.attackInfo.people2) { + for (; i < DAT_TroopValueState::instance.attackInfo.people2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.peopleValuesArray[i].unitID != 0) { + continue; + } + int const fromYPosition = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.peopleValuesArray[i].tile2]; + int const fromXPosition = DAT_TroopValueState::instance.attackInfo.peopleValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.peopleValuesArray[i].tile; + bestIndex = i; + } + } + if (bestIndex <= -1) { + return 0; + } + DAT_TroopValueState::instance.attackInfo.peopleValuesArray[bestIndex].unitID = unitID; + return DAT_TroopValueState::instance.attackInfo.peopleValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f8eb8bbc33..117f541837 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45803,7 +45803,7 @@ SHC_3BB0A8C1_0x0051A0C0 | 0.0% | Pending SHC_3BB0A8C1_0x0051A100 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A140 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A220 | 0.0% | Pending From 0f1ce8c2bf04e7c2ebcaf1ee1314b84f6a0decd7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:42 +0100 Subject: [PATCH 17/94] reimplement: SHC_3BB0A8C1_0x0051AFF0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../claimArcherAttackPoint.cpp | 50 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp new file mode 100644 index 0000000000..26345b9fc7 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp @@ -0,0 +1,50 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AFF0 + int TroopValueState::claimArcherAttackPoint(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int pointIndex = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::tribeHasActiveLaddermanUnit, DAT_TribesState::ptr)(tribeID); + if (!pointIndex) { + pointIndex = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findArcherRelatedAttackInfoIndex, + DAT_PathFindingState::ptr)( + 200, DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, tribeID); + if (!pointIndex) { + return 0; + } + short const oldPointIndex = DAT_TribesState::instance.tribes[tribeID].archerRelated; + int const tribeUID = DAT_TribesState::instance.tribes[tribeID].uid; + DAT_TribesState::instance.tribes[tribeID].archerRelated2 = oldPointIndex; + DAT_TroopValueState::instance.attackInfo.archerPointArray[oldPointIndex].tribeID = 0; + DAT_TroopValueState::instance.attackInfo.archerPointArray[oldPointIndex].tribeUID = 0; + int const pointY = DAT_TroopValueState::instance.attackInfo.archerPointArray[pointIndex].y; + DAT_TroopValueState::instance.attackInfo.archerPointArray[pointIndex].tribeUID = tribeUID; + int const pointX = DAT_TroopValueState::instance.attackInfo.archerPointArray[pointIndex].x; + DAT_TribesState::instance.tribes[tribeID].archerRelated = pointIndex; + DAT_TroopValueState::instance.attackInfo.archerPointArray[pointIndex].tribeID = tribeID; + DAT_TroopValueState::instance.attackInfo.archerPointArray[pointIndex].claimCooldown = 3; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, pointX, pointY, 0, 0, Map::Units::Instructions::UMSE_0); + return pointIndex; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 117f541837..4dbc1278d5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45857,7 +45857,7 @@ SHC_3BB0A8C1_0x0051AF70 | 0.0% | Pending SHC_3BB0A8C1_0x0051AF80 | 0.0% | Pending -SHC_3BB0A8C1_0x0051AFF0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AFF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B0C0 | 0.0% | Pending From 2d38386e65a364c55ce8208e02746cb8d2e9464b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:43 +0100 Subject: [PATCH 18/94] reimplement: SHC_3BB0A8C1_0x0051CA50 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../collectArcherUnitsByLocation.cpp | 82 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp b/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp new file mode 100644 index 0000000000..0c809e5615 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp @@ -0,0 +1,82 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051CA50 + void TroopValueState::collectArcherUnitsByLocation() + { + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2b57c), 0, + DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2b57c); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.tileArray_0x2bd50), 0, + DAT_TroopValueState::instance.attackInfo.tileArray_0x2bd50); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2c070), 0, + DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2c070); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.uidArray_0x2c200), 0, + DAT_TroopValueState::instance.attackInfo.uidArray_0x2c200); + DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c = 0; + DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520 = 0; + for (int _unitID = 1; _unitID < DAT_UnitsState::instance.maxUnitCount; ++_unitID) { + if (DAT_UnitsState::instance.units[_unitID].logicalState != Map::Units::ULS_INVISIBLE + && MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[_unitID].owner) + && (DAT_UnitsState::instance.units[_unitID].unitType == Map::Units::UT_E_ARCHER + || DAT_UnitsState::instance.units[_unitID].unitType == Map::Units::UT_E_XBOW)) { + if (DAT_TileMapState::instance.LogicLayer[DAT_UnitsState::instance.units[_unitID].tile] + & (L_KEEP_NON_MANOR_HOUSE | L_WALL_OR_GATEHOUSE)) { + if (DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520 + < countof(DAT_TroopValueState::instance.attackInfo.tileArray_0x2bd50)) { + int const _tribeID = DAT_UnitsState::instance.units[_unitID].tribeID; + if (_tribeID == 0 || DAT_TribesState::instance.tribes[_tribeID].isRallyingUnk == 0) { + DAT_TroopValueState::instance.attackInfo + .tileArray_0x2bd50[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520] + = DAT_UnitsState::instance.units[_unitID].tile; + DAT_TroopValueState::instance.attackInfo + .uidArray_0x2c200[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520] + = DAT_UnitsState::instance.units[_unitID].uid; + DAT_TroopValueState::instance.attackInfo + .unitIDArray_0x2c070[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520] + = (short)_unitID; + DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520++; + } + } + } else { + if (DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c + < countof(DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2b57c)) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::removeUnitFromTribe, DAT_TribesState::ptr)( + _unitID, DAT_UnitsState::instance.units[_unitID].tribeID); + DAT_TroopValueState::instance.attackInfo + .unitIDArray_0x2b57c[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c] + = (short)_unitID; + DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c++; + } + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4dbc1278d5..6618f262ce 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46131,7 +46131,7 @@ SHC_3BB0A8C1_0x0051C7F0 | 0.0% | Pending SHC_3BB0A8C1_0x0051C800 | 0.0% | Pending -SHC_3BB0A8C1_0x0051CA50 | 0.0% | Pending +SHC_3BB0A8C1_0x0051CA50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CAE0 | 0.0% | Pending From 29f75935ce3ef1dbf7abcd92de16650fcb632ae5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:43 +0100 Subject: [PATCH 19/94] reimplement: SHC_3BB0A8C1_0x0051C800 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../commandUnitsToMoveToKeep.cpp | 117 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp new file mode 100644 index 0000000000..72e0e7c112 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp @@ -0,0 +1,117 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::Buildings::BuildingTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051C800 + void TroopValueState::commandUnitsToMoveToKeep() + { + uint y1; + uint x1; + int _playerID = DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID; + uint _keep = DAT_GameState::instance.playerDataArray[_playerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .id; + if (0 < (int)_keep) { + BuildingTypeShort _buildingType = DAT_BuildingsState::instance.buildings[_keep].buildingType; + if (_buildingType == Map::Buildings::BT_MANORHOUSE) { + x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 8; + } else if (_buildingType == Map::Buildings::BT_STONEKEEP) { + x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 3; + } else if (_buildingType == Map::Buildings::BT_STRONGHOLD) { + x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 3; + } else if (_buildingType == Map::Buildings::BT_KEEPFOUR) { + x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 4; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 4; + } else if (_buildingType == Map::Buildings::BT_KEEPFIVE) { + x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 5; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 5; + } else { + return; + } + int _swordsTribe = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID, 0); + DAT_TribesState::instance.tribes[_swordsTribe].tribeType = AI::Tribes::AITT_SWORDSMEN; + int _archersTribe + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(_playerID, 0); + DAT_TribesState::instance.tribes[_archersTribe].tribeType = AI::Tribes::AITT_ARCHERS; + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_INVISIBLE) { + continue; + } + if (!MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[unitID].owner)) { + continue; + } + if (DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_MACE + && DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_SWORD + && DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_SPEAR) { + if (DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_ARCHER + && DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_XBOW) { + continue; + } + if (DAT_TileMapState::instance.LogicLayer[DAT_UnitsState::instance.units[unitID].tile] + & 0x10000100U) { + continue; + } + } + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, x1, y1); + if (DAT_DirectionAlgorithmState::instance.distanceHigh >= 30) { + continue; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::removeUnitFromTribe, DAT_TribesState::ptr)( + unitID, DAT_UnitsState::instance.units[unitID].tribeID); + if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_SWORD) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( + unitID, _swordsTribe); + } else { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( + unitID, _archersTribe); + } + } + if (DAT_TribesState::instance.tribes[_swordsTribe].size <= 0) { + DAT_TribesState::instance.tribes[_swordsTribe].tribeState = 3; + } else { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + _swordsTribe, x1, y1 + 1, 0, 0, Map::Units::Instructions::UMSE_0); + } + if (DAT_TribesState::instance.tribes[_archersTribe].size <= 0) { + DAT_TribesState::instance.tribes[_archersTribe].tribeState = 3; + } else { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + _archersTribe, x1, y1, 0, 0, Map::Units::Instructions::UMSE_0); + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6618f262ce..23d32f2948 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46129,7 +46129,7 @@ SHC_3BB0A8C1_0x0051C7EF | 0.0% | Pending SHC_3BB0A8C1_0x0051C7F0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051C800 | 0.0% | Pending +SHC_3BB0A8C1_0x0051C800 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CA50 | 100.0% | Reimplemented From fba5476c26f6e0f54c7a2392e34390e5aa32d6d2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:44 +0100 Subject: [PATCH 20/94] reimplement: SHC_3BB0A8C1_0x00519310 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../computeAttackWaveTroopComposition.cpp | 204 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/computeAttackWaveTroopComposition.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/computeAttackWaveTroopComposition.cpp b/src/OpenSHC/Map/Units/TroopValueState/computeAttackWaveTroopComposition.cpp new file mode 100644 index 0000000000..53e1d74613 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/computeAttackWaveTroopComposition.cpp @@ -0,0 +1,204 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519310 + void TroopValueState::computeAttackWaveTroopComposition() + { + if (DAT_TroopValueState::instance.attackInfo.attackTribeCount < 6) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes + = DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen; + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 1; + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 1; + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 1; + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 1; + DAT_TroopValueState::instance.attackInfo.maxLadderTribes = 0; + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 0; + DAT_TroopValueState::instance.attackInfo.maxEngineerTribes + = DAT_TroopValueState::instance.attackInfo.engineers; + } else if (DAT_TroopValueState::instance.attackInfo.attackTribeCount < 10) { + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 0) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 0; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 1) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 1; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen >= 3) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 2; + } else { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes + = DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen - 1; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore != 0) { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 2; + } else { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 1; + } + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen > 4) { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore != 0) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 1; + } else { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 0; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 0) { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 1; + } else { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 0; + } + DAT_TroopValueState::instance.attackInfo.maxLadderTribes = 2; + if (DAT_TroopValueState::instance.attackInfo.laddermen <= 2) { + DAT_TroopValueState::instance.attackInfo.maxLadderTribes + = DAT_TroopValueState::instance.attackInfo.laddermen; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore != 0) { + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 1; + } else { + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 0; + } + DAT_TroopValueState::instance.attackInfo.maxEngineerTribes + = DAT_TroopValueState::instance.attackInfo.engineers; + } else if (DAT_TroopValueState::instance.attackInfo.attackTribeCount < 20) { + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 0) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 0; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 1) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 1; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen >= 4) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes + = DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen - 1; + } + DAT_TroopValueState::instance.attackInfo.maxLadderTribes = 4; + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 1) { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen > 6) { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 4; + } else { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 3; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 4) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 0) { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 2; + } else { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 1; + } + if (DAT_TroopValueState::instance.attackInfo.laddermen <= 4) { + DAT_TroopValueState::instance.attackInfo.maxLadderTribes + = DAT_TroopValueState::instance.attackInfo.laddermen; + } + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 1; + DAT_TroopValueState::instance.attackInfo.maxEngineerTribes + = DAT_TroopValueState::instance.attackInfo.engineers; + } else if (DAT_TroopValueState::instance.attackInfo.attackTribeCount < 30) { + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 0) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 0; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 1) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 1; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen >= 4) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes + = DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen - 1; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 4) { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 4; + } else { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 10) { + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen > 5) { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 4; + } else { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 2; + } + } else { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 6; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 8) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 5; + } else if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 4) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 4; + } else { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 2; + } + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 2; + DAT_TroopValueState::instance.attackInfo.maxLadderTribes = 5; + if (DAT_TroopValueState::instance.attackInfo.laddermen <= 5) { + DAT_TroopValueState::instance.attackInfo.maxLadderTribes + = DAT_TroopValueState::instance.attackInfo.laddermen; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 4) { + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 2; + } else { + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 1; + } + DAT_TroopValueState::instance.attackInfo.maxEngineerTribes + = DAT_TroopValueState::instance.attackInfo.engineers; + } else { + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 0) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 0; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen <= 1) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 1; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen >= 5) { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes = 4; + } else { + DAT_TroopValueState::instance.attackInfo.maxWallScaleTribes + = DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen - 1; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 5) { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 5; + } else { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen > 12) { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 8; + } else if (DAT_TroopValueState::instance.attackInfo.spearmenAndMacemen > 6) { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 5; + } else { + DAT_TroopValueState::instance.attackInfo.maxMoatAttackTribes = 3; + } + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 10) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 6; + } else if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 8) { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 5; + } else { + DAT_TroopValueState::instance.attackInfo.maxPeopleAttackTribes = 3; + } + DAT_TroopValueState::instance.attackInfo.maxLadderTribes = 6; + if (DAT_TroopValueState::instance.attackInfo.pikemenSwordsmenAndMore > 0) { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 3; + } else { + DAT_TroopValueState::instance.attackInfo.maxGateAttackTribes = 2; + } + if (DAT_TroopValueState::instance.attackInfo.laddermen <= 6) { + DAT_TroopValueState::instance.attackInfo.maxLadderTribes + = DAT_TroopValueState::instance.attackInfo.laddermen; + } + DAT_TroopValueState::instance.attackInfo.maxTunnelerTribes = 2; + DAT_TroopValueState::instance.attackInfo.maxEngineerTribes + = DAT_TroopValueState::instance.attackInfo.engineers; + } + if (DAT_TroopValueState::instance.attackInfo.assassinTribeCount + > DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes) { + DAT_TroopValueState::instance.attackInfo.maxTownAttackTribes + = DAT_TroopValueState::instance.attackInfo.assassinTribeCount; + } + DAT_TroopValueState::instance.attackInfo.maxLordAttackTribes = 3; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 23d32f2948..007ef725c9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45763,7 +45763,7 @@ SHC_3BB0A8C1_0x00518BB0 | 0.0% | Pending SHC_3BB0A8C1_0x00518C50 | 0.0% | Pending -SHC_3BB0A8C1_0x00519310 | 0.0% | Pending +SHC_3BB0A8C1_0x00519310 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519690 | 100.0% | Reimplemented From 7aae0d656b8f6ad8bfaf2a7c21da15f1f188244d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:44 +0100 Subject: [PATCH 21/94] reimplement: SHC_3BB0A8C1_0x00519990 96.43% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../computeSiegeSpotScores.cpp | 186 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp b/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp new file mode 100644 index 0000000000..0acac15b94 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp @@ -0,0 +1,186 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519990 + void TroopValueState::computeSiegeSpotScores(int attackedPlayerID, int attackingPlayerID) + { + if (DAT_GameState::instance.playerDataArray[attackedPlayerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .id + == 0) { + return; + } + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].someMinimumDistance = 10000; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hack2; ++i) { + int const cost + = DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[attackedPlayerID][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .hackValuesArray[i] + .tile]; + if (cost + < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].someMinimumDistance) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].someMinimumDistance + = cost; + } + } + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hack3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hack2; ++i) { + int const tile = DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] + .hackValuesArray[i] + .tile; + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const cost = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[attackedPlayerID][tile]; + if (MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadderInRightDirection, + DAT_UnitsState::ptr)(tile, y)) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hackValuesArray[i].score + = 9999; + } else if (cost <= 0) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hackValuesArray[i].score + = 9999; + } else { + int const minimumDistance + = DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] + .someMinimumDistance; + if (minimumDistance >= 50) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] + .hackValuesArray[i] + .score = 9999; + } else if (cost >= minimumDistance + 15) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] + .hackValuesArray[i] + .score = 9999; + } else { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hack3++; + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] + .hackValuesArray[i] + .score = cost; + } + } + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].scale2; + ++i) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].scaleValuesArray[i].score + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .scaleValuesArray[i] + .tile] + > 5 + ? 9999 + : 0; + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].town2; ++i) { + int const cost + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .townValuesArray[i] + .tile]; + if (cost <= 0) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].townValuesArray[i].score + = 100; + } else { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].townValuesArray[i].score + = cost; + } + } + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].field22_0x3ea4 = 10000; + for (int i = 0; + i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].some1000ArrayIndex_2; + ++i) { + int const cost + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .gateValuesArray[i] + .tile]; + if (cost < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].field22_0x3ea4) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].field22_0x3ea4 = cost; + } + } + for (int i = 0; + i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].some1000ArrayIndex_2; + ++i) { + int const cost + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .gateValuesArray[i] + .tile]; + if (DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].field22_0x3ea4 > 10) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].gateValuesArray[i].score + = cost > 20 ? 9999 : 0; + } else { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].gateValuesArray[i].score + = cost > 10 ? 9999 : 0; + } + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].wide2; ++i) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].wideValuesArray[i].score + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .wideValuesArray[i] + .tile] + > 5 + ? 9999 + : 0; + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moat2; ++i) { + int const cost + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one][DAT_TroopValueState::instance.attackInfo + .playerInfo[attackingPlayerID - 1] + .moatValuesArray[i] + .tile]; + if (cost <= 0) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = 9999; + } else if (cost <= 10) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost; + } else if (cost <= 15) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost * 2; + } else if (cost <= 20) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost * 3; + } else if (cost <= 25) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost * 4; + } else if (cost <= 50) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost * 5; + } else if (cost <= 70) { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = cost * 6; + } else { + DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score + = 9999; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 007ef725c9..5a7ba29f57 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45775,7 +45775,7 @@ SHC_3BB0A8C1_0x005198C0 | 0.0% | Pending SHC_3BB0A8C1_0x00519960 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00519990 | 0.0% | Pending +SHC_3BB0A8C1_0x00519990 | 96.4% | Register allocation differs SHC_3BB0A8C1_0x005199E0 | 0.0% | Pending From d45bdcaf351994c3bc555c26eeb3b48e67e3bc61 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:44 +0100 Subject: [PATCH 22/94] reimplement: SHC_3BB0A8C1_0x0051A0C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../countAvailablePeopleValueSlots.cpp | 24 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp b/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp new file mode 100644 index 0000000000..63df8a10b6 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp @@ -0,0 +1,24 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A0C0 + void TroopValueState::countAvailablePeopleValueSlots(BOOLEnum includeOccupied) + { + DAT_TroopValueState::instance.attackInfo.people3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.people2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.peopleValuesArray[i].unitID == 0 || includeOccupied) { + ++DAT_TroopValueState::instance.attackInfo.people3; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5a7ba29f57..9ce0aac371 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45799,7 +45799,7 @@ SHC_3BB0A8C1_0x00519F50 | 0.0% | Pending SHC_3BB0A8C1_0x00519FB0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A0C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A0C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A100 | 100.0% | Reimplemented From 436573f331b8677fe5e26b63bbd7c9dfa47f0684 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:45 +0100 Subject: [PATCH 23/94] reimplement: SHC_3BB0A8C1_0x0051D2B0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../decideAndExecuteTribeAttackAction.cpp | 79 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp b/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp new file mode 100644 index 0000000000..762d0c3e74 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp @@ -0,0 +1,79 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D2B0 + void TroopValueState::decideAndExecuteTribeAttackAction(int tribeID) + { + int const targetUnitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int const enemyBuildingID + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findNearestEnemyBuildingWithinDistance, + DAT_PathFindingState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, 15); + int const enemyUnitID + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findNearestEnemyUnitWithinDistance, + DAT_PathFindingState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, 10); + if (enemyBuildingID && (SEC_RNG::instance.currentNumber2 & 1)) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)(tribeID, + Map::Units::UIT_ATTACK_BUILDING, enemyBuildingID, + DAT_BuildingsState::instance.buildings[enemyBuildingID].uid, 0); + return; + } + if (enemyUnitID && (SEC_RNG::instance.currentNumber2 & 1)) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)(tribeID, + Map::Units::UIT_UNIT_ATTACK_UNIT, enemyUnitID, DAT_UnitsState::instance.units[enemyUnitID].uid, 0); + return; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)( + tribeID, Map::Units::UIT_NO_INSTRUCTION_OR_MOVEUnk, 0, 0, 0); + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 1); + int targetTile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findBestAttackTileByPathCost, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, DAT_UnitsState::instance.units[targetUnitID].owner, 6); + if (targetTile <= 0) { + targetTile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findBestAttackTileByPathCost, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, DAT_UnitsState::instance.units[targetUnitID].owner, + 30); + if (targetTile <= 0) { + targetTile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findBestAttackTileByPathCost, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, + DAT_UnitsState::instance.units[targetUnitID].owner, 50); + } + } + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 0); + if (0 < targetTile) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + targetTile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance + .tileTranslationMatrix_YComponent[targetTile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[targetTile], 0, 0, + Map::Units::Instructions::UMSE_0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9ce0aac371..516ab4e518 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46151,7 +46151,7 @@ SHC_3BB0A8C1_0x0051D0D0 | 0.0% | Pending SHC_3BB0A8C1_0x0051D1C0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D2B0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D2B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D450 | 0.0% | Pending From 4433448793a935d19f8f058771dfaa5dbbe6f00e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:45 +0100 Subject: [PATCH 24/94] reimplement: SHC_3BB0A8C1_0x0051D5D0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/decrementTileMap1104.cpp | 37 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp b/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp new file mode 100644 index 0000000000..2d4eaeb662 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp @@ -0,0 +1,37 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D5D0 + void TroopValueState::decrementTileMap1104() + { + for (int offset = 0; offset < 200; offset += 5) { + for (int i = 0; i < 5; ++i) { + uchar const value + = DAT_TileMapState::instance + .SEC_TileMap1104[DAT_TroopValueState::instance.attackInfo.tilemapOffset + offset + i]; + if (0 < value) { + DAT_TileMapState::instance + .SEC_TileMap1104[DAT_TroopValueState::instance.attackInfo.tilemapOffset + offset + i] + = value - 1; + } + } + } + if (DAT_TroopValueState::instance.attackInfo.tilemapOffset < MC_MAP_TILES_COUNT - 200) { + DAT_TroopValueState::instance.attackInfo.tilemapOffset += 200; + } else { + DAT_TroopValueState::instance.attackInfo.tilemapOffset = 0; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 516ab4e518..d3ff38dfd8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46157,7 +46157,7 @@ SHC_3BB0A8C1_0x0051D450 | 0.0% | Pending SHC_3BB0A8C1_0x0051D510 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D5D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D5D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D5E0 | 0.0% | Pending From d8a9fe387d3e7ac08e0815223de7ebd17b5d7f10 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:46 +0100 Subject: [PATCH 25/94] reimplement: SHC_3BB0A8C1_0x00520CD0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...ecuteDelayedAttackWaveTargetAssignment.cpp | 109 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp b/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp new file mode 100644 index 0000000000..882a210837 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp @@ -0,0 +1,109 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.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_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00520CD0 + void TroopValueState::executeDelayedAttackWaveTargetAssignment(int attackID) + { + int _playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) + && (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE)) { + _playerID = 2; + } + DAT_TroopValueState::instance.attackInfo.delayedWaveAssignmentCount++; + BOOLEnum _canReachSignpostZone = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::canKeepReachSignpostZone, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, _playerID, attackID); + if (!_canReachSignpostZone) { + DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_ASSIGNING_TARGETS; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 0; + return; + } + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID]++; + if (400 <= DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID]) { + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 0; + DAT_TroopValueState::instance.attackInfo.someCounter1++; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::aiRecomputeAttacks, this)( + DAT_TroopValueState::instance.attackInfo.attackWaveSignpostShorts[attackID]++, attackID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_0x41b); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x41b, Map::Units::STBT_1, 50, 50); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_0x418); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x418, Map::Units::STBT_1, 20, 70); + if ((DAT_TroopValueState::instance.attackInfo.people3) + && (10 <= DAT_TroopValueState::instance.attackInfo.attackTribeCount)) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1, DAT_TroopValueState::instance.attackInfo.people3, Map::Units::STBT_0x3fb); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3fb, Map::Units::STBT_1, 5, 15); + } + if (DAT_TroopValueState::instance.attackInfo.lord2) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, DAT_TroopValueState::instance.attackInfo.maxLordAttackTribes, 1000, + Map::Units::STBT_0x3fd); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::assignBehaviorTypeToNearbyTribes, this)( + Map::Units::STBT_0x3fd, 1, 0, 5); + } + if (DAT_TroopValueState::instance.attackInfo.high3) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, DAT_TroopValueState::instance.attackInfo.high3, 10000, Map::Units::STBT_0x3f8); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3f8, Map::Units::STBT_1, 20, 10); + } + if (DAT_TroopValueState::instance.attackInfo.arch3) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, DAT_TroopValueState::instance.attackInfo.arch3, 10000, Map::Units::STBT_0x3f9); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3f9, Map::Units::STBT_1, 20, 10); + } + if (DAT_TroopValueState::instance.attackInfo.people3) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 2, DAT_TroopValueState::instance.attackInfo.people3, Map::Units::STBT_0x3fb); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3fb, Map::Units::STBT_1, 0, 10); + } + int tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[_playerID - 1].town3; + if (tribeSizeSumLimit) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1, tribeSizeSumLimit, Map::Units::STBT_0x3f5); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3f5, Map::Units::STBT_1, 20, 10); + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_0x411); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::assignBehaviorTypeAndLinkSupportTribe, this)( + attackID, _playerID, Map::Units::STBT_0x411, 0, 10); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_7); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_7, Map::Units::STBT_1, 0, 5); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 1000, 10000, Map::Units::STBT_0x416); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x416, Map::Units::STBT_1, 0, 5); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d3ff38dfd8..8d302211b0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46375,7 +46375,7 @@ SHC_3BB0A8C1_0x00520450 | 0.0% | Pending SHC_3BB0A8C1_0x005205A0 | 0.0% | Pending -SHC_3BB0A8C1_0x00520CD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00520CD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00520F70 | 100.0% | Reimplemented From 5f6b0f25dec8efa6fdeb21d674c9e844b0da67d5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:46 +0100 Subject: [PATCH 26/94] reimplement: SHC_3BB0A8C1_0x0051BD10 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../exitSiegeEquipmentForWave.cpp | 50 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp new file mode 100644 index 0000000000..cd156b6dba --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp @@ -0,0 +1,50 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using AI::Tribes::AITribeType; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BD10 + void TroopValueState::exitSiegeEquipmentForWave(int wave) + { + for (int _tribeID = 1; _tribeID < countof(DAT_TribesState::instance.tribes); ++_tribeID) { + // 19 to 24 are the siege equipment tribe types; 19 to 21 have no AITribeType name yet. + if (DAT_TribesState::instance.tribes[_tribeID].tribeState + && DAT_TribesState::instance.tribes[_tribeID].attackWave == wave + && (DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)19 + || DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)20 + || DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)21 + || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_CATAPULT + || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_TREBUCHET + || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_FIRE_BALLISTA)) { + for (int _tribeUnitIndex = 0; _tribeUnitIndex < DAT_TribesState::instance.tribes[_tribeID].size;) { + int const _unitID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(_tribeID, _tribeUnitIndex); + _tribeUnitIndex++; + if (DAT_UnitsState::instance.units[_unitID].logicalState == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[_unitID].dying == 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, + DAT_TribesState::ptr)(_tribeID, Map::Units::UIT_EXIT_SIEGE_EQUIPMENT, _unitID, + DAT_UnitsState::instance.units[_unitID].uid, 0); + DAT_UnitsState::instance.units[_unitID].state.generic = Map::Units::States::US_DISAPPEAR; + } + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8d302211b0..eb831db124 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45907,7 +45907,7 @@ SHC_3BB0A8C1_0x0051BA90 | 0.0% | Pending SHC_3BB0A8C1_0x0051BC70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051BD10 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BD10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BDE0 | 0.0% | Pending From 5f23e7c09a2602e71d423c6072d38cfc95eee776 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:47 +0100 Subject: [PATCH 27/94] reimplement: SHC_3BB0A8C1_0x0051ACE0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../expandAIZoneLayerStage1.cpp | 74 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp new file mode 100644 index 0000000000..b24b25612f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp @@ -0,0 +1,74 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/AIInfoFlag.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051ACE0 + void TroopValueState::expandAIZoneLayerStage1() + { + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] != Map::Enums::AIF_RING_1) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + for (int direction = 0; direction < 4; ++direction) { + if (!(DAT_TileMapState::instance.AIInfoLayer[tile + + DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2]] + & Map::Enums::AIF_ANY_RING)) { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::recomputeALGPathFindingTileMapUnk, + DAT_PathFindingState::ptr)(6, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.xOffset + + x, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.yOffset + + y, + Map::Enums::AIF_RING_2); + break; + } + } + } + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] == Map::Enums::AIF_RING_2) { + DAT_TileMapState::instance.AIInfoLayer[tile] = Map::Enums::AIF_RING_1; + } + } + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] != Map::Enums::AIF_RING_1) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + for (int direction = 0; direction < 4; ++direction) { + if (!(DAT_TileMapState::instance.AIInfoLayer[tile + + DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2]] + & Map::Enums::AIF_ANY_RING)) { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::recomputeALGPathFindingTileMapUnk, + DAT_PathFindingState::ptr)(10, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.xOffset + + x, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.yOffset + + y, + Map::Enums::AIF_RING_2); + break; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index eb831db124..a0d09e69d4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45843,7 +45843,7 @@ SHC_3BB0A8C1_0x0051AC80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051ACB0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051ACE0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051ACE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051ACF0 | 0.0% | Pending From ca076402a7a959930a5c2e0070784903c449a85a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:47 +0100 Subject: [PATCH 28/94] reimplement: SHC_3BB0A8C1_0x0051AE00 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../expandAIZoneLayerStage2.cpp | 45 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp new file mode 100644 index 0000000000..e64a5e3bb9 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp @@ -0,0 +1,45 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/AIInfoFlag.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AE00 + void TroopValueState::expandAIZoneLayerStage2() + { + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] != Map::Enums::AIF_RING_2) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + for (int direction = 0; direction < 4; ++direction) { + if (DAT_TileMapState::instance + .AIInfoLayer[tile + DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2]] + & Map::Enums::AIF_ANY_RING) { + continue; + } + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::recomputeALGPathFindingTileMapUnk, + DAT_PathFindingState::ptr)(15, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2].int_.xOffset + + x, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2].int_.yOffset + + y, + Map::Enums::AIF_RING_3); + break; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a0d09e69d4..6d81a8d52b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45847,7 +45847,7 @@ SHC_3BB0A8C1_0x0051ACE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051ACF0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051AE00 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AE00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AE90 | 0.0% | Pending From 3972daecf173251fe5d6eff93e6e1953206be842 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:48 +0100 Subject: [PATCH 29/94] reimplement: SHC_3BB0A8C1_0x0051AE90 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../expandAIZoneLayerStage3.cpp | 46 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp new file mode 100644 index 0000000000..e8b1648a14 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp @@ -0,0 +1,46 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/AIInfoFlag.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AE90 + void TroopValueState::expandAIZoneLayerStage3() + { + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] != Map::Enums::AIF_RING_3) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + for (int direction = 0; direction < 4; ++direction) { + if (!(DAT_TileMapState::instance.AIInfoLayer[tile + + DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2]] + & Map::Enums::AIF_ANY_RING)) { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::recomputeALGPathFindingTileMapUnk, + DAT_PathFindingState::ptr)(15, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.xOffset + + x, + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction * 2] + .int_.yOffset + + y, + Map::Enums::AIF_RING_4); + break; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6d81a8d52b..62ac9fdc75 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45849,7 +45849,7 @@ SHC_3BB0A8C1_0x0051ACF0 | 0.0% | Pending SHC_3BB0A8C1_0x0051AE00 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051AE90 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AE90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AF20 | 0.0% | Pending From 7601bf07f51e402d3b3b96a31d69808a134e2470 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:48 +0100 Subject: [PATCH 30/94] reimplement: SHC_3BB0A8C1_0x00519FB0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findEnemyBuildingsClosestToUnit.cpp | 56 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp new file mode 100644 index 0000000000..446d3c8cf9 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp @@ -0,0 +1,56 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519FB0 + int TroopValueState::findEnemyBuildingsClosestToUnit(int unitID) + { + int const owner = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 1000; + int bestIndex = -1; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].town2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[i].unitID) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + int const distance = DAT_DirectionAlgorithmState::instance.distanceHigh + + (100 - DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[i].score) + * 2; + DAT_DirectionAlgorithmState::instance.distanceHigh = distance; + if (distance < minDistance) { + minDistance = distance; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[bestIndex].unitID + = unitID; + return DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].townValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 62ac9fdc75..ea3e8c32b3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45797,7 +45797,7 @@ SHC_3BB0A8C1_0x00519E40 | 0.0% | Pending SHC_3BB0A8C1_0x00519F50 | 0.0% | Pending -SHC_3BB0A8C1_0x00519FB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00519FB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A0C0 | 100.0% | Reimplemented From 9635bf9dda47a60b1efaca6ab4193fd4227dfeb7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:49 +0100 Subject: [PATCH 31/94] reimplement: SHC_3BB0A8C1_0x0051A220 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Units/TroopValueState/findEnemyLord.cpp | 42 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp new file mode 100644 index 0000000000..41f687039d --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp @@ -0,0 +1,42 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A220 + int TroopValueState::findEnemyLord(int unitID) + { + int i = 0; + if (0 < DAT_TroopValueState::instance.attackInfo.lord3) { + // Stays a do-while: a for-loop here measured 92.1% instead of 100%. + do { + if (DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].unitID == 0) { + this->y = (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile2]; + this->x = DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[this->y].addXgetTile; + this->tile = DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile; + DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].unitID = unitID; + return DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile2; + } + i++; + } while (i < DAT_TroopValueState::instance.attackInfo.lord3); + this->y = (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile2]; + this->x = DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[this->y].addXgetTile; + this->tile = DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile; + return DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ea3e8c32b3..5eeb840eb4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45805,7 +45805,7 @@ SHC_3BB0A8C1_0x0051A100 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A140 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A220 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A220 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A2D0 | 0.0% | Pending From a1a80a209c183ec776b0d04a43be7f825a38c1b6 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:49 +0100 Subject: [PATCH 32/94] reimplement: SHC_3BB0A8C1_0x0051A330 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findEnemyTowersOrGates.cpp | 85 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp new file mode 100644 index 0000000000..44c25698bc --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp @@ -0,0 +1,85 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A330 + int TroopValueState::findEnemyTowersOrGates(int unitID) + { + int const owner = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 1000; + int bestIndex = -1; + int i; + for (i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].some1000ArrayIndex_2; ++i) { + if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score + || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].unitID) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + int const bestTile + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[bestIndex].tile2; + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[bestIndex].unitID + = unitID; + return bestTile; + } + for (i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].some1000ArrayIndex_2; ++i) { + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].unitID = 0; + } + minDistance = 1000; + for (i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].some1000ArrayIndex_2; ++i) { + if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score + || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].unitID) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + return DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5eeb840eb4..a2a8b5b611 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45809,7 +45809,7 @@ SHC_3BB0A8C1_0x0051A220 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A2D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A330 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A330 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A490 | 0.0% | Pending From 43a95a86b94c400e1c56cc32c167bc47e88c18e8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:50 +0100 Subject: [PATCH 33/94] reimplement: SHC_3BB0A8C1_0x00519CC0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Units/TroopValueState/findEnemyWalls.cpp | 58 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp new file mode 100644 index 0000000000..ba7e860850 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp @@ -0,0 +1,58 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519CC0 + int TroopValueState::findEnemyWalls(int unitID) + { + int const owner = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 1000; + int bestIndex = -1; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hack2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].score + >= Map::Enums::SSS_UNUSABLE + || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].unitID) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + int const distance = DAT_DirectionAlgorithmState::instance.distanceHigh + + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].score * 8; + DAT_DirectionAlgorithmState::instance.distanceHigh = distance; + if (distance < minDistance) { + minDistance = distance; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[bestIndex].unitID + = unitID; + return DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].hackValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a2a8b5b611..011dd80683 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45789,7 +45789,7 @@ SHC_3BB0A8C1_0x00519BF0 | 0.0% | Pending SHC_3BB0A8C1_0x00519C40 | 0.0% | Pending -SHC_3BB0A8C1_0x00519CC0 | 0.0% | Pending +SHC_3BB0A8C1_0x00519CC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519DE0 | 0.0% | Pending From b1e959dde742f7bd42c3a0eb4047bd0142181828 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:50 +0100 Subject: [PATCH 34/94] reimplement: SHC_3BB0A8C1_0x00519E40 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findNearestAvailableScalePoint.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp new file mode 100644 index 0000000000..f3b4f1c2a2 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp @@ -0,0 +1,57 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519E40 + int TroopValueState::findNearestAvailableScalePoint(int unitID) + { + int const playerID = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 1000; + int bestIndex = -1; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale2; ++i) { + if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score + || DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].unitID + != 0) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < minDistance) { + minDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + this->y = fromYPosition; + this->x = fromXPosition; + this->tile + = DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].tile; + bestIndex = i; + } + } + if (-1 < bestIndex) { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[bestIndex].unitID + = unitID; + return DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1] + .scaleValuesArray[bestIndex] + .tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 011dd80683..e167635ee7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45793,7 +45793,7 @@ SHC_3BB0A8C1_0x00519CC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519DE0 | 0.0% | Pending -SHC_3BB0A8C1_0x00519E40 | 0.0% | Pending +SHC_3BB0A8C1_0x00519E40 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519F50 | 0.0% | Pending From 4fbb6ba8f4112656b2e3fcd73f224f1dd7fe32b8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:51 +0100 Subject: [PATCH 35/94] reimplement: SHC_3BB0A8C1_0x0051A8A0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findNearestDiggableMoatPoint.cpp | 34 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp new file mode 100644 index 0000000000..b50f43b105 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp @@ -0,0 +1,34 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A8A0 + int TroopValueState::findNearestDiggableMoatPoint(int unitID) + { + int const moatTile = MACRO_CALL_MEMBER(Map::TileMapState_Func::findNearestFriendlyMoatTileForDigging, + DAT_TileMapState::ptr)(DAT_UnitsState::instance.units[unitID].owner, unitID, 2); + if (moatTile <= -1) { + return 0; + } + int const result = MACRO_CALL_MEMBER(Map::TileMapState_Func::setXYBasedOnMoatID, DAT_TileMapState::ptr)( + moatTile, 2, DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y); + if (result <= 0) { + return 0; + } + this->x = DAT_TileMapState::instance.ALG_MoatXResult; + this->y = DAT_TileMapState::instance.ALG_MoatYResult; + this->tile = DAT_TileMapState::instance.someMoatTile; + return result; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e167635ee7..f2e5a84df8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45823,7 +45823,7 @@ SHC_3BB0A8C1_0x0051A720 | 0.0% | Pending SHC_3BB0A8C1_0x0051A780 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A8A0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A8A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A920 | 0.0% | Pending From e509ac1fc0fae78658088df47b8e0b6ab277de76 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:51 +0100 Subject: [PATCH 36/94] reimplement: SHC_3BB0A8C1_0x0051AF20 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findOrReserveArcherPointSlot.cpp | 29 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp b/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp new file mode 100644 index 0000000000..27ce49f841 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp @@ -0,0 +1,29 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AF20 + int TroopValueState::findOrReserveArcherPointSlot(int tile) + { + DAT_TroopValueState::instance.attackInfo.archerPointsNext = 0; + for (int i = 1; i < countof(DAT_TroopValueState::instance.attackInfo.archerPointArray) - 1; ++i) { + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[i].tile == tile) { + return i; + } + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[i].tile == 0 + && !DAT_TroopValueState::instance.attackInfo.archerPointsNext) { + DAT_TroopValueState::instance.attackInfo.archerPointsNext = i; + } + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f2e5a84df8..864466f8c8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45851,7 +45851,7 @@ SHC_3BB0A8C1_0x0051AE00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AE90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051AF20 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AF20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AF70 | 0.0% | Pending From 9443013af66a448179e0d72afe8b0ed2dd8a7024 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:51 +0100 Subject: [PATCH 37/94] reimplement: SHC_3BB0A8C1_0x0051A920 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../findTribeWithMoatAttackBehavior.cpp | 41 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp new file mode 100644 index 0000000000..9b3ea12cac --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp @@ -0,0 +1,41 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A920 + BOOLEnum TroopValueState::findTribeWithMoatAttackBehavior() + { + for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState == 0) { + continue; + } + BOOLEnum const fullIDIsMinus1 + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::isFullIDEqualsToMinus1, DAT_GameState::ptr)( + DAT_TribesState::instance.tribes[tribeID].owner); + if (fullIDIsMinus1 + && DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType == Map::Units::STBT_0x3f7) { + this->x = DAT_TribesState::instance.tribes[tribeID].targetX; + this->y = DAT_TribesState::instance.tribes[tribeID].targetY; + DAT_TroopValueState::instance.attackInfo.field127625_0x42744 = tribeID; + return TRUE; + } + } + return FALSE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 864466f8c8..a3272ff1f3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45825,7 +45825,7 @@ SHC_3BB0A8C1_0x0051A780 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A8A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A920 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A920 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A9A0 | 100.0% | Reimplemented From 06a69d0641c55cc2d417180cf4b81b22809c87a8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:52 +0100 Subject: [PATCH 38/94] reimplement: SHC_3BB0A8C1_0x0051A5B0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../getClosestWideValueBasedOnPlayer.cpp | 73 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp new file mode 100644 index 0000000000..b8e03383bc --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp @@ -0,0 +1,73 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A5B0 + int TroopValueState::getClosestWideValueBasedOnPlayer(int unitID) + { + int const owner = DAT_UnitsState::instance.units[unitID].owner; + int minDistance = 1000; + int bestIndex = -1; + int const attackedPlayerID = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1] + .currentPlayerID_OR_attackedPlayerID_OR_one; + int const destinationXPosition = DAT_GameState::instance.playerDataArray[attackedPlayerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry; + int const destinationYPosition = DAT_GameState::instance.playerDataArray[attackedPlayerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry; + int i = 0; + if (0 < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wide2) { + for (; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wide2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].score >= 5999 + || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].unitID) { + continue; + } + int const fromYPosition + = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + [DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].tile2]; + int const fromXPosition + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].tile2 + - DAT_ViewportRenderState::instance.translationMatrix[fromYPosition].addXgetTile; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, fromXPosition, fromYPosition); + int distance = DAT_DirectionAlgorithmState::instance.distanceHigh; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)( + destinationXPosition, destinationYPosition, fromXPosition, fromYPosition); + distance += DAT_DirectionAlgorithmState::instance.distanceHigh; + if (distance < minDistance) { + this->y = fromYPosition; + this->x = fromXPosition; + this->tile + = DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].tile; + minDistance = distance; + bestIndex = i; + } + } + if (bestIndex <= -1) { + return 0; + } + DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[bestIndex].unitID + = unitID; + return DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[bestIndex].tile2; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a3272ff1f3..e0762879d7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45815,7 +45815,7 @@ SHC_3BB0A8C1_0x0051A490 | 0.0% | Pending SHC_3BB0A8C1_0x0051A550 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A5B0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A5B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A630 | 0.0% | Pending From db21b54e2bded36a14696851107c66e440cb0c72 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:52 +0100 Subject: [PATCH 39/94] reimplement: SHC_3BB0A8C1_0x0051BDE0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../getPlayerNot1AndHasKeep.cpp | 38 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp new file mode 100644 index 0000000000..40c6d9770d --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp @@ -0,0 +1,38 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BDE0 + BOOLEnum TroopValueState::getPlayerNot1AndHasKeep(int playerID) + { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + if (playerID == 1) { + return TRUE; + } + } else if (playerID != 1 + && 0 < DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .id) { + return TRUE; + } + return FALSE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e0762879d7..3e6b3277eb 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45909,7 +45909,7 @@ SHC_3BB0A8C1_0x0051BC70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BD10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051BDE0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BDE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BE20 | 100.0% | Reimplemented From 4f00b79669aab55dfc7d8b697c1afaa0caf98989 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:53 +0100 Subject: [PATCH 40/94] reimplement: SHC_3BB0A8C1_0x0051B240 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/getSiegeIndexForTile.cpp | 29 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp new file mode 100644 index 0000000000..c44b7fbe82 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp @@ -0,0 +1,29 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B240 + int TroopValueState::getSiegeIndexForTile(int tile) + { + DAT_TroopValueState::instance.attackInfo.tentPointsNext = 0; + for (int i = 1; i < countof(DAT_TroopValueState::instance.attackInfo.tentPointsValues) - 1; ++i) { + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[i].tile == tile) { + return i; + } + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[i].tile == 0 + && !DAT_TroopValueState::instance.attackInfo.tentPointsNext) { + DAT_TroopValueState::instance.attackInfo.tentPointsNext = i; + } + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3e6b3277eb..9f28fee382 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45867,7 +45867,7 @@ SHC_3BB0A8C1_0x0051B120 | 0.0% | Pending SHC_3BB0A8C1_0x0051B190 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051B240 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B240 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B290 | 0.0% | Pending From 286cafa12634b0b4e4a12a633019d7b49121a070 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:53 +0100 Subject: [PATCH 41/94] reimplement: SHC_3BB0A8C1_0x0051B0C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/getSupportPointIndex.cpp | 29 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp b/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp new file mode 100644 index 0000000000..82b4707475 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp @@ -0,0 +1,29 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B0C0 + int TroopValueState::getSupportPointIndex(int tile) + { + DAT_TroopValueState::instance.attackInfo.supportPointsNext = 0; + for (int i = 1; i < countof(DAT_TroopValueState::instance.attackInfo.supportPointsArray) - 1; ++i) { + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[i].tile == tile) { + return i; + } + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[i].tile == 0 + && !DAT_TroopValueState::instance.attackInfo.supportPointsNext) { + DAT_TroopValueState::instance.attackInfo.supportPointsNext = i; + } + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9f28fee382..c1e1c0ea56 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45859,7 +45859,7 @@ SHC_3BB0A8C1_0x0051AF80 | 0.0% | Pending SHC_3BB0A8C1_0x0051AFF0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051B0C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B0C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B110 | 0.0% | Pending From 79f7f6a02f88cd39302eba46336e2d223d27a2ac Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:54 +0100 Subject: [PATCH 42/94] reimplement: SHC_3BB0A8C1_0x0051C360 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/getValueOfTroopType.cpp | 52 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp b/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp new file mode 100644 index 0000000000..806206285e --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp @@ -0,0 +1,52 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::Units::UnitType; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051C360 + int TroopValueState::getValueOfTroopType(UnitType unitType) + { + switch (unitType) { + case Map::Units::UT_E_MONK: + return DAT_RenderingDefinedData::instance.MONK; + case Map::Units::UT_TUNNELER: + return DAT_RenderingDefinedData::instance.TUNNELER; + case Map::Units::UT_A_ARCHER: + return DAT_RenderingDefinedData::instance.A_ARCHER; + case Map::Units::UT_A_SLAVE: + return DAT_RenderingDefinedData::instance.SLAVE; + case Map::Units::UT_A_SLINGER: + return DAT_RenderingDefinedData::instance.SLINGER; + case Map::Units::UT_A_ASSASSIN: + return DAT_RenderingDefinedData::instance.ASSASSIN; + case Map::Units::UT_A_HARCHER: + return DAT_RenderingDefinedData::instance.HARCHER; + case Map::Units::UT_A_SWORDSMAN: + return DAT_RenderingDefinedData::instance.A_SWORDSMAN; + case Map::Units::UT_A_FIRETHROWER: + return DAT_RenderingDefinedData::instance.FIRETHROWER; + case Map::Units::UT_S_FBALLISTA: + return DAT_RenderingDefinedData::instance.S_FBALLISTA; + case Map::Units::UT_S_CATAPULT: + return DAT_RenderingDefinedData::instance.CATAPULT; + } + if (unitType < Map::Units::UT_E_ARCHER) { + return 0; + } + if (unitType <= Map::Units::UT_E_ENGINEER) { + return DAT_RenderingDefinedData::instance.NoRushTicks[unitType + Map::Units::UT_TUNNELER]; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c1e1c0ea56..5c9b06ee63 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45925,7 +45925,7 @@ SHC_3BB0A8C1_0x0051C1A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C2D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051C360 | 0.0% | Pending +SHC_3BB0A8C1_0x0051C360 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C3EC | 0.0% | Pending From 58b4ca808223d449fe447a3e76f628e48762970d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:54 +0100 Subject: [PATCH 43/94] reimplement: SHC_3BB0A8C1_0x0051BF70 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...htPitchInstructionToUnitClosestToPitch.cpp | 90 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp new file mode 100644 index 0000000000..211c9fed3f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp @@ -0,0 +1,90 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BF70 + BOOLEnum TroopValueState::giveLightPitchInstructionToUnitClosestToPitch(int tile) + { + BOOLEnum isAIPlayerWithKeep; + int _shot; + int _ditchID + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(tile); + int _minUnitID = 0; + int _minDistance = 100000000; + int _unitID = 1; + if (1 < DAT_UnitsState::instance.maxUnitCount) { + Unit* _pUnit = &DAT_UnitsState::instance.units[1]; + for (; _unitID < DAT_UnitsState::instance.maxUnitCount; _unitID++, _pUnit++) { + if (_pUnit->logicalState != Map::Units::ULS_INVISIBLE + && (isAIPlayerWithKeep = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)((int)_pUnit->owner), + isAIPlayerWithKeep) + && (_pUnit->unitType == Map::Units::UT_E_ARCHER + || (_pUnit->unitType == Map::Units::UT_A_ARCHER)) + && !_pUnit->dying && _pUnit->field_0x40d != false + && _pUnit->targetingType != Map::Units::UIT_LIGHT_PITCH) { + int const _ditchY = (int)DAT_TileMapState::instance.pitchDitches[_ditchID].y; + int const _ditchX = (int)DAT_TileMapState::instance.pitchDitches[_ditchID].x; + int const _unitY = _ditchY - _pUnit->y; + int const _unitX = _ditchX - _pUnit->x; + int _distancePyth = _unitX * _unitX + _unitY * _unitY; + if (_distancePyth <= 2500 + && (_shot = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::arrowShootingRelated, + DAT_EntityState::ptr)((int)_pUnit->microXPosition, (int)(_pUnit->microYPosition), + (int)(_pUnit->buildingHeight + 30 + _pUnit->terrainOrClimbHeight), _ditchX * 8 + 4, + _ditchY * 8 + 4, + (int)(DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile])), + 0 < _shot) + && _distancePyth < _minDistance) { + _minDistance = _distancePyth; + _minUnitID = _unitID; + } + } + } + } + if (!_minUnitID) { + return 0; + } + DAT_UnitsState::instance.units[_minUnitID].shootTargetMicroX + = DAT_TileMapState::instance.pitchDitches[_ditchID].x * 8 + 4; + DAT_UnitsState::instance.units[_minUnitID].shootTargetMicroY + = DAT_TileMapState::instance.pitchDitches[_ditchID].y * 8 + 4; + DAT_UnitsState::instance.units[_minUnitID].shootTargetZ + = DAT_TileMapState::instance.HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile]; + DAT_UnitsState::instance.units[_minUnitID].targetID_OR_targetBuildingID = (short)_ditchID; + int _ditchUID = DAT_TileMapState::instance.pitchDitches[_ditchID].uid; + DAT_UnitsState::instance.units[_minUnitID].shootTargetedUnit = -1; + DAT_UnitsState::instance.units[_minUnitID] + .targetedUnitUIDUnk_OR_someAppearTileUnk_OR_buildingUID_OR_pitchDitchUID_OR_entityUID = _ditchUID; + DAT_UnitsState::instance.units[_minUnitID].field_0x3c5 = 34; + DAT_UnitsState::instance.units[_minUnitID].targetingType = Map::Units::UIT_LIGHT_PITCH; + DAT_UnitsState::instance.units[_minUnitID].field_0x3f8 = 0; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::makeUnitStopWalkingByClearingPathProgressState, + DAT_UnitsState::ptr)(_minUnitID); + DAT_UnitsState::instance.units[_minUnitID].state.generic = Map::Units::States::US_FIRE_WEAPONUnk; + DAT_UnitsState::instance.units[_minUnitID].field_0x40e = true; + return 1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5c9b06ee63..bacd576872 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45919,7 +45919,7 @@ SHC_3BB0A8C1_0x0051BEE0 | 0.0% | Pending SHC_3BB0A8C1_0x0051BF20 | 0.0% | Pending -SHC_3BB0A8C1_0x0051BF70 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BF70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C1A0 | 100.0% | Reimplemented From ebb0012433c4ecce6bb9e17f1800c77769ef83d1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:54 +0100 Subject: [PATCH 44/94] reimplement: SHC_3BB0A8C1_0x0051C570 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../ifNecessaryThrowOilAutomatically.cpp | 135 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp b/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp new file mode 100644 index 0000000000..7725676eb0 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp @@ -0,0 +1,135 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051C570 + BOOLEnum TroopValueState::ifNecessaryThrowOilAutomatically(int unitID) + { + int const tribeID = DAT_UnitsState::instance.units[unitID].tribeID; + int searchRadius = 4; + if (DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight > 110) { + searchRadius = 5; + } + if (tribeID <= 0) { + return FALSE; + } + if (DAT_UnitsState::instance.units[unitID].closestEnemyMicroDistance > 80) { + return FALSE; + } + int const playerID = DAT_UnitsState::instance.units[unitID].owner; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1 + && DAT_TribesState::instance.tribes[tribeID].unitStance == Map::Units::Behavior::USE_STAND_GROUND) { + return FALSE; + } + DAT_UnitsState::instance.units[unitID].updateTickTracker++; + if (DAT_UnitsState::instance.units[unitID].updateTickTracker < 8) { + return FALSE; + } + DAT_UnitsState::instance.units[unitID].updateTickTracker = 0; + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeTotalUnitsWithinDistance, + DAT_PathFindingState::ptr)(playerID, 0, 0, DAT_UnitsState::instance.units[unitID].tile, searchRadius); + if (DAT_TribesState::instance.tribes[tribeID].unitStance == Map::Units::Behavior::USE_AGGRESSIVE) { + if (DAT_PathFindingState::instance.ALGO_TotalTroopCount < 1) { + return FALSE; + } + } else if (DAT_PathFindingState::instance.ALGO_TotalTroopCount <= 3 + && DAT_PathFindingState::instance.ALGO_TotalTroopValue < 20) { + return FALSE; + } + int const targetUnitID = DAT_PathFindingState::instance.field_0x64; + if (targetUnitID == 0) { + return FALSE; + } + short const buildingID + = DAT_TileMapState::instance.BuildingLayer[DAT_UnitsState::instance.units[targetUnitID].tile]; + if (buildingID != 0) { + int buildingSize = 0; + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case Map::Buildings::BT_CAMPGROUND: + buildingSize = 7; + break; + case Map::Buildings::BT_PARADEGROUND: + case Map::Buildings::BT_PARADEGROUND2: + case Map::Buildings::BT_PARADEGROUND3: + case Map::Buildings::BT_PARADEGROUND4: + case Map::Buildings::BT_PARADEGROUND5: + buildingSize = 5; + break; + case Map::Buildings::BT_CAMPFIRE: + buildingSize = 4; + break; + default: + break; + } + if (buildingSize != 0) { + int tileIndex = 0; + int const buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; + int const buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; + int friendlyTroopValue = 0; + int enemyTroopValue = 0; + // Stays a do-while: getBuildingSizeIndexMappingData sets constructionTileCount, so the first + // pass runs before the count is known. + do { + MACRO_CALL_MEMBER(Map::TileMapState_Func::getBuildingSizeIndexMappingData, + DAT_TileMapState::ptr)(tileIndex, buildingSize); + for (int tileUnitID = DAT_TileMapState::instance + .UnitLayer[DAT_ViewportRenderState::instance + .translationMatrix[DAT_TileMapState::instance.buildingY + buildingY] + .addXgetTile + + DAT_TileMapState::instance.buildingX + buildingX]; + tileUnitID != 0; + tileUnitID = DAT_UnitsState::instance.units[tileUnitID].nextUnitOnTheSameTile) { + if (DAT_UnitsState::instance.units[tileUnitID].isSelectable_OR_matchTime == 0) { + continue; + } + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_UnitsState::instance.units[unitID].owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_UnitsState::instance.units[tileUnitID].owner]) { + enemyTroopValue += MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::getValueOfTroopType, DAT_TroopValueState::ptr)( + (Map::Units::UnitType)DAT_UnitsState::instance.units[tileUnitID].unitType); + } else { + friendlyTroopValue += MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::getValueOfTroopType, DAT_TroopValueState::ptr)( + (Map::Units::UnitType)DAT_UnitsState::instance.units[tileUnitID].unitType); + } + } + tileIndex++; + } while (tileIndex < DAT_TileMapState::instance.constructionTileCount); + if (friendlyTroopValue > enemyTroopValue) { + return FALSE; + } + } + } + DAT_UnitsState::instance.units[unitID].targetingType = Map::Units::UIT_THROW_OIL; + DAT_UnitsState::instance.units[unitID].attackAtTileX = DAT_UnitsState::instance.units[targetUnitID].x; + DAT_UnitsState::instance.units[unitID].attackAtTileY = DAT_UnitsState::instance.units[targetUnitID].y; + DAT_UnitsState::instance.units[unitID].animationFrame = 4; + return TRUE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bacd576872..b084f9d00f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46099,7 +46099,7 @@ SHC_3BB0A8C1_0x0051C464 | 0.0% | Pending SHC_3BB0A8C1_0x0051C470 | 0.0% | Pending -SHC_3BB0A8C1_0x0051C570 | 0.0% | Pending +SHC_3BB0A8C1_0x0051C570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C710 | 0.0% | Pending From 4cf109158743df3319fa6f5281aebd5eda80f5c8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:55 +0100 Subject: [PATCH 45/94] reimplement: SHC_3BB0A8C1_0x00519850 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../initializeAttackZoneSearch.cpp | 38 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp new file mode 100644 index 0000000000..8876dbef8f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp @@ -0,0 +1,38 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519850 + void TroopValueState::initializeAttackZoneSearch(int attackID) + { + DAT_TroopValueState::instance.attackInfo.biggestZone = 0; + int const tile + = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackID]] + .tile; + DAT_TroopValueState::instance.attackInfo.startZone = DAT_TileMapState::instance.AIZoneLayer[tile]; + DAT_TroopValueState::instance.attackInfo.startCon = DAT_TileMapState::instance.PathConnectionLayer[tile]; + DAT_TroopValueState::instance.attackInfo.zoneSize + = DAT_PathFindingState::instance.zoneSizesArray[DAT_TileMapState::instance.PathConnectionLayer[tile]]; + DAT_TroopValueState::instance.attackInfo.unknownOne_0x20f90 = 1; + DAT_TroopValueState::instance.attackInfo.keepCon + = DAT_TileMapState::instance.PathConnectionLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b084f9d00f..23d57ec8ec 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45769,7 +45769,7 @@ SHC_3BB0A8C1_0x00519690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519790 | 0.0% | Pending -SHC_3BB0A8C1_0x00519850 | 0.0% | Pending +SHC_3BB0A8C1_0x00519850 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005198C0 | 0.0% | Pending From f82279a742672545629ba8ea58dddbd98a148183 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:55 +0100 Subject: [PATCH 46/94] reimplement: SHC_3BB0A8C1_0x0051FF90 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../initializeOrAdvanceAttackWave.cpp | 62 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp new file mode 100644 index 0000000000..eff36cf247 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp @@ -0,0 +1,62 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051FF90 + void TroopValueState::initializeOrAdvanceAttackWave(int attackWave) + { + if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] == 0) { + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = 1; + DAT_TroopValueState::instance.attackInfo.pendingAttackWaveCount++; + DAT_TroopValueState::instance.attackInfo.someCounter1 = 1; + DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed = FALSE; + DAT_TroopValueState::instance.attackInfo.attackWaveRetargetCount = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recountAttackTroopValue, this)(TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::computeAttackWaveTroopComposition, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackZoneSearch, this)(attackWave); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::recountTotalTroopValue, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackWave, 2, 100000, Map::Units::STBT_0x3fb); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3fe, Map::Units::STBT_1, 0, 50); + DAT_TroopValueState::instance.attackInfo.casDis = MACRO_CALL_MEMBER( + Map::WildlifeState_Func::getDistanceFromAttackSignpostToZoneProximity, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::applyTribeBehaviorType, DAT_TribesState::ptr)( + attackWave, Map::Units::STBT_3); + } + if ((int)(char)DAT_TroopValueState::instance.attackInfo.unknownByteArray02[attackWave] + >= (char)DAT_TroopValueState::instance.attackInfo.nof_tribes[attackWave] - 5) { + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave]++; + if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] + >= DAT_AttackInfoDefinedData::instance + .AIAttackWaveAdvanceDelay[DAT_TroopValueState::instance.attackInfo.attacker]) { + if (DAT_TroopValueState::instance.attackInfo.attacker == 8) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::playAttackAlarmSound, this)(); + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = 10000; + DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] + = Map::Enums::AWS_ASSIGNING_TARGETS; + DAT_TroopValueState::instance.attackInfo.value10 = 0; + } else { + DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] = Map::Enums::AWS_ADVANCING; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = 0; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 23d57ec8ec..304f63927a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46365,7 +46365,7 @@ SHC_3BB0A8C1_0x0051FB90 | 0.0% | Pending SHC_3BB0A8C1_0x0051FE80 | 0.0% | Pending -SHC_3BB0A8C1_0x0051FF90 | 0.0% | Pending +SHC_3BB0A8C1_0x0051FF90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005200A0 | 100.0% | Reimplemented From 897b5d214ccd29ce4d27dcce375d29a64c207a2a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:55 +0100 Subject: [PATCH 47/94] reimplement: SHC_3BB0A8C1_0x00518BB0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...essThanPercentageOfTribesInAttackDying.cpp | 46 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp new file mode 100644 index 0000000000..a9ad10db58 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp @@ -0,0 +1,46 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00518BB0 + BOOLEnum TroopValueState::isLessThanPercentageOfTribesInAttackDying(int attackID, int leDyingPerc) + { + int dying = 0; + int living = 0; + for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { + if (!DAT_TribesState::instance.tribes[tribeID].tribeState + || DAT_TribesState::instance.tribes[tribeID].tribeState == 3 + || DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_TribesState::instance.tribes[tribeID].owner] + != -1 + || DAT_TribesState::instance.tribes[tribeID].attackWave != attackID) { + continue; + } + int const aliveStatus = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getTribeAliveStatus, DAT_TribesState::ptr)(tribeID); + if (aliveStatus < 50) { + ++living; + } else { + ++dying; + } + } + int dyingPercentage; + if (dying + living == 0) { + dyingPercentage = 100; + } else { + dyingPercentage = (dying * 100) / (dying + living); + } + return dyingPercentage >= leDyingPerc; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 304f63927a..bbce69205e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45759,7 +45759,7 @@ SHC_3BB0A8C1_0x00518930 | 0.0% | Pending SHC_3BB0A8C1_0x00518A10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00518BB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00518BB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00518C50 | 0.0% | Pending From 5067406278edb6ab3afec616f3ecebe14d2cfb3b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:56 +0100 Subject: [PATCH 48/94] reimplement: SHC_3BB0A8C1_0x0051D510 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../moveTowardsParticularUnits.cpp | 44 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp new file mode 100644 index 0000000000..c5fb432e86 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp @@ -0,0 +1,44 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D510 + void TroopValueState::moveTowardsParticularUnits(int tribeID) + { + int const selectedUnitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int targetUnitID = MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::findDistanceOrThreatLevelToUnitUnk, DAT_PathFindingState::ptr)( + DAT_TribesState::instance.tribes[tribeID].owner, DAT_UnitsState::instance.units[selectedUnitID].x, + DAT_UnitsState::instance.units[selectedUnitID].y, 80); + if (!targetUnitID) { + targetUnitID + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findDistanceOrThreatLevelToUnitUnk, + DAT_PathFindingState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, + DAT_UnitsState::instance.units[selectedUnitID].x, + DAT_UnitsState::instance.units[selectedUnitID].y, 200); + if (!targetUnitID) { + return; + } + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)( + tribeID, Map::Units::UIT_NO_INSTRUCTION_OR_MOVEUnk, 0, 0, 0); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, 0, 0, + Map::Units::Instructions::UMSE_0); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bbce69205e..1431884da3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46155,7 +46155,7 @@ SHC_3BB0A8C1_0x0051D2B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D450 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D510 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D510 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D5D0 | 100.0% | Reimplemented From 63df0fc0bc3fa01f5b7711e6b0ae33f3ea589054 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:56 +0100 Subject: [PATCH 49/94] reimplement: SHC_3BB0A8C1_0x0051D450 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../moveTribeToNearbyGatehouse.cpp | 46 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp new file mode 100644 index 0000000000..e57c9d8c71 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp @@ -0,0 +1,46 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D450 + BOOLEnum TroopValueState::moveTribeToNearbyGatehouse(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int gatehouseID = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::getGatehouseNearSomethingUnk, + DAT_PathFindingState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, 80); + if (!gatehouseID) { + gatehouseID = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::getGatehouseNearSomethingUnk, + DAT_PathFindingState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, 200); + if (!gatehouseID) { + return FALSE; + } + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)( + tribeID, Map::Units::UIT_NO_INSTRUCTION_OR_MOVEUnk, 0, 0, 0); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + DAT_BuildingsState::instance.buildings[gatehouseID].someX, + DAT_BuildingsState::instance.buildings[gatehouseID].someY, 0, 0, Map::Units::Instructions::UMSE_0); + return TRUE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1431884da3..027eb65568 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46153,7 +46153,7 @@ SHC_3BB0A8C1_0x0051D1C0 | 0.0% | Pending SHC_3BB0A8C1_0x0051D2B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051D450 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D450 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D510 | 100.0% | Reimplemented From 66c4e8b195ccf301eac8d4d34c9865ae7d4116e2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:57 +0100 Subject: [PATCH 50/94] reimplement: SHC_3BB0A8C1_0x0051D1C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../moveTribeToReachableNearbyTile.cpp | 53 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp new file mode 100644 index 0000000000..a76ac78185 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp @@ -0,0 +1,53 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D1C0 + void TroopValueState::moveTribeToReachableNearbyTile(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 1); + int tile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, DAT_UnitsState::instance.units[unitID].owner, 12, 0); + if (tile <= 0) { + tile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, DAT_UnitsState::instance.units[unitID].owner, 30, 0); + if (tile <= 0) { + tile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, DAT_UnitsState::instance.units[unitID].owner, 50, 0); + } + } + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 0); + if (0 < tile) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + tile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile], 0, 0, + Map::Units::Instructions::UMSE_0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 027eb65568..5a79950d78 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46149,7 +46149,7 @@ SHC_3BB0A8C1_0x0051D020 | 0.0% | Pending SHC_3BB0A8C1_0x0051D0D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D1C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D1C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D2B0 | 100.0% | Reimplemented From 556c262b7a4ef9c90eeebea4a2f41c1e99fcd683 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:57 +0100 Subject: [PATCH 51/94] reimplement: SHC_3BB0A8C1_0x0051B310 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../placeSiegeTentAtAttackAngle.cpp | 56 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp new file mode 100644 index 0000000000..bd409aed84 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp @@ -0,0 +1,56 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B310 + int TroopValueState::placeSiegeTentAtAttackAngle(int tribeID, MappersEnum commandBuildingType) + { + int const targetUnitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int const attackLocationIndex + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::algFindAttackAngle, + DAT_PathFindingState::ptr)(200, DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, tribeID); + if (attackLocationIndex) { + short const previousSiegeIndex = DAT_TribesState::instance.tribes[tribeID].siegeIndexValue1; + int const tribeUID = DAT_TribesState::instance.tribes[tribeID].uid; + DAT_TribesState::instance.tribes[tribeID].siegeIndexValue2 = previousSiegeIndex; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[previousSiegeIndex].tribeID = 0; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[previousSiegeIndex].tribeUID = 0; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[attackLocationIndex].tribeUID = tribeUID; + int const y = DAT_TroopValueState::instance.attackInfo.tentPointsValues[attackLocationIndex].y; + int const x = DAT_TroopValueState::instance.attackInfo.tentPointsValues[attackLocationIndex].x; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[attackLocationIndex].tribeID = tribeID; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[attackLocationIndex].three = 3; + int const playerID = DAT_TribesState::instance.tribes[tribeID].owner; + DAT_TribesState::instance.tribes[tribeID].siegeIndexValue1 = attackLocationIndex; + MACRO_CALL_MEMBER(Map::TileMapState_Func::placeBuilding, DAT_TileMapState::ptr)( + playerID, x - 1, y - 1, commandBuildingType, 3, 15); + int const buildingID = DAT_TileMapState::instance.placedBuildingID; + DAT_BuildingsState::instance.buildings[DAT_TileMapState::instance.placedBuildingID].attackWave + = DAT_TribesState::instance.tribes[tribeID].attackWave; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)(tribeID, + Map::Units::UIT_CONSTRUCT_SIEGE_EQUIPMENTOIL_DUTYENGINEERRELATED, buildingID, + DAT_BuildingsState::instance.buildings[buildingID].uid, 0); + return attackLocationIndex; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5a79950d78..ec76942252 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45873,7 +45873,7 @@ SHC_3BB0A8C1_0x0051B290 | 0.0% | Pending SHC_3BB0A8C1_0x0051B2A0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051B310 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B310 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B420 | 0.0% | Pending From dd508437750787f402f5fb02943318f58b92ac9e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:57 +0100 Subject: [PATCH 52/94] reimplement: SHC_3BB0A8C1_0x0051B710 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../placeSiegeTentsAndAssignEngineers.cpp | 143 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp new file mode 100644 index 0000000000..4277322e4b --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp @@ -0,0 +1,143 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B710 + void TroopValueState::placeSiegeTentsAndAssignEngineers(int attackWave, BOOLEnum useAttackAngle) + { + int owner = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; + if (!owner) { + owner = 2; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + owner = 2; + } + int engineerTotal = 0; + DAT_TroopValueState::instance.attackInfo.createTribeAmount = 0; + for (int k = 0; k <= 4; k++) { + Commands::MappersEnum const buildingType = DAT_ARRAY_00b4c7cc::instance[k]; + int const engineers = INT_ARRAY_00b4d0f0::instance[k]; + int const count = (char)DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave][k]; + for (int n = 0; n < count; n++) { + DAT_TroopValueState::instance.attackInfo + .engineerBuildQueue[DAT_TroopValueState::instance.attackInfo.createTribeAmount] + .engineerBuildingType = buildingType; + DAT_TroopValueState::instance.attackInfo + .engineerBuildQueue[DAT_TroopValueState::instance.attackInfo.createTribeAmount] + .engineerCount = engineers; + DAT_TroopValueState::instance.attackInfo.createTribeAmount++; + engineerTotal += engineers; + if (DAT_TroopValueState::instance.attackInfo.createTribeAmount >= 250) { + break; + } + } + } + int const count = (char)DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave][8]; + Commands::MappersEnum const buildingType = DAT_ARRAY_00b4c7cc::instance[8]; + int const engineers = INT_ARRAY_00b4d0f0::instance[8]; + for (int n = 0; n < count; n++) { + if (DAT_TroopValueState::instance.attackInfo.createTribeAmount >= 250) { + break; + } + DAT_TroopValueState::instance.attackInfo + .engineerBuildQueue[DAT_TroopValueState::instance.attackInfo.createTribeAmount] + .engineerBuildingType = buildingType; + DAT_TroopValueState::instance.attackInfo + .engineerBuildQueue[DAT_TroopValueState::instance.attackInfo.createTribeAmount] + .engineerCount = engineers; + DAT_TroopValueState::instance.attackInfo.createTribeAmount++; + engineerTotal += engineers; + } + int tribeID = 1; + DAT_TroopValueState::instance.attackInfo.tribeIDArraySize = 0; + for (; tribeID < countof(DAT_TribesState::instance.tribes); tribeID++) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState + && DAT_TribesState::instance.tribes[tribeID].owner == owner + && DAT_TribesState::instance.tribes[tribeID].attackWave == attackWave + && DAT_TribesState::instance.tribes[tribeID].tribeType == AI::Tribes::AITT_ENGINEERS) { + DAT_TroopValueState::instance.attackInfo + .tribeIDArray[DAT_TroopValueState::instance.attackInfo.tribeIDArraySize] = tribeID; + DAT_TroopValueState::instance.attackInfo.tribeIDArraySize++; + } + } + if (!DAT_TroopValueState::instance.attackInfo.tribeIDArraySize) { + return; + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.tribeIDArraySize; i++) { + tribeID = DAT_TroopValueState::instance.attackInfo.tribeIDArray[i]; + for (; DAT_TribesState::instance.tribes[tribeID].size && engineerTotal > 0; engineerTotal--) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::popUnitFromTribe, DAT_TribesState::ptr)(tribeID); + } + } + int unitID = 0; + for (int q = 0; q < DAT_TroopValueState::instance.attackInfo.createTribeAmount; q++) { + int remaining = DAT_TroopValueState::instance.attackInfo.engineerBuildQueue[q].engineerCount; + int const newTribeID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, + DAT_TribesState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, 0); + DAT_TribesState::instance.tribes[newTribeID].tribeType = AI::Tribes::AITT_ENGINEERS; + DAT_TribesState::instance.tribes[newTribeID].tribeBehaviorType = 1040; + DAT_TribesState::instance.tribes[newTribeID].attackWave + = DAT_TribesState::instance.tribes[tribeID].attackWave; + DAT_TribesState::instance.tribes[newTribeID].attackInfo_someCounter1 + = DAT_TribesState::instance.tribes[tribeID].attackInfo_someCounter1; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + for (;;) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[unitID].owner == owner + && !DAT_UnitsState::instance.units[unitID].dying + && DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_ENGINEER + && !DAT_UnitsState::instance.units[unitID].tribeID) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( + unitID, newTribeID); + remaining--; + if (remaining <= 0) { + break; + } + } + unitID++; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + } + unitID++; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + if (useAttackAngle) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeSiegeTentAtAttackAngle, this)(newTribeID, + DAT_TroopValueState::instance.attackInfo.engineerBuildQueue[q].engineerBuildingType); + } else { + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::placeSiegeTentOrTunnelAtSuitableLocationAndAssignEngineers, + this)(newTribeID, + DAT_TroopValueState::instance.attackInfo.engineerBuildQueue[q].engineerBuildingType, 0, + Map::Units::UIT_CONSTRUCT_SIEGE_EQUIPMENTOIL_DUTYENGINEERRELATED); + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ec76942252..c8fe688c2d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45893,7 +45893,7 @@ SHC_3BB0A8C1_0x0051B708 | 0.0% | Pending SHC_3BB0A8C1_0x0051B70C | 0.0% | Pending -SHC_3BB0A8C1_0x0051B710 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B710 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B770 | 0.0% | Pending From 200756d24b8a7eff7f7d5eeca7aa30d61812c9eb Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:58 +0100 Subject: [PATCH 53/94] reimplement: SHC_3BB0A8C1_0x0051B570 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/placeTunnelEntrances.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp new file mode 100644 index 0000000000..27745f3b11 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp @@ -0,0 +1,57 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B570 + int TroopValueState::placeTunnelEntrances(int tribeID) + { + int const unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + int const tentPointIndex = MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::algFindAttackAngle, DAT_PathFindingState::ptr)( + 200, DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, tribeID); + if (tentPointIndex) { + short const previousSiegeIndex = DAT_TribesState::instance.tribes[tribeID].siegeIndexValue1; + int const tribeUID = DAT_TribesState::instance.tribes[tribeID].uid; + DAT_TribesState::instance.tribes[tribeID].siegeIndexValue2 = previousSiegeIndex; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[previousSiegeIndex].tribeID = 0; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[previousSiegeIndex].tribeUID = 0; + int const tentPointY = DAT_TroopValueState::instance.attackInfo.tentPointsValues[tentPointIndex].y; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[tentPointIndex].tribeUID = tribeUID; + int const playerID = DAT_TribesState::instance.tribes[tribeID].owner; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[tentPointIndex].tribeID = tribeID; + DAT_TroopValueState::instance.attackInfo.tentPointsValues[tentPointIndex].three = 3; + int const tentPointX = DAT_TroopValueState::instance.attackInfo.tentPointsValues[tentPointIndex].x; + DAT_TribesState::instance.tribes[tribeID].siegeIndexValue1 = tentPointIndex; + MACRO_CALL_MEMBER(Map::TileMapState_Func::placeBuilding, DAT_TileMapState::ptr)( + playerID, tentPointX - 1, tentPointY - 1, Commands::M_MAPPER_TUNNEL_CONSTRUCTION, 3, 15); + int const buildingID = DAT_TileMapState::instance.placedBuildingID; + if (buildingID <= 0) { + return 0; + } + DAT_BuildingsState::instance.buildings[buildingID].attackWave + = DAT_TribesState::instance.tribes[tribeID].attackWave; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)( + tribeID, UIT_DIG_TUNNEL, buildingID, DAT_BuildingsState::instance.buildings[buildingID].uid, 0); + return tentPointIndex; + } + return 0; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c8fe688c2d..7480426dd9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45877,7 +45877,7 @@ SHC_3BB0A8C1_0x0051B310 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B420 | 0.0% | Pending -SHC_3BB0A8C1_0x0051B570 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B680 | 100.0% | Reimplemented From 3899f6e2b7e6f4729e0d607d574964d97e5385cd Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:58 +0100 Subject: [PATCH 54/94] reimplement: SHC_3BB0A8C1_0x0051BA30 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../placeTunnelForEveryTunneler.cpp | 98 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp new file mode 100644 index 0000000000..768901a882 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp @@ -0,0 +1,98 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BA30 + void TroopValueState::placeTunnelForEveryTunneler(int attackWave) + { + int _playerID = (char)DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; + int _nTunnelers = 0; + if (!_playerID) { + _playerID = 2; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + _playerID = 2; + } + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[unitID].owner == _playerID + && !DAT_UnitsState::instance.units[unitID].dying + && DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_TUNNELER) { + _nTunnelers++; + } + } + int _tribeID = 1; + DAT_TroopValueState::instance.attackInfo.tribeIDArraySize = 0; + for (; _tribeID < countof(DAT_TribesState::instance.tribes); ++_tribeID) { + if (DAT_TribesState::instance.tribes[_tribeID].tribeState + && DAT_TribesState::instance.tribes[_tribeID].owner == _playerID + && DAT_TribesState::instance.tribes[_tribeID].attackWave == attackWave + && DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_TUNNELERS) { + DAT_TroopValueState::instance.attackInfo + .tribeIDArray[DAT_TroopValueState::instance.attackInfo.tribeIDArraySize] = _tribeID; + DAT_TroopValueState::instance.attackInfo.tribeIDArraySize++; + } + } + if (!DAT_TroopValueState::instance.attackInfo.tribeIDArraySize) { + return; + } + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.tribeIDArraySize; ++i) { + _tribeID = DAT_TroopValueState::instance.attackInfo.tribeIDArray[i]; + for (; DAT_TribesState::instance.tribes[_tribeID].size;) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::popUnitFromTribe, DAT_TribesState::ptr)(_tribeID); + } + } + // The new tribes copy their wave and counter from the last tunneler tribe emptied above. + int unitID = 0; + for (int n = 0; n < _nTunnelers; ++n) { + int const _tribe + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(_playerID, 0); + DAT_TribesState::instance.tribes[_tribe].tribeType = AI::Tribes::AITT_TUNNELERS; + DAT_TribesState::instance.tribes[_tribe].tribeBehaviorType = Map::Units::STBT_0x415; + DAT_TribesState::instance.tribes[_tribe].attackWave + = DAT_TribesState::instance.tribes[_tribeID].attackWave; + DAT_TribesState::instance.tribes[_tribe].attackInfo_someCounter1 + = DAT_TribesState::instance.tribes[_tribeID].attackInfo_someCounter1; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + for (; !(DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[unitID].owner == _playerID + && !DAT_UnitsState::instance.units[unitID].dying + && DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_TUNNELER + && !DAT_UnitsState::instance.units[unitID].tribeID);) { + ++unitID; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)(unitID, _tribe); + unitID++; + if (unitID >= DAT_UnitsState::instance.maxUnitCount) { + return; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeTunnelEntrances, this)(_tribe); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7480426dd9..37c04b6b5f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45901,7 +45901,7 @@ SHC_3BB0A8C1_0x0051B890 | 0.0% | Pending SHC_3BB0A8C1_0x0051B900 | 0.0% | Pending -SHC_3BB0A8C1_0x0051BA30 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BA30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BA90 | 0.0% | Pending From 83d4ed6a318912f8c2d8a3c13c35740d33c47ceb Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:59 +0100 Subject: [PATCH 55/94] reimplement: SHC_3BB0A8C1_0x0051B6C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/playAttackAlarmSound.cpp | 44 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp b/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp new file mode 100644 index 0000000000..593098f863 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp @@ -0,0 +1,44 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/string-macros.hpp" + +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B6C0 + void TroopValueState::playAttackAlarmSound() + { + MACRO_CALL_MEMBER( + Audio::MSS::SoundSystem_Func::playBattleGloryMusicIfConditionsMet, DAT_SoundSystemState::ptr)(); + switch (DAT_TroopValueState::instance.attackInfo.attacker) { + case 5: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playOnSpeechSfxStream, DAT_SFXState::ptr)( + S_DRUMHORN_WAV_005ABB58); + break; + case 2: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playOnSpeechSfxStream, DAT_SFXState::ptr)( + S_BATTLEHORN_WAV_005A77D8); + break; + case 3: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playOnSpeechSfxStream, DAT_SFXState::ptr)( + S_BATTLEHORN_WAV_005A77D8); + break; + case 4: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playOnSpeechSfxStream, DAT_SFXState::ptr)( + S_BATTLEHORN_WAV_005A77D8); + break; + } + DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed = TRUE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 37c04b6b5f..7df8ee66ba 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45883,7 +45883,7 @@ SHC_3BB0A8C1_0x0051B680 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B690 | 0.0% | Pending -SHC_3BB0A8C1_0x0051B6C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B6C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B700 | 0.0% | Pending From ff417dc7a17794840127807d69780b5479e19aef Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:59 +0100 Subject: [PATCH 56/94] reimplement: SHC_3BB0A8C1_0x0051F950 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSpottedEnemyTiles.cpp | 49 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp b/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp new file mode 100644 index 0000000000..cf56da1d1b --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp @@ -0,0 +1,49 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051F950 + void TroopValueState::processSpottedEnemyTiles() + { + for (int i = 0; i < countof(DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles); ++i) { + int const tile = DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].tile; + if (tile <= 0) { + continue; + } + if (MC_MAP_TILES_COUNT <= tile) { + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].tile = 0; + } + if (DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].value == 100) { + BOOLEnum const shouldLightPitch + = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::shouldLightPitchBasedOnTroopValue, this)( + tile, DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID, + DAT_TroopValueState::instance.attackInfo.playerID_0x2c850); + if (shouldLightPitch) { + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::giveLightPitchInstructionToUnitClosestToPitch, this)( + tile); + } + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].value = 99; + } else { + int const countdown = DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].value - 1; + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].value = countdown; + if (countdown <= 0) { + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[i].tile = 0; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7df8ee66ba..567a2c498f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46353,7 +46353,7 @@ SHC_3BB0A8C1_0x0051F5E0 | 0.0% | Pending SHC_3BB0A8C1_0x0051F630 | 0.0% | Pending -SHC_3BB0A8C1_0x0051F950 | 0.0% | Pending +SHC_3BB0A8C1_0x0051F950 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051F9C0 | 0.0% | Pending From 9e551252a5b2d9760c7ea499472a2244f9c2c139 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:26:59 +0100 Subject: [PATCH 57/94] reimplement: SHC_3BB0A8C1_0x0051C470 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../queueOilThrowForIdleArchers.cpp | 58 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp b/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp new file mode 100644 index 0000000000..5c0fb104a1 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp @@ -0,0 +1,58 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitInstructionType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051C470 + void TroopValueState::queueOilThrowForIdleArchers() + { + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_INVISIBLE) { + continue; + } + BOOLEnum const isAIPlayerWithKeep + = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( + DAT_UnitsState::instance.units[unitID].owner); + if (!isAIPlayerWithKeep || DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_ENGINEER + || DAT_UnitsState::instance.units[unitID].dying != 0 + || DAT_UnitsState::instance.units[unitID].state.generic != Map::Units::States::US_SIT_DOWNUnk) { + continue; + } + int radius = 3; + if (110 < DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight) { + radius = 5; + } + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeTotalUnitsWithinDistance, + DAT_PathFindingState::ptr)(DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID, 0, 0, + DAT_UnitsState::instance.units[unitID].tile, radius); + if (DAT_PathFindingState::instance.ALGO_TotalTroopValue < 10 + || DAT_PathFindingState::instance.ALGO_TotalTroopCount < 2 + || !DAT_PathFindingState::instance.field_0x64) { + continue; + } + int const targetUnitID = DAT_PathFindingState::instance.field_0x64; + DAT_UnitsState::instance.units[unitID].targetingType = Map::Units::UIT_THROW_OIL; + DAT_UnitsState::instance.units[unitID].attackAtTileX = DAT_UnitsState::instance.units[targetUnitID].x; + DAT_UnitsState::instance.units[unitID].attackAtTileY = DAT_UnitsState::instance.units[targetUnitID].y; + DAT_UnitsState::instance.units[unitID].animationFrame = 4; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 567a2c498f..cda54356de 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46097,7 +46097,7 @@ SHC_3BB0A8C1_0x0051C463 | 0.0% | Pending SHC_3BB0A8C1_0x0051C464 | 0.0% | Pending -SHC_3BB0A8C1_0x0051C470 | 0.0% | Pending +SHC_3BB0A8C1_0x0051C470 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C570 | 100.0% | Reimplemented From fbf55beee0009f5e7cf13b24dba11e97f1b14cbe Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:00 +0100 Subject: [PATCH 58/94] reimplement: SHC_3BB0A8C1_0x005198C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../recomputeTargetedBuildingTilesArray.cpp | 43 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp b/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp new file mode 100644 index 0000000000..de7dae0628 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp @@ -0,0 +1,43 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x005198C0 + void TroopValueState::recomputeTargetedBuildingTilesArray(int playerID) + { + DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArraySize = 0; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArray), 0, + DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArray); + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[unitID].isSelectable_OR_matchTime + && DAT_UnitsState::instance.units[unitID].owner == playerID + && DAT_UnitsState::instance.units[unitID].targetedBuildingTile + && DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_A_SLAVE) { + DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArray[DAT_TroopValueState::instance + .attackInfo.targetedBuildingTilesArraySize] + = DAT_UnitsState::instance.units[unitID].targetedBuildingTile; + ++DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArraySize; + if (countof(DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArray) + <= DAT_TroopValueState::instance.attackInfo.targetedBuildingTilesArraySize) { + break; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index cda54356de..d695da82ab 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45771,7 +45771,7 @@ SHC_3BB0A8C1_0x00519790 | 0.0% | Pending SHC_3BB0A8C1_0x00519850 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005198C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005198C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519960 | 100.0% | Reimplemented From 918975ded320f892cf2edff713a59304805c60a1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:00 +0100 Subject: [PATCH 59/94] reimplement: SHC_3BB0A8C1_0x0051FA70 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...computeTotalTroopValueOfTroopsNearKeep.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp new file mode 100644 index 0000000000..4841ffca6b --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp @@ -0,0 +1,57 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051FA70 + void TroopValueState::recomputeTotalTroopValueOfTroopsNearKeep() + { + for (int player = 0; + player < countof(DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueOfTroopsNearKeep); + ++player) { + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueOfTroopsNearKeep[player] = 0; + } + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + Unit* const unit = &DAT_UnitsState::instance.units[unitID]; + if (unit->logicalState == Map::Units::ULS_INVISIBLE || unit->dying + || !unit->isSelectable_OR_matchTime) { + continue; + } + UnitTypeShort const troopType = unit->unitType; + if (troopType == Map::Units::UT_E_ENGINEER || troopType == Map::Units::UT_TUNNELER + || troopType == Map::Units::UT_E_LADDER) { + continue; + } + int const playerID = unit->owner; + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry, + DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry, + unit->x, unit->y); + if (DAT_DirectionAlgorithmState::instance.distanceHigh <= 40) { + int const troopValue = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + this)((Map::Units::UnitType)unit->unitType); + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueOfTroopsNearKeep[playerID] + += troopValue; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d695da82ab..8203d0283a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46357,7 +46357,7 @@ SHC_3BB0A8C1_0x0051F950 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051F9C0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051FA70 | 0.0% | Pending +SHC_3BB0A8C1_0x0051FA70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051FB80 | 100.0% | Reimplemented From 9b6839965ec518a16ca1a1fc6b30ed6f4a0b0c02 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:01 +0100 Subject: [PATCH 60/94] reimplement: SHC_3BB0A8C1_0x0051F9C0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../recountTotalTroopValue.cpp | 41 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp b/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp new file mode 100644 index 0000000000..0f1bcd7964 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp @@ -0,0 +1,41 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::Units::UnitType; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051F9C0 + void TroopValueState::recountTotalTroopValue() + { + for (int _player = 0; + _player < countof(DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray); ++_player) { + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[_player] = 0; + } + for (int _unitID = 1; _unitID < DAT_UnitsState::instance.maxUnitCount; ++_unitID) { + if (DAT_UnitsState::instance.units[_unitID].logicalState != Map::Units::ULS_INVISIBLE + && !DAT_UnitsState::instance.units[_unitID].dying + && DAT_UnitsState::instance.units[_unitID].isSelectable_OR_matchTime + && DAT_UnitsState::instance.units[_unitID].unitType != Map::Units::UT_E_ENGINEER + && DAT_UnitsState::instance.units[_unitID].unitType != Map::Units::UT_TUNNELER + && DAT_UnitsState::instance.units[_unitID].unitType != Map::Units::UT_E_LADDER) { + int const _playerID = DAT_UnitsState::instance.units[_unitID].owner; + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[_playerID] + = DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[_playerID] + + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, this)( + (Map::Units::UnitType)DAT_UnitsState::instance.units[_unitID].unitType); + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8203d0283a..012d355611 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46355,7 +46355,7 @@ SHC_3BB0A8C1_0x0051F630 | 0.0% | Pending SHC_3BB0A8C1_0x0051F950 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051F9C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051F9C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051FA70 | 100.0% | Reimplemented From 4519b7f2f418ff79a1db078d07e35ce83a4bc955 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:01 +0100 Subject: [PATCH 61/94] reimplement: SHC_3BB0A8C1_0x0051CBD0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../redeployArchersToDefensivePositions.cpp | 55 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp b/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp new file mode 100644 index 0000000000..210919b954 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp @@ -0,0 +1,55 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051CBD0 + void TroopValueState::redeployArchersToDefensivePositions() + { + if (DAT_TroopValueState::instance.attackInfo.unitsSentToKeepFlag + || DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c <= 0) { + return; + } + for (int index = 0; index < DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520; ++index) { + int const postedUnitID = DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2c070[index]; + if (postedUnitID + && DAT_UnitsState::instance.units[postedUnitID].uid + == DAT_TroopValueState::instance.attackInfo.uidArray_0x2c200[index]) { + continue; + } + int const tile = DAT_TroopValueState::instance.attackInfo.tileArray_0x2bd50[index]; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_WALL_OR_GATEHOUSE))) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + --DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c; + int const unitID + = DAT_TroopValueState::instance.attackInfo + .unitIDArray_0x2b57c[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c]; + int const rowStartTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + DAT_TroopValueState::instance.attackInfo.uidArray_0x2c200[index] + = DAT_UnitsState::instance.units[unitID].uid; + DAT_TroopValueState::instance.attackInfo.unitIDArray_0x2c070[index] = unitID; + DAT_UnitsState::instance.units[unitID].state.generic = Map::Units::States::US_MOVE_TO_DESTINATION; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setDestinationForUnit, DAT_UnitsState::ptr)( + unitID, tile - rowStartTile, y, 0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 012d355611..65ad638b68 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46135,7 +46135,7 @@ SHC_3BB0A8C1_0x0051CA50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CAE0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051CBD0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051CBD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CC00 | 0.0% | Pending From 318309009888adc4685e7c288b0500dc2194c9a0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:01 +0100 Subject: [PATCH 62/94] reimplement: SHC_3BB0A8C1_0x0051BE60 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../registerSpottedEnemyTile.cpp | 58 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp new file mode 100644 index 0000000000..d3cf0d4764 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp @@ -0,0 +1,58 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BE60 + void TroopValueState::registerSpottedEnemyTile(int enemyTile) + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + || 0 < DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .id) { + return; + } + int const unitID = DAT_TileMapState::instance.UnitLayer[enemyTile]; + if (unitID <= 0 + || DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_UnitsState::instance.units[unitID].owner] + == -1 + || DAT_UnitsState::instance.units[unitID].isSelectable_OR_matchTime == 0) { + return; + } + int const entityID = DAT_TileMapState::instance.EntityLayer[enemyTile]; + if (entityID && DAT_EntityState::instance.entityArray[entityID].entityType == Map::Entities::ET_FIRE) { + return; + } + int freeSlot = -1; + for (int slot = 0; slot < countof(DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles); ++slot) { + int const tile = DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[slot].tile; + if (tile == enemyTile) { + return; + } + if (!tile && freeSlot == -1) { + freeSlot = slot; + } + } + if (-1 < freeSlot) { + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[freeSlot].tile = enemyTile; + DAT_TroopValueState::instance.attackInfo.spottedEnemyTiles[freeSlot].value = 100; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 65ad638b68..e339b6fb81 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45913,7 +45913,7 @@ SHC_3BB0A8C1_0x0051BDE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BE20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051BE60 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BE60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BEE0 | 0.0% | Pending From 5a706b9aa81952bfc667067a0a775dfe39d76c58 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:02 +0100 Subject: [PATCH 63/94] reimplement: SHC_3BB0A8C1_0x00518C50 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../renderAttackInfoDebugOverlay.cpp | 206 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp b/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp new file mode 100644 index 0000000000..87aa686859 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp @@ -0,0 +1,206 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00518C50 + void TroopValueState::renderAttackInfoDebugOverlay(int x, int y, int width, int height) + { + char textBuffer[1000]; + uint const securityCookie = MSVC_SecurityCookie::instance ^ (uint)textBuffer; + int const column1X = x + 2; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_Biggest_zone__005abb48, column1X, y, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.biggestZone, column1X, y, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + int const column2X = column1X + 10; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_Start_zone__005abb38, column2X, y, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.startZone, column2X, y, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + int rowY = y + 16; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_Scale_zone__005abb28, column1X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.scaleZone, column1X, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_keep_POS__005abb1c, column2X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .yEntry, + column2X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_0080FF, 18, TRUE, 0); + rowY = y + 32; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_nof_fpoints__005abb0c, column1X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.nof_fpoints, column1X, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_inv_count__005abb00, column2X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, column2X, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_nof_tribes__005abaf0, column1X + 20, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, + 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.nof_tribes[DAT_TroopValueState::instance.attackInfo.inv_count], + column1X + 20, rowY, Text::TTA_LEFT, Rendering::Colors::COL_0080FF, 18, TRUE, 0); + rowY = y + 48; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_Start_con__005abae4, column1X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.startCon, column1X, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_Keep_con__005abad8, column2X, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.keepCon, column2X, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_cas_dis__005abacc, column1X + 20, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.casDis, column1X + 20, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s_zone_size__005abac0, column1X + 30, rowY, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, TRUE, 0); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_TroopValueState::instance.attackInfo.zoneSize, column1X + 30, rowY, Text::TTA_LEFT, + Rendering::Colors::COL_0080FF, 18, TRUE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Hack_d_d_d__Scale_d_d_d__005aba94, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .hack1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .hack2, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .hack3, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .scale1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .scale2, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .scale3, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .stone1); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 64, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Town_d_d__Gate_d_d__Moat_d__005aba60, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .town1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .town3, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .gate1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .gate2, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .moat1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .moat3, + DAT_TroopValueState::instance.attackInfo.lord1, DAT_TroopValueState::instance.attackInfo.lord2); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 80, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_High_d_d_d__Arch_d_d_d__P_005aba2c, + DAT_TroopValueState::instance.attackInfo.high1, DAT_TroopValueState::instance.attackInfo.high2, + DAT_TroopValueState::instance.attackInfo.high3, DAT_TroopValueState::instance.attackInfo.arch1, + DAT_TroopValueState::instance.attackInfo.arch2, DAT_TroopValueState::instance.attackInfo.arch3, + DAT_TroopValueState::instance.attackInfo.people1, DAT_TroopValueState::instance.attackInfo.people2, + DAT_TroopValueState::instance.attackInfo.people3); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 96, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Wide_d_d_d__005aba1c, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .wide1, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .wide2, + DAT_TroopValueState::instance.attackInfo + .playerInfo[DAT_TroopValueState::instance.attackInfo.attacker - 1] + .wide3); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 112, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Archer_points_d__Next_d_005aba00, + DAT_TroopValueState::instance.attackInfo.archerPoints, + DAT_TroopValueState::instance.attackInfo.archerPointsNext); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 128, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Support_points_d__Next_d_005ab9e4, + DAT_TroopValueState::instance.attackInfo.supportPoints, + DAT_TroopValueState::instance.attackInfo.supportPointsNext); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 144, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Tent_points_d__Next_d_005ab9c8, + DAT_TroopValueState::instance.attackInfo.tentPoints, + DAT_TroopValueState::instance.attackInfo.tentPointsNext); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 160, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_ai_troops__A_d_X_d_S_d_P_d_M_005ab988, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_A, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_X, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_S, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_P, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_M, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_S2, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_K, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_L, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_E, + DAT_TroopValueState::instance.attackInfo.aiTribeSizesPerTribeType.aiTroops_T); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 176, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_killed_d_lost_d_AI_troops_d_005ab968, + DAT_GameState::instance.playerDataArray[1].troopsKilled, + DAT_GameState::instance.playerDataArray[1].troopsLost, + DAT_TroopValueState::instance.attackInfo.aiTroops); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 192, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + MACRO_CALL(OS_Func::_sprintf)(textBuffer, s_Points___d___d___d___d___d___d____005ab93c, + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[0], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[1], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[2], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[3], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[4], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[5], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[6], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[7], + DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[8]); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + textBuffer, column1X, y + 208, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e339b6fb81..d7ccf3e67e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45761,7 +45761,7 @@ SHC_3BB0A8C1_0x00518A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00518BB0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00518C50 | 0.0% | Pending +SHC_3BB0A8C1_0x00518C50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519310 | 100.0% | Reimplemented From e10d42caf41e447f5ce9596b94148043c3c037f2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:02 +0100 Subject: [PATCH 64/94] reimplement: SHC_3BB0A8C1_0x0051F340 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/scanForArcherPoints.cpp | 82 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp new file mode 100644 index 0000000000..2cec9d3309 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp @@ -0,0 +1,82 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051F340 + void TroopValueState::scanForArcherPoints() + { + int _searchRadius; + DAT_TroopValueState::instance.attackInfo.archerPoints = 0; + if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 0) { + _searchRadius = 8; + } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 2) { + _searchRadius = 5; + } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 4) { + _searchRadius = 6; + } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 8) { + _searchRadius = 7; + } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 20) { + _searchRadius = 8; + } else { + _searchRadius = 10; + } + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] == 2) { + uint const y = (uint)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + for (int _direction = 0; _direction < 4; ++_direction) { + int const neighbour + = DAT_TileMapState::instance.directionTranslationMatrix[y][_direction * 2] + tile; + if ((DAT_TileMapState::instance.AIInfoLayer[neighbour] & 0xf) == 4 + && !(DAT_TileMapState::instance.RandomLayer[neighbour] & 3)) { + uint const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + BOOLEnum hasArcherZoneFlag + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findAIZoneWithFlags, + DAT_PathFindingState::ptr)(_searchRadius, x, y, 0x10); + if (!hasArcherZoneFlag) { + DAT_TileMapState::instance.AIInfoLayer[tile] |= 0x10; + int _existingPointIndex = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::findOrReserveArcherPointSlot, this)(tile); + int const _nextPointIndex = DAT_TroopValueState::instance.attackInfo.archerPointsNext; + if (_existingPointIndex) { + DAT_TroopValueState::instance.attackInfo.archerPointArray[_existingPointIndex] + .lastSeenCounter = DAT_TroopValueState::instance.attackInfo.someCounter1; + } else { + DAT_TroopValueState::instance.attackInfo + .archerPointArray[DAT_TroopValueState::instance.attackInfo.archerPointsNext] + .x = x; + DAT_TroopValueState::instance.attackInfo.archerPointArray[_nextPointIndex].y = y; + DAT_TroopValueState::instance.attackInfo.archerPointArray[_nextPointIndex].tile + = tile; + DAT_TroopValueState::instance.attackInfo.archerPointArray[_nextPointIndex] + .lastSeenCounter = DAT_TroopValueState::instance.attackInfo.someCounter1; + } + DAT_TroopValueState::instance.attackInfo.archerPoints++; + if (200 <= DAT_TroopValueState::instance.attackInfo.archerPoints) { + return; + } + break; + } + } + } + } + } + DAT_TroopValueState::instance.attackInfo.archerPointCountPrev + = DAT_TroopValueState::instance.attackInfo.archerPoints; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d7ccf3e67e..9e36ae706b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46339,7 +46339,7 @@ SHC_3BB0A8C1_0x0051EDF0 | 0.0% | Pending SHC_3BB0A8C1_0x0051F320 | 0.0% | Pending -SHC_3BB0A8C1_0x0051F340 | 0.0% | Pending +SHC_3BB0A8C1_0x0051F340 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051F3D0 | 0.0% | Pending From 949c8d9c68de166ec8aa5332d40da4f647c3c579 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:03 +0100 Subject: [PATCH 65/94] reimplement: SHC_3BB0A8C1_0x0051F4B0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/scanForSupportPoints.cpp | 74 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp new file mode 100644 index 0000000000..79a7f4acc4 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp @@ -0,0 +1,74 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/AIInfoFlag.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051F4B0 + void TroopValueState::scanForSupportPoints() + { + DAT_TroopValueState::instance.attackInfo.supportPoints = 0; + for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { + if (DAT_TileMapState::instance.AIInfoLayer[tile] != Map::Enums::AIF_RING_1) { + continue; + } + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + for (int direction = 0; direction < 4; ++direction) { + if ((DAT_TileMapState::instance + .AIInfoLayer[DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2] + + tile] + & Map::Enums::AIF_ANY_RING) + != Map::Enums::AIF_RING_2 + || (DAT_TileMapState::instance + .RandomLayer[DAT_TileMapState::instance.directionTranslationMatrix[y][direction * 2] + + tile] + & 3)) { + continue; + } + int const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + BOOLEnum const hasSupportZoneFlag + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findAIZoneWithFlags, + DAT_PathFindingState::ptr)(8, x, y, Map::Enums::AIF_SUPPORT_POINT); + if (hasSupportZoneFlag) { + continue; + } + DAT_TileMapState::instance.AIInfoLayer[tile] |= Map::Enums::AIF_SUPPORT_POINT; + int const existingPointIndex + = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getSupportPointIndex, this)(tile); + int const nextPointIndex = DAT_TroopValueState::instance.attackInfo.supportPointsNext; + if (existingPointIndex) { + DAT_TroopValueState::instance.attackInfo.supportPointsArray[existingPointIndex].someCounter + = DAT_TroopValueState::instance.attackInfo.someCounter1; + } else { + DAT_TroopValueState::instance.attackInfo + .supportPointsArray[DAT_TroopValueState::instance.attackInfo.supportPointsNext] + .x = x; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[nextPointIndex].y = y; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[nextPointIndex].tile = tile; + DAT_TroopValueState::instance.attackInfo.supportPointsArray[nextPointIndex].someCounter + = DAT_TroopValueState::instance.attackInfo.someCounter1; + } + ++DAT_TroopValueState::instance.attackInfo.supportPoints; + if (200 <= DAT_TroopValueState::instance.attackInfo.supportPoints) { + return; + } + break; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9e36ae706b..23991980c3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46343,7 +46343,7 @@ SHC_3BB0A8C1_0x0051F340 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051F3D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051F4B0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051F4B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051F4F0 | 0.0% | Pending From b56de82bc7e36fd0fd3037254e8ff6fc1f8d2f3a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:03 +0100 Subject: [PATCH 66/94] reimplement: SHC_3BB0A8C1_0x005182A0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../searchTribeWithProperties.cpp | 49 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp new file mode 100644 index 0000000000..d33f51e6aa --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp @@ -0,0 +1,49 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x005182A0 + BOOLEnum TroopValueState::searchTribeWithProperties(int attackID) + { + if (DAT_TroopValueState::instance.attackInfo.nof_tribes[attackID] == 0) { + return FALSE; + } + int owner = 0; + for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState == 2 + && DAT_TribesState::instance.tribes[tribeID].owner + && DAT_TribesState::instance.tribes[tribeID].owner + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + owner = DAT_TribesState::instance.tribes[tribeID].owner; + break; + } + } + if (!owner) { + DAT_TroopValueState::instance.attackInfo.nof_tribes[attackID] = 0; + DAT_TroopValueState::instance.attackInfo.unknownByteArray02[attackID] = 0; + return FALSE; + } + DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID] = owner; + DAT_TroopValueState::instance.attackInfo.attacker + = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 10000; + DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_ASSIGNING_TARGETS; + DAT_TroopValueState::instance.attackInfo.value10 = 10; + return TRUE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 23991980c3..6ea1fcc0cd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45741,7 +45741,7 @@ SHC_3BB0A8C1_0x00518130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00518180 | 0.0% | Pending -SHC_3BB0A8C1_0x005182A0 | 0.0% | Pending +SHC_3BB0A8C1_0x005182A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00518350 | 100.0% | Reimplemented From 3e4a683c2d9cf7430f429179c28329fc54e84232 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:03 +0100 Subject: [PATCH 67/94] reimplement: SHC_3BB0A8C1_0x0051D0D0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...ackingPatrolTribeToComputedDestination.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp b/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp new file mode 100644 index 0000000000..aeb71663b0 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp @@ -0,0 +1,57 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D0D0 + void TroopValueState::sendAttackingPatrolTribeToComputedDestination(int tribeID) + { + int const targetUnitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 1); + int destinationTile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, DAT_UnitsState::instance.units[targetUnitID].owner, 12, + 1); + if (destinationTile <= 0) { + destinationTile = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[targetUnitID].x, + DAT_UnitsState::instance.units[targetUnitID].y, DAT_UnitsState::instance.units[targetUnitID].owner, + 30, 1); + if (destinationTile <= 0) { + destinationTile = MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::pathfindingRelated49ff20, DAT_PathFindingState::ptr)( + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, + DAT_UnitsState::instance.units[targetUnitID].owner, 50, 1); + } + } + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updatePathLinkageTileMap, DAT_BuildingsState::ptr)( + 0); + if (0 < destinationTile) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + destinationTile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance + .tileTranslationMatrix_YComponent[destinationTile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[destinationTile], 0, 0, + Map::Units::Instructions::UMSE_0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6ea1fcc0cd..6b79ef4e06 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46147,7 +46147,7 @@ SHC_3BB0A8C1_0x0051CF90 | 0.0% | Pending SHC_3BB0A8C1_0x0051D020 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D0D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D0D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D1C0 | 100.0% | Reimplemented From b7cb50aa836a6deab6a3e60a6b6000bae79b6bf5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:04 +0100 Subject: [PATCH 68/94] reimplement: SHC_3BB0A8C1_0x0051A2D0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TroopValueState/setGate2.cpp | 27 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp new file mode 100644 index 0000000000..3677f1dc18 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp @@ -0,0 +1,27 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A2D0 + void TroopValueState::setGate2(BOOLEnum includeAll, int playerID) + { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gate2 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].some1000ArrayIndex_2; + ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gateValuesArray[i].score < 5999 + && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gateValuesArray[i].unitID == 0 + || includeAll)) { + ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gate2; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6b79ef4e06..dcb1aa7a18 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45807,7 +45807,7 @@ SHC_3BB0A8C1_0x0051A140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A220 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051A2D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A2D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A330 | 100.0% | Reimplemented From ba4f8c61ded47a5bfd1d11c4800aceb5ad955ac5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:04 +0100 Subject: [PATCH 69/94] reimplement: SHC_3BB0A8C1_0x0051A720 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TroopValueState/setMoat3.cpp | 26 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp new file mode 100644 index 0000000000..34928d1f41 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp @@ -0,0 +1,26 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A720 + void TroopValueState::setMoat3(BOOLEnum includeAll, int playerID) + { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moatValuesArray[i].score < 5999 + && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moatValuesArray[i].unitID == 0 + || includeAll)) { + ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat3; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index dcb1aa7a18..3d017ebefe 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45819,7 +45819,7 @@ SHC_3BB0A8C1_0x0051A5B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A630 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A720 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A780 | 100.0% | Reimplemented From f4394add5e0ac5558e0ee599862d84f7950ffa1a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:05 +0100 Subject: [PATCH 70/94] reimplement: SHC_3BB0A8C1_0x00519790 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../setRallyPointForLaddermenTribe.cpp | 47 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp new file mode 100644 index 0000000000..e4ac2fe29f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp @@ -0,0 +1,47 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519790 + void TroopValueState::setRallyPointForLaddermenTribe(int laddermenTribeID) + { + int laddermenTribeCount = 0; + for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState != 0) { + if (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::isFullIDEqualsToMinus1, DAT_GameState::ptr)( + DAT_TribesState::instance.tribes[tribeID].owner) + && DAT_TribesState::instance.tribes[tribeID].tribeType == AI::Tribes::AITT_LADDERMEN) { + ++laddermenTribeCount; + if (laddermenTribeCount + == DAT_TribesState::instance.tribes[laddermenTribeID].someCounter1 + 1) { + int const _unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeNextRallyPointDestination, + DAT_PathFindingState::ptr)(-1, (int)(DAT_UnitsState::instance.units[_unitID].x), + (int)(DAT_UnitsState::instance.units[_unitID].y)); + short const _rallyPointY = (short)DAT_PathFindingState::instance.ALG_ResultY; + DAT_TribesState::instance.tribes[laddermenTribeID].rallyPointArray[0][0] + = (short)DAT_PathFindingState::instance.ALG_ResultX; + DAT_TribesState::instance.tribes[laddermenTribeID].rallyPointArray[0][1] = _rallyPointY; + return; + } + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3d017ebefe..460e3664dd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45767,7 +45767,7 @@ SHC_3BB0A8C1_0x00519310 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519690 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00519790 | 0.0% | Pending +SHC_3BB0A8C1_0x00519790 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519850 | 100.0% | Reimplemented From 6044075fb01ee714aef01fce7b3af92d057cb860 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:05 +0100 Subject: [PATCH 71/94] reimplement: SHC_3BB0A8C1_0x00519DE0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TroopValueState/setScale3.cpp | 27 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp new file mode 100644 index 0000000000..e031634c9e --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp @@ -0,0 +1,27 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519DE0 + void TroopValueState::setScale3(BOOLEnum includeAll, int playerID) + { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score < 5999 + && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].unitID + == 0 + || includeAll)) { + ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale3; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 460e3664dd..472e9124f2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45791,7 +45791,7 @@ SHC_3BB0A8C1_0x00519C40 | 0.0% | Pending SHC_3BB0A8C1_0x00519CC0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00519DE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00519DE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519E40 | 100.0% | Reimplemented From f976d94b5dd7b9b3d5cb3423b1b62548b0edc3bf Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:05 +0100 Subject: [PATCH 72/94] reimplement: SHC_3BB0A8C1_0x00519F50 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TroopValueState/setTown2.cpp | 25 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp b/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp new file mode 100644 index 0000000000..6c0a33ed32 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp @@ -0,0 +1,25 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00519F50 + void TroopValueState::setTown2(BOOLEnum includeAll, int playerID) + { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].townValuesArray[i].unitID == 0 + || includeAll) { + ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town3; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 472e9124f2..3cb800d103 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45795,7 +45795,7 @@ SHC_3BB0A8C1_0x00519DE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519E40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00519F50 | 0.0% | Pending +SHC_3BB0A8C1_0x00519F50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00519FB0 | 100.0% | Reimplemented From 48d2949971ec39448bc5ff9ab477e5fd0233a293 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:06 +0100 Subject: [PATCH 73/94] reimplement: SHC_3BB0A8C1_0x0051A550 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TroopValueState/setWide3.cpp | 26 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp new file mode 100644 index 0000000000..2ad00176f2 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp @@ -0,0 +1,26 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" + +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051A550 + void TroopValueState::setWide3(BOOLEnum includeAll, int playerID) + { + DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide3 = 0; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide2; ++i) { + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wideValuesArray[i].score < 5999 + && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wideValuesArray[i].unitID == 0 + || includeAll)) { + ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide3; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3cb800d103..408a6fa06b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45813,7 +45813,7 @@ SHC_3BB0A8C1_0x0051A330 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A490 | 0.0% | Pending -SHC_3BB0A8C1_0x0051A550 | 0.0% | Pending +SHC_3BB0A8C1_0x0051A550 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051A5B0 | 100.0% | Reimplemented From 8b17f51f45cf049a1e8635da4011af10ab081b34 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:06 +0100 Subject: [PATCH 74/94] reimplement: SHC_3BB0A8C1_0x0051BF20 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../shouldLightPitchBasedOnTroopValue.cpp | 25 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp b/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp new file mode 100644 index 0000000000..0e636b1b1d --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp @@ -0,0 +1,25 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051BF20 + BOOLEnum TroopValueState::shouldLightPitchBasedOnTroopValue(int tile, int playerID, int unusedUnk) + { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeTotalUnitsWithinDistance, + DAT_PathFindingState::ptr)(playerID, 1, 1, tile, 10); + int const nearbyTroopValue = DAT_PathFindingState::instance.ALGO_TotalTroopValue; + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeTotalUnitsWithinDistance, + DAT_PathFindingState::ptr)(playerID, 0, 1, tile, 6); + return DAT_PathFindingState::instance.ALGO_TotalTroopValue > nearbyTroopValue * 2; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 408a6fa06b..f06e7820fb 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45917,7 +45917,7 @@ SHC_3BB0A8C1_0x0051BE60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BEE0 | 0.0% | Pending -SHC_3BB0A8C1_0x0051BF20 | 0.0% | Pending +SHC_3BB0A8C1_0x0051BF20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051BF70 | 100.0% | Reimplemented From 315cc54f915ce5057269e0119e7989e4623ec3ee Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:07 +0100 Subject: [PATCH 75/94] reimplement: SHC_3BB0A8C1_0x0051D020 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../trySendKnightTribeToAttack.cpp | 50 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp b/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp new file mode 100644 index 0000000000..847fc28c1b --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp @@ -0,0 +1,50 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D020 + void TroopValueState::trySendKnightTribeToAttack() + { + int const playerID = DAT_TroopValueState::instance.attackInfo.playerID_0x2c850; + if (DAT_TroopValueState::instance.attackInfo.knightTribeCount <= 0 + || DAT_TroopValueState::instance.attackInfo.attackInfoTickWrapCount < 10 + || (DAT_TroopValueState::instance.attackInfo.attackInfoTickWrapCount < 100 + && DAT_GameState::instance.playerDataArray[playerID].previousSiegeWeaponsCount <= 0) + || (SEC_RNG::instance.currentNumber2 & 7)) { + return; + } + int const siegeWeaponsCount = DAT_GameState::instance.playerDataArray[playerID].previousSiegeWeaponsCount; + --DAT_TroopValueState::instance.attackInfo.knightTribeCount; + int const tribeID = DAT_TroopValueState::instance.attackInfo + .knightTribeArray[DAT_TroopValueState::instance.attackInfo.knightTribeCount]; + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + int unitID; + if (siegeWeaponsCount) { + unitID = MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::findActiveSiegeEngineForTribe, DAT_UnitsState::ptr)(playerID); + } else { + unitID = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::getLivingSelectableUnit, DAT_UnitsState::ptr)( + playerID); + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)(tribeID, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, 0, 0, + Map::Units::Instructions::UMSE_0); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f06e7820fb..f77a985be3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46145,7 +46145,7 @@ SHC_3BB0A8C1_0x0051CE50 | 0.0% | Pending SHC_3BB0A8C1_0x0051CF90 | 0.0% | Pending -SHC_3BB0A8C1_0x0051D020 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D0D0 | 100.0% | Reimplemented From c93bfe8297a1dc47ed9f4efa66081275051baf15 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:07 +0100 Subject: [PATCH 76/94] reimplement: SHC_3BB0A8C1_0x0051CF90 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../trySendMacemenTribeToAttack.cpp | 49 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp b/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp new file mode 100644 index 0000000000..d1bfcad9c0 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp @@ -0,0 +1,49 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051CF90 + void TroopValueState::trySendMacemenTribeToAttack() + { + int const playerID = DAT_TroopValueState::instance.attackInfo.playerID_0x2c850; + if (DAT_TroopValueState::instance.attackInfo.macemenTribeCount <= 0 + || DAT_TroopValueState::instance.attackInfo.attackInfoTickWrapCount < 4 + || (SEC_RNG::instance.currentNumber2 & 7)) { + return; + } + BOOLEnum const isNotCampaignMission = DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION; + --DAT_TroopValueState::instance.attackInfo.macemenTribeCount; + int const macemenTribeID + = DAT_TroopValueState::instance.attackInfo + .macemenTribeArray[DAT_TroopValueState::instance.attackInfo.macemenTribeCount]; + DAT_TribesState::instance.tribes[macemenTribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + if (isNotCampaignMission || 15 <= DAT_GameCore::instance.missionNumber1to20) { + int const unitID = MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::getLivingSelectableUnit, DAT_UnitsState::ptr)(playerID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + macemenTribeID, DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + 0, 0, Map::Units::Instructions::UMSE_0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f77a985be3..9feec1cf30 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46143,7 +46143,7 @@ SHC_3BB0A8C1_0x0051CCB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051CE50 | 0.0% | Pending -SHC_3BB0A8C1_0x0051CF90 | 0.0% | Pending +SHC_3BB0A8C1_0x0051CF90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D020 | 100.0% | Reimplemented From 3dd7d76892e8dc497d26dbd7959f6bc35c92ceaf Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:07 +0100 Subject: [PATCH 77/94] reimplement: SHC_3BB0A8C1_0x0051D730 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../updateActiveAttackWaveState.cpp | 53 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp new file mode 100644 index 0000000000..920382bc2c --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp @@ -0,0 +1,53 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D730 + void TroopValueState::updateActiveAttackWaveState(int attackWave) + { + int playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + playerID = 2; + } + int const ticker = DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave]; + int const nextTicker = ticker + 1; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = nextTicker; + if (0 < ticker) { + if (100 < nextTicker) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::applyTribeBehaviorType, DAT_TribesState::ptr)( + attackWave, Map::Units::STBT_0x400); + } + if (1000 < DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave]) { + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = 0; + } + return; + } + ++DAT_TroopValueState::instance.attackInfo.someCounter1; + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::removeSiegeBuildings, DAT_BuildingsState::ptr)( + attackWave, playerID); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::exitSiegeEquipmentForWave, this)(attackWave); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackWave, 1000, 10000, Map::Units::STBT_0x3ff); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3ff, Map::Units::STBT_1, 0, 10); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9feec1cf30..2d0188b403 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46165,7 +46165,7 @@ SHC_3BB0A8C1_0x0051D680 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D690 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051D730 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D730 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D7F0 | 0.0% | Pending From 3cd205bbdfcc337b7204ffa4510a2cc184b1045d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:08 +0100 Subject: [PATCH 78/94] reimplement: SHC_3BB0A8C1_0x0051C2D0 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../updateArcherBrazierProximityFlags.cpp | 42 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp new file mode 100644 index 0000000000..cd2a8b0f21 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp @@ -0,0 +1,42 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051C2D0 + void TroopValueState::updateArcherBrazierProximityFlags() + { + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + Unit* const unit = &DAT_UnitsState::instance.units[unitID]; + if (unit->logicalState == Map::Units::ULS_INVISIBLE) { + continue; + } + BOOLEnum const isAIPlayerWithKeep + = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)(unit->owner); + if (!isAIPlayerWithKeep) { + continue; + } + if ((unit->unitType == Map::Units::UT_E_ARCHER || unit->unitType == Map::Units::UT_A_ARCHER) + && !unit->dying) { + BOOLEnum const isBrazierNearby = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::isBrazierNearby, + DAT_EntityState::ptr)(unit->x, unit->y, unit->buildingHeight + unit->terrainOrClimbHeight); + unit->field_0x40d = isBrazierNearby != 0; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2d0188b403..c9bb784aa9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45923,7 +45923,7 @@ SHC_3BB0A8C1_0x0051BF70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C1A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051C2D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051C2D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051C360 | 100.0% | Reimplemented From e6190e9fed743566d62824de598a6c976a903f83 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:08 +0100 Subject: [PATCH 79/94] reimplement: SHC_3BB0A8C1_0x0051FE80 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/updateAttackInfoTick.cpp | 72 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp new file mode 100644 index 0000000000..ec9c28f971 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp @@ -0,0 +1,72 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051FE80 + void TroopValueState::updateAttackInfoTick() + { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID = 1; + DAT_TroopValueState::instance.attackInfo.playerID_0x2c850 = 2; + } else { + DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID + = MACRO_CALL(Map::Units_Func::FindFirstOpponentWithKeep)(); + DAT_TroopValueState::instance.attackInfo.playerID_0x2c850 = 1; + } + if (!DAT_TroopValueState::instance.attackInfo.aiTickPhase) { + DAT_TroopValueState::instance.attackInfo.unitsSentToKeepFlag = FALSE; + DAT_TroopValueState::instance.attackInfo.attackInfoTickWrapCount + = DAT_TroopValueState::instance.attackInfo.aiTickPhase; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::collectArcherUnitsByLocation, this)(); + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::assignMacemenAndKnightsNotFromPlayer1ToTribes, this)(); + } else if (DAT_TroopValueState::instance.attackInfo.aiTickPhase == 1) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::updateArcherBrazierProximityFlags, this)(); + } else if (DAT_TroopValueState::instance.attackInfo.aiTickPhase != 50 + && DAT_TroopValueState::instance.attackInfo.aiTickPhase != 100) { + if (DAT_TroopValueState::instance.attackInfo.aiTickPhase == 70) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::trySendMacemenTribeToAttack, this)(); + } else if (DAT_TroopValueState::instance.attackInfo.aiTickPhase == 60) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::trySendKnightTribeToAttack, this)(); + } + } + if (!(DAT_TroopValueState::instance.attackInfo.aiTickPhase & 0xf)) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::queueOilThrowForIdleArchers, this)(); + } + if ((DAT_TroopValueState::instance.attackInfo.aiTickPhase & 0xf) == 8) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::redeployArchersToDefensivePositions, this)(); + } + ++DAT_TroopValueState::instance.attackInfo.aiTickPhase; + if (100 < DAT_TroopValueState::instance.attackInfo.aiTickPhase) { + ++DAT_TroopValueState::instance.attackInfo.attackInfoTickWrapCount; + DAT_TroopValueState::instance.attackInfo.aiTickPhase = 2; + } + BOOLEnum const canMoveFromKeep = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::unitsCanMoveFromKeepOfPlayerToAnotherArea, DAT_GameState::ptr)(1); + if (canMoveFromKeep && !DAT_TroopValueState::instance.attackInfo.unitsSentToKeepFlag) { + DAT_TroopValueState::instance.attackInfo.unitsSentToKeepFlag = TRUE; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::commandUnitsToMoveToKeep, this)(); + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::processSpottedEnemyTiles, this)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c9bb784aa9..20925a391f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46363,7 +46363,7 @@ SHC_3BB0A8C1_0x0051FB80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051FB90 | 0.0% | Pending -SHC_3BB0A8C1_0x0051FE80 | 0.0% | Pending +SHC_3BB0A8C1_0x0051FE80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051FF90 | 100.0% | Reimplemented From 3f86fe18df24fdaab71a336fa867cc33b960ca81 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:09 +0100 Subject: [PATCH 80/94] reimplement: SHC_3BB0A8C1_0x00520450 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../updateInProgressAttackWave.cpp | 77 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp new file mode 100644 index 0000000000..acba3fd88c --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp @@ -0,0 +1,77 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00520450 + void TroopValueState::updateInProgressAttackWave(int attackID) + { + // The original reads the wave's player here, before any of the calls below. + int const playerID = (char)DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + BOOLEnum isAttackMostlyAlive = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::isLessThanPercentageOfTribesInAttackDying, this)(attackID, (int)(50)); + if (isAttackMostlyAlive && !DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::playAttackAlarmSound, this)(); + } + if (!DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed) { + return; + } + if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] == 0) { + DAT_TroopValueState::instance.attackInfo.someCounter1++; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::aiRecomputeAttacks2, this)(TRUE, attackID); + if (0 < DAT_TroopValueState::instance.attackInfo.tentPoints) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeSiegeTentsAndAssignEngineers, this)( + attackID, TRUE); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeTunnelForEveryTunneler, this)(attackID); + } else { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeSiegeTentsAndAssignEngineers, this)( + attackID, FALSE); + } + int tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town3; + if (tribeSizeSumLimit) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 2, tribeSizeSumLimit, Map::Units::STBT_0x3f5); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3f5, Map::Units::STBT_1, 0, 20); + } + if (DAT_TroopValueState::instance.attackInfo.people3) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( + attackID, 2, DAT_TroopValueState::instance.attackInfo.people3, Map::Units::STBT_0x3fb); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( + Map::Units::STBT_0x3fb, Map::Units::STBT_1, 5, 30); + } + } + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID]++; + if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] + >= DAT_AttackInfoDefinedData::instance + .AttackWaveDurationPerAttacker[DAT_TroopValueState::instance.attackInfo.attacker]) { + BOOLEnum isMission39 = DAT_GameCore::instance.missionNumber1to20 == 39; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 10000; + DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_ASSIGNING_TARGETS; + DAT_TroopValueState::instance.attackInfo.value10 = 0; + if ((isMission39) && (DAT_TroopValueState::instance.attackInfo.attacker == 4)) { + /* + "we are the macemen" + */ + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)("Mace_s4.wav"); + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 20925a391f..5100105c1c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46371,7 +46371,7 @@ SHC_3BB0A8C1_0x005200A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005202B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00520450 | 0.0% | Pending +SHC_3BB0A8C1_0x00520450 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005205A0 | 0.0% | Pending From 2dc1a1a8db63776baf69c8174c5d1511f59afaa0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:27:09 +0100 Subject: [PATCH 81/94] reimplement: SHC_3BB0A8C1_0x00522590 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Units/TribesState/addUnitToTribe.cpp | 30 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp diff --git a/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp b/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp new file mode 100644 index 0000000000..6cff85f557 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp @@ -0,0 +1,30 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522590 + void TribesState::addUnitToTribe(uint unitID, int tribeID) + { + this->tribes[tribeID].size++; + int const bitFlagsIndex = (int)unitID / 16; + int const bitMaskIndex = (int)unitID % 16; + this->tribes[tribeID].unitSelectionBitMasked[bitFlagsIndex] + |= DAT_UnitSelectionDefinedData::instance.BitMaskHelper[bitMaskIndex]; + if (this->tribes[tribeID].selectionTargetUnitID == 0) { + this->tribes[tribeID].selectionTargetUnitID = unitID; + } + DAT_UnitsState::instance.units[unitID].selectionTargetUnitID = this->tribes[tribeID].selectionTargetUnitID; + DAT_UnitsState::instance.units[unitID].tribeID = tribeID; + DAT_UnitsState::instance.units[unitID].tribeUID = this->tribes[tribeID].uid; + DAT_UnitsState::instance.units[unitID].idInTribe = this->tribes[tribeID].size; + MACRO_CALL_MEMBER(TribesState_Func::setWhetherTribeContainsAnyUnits, this)(tribeID); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5100105c1c..73fc6366dd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46791,7 +46791,7 @@ SHC_3BB0A8C1_0x00522520 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522550 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522590 | 0.0% | Pending +SHC_3BB0A8C1_0x00522590 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522630 | 0.0% | Pending From bf2c194a2ef85fa978fd34dc64c706c75485c61c Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:42:06 +0100 Subject: [PATCH 82/94] Restore the comment explaining tribeID's early initialisation in placeSiegeTentsAndAssignEngineers The style pass dropped #528's comment, but the statement order it explains is still load-bearing for the 100% match. Comment-only change. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp index 4277322e4b..8f54013464 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp @@ -68,6 +68,7 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.createTribeAmount++; engineerTotal += engineers; } + // tribeID is initialised before the size reset: the original loads 1 with a mov, not as lea from the zero int tribeID = 1; DAT_TroopValueState::instance.attackInfo.tribeIDArraySize = 0; for (; tribeID < countof(DAT_TribesState::instance.tribes); tribeID++) { From b8764e558cd2d59e8803af91169f90085b32e8cb Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:33:22 +0100 Subject: [PATCH 83/94] reimplement: SHC_3BB0A8C1_0x00518180 96.88% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../initializeAttackWaveSlot.cpp | 50 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp new file mode 100644 index 0000000000..315fc9684f --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp @@ -0,0 +1,50 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Enums/AttackWaveState.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00518180 + void TroopValueState::initializeAttackWaveSlot(int attackWave, int signpostChoice) + { + DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] = Map::Enums::AWS_GATHERING; + DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] = 0; + DAT_TroopValueState::instance.attackInfo.someIntArray2[attackWave - 1] = 0; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave]), 0, + &DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave]); + DAT_TroopValueState::instance.attackInfo.aiTickPhase = 0; + DAT_TroopValueState::instance.attackInfo.counter = 16; + DAT_TroopValueState::instance.attackInfo.archerPointCountPrev = -1; + DAT_TroopValueState::instance.attackInfo.delayedWaveAssignmentCount = 0; + DAT_TroopValueState::instance.attackInfo.buildingDamageEventCount = 0; + DAT_TroopValueState::instance.attackInfo.enemyUnitsInsideCastleCount = 0; + for (int player = 0; player < countof(DAT_TroopValueState::instance.attackInfo.playerInfo); ++player) { + DAT_TroopValueState::instance.attackInfo.playerInfo[player].field22_0x3ea4 = 0; + DAT_TroopValueState::instance.attackInfo.playerInfo[player].field_0x3ea8 = 0; + } + int randomSignpost = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::pickRandomAccessibleSignpostEntry, DAT_GameState::ptr)(); + int activeSignposts + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::countActiveSignposts, DAT_GameState::ptr)(); + if (signpostChoice <= activeSignposts && signpostChoice) { + DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackWave] = signpostChoice - 1; + } else { + DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackWave] = randomSignpost; + } + DAT_TroopValueState::instance.attackInfo.field_0x469d4 + = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackWave]; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1af6268df4..23bf7da19f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45739,7 +45739,7 @@ SHC_3BB0A8C1_0x0051812A | 0.0% | Pending SHC_3BB0A8C1_0x00518130 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00518180 | 0.0% | Pending +SHC_3BB0A8C1_0x00518180 | 96.9% | Register allocation differs SHC_3BB0A8C1_0x005182A0 | 100.0% | Reimplemented From e3a8a14e41f1c3d99e637b351c1d7907edf881ff Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:33:22 +0100 Subject: [PATCH 84/94] reimplement: SHC_3BB0A8C1_0x0051AF70 80.49% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../pruneStaleArcherPoints.cpp | 45 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp new file mode 100644 index 0000000000..b61af92659 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp @@ -0,0 +1,45 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051AF70 + void TroopValueState::pruneStaleArcherPoints() + { + for (int slot = 1; slot < countof(DAT_TroopValueState::instance.attackInfo.archerPointArray) - 1; ++slot) { + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].lastSeenCounter + != DAT_TroopValueState::instance.attackInfo.someCounter1) { + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]); + } else { + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID != 0 + && MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeUID) + == FALSE) { + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]); + } + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].claimCooldown > 0) { + DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].claimCooldown--; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 23bf7da19f..55b6f5bd86 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45853,7 +45853,7 @@ SHC_3BB0A8C1_0x0051AE90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051AF20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051AF70 | 0.0% | Pending +SHC_3BB0A8C1_0x0051AF70 | 80.5% | Register allocation differs SHC_3BB0A8C1_0x0051AF80 | 0.0% | Pending From 8131abee4f5695a0b4dcd300788221cd2597e162 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:33:23 +0100 Subject: [PATCH 85/94] reimplement: SHC_3BB0A8C1_0x0051B110 80.49% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../pruneStaleSupportPoints.cpp | 44 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp new file mode 100644 index 0000000000..76d4967d11 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp @@ -0,0 +1,44 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B110 + void TroopValueState::pruneStaleSupportPoints() + { + for (int slot = 1; slot < countof(DAT_TroopValueState::instance.attackInfo.supportPointsArray) - 1; + ++slot) { + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].someCounter + != DAT_TroopValueState::instance.attackInfo.someCounter1) { + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]); + } else { + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID != 0 + && MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeUID) + == FALSE) { + MACRO_CALL_MEMBER( + OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]); + } + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].three > 0) { + DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].three--; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 55b6f5bd86..f344f8d3ef 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45861,7 +45861,7 @@ SHC_3BB0A8C1_0x0051AFF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B0C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051B110 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B110 | 80.5% | Register allocation differs SHC_3BB0A8C1_0x0051B120 | 0.0% | Pending From c74ae64d819f26221c38f9d6af566233d2630c18 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:33:23 +0100 Subject: [PATCH 86/94] reimplement: SHC_3BB0A8C1_0x0051B290 80.49% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/pruneStaleTentPoints.cpp | 45 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp new file mode 100644 index 0000000000..bf18f43d52 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp @@ -0,0 +1,45 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" + +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0051B290 + void TroopValueState::pruneStaleTentPoints() + { + // The original walks slots 1..1999 (end 0x17A52B4): the tent point table really has 2000 entries, + // tentPointsValues is declared with only 216. + for (int slot = 1; slot < countof(DAT_TroopValueState::instance.attackInfo.tentPointsValues) - 1; ++slot) { + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].someCounter + != DAT_TroopValueState::instance.attackInfo.someCounter1) { + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]); + } else { + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID != 0 + && MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeUID) + == FALSE) { + MACRO_CALL_MEMBER( + OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]), 0, + &DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]); + } + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].three > 0) { + DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].three--; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f344f8d3ef..49f1336595 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -45869,7 +45869,7 @@ SHC_3BB0A8C1_0x0051B190 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051B240 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051B290 | 0.0% | Pending +SHC_3BB0A8C1_0x0051B290 | 80.5% | Register allocation differs SHC_3BB0A8C1_0x0051B2A0 | 0.0% | Pending From 42afb3ff0358a96f5ba4f25fc454243fe48e6a3b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:33:23 +0100 Subject: [PATCH 87/94] reimplement: SHC_3BB0A8C1_0x0051D7F0 97.47% Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...updateTribeBehaviorBasedOnBehaviorType.cpp | 449 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 450 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp new file mode 100644 index 0000000000..ae0b3d9c56 --- /dev/null +++ b/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp @@ -0,0 +1,449 @@ +#include "../TroopValueState.func.hpp" + +#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using Map::Buildings::BuildingTypeShort; + using Map::Units::Behavior::UnitStanceEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0051D7F0 + void TroopValueState::updateTribeBehaviorBasedOnBehaviorType(int tribeID) + { + short const tribeWave = DAT_TribesState::instance.tribes[tribeID].attackWave; + if (tribeWave && tribeWave < DAT_TroopValueState::instance.attackInfo.index) { + DAT_TribesState::instance.tribes[tribeID].attackWave + = (short)DAT_TroopValueState::instance.attackInfo.index; + } + int const attackWave = DAT_TribesState::instance.tribes[tribeID].attackWave; + DAT_TroopValueState::instance.attackInfo.nof_tribes[attackWave]++; + if (DAT_TribesState::instance.tribes[tribeID].percentageMovingUnk <= 0) { + DAT_TroopValueState::instance.attackInfo.unknownByteArray02[attackWave]++; + } + int const behaviorType = DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType; + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter++; + short const updateCounter = DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter; + DAT_TribesState::instance.tribes[tribeID].field_0x2ae = 0; + switch (behaviorType) { + case Map::Units::STBT_3: + if (MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::stopTribeMovementAndCheckIdle, DAT_TribesState::ptr)(tribeID)) { + int const signpost + = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TribesState::instance.tribes[tribeID].attackWave]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, + DAT_GameState::instance.mapAndTime + .unitMoveDestinationXYPairs[signpost][DAT_TribesState::instance.tribes[tribeID].someIndex] + .x, + DAT_GameState::instance.mapAndTime + .unitMoveDestinationXYPairs[signpost][DAT_TribesState::instance.tribes[tribeID].someIndex] + .y, + 0, 0, Map::Units::Instructions::UMSE_0); + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_4; + } + return; + case Map::Units::STBT_4: + case Map::Units::STBT_6: + return; + case Map::Units::STBT_5: + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, + DAT_GameState::instance.mapAndTime + .somePairArray[DAT_TribesState::instance.tribes[tribeID].someIndex] + .x, + DAT_GameState::instance.mapAndTime + .somePairArray[DAT_TribesState::instance.tribes[tribeID].someIndex] + .y, + 0, 0, Map::Units::Instructions::UMSE_0); + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_6; + } + return; + case Map::Units::STBT_7: + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + int vector; + for (vector = 0; vector < 49; ++vector) { + if (DAT_GameState::instance.mapAndTime + .attackVectors[DAT_GameSynchronyState::instance.currentPlayerSlotID][vector] + .tribeID + == 0) { + DAT_GameState::instance.mapAndTime + .attackVectors[DAT_GameSynchronyState::instance.currentPlayerSlotID][vector] + .tribeID = tribeID; + break; + } + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, + DAT_GameState::instance.mapAndTime + .attackVectors[DAT_GameSynchronyState::instance.currentPlayerSlotID][vector] + .x, + DAT_GameState::instance.mapAndTime + .attackVectors[DAT_GameSynchronyState::instance.currentPlayerSlotID][vector] + .y, + 0, 0, Map::Units::Instructions::UMSE_0); + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_8; + } + return; + case Map::Units::STBT_8: + if (DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID] + .totalSizeOfPathPlan + < 25) { + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + } + return; + case Map::Units::STBT_1: + if (updateCounter >= 30) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + if (MACRO_CALL_MEMBER(Map::Units::TribesState_Func::isTribeUnitBlockedByOtherUnit, + DAT_TribesState::ptr)(tribeID)) { + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::moveTribeToNearbyClearTile, DAT_TribesState::ptr)(tribeID); + } + } + return; + case Map::Units::STBT_0x3f2: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_STAND_GROUND; + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3f2); + } + return; + case Map::Units::STBT_0x3ff: + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + int const signpost + = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray[attackWave]; + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][0].x, + DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][0].y, 0, 0, + Map::Units::Instructions::UMSE_0); + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_0x400; + } + return; + case Map::Units::STBT_0x3f6: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_STAND_GROUND; + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3f6); + } + return; + case Map::Units::STBT_0x413: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_STAND_GROUND; + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x413); + } + return; + case Map::Units::STBT_0x414: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_STAND_GROUND; + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x414); + } + return; + case Map::Units::STBT_0x3f5: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_STAND_GROUND; + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3f5); + } + return; + case Map::Units::STBT_0x3fb: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3fb); + } + return; + case Map::Units::STBT_0x401: + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + if (MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::allUnitsReachedTheirDestination, DAT_TribesState::ptr)(tribeID)) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::buildRallyPointsFromSiegeUnits, this)(tribeID); + short const rallyPointCount = DAT_TribesState::instance.tribes[tribeID].rallyPointCount; + int rallyPoint = DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex + 1; + if (rallyPoint >= rallyPointCount) { + rallyPoint = 0; + } + int const rallyX = DAT_TribesState::instance.tribes[tribeID].rallyPointArray[rallyPoint][0]; + int const rallyY = DAT_TribesState::instance.tribes[tribeID].rallyPointArray[rallyPoint][1]; + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = (short)rallyPoint; + if (rallyPointCount > 1 + && DAT_UnitsState::instance + .units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID] + .closestEnemyMicroDistance + > 96) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, rallyX, rallyY, 0, 0, Map::Units::Instructions::UMSE_0); + } + } + return; + case Map::Units::STBT_0x3fe: + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + return; + case Map::Units::STBT_0x3fd: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3fd); + } + return; + case Map::Units::STBT_0x416: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::stopTribeMovementAndCheckIdle, DAT_TribesState::ptr)(tribeID)) { + int const keep + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] + .id; + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + if (keep <= 0) { + return; + } + int x; + int y; + BuildingTypeShort const keepType = DAT_BuildingsState::instance.buildings[keep].buildingType; + if (keepType == Map::Buildings::BT_MANORHOUSE) { + x = DAT_BuildingsState::instance.buildings[keep].x + 3; + y = DAT_BuildingsState::instance.buildings[keep].y + 8; + } else if (keepType == Map::Buildings::BT_STONEKEEP) { + x = DAT_BuildingsState::instance.buildings[keep].x + 3; + y = DAT_BuildingsState::instance.buildings[keep].y + 3; + } else if (keepType == Map::Buildings::BT_STRONGHOLD) { + x = DAT_BuildingsState::instance.buildings[keep].x + 3; + y = DAT_BuildingsState::instance.buildings[keep].y + 3; + } else if (keepType == Map::Buildings::BT_KEEPFOUR) { + x = DAT_BuildingsState::instance.buildings[keep].x + 4; + y = DAT_BuildingsState::instance.buildings[keep].y + 4; + } else if (keepType == Map::Buildings::BT_KEEPFIVE) { + x = DAT_BuildingsState::instance.buildings[keep].x + 5; + y = DAT_BuildingsState::instance.buildings[keep].y + 5; + } else { + return; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, x, y, 0, 0, Map::Units::Instructions::UMSE_0); + DAT_TribesState::instance.tribes[tribeID].unitStance = Map::Units::Behavior::USE_AGGRESSIVE; + } + return; + case Map::Units::STBT_0x3f8: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::calculateHigh2ClostestToTribeTargetUnit, this)( + tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, this->x, this->y, 0, 0, Map::Units::Instructions::UMSE_0); + } + return; + case Map::Units::STBT_0x3f9: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::calculateArch2ClosestToTribeTargetUnit, this)( + tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, this->x, this->y, 0, 0, Map::Units::Instructions::UMSE_0); + } + return; + case Map::Units::STBT_0x3f7: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3f7); + } + return; + case Map::Units::STBT_0x418: + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::sendAttackingPatrolTribeToComputedDestination, this)(tribeID); + } + return; + case Map::Units::STBT_0x41e: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::moveTribeToReachableNearbyTile, this)(tribeID); + } + return; + case Map::Units::STBT_0x419: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::decideAndExecuteTribeAttackAction, this)( + tribeID); + } + return; + case Map::Units::STBT_0x41a: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::moveTribeToNearbyGatehouse, this)(tribeID); + } + return; + case Map::Units::STBT_0x41b: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::moveTowardsParticularUnits, this)(tribeID); + } + return; + case Map::Units::STBT_0x3fc: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + DAT_TribesState::instance.tribes[tribeID].unitStance + = (UnitStanceEnum)(DAT_TroopValueState::instance.attackInfo.attackWaveRetargetCount > 2); + if (DAT_TribesState::instance.tribes[tribeID].countdown2 <= 0) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::claimArcherAttackPoint, this)(tribeID); + } + } + return; + case Map::Units::STBT_0x412: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + if (DAT_TribesState::instance.tribes[tribeID].countdown2 <= 0) { + if (!MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::findTribeWithMoatAttackBehavior, this)()) { + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::claimArcherAttackPoint, this)(tribeID); + return; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::assignTribeToSupportPoint, this)( + this->x, this->y, tribeID); + } + } + return; + case Map::Units::STBT_0x406: + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::setRallyPointForLaddermenTribe, this)(tribeID); + if (DAT_TribesState::instance.tribes[tribeID].countdown2 <= 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, DAT_TribesState::instance.tribes[tribeID].rallyPointArray[0][0], + DAT_TribesState::instance.tribes[tribeID].rallyPointArray[0][1], 0, 0, + Map::Units::Instructions::UMSE_0); + } + } + return; + case Map::Units::STBT_0x3f3: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + } + return; + case Map::Units::STBT_0x3f4: + if (DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit + && updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::assignAttackTargetsForTribe, DAT_TribesState::ptr)( + tribeID, Map::Units::STBT_0x3f4); + } + return; + case Map::Units::STBT_0x411: { + // The original falls back to the plain behaviour and stops here when the support tribe is gone. + int const supportTribeID = DAT_TribesState::instance.tribes[tribeID].supportTribeID; + if (!supportTribeID + || DAT_TribesState::instance.tribes[tribeID].uid2 + != DAT_TribesState::instance.tribes[supportTribeID].uid) { + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { + DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + int const unitID = DAT_TribesState::instance.tribes[supportTribeID].selectionTargetUnitID; + int const targetTile = MACRO_CALL_MEMBER( + Map::Navigation::PathFindingState_Func::pathFindingRelated, DAT_PathFindingState::ptr)(2, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DAT_UnitsState::instance.units[unitID].siegeTargetPlayerID); + if (targetTile > 0) { + int const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[targetTile]; + int const x = targetTile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( + tribeID, x, y, 0, 0, Map::Units::Instructions::UMSE_0); + MACRO_CALL_MEMBER( + Map::Navigation::DirectionAlgorithmState_Func::calculatePreferredRelativeOrientation, + DAT_DirectionAlgorithmState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, x, y); + DAT_TribesState::instance.tribes[tribeID].orientation + = (short)DAT_DirectionAlgorithmState::instance.orientation; + } + } + return; + } + case Map::Units::STBT_0x400: + return; + default: + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::updateTribeCombatStanceBehavior, DAT_TribesState::ptr)( + tribeID); + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 49f1336595..4a0d6cc98c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46167,7 +46167,7 @@ SHC_3BB0A8C1_0x0051D690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0051D730 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0051D7F0 | 0.0% | Pending +SHC_3BB0A8C1_0x0051D7F0 | 97.5% | Register allocation differs SHC_3BB0A8C1_0x0051D960 | 0.0% | Pending From fc6339a7d9fbf026f917602a7fafe39fd79b19a3 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:20:11 +0100 Subject: [PATCH 88/94] headers: add the TribeState enum (Map::Enums, TRS_ prefix) Tribe::tribeState takes three values in the reimplemented code: 0 for a free slot, 2 once createTribe has set the tribe up, and 3 once a tribe has been emptied or given up. 1 is never written. TRS_ is used because TS_ already belongs to TreeState. TribeStateShort matches the short field. Tribe.hpp still declares the field as plain short and is left unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Enums/TribeState.hpp | 25 +++++++++++++++++++++++ src/OpenSHC/Map/Enums/TribeStateShort.hpp | 21 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/OpenSHC/Map/Enums/TribeState.hpp create mode 100644 src/OpenSHC/Map/Enums/TribeStateShort.hpp diff --git a/src/OpenSHC/Map/Enums/TribeState.hpp b/src/OpenSHC/Map/Enums/TribeState.hpp new file mode 100644 index 0000000000..efbe3b2207 --- /dev/null +++ b/src/OpenSHC/Map/Enums/TribeState.hpp @@ -0,0 +1,25 @@ +/** + 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/TribeState.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef enum TribeState { + + TRS_UNUSED = 0, // 0x00000000 + TRS_ACTIVE = 2, // 0x00000002 + TRS_DISBANDED = 3 // 0x00000003 + + } TribeState; + + static_assert_cpp98_obj(sizeof(TribeState) == 4, TribeState); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Enums/TribeStateShort.hpp b/src/OpenSHC/Map/Enums/TribeStateShort.hpp new file mode 100644 index 0000000000..3ec4c7e2fb --- /dev/null +++ b/src/OpenSHC/Map/Enums/TribeStateShort.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/TribeStateShort.hpp' +*/ + +#pragma once + +#include "OpenSHC/Map/Enums/TribeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Enums { + typedef short TribeStateShort; + + static_assert_cpp98_obj(sizeof(TribeStateShort) == 2, TribeStateShort); + } // namespace Enums +} // namespace Map +} // namespace OpenSHC From c28826c02acd37495a970a52b745e9a5ab003f1d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:20:11 +0100 Subject: [PATCH 89/94] review: pre-review pass over the 84 TroopValueState functions - Named constants instead of magic numbers: - TribeState (TRS_*) for tribeState; - AIInfoFlag for the AI info layer bits; - SSS_UNUSABLE for siege spot scores; - the Logic1 flags for the keep/wall test; - STBT_0x410_SIEGE_EQUIPMENT_CONSTRUCTION; - countof() instead of literal table sizes. - Removed redundant casts. - TRUE/FALSE returns, and truthiness for the dying/tribeID tests. - const on locals that are assigned once, and `+=` instead of a self-assignment. - "Mace_s4.wav" now comes from string-literals.hpp. - Removed a dead security-cookie read. - Removed unused includes. initializeOrAdvanceAttackWave keeps Map.func.hpp because its code changes without it. - Removed the comments that only explained a form kept for the match; they are now in a PR comment. Also removed a stale comment on the size of the tent point table. Every function keeps its score in a full reccmp build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../TroopValueState/addUnitToNewTribe.cpp | 1 - .../advanceAttackWaveStaging.cpp | 1 - .../TroopValueState/aiRecomputeAttacks.cpp | 1 - .../TroopValueState/aiRecomputeAttacks2.cpp | 1 - .../applyTribeBehaviorTypes.cpp | 1 - .../assignBehaviorTypeAndLinkSupportTribe.cpp | 21 ++++++----- ...acemenAndKnightsNotFromPlayer1ToTribes.cpp | 2 -- .../assignTribeToSupportPoint.cpp | 1 - .../buildRallyPointsFromSiegeUnits.cpp | 1 - ...calculateArch2ClosestToTribeTargetUnit.cpp | 1 - ...alculateHigh2ClostestToTribeTargetUnit.cpp | 1 - .../calculateTile2MoatValueClosestToUnit.cpp | 1 - .../calculateTile2PeoplValueClosestToUnit.cpp | 1 - .../claimArcherAttackPoint.cpp | 1 - .../collectArcherUnitsByLocation.cpp | 6 ++-- .../commandUnitsToMoveToKeep.cpp | 36 +++++++++---------- .../computeSiegeSpotScores.cpp | 22 ++++++------ .../countAvailablePeopleValueSlots.cpp | 2 -- .../decideAndExecuteTribeAttackAction.cpp | 1 - .../TroopValueState/decrementTileMap1104.cpp | 1 - ...ecuteDelayedAttackWaveTargetAssignment.cpp | 16 ++++----- .../exitSiegeEquipmentForWave.cpp | 3 +- .../expandAIZoneLayerStage1.cpp | 1 - .../expandAIZoneLayerStage2.cpp | 1 - .../expandAIZoneLayerStage3.cpp | 1 - .../findEnemyBuildingsClosestToUnit.cpp | 1 - .../Units/TroopValueState/findEnemyLord.cpp | 7 ++-- .../findEnemyTowersOrGates.cpp | 1 - .../Units/TroopValueState/findEnemyWalls.cpp | 1 - .../findNearestAvailableScalePoint.cpp | 1 - .../findNearestDiggableMoatPoint.cpp | 1 - .../findOrReserveArcherPointSlot.cpp | 2 -- .../findTribeWithMoatAttackBehavior.cpp | 4 +-- .../getClosestWideValueBasedOnPlayer.cpp | 1 - .../getPlayerNot1AndHasKeep.cpp | 1 - .../TroopValueState/getSiegeIndexForTile.cpp | 2 -- .../TroopValueState/getSupportPointIndex.cpp | 2 -- .../TroopValueState/getValueOfTroopType.cpp | 1 - ...htPitchInstructionToUnitClosestToPitch.cpp | 19 +++++----- .../ifNecessaryThrowOilAutomatically.cpp | 3 -- .../initializeAttackWaveSlot.cpp | 1 - .../initializeAttackZoneSearch.cpp | 1 - .../initializeOrAdvanceAttackWave.cpp | 4 +-- ...essThanPercentageOfTribesInAttackDying.cpp | 4 +-- .../moveTowardsParticularUnits.cpp | 1 - .../moveTribeToNearbyGatehouse.cpp | 1 - .../moveTribeToReachableNearbyTile.cpp | 1 - .../placeSiegeTentAtAttackAngle.cpp | 1 - .../placeSiegeTentsAndAssignEngineers.cpp | 11 +++--- .../TroopValueState/placeTunnelEntrances.cpp | 1 - .../placeTunnelForEveryTunneler.cpp | 3 +- .../TroopValueState/playAttackAlarmSound.cpp | 1 - .../processSpottedEnemyTiles.cpp | 1 - .../pruneStaleArcherPoints.cpp | 13 +++---- .../pruneStaleSupportPoints.cpp | 9 +++-- .../TroopValueState/pruneStaleTentPoints.cpp | 11 +++--- .../queueOilThrowForIdleArchers.cpp | 3 +- .../recomputeTargetedBuildingTilesArray.cpp | 1 - ...computeTotalTroopValueOfTroopsNearKeep.cpp | 1 - .../recountTotalTroopValue.cpp | 4 +-- .../redeployArchersToDefensivePositions.cpp | 1 - .../registerSpottedEnemyTile.cpp | 1 - .../renderAttackInfoDebugOverlay.cpp | 4 --- .../TroopValueState/scanForArcherPoints.cpp | 26 +++++++------- .../TroopValueState/scanForSupportPoints.cpp | 4 +-- .../searchTribeWithProperties.cpp | 4 +-- ...ackingPatrolTribeToComputedDestination.cpp | 1 - .../Map/Units/TroopValueState/setGate2.cpp | 2 -- .../Map/Units/TroopValueState/setMoat3.cpp | 2 -- .../setRallyPointForLaddermenTribe.cpp | 13 ++++--- .../Map/Units/TroopValueState/setScale3.cpp | 2 -- .../Map/Units/TroopValueState/setTown2.cpp | 2 -- .../Map/Units/TroopValueState/setWide3.cpp | 2 -- .../shouldLightPitchBasedOnTroopValue.cpp | 1 - .../trySendKnightTribeToAttack.cpp | 1 - .../trySendMacemenTribeToAttack.cpp | 1 - .../updateActiveAttackWaveState.cpp | 1 - .../updateArcherBrazierProximityFlags.cpp | 1 - .../TroopValueState/updateAttackInfoTick.cpp | 1 - .../updateInProgressAttackWave.cpp | 17 +++++---- ...updateTribeBehaviorBasedOnBehaviorType.cpp | 12 +++---- 81 files changed, 126 insertions(+), 218 deletions(-) diff --git a/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp index e010957f7f..b0c5682ffb 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Game/GameMode2.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp b/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp index abb1030056..a406812b8a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp @@ -1,7 +1,6 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp index e010b5dc2c..11ed53693b 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/Game/GameStateStructures.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Util/Timing/Stopwatch.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp index 51e82433ce..b16adf970d 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks2.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/Game/GameStateStructures.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Util/Timing/Stopwatch.func.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp b/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp index 74500340c8..f7eda4b9fd 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/applyTribeBehaviorTypes.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp index 6a05eb9cd2..c8c939b0f4 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp @@ -1,8 +1,8 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" @@ -29,23 +29,22 @@ namespace Map { if (11 <= DAT_TroopValueState::instance.attackInfo.tribeRelatedArrayValue0UpTo12[i]) { return; } - int _supportTribeID = (int)DAT_TribesState::instance.tribes[_tribeID].supportTribeID; + int _supportTribeID = DAT_TribesState::instance.tribes[_tribeID].supportTribeID; if (_supportTribeID && DAT_TribesState::instance.tribes[_tribeID].uid2 == DAT_TribesState::instance.tribes[_supportTribeID].uid) { return; } - // The original stores the update limit first, and both searches jump straight to the link. DAT_TribesState::instance.tribes[_tribeID].someUpdateUpperLimit = ((short)i + 1) * (short)updateLimitStep + (short)updateLimitBase; - DAT_TribesState::instance.tribes[_tribeID].tribeBehaviorType = (undefined2)behaviorType; + DAT_TribesState::instance.tribes[_tribeID].tribeBehaviorType = behaviorType; DAT_TribesState::instance.tribes[_tribeID].attackInfo_someCounter1 - = (short)DAT_TroopValueState::instance.attackInfo.someCounter1; + = DAT_TroopValueState::instance.attackInfo.someCounter1; DAT_TribesState::instance.tribes[_tribeID].unknownAttackRelatedUpdateCounter = 0; for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); ++_supportTribeID) { - if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 0 - && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 3 + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_UNUSED + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_DISBANDED && DAT_TribesState::instance.tribes[_supportTribeID].owner == DAT_TribesState::instance.tribes[_tribeID].owner && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 @@ -61,8 +60,8 @@ namespace Map { == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { break; } - if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 0 - && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != 3 + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_UNUSED + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_DISBANDED && DAT_TribesState::instance.tribes[_supportTribeID].owner == DAT_TribesState::instance.tribes[_tribeID].owner && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 @@ -74,9 +73,9 @@ namespace Map { } continue; link: - DAT_TribesState::instance.tribes[_tribeID].supportTribeID = (short)_supportTribeID; + DAT_TribesState::instance.tribes[_tribeID].supportTribeID = _supportTribeID; DAT_TribesState::instance.tribes[_tribeID].uid2 = DAT_TribesState::instance.tribes[_supportTribeID].uid; - DAT_TribesState::instance.tribes[_supportTribeID].tribeID = (short)_tribeID; + DAT_TribesState::instance.tribes[_supportTribeID].tribeID = _tribeID; } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp index 26f794f1a1..274d558988 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignMacemenAndKnightsNotFromPlayer1ToTribes.cpp @@ -1,11 +1,9 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp index 544e0062e0..f85ee93449 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignTribeToSupportPoint.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp b/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp index 19587e162a..70724c19a7 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/buildRallyPointsFromSiegeUnits.cpp @@ -1,7 +1,6 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp index 7ec2573cf8..aa4f816e71 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateArch2ClosestToTribeTargetUnit.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp index f0858b391a..7e7cd85b1a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateHigh2ClostestToTribeTargetUnit.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp index 4ddea32d03..38262c4da2 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp index 837966ce7c..9896e7842d 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2PeoplValueClosestToUnit.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp index 26345b9fc7..b1b9954f52 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/claimArcherAttackPoint.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp b/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp index 0c809e5615..120a698266 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/collectArcherUnitsByLocation.cpp @@ -1,12 +1,10 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -58,7 +56,7 @@ namespace Map { = DAT_UnitsState::instance.units[_unitID].uid; DAT_TroopValueState::instance.attackInfo .unitIDArray_0x2c070[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520] - = (short)_unitID; + = _unitID; DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2c520++; } } @@ -69,7 +67,7 @@ namespace Map { _unitID, DAT_UnitsState::instance.units[_unitID].tribeID); DAT_TroopValueState::instance.attackInfo .unitIDArray_0x2b57c[DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c] - = (short)_unitID; + = _unitID; DAT_TroopValueState::instance.attackInfo.unitIDIndex_0x2bd4c++; } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp index 72e0e7c112..fa12959fc3 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp @@ -1,16 +1,16 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" #include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" @@ -38,27 +38,27 @@ namespace Map { if (0 < (int)_keep) { BuildingTypeShort _buildingType = DAT_BuildingsState::instance.buildings[_keep].buildingType; if (_buildingType == Map::Buildings::BT_MANORHOUSE) { - x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; - y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 8; + x1 = DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = DAT_BuildingsState::instance.buildings[_keep].y + 8; } else if (_buildingType == Map::Buildings::BT_STONEKEEP) { - x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; - y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 3; + x1 = DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = DAT_BuildingsState::instance.buildings[_keep].y + 3; } else if (_buildingType == Map::Buildings::BT_STRONGHOLD) { - x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 3; - y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 3; + x1 = DAT_BuildingsState::instance.buildings[_keep].x + 3; + y1 = DAT_BuildingsState::instance.buildings[_keep].y + 3; } else if (_buildingType == Map::Buildings::BT_KEEPFOUR) { - x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 4; - y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 4; + x1 = DAT_BuildingsState::instance.buildings[_keep].x + 4; + y1 = DAT_BuildingsState::instance.buildings[_keep].y + 4; } else if (_buildingType == Map::Buildings::BT_KEEPFIVE) { - x1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].x + 5; - y1 = (int)(short)DAT_BuildingsState::instance.buildings[_keep].y + 5; + x1 = DAT_BuildingsState::instance.buildings[_keep].x + 5; + y1 = DAT_BuildingsState::instance.buildings[_keep].y + 5; } else { return; } - int _swordsTribe = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)( - DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID, 0); + int const _swordsTribe = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, + DAT_TribesState::ptr)(DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID, 0); DAT_TribesState::instance.tribes[_swordsTribe].tribeType = AI::Tribes::AITT_SWORDSMEN; - int _archersTribe + int const _archersTribe = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(_playerID, 0); DAT_TribesState::instance.tribes[_archersTribe].tribeType = AI::Tribes::AITT_ARCHERS; for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { @@ -77,7 +77,7 @@ namespace Map { continue; } if (DAT_TileMapState::instance.LogicLayer[DAT_UnitsState::instance.units[unitID].tile] - & 0x10000100U) { + & (Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE | Map::LogicHelpers::L_WALL_OR_GATEHOUSE)) { continue; } } @@ -98,13 +98,13 @@ namespace Map { } } if (DAT_TribesState::instance.tribes[_swordsTribe].size <= 0) { - DAT_TribesState::instance.tribes[_swordsTribe].tribeState = 3; + DAT_TribesState::instance.tribes[_swordsTribe].tribeState = Map::Enums::TRS_DISBANDED; } else { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( _swordsTribe, x1, y1 + 1, 0, 0, Map::Units::Instructions::UMSE_0); } if (DAT_TribesState::instance.tribes[_archersTribe].size <= 0) { - DAT_TribesState::instance.tribes[_archersTribe].tribeState = 3; + DAT_TribesState::instance.tribes[_archersTribe].tribeState = Map::Enums::TRS_DISBANDED; } else { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( _archersTribe, x1, y1, 0, 0, Map::Units::Instructions::UMSE_0); diff --git a/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp b/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp index 0acac15b94..c7d06f1059 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/computeSiegeSpotScores.cpp @@ -1,8 +1,8 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -47,10 +47,10 @@ namespace Map { if (MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadderInRightDirection, DAT_UnitsState::ptr)(tile, y)) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hackValuesArray[i].score - = 9999; + = Map::Enums::SSS_UNUSABLE; } else if (cost <= 0) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hackValuesArray[i].score - = 9999; + = Map::Enums::SSS_UNUSABLE; } else { int const minimumDistance = DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] @@ -58,11 +58,11 @@ namespace Map { if (minimumDistance >= 50) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] .hackValuesArray[i] - .score = 9999; + .score = Map::Enums::SSS_UNUSABLE; } else if (cost >= minimumDistance + 15) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] .hackValuesArray[i] - .score = 9999; + .score = Map::Enums::SSS_UNUSABLE; } else { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].hack3++; DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1] @@ -81,7 +81,7 @@ namespace Map { .scaleValuesArray[i] .tile] > 5 - ? 9999 + ? Map::Enums::SSS_UNUSABLE : 0; } for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].town2; ++i) { @@ -127,10 +127,10 @@ namespace Map { .tile]; if (DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].field22_0x3ea4 > 10) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].gateValuesArray[i].score - = cost > 20 ? 9999 : 0; + = cost > 20 ? Map::Enums::SSS_UNUSABLE : 0; } else { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].gateValuesArray[i].score - = cost > 10 ? 9999 : 0; + = cost > 10 ? Map::Enums::SSS_UNUSABLE : 0; } } for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].wide2; ++i) { @@ -142,7 +142,7 @@ namespace Map { .wideValuesArray[i] .tile] > 5 - ? 9999 + ? Map::Enums::SSS_UNUSABLE : 0; } for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moat2; ++i) { @@ -155,7 +155,7 @@ namespace Map { .tile]; if (cost <= 0) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score - = 9999; + = Map::Enums::SSS_UNUSABLE; } else if (cost <= 10) { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score = cost; @@ -176,7 +176,7 @@ namespace Map { = cost * 6; } else { DAT_TroopValueState::instance.attackInfo.playerInfo[attackingPlayerID - 1].moatValuesArray[i].score - = 9999; + = Map::Enums::SSS_UNUSABLE; } } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp b/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp index 63df8a10b6..8603b28fba 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/countAvailablePeopleValueSlots.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp b/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp index 762d0c3e74..6f2c53dee1 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/decideAndExecuteTribeAttackAction.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp b/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp index 2d4eaeb662..3dbdfbf473 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/decrementTileMap1104.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp b/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp index 882a210837..509afc85ca 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/executeDelayedAttackWaveTargetAssignment.cpp @@ -1,7 +1,6 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" #include "OpenSHC/Map/MapType2.hpp" @@ -24,13 +23,14 @@ namespace Map { void TroopValueState::executeDelayedAttackWaveTargetAssignment(int attackID) { int _playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; - if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) - && (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE)) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { _playerID = 2; } DAT_TroopValueState::instance.attackInfo.delayedWaveAssignmentCount++; - BOOLEnum _canReachSignpostZone = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::canKeepReachSignpostZone, - DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, _playerID, attackID); + BOOLEnum const _canReachSignpostZone + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::canKeepReachSignpostZone, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, _playerID, attackID); if (!_canReachSignpostZone) { DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_ASSIGNING_TARGETS; DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 0; @@ -50,8 +50,8 @@ namespace Map { attackID, 1000, 10000, Map::Units::STBT_0x418); MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( Map::Units::STBT_0x418, Map::Units::STBT_1, 20, 70); - if ((DAT_TroopValueState::instance.attackInfo.people3) - && (10 <= DAT_TroopValueState::instance.attackInfo.attackTribeCount)) { + if (DAT_TroopValueState::instance.attackInfo.people3 + && 10 <= DAT_TroopValueState::instance.attackInfo.attackTribeCount) { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( attackID, 1, DAT_TroopValueState::instance.attackInfo.people3, Map::Units::STBT_0x3fb); MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( @@ -82,7 +82,7 @@ namespace Map { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::applyTribeBehaviorTypes, this)( Map::Units::STBT_0x3fb, Map::Units::STBT_1, 0, 10); } - int tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[_playerID - 1].town3; + int const tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[_playerID - 1].town3; if (tribeSizeSumLimit) { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( attackID, 1, tribeSizeSumLimit, Map::Units::STBT_0x3f5); diff --git a/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp index cd156b6dba..b84713064c 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Map/Units/States/UnitState.hpp" @@ -34,7 +33,7 @@ namespace Map { DAT_TribesState::ptr)(_tribeID, _tribeUnitIndex); _tribeUnitIndex++; if (DAT_UnitsState::instance.units[_unitID].logicalState == Map::Units::ULS_NORMAL - && DAT_UnitsState::instance.units[_unitID].dying == 0) { + && !DAT_UnitsState::instance.units[_unitID].dying) { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeAnInstruction, DAT_TribesState::ptr)(_tribeID, Map::Units::UIT_EXIT_SIEGE_EQUIPMENT, _unitID, DAT_UnitsState::instance.units[_unitID].uid, 0); diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp index b24b25612f..6ba2ed3600 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage1.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Enums/AIInfoFlag.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp index e64a5e3bb9..f9f6da4e67 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage2.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Enums/AIInfoFlag.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp index e8b1648a14..1d8662e5d5 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/expandAIZoneLayerStage3.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Enums/AIInfoFlag.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp index 446d3c8cf9..9ad4b019ad 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyBuildingsClosestToUnit.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp index 41f687039d..20f7adfdd2 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyLord.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" @@ -14,10 +12,9 @@ namespace Map { { int i = 0; if (0 < DAT_TroopValueState::instance.attackInfo.lord3) { - // Stays a do-while: a for-loop here measured 92.1% instead of 100%. do { if (DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].unitID == 0) { - this->y = (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + this->y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent [DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile2]; this->x = DAT_TroopValueState::instance.attackInfo.lordValuesArray[i].tile2 - DAT_ViewportRenderState::instance.translationMatrix[this->y].addXgetTile; @@ -27,7 +24,7 @@ namespace Map { } i++; } while (i < DAT_TroopValueState::instance.attackInfo.lord3); - this->y = (int)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent + this->y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent [DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile2]; this->x = DAT_TroopValueState::instance.attackInfo.lordValuesArray[0].tile2 - DAT_ViewportRenderState::instance.translationMatrix[this->y].addXgetTile; diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp index 44c25698bc..fb015bc102 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp index ba7e860850..63761d05dc 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyWalls.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp index f3b4f1c2a2..16e602e46a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp index b50f43b105..26b139a8ce 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findNearestDiggableMoatPoint.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp b/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp index 27ce49f841..4262eb4571 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findOrReserveArcherPointSlot.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp index 9b3ea12cac..bf735bd932 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp @@ -1,7 +1,7 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" @@ -19,7 +19,7 @@ namespace Map { BOOLEnum TroopValueState::findTribeWithMoatAttackBehavior() { for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState == 0) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_UNUSED) { continue; } BOOLEnum const fullIDIsMinus1 diff --git a/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp index b8e03383bc..bb703f78c5 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp index 40c6d9770d..0bc390c333 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getPlayerNot1AndHasKeep.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Map/MapType2.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp index c44b7fbe82..26a5166f53 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getSiegeIndexForTile.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp b/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp index 82b4707475..f233f1769b 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getSupportPointIndex.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp b/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp index 806206285e..f5cdd8580e 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getValueOfTroopType.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" #include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp index 211c9fed3f..afb876b367 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" @@ -35,21 +34,21 @@ namespace Map { for (; _unitID < DAT_UnitsState::instance.maxUnitCount; _unitID++, _pUnit++) { if (_pUnit->logicalState != Map::Units::ULS_INVISIBLE && (isAIPlayerWithKeep = MACRO_CALL_MEMBER( - Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)((int)_pUnit->owner), + Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)(_pUnit->owner), isAIPlayerWithKeep) && (_pUnit->unitType == Map::Units::UT_E_ARCHER || (_pUnit->unitType == Map::Units::UT_A_ARCHER)) - && !_pUnit->dying && _pUnit->field_0x40d != false + && !_pUnit->dying && _pUnit->field_0x40d && _pUnit->targetingType != Map::Units::UIT_LIGHT_PITCH) { - int const _ditchY = (int)DAT_TileMapState::instance.pitchDitches[_ditchID].y; - int const _ditchX = (int)DAT_TileMapState::instance.pitchDitches[_ditchID].x; + int const _ditchY = DAT_TileMapState::instance.pitchDitches[_ditchID].y; + int const _ditchX = DAT_TileMapState::instance.pitchDitches[_ditchID].x; int const _unitY = _ditchY - _pUnit->y; int const _unitX = _ditchX - _pUnit->x; int _distancePyth = _unitX * _unitX + _unitY * _unitY; if (_distancePyth <= 2500 && (_shot = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::arrowShootingRelated, - DAT_EntityState::ptr)((int)_pUnit->microXPosition, (int)(_pUnit->microYPosition), - (int)(_pUnit->buildingHeight + 30 + _pUnit->terrainOrClimbHeight), _ditchX * 8 + 4, + DAT_EntityState::ptr)(_pUnit->microXPosition, _pUnit->microYPosition, + _pUnit->buildingHeight + 30 + _pUnit->terrainOrClimbHeight, _ditchX * 8 + 4, _ditchY * 8 + 4, (int)(DAT_TileMapState::instance .HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile])), @@ -62,7 +61,7 @@ namespace Map { } } if (!_minUnitID) { - return 0; + return FALSE; } DAT_UnitsState::instance.units[_minUnitID].shootTargetMicroX = DAT_TileMapState::instance.pitchDitches[_ditchID].x * 8 + 4; @@ -70,7 +69,7 @@ namespace Map { = DAT_TileMapState::instance.pitchDitches[_ditchID].y * 8 + 4; DAT_UnitsState::instance.units[_minUnitID].shootTargetZ = DAT_TileMapState::instance.HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile]; - DAT_UnitsState::instance.units[_minUnitID].targetID_OR_targetBuildingID = (short)_ditchID; + DAT_UnitsState::instance.units[_minUnitID].targetID_OR_targetBuildingID = _ditchID; int _ditchUID = DAT_TileMapState::instance.pitchDitches[_ditchID].uid; DAT_UnitsState::instance.units[_minUnitID].shootTargetedUnit = -1; DAT_UnitsState::instance.units[_minUnitID] @@ -82,7 +81,7 @@ namespace Map { DAT_UnitsState::ptr)(_minUnitID); DAT_UnitsState::instance.units[_minUnitID].state.generic = Map::Units::States::US_FIRE_WEAPONUnk; DAT_UnitsState::instance.units[_minUnitID].field_0x40e = true; - return 1; + return TRUE; } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp b/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp index 7725676eb0..73504bfee3 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/ifNecessaryThrowOilAutomatically.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" @@ -88,8 +87,6 @@ namespace Map { int const buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; int friendlyTroopValue = 0; int enemyTroopValue = 0; - // Stays a do-while: getBuildingSizeIndexMappingData sets constructionTileCount, so the first - // pass runs before the count is known. do { MACRO_CALL_MEMBER(Map::TileMapState_Func::getBuildingSizeIndexMappingData, DAT_TileMapState::ptr)(tileIndex, buildingSize); diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp index 315fc9684f..d094fb04e0 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackWaveSlot.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/Game/GameStateStructures.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp index 8876dbef8f..bc5e0b5b74 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeAttackZoneSearch.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp index eff36cf247..5db2ab1c71 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp @@ -37,8 +37,8 @@ namespace Map { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::applyTribeBehaviorType, DAT_TribesState::ptr)( attackWave, Map::Units::STBT_3); } - if ((int)(char)DAT_TroopValueState::instance.attackInfo.unknownByteArray02[attackWave] - >= (char)DAT_TroopValueState::instance.attackInfo.nof_tribes[attackWave] - 5) { + if ((char)DAT_TroopValueState::instance.attackInfo.unknownByteArray02[attackWave] + >= DAT_TroopValueState::instance.attackInfo.nof_tribes[attackWave] - 5) { DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave]++; if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackWave] >= DAT_AttackInfoDefinedData::instance diff --git a/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp index a9ad10db58..187fd6f15c 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp @@ -1,7 +1,7 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" @@ -17,7 +17,7 @@ namespace Map { int living = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { if (!DAT_TribesState::instance.tribes[tribeID].tribeState - || DAT_TribesState::instance.tribes[tribeID].tribeState == 3 + || DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_DISBANDED || DAT_GameSynchronyState::instance .currentPlayerFullIDArray[DAT_TribesState::instance.tribes[tribeID].owner] != -1 diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp index c5fb432e86..72b8d53e7a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTowardsParticularUnits.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp index e57c9d8c71..0d0ddebe92 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToNearbyGatehouse.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp index a76ac78185..90d2667fd8 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/moveTribeToReachableNearbyTile.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp index bd409aed84..d2d6ff3a19 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentAtAttackAngle.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp index 8f54013464..a548ec6424 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Game/GameMode2.hpp" @@ -47,7 +46,8 @@ namespace Map { .engineerCount = engineers; DAT_TroopValueState::instance.attackInfo.createTribeAmount++; engineerTotal += engineers; - if (DAT_TroopValueState::instance.attackInfo.createTribeAmount >= 250) { + if (DAT_TroopValueState::instance.attackInfo.createTribeAmount + >= countof(DAT_TroopValueState::instance.attackInfo.engineerBuildQueue)) { break; } } @@ -56,7 +56,8 @@ namespace Map { Commands::MappersEnum const buildingType = DAT_ARRAY_00b4c7cc::instance[8]; int const engineers = INT_ARRAY_00b4d0f0::instance[8]; for (int n = 0; n < count; n++) { - if (DAT_TroopValueState::instance.attackInfo.createTribeAmount >= 250) { + if (DAT_TroopValueState::instance.attackInfo.createTribeAmount + >= countof(DAT_TroopValueState::instance.attackInfo.engineerBuildQueue)) { break; } DAT_TroopValueState::instance.attackInfo @@ -68,7 +69,6 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.createTribeAmount++; engineerTotal += engineers; } - // tribeID is initialised before the size reset: the original loads 1 with a mov, not as lea from the zero int tribeID = 1; DAT_TroopValueState::instance.attackInfo.tribeIDArraySize = 0; for (; tribeID < countof(DAT_TribesState::instance.tribes); tribeID++) { @@ -96,7 +96,8 @@ namespace Map { int const newTribeID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(DAT_TribesState::instance.tribes[tribeID].owner, 0); DAT_TribesState::instance.tribes[newTribeID].tribeType = AI::Tribes::AITT_ENGINEERS; - DAT_TribesState::instance.tribes[newTribeID].tribeBehaviorType = 1040; + DAT_TribesState::instance.tribes[newTribeID].tribeBehaviorType + = Map::Units::STBT_0x410_SIEGE_EQUIPMENT_CONSTRUCTION; DAT_TribesState::instance.tribes[newTribeID].attackWave = DAT_TribesState::instance.tribes[tribeID].attackWave; DAT_TribesState::instance.tribes[newTribeID].attackInfo_someCounter1 diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp index 27745f3b11..c36d02e513 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelEntrances.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp index 768901a882..f5ab40dcdf 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeTunnelForEveryTunneler.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" #include "OpenSHC/Game/GameMode2.hpp" @@ -22,7 +21,7 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0051BA30 void TroopValueState::placeTunnelForEveryTunneler(int attackWave) { - int _playerID = (char)DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; + int _playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackWave]; int _nTunnelers = 0; if (!_playerID) { _playerID = 2; diff --git a/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp b/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp index 593098f863..393459ca0c 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/playAttackAlarmSound.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" #include "OpenSHC/Audio/SFX/SFXState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/string-macros.hpp" #include "OpenSHC/Globals/DAT_SFXState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp b/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp index cf56da1d1b..117371b481 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/processSpottedEnemyTiles.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp index b61af92659..1c126e3ff6 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleArcherPoints.cpp @@ -1,9 +1,7 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" @@ -23,12 +21,11 @@ namespace Map { sizeof(DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]), 0, &DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]); } else { - if (DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID != 0 - && MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( - DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID, - DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeUID) - == FALSE) { + if (DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID + && !MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.archerPointArray[slot].tribeUID)) { MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]), 0, &DAT_TroopValueState::instance.attackInfo.archerPointArray[slot]); diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp index 76d4967d11..9545673973 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleSupportPoints.cpp @@ -22,11 +22,10 @@ namespace Map { sizeof(DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]), 0, &DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]); } else { - if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID != 0 - && MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( - DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID, - DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeUID) - == FALSE) { + if (DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID + && !MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot].tribeUID)) { MACRO_CALL_MEMBER( OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(DAT_TroopValueState::instance.attackInfo.supportPointsArray[slot]), 0, diff --git a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp index bf18f43d52..82f3fd9239 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/pruneStaleTentPoints.cpp @@ -14,8 +14,6 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0051B290 void TroopValueState::pruneStaleTentPoints() { - // The original walks slots 1..1999 (end 0x17A52B4): the tent point table really has 2000 entries, - // tentPointsValues is declared with only 216. for (int slot = 1; slot < countof(DAT_TroopValueState::instance.attackInfo.tentPointsValues) - 1; ++slot) { if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].someCounter != DAT_TroopValueState::instance.attackInfo.someCounter1) { @@ -23,11 +21,10 @@ namespace Map { sizeof(DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]), 0, &DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]); } else { - if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID != 0 - && MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( - DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID, - DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeUID) - == FALSE) { + if (DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID + && !MACRO_CALL_MEMBER(TribesState_Func::tribeCorrespondsWithUID, DAT_TribesState::ptr)( + DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeID, + DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot].tribeUID)) { MACRO_CALL_MEMBER( OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( sizeof(DAT_TroopValueState::instance.attackInfo.tentPointsValues[slot]), 0, diff --git a/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp b/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp index 5c0fb104a1..b8fc1e8230 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/queueOilThrowForIdleArchers.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/States/UnitState.hpp" #include "OpenSHC/Map/Units/UnitInstructionType.hpp" @@ -29,7 +28,7 @@ namespace Map { = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( DAT_UnitsState::instance.units[unitID].owner); if (!isAIPlayerWithKeep || DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_ENGINEER - || DAT_UnitsState::instance.units[unitID].dying != 0 + || DAT_UnitsState::instance.units[unitID].dying || DAT_UnitsState::instance.units[unitID].state.generic != Map::Units::States::US_SIT_DOWNUnk) { continue; } diff --git a/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp b/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp index de7dae0628..2fc43f62ce 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/recomputeTargetedBuildingTilesArray.cpp @@ -1,7 +1,6 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/IO/LowLevelMemory.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp index 4841ffca6b..2492b1dc0d 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/recomputeTotalTroopValueOfTroopsNearKeep.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp b/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp index 0f1bcd7964..ac33f5cf5a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/recountTotalTroopValue.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" @@ -29,8 +28,7 @@ namespace Map { && DAT_UnitsState::instance.units[_unitID].unitType != Map::Units::UT_E_LADDER) { int const _playerID = DAT_UnitsState::instance.units[_unitID].owner; DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[_playerID] - = DAT_TroopValueState::instance.attackInfo.playerTotalTroopValueArray[_playerID] - + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, this)( + += MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, this)( (Map::Units::UnitType)DAT_UnitsState::instance.units[_unitID].unitType); } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp b/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp index 210919b954..18d21d5e7d 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/redeployArchersToDefensivePositions.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Map/Units/States/UnitState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp b/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp index d3cf0d4764..960d618663 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/registerSpottedEnemyTile.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp b/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp index 87aa686859..1501f8a2cf 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/renderAttackInfoDebugOverlay.cpp @@ -1,19 +1,16 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/OS.func.hpp" #include "OpenSHC/Text/TextManager.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" #include "OpenSHC/Text/TextAlignment.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_TextManagerObject.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" -#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" namespace OpenSHC { namespace Map { @@ -23,7 +20,6 @@ namespace Map { void TroopValueState::renderAttackInfoDebugOverlay(int x, int y, int width, int height) { char textBuffer[1000]; - uint const securityCookie = MSVC_SecurityCookie::instance ^ (uint)textBuffer; int const column1X = x + 2; MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( s_Biggest_zone__005abb48, column1X, y, Text::TTA_LEFT, Rendering::Colors::COL_FFFFFF, 18, FALSE, 0); diff --git a/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp index 2cec9d3309..f02c57f10c 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/scanForArcherPoints.cpp @@ -1,7 +1,7 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/AIInfoFlag.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -20,33 +20,34 @@ namespace Map { { int _searchRadius; DAT_TroopValueState::instance.attackInfo.archerPoints = 0; - if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 0) { + if (DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 0) { _searchRadius = 8; - } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 2) { + } else if (DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 2) { _searchRadius = 5; - } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 4) { + } else if (DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 4) { _searchRadius = 6; - } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 8) { + } else if (DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 8) { _searchRadius = 7; - } else if ((int)DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 20) { + } else if (DAT_TroopValueState::instance.attackInfo.archerPointCountPrev < 20) { _searchRadius = 8; } else { _searchRadius = 10; } for (int tile = 0; tile < countof(DAT_TileMapState::instance.AIInfoLayer); ++tile) { - if (DAT_TileMapState::instance.AIInfoLayer[tile] == 2) { - uint const y = (uint)DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + if (DAT_TileMapState::instance.AIInfoLayer[tile] == Map::Enums::AIF_RING_2) { + uint const y = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; for (int _direction = 0; _direction < 4; ++_direction) { int const neighbour = DAT_TileMapState::instance.directionTranslationMatrix[y][_direction * 2] + tile; - if ((DAT_TileMapState::instance.AIInfoLayer[neighbour] & 0xf) == 4 + if ((DAT_TileMapState::instance.AIInfoLayer[neighbour] & Map::Enums::AIF_ANY_RING) + == Map::Enums::AIF_RING_3 && !(DAT_TileMapState::instance.RandomLayer[neighbour] & 3)) { uint const x = tile - DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile; BOOLEnum hasArcherZoneFlag = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findAIZoneWithFlags, - DAT_PathFindingState::ptr)(_searchRadius, x, y, 0x10); + DAT_PathFindingState::ptr)(_searchRadius, x, y, Map::Enums::AIF_ARCHER_POINT); if (!hasArcherZoneFlag) { - DAT_TileMapState::instance.AIInfoLayer[tile] |= 0x10; + DAT_TileMapState::instance.AIInfoLayer[tile] |= Map::Enums::AIF_ARCHER_POINT; int _existingPointIndex = MACRO_CALL_MEMBER( Map::Units::TroopValueState_Func::findOrReserveArcherPointSlot, this)(tile); int const _nextPointIndex = DAT_TroopValueState::instance.attackInfo.archerPointsNext; @@ -64,7 +65,8 @@ namespace Map { .lastSeenCounter = DAT_TroopValueState::instance.attackInfo.someCounter1; } DAT_TroopValueState::instance.attackInfo.archerPoints++; - if (200 <= DAT_TroopValueState::instance.attackInfo.archerPoints) { + if (countof(DAT_TroopValueState::instance.attackInfo.archerPointArray) - 1 + <= DAT_TroopValueState::instance.attackInfo.archerPoints) { return; } break; diff --git a/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp b/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp index 79a7f4acc4..62774ea731 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/scanForSupportPoints.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Enums/AIInfoFlag.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" @@ -61,7 +60,8 @@ namespace Map { = DAT_TroopValueState::instance.attackInfo.someCounter1; } ++DAT_TroopValueState::instance.attackInfo.supportPoints; - if (200 <= DAT_TroopValueState::instance.attackInfo.supportPoints) { + if (countof(DAT_TroopValueState::instance.attackInfo.supportPointsArray) - 1 + <= DAT_TroopValueState::instance.attackInfo.supportPoints) { return; } break; diff --git a/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp index d33f51e6aa..0c0271579e 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp @@ -1,7 +1,7 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" @@ -22,7 +22,7 @@ namespace Map { } int owner = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState == 2 + if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_ACTIVE && DAT_TribesState::instance.tribes[tribeID].owner && DAT_TribesState::instance.tribes[tribeID].owner != DAT_GameSynchronyState::instance.currentPlayerSlotID) { diff --git a/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp b/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp index aeb71663b0..0c33c03f86 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/sendAttackingPatrolTribeToComputedDestination.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp index 3677f1dc18..a483e89486 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp index 34928d1f41..64060319a5 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp index e4ac2fe29f..d55376dce3 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp @@ -1,10 +1,9 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/AI/Tribes/AITribeType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" @@ -20,7 +19,7 @@ namespace Map { { int laddermenTribeCount = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState != 0) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState != Map::Enums::TRS_UNUSED) { if (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::isFullIDEqualsToMinus1, DAT_GameState::ptr)( DAT_TribesState::instance.tribes[tribeID].owner) && DAT_TribesState::instance.tribes[tribeID].tribeType == AI::Tribes::AITT_LADDERMEN) { @@ -29,11 +28,11 @@ namespace Map { == DAT_TribesState::instance.tribes[laddermenTribeID].someCounter1 + 1) { int const _unitID = DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID; MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::computeNextRallyPointDestination, - DAT_PathFindingState::ptr)(-1, (int)(DAT_UnitsState::instance.units[_unitID].x), - (int)(DAT_UnitsState::instance.units[_unitID].y)); - short const _rallyPointY = (short)DAT_PathFindingState::instance.ALG_ResultY; + DAT_PathFindingState::ptr)(-1, DAT_UnitsState::instance.units[_unitID].x, + DAT_UnitsState::instance.units[_unitID].y); + short const _rallyPointY = DAT_PathFindingState::instance.ALG_ResultY; DAT_TribesState::instance.tribes[laddermenTribeID].rallyPointArray[0][0] - = (short)DAT_PathFindingState::instance.ALG_ResultX; + = DAT_PathFindingState::instance.ALG_ResultX; DAT_TribesState::instance.tribes[laddermenTribeID].rallyPointArray[0][1] = _rallyPointY; return; } diff --git a/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp index e031634c9e..62a0cb4722 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp b/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp index 6c0a33ed32..d937ef013b 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setTown2.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp index 2ad00176f2..fbaba1549f 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp @@ -1,7 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" - #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { diff --git a/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp b/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp index 0e636b1b1d..ee46410e20 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/shouldLightPitchBasedOnTroopValue.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Globals/DAT_PathFindingState.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp b/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp index 847fc28c1b..fb4beb91f6 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/trySendKnightTribeToAttack.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp b/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp index d1bfcad9c0..f1f42ae6d6 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/trySendMacemenTribeToAttack.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp index 920382bc2c..1021a30670 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/updateActiveAttackWaveState.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp index cd2a8b0f21..fa64063f38 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/updateArcherBrazierProximityFlags.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp index ec9c28f971..c9247178a0 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/updateAttackInfoTick.cpp @@ -1,7 +1,6 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Game/GameStateStructures.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Units.func.hpp" #include "OpenSHC/Game/GameMode2.hpp" #include "OpenSHC/Map/MapType2.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp index acba3fd88c..88498b9be0 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/updateInProgressAttackWave.cpp @@ -1,10 +1,10 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Audio/SFX/SFXState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" @@ -20,10 +20,9 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x00520450 void TroopValueState::updateInProgressAttackWave(int attackID) { - // The original reads the wave's player here, before any of the calls below. - int const playerID = (char)DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; - BOOLEnum isAttackMostlyAlive = MACRO_CALL_MEMBER( - Map::Units::TroopValueState_Func::isLessThanPercentageOfTribesInAttackDying, this)(attackID, (int)(50)); + int const playerID = DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray[attackID]; + BOOLEnum const isAttackMostlyAlive = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::isLessThanPercentageOfTribesInAttackDying, this)(attackID, 50); if (isAttackMostlyAlive && !DAT_TroopValueState::instance.attackInfo.attackAlarmPlayed) { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::playAttackAlarmSound, this)(); } @@ -41,7 +40,7 @@ namespace Map { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::placeSiegeTentsAndAssignEngineers, this)( attackID, FALSE); } - int tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town3; + int const tribeSizeSumLimit = DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].town3; if (tribeSizeSumLimit) { MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::sortAttackInfoTribeIDArrayBasedOn, this)( attackID, 2, tribeSizeSumLimit, Map::Units::STBT_0x3f5); @@ -59,15 +58,15 @@ namespace Map { if (DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] >= DAT_AttackInfoDefinedData::instance .AttackWaveDurationPerAttacker[DAT_TroopValueState::instance.attackInfo.attacker]) { - BOOLEnum isMission39 = DAT_GameCore::instance.missionNumber1to20 == 39; + BOOLEnum const isMission39 = DAT_GameCore::instance.missionNumber1to20 == 39; DAT_TroopValueState::instance.attackInfo.attackWaveTicker[attackID] = 10000; DAT_TroopValueState::instance.attackInfo.value3Array01[attackID] = Map::Enums::AWS_ASSIGNING_TARGETS; DAT_TroopValueState::instance.attackInfo.value10 = 0; - if ((isMission39) && (DAT_TroopValueState::instance.attackInfo.attacker == 4)) { + if (isMission39 && DAT_TroopValueState::instance.attackInfo.attacker == 4) { /* "we are the macemen" */ - MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)("Mace_s4.wav"); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Mace_s4_wav_005abb68); } } } diff --git a/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp b/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp index ae0b3d9c56..de5b35a802 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/updateTribeBehaviorBasedOnBehaviorType.cpp @@ -1,6 +1,5 @@ #include "../TroopValueState.func.hpp" -#include "OpenSHC/Map.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" #include "OpenSHC/Map/Units/TribesState.func.hpp" @@ -10,7 +9,6 @@ #include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" @@ -34,8 +32,7 @@ namespace Map { { short const tribeWave = DAT_TribesState::instance.tribes[tribeID].attackWave; if (tribeWave && tribeWave < DAT_TroopValueState::instance.attackInfo.index) { - DAT_TribesState::instance.tribes[tribeID].attackWave - = (short)DAT_TroopValueState::instance.attackInfo.index; + DAT_TribesState::instance.tribes[tribeID].attackWave = DAT_TroopValueState::instance.attackInfo.index; } int const attackWave = DAT_TribesState::instance.tribes[tribeID].attackWave; DAT_TroopValueState::instance.attackInfo.nof_tribes[attackWave]++; @@ -87,7 +84,8 @@ namespace Map { if (updateCounter >= DAT_TribesState::instance.tribes[tribeID].someUpdateUpperLimit) { DAT_TribesState::instance.tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; int vector; - for (vector = 0; vector < 49; ++vector) { + for (vector = 0; vector < countof(DAT_GameState::instance.mapAndTime.attackVectors[0]) - 1; + ++vector) { if (DAT_GameState::instance.mapAndTime .attackVectors[DAT_GameSynchronyState::instance.currentPlayerSlotID][vector] .tribeID @@ -212,7 +210,7 @@ namespace Map { } int const rallyX = DAT_TribesState::instance.tribes[tribeID].rallyPointArray[rallyPoint][0]; int const rallyY = DAT_TribesState::instance.tribes[tribeID].rallyPointArray[rallyPoint][1]; - DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = (short)rallyPoint; + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = rallyPoint; if (rallyPointCount > 1 && DAT_UnitsState::instance .units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID] @@ -430,7 +428,7 @@ namespace Map { DAT_DirectionAlgorithmState::ptr)( DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, x, y); DAT_TribesState::instance.tribes[tribeID].orientation - = (short)DAT_DirectionAlgorithmState::instance.orientation; + = DAT_DirectionAlgorithmState::instance.orientation; } } return; From 470cdda7e67ca9829c9da5bd8d9640644e61388b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:34:26 +0100 Subject: [PATCH 90/94] TribeState: use the TS_ prefix (TS_UNUSED, TS_ACTIVE, TS_DISBANDED) This aligns the enum with #555, which carries the same two files byte for byte, so the two PRs do not conflict. TS_ becomes free once #549 renames TreeState to TreeStateEnum (TSE_). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Enums/TribeState.hpp | 6 +++--- .../assignBehaviorTypeAndLinkSupportTribe.cpp | 8 ++++---- .../Units/TroopValueState/commandUnitsToMoveToKeep.cpp | 4 ++-- .../TroopValueState/findTribeWithMoatAttackBehavior.cpp | 2 +- .../isLessThanPercentageOfTribesInAttackDying.cpp | 2 +- .../Units/TroopValueState/searchTribeWithProperties.cpp | 2 +- .../TroopValueState/setRallyPointForLaddermenTribe.cpp | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/Enums/TribeState.hpp b/src/OpenSHC/Map/Enums/TribeState.hpp index efbe3b2207..a0233c3a14 100644 --- a/src/OpenSHC/Map/Enums/TribeState.hpp +++ b/src/OpenSHC/Map/Enums/TribeState.hpp @@ -13,9 +13,9 @@ namespace Map { namespace Enums { typedef enum TribeState { - TRS_UNUSED = 0, // 0x00000000 - TRS_ACTIVE = 2, // 0x00000002 - TRS_DISBANDED = 3 // 0x00000003 + TS_UNUSED = 0, // 0x00000000 + TS_ACTIVE = 2, // 0x00000002 + TS_DISBANDED = 3 // 0x00000003 } TribeState; diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp index c8c939b0f4..a6be51806f 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp @@ -43,8 +43,8 @@ namespace Map { DAT_TribesState::instance.tribes[_tribeID].unknownAttackRelatedUpdateCounter = 0; for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); ++_supportTribeID) { - if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_UNUSED - && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_DISBANDED + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_UNUSED + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_DISBANDED && DAT_TribesState::instance.tribes[_supportTribeID].owner == DAT_TribesState::instance.tribes[_tribeID].owner && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 @@ -60,8 +60,8 @@ namespace Map { == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { break; } - if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_UNUSED - && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TRS_DISBANDED + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_UNUSED + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_DISBANDED && DAT_TribesState::instance.tribes[_supportTribeID].owner == DAT_TribesState::instance.tribes[_tribeID].owner && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 diff --git a/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp index fa12959fc3..669f2bd284 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/commandUnitsToMoveToKeep.cpp @@ -98,13 +98,13 @@ namespace Map { } } if (DAT_TribesState::instance.tribes[_swordsTribe].size <= 0) { - DAT_TribesState::instance.tribes[_swordsTribe].tribeState = Map::Enums::TRS_DISBANDED; + DAT_TribesState::instance.tribes[_swordsTribe].tribeState = Map::Enums::TS_DISBANDED; } else { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( _swordsTribe, x1, y1 + 1, 0, 0, Map::Units::Instructions::UMSE_0); } if (DAT_TribesState::instance.tribes[_archersTribe].size <= 0) { - DAT_TribesState::instance.tribes[_archersTribe].tribeState = Map::Enums::TRS_DISBANDED; + DAT_TribesState::instance.tribes[_archersTribe].tribeState = Map::Enums::TS_DISBANDED; } else { MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, DAT_TribesState::ptr)( _archersTribe, x1, y1, 0, 0, Map::Units::Instructions::UMSE_0); diff --git a/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp index bf735bd932..edeec47f11 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findTribeWithMoatAttackBehavior.cpp @@ -19,7 +19,7 @@ namespace Map { BOOLEnum TroopValueState::findTribeWithMoatAttackBehavior() { for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_UNUSED) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TS_UNUSED) { continue; } BOOLEnum const fullIDIsMinus1 diff --git a/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp index 187fd6f15c..141b1d3ead 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/isLessThanPercentageOfTribesInAttackDying.cpp @@ -17,7 +17,7 @@ namespace Map { int living = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { if (!DAT_TribesState::instance.tribes[tribeID].tribeState - || DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_DISBANDED + || DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TS_DISBANDED || DAT_GameSynchronyState::instance .currentPlayerFullIDArray[DAT_TribesState::instance.tribes[tribeID].owner] != -1 diff --git a/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp index 0c0271579e..a1fb62034a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/searchTribeWithProperties.cpp @@ -22,7 +22,7 @@ namespace Map { } int owner = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TRS_ACTIVE + if (DAT_TribesState::instance.tribes[tribeID].tribeState == Map::Enums::TS_ACTIVE && DAT_TribesState::instance.tribes[tribeID].owner && DAT_TribesState::instance.tribes[tribeID].owner != DAT_GameSynchronyState::instance.currentPlayerSlotID) { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp index d55376dce3..8cd9579228 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setRallyPointForLaddermenTribe.cpp @@ -19,7 +19,7 @@ namespace Map { { int laddermenTribeCount = 0; for (int tribeID = 1; tribeID < countof(DAT_TribesState::instance.tribes); ++tribeID) { - if (DAT_TribesState::instance.tribes[tribeID].tribeState != Map::Enums::TRS_UNUSED) { + if (DAT_TribesState::instance.tribes[tribeID].tribeState != Map::Enums::TS_UNUSED) { if (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::isFullIDEqualsToMinus1, DAT_GameState::ptr)( DAT_TribesState::instance.tribes[tribeID].owner) && DAT_TribesState::instance.tribes[tribeID].tribeType == AI::Tribes::AITT_LADDERMEN) { From 931d540da5a880688e12083ca7b8982b40606ac9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 18:50:45 +0100 Subject: [PATCH 91/94] Adapt to main's AttackInfoDefinedData and SiegeSpotScore - Main's AttackInfoDefinedData now declares `MappersEnum field_0xc8[9]`, which is the array at 0xB4C7CC. DAT_ARRAY_00b4c7cc.hpp is removed, and placeSiegeTentsAndAssignEngineers reads DAT_AttackInfoDefinedData::instance.field_0xc8[k]. - The 5999 comparisons use main's new SSS_UNUSABLE_THRESHOLD. - initializeOrAdvanceAttackWave includes Map/Enums/TribeState.hpp. With main's smaller struct declaration the function dropped from 100% to 46.8%: the compiler gives the &attackWaveTicker[attackWave] address its own register instead of attackWave. Declaring a few more names in the translation unit restores the original allocation, and so does the old header. Of the includes tried, this one restores 100%. Every function keeps its score in a full reccmp build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp | 23 ---------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp diff --git a/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp b/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp deleted file mode 100644 index c487b2677d..0000000000 --- a/src/OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp +++ /dev/null @@ -1,23 +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/Globals/DAT_ARRAY_00b4c7cc.hpp' -*/ - -#pragma once - -#include "OpenSHC/Commands/MappersEnum.hpp" - -// GLOBAL: STRONGHOLDCRUSADER 0x00B4C7CC -// StructResolver::Instance::instance - -namespace OpenSHC { - -using OpenSHC::Commands::MappersEnum; - -MACRO_STRUCT_RESOLVER(MappersEnum[9], false, Address::SHC_3BB0A8C1_0x00B4C7CC) DAT_ARRAY_00b4c7cc; -} // namespace OpenSHC - -MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B4C7CC); From 43b17383011cd0d611e7c03139d57e465015353a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 18:51:06 +0100 Subject: [PATCH 92/94] Adapt the .cpp files to main's AttackInfoDefinedData and SiegeSpotScore This completes 931d540da, which only removed the header. - placeSiegeTentsAndAssignEngineers reads DAT_AttackInfoDefinedData::instance.field_0xc8[k] instead of DAT_ARRAY_00b4c7cc. - The 5999 comparisons use main's new SSS_UNUSABLE_THRESHOLD, in calculateTile2MoatValueClosestToUnit, findEnemyTowersOrGates, findNearestAvailableScalePoint, getClosestWideValueBasedOnPlayer and setGate2/setMoat3/setScale3/setWide3. - initializeOrAdvanceAttackWave includes Map/Enums/TribeState.hpp. With main's smaller AttackInfoDefinedData declaration, the function dropped from 100% to 46.8%. The compiler gave the &attackWaveTicker[attackWave] address its own register instead of attackWave. Declaring a few more names in the translation unit restores the original allocation, and so does the old header. Of the includes tried, this one restores 100%. Every function keeps its score in a full reccmp build. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../calculateTile2MoatValueClosestToUnit.cpp | 4 +++- .../Map/Units/TroopValueState/findEnemyTowersOrGates.cpp | 7 +++++-- .../TroopValueState/findNearestAvailableScalePoint.cpp | 4 +++- .../TroopValueState/getClosestWideValueBasedOnPlayer.cpp | 4 +++- .../TroopValueState/initializeOrAdvanceAttackWave.cpp | 1 + .../TroopValueState/placeSiegeTentsAndAssignEngineers.cpp | 6 +++--- src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp | 5 ++++- src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp | 5 ++++- src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp | 5 ++++- src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp | 5 ++++- 10 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp index 38262c4da2..6b4395d5d1 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/calculateTile2MoatValueClosestToUnit.cpp @@ -1,6 +1,7 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" @@ -18,7 +19,8 @@ namespace Map { int minDistance = 100000; int bestIndex = -1; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moat2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].score >= 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].score + >= Map::Enums::SSS_UNUSABLE_THRESHOLD || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].moatValuesArray[i].unitID != 0) { continue; } diff --git a/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp index fb015bc102..9d4b9d581a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findEnemyTowersOrGates.cpp @@ -1,6 +1,7 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" @@ -19,7 +20,8 @@ namespace Map { int bestIndex = -1; int i; for (i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].some1000ArrayIndex_2; ++i) { - if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score + if (Map::Enums::SSS_UNUSABLE_THRESHOLD + <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].unitID) { continue; } @@ -52,7 +54,8 @@ namespace Map { } minDistance = 1000; for (i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].some1000ArrayIndex_2; ++i) { - if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score + if (Map::Enums::SSS_UNUSABLE_THRESHOLD + <= DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].score || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].gateValuesArray[i].unitID) { continue; } diff --git a/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp index 16e602e46a..a2fadb6638 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/findNearestAvailableScalePoint.cpp @@ -1,6 +1,7 @@ #include "../TroopValueState.func.hpp" #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" @@ -18,7 +19,8 @@ namespace Map { int minDistance = 1000; int bestIndex = -1; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale2; ++i) { - if (5999 <= DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score + if (Map::Enums::SSS_UNUSABLE_THRESHOLD + <= DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score || DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].unitID != 0) { continue; diff --git a/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp index bb703f78c5..c5310aa492 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/getClosestWideValueBasedOnPlayer.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" @@ -30,7 +31,8 @@ namespace Map { int i = 0; if (0 < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wide2) { for (; i < DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wide2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].score >= 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].score + >= Map::Enums::SSS_UNUSABLE_THRESHOLD || DAT_TroopValueState::instance.attackInfo.playerInfo[owner - 1].wideValuesArray[i].unitID) { continue; } diff --git a/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp index 5db2ab1c71..af032cb0f2 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/initializeOrAdvanceAttackWave.cpp @@ -4,6 +4,7 @@ #include "OpenSHC/Map/Units/TribesState.func.hpp" #include "OpenSHC/Map/WildlifeState.func.hpp" #include "OpenSHC/Map/Enums/AttackWaveState.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" #include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" #include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" diff --git a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp index a548ec6424..32f116da34 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/placeSiegeTentsAndAssignEngineers.cpp @@ -8,7 +8,7 @@ #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" -#include "OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp" +#include "OpenSHC/Globals/DAT_AttackInfoDefinedData.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" @@ -34,7 +34,7 @@ namespace Map { int engineerTotal = 0; DAT_TroopValueState::instance.attackInfo.createTribeAmount = 0; for (int k = 0; k <= 4; k++) { - Commands::MappersEnum const buildingType = DAT_ARRAY_00b4c7cc::instance[k]; + Commands::MappersEnum const buildingType = DAT_AttackInfoDefinedData::instance.field_0xc8[k]; int const engineers = INT_ARRAY_00b4d0f0::instance[k]; int const count = (char)DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave][k]; for (int n = 0; n < count; n++) { @@ -53,7 +53,7 @@ namespace Map { } } int const count = (char)DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore[attackWave][8]; - Commands::MappersEnum const buildingType = DAT_ARRAY_00b4c7cc::instance[8]; + Commands::MappersEnum const buildingType = DAT_AttackInfoDefinedData::instance.field_0xc8[8]; int const engineers = INT_ARRAY_00b4d0f0::instance[8]; for (int n = 0; n < count; n++) { if (DAT_TroopValueState::instance.attackInfo.createTribeAmount diff --git a/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp index a483e89486..3befb42c4e 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setGate2.cpp @@ -1,5 +1,7 @@ #include "../TroopValueState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" + #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { @@ -12,7 +14,8 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gate2 = 0; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].some1000ArrayIndex_2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gateValuesArray[i].score < 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gateValuesArray[i].score + < Map::Enums::SSS_UNUSABLE_THRESHOLD && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gateValuesArray[i].unitID == 0 || includeAll)) { ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].gate2; diff --git a/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp index 64060319a5..f014811a21 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setMoat3.cpp @@ -1,5 +1,7 @@ #include "../TroopValueState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" + #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { @@ -11,7 +13,8 @@ namespace Map { { DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat3 = 0; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moatValuesArray[i].score < 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moatValuesArray[i].score + < Map::Enums::SSS_UNUSABLE_THRESHOLD && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moatValuesArray[i].unitID == 0 || includeAll)) { ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].moat3; diff --git a/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp index 62a0cb4722..f4bd572b0e 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setScale3.cpp @@ -1,5 +1,7 @@ #include "../TroopValueState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" + #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { @@ -11,7 +13,8 @@ namespace Map { { DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale3 = 0; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scale2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score < 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].score + < Map::Enums::SSS_UNUSABLE_THRESHOLD && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].scaleValuesArray[i].unitID == 0 || includeAll)) { diff --git a/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp index fbaba1549f..17e395ec55 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/setWide3.cpp @@ -1,5 +1,7 @@ #include "../TroopValueState.func.hpp" +#include "OpenSHC/Map/Enums/SiegeSpotScore.hpp" + #include "OpenSHC/Globals/DAT_TroopValueState.hpp" namespace OpenSHC { @@ -11,7 +13,8 @@ namespace Map { { DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide3 = 0; for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide2; ++i) { - if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wideValuesArray[i].score < 5999 + if (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wideValuesArray[i].score + < Map::Enums::SSS_UNUSABLE_THRESHOLD && (DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wideValuesArray[i].unitID == 0 || includeAll)) { ++DAT_TroopValueState::instance.attackInfo.playerInfo[playerID - 1].wide3; From df66bdfdcfd7ae1f3800f5540e2fddce2e4d3f13 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 22:50:22 +0100 Subject: [PATCH 93/94] assignBehaviorTypeAndLinkSupportTribe: replace the two gotos with a found flag Each support-tribe search sets found and breaks; the second search runs only when the first found nothing, and the link block runs when found is set. Same code as the goto form. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../assignBehaviorTypeAndLinkSupportTribe.cpp | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp index a6be51806f..d203ec5a19 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp @@ -41,6 +41,7 @@ namespace Map { DAT_TribesState::instance.tribes[_tribeID].attackInfo_someCounter1 = DAT_TroopValueState::instance.attackInfo.someCounter1; DAT_TribesState::instance.tribes[_tribeID].unknownAttackRelatedUpdateCounter = 0; + bool found = false; for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); ++_supportTribeID) { if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_UNUSED @@ -51,31 +52,36 @@ namespace Map { && (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_CATAPULT || (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_TREBUCHET))) { - goto link; - } - } - for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); - ++_supportTribeID) { - if (DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] - == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { + found = true; break; } - if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_UNUSED - && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_DISBANDED - && DAT_TribesState::instance.tribes[_supportTribeID].owner - == DAT_TribesState::instance.tribes[_tribeID].owner - && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 - && (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_ARCHERS - || (DAT_TribesState::instance.tribes[_supportTribeID].tribeType - == AI::Tribes::AITT_CROSSBOWMEN))) { - goto link; + } + if (!found) { + for (_supportTribeID = 1; _supportTribeID < countof(DAT_TribesState::instance.tribes); + ++_supportTribeID) { + if (DAT_TroopValueState::instance.attackInfo.value3Array01[attackWave] + == Map::Enums::AWS_DELAYED_TARGET_ASSIGNMENT) { + break; + } + if (DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_UNUSED + && DAT_TribesState::instance.tribes[_supportTribeID].tribeState != Map::Enums::TS_DISBANDED + && DAT_TribesState::instance.tribes[_supportTribeID].owner + == DAT_TribesState::instance.tribes[_tribeID].owner + && DAT_TribesState::instance.tribes[_supportTribeID].tribeID == 0 + && (DAT_TribesState::instance.tribes[_supportTribeID].tribeType == AI::Tribes::AITT_ARCHERS + || (DAT_TribesState::instance.tribes[_supportTribeID].tribeType + == AI::Tribes::AITT_CROSSBOWMEN))) { + found = true; + break; + } } } - continue; - link: - DAT_TribesState::instance.tribes[_tribeID].supportTribeID = _supportTribeID; - DAT_TribesState::instance.tribes[_tribeID].uid2 = DAT_TribesState::instance.tribes[_supportTribeID].uid; - DAT_TribesState::instance.tribes[_supportTribeID].tribeID = _tribeID; + if (found) { + DAT_TribesState::instance.tribes[_tribeID].supportTribeID = _supportTribeID; + DAT_TribesState::instance.tribes[_tribeID].uid2 + = DAT_TribesState::instance.tribes[_supportTribeID].uid; + DAT_TribesState::instance.tribes[_supportTribeID].tribeID = _tribeID; + } } } From 37ab3d828c3c42f82b7213a2ffda19fa393214ec Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 00:40:34 +0100 Subject: [PATCH 94/94] 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 --- .../assignBehaviorTypeAndLinkSupportTribe.cpp | 2 +- .../Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp | 6 +++--- .../giveLightPitchInstructionToUnitClosestToPitch.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp index d203ec5a19..6d69c7eceb 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/assignBehaviorTypeAndLinkSupportTribe.cpp @@ -36,7 +36,7 @@ namespace Map { return; } DAT_TribesState::instance.tribes[_tribeID].someUpdateUpperLimit - = ((short)i + 1) * (short)updateLimitStep + (short)updateLimitBase; + = (i + 1) * updateLimitStep + updateLimitBase; DAT_TribesState::instance.tribes[_tribeID].tribeBehaviorType = behaviorType; DAT_TribesState::instance.tribes[_tribeID].attackInfo_someCounter1 = DAT_TroopValueState::instance.attackInfo.someCounter1; diff --git a/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp index b84713064c..c2511773a7 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/exitSiegeEquipmentForWave.cpp @@ -22,9 +22,9 @@ namespace Map { // 19 to 24 are the siege equipment tribe types; 19 to 21 have no AITribeType name yet. if (DAT_TribesState::instance.tribes[_tribeID].tribeState && DAT_TribesState::instance.tribes[_tribeID].attackWave == wave - && (DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)19 - || DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)20 - || DAT_TribesState::instance.tribes[_tribeID].tribeType == (AITribeType)21 + && (DAT_TribesState::instance.tribes[_tribeID].tribeType == 19 + || DAT_TribesState::instance.tribes[_tribeID].tribeType == 20 + || DAT_TribesState::instance.tribes[_tribeID].tribeType == 21 || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_CATAPULT || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_TREBUCHET || DAT_TribesState::instance.tribes[_tribeID].tribeType == AI::Tribes::AITT_FIRE_BALLISTA)) { diff --git a/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp index afb876b367..5bad844a3a 100644 --- a/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp +++ b/src/OpenSHC/Map/Units/TroopValueState/giveLightPitchInstructionToUnitClosestToPitch.cpp @@ -50,8 +50,8 @@ namespace Map { DAT_EntityState::ptr)(_pUnit->microXPosition, _pUnit->microYPosition, _pUnit->buildingHeight + 30 + _pUnit->terrainOrClimbHeight, _ditchX * 8 + 4, _ditchY * 8 + 4, - (int)(DAT_TileMapState::instance - .HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile])), + DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[_ditchID].tile]), 0 < _shot) && _distancePyth < _minDistance) { _minDistance = _distancePyth;