diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 17882af542..67a4402c3e 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -20,6 +20,7 @@ src/OpenSHC/Input/MouseState/updateRightDragCameraControl.cpp src/OpenSHC/Text/FontSizeClass/setupFontSizeClassObject.cpp src/OpenSHC/Text/TextManager/setupFontSizeClassObjects.cpp src/OpenSHC/Game/GameStateStructures/updateFoodTypesInStockForAllPlayers.cpp +src/OpenSHC/Game/GameStateStructures/processFoodConsumption.cpp src/OpenSHC/Game/GameStateStructures/clearEnemyRelatedStructures.cpp src/OpenSHC/Game/GameStateStructures/fillWith0xFF.cpp src/OpenSHC/Game/GameStateStructures/computeSignPostEntryData.cpp @@ -280,6 +281,10 @@ src/OpenSHC/Map/Units/UpdateMinerIronFetcher.cpp src/OpenSHC/Map/Units/UpdateWorker_ConsiderTakingABreakUnk.cpp src/OpenSHC/Map/Units/UnitsState/isWorkplaceBuildingOnAdjacentTile.cpp src/OpenSHC/Map/Units/ConsiderHavingABreakNowUnk.cpp +src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp +src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp +src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp +src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp src/OpenSHC/Map/Units/UnitsState/acquireShootTarget.cpp src/OpenSHC/Map/Units/UnitsState/calculateUnitMovementSpeed.cpp src/OpenSHC/Map/Units/UnitsState/chooseHusbandAndWife.cpp diff --git a/src/OpenSHC/Game/GameStateStructures/processFoodConsumption.cpp b/src/OpenSHC/Game/GameStateStructures/processFoodConsumption.cpp new file mode 100644 index 0000000000..94fbd6e3b6 --- /dev/null +++ b/src/OpenSHC/Game/GameStateStructures/processFoodConsumption.cpp @@ -0,0 +1,161 @@ +#include "../GameStateStructures.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Game/Resources/FoodTypeEnum.hpp" +#include "OpenSHC/Game/Resources/FoodTypeEnumInt.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_CounterFoodWarningInterval.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_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" + +namespace OpenSHC { +namespace Game { + +#define PLAYER_FIELD(type, field) \ + (*(type*)((char*)foodClockSpeed + offsetof(PlayerData, field) - offsetof(PlayerData, foodClockSpeed))) + + // FUNCTION: STRONGHOLDCRUSADER 0x00458AD0 + void GameStateStructures::processFoodConsumption() + { + if (DAT_GameCore::instance.gameMode_2 == GM_EDITOR) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == GM_SIEGE_THAT) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == GM_BUILDERUnk + && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER(GameStateStructures_Func::updateFoodTypesInStockForAllPlayers, this)(); + int playerID = 1; + int* foodClockSpeed = &this->playerDataArray[1].foodClockSpeed; + for (; playerID < countof(this->playerDataArray); + ++playerID, foodClockSpeed += sizeof(PlayerData) / sizeof(int)) { + if (PLAYER_FIELD(int, buildingEntryInfos[Player::Enums::BEIE_KEEP].id) <= 0 + || PLAYER_FIELD(int, buildingEntryInfos[Player::Enums::BEIE_CAMPGROUND].id) <= 0) { + continue; + } + PLAYER_FIELD(int, foodStorageLevel) = -1; + if (PLAYER_FIELD(int, foodTypesInStock) <= 0) { + PLAYER_FIELD(int, foodTypesCurrentlyEaten) = 0; + continue; + } + int const clockSpeed = PLAYER_FIELD(int, currentPopulation) * 3; + PLAYER_FIELD(int, foodClockSpeed) = clockSpeed; + if (DAT_GameSynchronyState::instance.currentGameMode != GM_SOLITARY + && MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::isAIPlayer, DAT_GameSynchronyState::ptr)( + playerID)) { + PLAYER_FIELD(int, foodClockSpeed) = (clockSpeed * 60) / 100; + } + switch (PLAYER_FIELD(int, rationsSetting)) { + case 0: + PLAYER_FIELD(int, foodClockSpeed) = 0; + PLAYER_FIELD(int, foodTypesCurrentlyEaten) = 0; + break; + case 1: + PLAYER_FIELD(int, foodClockSpeed) = PLAYER_FIELD(int, foodClockSpeed) / 2; + break; + case 3: + PLAYER_FIELD(int, foodClockSpeed) = (PLAYER_FIELD(int, foodClockSpeed) * 3) / 2; + break; + case 4: + PLAYER_FIELD(int, foodClockSpeed) = PLAYER_FIELD(int, foodClockSpeed) * 2; + } + if (PLAYER_FIELD(int, foodClockSpeed) != 0) { + PLAYER_FIELD(int, foodStorageLevel) + = ((15000 / PLAYER_FIELD(int, foodClockSpeed)) * PLAYER_FIELD(int, totalFood)) / 800; + } + if (DAT_GameState::instance.mapAndTime.monthChanged != 0) { + short const leftover = PLAYER_FIELD(int, foodStorageLevel); + PLAYER_FIELD(short, foodStorageLevelLastLastMonth) = PLAYER_FIELD(short, foodStorageLevelLastMonth); + PLAYER_FIELD(short, foodStorageLevelLastMonth) = leftover; + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_GameState::instance.mapAndTime.singlePlayerHasKeepAndGranary) { + if (PLAYER_FIELD(int, totalFood) == 0) { + if (DAT_CounterFoodWarningInterval::instance == 0 + && !MACRO_CALL_MEMBER( + Audio::MSS::SoundSystem_Func::shouldSoundXNotBePlaying, DAT_SoundSystemState::ptr)()) { + // "No food distributed this month" + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_food_warning4_wav_005a509c); + } + ++DAT_CounterFoodWarningInterval::instance; + if (DAT_CounterFoodWarningInterval::instance > 2) { + DAT_CounterFoodWarningInterval::instance = 0; + } + } else if (leftover < 2 && leftover != PLAYER_FIELD(short, foodStorageLevelLastLastMonth) + && PLAYER_FIELD(int, rationsSetting) != 0) { + if (leftover == 1) { + if (!MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::shouldSoundXNotBePlaying, + DAT_SoundSystemState::ptr)()) { + // "Granary stocks are very low sire" + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_food_warning2_wav_005a5088); + } + } else if (!MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::shouldSoundXNotBePlaying, + DAT_SoundSystemState::ptr)()) { + // "We are almost out of food sire" + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_food_warning3_wav_005a5074); + } + } + } + } + PLAYER_FIELD(int, foodClock) += PLAYER_FIELD(int, foodClockSpeed); + if (PLAYER_FIELD(int, foodClock) > 15000) { + PLAYER_FIELD(int, foodClock) = 0; + PLAYER_FIELD(int, foodTypesCurrentlyEaten) = PLAYER_FIELD(int, foodTypesInStock); + for (;;) { + ++PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext); + if (PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) > Resources::FTE_APPLE) { + PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) = Resources::FTE_BREAD; + } + if (PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) == Resources::FTE_BREAD + && PLAYER_FIELD(int, breadCount) > 0) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(playerID, Resources::RT_BREAD, 1, 0); + break; + } + if (PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) == Resources::FTE_CHEESE + && PLAYER_FIELD(int, cheeseCount) > 0) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(playerID, Resources::RT_CHEESE, 1, 0); + break; + } + if (PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) == Resources::FTE_MEAT + && PLAYER_FIELD(int, meatCount) > 0) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(playerID, Resources::RT_MEAT, 1, 0); + break; + } + if (PLAYER_FIELD(Resources::FoodTypeEnumInt, foodTypeToBeEatenNext) == Resources::FTE_APPLE + && PLAYER_FIELD(int, appleCount) > 0) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(playerID, Resources::RT_APPLE, 1, 0); + break; + } + } + } + } + } + +#undef PLAYER_FIELD + +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/GameStateStructures/updateCrowding.cpp b/src/OpenSHC/Game/GameStateStructures/updateCrowding.cpp new file mode 100644 index 0000000000..99ab672aa0 --- /dev/null +++ b/src/OpenSHC/Game/GameStateStructures/updateCrowding.cpp @@ -0,0 +1,35 @@ +#include "../GameStateStructures.func.hpp" + +namespace OpenSHC { +namespace Game { + +#define PLAYER_FIELD(type, field) \ + (*(type*)((char*)currentPopulation + offsetof(PlayerData, field) - offsetof(PlayerData, currentPopulation))) + + // FUNCTION: STRONGHOLDCRUSADER 0x00458E60 + void GameStateStructures::updateCrowding() + { + int* currentPopulation = &this->playerDataArray[1].currentPopulation; + for (int playerID = 1; playerID != countof(this->playerDataArray); ++playerID) { + int const populationCap = PLAYER_FIELD(int, populationCap); + int const population = PLAYER_FIELD(int, currentPopulation); + if (population <= populationCap) { + PLAYER_FIELD(int, crowding) = 0; + currentPopulation += sizeof(PlayerData) / sizeof(int); + continue; + } + if (population <= 0) { + PLAYER_FIELD(int, crowding) = 0; + } else if (populationCap <= 0) { + PLAYER_FIELD(int, crowding) = 150; + } else { + PLAYER_FIELD(int, crowding) = (population * 100) / populationCap; + } + currentPopulation += sizeof(PlayerData) / sizeof(int); + } + } + +#undef PLAYER_FIELD + +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp new file mode 100644 index 0000000000..8ddc47689d --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -0,0 +1,46 @@ +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 + void WildlifeState::updateSection1034Info() + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + for (int pass = 0; pass < 20; pass = *(int volatile*)&pass + 1) { + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); x++) { + this->grid[x][y].unknownNonZero01 = 0; + this->grid[x][y].field_0x6c = 0; + if (this->grid[x][y].castlebuildings != 0 + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::hasAdjacentCellWithField24Or25, this)(x, y)) { + this->grid[x][y].field_0x64++; + } + } + } + } + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); x++) { + if (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillZoneProximityFromCell, this)(x, y, 6); + } + } + } + for (int y = 0; y < countof(this->grid[0]); y++) { + for (int x = 0; x < countof(this->grid); x++) { + if (this->grid[x][y].unknownNonZero01 == 0 + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)(x, y)) { + this->grid[x][y].field_0x6c++; + } + } + } + } + +} // namespace Map +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..bbb62055dd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17733,7 +17733,7 @@ SHC_3BB0A8C1_0x00458A70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00458A80 | 0.0% | Pending -SHC_3BB0A8C1_0x00458AD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00458AD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00458D38 | 0.0% | Pending @@ -17749,7 +17749,7 @@ SHC_3BB0A8C1_0x00458D50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00458E20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00458E60 | 0.0% | Pending +SHC_3BB0A8C1_0x00458E60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00458EC0 | 100.0% | Reimplemented @@ -49297,7 +49297,7 @@ SHC_3BB0A8C1_0x0052DF50 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052E020 | 0.0% | Pending +SHC_3BB0A8C1_0x0052E020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052E120 | 0.0% | Pending