Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
8fb650c
headers: add globals DAT_ARRAY_00b4c7cc and INT_ARRAY_00b4d0f0
gynt Dec 4, 2026
25cfbb9
cmake: add /GL entries for the TroopValueState functions from #275
gynt Dec 4, 2026
5f57f8d
reimplement: SHC_3BB0A8C1_0x0051BC70 100.00% Reimplemented
gynt Dec 4, 2026
43df72f
reimplement: SHC_3BB0A8C1_0x0051D690 100.00% Reimplemented
gynt Dec 4, 2026
3c93ff8
reimplement: SHC_3BB0A8C1_0x00520F70 100.00% Reimplemented
gynt Dec 4, 2026
ec5b06b
reimplement: SHC_3BB0A8C1_0x005202B0 100.00% Reimplemented
gynt Dec 4, 2026
4497e17
reimplement: SHC_3BB0A8C1_0x005200A0 100.00% Reimplemented
gynt Dec 4, 2026
53f1737
reimplement: SHC_3BB0A8C1_0x00518870 100.00% Reimplemented
gynt Dec 4, 2026
c6cf0cb
reimplement: SHC_3BB0A8C1_0x00518A10 100.00% Reimplemented
gynt Dec 4, 2026
169edc1
reimplement: SHC_3BB0A8C1_0x0051CCB0 100.00% Reimplemented
gynt Dec 4, 2026
dd2d453
reimplement: SHC_3BB0A8C1_0x0051B190 100.00% Reimplemented
gynt Dec 4, 2026
7aed594
reimplement: SHC_3BB0A8C1_0x00519690 100.00% Reimplemented
gynt Dec 4, 2026
18b0f63
reimplement: SHC_3BB0A8C1_0x0051AB60 100.00% Reimplemented
gynt Dec 4, 2026
acd0914
reimplement: SHC_3BB0A8C1_0x0051A9F0 100.00% Reimplemented
gynt Dec 4, 2026
cdef502
reimplement: SHC_3BB0A8C1_0x0051A780 100.00% Reimplemented
gynt Dec 4, 2026
0df274b
reimplement: SHC_3BB0A8C1_0x0051A140 100.00% Reimplemented
gynt Dec 4, 2026
0f1ce8c
reimplement: SHC_3BB0A8C1_0x0051AFF0 100.00% Reimplemented
gynt Dec 4, 2026
2d38386
reimplement: SHC_3BB0A8C1_0x0051CA50 100.00% Reimplemented
gynt Dec 4, 2026
29f7593
reimplement: SHC_3BB0A8C1_0x0051C800 100.00% Reimplemented
gynt Dec 4, 2026
fba5476
reimplement: SHC_3BB0A8C1_0x00519310 100.00% Reimplemented
gynt Dec 4, 2026
7aae0d6
reimplement: SHC_3BB0A8C1_0x00519990 96.43% Register allocation differs
gynt Dec 4, 2026
d45bdca
reimplement: SHC_3BB0A8C1_0x0051A0C0 100.00% Reimplemented
gynt Dec 4, 2026
436573f
reimplement: SHC_3BB0A8C1_0x0051D2B0 100.00% Reimplemented
gynt Dec 4, 2026
4433448
reimplement: SHC_3BB0A8C1_0x0051D5D0 100.00% Reimplemented
gynt Dec 4, 2026
d8a9fe3
reimplement: SHC_3BB0A8C1_0x00520CD0 100.00% Reimplemented
gynt Dec 4, 2026
5f6b0f2
reimplement: SHC_3BB0A8C1_0x0051BD10 100.00% Reimplemented
gynt Dec 4, 2026
5f23e7c
reimplement: SHC_3BB0A8C1_0x0051ACE0 100.00% Reimplemented
gynt Dec 4, 2026
ca07640
reimplement: SHC_3BB0A8C1_0x0051AE00 100.00% Reimplemented
gynt Dec 4, 2026
3972dae
reimplement: SHC_3BB0A8C1_0x0051AE90 100.00% Reimplemented
gynt Dec 4, 2026
7601bf0
reimplement: SHC_3BB0A8C1_0x00519FB0 100.00% Reimplemented
gynt Dec 4, 2026
9635bf9
reimplement: SHC_3BB0A8C1_0x0051A220 100.00% Reimplemented
gynt Dec 4, 2026
a1a80a2
reimplement: SHC_3BB0A8C1_0x0051A330 100.00% Reimplemented
gynt Dec 4, 2026
43a95a8
reimplement: SHC_3BB0A8C1_0x00519CC0 100.00% Reimplemented
gynt Dec 4, 2026
b1e959d
reimplement: SHC_3BB0A8C1_0x00519E40 100.00% Reimplemented
gynt Dec 4, 2026
4fbb6ba
reimplement: SHC_3BB0A8C1_0x0051A8A0 100.00% Reimplemented
gynt Dec 4, 2026
e509ac1
reimplement: SHC_3BB0A8C1_0x0051AF20 100.00% Reimplemented
gynt Dec 4, 2026
9443013
reimplement: SHC_3BB0A8C1_0x0051A920 100.00% Reimplemented
gynt Dec 4, 2026
06a69d0
reimplement: SHC_3BB0A8C1_0x0051A5B0 100.00% Reimplemented
gynt Dec 4, 2026
db21b54
reimplement: SHC_3BB0A8C1_0x0051BDE0 100.00% Reimplemented
gynt Dec 4, 2026
4f00b79
reimplement: SHC_3BB0A8C1_0x0051B240 100.00% Reimplemented
gynt Dec 4, 2026
286cafa
reimplement: SHC_3BB0A8C1_0x0051B0C0 100.00% Reimplemented
gynt Dec 4, 2026
79f7f6a
reimplement: SHC_3BB0A8C1_0x0051C360 100.00% Reimplemented
gynt Dec 4, 2026
58b4ca8
reimplement: SHC_3BB0A8C1_0x0051BF70 100.00% Reimplemented
gynt Dec 4, 2026
ebb0012
reimplement: SHC_3BB0A8C1_0x0051C570 100.00% Reimplemented
gynt Dec 4, 2026
4cf1091
reimplement: SHC_3BB0A8C1_0x00519850 100.00% Reimplemented
gynt Dec 4, 2026
f82279a
reimplement: SHC_3BB0A8C1_0x0051FF90 100.00% Reimplemented
gynt Dec 4, 2026
897b5d2
reimplement: SHC_3BB0A8C1_0x00518BB0 100.00% Reimplemented
gynt Dec 4, 2026
5067406
reimplement: SHC_3BB0A8C1_0x0051D510 100.00% Reimplemented
gynt Dec 4, 2026
63df0fc
reimplement: SHC_3BB0A8C1_0x0051D450 100.00% Reimplemented
gynt Dec 4, 2026
66c4e8b
reimplement: SHC_3BB0A8C1_0x0051D1C0 100.00% Reimplemented
gynt Dec 4, 2026
556c262
reimplement: SHC_3BB0A8C1_0x0051B310 100.00% Reimplemented
gynt Dec 4, 2026
dd50843
reimplement: SHC_3BB0A8C1_0x0051B710 100.00% Reimplemented
gynt Dec 4, 2026
200756d
reimplement: SHC_3BB0A8C1_0x0051B570 100.00% Reimplemented
gynt Dec 4, 2026
3899f6e
reimplement: SHC_3BB0A8C1_0x0051BA30 100.00% Reimplemented
gynt Dec 4, 2026
83d4ed6
reimplement: SHC_3BB0A8C1_0x0051B6C0 100.00% Reimplemented
gynt Dec 4, 2026
ff417dc
reimplement: SHC_3BB0A8C1_0x0051F950 100.00% Reimplemented
gynt Dec 4, 2026
9e55125
reimplement: SHC_3BB0A8C1_0x0051C470 100.00% Reimplemented
gynt Dec 4, 2026
fbf55be
reimplement: SHC_3BB0A8C1_0x005198C0 100.00% Reimplemented
gynt Dec 4, 2026
918975d
reimplement: SHC_3BB0A8C1_0x0051FA70 100.00% Reimplemented
gynt Dec 4, 2026
9b68399
reimplement: SHC_3BB0A8C1_0x0051F9C0 100.00% Reimplemented
gynt Dec 4, 2026
4519b7f
reimplement: SHC_3BB0A8C1_0x0051CBD0 100.00% Reimplemented
gynt Dec 4, 2026
3183090
reimplement: SHC_3BB0A8C1_0x0051BE60 100.00% Reimplemented
gynt Dec 4, 2026
5a706b9
reimplement: SHC_3BB0A8C1_0x00518C50 100.00% Reimplemented
gynt Dec 4, 2026
e10d42c
reimplement: SHC_3BB0A8C1_0x0051F340 100.00% Reimplemented
gynt Dec 4, 2026
949c8d9
reimplement: SHC_3BB0A8C1_0x0051F4B0 100.00% Reimplemented
gynt Dec 4, 2026
b56de82
reimplement: SHC_3BB0A8C1_0x005182A0 100.00% Reimplemented
gynt Dec 4, 2026
3e4a683
reimplement: SHC_3BB0A8C1_0x0051D0D0 100.00% Reimplemented
gynt Dec 4, 2026
b7cb50a
reimplement: SHC_3BB0A8C1_0x0051A2D0 100.00% Reimplemented
gynt Dec 4, 2026
ba4f8c6
reimplement: SHC_3BB0A8C1_0x0051A720 100.00% Reimplemented
gynt Dec 4, 2026
f4394ad
reimplement: SHC_3BB0A8C1_0x00519790 100.00% Reimplemented
gynt Dec 4, 2026
6044075
reimplement: SHC_3BB0A8C1_0x00519DE0 100.00% Reimplemented
gynt Dec 4, 2026
f976d94
reimplement: SHC_3BB0A8C1_0x00519F50 100.00% Reimplemented
gynt Dec 4, 2026
48d2949
reimplement: SHC_3BB0A8C1_0x0051A550 100.00% Reimplemented
gynt Dec 4, 2026
8b17f51
reimplement: SHC_3BB0A8C1_0x0051BF20 100.00% Reimplemented
gynt Dec 4, 2026
315cc54
reimplement: SHC_3BB0A8C1_0x0051D020 100.00% Reimplemented
gynt Dec 4, 2026
c93bfe8
reimplement: SHC_3BB0A8C1_0x0051CF90 100.00% Reimplemented
gynt Dec 4, 2026
3dd7d76
reimplement: SHC_3BB0A8C1_0x0051D730 100.00% Reimplemented
gynt Dec 4, 2026
3cd205b
reimplement: SHC_3BB0A8C1_0x0051C2D0 100.00% Reimplemented
gynt Dec 4, 2026
e6190e9
reimplement: SHC_3BB0A8C1_0x0051FE80 100.00% Reimplemented
gynt Dec 4, 2026
3f86fe1
reimplement: SHC_3BB0A8C1_0x00520450 100.00% Reimplemented
gynt Dec 4, 2026
2dc1a1a
reimplement: SHC_3BB0A8C1_0x00522590 100.00% Reimplemented
gynt Dec 4, 2026
bf2c194
Restore the comment explaining tribeID's early initialisation in plac…
gynt Dec 4, 2026
52f8c09
Merge origin/main into reimpl/pr275-matched
gynt Dec 4, 2026
b8764e5
reimplement: SHC_3BB0A8C1_0x00518180 96.88% Register allocation differs
gynt Dec 4, 2026
e3a8a14
reimplement: SHC_3BB0A8C1_0x0051AF70 80.49% Register allocation differs
gynt Dec 4, 2026
8131abe
reimplement: SHC_3BB0A8C1_0x0051B110 80.49% Register allocation differs
gynt Dec 4, 2026
c74ae64
reimplement: SHC_3BB0A8C1_0x0051B290 80.49% Register allocation differs
gynt Dec 4, 2026
42afb3f
reimplement: SHC_3BB0A8C1_0x0051D7F0 97.47% Register allocation differs
gynt Dec 4, 2026
fc6339a
headers: add the TribeState enum (Map::Enums, TRS_ prefix)
gynt Dec 4, 2026
c28826c
review: pre-review pass over the 84 TroopValueState functions
gynt Dec 4, 2026
470cdda
TribeState: use the TS_ prefix (TS_UNUSED, TS_ACTIVE, TS_DISBANDED)
gynt Dec 4, 2026
f43e722
Merge origin/main 0701799a9 (upstream ghidra changes) into reimpl/pr2…
gynt Dec 4, 2026
02a1053
Merge origin/main 06cdd8116 into reimpl/pr275-matched
gynt Dec 4, 2026
931d540
Adapt to main's AttackInfoDefinedData and SiegeSpotScore
gynt Dec 4, 2026
43b1738
Adapt the .cpp files to main's AttackInfoDefinedData and SiegeSpotScore
gynt Dec 4, 2026
bdc5f83
Merge origin/main into reimpl/pr275-matched
gynt Dec 4, 2026
794bf11
Merge origin/main into reimpl/pr275-matched
gynt Dec 4, 2026
29ba1fb
Merge origin/main into reimpl/pr275-matched
gynt Dec 4, 2026
df66bdf
assignBehaviorTypeAndLinkSupportTribe: replace the two gotos with a f…
gynt Dec 4, 2026
c4608dc
Merge origin/main into reimpl/pr275-matched
gynt Dec 4, 2026
37ab3d8
review: drop redundant casts
gynt Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,19 @@ 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
src/OpenSHC/Map/Units/UpdateSlinger.cpp
src/OpenSHC/Map/Units/UpdateWoodcutter.cpp
src/OpenSHC/Map/Units/UpdateFletcher.cpp
Expand Down
30 changes: 30 additions & 0 deletions src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
}
47 changes: 47 additions & 0 deletions src/OpenSHC/Map/Units/TroopValueState/addUnitToNewTribe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "../TroopValueState.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);
}

}
}
}
38 changes: 38 additions & 0 deletions src/OpenSHC/Map/Units/TroopValueState/advanceAttackWaveStaging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "../TroopValueState.func.hpp"

#include "OpenSHC/Game/GameStateStructures.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);
}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
}
80 changes: 80 additions & 0 deletions src/OpenSHC/Map/Units/TroopValueState/aiRecomputeAttacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "../TroopValueState.func.hpp"

#include "OpenSHC/Game/GameStateStructures.func.hpp"
#include "OpenSHC/IO/LowLevelMemory.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)();
}

}
}
}
Loading
Loading