diff --git a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp new file mode 100644 index 0000000000..15ab6aca73 --- /dev/null +++ b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp @@ -0,0 +1,63 @@ +#include "../../Audio.func.hpp" + +#include "OpenSHC/Audio/SFX.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Audio { + + /* + variable _playerPointsArray made by gynt decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0044B680 + int SFX::ComputePlayerRanking(int playerID) + { + int deadPlayers[10]; + int playerPoints[10][2]; + for (int i = 0; i < 10; i++) { + playerPoints[i][0] = 0; + } + int count = 0; + for (int player = 1; player < 9; player++) { + if (DAT_GameSynchronyState::instance.finalResults.active[player] == 0) { + continue; + } + playerPoints[count][0] = player; + if (!MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::getAliveLordForPlayer, DAT_UnitsState::ptr)(player)) { + if (player == playerID) { + return 0; + } + deadPlayers[player] = 1; + playerPoints[count][1] = 0; + } else { + playerPoints[count][1] = MACRO_CALL(Audio::SFX_Func::ComputePlayerPoints1)(player); + } + count = count + 1; + } + int highestPoints; + for (int rank = 0; rank < count; rank++) { + int highestIndex = -1; + for (int i = 0; i < count; i++) { + if (playerPoints[i][0] != 0 && (highestIndex == -1 || playerPoints[i][1] > highestPoints)) { + highestPoints = playerPoints[i][1]; + highestIndex = i; + } + } + if (highestIndex < 0) { + return 0; + } + int const id = playerPoints[highestIndex][0]; + if (id == playerID) { + playerPoints[highestIndex][0] = 0; + return rank + 1; + } + playerPoints[highestIndex][0] = 0; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp new file mode 100644 index 0000000000..c7ce6d5704 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -0,0 +1,115 @@ +#include "../../Game.func.hpp" +#include "../Skirmish.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Actions.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/TrailType.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_SkirmishDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace Game { + + using Commands::GameCommandType; + using Game::GameMode; + using Game::GameMode2; + using Game::TrailType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C68D0 + void Skirmish::SetupSkirmishMode(int skirmishTrailMission) + { + CampaignTrailMission* mission; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + mission = &DAT_SkirmishDefinedData::instance.ExtremeTrailMissions[skirmishTrailMission]; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + mission = &DAT_SkirmishDefinedData::instance.WarchestTrailMissions[skirmishTrailMission]; + } else { + mission = &DAT_SkirmishDefinedData::instance.SkirmishTrailMissions[skirmishTrailMission]; + } + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); + DAT_GameSynchronyState::instance.isHost = TRUE; + DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; + DAT_GameSynchronyState::instance.DPLAYX_ReceivedPlayerID = 1; + DAT_GameCore::instance.gameMode_2 = Game::GM_SKIRMISH_AND_MULTIPLAYER; + memset(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerNames)); + int i = 0; + do { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] = -1; + DAT_GameSynchronyState::instance.currentAIArray[i] = 0; + DAT_GameSynchronyState::instance.aiVariationArray[i] = -1; + i++; + } while (i < 9); + strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[1], + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0)); + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); + for (i = 0; i < 9; i++) { + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[i] = 1; + } + DAT_GameSynchronyState::instance.skirmishRelated1 = -1; + DAT_GameCore::instance.mapU4Int0 = 0; + // the trail mission lists the AI of each player in turn; player 1 is the human + for (i = 1; i < mission->numberOfPlayers; i++) { + DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&mission->player1AI)[i]; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); + } + memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); + for (i = 0; i < 8; i++) { + if ((&mission->position1)[i] != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[(&mission->position1)[i] - 1] = (char)i; + } + } + int const players = mission->numberOfPlayers; + for (i = 0; i < 8; i++) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = (char)(&mission->team1)[i]; + if (i >= players) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = -1; + } + } + strcpy(DAT_GameSynchronyState::instance.mapName, (char*)mission->mapNameAddress); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = mission->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = mission->startLevels; + DAT_GameCore::instance.isSkirmishTrail = TRUE; + int startDateInMonths; + int monthsPerYear = 12; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + DAT_GameCore::instance.extremeTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); + startDateInMonths + = DAT_GameCore::instance.extremeTrailStartDatesInMonths[DAT_GameCore::instance.extremeTrailProgress]; + DAT_GameCore::instance.extremeTrailStartDateMonths = startDateInMonths; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + DAT_GameCore::instance.warchestTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); + startDateInMonths + = DAT_GameCore::instance.warchestTrailStartDatesInMonths[DAT_GameCore::instance.warchestTrailProgress]; + DAT_GameCore::instance.warchestTrailStartDateMonths = startDateInMonths; + } else { + DAT_GameCore::instance.skirmishTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); + startDateInMonths + = DAT_GameCore::instance.skirmishTrailStartDateInMonths[DAT_GameCore::instance.skirmishTrailProgress]; + DAT_GameCore::instance.skirmishTrailStartDateMonths = startDateInMonths; + } + DAT_GameState::instance.mapAndTime.year = startDateInMonths / monthsPerYear; + DAT_GameState::instance.mapAndTime.month = startDateInMonths % monthsPerYear; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / monthsPerYear; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % monthsPerYear; + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp new file mode 100644 index 0000000000..e25512f7f9 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp @@ -0,0 +1,31 @@ +#include "../../Game.func.hpp" +#include "../Skirmish.func.hpp" + +#include "OpenSHC/IO.func.hpp" + +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" + +namespace OpenSHC { +namespace Game { + + /* + This removes the skirmish leaderboard entry at a given index by shifting all subsequent entries down by one, + decrementing the count, and saving to disk. It's the delete operation for the SkMasters2 high score / results + table — likely called when the player deletes a saved skirmish result from the UI. decompilerscript: + committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004D5370 + void Skirmish::SkirmishLeaderboard_DeleteEntry(int index) + { + if (index >= 0 && index < DAT_SkMasters2Data::instance.count) { + // close the gap by moving every later entry up one + for (int i = index; i < DAT_SkMasters2Data::instance.count - 1; i++) { + DAT_SkMasters2Data::instance.entries[i] = DAT_SkMasters2Data::instance.entries[i + 1]; + } + DAT_SkMasters2Data::instance.count = DAT_SkMasters2Data::instance.count - 1; + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp new file mode 100644 index 0000000000..d60116df65 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp @@ -0,0 +1,92 @@ +#include "../../../Game.func.hpp" +#include "../SkirmishLobbySetupStructure.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/INT_00b960b0.hpp" + +namespace OpenSHC { +namespace Game { + namespace Skirmish { + + // FUNCTION: STRONGHOLDCRUSADER 0x00490060 + void SkirmishLobbySetupStructure::restoreSkirmishLobbySetup() + { + DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes = this->mapu4int2; + this->mbr_0x4 = DAT_GameState::instance.mapAndTime.skirmishFogOfWar; + strcpy(DAT_GameSynchronyState::instance.mapName, this->mapName); + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[0] = this->roundTableOrderArray[0]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[0] = this->playerGroupArray[0]; + DAT_GameSynchronyState::instance.currentAIArray[0] = this->currentAIArray[0]; + DAT_GameSynchronyState::instance.aiVariationArray[0] = this->aiVariationArray[0]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[1] = this->roundTableOrderArray[1]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[1] = this->playerGroupArray[1]; + DAT_GameSynchronyState::instance.currentAIArray[1] = this->currentAIArray[1]; + DAT_GameSynchronyState::instance.aiVariationArray[1] = this->aiVariationArray[1]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[2] = this->roundTableOrderArray[2]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[2] = this->playerGroupArray[2]; + DAT_GameSynchronyState::instance.currentAIArray[2] = this->currentAIArray[2]; + DAT_GameSynchronyState::instance.aiVariationArray[2] = this->aiVariationArray[2]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[3] = this->roundTableOrderArray[3]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[3] = this->playerGroupArray[3]; + DAT_GameSynchronyState::instance.currentAIArray[3] = this->currentAIArray[3]; + DAT_GameSynchronyState::instance.aiVariationArray[3] = this->aiVariationArray[3]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[4] = this->roundTableOrderArray[4]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[4] = this->playerGroupArray[4]; + DAT_GameSynchronyState::instance.currentAIArray[4] = this->currentAIArray[4]; + DAT_GameSynchronyState::instance.aiVariationArray[4] = this->aiVariationArray[4]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[5] = this->roundTableOrderArray[5]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[5] = this->playerGroupArray[5]; + DAT_GameSynchronyState::instance.currentAIArray[5] = this->currentAIArray[5]; + DAT_GameSynchronyState::instance.aiVariationArray[5] = this->aiVariationArray[5]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[6] = this->roundTableOrderArray[6]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[6] = this->playerGroupArray[6]; + DAT_GameSynchronyState::instance.currentAIArray[6] = this->currentAIArray[6]; + DAT_GameSynchronyState::instance.aiVariationArray[6] = this->aiVariationArray[6]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[7] = this->roundTableOrderArray[7]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[7] = this->playerGroupArray[7]; + DAT_GameSynchronyState::instance.currentAIArray[7] = this->currentAIArray[7]; + DAT_GameSynchronyState::instance.aiVariationArray[7] = this->aiVariationArray[7]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[8] = this->roundTableOrderArray[8]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[8] = this->playerGroupArray[8]; + DAT_GameSynchronyState::instance.currentAIArray[8] = this->currentAIArray[8]; + DAT_GameSynchronyState::instance.aiVariationArray[8] = this->aiVariationArray[8]; + DAT_GameSynchronyState::instance.playerPositionsArray[0] = this->slot1Position; + DAT_GameSynchronyState::instance.playerPositionsArray[1] = this->slot2Position; + DAT_GameSynchronyState::instance.playerPositionsArray[2] = this->slot3Position; + DAT_GameSynchronyState::instance.playerPositionsArray[3] = this->slot4Position; + DAT_GameSynchronyState::instance.playerPositionsArray[4] = this->slot5Position; + DAT_GameSynchronyState::instance.playerPositionsArray[5] = this->slot6Position; + DAT_GameSynchronyState::instance.playerPositionsArray[6] = this->slot7Position; + DAT_GameSynchronyState::instance.playerPositionsArray[7] = this->slot8Position; + DAT_GameSynchronyState::instance.currentPlayerSlotID = this->currentPlayerSlotID; + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = this->currentAdvantageBalance; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = this->currentAdvantageGroup; + DAT_GameSynchronyState::instance.skirmishTechLevel = this->mbr_0x80; + DAT_GameCore::instance.selectedLordTypes[0] = this->playerLordTypeArray[0]; + DAT_GameCore::instance.selectedLordTypes[1] = this->playerLordTypeArray[1]; + DAT_GameCore::instance.selectedLordTypes[2] = this->playerLordTypeArray[2]; + DAT_GameCore::instance.selectedLordTypes[3] = this->playerLordTypeArray[3]; + DAT_GameCore::instance.selectedLordTypes[4] = this->playerLordTypeArray[4]; + DAT_GameCore::instance.selectedLordTypes[5] = this->playerLordTypeArray[5]; + DAT_GameCore::instance.selectedLordTypes[6] = this->playerLordTypeArray[6]; + DAT_GameCore::instance.selectedLordTypes[7] = this->playerLordTypeArray[7]; + DAT_GameCore::instance.selectedLordTypes[8] = this->playerLordTypeArray[8]; + DAT_GameCore::instance.field_0x2340 = this->mbr_0xf0; + DAT_GameCore::instance.selectedLordTypeUnk = this->selectedLordType; + DAT_GameSynchronyState::instance.skirmishDefaultPopularity = this->popularity; + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = this->mapSelectionRelativeSelected; + DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = this->mapSelectionScrollOffset; + DAT_GameSynchronyState::instance.lobbyMapSortOrder = this->mbr_0xfc; + INT_00b960b0::instance = DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected; + MACRO_CALL_MEMBER( + Synchrony::GameSynchronyState_Func::reorderTeamsAndPositions, DAT_GameSynchronyState::ptr)(); + } + + } +} +} diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp new file mode 100644 index 0000000000..a8f1a1b9b6 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -0,0 +1,134 @@ +#include "../../Game.func.hpp" + +#include "OpenSHC/Game/Skirmish.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_00ed3124.hpp" +#include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/INT_00eb9b60.hpp" +#include "OpenSHC/Globals/INT_00ed2bdc.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00eb0e48.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00eb96d8.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00ed27f0.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00ed2be0.hpp" + +namespace OpenSHC { +namespace Game { + + using DE::SHCDE::eTextSections; + + // FUNCTION: STRONGHOLDCRUSADER 0x004D9400 + void Skirmish::Skirmish_PrepareLeaderboardView() + { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + INT_ARRAY_00eb0e48::instance[i] = 1; + } + // filter 1 hides the custom maps (no trail mission score), filter 2 the trail missions + if (DAT_00ed3124::instance == 1) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (!DAT_SkMasters2Data::instance.entries[i].score) { + INT_ARRAY_00eb0e48::instance[i] = 0; + } + } + } else if (DAT_00ed3124::instance == 2) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (DAT_SkMasters2Data::instance.entries[i].score) { + INT_ARRAY_00eb0e48::instance[i] = 0; + } + } + } + // columns 0 and 1 keep the stored order, forwards or backwards + if (DAT_MissionDefinedData::instance.sortColumn <= 1) { + INT_00eb9b60::instance = 0; + if (DAT_MissionDefinedData::instance.descending == 1) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + } else if (!DAT_MissionDefinedData::instance.descending) { + for (int k = 0; k < DAT_SkMasters2Data::instance.count; k++) { + int const i = DAT_SkMasters2Data::instance.count - 1 - k; + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + } + return; + } + // date + if (DAT_MissionDefinedData::instance.sortColumn == 4) { + INT_00eb9b60::instance = 0; + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = ((DAT_SkMasters2Data::instance.entries[i].localTimeYear - 2000) * 16 + + DAT_SkMasters2Data::instance.entries[i].localTimeMonth) + * 32 + + DAT_SkMasters2Data::instance.entries[i].localTimeDay; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + return; + } + // mission: trail missions by score, custom maps by the first two letters of their name + if (DAT_MissionDefinedData::instance.sortColumn == 2) { + INT_00eb9b60::instance = 0; + if (DAT_00ed3124::instance == 1) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = 0x50 - DAT_SkMasters2Data::instance.entries[i].score; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + } else { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + OpenSHC::IO::SkMasterDataEntry& entry = DAT_SkMasters2Data::instance.entries[i]; + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + if (entry.score) { + strcpy(entry.mapName, + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_TRAIL_NAMES_CRU, entry.score)); + } + byte first = entry.mapName[0]; + if (first >= 'A' && first <= 'Z') { + first = first + 0x20; + } + byte second = entry.mapName[1]; + if (second >= 'A' && second <= 'Z') { + second = second + 0x20; + } + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] = -1 - first * 0x100 - second; + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + return; + } + // duration + if (DAT_MissionDefinedData::instance.sortColumn == 3) { + INT_00eb9b60::instance = 0; + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = -1 - DAT_SkMasters2Data::instance.entries[i].gameDurationInMinutes; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + } +} +} diff --git a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp new file mode 100644 index 0000000000..b06dfd56fe --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp @@ -0,0 +1,54 @@ +#include "../../Game.func.hpp" + +#include "OpenSHC/Game/Skirmish.func.hpp" +#include "OpenSHC/IO.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_SkMasterDataEntry.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" + +namespace OpenSHC { +namespace Game { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004D52A0 + void Skirmish::StoreGameIntoSKMasters(int score) + { + if (!MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score)) { + return; + } + int count = DAT_SkMasters2Data::instance.count; + int insertIndex = -1; + if (count <= 0) { + insertIndex = 0; + } + if (count < 250) { + insertIndex = count; + } + if (insertIndex != 0) { + for (int i = 0; i < count; i++) { + if (DAT_SkMasterDataEntry::instance.skMasterScore + > DAT_SkMasters2Data::instance.entries[i].skMasterScore) { + insertIndex = i; + break; + } + } + if (insertIndex == -1) { + return; + } + } + for (; count > insertIndex; count--) { + if (count <= 249) { + DAT_SkMasters2Data::instance.entries[count] = DAT_SkMasters2Data::instance.entries[count - 1]; + } + } + DAT_SkMasters2Data::instance.entries[insertIndex] = DAT_SkMasterDataEntry::instance; + if (DAT_SkMasters2Data::instance.count < 250) { + DAT_SkMasters2Data::instance.count = DAT_SkMasters2Data::instance.count + 1; + } + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + +} +} diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp new file mode 100644 index 0000000000..7ef67b72a7 --- /dev/null +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -0,0 +1,94 @@ +#include "../Game.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_00df5558.hpp" +#include "OpenSHC/Globals/DAT_00df5560.hpp" +#include "OpenSHC/Globals/DAT_00df5590.hpp" +#include "OpenSHC/Globals/DAT_DisableTutorialRestrictions.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" + +namespace OpenSHC { + +using WindowsHelper::Enums::BOOLEnum; + +// FUNCTION: STRONGHOLDCRUSADER 0x004BD800 +BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) +{ + if (DAT_DisableTutorialRestrictions::instance) { + return TRUE; + } + switch (actionType) { + case 1: + if (DAT_TutorialCurrentStep::instance == 2) { + if (DAT_00df5558::instance < 2 && actionParam == 40) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (DAT_00df5558::instance == 0 && actionParam == 19) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == 3 && DAT_00df5560::instance == 0) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == 7) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == 1) { + return TRUE; + } + } + return FALSE; + case 2: + if (DAT_TutorialCurrentStep::instance == 2) { + if (DAT_00df5558::instance < 2 && actionParam == 40) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (DAT_00df5558::instance == 0 && actionParam == 19 && DAT_00df5560::instance == 0) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == 3 && (int)DAT_00df5590::instance < 4) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == 7 && (int)DAT_00df5590::instance < 4) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == 1 && DAT_00df5560::instance == 0) { + return TRUE; + } + } + return FALSE; + case 3: + if (DAT_TutorialCurrentStep::instance != 8) { + return FALSE; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].rationsSetting + == 4 + && actionParam != 4) { + return FALSE; + } + break; + case 4: + if (DAT_TutorialCurrentStep::instance != 10) { + return FALSE; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting + == 7 + && actionParam != 7) { + return FALSE; + } + break; + } + return TRUE; +} + +} diff --git a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp new file mode 100644 index 0000000000..1dfaddd6b9 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp @@ -0,0 +1,41 @@ +#include "../../Map.func.hpp" +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BC110 + void MapPropertiesState::adjustEventMonthAndYearForSection1047() + { + DAT_GameState::instance.mapAndTime.militaryCampaignStage = 0; + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month; + DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; + DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + if (DAT_GameCore::instance.missionNumber1to20 == 17) { + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 1); + } else if (DAT_GameCore::instance.missionNumber1to20 == 18) { + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 1); + return; + } else if (DAT_GameCore::instance.missionNumber1to20 == 19) { + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 6); + } else if (DAT_GameCore::instance.missionNumber1to20 == 20) { + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 3); + } else { + return; + } + if (DAT_GameState::instance.mapAndTime.month >= 12) { + DAT_GameState::instance.mapAndTime.month = DAT_GameState::instance.mapAndTime.month - 12; + DAT_GameState::instance.mapAndTime.year = DAT_GameState::instance.mapAndTime.year + 1; + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp new file mode 100644 index 0000000000..ff1e0d14df --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -0,0 +1,309 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.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_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode2; + using Map::Units::UnitLogicState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BDE40 + void MapPropertiesState::computeMissionCompletionScore() + { + int deadlineMonth = 0; + int deadlineYear = 0; + this->missionScore = 0xffffffff; + this->objectiveGoodsCount = 0; + for (int i = 0; i < this->eventsCount; i++) { + // a goal with a time limit sets the deadline + if (this->scenarioEvents[i].header.tl_type == 3 + && (this->scenarioEvents[i].data.scenario.ScenarioEventType == 1 + || this->scenarioEvents[i].data.scenario.ScenarioEventType == 0x1b) + && this->scenarioEvents[i].data.scenario.conditions[0].enabled) { + deadlineMonth = this->scenarioEvents[i].header.month; + deadlineYear = this->scenarioEvents[i].header.year; + } + if (this->scenarioEvents[i].header.tl_type != 3 + || (this->scenarioEvents[i].data.scenario.ScenarioEventType != 0 + && this->scenarioEvents[i].data.scenario.ScenarioEventType != 0x1a)) { + continue; + } + // only the last win condition counts + bool superseded = false; + for (int later = i + 1; later < this->eventsCount; later++) { + if (this->scenarioEvents[later].header.tl_type == 3 + && (this->scenarioEvents[later].data.scenario.ScenarioEventType == 0 + || this->scenarioEvents[later].data.scenario.ScenarioEventType == 0x1a)) { + superseded = true; + break; + } + } + if (superseded) { + continue; + } + if (this->scenarioEvents[i].data.scenario.conditions[6].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[6].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[6].value); + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 11: + case 12: + case 13: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; + } + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (this->scenarioEvents[i].data.scenario.conditions[17].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[17].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[17].value); + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 11: + case 12: + case 13: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; + } + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (this->scenarioEvents[i].data.scenario.conditions[5].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[5].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[5].value); + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 11: + case 12: + case 13: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; + } + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (this->scenarioEvents[i].data.scenario.conditions[7].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[7].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[7].value); + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 11: + case 12: + case 13: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; + } + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (this->scenarioEvents[i].data.scenario.conditions[4].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[0xf] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[4].value); + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (this->scenarioEvents[i].data.scenario.conditions[1].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = -1; + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentPopulation + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + this->scenarioEvents[i].data.scenario.conditions[1].value); + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + } + this->monthsRemaining = 0; + this->timeBonusScore = 0; + if (deadlineYear != 0) { + int const months = (deadlineYear - DAT_GameState::instance.mapAndTime.year) * 12 + - DAT_GameState::instance.mapAndTime.month + deadlineMonth; + this->monthsRemaining = months > 0 ? months : 0; + this->timeBonusScore = this->monthsRemaining * 100; + } + this->missionScore = this->timeBonusScore; + this->missionScore = this->missionScore + + DAT_MissionAestheticsDefinedData::instance + .MissionScoreByDifficulty[DAT_GameState::instance.mapAndTime.difficulty]; + for (int i = 0; i < this->objectiveGoodsCount; i++) { + this->missionScore = this->missionScore + this->objectiveGoodsScore[i]; + } + this->troopSurvivalScore = 0; + // the original reads the global instance here rather than this + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && (int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2)) { + int surviving = 0; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].owner == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_UnitsState::instance.units[i].isSelectable_OR_matchTime != 0) { + surviving = surviving + + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)DAT_UnitsState::instance.units[i].unitType); + } + } + int const lost + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .weightedLosses; + int const total = lost + surviving; + if (total != 0) { + this->troopLossPercent = lost * 100 / total; + this->troopSurvivalScore = (100 - this->troopLossPercent) * 100; + this->missionScore = this->missionScore + this->troopSurvivalScore; + } + } + if (DAT_GameCore::instance.mapU4Int1) { + int surviving = 0; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].owner == 1 + && DAT_UnitsState::instance.units[i].isSelectable_OR_matchTime != 0) { + surviving = surviving + + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)DAT_UnitsState::instance.units[i].unitType); + } + } + this->enemyTroopValueSurviving = surviving; + int const lost = DAT_GameState::instance.playerDataArray[2].weightedLosses; + this->enemyTroopValueLost = lost; + this->enemyTroopValueTotal = lost + surviving; + } + } +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp new file mode 100644 index 0000000000..d01f93c98d --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp @@ -0,0 +1,231 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/AI/AICState.func.hpp" +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/FilePackager.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/AI/Siege/SiegeUnitCounts.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/GameMode2Int.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.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_VideoBikQueue.hpp" +#include "OpenSHC/Globals/FilePackagerObj.hpp" +#include "OpenSHC/Globals/TIME_ReceivedMessage_2.hpp" + +namespace OpenSHC { +namespace Map { + + using AI::Siege::SiegeUnitCounts; + using Game::GameMode2; + using Game::GameMode2Int; + using IO::FileResourceType; + using Map::Units::UnitLogicState; + using Map::Units::UnitType; + using Map::Units::UnitTypeShort; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C62C0 + void MapPropertiesState::loadMap(char* mapName) + { + // reading the map overwrites these, so they are kept across it + GameMode2Int const gameMode = DAT_GameCore::instance.gameMode_2; + int const missionNumber = DAT_GameCore::instance.missionNumber1to20; + int const difficulty = DAT_GameState::instance.mapAndTime.difficulty; + int const playerSlotID = DAT_GameSynchronyState::instance.currentPlayerSlotID; + int const xbowProducible = DAT_GameCore::instance.xbowProducible_logic; + int const swordProducible = DAT_GameCore::instance.swordProducible_logic; + int const pikeProducible = DAT_GameCore::instance.pikeProducible_logic; + int const bowProducible = DAT_GameCore::instance.bowProducible_logic; + int const maceProducible = DAT_GameCore::instance.maceProducible_logic; + int const spearProducible = DAT_GameCore::instance.spearProducible_logic; + int const jester = DAT_GameState::instance.mapAndTime.unitJesterRelated; + int const lady = DAT_GameState::instance.mapAndTime.unitLadyRelated; + // a byte buffer: the original has a security cookie, and these two sit right under it + char savedFields[8]; + memcpy(savedFields, &DAT_GameState::instance.mapAndTime.field43_0xf0, sizeof(savedFields)); + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::resetTeams, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::setupAllMapSections, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + IO::FRT_MAPS, mapName); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapOrSavFile, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray); + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::mapLoadingAndLaunchGameRelated1, DAT_SoundSystemState::ptr)(); + DAT_GameState::instance.mapAndTime.difficulty = difficulty; + DAT_GameCore::instance.xbowProducible_logic = xbowProducible; + DAT_GameCore::instance.swordProducible_logic = swordProducible; + DAT_GameCore::instance.pikeProducible_logic = pikeProducible; + DAT_GameCore::instance.bowProducible_logic = bowProducible; + DAT_GameCore::instance.mapTimeInTicks = 1; + DAT_GameCore::instance.section1127 = 1; + DAT_GameCore::instance.spearProducible_logic = spearProducible; + DAT_GameCore::instance.maceProducible_logic = maceProducible; + DAT_GameCore::instance.missionNumber1to20 = missionNumber; + DAT_GameCore::instance.gameMode_2 = gameMode; + if (missionNumber == 1) { + // the first mission hands up to eight of the player's archers to player 3 + int left = 8; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].unitType == Map::Units::UT_E_ARCHER + && DAT_UnitsState::instance.units[i].owner == 1) { + left = left - 1; + DAT_UnitsState::instance.units[i].calculatedOwnerPlayerIndex = 3; + if (left == 0) { + break; + } + } + } + } + DAT_GameState::instance.mapAndTime.unitLadyRelated = (short)lady; + for (int i = 0; i < 9; i++) { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] = -1; + } + DAT_GameState::instance.mapAndTime.unitJesterRelated = (short)jester; + DAT_GameSynchronyState::instance.currentPlayerSlotID = playerSlotID; + memcpy(&DAT_GameState::instance.mapAndTime.field43_0xf0, savedFields, sizeof(savedFields)); + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerSlotID] = 1; + for (int i = 1; i < 9; i++) { + DAT_GameState::instance.playerDataArray[i].tacticalPowersBarLevel = 0; + } + DAT_GameCore::instance.isTimeHalted = FALSE; + DAT_GameCore::instance.section1095 = 0; + strcpy((char*)this->SEC_Section1089, mapName); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + MACRO_CALL_MEMBER(Game::GameCore_Func::removeJesterAndLadyUnitsInCertainMissions, DAT_GameCore::ptr)(); + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::removeLadyAndJester, DAT_GameCore::ptr)(); + } + int* const eventsExtra = (int*)this->SEC_EventsExtra; + for (int i = 0; i < 8000; i++) { + eventsExtra[i] = 0; + } + DAT_GameState::instance.mapAndTime.month = this->SEC_StartingMonth; + DAT_GameState::instance.mapAndTime.year = this->SEC_StartingYear; + if (DAT_GameCore::instance.missionNumber1to20 >= 16 && DAT_GameCore::instance.missionNumber1to20 <= 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::adjustEventMonthAndYearForSection1047, this)(); + } + // the start goods only apply when the events left the start date alone + if (DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth + && DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear) { + for (int i = 0; i < 25; i++) { + DAT_GameState::instance.mapAndTime.startGoods[i] = this->SEC_StartingResources[i]; + } + DAT_GameState::instance.mapAndTime.startGoods[7] = DAT_GameState::instance.mapAndTime.startGoods[8]; + DAT_GameState::instance.mapAndTime.startGoods[8] = 0; + int* const siegeInformation = (int*)&DAT_GameState::instance.mapAndTime.siegeInformation; + for (int i = 0; i < 20; i++) { + siegeInformation[i] = this->SEC_SiegeInformation[i]; + } + DAT_GameState::instance.mapAndTime.startingPopularity = this->SEC_StartingPopularity * 10; + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::setMonthAndYear, DAT_GameState::ptr)( + this->SEC_StartingMonth, this->SEC_StartingYear); + } + this->SEC_Section1080 = 0; + this->SEC_Section1081 = FALSE; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::countDeerEfficiently, DAT_TribesState::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::prepareMap, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::clearEnemyRelatedStructures, DAT_GameState::ptr)(); + DAT_UnitsState::instance.lastSelectedUnitID = 0; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::clearSelectionCountsAndPlayerIDs, DAT_UnitsState::ptr)(); + // the original reads the global instance here rather than this + DAT_GameState::instance.mapAndTime.euroRecruitable[4] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.macemen; + DAT_GameState::instance.mapAndTime.euroRecruitable[5] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.swordsmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[6] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.knights; + DAT_GameState::instance.mapAndTime.mercRecruitable[0] = DAT_MapPropertiesState::instance.SEC_MercRecruitable[0]; + DAT_GameState::instance.mapAndTime.euroRecruitable[0] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.archers; + DAT_GameState::instance.mapAndTime.euroRecruitable[1] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.crossbowmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[2] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.spearmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[3] + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.pikemen; + for (int i = 1; i < 7; i++) { + DAT_GameState::instance.mapAndTime.mercRecruitable[i] + = DAT_MapPropertiesState::instance.SEC_MercRecruitable[i]; + } + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c = 0; + if (DAT_GameState::instance.mapAndTime.euroRecruitable[0] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[2] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[4] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[5] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[6] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c = 1; + } + DAT_GameState::instance.mapAndTime.countUpTo201 = 0; + DAT_GameState::instance.mapAndTime.cathedralRelated1 = 0; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::importTradingCosts, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::clearAttackInfo, DAT_TroopValueState::ptr)(); + MACRO_CALL_MEMBER(AI::AICState_Func::recomputeAIZonerLayer, DAT_AICState::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::setSignpostDistanceForCampaignMission, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playNextStoredBinkVideo, DAT_VideoBikQueue::ptr)(); + DAT_GameCore::instance.xbowProducible_logic = DAT_MapPropertiesState::instance.SEC_XbowProducible_save; + DAT_GameCore::instance.bowProducible_logic = DAT_MapPropertiesState::instance.SEC_BowProducible_save; + DAT_GameCore::instance.pikeProducible_logic = DAT_MapPropertiesState::instance.SEC_PikeProducible_save; + DAT_GameCore::instance.spearProducible_logic = DAT_MapPropertiesState::instance.SEC_SpearProducible_save; + DAT_GameCore::instance.swordProducible_logic = DAT_MapPropertiesState::instance.SEC_SwordProducible_save; + DAT_GameCore::instance.maceProducible_logic = DAT_MapPropertiesState::instance.SEC_MaceProducible_save; + DAT_GameCore::instance.timeSum_2 = timeGetTime(); + DAT_GameCore::instance.gameDuration = 0; + TIME_ReceivedMessage_2::instance = 0; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp new file mode 100644 index 0000000000..fbbb0c20c4 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp @@ -0,0 +1,41 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + /* + Looks up the map filename for mission index param_1 (1-based, range 1-20) from + MissionAestheticsDefinedData.field15_0x3c and calls loadMapSiegeHeaderSections. Covers all four groups of 5 + missions (1-5, 6-10, 11-15, 16-20). Does nothing if param_1 is out of range. renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6820 + void MapPropertiesState::loadMapSiegeHeaderForMissionIndex(char* param_1) + { + param_1 = param_1 - 1; + if ((int)param_1 < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; + } + if ((int)param_1 < 10) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; + } + if ((int)param_1 < 15) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; + } + if ((int)param_1 < 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp new file mode 100644 index 0000000000..9761c048c8 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp @@ -0,0 +1,39 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + /* + Loads the map file for the given mission number (1-based) from MissionAestheticsDefinedData.field14_0x38, then + calls UnitsState::setMissionNumberSpecificLord to configure the lord unit for that mission. Covers missions + 1-20. renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6880 + void MapPropertiesState::loadMissionMapAndSetLord(int missionNumber) + { + missionNumber = missionNumber - 1; + if (missionNumber < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 10) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 15) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setMissionNumberSpecificLord, DAT_UnitsState::ptr)( + missionNumber + 1); + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp new file mode 100644 index 0000000000..e534fc3da7 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -0,0 +1,2668 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Game/ScenarioEvents/ScenarioEventCondition.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" +#include "OpenSHC/UI/Enums/BuildMenuTabType.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BinkControlState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition3.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.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_VideoBikQueue.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using Audio::SFX::SoundEffectID; + using Commands::MappersEnum; + using DE::SHCDE::eTextSections; + using Game::GameMode; + using Game::GameMode2; + using Game::ScenarioEvents::ScenarioEventCondition; + using Map::MapType2; + using Map::Buildings::BuildingLogicalState; + using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; + using Map::Units::UnitLogicState; + using Map::Units::UnitType; + using Map::Units::UnitTypeInt; + using Map::Units::UnitTypeShort; + using Map::Units::Instructions::UnitMatchSpeedEnum; + using UI::Enums::BuildingsAndStatusMenuTabType; + using UI::Enums::BuildMenuTabType; + using UI::Enums::DisplayElementID; + using UI::Enums::MenuModalType; + using UI::Enums::MenuViewType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C31A0 + void MapPropertiesState::processSingleplayerEvents() + { + int iVar1; + byte(*pabVar2)[10]; + byte* pbVar3; + byte bVar4; + byte bVar5; + UnitTypeShort UVar6; + short sVar7; + short sVar8; + BuildingTypeShort BVar9; + char* pcVar10; + BOOLEnum BVar11; + UnitTypeShort* pUVar12; + BuildingTypeShort* pBVar13; + dword tribeID; + dword dVar14; + ScenarioEventCondition* pSVar15; + int _invasionAmplifier; + InGameEventUnionVersion* pIVar16; + char cVar17; + int iVar18; + int uVar19; + int _unitSpawnTotalAdjustment; + int iVar20; + int numInGroup; + InGameEventUnionVersion* psVar21; + int _unitAIBehaviourTypeUnk; + int iVar21; + int iVar22; + uint y1; + UnitTypeInt _unitType; + int bVar23; + char* pcVar25; + int local_a0; + int _eventIndex; + int _subIndex; + int _spawnUnitCount; + int local_88; + int local_80; + int _previousScenarioEventIndex; + int local_70[10]; + int local_48[18]; + int _amplifiedUnitTotalForUnitType; + int _crusaderOrArabian; + int _repeatMonths; + int _counter; + int _scenarioEventType; + int _eventType; + int* _pConditionIsMet; + local_88 = 0; + local_70[9] = DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter; + _previousScenarioEventIndex = -1; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::updateMilitaryCampaignMissionState, this)(); + } + return; + } + + if ((DAT_GameCore::instance.gameMode_2 != Game::GM_EDITOR) + && (DAT_GameCore::instance.gameMode_2 != Game::GM_SIEGE_THAT)) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(UI::Helpers_Func::UpdateTutorialStepAndProgress)(); + } + if (DAT_GameCore::instance.section1095 != 1) { + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + != 0) { + if (DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0 + && !DAT_VideoBikQueue::instance.storedMessages_0x924) { + DAT_GameState::instance.mapAndTime.unknownCountdown01 + = DAT_GameState::instance.mapAndTime.unknownCountdown01 - 1; + } + if (DAT_GameState::instance.mapAndTime.unknownCountdown01 != 0) { + return; + } + DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; + MACRO_CALL_MEMBER( + UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); + DAT_GameCore::instance.section1066 = 2; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + DAT_GameCore::instance.section1066 = 0; + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMission, DAT_GameCore::ptr)(); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + if (DAT_GameCore::instance.field_0x6c) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL(UI::MenuItems::General_Func:: + MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); + } else { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + if ((int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } else { + DAT_GameCore::instance.section1095 = 1; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + } + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + DAT_GameCore::instance.section1066 = 2; + } + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + return; + } else { + if ((this->SEC_Section1081) && (0 < this->SEC_Section1080)) { + this->SEC_Section1080 = this->SEC_Section1080 + -1; + } + if (DAT_GameState::instance.mapAndTime.startOfDay) { + if (DAT_GameCore::instance.unknownAlwaysZero) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated = 1; + DAT_GameCore::instance.unknownAlwaysZero = 0; + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 10; + return; + } + _pConditionIsMet = DAT_GameState::instance.mapAndTime.scenarioEventTimers; + do { + if ((*_pConditionIsMet != 0) + && (iVar18 = *_pConditionIsMet + 1, *_pConditionIsMet = iVar18, 0x4b0 < iVar18)) { + *_pConditionIsMet = 0; + } + _pConditionIsMet = _pConditionIsMet + 1; + } while ((int)_pConditionIsMet < 0x117ee60); + local_48[0] = -1; + local_48[1] = 0xffffffff; + local_48[2] = 0xffffffff; + local_48[3] = 0xffffffff; + local_48[4] = 0xffffffff; + local_48[5] = 0xffffffff; + local_48[6] = 0xffffffff; + local_48[7] = 0xffffffff; + local_48[8] = 0xffffffff; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + local_70[0] = 0; + local_48[9] = 0; + local_70[1] = 0; + local_48[10] = 0; + local_70[2] = 0; + local_48[0xb] = 0; + local_70[3] = 0; + local_48[0xc] = 0; + local_70[4] = 0; + local_48[0xd] = 0; + local_70[5] = 0; + local_48[0xe] = 0; + local_70[6] = 0; + local_48[0xf] = 0; + local_70[7] = 0; + local_48[0x10] = 0; + local_70[8] = 0; + local_48[0x11] = 0; + if ((((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) + && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear + 1)) + && (DAT_GameState::instance.gameTicksLoadBalancer == 1)) + && ((!DAT_GameState::instance.mapAndTime.week && (bVar23 = 0, 0 < this->eventsCount)))) { + _pConditionIsMet = &this->scenarioEvents[0].data.scenario.ScenarioEventType; + iVar18 = this->eventsCount; + do { + if ((_pConditionIsMet[-3] == 3) && (*_pConditionIsMet == 0x1e)) { + bVar23 = 1; + } + _pConditionIsMet = _pConditionIsMet + 0x39; + iVar18 = iVar18 + -1; + } while (iVar18); + if (bVar23) { + /* + if a fire warning event + */ + for (iVar18 = 0; iVar18 < DAT_BuildingsState::instance.maxBuildingsCount; iVar18++) { + if (DAT_BuildingsState::instance.buildings[iVar18].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar18].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && (DAT_BuildingsState::instance.buildings[iVar18].buildingType + == Map::Buildings::BT_WELL + || DAT_BuildingsState::instance.buildings[iVar18].buildingType + == Map::Buildings::BT_WATERPOT)) + goto LAB_004c3637; + } + /* + "there are no wells in the castle my liege. should a fire break out, we are int + great danger." added by script: "There are no wells in the castle my Liege. + Should a fire break out we would be in great danger." + */ + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12), + "ap_civil12.bik", "general_message3.wav"); + } + } + LAB_004c3637: + _eventIndex = 0; + if (0 < this->eventsCount) { + do { + iVar18 = this->scenarioEvents[_eventIndex].header.year; + if ((DAT_GameState::instance.mapAndTime.year < iVar18) + || ((DAT_GameState::instance.mapAndTime.year == iVar18 + && (DAT_GameState::instance.mapAndTime.month + < this->scenarioEvents[_eventIndex].header.month)))) + break; + /* + "next Event" + */ + if (this->scenarioEvents[_eventIndex].header.done != 0) + goto LAB_004c5f28; + _eventType = this->scenarioEvents[_eventIndex].header.tl_type; + switch (_eventType) { + case 3: + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + if ((!iVar18) || (iVar18 == 0x1a)) { + if (_previousScenarioEventIndex != -1) { + this->scenarioEvents[_previousScenarioEventIndex].header.done = 1; + } + _previousScenarioEventIndex = _eventIndex; + } + local_a0 = 0; + /* + this is from invasion event code, ignore the meaning here + */ + _counter = 0; + for (_subIndex = 0; _subIndex < 40; _subIndex++) { + /* + this condition is empty? then move to next condition + */ + if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .enabled + == 0) + continue; + _counter = _counter + 1; + /* + Extra event info at: 0x0165f028 + */ + _pConditionIsMet + = &this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex]; + *_pConditionIsMet = 0; + switch (_subIndex) { + case 0: + local_a0 = _counter; + break; + case 1: + iVar22 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentPopulation; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; + case 2: + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .lordKilledByPlayerID; + if (!iVar18) + break; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 == '\0' || iVar18 == 10 || cVar17 + 1 == iVar18) + goto LAB_004c3fcd; + LAB_004c37cd: + *_pConditionIsMet = 0; + break; + case 3: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerRelatedFlag + != 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + } + goto LAB_004c37cd; + case 4: + iVar22 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xf]; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; + case 5: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 == 0) { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xd] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xc] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xb] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[10]; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } else { + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } + break; + case 6: + case 0x11: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 == 0) { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x18] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x17] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x16] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x15] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x14] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x13] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x12] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x11]; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } else { + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } + break; + case 7: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 == 0) { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[9] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[7] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[6] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[4] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[3] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[2] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xe]; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } else { + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + } + break; + LAB_004c3fcd: + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xf: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) + || (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 + != Map::MT_SIEGE)) + || ((DAT_GameSynchronyState::instance.currentPlayerSlotID != 1 + || (BVar11 = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::isAttackWaveComplete, + DAT_TroopValueState::ptr)(), + !BVar11)))) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 8: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) { + _scenarioEventType + = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + if (((_scenarioEventType == 0x1a) || (!_scenarioEventType)) + || (_scenarioEventType == 0x17)) { + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; + iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 1 + && this->scenarioEvents[iVar18].data.invasion.repeatMonths + == 0 + && this->scenarioEvents[iVar18].header.done == 0) + goto switchD_004c3756_caseD_18; + } + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } + break; + case 9: + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::checkKeepEnclosed, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + if (!BVar11) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 10: + iVar18 = 0; + if (DAT_UnitsState::instance.maxUnitCount < 2) + goto LAB_004c3fcd; + pUVar12 = &DAT_UnitsState::instance.units[1].unitType; + iVar22 = DAT_UnitsState::instance.maxUnitCount - 1; + do { + if ((pUVar12[-1] == Map::Units::ULS_NORMAL) + && (*pUVar12 == Map::Units::UT_LIONSHWOLF)) { + iVar18 = iVar18 + 1; + } + pUVar12 = pUVar12 + 0x248; + iVar22 = iVar22 + -1; + } while (iVar22); + if (iVar18) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xb: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xc: + iVar18 = 0; + for (iVar22 = 1; iVar22 < DAT_UnitsState::instance.maxUnitCount; iVar22++) { + if (DAT_UnitsState::instance.units[iVar22].logicalState + == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[iVar22].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_UnitsState::instance.units[iVar22].isStalked == 0 + && DAT_UnitsState::instance.units[iVar22].unknownTestAgainst0_2 + == 0) { + UVar6 = DAT_UnitsState::instance.units[iVar22].unitType; + if (UVar6 != Map::Units::UT_E_LADDER + && (UVar6 != Map::Units::UT_E_ENGINEER + || DAT_UnitsState::instance.units[iVar22].resourceToDeposit + != 0) + && UVar6 != Map::Units::UT_S_TOWER + && UVar6 != Map::Units::UT_S_BATTERINGRAM + && UVar6 != Map::Units::UT_S_SHIELD + && UVar6 != Map::Units::UT_S_MANGONEL + && UVar6 != Map::Units::UT_S_BALLISTA + && UVar6 != Map::Units::UT_S_CATAPULT + && UVar6 != Map::Units::UT_S_FBALLISTA + && UVar6 != Map::Units::UT_S_TREBUCHET) { + iVar18 = iVar18 + 1; + } + } + } + if (iVar18 == 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; + case 0xd: + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 != '\0') { + if (((byte)(cVar17 - 1U) <= 3) + && (DAT_GameState::instance.mapAndTime + .hitsDealtToPlayerArray[cVar17 + 1] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value)) { + DAT_GameState::instance.mapAndTime + .hitsDealtToPlayerArray[cVar17 + 1] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { + if (DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value) { + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8] = 0; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex] = 1; + local_a0 = local_a0 + 1; + } + } + break; + case 0xe: + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; + if (cVar17 != '\0') { + if (((byte)(cVar17 - 1U) <= 3) + && (DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value)) { + DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { + if (DAT_GameState::instance.mapAndTime.emenyHitArray[8] + + DAT_GameState::instance.mapAndTime.emenyHitArray[7] + + DAT_GameState::instance.mapAndTime.emenyHitArray[6] + + DAT_GameState::instance.mapAndTime.emenyHitArray[5] + + DAT_GameState::instance.mapAndTime.emenyHitArray[4] + + DAT_GameState::instance.mapAndTime.emenyHitArray[3] + + DAT_GameState::instance.mapAndTime.emenyHitArray[2] + + DAT_GameState::instance.mapAndTime.emenyHitArray[1] + + DAT_GameState::instance.mapAndTime.emenyHitArray[0] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value) { + DAT_GameState::instance.mapAndTime.emenyHitArray[0] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[1] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[2] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[3] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[4] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[5] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[6] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[7] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[8] = 0; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex] = 1; + local_a0 = local_a0 + 1; + } + } + break; + case 0x14: + sVar7 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .previousBlessedPeoplePercentage; + sVar8 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value; + if (sVar7 >= sVar8) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x16: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .fearFactorLevel + <= -(int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x17: + iVar22 = (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value; + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .fearFactorLevel; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x15: + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::computeAleCoverage, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + iVar22 = (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x27: + if (local_a0 == _counter - 1) { + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_VICTORY, 1); + if (!this->SEC_Section1081) { + this->SEC_Section1080 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x27] + .value + * 800; + this->SEC_Section1090 = this->SEC_Section1080; + } + this->SEC_Section1081 = 1; + if (this->SEC_Section1080 <= 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { + if (this->SEC_Section1081) { + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_VICTORY, 0); + } + this->SEC_Section1081 = 0; + } + break; + case 0x10: + if (DAT_GameState::instance.mapAndTime.cathedralRelated1 == 1) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x12: + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + break; + } + iVar18 = 0; + for (iVar22 = 1; iVar22 < DAT_BuildingsState::instance.maxBuildingsCount; + iVar22++) { + if (DAT_BuildingsState::instance.buildings[iVar22].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar22].buildingType + == Map::Buildings::BT_DAIRYFARM + && DAT_BuildingsState::instance.buildings[iVar22] + .currentlyNeededEmployeeCount + == 0) { + iVar18 = iVar18 + 1; + } + } + if (iVar18 >= 4) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; + case 0x13: + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + break; + } + iVar18 = 0; + for (iVar22 = 1; iVar22 < DAT_BuildingsState::instance.maxBuildingsCount; + iVar22++) { + if (DAT_BuildingsState::instance.buildings[iVar22].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar22].buildingType + == Map::Buildings::BT_INN + && DAT_BuildingsState::instance.buildings[iVar22] + .currentlyNeededEmployeeCount + == 0 + && DAT_BuildingsState::instance.buildings[iVar22] + .flagonsOfAleOrCheeseOrReleaseDogs + > 0) { + iVar18 = iVar18 + 1; + } + } + if (iVar18 >= 2) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; + } + switchD_004c3756_caseD_18:; + } + if (((this->scenarioEvents[_eventIndex].data.scenario.allOrAnyCondition != 0) + || (!local_a0)) + && (local_a0 < _counter)) + goto LAB_004c5f28; + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + this->scenarioEvents[_eventIndex].header.done = 1; + DAT_GameState::instance.mapAndTime.scenarioEventTimers[iVar18] = 1; + switch (this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType) { + case 0x1a: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 3 + && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0 + || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0x1a) + && this->scenarioEvents[iVar18].header.year + <= DAT_GameState::instance.mapAndTime.year + && (DAT_GameState::instance.mapAndTime.year + != this->scenarioEvents[iVar18].header.year + || DAT_GameState::instance.mapAndTime.month + > this->scenarioEvents[iVar18].header.month)) + goto switchD_004c382e_caseD_2; + } + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 0; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + LAB_004c4072: + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + this->scenarioEvents[_eventIndex].header.month = iVar22; + if (iVar22 >= 12) { + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar22 - 12; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 0: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 3 + && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0 + || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0x1a) + && this->scenarioEvents[iVar18].header.year + <= DAT_GameState::instance.mapAndTime.year + && (DAT_GameState::instance.mapAndTime.year + != this->scenarioEvents[iVar18].header.year + || DAT_GameState::instance.mapAndTime.month + > this->scenarioEvents[iVar18].header.month)) + goto switchD_004c382e_caseD_2; + } + if (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_ECONOMIC_CAMPAIGN_SH1)) + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk)) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerDeathRelated = 1; + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 1); + if ((DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM) + || (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab + = DAT_GameCore::instance.tabTypeSiegeSubset; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + } + DAT_TileMapState::instance.currentMapperCommand + = Commands::M_MAPPER_NULL; + if (0 < DAT_UnitsState::instance.totalUnitsInSelection) { + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::queueEscapeCommand, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, + DAT_MouseState::ptr)(); + } + this->field133_0x145d8 = 0; + if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[1] + .enabled + != 0) { + this->field133_0x145d8 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[4] + .enabled + != 0) { + this->field133_0x145d8 = 2; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[5] + .enabled + == 0 + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[6] + .enabled + == 0 + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[7] + .enabled + == 0 + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[17] + .enabled + == 0) { + this->field133_0x145d8 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else { + this->field133_0x145d8 = 3; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } + break; + } + } + goto switchD_004c382e_caseD_2; + case 0x1b: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 1; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + goto LAB_004c4072; + } + goto switchD_004c382e_caseD_2; + case 1: + if ((DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerDeathRelated + == 0) + && (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_ECONOMIC_CAMPAIGN_SH1)) + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk)))) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated = 2; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setAIControlStatusTo100000, + DAT_UnitsState::ptr)(); + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; + if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) + && (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 + == Map::MT_SIEGE)) { + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0x280; + } + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 2); + if ((DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM) + || (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab + = DAT_GameCore::instance.tabTypeSiegeSubset; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + } + DAT_TileMapState::instance.currentMapperCommand = Commands::M_MAPPER_NULL; + if (0 < DAT_UnitsState::instance.totalUnitsInSelection) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::queueEscapeCommand, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, + DAT_MouseState::ptr)(); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 3: + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::flagTribesOfType, DAT_TribesState::ptr)(0xe); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 4: + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.actionData; + if (!iVar18) { + iVar18 = 1; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::consumeFlaggedTribesOfType, + DAT_TribesState::ptr)(0xe, iVar18); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 5: + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (int)((int)(SEC_RNG::instance.currentNumber2 % 9)), + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry + * 8, + (int)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 3) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 6) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 9) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), + Map::Units::UT_FIREEATER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 0xc) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), + Map::Units::UT_FIREEATER); + /* + "a travelling fair has come to town my lord" added by script: "A + ‘Travelling Fair’ has come to town, my Lord." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1), + DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName, + "Random_Events1.wav"); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 >= 12) { + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + } + LAB_004c4621: + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 6: + DAT_GameCore::instance.isTimeHalted = TRUE; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 7: + DAT_GameCore::instance.isTimeHalted = FALSE; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 8: + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::switchPlayerOwnership, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setupBarracksCampgroundPositions, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setupMercenaryPostCampgroundPositions, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::triggerStoneTowerDeathForPlayer, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::countPlayerResources, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + DAT_GameCore::instance.secondaryActiveMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + DAT_GameCore::instance.tabTypeSiegeSubset = UI::Enums::BMTT_CASTLE; + if (((DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU) + && ((DAT_GameCore::instance.activeMenuTab.tabType + != UI::Enums::BASMTT_STOCKS + || (MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0), + DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU)))) + && ((DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM + || (DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_BUILD_MENU, 0); + } + iVar22 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + iVar18 + = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .lordID; + if ((!iVar18) + || (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .lordUID + == DAT_UnitsState::instance.units[iVar18].uid)) + goto switchD_004c382e_caseD_2; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .lordID = 0; + DAT_GameState::instance.playerDataArray[iVar22].lordUID = 0; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 9: + DAT_GameCore::instance.xbowProducible_logic = 1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xb: + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventPlagueCountdown = 0x18; + iVar22 + = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity; + if (6000 < iVar22) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = (iVar22 + -6000) / 2 + 6000; + } + MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: + spawnPoisonCloudsAtRandomStorageOrArmyBuilding, + DAT_GameState::ptr)( + iVar18, this->scenarioEvents[_eventIndex].data.scenario.actionData); + /* + added by script: "Plague has descended on our castle your lordship." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2), + DAT_MissionAestheticsDefinedData::instance.RandomEvent2VideoName, + "Random_Events2.wav"); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xc: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WHEATFARM); + if (iVar18) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::harmWheatFarmsOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + /* + added by script: "A pestilence is devastating our wheat crops, Sire." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 3), + DAT_MissionAestheticsDefinedData::instance.RandomEvent3VideoName, + "Random_Events3.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xd: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_HOPFARM); + if (iVar18) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::harmHopFarmsOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + /* + added by script: "Our hops plants are overrun with hop weevil, the + crop is ruined, My Liege." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 4), + DAT_MissionAestheticsDefinedData::instance.RandomEvent4VideoName, + "Random_Events4.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xe: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_APPLEFARM); + if (iVar18) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::harmAppleFarmTreesOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + /* + added by script: "Our apple orchards are barren, my lord. The people + suspect witchcraft." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 5), + "", "Random_Events5.wav"); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", + (char*)((int)(DAT_MissionAestheticsDefinedData::instance + .RandomEvent5VideoName)), + ""); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xf: + MACRO_CALL_MEMBER(Map::LandscapeState_Func::ageFourFifthsOfGrowingTrees, + DAT_LandscapeState::ptr)(); + /* + added by script: "Sire, woodcutters report that the recent drought has + killed off many trees." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6), + DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName, + "Random_Events6.wav"); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x10: + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::hasAvailableSpawnSlotForWildlifeOrMercs, + DAT_TribesState::ptr)(); + if ((iVar18) + && ((iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_HOPFARM), + iVar18 != 0 + || (iVar18 = MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WHEATFARM), + iVar18 != 0)))) { + DAT_GameState::instance.mapAndTime.eventCountdownRabbitInfestation = 1200; + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::spawnRabbitAtFirstFreeSpawnPoint, + DAT_TribesState::ptr)(); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)(DAT_TribesState::instance.unknownX_01, + DAT_TribesState::instance.unknownY_01); + /* + added by script: "Rabbits are breeding at an alarming rate Liege. Our + crops are threatened." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 7), + DAT_MissionAestheticsDefinedData::instance.RandomEvent7VideoName, + "Random_Events7.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x11: { + uint uStack_7c; + uint uStack_78; + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::findRecentOrSignpostSpawnLocation, + DAT_TribesState::ptr)(&uStack_78, &uStack_7c); + if ((iVar18) + && (BVar11 + = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(uStack_78, uStack_7c), + iVar18 = DAT_GameSynchronyState::instance.currentPlayerSlotID, + BVar11)) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventLionsCountdown = 0xc; + iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; + if (6000 < iVar22) { + DAT_GameState::instance.playerDataArray[iVar18].popularity + = (iVar22 + -6000) / 2 + 6000; + } + iVar18 = 0; + if (0 < this->scenarioEvents[_eventIndex].data.scenario.actionData) { + do { + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::findRecentOrSignpostSpawnLocation, + DAT_TribesState::ptr)(&uStack_78, &uStack_7c); + dVar14 + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createAnimal, + DAT_TribesState::ptr)(Commands::M_MAPPER_LION, uStack_78, + uStack_7c, + (int)((int)((uint) + * (byte*)(DAT_ViewportRenderState::instance + .translationMatrix[uStack_7c] + .addXgetTile + + 0x1d32c38 + uStack_78)))); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)(uStack_78, (int)((int)(uStack_7c))); + iVar18 = iVar18 + 1; + DAT_TribesState::instance.tribes[dVar14].unknownBool02 = 0; + DAT_TribesState::instance.tribes[dVar14].unknownBool01 = 1; + } while (iVar18 + < this->scenarioEvents[_eventIndex].data.scenario.actionData); + } + /* + added by script: "I have alarming reports that lions are abroad in the + land. People are scared my Lord." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 8), + "", ""); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + case 0x12: + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::hasAnySignpost, DAT_GameState::ptr)(); + if (BVar11) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventBanditsCountdown = 0x10; + DAT_TroopValueState::instance.attackInfo.inv_count + = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, 0); + DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray + [DAT_TroopValueState::instance.attackInfo.inv_count] = 8; + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::pickRandomAccessibleSignpostEntry, + DAT_GameState::ptr)(); + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_MACEMEN, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, 8, + Map::Units::UT_E_MACE, + this->scenarioEvents[_eventIndex].data.scenario.actionData + 1); + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + iVar18 = 0; + if (0 < DAT_TribesState::instance.tribes[dVar14].size) { + do { + iVar22 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar18); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + iVar18 = iVar18 + 1; + DAT_UnitsState::instance.units[iVar22].calculatedOwnerPlayerIndex + = 5; + DAT_UnitsState::instance.units[iVar22].logicalState + = Map::Units::ULS_NORMAL; + } while (iVar18 < sVar7); + } + /* + added by script: "Bandits are operating near the castle Lordship." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 9), + DAT_MissionAestheticsDefinedData::instance.RandomEvent9VideoName, + "Random_Events9.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x13: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_DAIRYFARM); + if (iVar18) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setRandomNumberOnCows, + DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setDairyFarmCheeseCounter, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + /* + added by script: "Our cows have been struck down by a strange malady, + my lord." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 10), + "", "Random_Events10.wav"); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", + (char*)((int)(DAT_MissionAestheticsDefinedData::instance + .RandomEvent10VideoName)), + ""); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x14: + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::hasAnySignpost, DAT_GameState::ptr)(); + if (BVar11) { + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::pickRandomAccessibleSignpostEntry, + DAT_GameState::ptr)(); + iVar22 = 0; + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_ARCHER, + this->scenarioEvents[_eventIndex].data.scenario.actionData); + tribeID = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_HOPS_FARMER_UNK, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_MONK, 1); + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 0; + DAT_TribesState::instance.tribes[tribeID].pendingScatterMove = 0; + if (0 < DAT_TribesState::instance.tribes[dVar14].size) { + do { + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar22); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + iVar22 = iVar22 + 1; + DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex + = 8; + DAT_UnitsState::instance.units[iVar18].logicalState + = Map::Units::ULS_NORMAL; + } while (iVar22 < sVar7); + } + iVar18 = 0; + if (0 < DAT_TribesState::instance.tribes[tribeID].size) { + do { + iVar22 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(tribeID, iVar18); + DAT_UnitsState::instance.units[iVar22].calculatedOwnerPlayerIndex + = 8; + DAT_UnitsState::instance.units[iVar22].logicalState + = Map::Units::ULS_NORMAL; + iVar18 = iVar18 + 1; + } while (iVar18 < DAT_TribesState::instance.tribes[tribeID].size); + } + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id; + if (0 < iVar18) { + BVar9 = DAT_BuildingsState::instance.buildings[iVar18].buildingType; + uVar19 = 0; + y1 = 0; + if (BVar9 == Map::Buildings::BT_MANORHOUSE) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 8; + } else if (BVar9 == Map::Buildings::BT_STONEKEEP) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 3; + } else if (BVar9 == Map::Buildings::BT_STRONGHOLD) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 3; + } else if (BVar9 == Map::Buildings::BT_KEEPFOUR) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 4; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 4; + } else if (BVar9 == Map::Buildings::BT_KEEPFIVE) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 5; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 5; + } + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveTribeMoveInstruction, + DAT_TribesState::ptr)( + dVar14, uVar19, y1, 0, 0, Map::Units::Instructions::UMSE_0); + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveTribeMoveInstruction, + DAT_TribesState::ptr)( + tribeID, uVar19, y1, 0, 0, Map::Units::Instructions::UMSE_0); + } + /* + added by script: "Some outlaws from the woods have returned to our + cause, my lord." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xb), + DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName, + "Random_Events11.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x15: + DAT_GameState::instance.mapAndTime.unitLadyRelated = 1; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventMarriageCountdown = 0xc; + if (10000 < DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = 10000; + } + /* + added by script: "The people rejoice at your forthcoming marriage, Sire." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc), + DAT_MissionAestheticsDefinedData::instance.RandomEvent12VideoName, + "Random_Events12.wav"); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, + DAT_SFXState::ptr)(Audio::SFX::SEID_CHAPEL_BELL); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x16: + DAT_GameState::instance.mapAndTime.unitJesterRelated = 1; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventJesterCountdown = 0x30; + if (10000 < DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = 10000; + } + /* + added by script: "A Jester has arrived at the castle Liege. I have taken + the liberty of offering him employment." + */ + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd), + DAT_MissionAestheticsDefinedData::instance.RandomEvent13VideoName, + "Random_Events13.wav"); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1d: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .totalFood + != 0) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::applyFoodLossPercentageToPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + this->scenarioEvents[_eventIndex].data.scenario.actionData); + /* added by script: "Thieves have stolen some food from our granary." */ + if (this->scenarioEvents[_eventIndex].data.scenario.actionData == 100) { + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x10), + DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, + "general_message3.wav"); + } else { + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xe), + DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, + "general_message3.wav"); + } + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1e: + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .eventFireCountdown = 8; + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::spreadFireRandomlyToBuildings, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + this->scenarioEvents[_eventIndex].data.scenario.actionData); + /* added by script: "There is fire in the castle and we have not built any wells + * my Liege!" */ + if (MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WELL)) { + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xf), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); + } else if (MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WATERPOT)) { + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xf), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); + } else { + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x11), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x17: + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) + && (this->scenarioEvents[_eventIndex].header.year == 0x43d)) + && (this->scenarioEvents[_eventIndex].header.month == 0xb)) { + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, 0x85, 0x116, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_ARCHER, 0x14); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 3; + if (0 < sVar7) { + iVar18 = 0; + do { + iVar22 = iVar18 + 1; + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar18); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex + = 6; + iVar18 = iVar22; + } while (iVar22 < sVar7); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 0x19: + DAT_GameCore::instance.section1076 = 1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x18: + DAT_GameCore::instance.section1076 = 0; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1c: + iVar18 = 0; + if (0 < this->eventsCount) { + do { + if (this->scenarioEvents[iVar18].header.tl_type == 1 + && this->scenarioEvents[iVar18].data.invasion.repeatMonths != 0) { + this->scenarioEvents[iVar18].data.invasion.repeatMonths = 0; + this->scenarioEvents[iVar18].header.done = 1; + this->scenarioEvents[iVar18].header.year = 1181; + } + iVar18 = iVar18 + 1; + } while (iVar18 < this->eventsCount); + } + default: + switchD_004c382e_caseD_2: + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + break; + case 2: + this->scenarioEvents[_eventIndex].header.done = 1; + break; + case 1: + /* + Invasion + */ + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 0; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiHoldBackTicks = -200; + /* + invasion. ? + */ + iVar18 = local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian]; + if (local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + == -1) { + DAT_TroopValueState::instance.attackInfo.inv_count + = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, + this->scenarioEvents[_eventIndex].data.invasion.messageMonth); + local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + = DAT_TroopValueState::instance.attackInfo.inv_count; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + iVar18 = DAT_TroopValueState::instance.attackInfo.inv_count; + } + DAT_TroopValueState::instance.attackInfo.inv_count = iVar18; + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] + = (char)this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian + 2; + _subIndex = 0; + do { + /* + if invasion.units[index] == 0 then index += 1 (break when not index < + 0x19) + */ + iVar18 = this->scenarioEvents[_eventIndex] + .data.invasion.unitCountsPerUnitType[_subIndex]; + if (!iVar18) + goto LAB_004c5db4; + _unitAIBehaviourTypeUnk = 0; + _unitType = ((UnitType)0); + _unitSpawnTotalAdjustment = 0; + switch (_subIndex) { + case 0: + _unitAIBehaviourTypeUnk = 3; + _unitType = Map::Units::UT_E_ARCHER; + break; + case 1: + _unitAIBehaviourTypeUnk = 7; + _unitType = Map::Units::UT_E_XBOW; + break; + case 2: + _unitAIBehaviourTypeUnk = 5; + _unitType = Map::Units::UT_E_SPEAR; + break; + case 3: + _unitAIBehaviourTypeUnk = 6; + _unitType = Map::Units::UT_E_PIKE; + break; + case 4: + _unitAIBehaviourTypeUnk = 9; + _unitType = Map::Units::UT_E_MACE; + break; + case 5: + _unitAIBehaviourTypeUnk = 8; + _unitType = Map::Units::UT_E_SWORD; + break; + case 6: + _unitAIBehaviourTypeUnk = 10; + _unitType = Map::Units::UT_E_KNIGHT; + _unitSpawnTotalAdjustment = 10; + goto switchD_004c5b0c_default; + case 7: + _unitAIBehaviourTypeUnk = 4; + _unitType = Map::Units::UT_E_LADDER; + break; + case 8: + _unitAIBehaviourTypeUnk = 0xb; + _unitType = Map::Units::UT_E_ENGINEER; + break; + case 9: + _unitAIBehaviourTypeUnk = 0x16; + _unitType = Map::Units::UT_S_CATAPULT; + break; + case 10: + _unitAIBehaviourTypeUnk = 0x17; + _unitType = Map::Units::UT_S_TREBUCHET; + break; + case 0xb: + _unitAIBehaviourTypeUnk = 0x13; + _unitType = Map::Units::UT_S_BATTERINGRAM; + break; + case 0xc: + _unitAIBehaviourTypeUnk = 0x14; + _unitType = Map::Units::UT_S_TOWER; + break; + case 0xd: + _unitAIBehaviourTypeUnk = 0x15; + _unitType = Map::Units::UT_S_SHIELD; + break; + case 0xe: + _unitAIBehaviourTypeUnk = 0xc; + _unitType = Map::Units::UT_E_MONK; + break; + case 0xf: + _unitAIBehaviourTypeUnk = 2; + _unitType = Map::Units::UT_TUNNELER; + break; + case 0x10: + _unitAIBehaviourTypeUnk = 0x19; + _unitType = Map::Units::UT_A_ARCHER; + break; + case 0x11: + _unitAIBehaviourTypeUnk = 0x1a; + _unitType = Map::Units::UT_A_SLAVE; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x12: + _unitAIBehaviourTypeUnk = 0x1b; + _unitType = Map::Units::UT_A_SLINGER; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x13: + _unitAIBehaviourTypeUnk = 0x1c; + _unitType = Map::Units::UT_A_ASSASSIN; + _unitSpawnTotalAdjustment = 2; + goto switchD_004c5b0c_default; + case 0x14: + _unitAIBehaviourTypeUnk = 0x1d; + _unitType = Map::Units::UT_A_HARCHER; + break; + case 0x15: + _unitAIBehaviourTypeUnk = 0x1e; + _unitType = Map::Units::UT_A_SWORDSMAN; + _unitSpawnTotalAdjustment = 8; + goto switchD_004c5b0c_default; + case 0x16: + _unitAIBehaviourTypeUnk = 0x1f; + _unitType = Map::Units::UT_A_FIRETHROWER; + _unitSpawnTotalAdjustment = 4; + goto switchD_004c5b0c_default; + case 0x17: + _unitAIBehaviourTypeUnk = 0x18; + _unitType = Map::Units::UT_S_FBALLISTA; + break; + default: + goto switchD_004c5b0c_default; + } + _unitSpawnTotalAdjustment = 10; + switchD_004c5b0c_default: + _invasionAmplifier = 100; + switch (DAT_GameState::instance.mapAndTime.difficulty) { + case 0: + _invasionAmplifier = 50; + break; + case 2: + _invasionAmplifier = 140; + break; + case 3: + _invasionAmplifier = 200; + break; + } + _amplifiedUnitTotalForUnitType = (_invasionAmplifier * iVar18) / 100; + cVar17 = (char)_amplifiedUnitTotalForUnitType; + if (_unitAIBehaviourTypeUnk == 0x16) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][0] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][0] + + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x17) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][1] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][1] + + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x13) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][2] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][2] + + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x14) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][3] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][3] + + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x15) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][4] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][4] + + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x18) { + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][8] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][8] + + cVar17; + } else { + _spawnUnitCount = _amplifiedUnitTotalForUnitType + / (_amplifiedUnitTotalForUnitType / _unitSpawnTotalAdjustment + 1); + while (0 < _amplifiedUnitTotalForUnitType) { + if (_spawnUnitCount > _amplifiedUnitTotalForUnitType) { + _spawnUnitCount = _amplifiedUnitTotalForUnitType; + } + iVar18 + = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; + iVar22 = local_48[iVar18 + 9]; + local_48[iVar18 + 9] = iVar22 + 1; + iVar21 = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance + .attackInfo.inv_count]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, + DAT_TribesState::ptr)(iVar22, _unitAIBehaviourTypeUnk, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .x, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .y, + iVar18 + 2, (UnitType)((int)(_unitType)), ((UnitType)0), + _spawnUnitCount, 0); + local_88 = local_88 + 1; + _amplifiedUnitTotalForUnitType + = _amplifiedUnitTotalForUnitType - _spawnUnitCount; + if (local_88 >= local_70[9]) { + local_88 = 0; + } + } + } + LAB_004c5db4: + _subIndex = _subIndex + 1; + } while (_subIndex < 0x19); + iVar18 = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray + [DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + DAT_TroopValueState::instance.attackInfo.inv_count = local_80; + if ((!DAT_GameCore::instance.section1076) + && (_crusaderOrArabian + = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian, + local_70[_crusaderOrArabian] == 0)) { + local_70[_crusaderOrArabian] = 1; + switch (_crusaderOrArabian) { + case 0: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", "sultan_nervous.bik", "infidel_attack.wav"); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + "", "good_soldier_nervous.bik", "arabian_attack.wav"); + break; + } + if ((DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU) + && ((DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || (DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { + MACRO_CALL_MEMBER( + Game::GameCore_Func::swapBuildMenuTab, DAT_GameCore::ptr)(); + if (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) { + if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + } else if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo.buildMenuTab + = 0xe7; + } + } + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + (UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, 0); + } + } + _repeatMonths = this->scenarioEvents[_eventIndex].data.invasion.repeatMonths; + if (!_repeatMonths) { + this->scenarioEvents[_eventIndex].header.done = 1; + } else { + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + _repeatMonths / 0xc; + iVar18 = this->scenarioEvents[_eventIndex].header.year; + this->scenarioEvents[_eventIndex].header.month + = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; + iVar22 = this->scenarioEvents[_eventIndex].header.month; + this->scenarioEvents[_eventIndex].header.pre_done = 0; + if (iVar22 >= 12) { + this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; + this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; + } + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + } + break; + } + LAB_004c5f28: + _eventIndex = _eventIndex + 1; + } while (_eventIndex < this->eventsCount); + } + local_88 = DAT_GameState::instance.mapAndTime.year; + iVar18 = DAT_GameState::instance.mapAndTime.month + 3; + if (iVar18 >= 12) { + iVar18 = iVar18 - 12; + local_88 = local_88 + 1; + } + local_70[0] = 0; + local_70[1] = 0; + local_70[2] = 0; + local_70[3] = 0; + local_70[4] = 0; + local_70[5] = 0; + local_70[6] = 0; + local_70[7] = 0; + local_70[8] = 0; + for (_eventIndex = 0; _eventIndex < this->eventsCount; _eventIndex++) { + if (local_88 != this->scenarioEvents[_eventIndex].header.year + || iVar18 != this->scenarioEvents[_eventIndex].header.month + || this->scenarioEvents[_eventIndex].header.pre_done != 0) { + continue; + } + this->scenarioEvents[_eventIndex].header.pre_done = 1; + switch (this->scenarioEvents[_eventIndex].header.tl_type) { + case 1: + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1; + if (DAT_GameCore::instance.section1076 != 0) { + continue; + } + iVar22 = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; + if (local_70[iVar22] != 0) { + continue; + } + iVar20 = 0; + numInGroup = iVar22 * 4 + 1; + for (int k = 0; k < 25; k++) { + iVar20 = iVar20 + + this->scenarioEvents[_eventIndex].data.invasion.unitCountsPerUnitType[k]; + } + if (iVar20 >= 25) { + if (iVar20 < 75) { + numInGroup = numInGroup + 1; + } else if (iVar20 < 150) { + numInGroup = numInGroup + 2; + } else { + numInGroup = numInGroup + 3; + } + } + local_70[iVar22] = 1; + switch (iVar22) { + case 0: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_arab_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_soldier_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + } + break; + } + } + if ((DAT_GameState::instance.gameTicksLoadBalancer == 0x97) + && (DAT_GameState::instance.mapAndTime.week == 3)) { + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + iVar18 = DAT_GameState::instance.mapAndTime.year; + if (iVar22 >= 12) { + iVar22 = iVar22 - 12; + iVar18 = iVar18 + 1; + } + for (iVar21 = 0; iVar21 < this->eventsCount; iVar21++) { + if (iVar18 == this->scenarioEvents[iVar21].header.year + && iVar22 == this->scenarioEvents[iVar21].header.month) { + switch (this->scenarioEvents[iVar21].header.tl_type) { + case 1: + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + break; + } + } + } + } + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp new file mode 100644 index 0000000000..b6aaef5369 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp @@ -0,0 +1,232 @@ +#include "../../Map.func.hpp" +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" + +namespace OpenSHC { +namespace Map { + + using Map::Units::UnitType; + using Map::Units::UnitTypeInt; + + /* + WARNING (jumptable): Heritage AFTER dead removal. Revisit: 0x01667ebc + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C13F0 + void MapPropertiesState::spawnInvasionEventAttackWave() + { + DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + int tribe = 0; + int edge = 0; + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, 0); + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] + = (char)this->invasionEventContent.crusaderArabian + 2; + // 25 sliders over 24 counts: the last one reads invasionPoint, as in the original + for (int slider = 0; slider < 25; slider++) { + int count = this->invasionEventContent.unitCountsPerUnitType[slider]; + if (!count) { + continue; + } + int troopType = 0; + UnitTypeInt unitType = 0; + int divisor = 0; + switch (slider) { + case 0: + troopType = 3; + unitType = Map::Units::UT_E_ARCHER; + divisor = 10; + break; + case 1: + troopType = 7; + unitType = Map::Units::UT_E_XBOW; + divisor = 10; + break; + case 2: + troopType = 5; + unitType = Map::Units::UT_E_SPEAR; + divisor = 10; + break; + case 3: + troopType = 6; + unitType = Map::Units::UT_E_PIKE; + divisor = 10; + break; + case 4: + troopType = 9; + unitType = Map::Units::UT_E_MACE; + divisor = 10; + break; + case 5: + troopType = 8; + unitType = Map::Units::UT_E_SWORD; + divisor = 10; + break; + case 6: + troopType = 10; + unitType = Map::Units::UT_E_KNIGHT; + divisor = 10; + break; + case 7: + troopType = 4; + unitType = Map::Units::UT_E_LADDER; + divisor = 10; + break; + case 8: + troopType = 0xb; + unitType = Map::Units::UT_E_ENGINEER; + divisor = 10; + break; + case 9: + troopType = 0x16; + unitType = Map::Units::UT_S_CATAPULT; + divisor = 10; + break; + case 10: + troopType = 0x17; + unitType = Map::Units::UT_S_TREBUCHET; + divisor = 10; + break; + case 0xb: + troopType = 0x13; + unitType = Map::Units::UT_S_BATTERINGRAM; + divisor = 10; + break; + case 0xc: + troopType = 0x14; + unitType = Map::Units::UT_S_TOWER; + divisor = 10; + break; + case 0xd: + troopType = 0x15; + unitType = Map::Units::UT_S_SHIELD; + divisor = 10; + break; + case 0xe: + troopType = 0xc; + unitType = Map::Units::UT_E_MONK; + divisor = 10; + break; + case 0xf: + troopType = 2; + unitType = Map::Units::UT_TUNNELER; + divisor = 10; + break; + case 0x10: + troopType = 0x19; + unitType = Map::Units::UT_A_ARCHER; + divisor = 10; + break; + case 0x11: + troopType = 0x1a; + unitType = Map::Units::UT_A_SLAVE; + divisor = 10; + break; + case 0x12: + troopType = 0x1b; + unitType = Map::Units::UT_A_SLINGER; + divisor = 10; + break; + case 0x13: + troopType = 0x1c; + unitType = Map::Units::UT_A_ASSASSIN; + divisor = 10; + break; + case 0x14: + troopType = 0x1d; + unitType = Map::Units::UT_A_HARCHER; + divisor = 10; + break; + case 0x15: + troopType = 0x1e; + unitType = Map::Units::UT_A_SWORDSMAN; + divisor = 10; + break; + case 0x16: + troopType = 0x1f; + unitType = Map::Units::UT_A_FIRETHROWER; + divisor = 10; + break; + case 0x17: + troopType = 0x18; + unitType = Map::Units::UT_S_FBALLISTA; + divisor = 10; + break; + } + // siege engines are only counted + switch (troopType) { + case 0x16: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][0] += count; + break; + case 0x17: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][1] += count; + break; + case 0x13: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][2] += count; + break; + case 0x14: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][3] += count; + break; + case 0x15: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][4] += count; + break; + case 0x18: + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][8] += count; + break; + default: + // split the troops into groups of about a tenth, one per map edge signpost in turn + int perTribe = count / (count / divisor + 1); + while (count > 0) { + if (perTribe > count) { + perTribe = count; + } + int const signpost + = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)(tribe, + troopType, DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][edge].x, + DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][edge].y, + this->invasionEventContent.crusaderArabian + 2, (UnitType)unitType, (UnitType)0, perTribe, 0); + tribe = tribe + 1; + edge = edge + 1; + count = count - perTribe; + if (edge >= DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter) { + edge = 0; + } + } + break; + } + } + switch (this->invasionEventContent.crusaderArabian) { + case 0: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + "", "sultan_nervous.bik", "infidel_attack.wav"); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + "", "good_soldier_nervous.bik", "arabian_attack.wav"); + break; + } + this->eventsCount = 0; + } +} +} diff --git a/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp new file mode 100644 index 0000000000..f2fc6c7f94 --- /dev/null +++ b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp @@ -0,0 +1,122 @@ +#include "../Synchrony.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/CampaignTrailMission.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/TrailType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/CHAR_ARRAY_00eb0ab0.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SkirmishDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { + +using Commands::GameCommandType; +using Game::CampaignTrailMission; +using Game::GameMode; +using Game::TrailType; +using WindowsHelper::Enums::BOOLEnum; + +// FUNCTION: STRONGHOLDCRUSADER 0x004C6B20 +void Synchrony::LoadSkirmishCampaignData(int missionID) +{ + char cVar1; + char* pcVar3; + int* piVar4; + int iVar5; + int iVar6; + int iVar7; + char (*pacVar8)[250]; + CampaignTrailMission* pCVar9; + pCVar9 = DAT_SkirmishDefinedData::instance.SkirmishTrailMissions + missionID; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + pCVar9 = DAT_SkirmishDefinedData::instance.ExtremeTrailMissions + missionID; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + pCVar9 = DAT_SkirmishDefinedData::instance.WarchestTrailMissions + missionID; + } + pcVar3 = (char*)(pCVar9->mapNameAddress); + iVar7 = (int)CHAR_ARRAY_00eb0ab0::instance - (int)pcVar3; + do { + cVar1 = *pcVar3; + pcVar3[iVar7] = cVar1; + pcVar3 = pcVar3 + 1; + } while (cVar1 != '\0'); + MACRO_CALL(OS_Func::_memset)(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, 0x8ca); + piVar4 = DAT_GameSynchronyState::instance.currentAIArray; + do { + piVar4[-0x1b] = -1; + *piVar4 = 0; + piVar4[9] = -1; + piVar4 = piVar4 + 1; + } while ((int)piVar4 < 0x191dea0); + pcVar3 = MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); + pacVar8 = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1; + do { + cVar1 = *pcVar3; + (*pacVar8)[0] = cVar1; + pcVar3 = pcVar3 + 1; + pacVar8 = (char (*)[250])(*pacVar8 + 1); + } while (cVar1 != '\0'); + DAT_GameSynchronyState::instance.isHost = TRUE; + DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); + for (int i = 1; i < pCVar9->numberOfPlayers; i++) { + DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&pCVar9->player1AI)[i]; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); + } + MACRO_CALL(Synchrony_Func::SetAIPlayerNickNames)(); + iVar7 = pCVar9->numberOfPlayers; + iVar5 = 0; + piVar4 = &pCVar9->team1; + do { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = (byte)*piVar4; + if (iVar5 >= iVar7) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = 0xff; + } + iVar5 = iVar5 + 1; + piVar4 = piVar4 + 1; + } while (iVar5 < 8); + iVar7 = 0; + iVar5 = 1; + do { + byte bVar2 = DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5]; + iVar6 = (int)(char)bVar2; + DAT_GameState::instance.mapAndTime.playerGroupArray[iVar5] = iVar6; + if (('\0' < (char)bVar2) && (DAT_GameState::instance.mapAndTime.playerTeams[iVar5] = iVar6, iVar6 > iVar7)) { + iVar7 = iVar6; + } + iVar5 = iVar5 + 1; + } while (iVar5 < 9); + iVar5 = 1; + do { + if (DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5] == 0) { + iVar7 = iVar7 + 1; + DAT_GameState::instance.mapAndTime.playerTeams[iVar5] = iVar7; + } + iVar5 = iVar5 + 1; + } while (iVar5 < 9); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = pCVar9->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = pCVar9->startLevels; + memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); + piVar4 = &pCVar9->position1; + iVar7 = 0; + do { + if (*piVar4 != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[*piVar4 - 1] = (char)iVar7; + } + iVar7 = iVar7 + 1; + piVar4 = piVar4 + 1; + } while (iVar7 < 8); +} + +} diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp new file mode 100644 index 0000000000..b0569fc322 --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -0,0 +1,120 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuItems/SaveLoadMap.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/INT_00b95b64.hpp" +#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" + +namespace OpenSHC { +namespace UI { + + using Commands::GameCommandType; + using Game::GameMode; + using UI::Enums::MenuModalType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004968A0 + void MenuTextInputState::loadOrSaveGame(int action) + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_GameSynchronyState::instance.saveRelated == 1 && action == 10) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + return; + } + DAT_MouseState::instance.waitCursorToggle = 1; + MACRO_CALL(UI::Helpers_Func::SetCursorDependingOnProgramState)(); + MACRO_CALL(OS_Func::_memset)(DAT_MinimapViewState::instance.loadedMiniMap, 0, 80000); + INT_00b95b64::instance = 1; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER) { + std::string savesPath(DAT_ResourceManager::instance.paths_getSavesPath(true)); + savesPath.append("*.msv", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)(savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + for (int i = 0; i < DAT_ResourceManager::instance.mapFileCounter; i++) { + this->DAT_ArrayOfMapIndices[i] = i; + // indexed by map number, which counts from 1 + this->DAT_ArrayOfMapIndices2[i - 1] = 1; + if (action != 10) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = i; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + (Commands::GameCommandType)(Commands::GCT_LOAD_MAP_HEADER + | Commands::GCT_MULTIPLAYER_INITIATE_ANNOUNCE_HOST)); + } + } + } else { + std::string savesPath(DAT_ResourceManager::instance.paths_getSavesPath(true)); + savesPath.append("*.sav", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)(savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + for (int i = 0; i < DAT_ResourceManager::instance.mapFileCounter; i++) { + this->DAT_ArrayOfMapIndices[i] = i; + } + } + DAT_MouseState::instance.waitCursorToggle = 0; + this->fileListSortOrder = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + if (!this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = -1; + } else { + this->menuLoadGameRelativeSelectionIndex = 0; + } + this->lastListClickTime = 0; + this->lastClickedListIndex = 0xffffffff; + this->DAT_ArrayOfMapU3EndInt2 = 0; + this->previewedListIndex = 0xffffffff; + this->fileListVisibleRowCount = 0x10; + if (action == 9) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_LOAD_MAP); + this->fileListContext = 1; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection1; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset1; + this->fileListSortOrder = this->savedListSortOrder1; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + } + } + } else { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_SAVE_MAP); + DAT_UserTextHandlerState::instance.allowUserTextInput = 0; + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(2); + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + this->fileListContext = 3; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection2; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset2; + this->fileListSortOrder = this->savedListSortOrder2; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionOffset = 0; + this->menuLoadGameRelativeSelectionIndex = 0; + } + } + } + MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( + -1 - this->fileListSortOrder); + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..b3e06785b9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16863,7 +16863,7 @@ SHC_3BB0A8C1_0x0044B673 | 0.0% | Pending SHC_3BB0A8C1_0x0044B674 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B680 | 0.0% | Pending +SHC_3BB0A8C1_0x0044B680 | 98.1% | id load folded into cmp SHC_3BB0A8C1_0x0044B760 | 100.0% | Reimplemented @@ -23369,7 +23369,7 @@ SHC_3BB0A8C1_0x0048FCB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048FFD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00490060 | 0.0% | Pending +SHC_3BB0A8C1_0x00490060 | 99.3% | Base/index operand order SHC_3BB0A8C1_0x00490080 | 0.0% | Pending @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004968A0 | 93.1% | 0x10 not kept in ebp (alloc) SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented @@ -29881,7 +29881,7 @@ SHC_3BB0A8C1_0x004BC100 | 0.0% | Pending SHC_3BB0A8C1_0x004BC104 | 0.0% | Pending -SHC_3BB0A8C1_0x004BC110 | 0.0% | Pending +SHC_3BB0A8C1_0x004BC110 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BC1C0 | 100.0% | Pending @@ -30243,7 +30243,7 @@ SHC_3BB0A8C1_0x004BD7F0 | 0.0% | Pending SHC_3BB0A8C1_0x004BD7F4 | 0.0% | Pending -SHC_3BB0A8C1_0x004BD800 | 0.0% | Pending +SHC_3BB0A8C1_0x004BD800 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BD970 | 0.0% | Pending @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 0.0% | Pending +SHC_3BB0A8C1_0x004BDE40 | 88.7% | goods-score switches: the *5 arm shares the default's store in the original, ours shares the *50 one (temp registers alternate); no case order changes it SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending @@ -33195,7 +33195,7 @@ SHC_3BB0A8C1_0x004C1370 | 0.0% | Pending SHC_3BB0A8C1_0x004C1390 | 0.0% | Pending -SHC_3BB0A8C1_0x004C13F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C13F0 | 91.0% | siege switch is a jump table, the original compares (if-chain gets jump-threaded) SHC_3BB0A8C1_0x004C1708 | 0.0% | Pending @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C31A0 | 67.5% | this vs numMet reg alloc: the original keeps this in ebx and zero in edi, ours swaps them; our frame is 0x98 against the original's 0xa0 and the body is 0x91 bytes shorter. The tail call to updateMilitaryCampaignMissionState (jmp 0x004C2280) is already emitted, so the address-taken-locals tail-call fix does not apply SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending @@ -34141,15 +34141,15 @@ SHC_3BB0A8C1_0x004C6298 | 0.0% | Pending SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C62C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C62C0 | 79.0% | equal-weight slot tie order -SHC_3BB0A8C1_0x004C6820 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C6880 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C68D0 | 83.2% | the original picks the mission in one register per arm (default first); written that way, mission and the constant 1 swap esi/edi; idiv divisor in esi -SHC_3BB0A8C1_0x004C6B20 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6B90 | 0.0% | Pending @@ -35565,9 +35565,9 @@ SHC_3BB0A8C1_0x004D5010 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D5180 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D52A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004D52A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D5370 | 0.0% | Pending +SHC_3BB0A8C1_0x004D5370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D53A0 | 0.0% | Pending @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only the instance[i - 1] address label differs) -SHC_3BB0A8C1_0x004D9400 | 0.0% | Pending +SHC_3BB0A8C1_0x004D9400 | 100.0% | Reimplemented (counted: only the labels of two array[-1] addresses differ) SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending