diff --git a/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp b/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp new file mode 100644 index 0000000000..6cff85f557 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/addUnitToTribe.cpp @@ -0,0 +1,30 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522590 + void TribesState::addUnitToTribe(uint unitID, int tribeID) + { + this->tribes[tribeID].size++; + int const bitFlagsIndex = (int)unitID / 16; + int const bitMaskIndex = (int)unitID % 16; + this->tribes[tribeID].unitSelectionBitMasked[bitFlagsIndex] + |= DAT_UnitSelectionDefinedData::instance.BitMaskHelper[bitMaskIndex]; + if (this->tribes[tribeID].selectionTargetUnitID == 0) { + this->tribes[tribeID].selectionTargetUnitID = unitID; + } + DAT_UnitsState::instance.units[unitID].selectionTargetUnitID = this->tribes[tribeID].selectionTargetUnitID; + DAT_UnitsState::instance.units[unitID].tribeID = tribeID; + DAT_UnitsState::instance.units[unitID].tribeUID = this->tribes[tribeID].uid; + DAT_UnitsState::instance.units[unitID].idInTribe = this->tribes[tribeID].size; + MACRO_CALL_MEMBER(TribesState_Func::setWhetherTribeContainsAnyUnits, this)(tribeID); + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/commandUnitsToLocation.cpp b/src/OpenSHC/Map/Units/TribesState/commandUnitsToLocation.cpp new file mode 100644 index 0000000000..bd987e0ac8 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/commandUnitsToLocation.cpp @@ -0,0 +1,103 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTribeID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00526F00 + BOOLEnum TribesState::commandUnitsToLocation( + int tribeID, uint destinationX, uint destinationY, undefined4 matchUnitSpeeds) + { + int index = 0; + BOOLEnum noneCommanded; + if (this->tribes[tribeID].size <= 0) { + noneCommanded = TRUE; + } else { + noneCommanded = TRUE; + do { + int const unitID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getUnitIDForIndexInTribe, this)( + tribeID, index); + ++index; + if (DAT_UnitsState::instance.units[unitID].logicalState != Map::Units::ULS_NORMAL + || DAT_UnitsState::instance.units[unitID].dying) { + continue; + } + short const goToRallyPoint = DAT_UnitsState::instance.units[unitID].goToRallyPoint; + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 0; + if (goToRallyPoint != 0 || DAT_UnitsState::instance.units[unitID].isSelectable_OR_matchTime == 0) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(destinationX, destinationY, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y); + if (DAT_DirectionAlgorithmState::instance.distanceHigh <= 4) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + if (DAT_UnitsState::instance.units[unitID].movementType_OR_targetUnitID != 0 + && DAT_UnitsState::instance + .units[DAT_UnitsState::instance.units[unitID] + .targetedUnitID__OR__engineerMannedSiegeEngineRef] + .logicalState + == Map::Units::ULS_NORMAL) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + short const shootTarget = DAT_UnitsState::instance.units[unitID].shootTargetedUnit; + if (shootTarget != 0 && this->tribes[DAT_CurrentTribeID::instance].countdown2 > 0 + && DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_A_HARCHER + && DAT_UnitsState::instance.units[unitID].targetUID + == DAT_UnitsState::instance.units[shootTarget].uid) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + if (DAT_UnitsState::instance.units[unitID].state.generic == Map::Units::States::US_MELEE_ATTACK) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + if ((char)matchUnitSpeeds == 0) { + UnitTypeShort const unitType = DAT_UnitsState::instance.units[unitID].unitType; + if (unitType == Map::Units::UT_S_FBALLISTA || unitType == Map::Units::UT_S_CATAPULT + || unitType == Map::Units::UT_S_SHIELD || unitType == Map::Units::UT_S_TOWER + || unitType == Map::Units::UT_S_BATTERINGRAM) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + } + if (DAT_UnitsState::instance.units[unitID].engineerRelatedUnk != 0 + && (DAT_UnitsState::instance.units[unitID].resourceToDeposit == 0 + || DAT_UnitsState::instance.units[unitID].field_0x3c4 != 0)) { + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 1; + continue; + } + DAT_UnitsState::instance.units[unitID].rallyRelatedFlag = 0; + noneCommanded = FALSE; + } while (index < this->tribes[tribeID].size); + } + if (noneCommanded) { + return FALSE; + } + if ((char)matchUnitSpeeds != 0) { + DAT_TribesState::instance.tribes[tribeID].freeUnitSpeeds = 0; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)( + tribeID, destinationX, destinationY, 0, 0, Map::Units::Instructions::UMSE_0); + return TRUE; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/createAnimal.cpp b/src/OpenSHC/Map/Units/TribesState/createAnimal.cpp new file mode 100644 index 0000000000..a52127ba56 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/createAnimal.cpp @@ -0,0 +1,141 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using AI::Tribes::AITribeType; + using Commands::MappersEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00525BA0 + dword TribesState::createAnimal(MappersEnum animalType, uint x, uint y, int tile) + { + UnitType unitType = Map::Units::UT_NONE; + int animalCount = 0; + int tribeID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, this)(0, 0); + if (tribeID <= 0) { + return 0; + } + if (x > Map::MC_MAP_XY_LIMIT_INCLUSIVE) { + return 0; + } + if (y > Map::MC_MAP_XY_LIMIT_INCLUSIVE) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * Map::MC_MAP_XY_LIMIT + x] == 0) { + return 0; + } + int const blockingTerrain = Map::LogicHelpers::L_SEA | Map::LogicHelpers::L_BORDER + | Map::LogicHelpers::L_BORDER_EDGE | Map::LogicHelpers::L_ROCKY | Map::LogicHelpers::L_BUILDING + | Map::LogicHelpers::L_TREE | Map::LogicHelpers::L_RIVER | Map::LogicHelpers::L_CRENEL_VARIATIONUnk + | Map::LogicHelpers::L_FARM_FIELD_HOP | Map::LogicHelpers::L_FARM_FIELD_DAIRY + | Map::LogicHelpers::L_MOAT; + int const logicTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + if (animalType == Commands::M_MAPPER_DEER) { + if (DAT_TileMapState::instance.LogicLayer[logicTile] & blockingTerrain) { + return 0; + } + this->tribes[tribeID].tribeType = AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_SPEARMEN; + unitType = Map::Units::UT_ANTELOPESHDEER; + animalCount = (SEC_RNG::instance.currentNumber2 & 3) + 9; + } else if (animalType == Commands::M_MAPPER_LION) { + if (DAT_TileMapState::instance.LogicLayer[logicTile] & blockingTerrain) { + return 0; + } + this->tribes[tribeID].tribeType = AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_PIKEMEN; + unitType = Map::Units::UT_LIONSHWOLF; + animalCount = (SEC_RNG::instance.currentNumber2 & 1) + 3; + } else if (animalType == Commands::M_MAPPER_RABBIT) { + if (DAT_TileMapState::instance.LogicLayer[logicTile] & blockingTerrain) { + return 0; + } + this->tribes[tribeID].tribeType = AI::Tribes::AITT_SWORDSMEN | AI::Tribes::AITT_CROSSBOWMEN; + unitType = Map::Units::UT_RABBIT; + animalCount = (SEC_RNG::instance.currentNumber2 & 7) + 14; + } else if (animalType == Commands::M_MAPPER_CAMEL) { + if (DAT_TileMapState::instance.LogicLayer[logicTile] & blockingTerrain) { + return 0; + } + this->tribes[tribeID].tribeType = 16; + unitType = Map::Units::UT_CAMELSHBEAR; + animalCount = (SEC_RNG::instance.currentNumber2 & 3) + 2; + } else { + if (animalType == Commands::M_MAPPER_CROW_SEAGULL) { + MACRO_CALL_MEMBER(Map::LandscapeState_Func::markNearbyTreesAsCrowTargets, DAT_LandscapeState::ptr)( + x, y); + return 0; + } + if (animalType == Commands::M_MAPPER_SEAGULL) { + if (!(DAT_TileMapState::instance.LogicLayer[logicTile] & Map::LogicHelpers::L_SEA)) { + return 0; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::createSeagull, DAT_EntityState::ptr)( + x * 8, y * 8); + return 0; + } + } + for (int spawnIndex = 0; spawnIndex < animalCount; ++spawnIndex) { + uint const unitID = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + 0, 0, x * 8, y * 8, tile, unitType); + if (unitID != 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, this)(unitID, tribeID); + DAT_UnitsState::instance.units[unitID].substate + = DAT_UnitsState::instance.units[unitID].fixedRng & 3; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + byte const rngValue = DAT_UnitsState::instance.units[unitID].fixedRng & 7; + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = rngValue; + if (rngValue == 3) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 1; + } else if (rngValue == 4) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 1; + } else if (rngValue == 5) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 1; + } else if (rngValue == 6 || rngValue == 7) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 2; + } + if (spawnIndex == 0) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 0; + } else if (spawnIndex == 1 || spawnIndex == 2) { + DAT_UnitsState::instance.units[unitID].antelopeBasedRngValue = 1; + } + } + DAT_UnitsState::instance.units[unitID].disappearFadeAlphaCountdown = 32; + } + } + short const herdSize = this->tribes[tribeID].size; + this->tribes[tribeID].herdMinSize = herdSize / 2; + if (animalType == Commands::M_MAPPER_LION) { + this->tribes[tribeID].herdMaxSize = herdSize; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::storeLionXAndYInMapInfo, this)(x, y); + } else { + this->tribes[tribeID].herdMaxSize = herdSize * 2; + if (animalType == Commands::M_MAPPER_DEER) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::storeDeerXAndYinMapInfo, this)(x, y); + } else if (animalType == Commands::M_MAPPER_RABBIT) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::setRabbitSpawnXY, this)(x, y); + } else if (animalType == Commands::M_MAPPER_CAMEL) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::setCamelSpawnXY, this)(x, y); + } + } + return tribeID; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/createTribe.cpp b/src/OpenSHC/Map/Units/TribesState/createTribe.cpp new file mode 100644 index 0000000000..f37ce12cc3 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/createTribe.cpp @@ -0,0 +1,54 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTribeID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using AI::Tribes::AITribeType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00522890 + int TribesState::createTribe(int playerID, int setAsCurrentTribeID) + { + int tribeID = 0; + for (DAT_CurrentTribeID::instance = 1; DAT_CurrentTribeID::instance < countof(this->tribes); + ++DAT_CurrentTribeID::instance) { + if (this->tribes[DAT_CurrentTribeID::instance].tribeState == Map::Enums::TS_UNUSED) { + tribeID = DAT_CurrentTribeID::instance; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(Tribe), 0, &this->tribes[tribeID]); + break; + } + } + if (tribeID <= 0) { + return 0; + } + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID && setAsCurrentTribeID) { + this->DAT_CurrentTribeID = tribeID; + } + this->tribes[tribeID].owner = playerID; + this->tribes[tribeID].tribeState = Map::Enums::TS_ACTIVE; + this->tribes[tribeID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + ++DAT_GameCore::instance.uniqueGameObjectTracker; + this->tribes[tribeID].tribeType = 0; + this->tribes[tribeID].field_0x1c = 0; + this->tribes[tribeID].field_0x1e = 0; + this->tribes[tribeID].tribeBehaviorType = 0; + this->tribes[tribeID].field_0x30 = 0; + this->tribes[tribeID].selectionTargetUnitID = 0; + this->tribes[tribeID].size = 0; + return tribeID; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/createTribeForPlayer.cpp b/src/OpenSHC/Map/Units/TribesState/createTribeForPlayer.cpp new file mode 100644 index 0000000000..a73c1124b7 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/createTribeForPlayer.cpp @@ -0,0 +1,47 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using AI::Tribes::AITribeType; + + // FUNCTION: STRONGHOLDCRUSADER 0x005227E0 + int TribesState::createTribeForPlayer(int playerID) + { + int tribeID; + for (tribeID = countof(this->tribes) - playerID; tribeID > 0; tribeID -= 8) { + if (this->tribes[tribeID].tribeState == Map::Enums::TS_UNUSED) { + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(Tribe), 0, &this->tribes[tribeID]); + break; + } + } + if (tribeID <= 0) { + return 0; + } + this->tribes[tribeID].owner = playerID; + this->tribes[tribeID].tribeState = Map::Enums::TS_ACTIVE; + this->tribes[tribeID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + ++DAT_GameCore::instance.uniqueGameObjectTracker; + this->tribes[tribeID].tribeType = 0; + this->tribes[tribeID].field_0x1c = 0; + this->tribes[tribeID].field_0x1e = 0; + this->tribes[tribeID].tribeBehaviorType = 0; + this->tribes[tribeID].field_0x30 = 0; + this->tribes[tribeID].selectionTargetUnitID = 0; + this->tribes[tribeID].size = 0; + return tribeID; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/getAvailableTribeID.cpp b/src/OpenSHC/Map/Units/TribesState/getAvailableTribeID.cpp new file mode 100644 index 0000000000..366813c0fb --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/getAvailableTribeID.cpp @@ -0,0 +1,50 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Enums/TribeState.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTribeID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522720 + int TribesState::getAvailableTribeID(int playerID) + { + int tribeID; + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + tribeID = 0; + for (DAT_CurrentTribeID::instance = countof(this->tribes) - 1; DAT_CurrentTribeID::instance > 0; + --DAT_CurrentTribeID::instance) { + if (this->tribes[DAT_CurrentTribeID::instance].tribeState == Map::Enums::TS_UNUSED + && this->tribes[DAT_CurrentTribeID::instance].time == 0) { + tribeID = DAT_CurrentTribeID::instance; + break; + } + } + if (tribeID <= 0) { + return 0; + } + this->tribes[tribeID].time = 1; + return tribeID; + } + for (tribeID = countof(this->tribes) - playerID, DAT_CurrentTribeID::instance = tribeID; tribeID > 0; + tribeID -= 8, DAT_CurrentTribeID::instance = tribeID) { + if (this->tribes[DAT_CurrentTribeID::instance].tribeState == Map::Enums::TS_UNUSED + && this->tribes[DAT_CurrentTribeID::instance].time == 0) { + break; + } + } + if (tribeID <= 0) { + return 0; + } + this->tribes[tribeID].time = DAT_GameCore::instance.mapTimeInTicks + 400; + return tribeID; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/getUnitIDForIndexInTribe.cpp b/src/OpenSHC/Map/Units/TribesState/getUnitIDForIndexInTribe.cpp new file mode 100644 index 0000000000..6199f1263d --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/getUnitIDForIndexInTribe.cpp @@ -0,0 +1,39 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Enums/TribeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522390 + int TribesState::getUnitIDForIndexInTribe(int tribeID, int unitSelectionIndex) + { + int count = 0; + if (this->tribes[tribeID].tribeState != Map::Enums::TS_ACTIVE) { + return 0; + } + if (unitSelectionIndex >= this->tribes[tribeID].size) { + return 0; + } + for (int wordIndex = 0; wordIndex < countof(this->tribes[tribeID].unitSelectionBitMasked); wordIndex++) { + short const bits = this->tribes[tribeID].unitSelectionBitMasked[wordIndex]; + if (bits == 0) { + continue; + } + for (int bitIndex = 0; bitIndex < 16; bitIndex++) { + if (((1 << bitIndex) & bits) == 0) { + continue; + } + if (count == unitSelectionIndex) { + return wordIndex * 16 + bitIndex; + } + count++; + } + } + return 0; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/moveTribeToIndexedNearbyTile.cpp b/src/OpenSHC/Map/Units/TribesState/moveTribeToIndexedNearbyTile.cpp new file mode 100644 index 0000000000..73a997d438 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/moveTribeToIndexedNearbyTile.cpp @@ -0,0 +1,47 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" + +#include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052A700 + void TribesState::moveTribeToIndexedNearbyTile(int tribeID) + { + int const targetUnitID = this->tribes[tribeID].selectionTargetUnitID; + int const x = DAT_UnitsState::instance.units[targetUnitID].x; + int const y = DAT_UnitsState::instance.units[targetUnitID].y; + int const someIndex = this->tribes[tribeID].someIndex; + int candidateCount = 40; + int index = someIndex % candidateCount; + if (index <= 0) { + index = 0; + } else if (index >= candidateCount) { + return; + } + for (; index < candidateCount; ++index) { + uint const candidateX = DAT_UnitSelectionDefinedData::instance.field_0xcc4[index].x + x; + uint const candidateY = DAT_UnitSelectionDefinedData::instance.field_0xcc4[index].y + y; + if (candidateX <= Map::MC_MAP_XY_LIMIT_INCLUSIVE && candidateY <= Map::MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance + .DAT_BinaryTileMap400x400[candidateY * Map::MC_MAP_XY_LIMIT + candidateX] + != 0) { + if (MACRO_CALL_MEMBER(Map::Units::TribesState_Func::isTribePathToDestinationClear, this)( + tribeID, x, y, candidateX, candidateY)) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)( + tribeID, candidateX, candidateY, 0, 0, Map::Units::Instructions::UMSE_0); + return; + } + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/moveUnitToBehaviorTarget.cpp b/src/OpenSHC/Map/Units/TribesState/moveUnitToBehaviorTarget.cpp new file mode 100644 index 0000000000..c69a541559 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/moveUnitToBehaviorTarget.cpp @@ -0,0 +1,134 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00521280 + BOOLEnum TribesState::moveUnitToBehaviorTarget(int unitID, int behaviorType) + { + uint y = 0; + uint x = 0; + uint tile = 0; + BOOLEnum found = FALSE; + int const tribeID = DAT_UnitsState::instance.units[unitID].tribeID; + if (DAT_UnitsState::instance.units[unitID].logicalState != Map::Units::ULS_NORMAL + || DAT_UnitsState::instance.units[unitID].dying + || DAT_UnitsState::instance.units[unitID].usingTeleport != 0 + || DAT_UnitsState::instance.units[unitID].field_0x413 != 0 + || DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_UnitsState::instance.units[unitID].owner] + != -1) { + return FALSE; + } + if (behaviorType == Map::Units::STBT_0x3f2) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::findEnemyWalls, DAT_TroopValueState::ptr)( + unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x3f5) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::findEnemyBuildingsClosestToUnit, + DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x3fb) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::calculateTile2PeoplValueClosestToUnit, + DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } else if (MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::findEnemyWalls, DAT_TroopValueState::ptr)(unitID)) { + if (this->tribes[tribeID].selectionTargetUnitID == unitID) { + DAT_TribesState::instance.tribes[tribeID].tribeBehaviorType = Map::Units::STBT_0x3f2; + } + DAT_UnitsState::instance.units[unitID].unknownDigMoatOrWallAttackFlag1015 = Map::Units::STBT_0x3f2; + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x3fd) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::findEnemyLord, DAT_TroopValueState::ptr)( + unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x3f6) { + if (MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::findEnemyTowersOrGates, DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x413) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getClosestWideValueBasedOnPlayer, + DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x414) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getClosestWideValueBasedOnPlayer, + DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } else if (behaviorType == Map::Units::STBT_0x3f7) { + if (MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::findNearestDiggableMoatPoint, + DAT_TroopValueState::ptr)(unitID)) { + x = DAT_TroopValueState::instance.x; + y = DAT_TroopValueState::instance.y; + tile = DAT_TroopValueState::instance.tile; + found = TRUE; + } + } + DAT_UnitsState::instance.units[unitID].targetedBuildingTile = 0; + if (!found) { + return FALSE; + } + short const tileY = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + DAT_UnitsState::instance.units[unitID].attackAtTileY = tileY; + DAT_UnitsState::instance.units[unitID].targetedBuildingTile = tile; + DAT_UnitsState::instance.units[unitID].state.generic = Map::Units::States::US_MOVE_TO_DESTINATION; + DAT_UnitsState::instance.units[unitID].attackAtTileX + = tile - DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile; + if (DAT_UnitsState::instance.units[unitID].selectionTargetUnitID == unitID) { + this->tribes[tribeID].targetX = DAT_UnitsState::instance.units[unitID].attackAtTileX; + this->tribes[tribeID].targetY = DAT_UnitsState::instance.units[unitID].attackAtTileY; + } + if (!MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::stopUnitIfNextToTarget, DAT_UnitsState::ptr)(unitID)) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setDestinationForUnit, DAT_UnitsState::ptr)( + unitID, x, y, 0); + } + return TRUE; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/playAttackCommandFeedback.cpp b/src/OpenSHC/Map/Units/TribesState/playAttackCommandFeedback.cpp new file mode 100644 index 0000000000..a933adb5c9 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/playAttackCommandFeedback.cpp @@ -0,0 +1,38 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522090 + void TribesState::playAttackCommandFeedback(int tribeID) + { + int selectionTribeID = tribeID; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::selectionContainsCombatUnit, DAT_UnitsState::ptr)(1); + UnitType unitType = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getMajoritySelectedUnitType, this)( + selectionTribeID, &tribeID); + if (unitType == Map::Units::UT_S_BATTERINGRAM || unitType == Map::Units::UT_S_CATAPULT + || unitType == Map::Units::UT_S_TREBUCHET || unitType == Map::Units::UT_S_MANGONEL + || unitType == Map::Units::UT_S_BALLISTA || unitType == Map::Units::UT_S_FBALLISTA) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::playUnitMoveSpeech, this)( + DAT_TribesState::instance.DAT_CurrentTribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::playUnitSelectionSound, this)(selectionTribeID); + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 21); + if (unitType != Map::Units::UT_E_ENGINEER) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::playUnitSelectionSound, this)(selectionTribeID); + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/playUnitCombatSpeechForTarget.cpp b/src/OpenSHC/Map/Units/TribesState/playUnitCombatSpeechForTarget.cpp new file mode 100644 index 0000000000..295918153a --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/playUnitCombatSpeechForTarget.cpp @@ -0,0 +1,191 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00521A90 + void TribesState::playUnitCombatSpeechForTarget(int selectionID, int unitID) + { + int selectedCount; + int const otherUnitID + = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::selectionContainsCombatUnit, DAT_UnitsState::ptr)(1); + UnitTypeInt const unitType = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getMajoritySelectedUnitType, this)(selectionID, &selectedCount); + int const tribeSize = DAT_TribesState::instance.tribes[selectionID].size; + switch (unitType) { + case Map::Units::UT_E_ARCHER: + case Map::Units::UT_E_XBOW: + case Map::Units::UT_A_ARCHER: + case Map::Units::UT_A_SLINGER: + case Map::Units::UT_A_HARCHER: + case Map::Units::UT_A_FIRETHROWER: { + int range; + if (unitType == Map::Units::UT_E_ARCHER) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1]; + } else if (unitType == Map::Units::UT_E_XBOW) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[7] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[7]; + } else if (unitType == Map::Units::UT_A_ARCHER) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1]; + } else if (unitType == Map::Units::UT_A_SLINGER) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[33] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[33]; + } else if (unitType == Map::Units::UT_A_HARCHER) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[1]; + } else if (unitType == Map::Units::UT_A_FIRETHROWER) { + range = DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[34] + * DAT_EntityDefinedData::instance.EntityTypeArrayForProjectileRange[34]; + } else { + range = unitID; + } + int const otherX = DAT_UnitsState::instance.units[otherUnitID].x; + int const otherY = DAT_UnitsState::instance.units[otherUnitID].y; + int const unitX = DAT_UnitsState::instance.units[unitID].x; + int const unitY = DAT_UnitsState::instance.units[unitID].y; + if ((otherX - unitX) * (otherX - unitX) + (otherY - unitY) * (otherY - unitY) > range) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)( + (UnitType)unitType, 30); + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)( + (UnitType)unitType, 25); + } + if (unitType != Map::Units::UT_A_HARCHER) { + return; + } + if (selectedCount == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_ARCHER1); + } else if (selectedCount <= 4) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_ARCHER2); + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_ARCHER3); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_WHINNY); + return; + } + case Map::Units::UT_E_KNIGHT: { + int const count = selectedCount; + if (count == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSES_1); + } else { + if (count == 2 || count == 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, + DAT_UnitsState::instance.units[otherUnitID].y, DE::SHCDE::FX_HORSES_3); + } + if (count >= 4) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, + DAT_UnitsState::instance.units[otherUnitID].y, DE::SHCDE::FX_HORSES_4); + } + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_WHINNY); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)((UnitType)unitType, 21); + if (tribeSize >= 15) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_HORSE_ARMY_CHARGE); + } + return; + } + case Map::Units::UT_E_SWORD: + if (selectedCount == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_SWORDWALK_1); + } else if (selectedCount == 2) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_SWORDWALK_2); + } else if (selectedCount >= 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + DE::SHCDE::FX_SWORDWALK_3); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)((UnitType)unitType, 21); + if (tribeSize >= 15) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + 20); + } + return; + case Map::Units::UT_E_SPEAR: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)((UnitType)unitType, 21); + if (tribeSize >= 15) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + 20); + } + return; + case Map::Units::UT_E_PIKE: + case Map::Units::UT_E_MACE: + case Map::Units::UT_E_MONK: { + UnitTypeShort const targetType = DAT_UnitsState::instance.units[unitID].unitType; + if (targetType == Map::Units::UT_E_KNIGHT || targetType == Map::Units::UT_E_SWORD + || targetType == Map::Units::UT_LORD) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)( + (UnitType)unitType, 17); + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)( + (UnitType)unitType, 21); + } + if (tribeSize >= 15) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + 20); + } + return; + } + case Map::Units::UT_A_SWORDSMAN: + if (tribeSize >= 15) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[otherUnitID].x, DAT_UnitsState::instance.units[otherUnitID].y, + 20); + } + return; + default: { + UnitTypeShort const targetType = DAT_UnitsState::instance.units[unitID].unitType; + if (targetType != Map::Units::UT_E_KNIGHT && targetType != Map::Units::UT_E_SWORD + && targetType != Map::Units::UT_E_MACE && targetType != Map::Units::UT_E_PIKE + && targetType != Map::Units::UT_LORD) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)( + (UnitType)unitType, 21); + return; + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)((UnitType)unitType, 17); + return; + } + case Map::Units::UT_E_ENGINEER: + return; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/playUnitMoveSpeech.cpp b/src/OpenSHC/Map/Units/TribesState/playUnitMoveSpeech.cpp new file mode 100644 index 0000000000..95c0f95d57 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/playUnitMoveSpeech.cpp @@ -0,0 +1,84 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Audio/SFX/SpeechEffectID.hpp" + +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00521EF0 + void TribesState::playUnitMoveSpeech(undefined4 tribeID) + { + int const unitID + = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::selectionContainsCombatUnit, DAT_UnitsState::ptr)(1); + UnitType unitType; + { + int selectedCount; + unitType = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getMajoritySelectedUnitType, this)( + tribeID, &selectedCount); + } + switch (unitType) { + case Map::Units::UT_E_ARCHER: + case Map::Units::UT_E_XBOW: + case Map::Units::UT_A_ARCHER: + case Map::Units::UT_A_SLINGER: + case Map::Units::UT_A_HARCHER: + case Map::Units::UT_A_FIRETHROWER: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 29); + return; + case Map::Units::UT_S_CATAPULT: + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + != 0) { + if (DAT_UnitsState::instance.units[unitID].stoneAmmunition < 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSpeechSFX, DAT_SFXState::ptr)( + Audio::SFX::SEID_RESOURCE_NEED25); + return; + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 16); + } + break; + case Map::Units::UT_S_TREBUCHET: + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + != 0) { + if (DAT_UnitsState::instance.units[unitID].stoneAmmunition < 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSpeechSFX, DAT_SFXState::ptr)( + Audio::SFX::SEID_RESOURCE_NEED25); + return; + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 17); + } + break; + case Map::Units::UT_S_MANGONEL: + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + != 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 15); + } + break; + case Map::Units::UT_S_BALLISTA: + case Map::Units::UT_S_FBALLISTA: + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + != 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 18); + } + break; + case Map::Units::UT_S_BATTERINGRAM: + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + != 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeech, DAT_SFXState::ptr)(unitType, 19); + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/playUnitSelectionSound.cpp b/src/OpenSHC/Map/Units/TribesState/playUnitSelectionSound.cpp new file mode 100644 index 0000000000..24d2d3eae8 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/playUnitSelectionSound.cpp @@ -0,0 +1,134 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x005217E0 + void TribesState::playUnitSelectionSound(int tribeID) + { + int const unitID + = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::selectionContainsCombatUnit, DAT_UnitsState::ptr)(1); + bool isSiege; + { + int selectedCount; + switch (MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getMajoritySelectedUnitType, this)( + tribeID, &selectedCount)) { + case Map::Units::UT_E_SWORD: + if (selectedCount == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_SWORDWALK_1); + } else if (selectedCount == 2) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_SWORDWALK_2); + } else if (selectedCount >= 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_SWORDWALK_3); + } + return; + case Map::Units::UT_E_KNIGHT: { + int const count = selectedCount; + if (count == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSES_1); + } else { + if (count == 2 || count == 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, + DAT_SFXState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, DE::SHCDE::FX_HORSES_3); + } + if (count >= 4) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, + DAT_SFXState::ptr)(DAT_UnitsState::instance.units[unitID].x, + DAT_UnitsState::instance.units[unitID].y, DE::SHCDE::FX_HORSES_4); + } + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSE_WHINNY); + return; + } + case Map::Units::UT_A_HARCHER: { + if (selectedCount == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSE_ARCHER1); + } else if (selectedCount <= 4) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSE_ARCHER2); + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSE_ARCHER3); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_HORSE_WHINNY); + return; + } + case Map::Units::UT_S_CATAPULT: + case Map::Units::UT_S_TOWER: + case Map::Units::UT_S_BATTERINGRAM: + isSiege = true; + break; + case Map::Units::UT_E_ENGINEER: + isSiege = false; + break; + default: + return; + } + } + if (isSiege) { + int const requiredEngineers = MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::getRemainingRequiredEngineers, DAT_UnitsState::ptr)(unitID); + if (requiredEngineers > 0) { + if (DAT_UnitsState::instance.units[unitID] + .digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + == 0 + || requiredEngineers > 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeechEffect, DAT_SFXState::ptr)(14); + return; + } + if (requiredEngineers == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeechEffect, DAT_SFXState::ptr)(11); + return; + } + if (requiredEngineers == 2) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeechEffect, DAT_SFXState::ptr)(12); + return; + } + if (requiredEngineers == 3) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeechEffect, DAT_SFXState::ptr)(13); + } + return; + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocationFullVolume, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_SIEGE_ROLL); + return; + } + if (DAT_UnitsState::instance.units[unitID].unitType != Map::Units::UT_E_ENGINEER) { + return; + } + if (DAT_UnitsState::instance.units[unitID].resourceToDeposit == 0) { + return; + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playUnitSpeechEffect, DAT_SFXState::ptr)(36); + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/processDeerMoving.cpp b/src/OpenSHC/Map/Units/TribesState/processDeerMoving.cpp new file mode 100644 index 0000000000..468566f689 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/processDeerMoving.cpp @@ -0,0 +1,153 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052AD50 + void TribesState::processDeerMoving(int tribeID) + { + int const targetUnitID = this->tribes[tribeID].selectionTargetUnitID; + int const marshTiles = DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .marshTiles; + int const rockyTiles = DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .rockyTiles; + int const predatorCount + = DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .field_0x48 + + DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .lionCount; + short const size = this->tribes[tribeID].size; + this->tribes[tribeID].unkIsAnimalTribe = 1; + if (size > 30) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::trimTribeToSize, this)(tribeID, 30); + this->tribes[tribeID].herdMinSize = 15; + this->tribes[tribeID].herdMaxSize = 60; + } else { + this->tribes[tribeID].herdMinSize = size / 2; + this->tribes[tribeID].herdMaxSize = size * 2; + } + if (predatorCount != 0 && this->tribes[tribeID].predatorNearby == 0) { + this->tribes[tribeID].predatorNearby = 1; + } + if (MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnDeerLionOrRabbit, this)( + tribeID, 100, Map::Units::UT_ANTELOPESHDEER)) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 0); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][0], + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][1], 0, 0, + Map::Units::Instructions::UMSE_0); + ++this->tribes[tribeID].currentRallyPointIndex; + if (this->tribes[tribeID].currentRallyPointIndex >= this->tribes[tribeID].rallyPointCount) { + this->tribes[tribeID].rallyPointCount = 0; + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + } + return; + } + if (this->tribes[tribeID].initialMoveOrderGiven == 0) { + int const unitID = this->tribes[tribeID].selectionTargetUnitID; + this->tribes[tribeID].initialMoveOrderGiven = 1; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, 0, 0, + Map::Units::Instructions::UMSE_0); + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + this->tribes[tribeID].unknownCounter01 = 0; + return; + } + ushort const predatorNearby = this->tribes[tribeID].predatorNearby; + if (predatorNearby != 0) { + if (predatorNearby == 1) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 5, 0); + if (this->tribes[tribeID].rallyPointCount <= 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 5, 1); + } + if (this->tribes[tribeID].rallyPointCount > 0) { + int const unitID = this->tribes[tribeID].selectionTargetUnitID; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + DE::SHCDE::FX_DEER_RUN); + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveUnitSelectionMoveInstructionNoMatchedSpeed, this)(tribeID, + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].rallyPointCount - 1][0], + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].rallyPointCount - 1][1], 0, 0); + } else { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::scatterTribeUnitsRandomly, this)(tribeID); + } + } + ++this->tribes[tribeID].predatorNearby; + if ((short)this->tribes[tribeID].predatorNearby >= 800) { + this->tribes[tribeID].predatorNearby = 0; + } + return; + } + if (this->tribes[tribeID].tribeBehaviorType == 0) { + if (marshTiles != 0) { + this->tribes[tribeID].wanderIntervalTicks = 200; + } + if (rockyTiles > 20) { + this->tribes[tribeID].wanderIntervalTicks = 200; + } + ++this->tribes[tribeID].unknownAttackRelatedUpdateCounter; + if ((short)this->tribes[tribeID].unknownAttackRelatedUpdateCounter + >= this->tribes[tribeID].wanderIntervalTicks) { + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].wanderIntervalTicks = (4 - (SEC_RNG::instance.currentNumber2 & 3)) * 200; + if (this->tribes[tribeID].rallyPointCount <= 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 5, 0); + return; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveUnitSelectionMoveInstructionNoMatchedSpeed, this)(tribeID, + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][0], + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][1], 0, 0); + ++this->tribes[tribeID].currentRallyPointIndex; + if (this->tribes[tribeID].currentRallyPointIndex >= this->tribes[tribeID].rallyPointCount) { + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + this->tribes[tribeID].rallyPointCount = 0; + } + } + } else if (this->tribes[tribeID].tribeBehaviorType == Map::Units::STBT_1) { + ++this->tribes[tribeID].unknownAttackRelatedUpdateCounter; + if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter == 800) { + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].tribeBehaviorType = 0; + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/removeUnitFromThisTribeIfInTribe.cpp b/src/OpenSHC/Map/Units/TribesState/removeUnitFromThisTribeIfInTribe.cpp new file mode 100644 index 0000000000..7cb2ce3c86 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/removeUnitFromThisTribeIfInTribe.cpp @@ -0,0 +1,44 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Enums/TribeState.hpp" + +#include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522630 + void TribesState::removeUnitFromThisTribeIfInTribe(uint unitID, int tribeID) + { + if (DAT_UnitsState::instance.units[unitID].tribeID == 0 + && (this->tribes[tribeID].unitSelectionBitMasked[(int)unitID / 16] + & DAT_UnitSelectionDefinedData::instance.BitMaskHelper[(int)unitID % 16]) + == 0) { + return; + } + short const size = this->tribes[tribeID].size; + if (size > 0) { + this->tribes[tribeID].size = size - 1; + } + if (this->tribes[tribeID].size <= 0) { + this->tribes[tribeID].tribeState = Map::Enums::TS_DISBANDED; + } + int const wordIndex = (int)unitID / 16; + int const bitIndex = (int)unitID % 16; + this->tribes[tribeID].unitSelectionBitMasked[wordIndex] + &= DAT_UnitSelectionDefinedData::instance.BitMaskHelper2[bitIndex]; + if (DAT_UnitsState::instance.units[unitID].tribeID == tribeID) { + DAT_UnitsState::instance.units[unitID].selectionTargetUnitID = 0; + DAT_UnitsState::instance.units[unitID].tribeID = 0; + DAT_UnitsState::instance.units[unitID].idInTribe = 0; + } + if (this->tribes[tribeID].selectionTargetUnitID == unitID) { + this->tribes[tribeID].selectionTargetUnitID = -1; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/removeUnitFromTribe.cpp b/src/OpenSHC/Map/Units/TribesState/removeUnitFromTribe.cpp new file mode 100644 index 0000000000..62ee7230fe --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/removeUnitFromTribe.cpp @@ -0,0 +1,44 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Enums/TribeState.hpp" + +#include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00525A70 + void TribesState::removeUnitFromTribe(uint unitID, int tribeID) + { + if (DAT_UnitsState::instance.units[unitID].tribeID != 0 + || (this->tribes[tribeID].unitSelectionBitMasked[(int)unitID / 16] + & DAT_UnitSelectionDefinedData::instance.BitMaskHelper[(int)unitID % 16]) + != 0) { + short const size = this->tribes[tribeID].size; + if (size > 0) { + this->tribes[tribeID].size = size - 1; + } + if (this->tribes[tribeID].size <= 0) { + this->tribes[tribeID].tribeState = Map::Enums::TS_DISBANDED; + } + int const wordIndex = (int)unitID / 16; + int const bitIndex = (int)unitID % 16; + this->tribes[tribeID].unitSelectionBitMasked[wordIndex] + &= DAT_UnitSelectionDefinedData::instance.BitMaskHelper2[bitIndex]; + if (DAT_UnitsState::instance.units[unitID].tribeID == tribeID) { + DAT_UnitsState::instance.units[unitID].selectionTargetUnitID = 0; + DAT_UnitsState::instance.units[unitID].tribeID = 0; + DAT_UnitsState::instance.units[unitID].idInTribe = 0; + } + if (this->tribes[tribeID].selectionTargetUnitID == unitID) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::setTargetUnitForTribe, this)(tribeID); + } + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::setWhetherTribeContainsAnyUnits, this)(tribeID); + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/snapshotSelectionTribeAndComputeStance.cpp b/src/OpenSHC/Map/Units/TribesState/snapshotSelectionTribeAndComputeStance.cpp new file mode 100644 index 0000000000..3655cf2fd2 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/snapshotSelectionTribeAndComputeStance.cpp @@ -0,0 +1,57 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Units/Behavior/UnitStanceEnum.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + using OpenSHC::Map::Units::Behavior::USE_AGGRESSIVE; + using OpenSHC::Map::Units::Behavior::USE_STAND_GROUND; + + // FUNCTION: STRONGHOLDCRUSADER 0x00522CA0 + void TribesState::snapshotSelectionTribeAndComputeStance(int playerID) + { + this->tribeCopiedToSlot0 = 0; + int stanceCount[3]; + stanceCount[0] = 0; + stanceCount[1] = 0; + stanceCount[2] = 0; + BOOL multipleTribes = FALSE; + int lastTribeID = -1; + for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; ++unitID) { + if (DAT_UnitsState::instance.units[unitID].logicalState == ULS_NORMAL + && !DAT_UnitsState::instance.units[unitID].dying + && DAT_UnitsState::instance.units[unitID].ifSelectedThenPlayerID == playerID) { + int const tribeID = DAT_UnitsState::instance.units[unitID].tribeID; + if (tribeID > 0) { + ++stanceCount[this->tribes[tribeID].unitStance]; + if (lastTribeID != -1 && tribeID != lastTribeID) { + multipleTribes = TRUE; + } + lastTribeID = tribeID; + } + } + } + if (lastTribeID != -1 && !multipleTribes) { + this->tribes[0] = this->tribes[lastTribeID]; + this->tribeCopiedToSlot0 = 1; + return; + } + if (stanceCount[2] + stanceCount[1] + stanceCount[0] != 0) { + if (stanceCount[2] >= stanceCount[1] && stanceCount[2] >= stanceCount[0]) { + this->tribes[0].unitStance = USE_AGGRESSIVE; + } else { + this->tribes[0].unitStance = stanceCount[1] >= stanceCount[0]; + } + } else { + this->tribes[0].unitStance = USE_STAND_GROUND; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/spawnDeerLionOrRabbit.cpp b/src/OpenSHC/Map/Units/TribesState/spawnDeerLionOrRabbit.cpp new file mode 100644 index 0000000000..b596b0a985 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/spawnDeerLionOrRabbit.cpp @@ -0,0 +1,85 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00525F20 + BOOLEnum TribesState::spawnDeerLionOrRabbit(int tribeID, int spawnInterval, UnitType unitType) + { + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + return FALSE; + } + if (tribeID <= 0) { + return FALSE; + } + if (this->tribes[tribeID].predatorNearby != 0) { + return FALSE; + } + TribesState* const shifted = (TribesState*)((char*)this + tribeID * sizeof(Tribe)); + int const targetUnitID = shifted->tribes[0].selectionTargetUnitID; + int unitID = targetUnitID; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + unitID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getNonDyingUnit, this)(tribeID); + if (unitID == 0) { + unitID = targetUnitID; + } + } + int const x = DAT_UnitsState::instance.units[unitID].x; + int const y = DAT_UnitsState::instance.units[unitID].y; + int const terrainHeight = DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight; + short const herdMinSize = shifted->tribes[0].herdMinSize; + short const size = shifted->tribes[0].size; + int const roll = SEC_RNG::instance.currentNumber2 & 0x7f; + if (size <= herdMinSize) { + spawnInterval /= 4; + } + ++shifted->tribes[0].field_0x284; + if ((short)shifted->tribes[0].field_0x284 < spawnInterval) { + return FALSE; + } + shifted->tribes[0].field_0x284 = 0; + if (size >= shifted->tribes[0].herdMaxSize) { + return FALSE; + } + int chance; + if (unitType == Map::Units::UT_RABBIT + && DAT_GameState::instance.mapAndTime.eventCountdownRabbitInfestation) { + chance = 110; + } else { + chance = size < herdMinSize ? 25 : 100; + } + if (chance > roll) { + return FALSE; + } + int const spawnedUnitID = MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + 0, 0, x * 8, y * 8, terrainHeight, unitType); + if (spawnedUnitID == 0) { + return FALSE; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, this)(spawnedUnitID, tribeID); + DAT_UnitsState::instance.units[spawnedUnitID].substate + = DAT_UnitsState::instance.units[spawnedUnitID].fixedRng & 3; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + DAT_UnitsState::instance.units[spawnedUnitID].antelopeBasedRngValue = 2; + } + DAT_UnitsState::instance.units[spawnedUnitID].disappearFadeAlphaCountdown = 32; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::updateAnimalHerdBehaviorState, this)(tribeID); + } + return TRUE; + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/trimTribeToSize.cpp b/src/OpenSHC/Map/Units/TribesState/trimTribeToSize.cpp new file mode 100644 index 0000000000..187a5b93d6 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/trimTribeToSize.cpp @@ -0,0 +1,42 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/Enums/TribeState.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTribeID.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x00522EF0 + void TribesState::trimTribeToSize(undefined4 tribeID, int smallerSize) + { + // fixme: the original ignores tribeID and trims the tribe in DAT_CurrentTribeID + int const currentTribeID = DAT_CurrentTribeID::instance; + int unitSelectionIndex = 0; + TribesState* const shifted = (TribesState*)((char*)this + currentTribeID * sizeof(Tribe)); + if (this->tribes[currentTribeID].tribeState == Map::Enums::TS_UNUSED) { + return; + } + int const size = shifted->tribes[0].size; + if (size < smallerSize || size <= 0) { + return; + } + for (; unitSelectionIndex < shifted->tribes[0].size;) { + int const unitID = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::getUnitIDForIndexInTribe, this)( + currentTribeID, unitSelectionIndex); + UnitLogicStateShort const logicalState = DAT_UnitsState::instance.units[unitID].logicalState; + ++unitSelectionIndex; + if ((logicalState == 1 || logicalState == Map::Units::ULS_NORMAL + || logicalState == Map::Units::ULS_TRANSITIONING) + && unitSelectionIndex >= smallerSize) { + DAT_UnitsState::instance.units[unitID].logicalState = Map::Units::ULS_REMOVE; + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/updateCamelTribeBehavior.cpp b/src/OpenSHC/Map/Units/TribesState/updateCamelTribeBehavior.cpp new file mode 100644 index 0000000000..9465f0b0e4 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/updateCamelTribeBehavior.cpp @@ -0,0 +1,97 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052B630 + void TribesState::updateCamelTribeBehavior(int tribeID) + { + BOOLEnum const noTunnelers = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::isTribeFreeOfTunnelingUnits, this)(tribeID, this->tribes[tribeID].uid); + ++this->tribes[tribeID].unknownCounter01; + this->tribes[tribeID].unkIsAnimalTribe = 1; + if (this->tribes[tribeID].unknownCounter01 >= 8000) { + this->tribes[tribeID].unknownCounter01 = 4000; + } + if (noTunnelers + && MACRO_CALL_MEMBER(Map::Units::TribesState_Func::trySpawnAdditionalWildlifeForTribe, this)( + tribeID, 1000, 10, Map::Units::UT_CAMELSHBEAR)) { + this->tribes[tribeID].initialMoveOrderGiven = 1; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + return; + } + ushort const moveOrder = this->tribes[tribeID].initialMoveOrderGiven; + if (moveOrder == 0) { + int const targetUnitID = this->tribes[tribeID].selectionTargetUnitID; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].initialMoveOrderGiven = 2; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, 0, + 0, Map::Units::Instructions::UMSE_0); + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + this->tribes[tribeID].unknownCounter01 = 0; + return; + } + if (moveOrder == 1) { + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].initialMoveOrderGiven = 2; + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 0); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][0], + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][1], 0, 0, + Map::Units::Instructions::UMSE_0); + ++this->tribes[tribeID].currentRallyPointIndex; + if (this->tribes[tribeID].currentRallyPointIndex >= this->tribes[tribeID].rallyPointCount) { + this->tribes[tribeID].rallyPointCount = 0; + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + } + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (this->tribes[tribeID].tribeBehaviorType == 0) { + if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter++ == 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 1); + if (this->tribes[tribeID].rallyPointCount > 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + int const lastRallyPoint = this->tribes[tribeID].rallyPointCount; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveUnitSelectionMoveInstructionNoMatchedSpeed, + this)(tribeID, this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][0], + this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][1], 0, 0); + } + } else if (noTunnelers) { + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } else if (this->tribes[tribeID].tribeBehaviorType == Map::Units::STBT_1) { + int timeout = 800; + if (this->tribes[tribeID].unknownCounter01 <= 100) { + timeout = 10; + } + ++this->tribes[tribeID].unknownAttackRelatedUpdateCounter; + if ((short)this->tribes[tribeID].unknownAttackRelatedUpdateCounter >= timeout) { + this->tribes[tribeID].tribeBehaviorType = 0; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/updateLionWolfTribeBehavior.cpp b/src/OpenSHC/Map/Units/TribesState/updateLionWolfTribeBehavior.cpp new file mode 100644 index 0000000000..2d3f2334d0 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/updateLionWolfTribeBehavior.cpp @@ -0,0 +1,111 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052B110 + void TribesState::updateLionWolfTribeBehavior(int tribeID) + { + BOOLEnum const noTunnelers = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::isTribeFreeOfTunnelingUnits, this)(tribeID, this->tribes[tribeID].uid); + ++this->tribes[tribeID].unknownCounter01; + this->tribes[tribeID].unkIsAnimalTribe = 1; + if (this->tribes[tribeID].unknownCounter01 >= 8000) { + this->tribes[tribeID].unknownCounter01 = 4000; + } + ushort const countdown = this->tribes[tribeID].countdown; + if (countdown != 0) { + if (countdown == 100) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::setStateForAllTribeUnits, this)( + tribeID, Map::Units::States::US_UNKNOWN_208); + this->tribes[tribeID].unknownBool01 = 1; + } + return; + } + if (noTunnelers + && MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnDeerLionOrRabbit, this)( + tribeID, 500, Map::Units::UT_LIONSHWOLF)) { + this->tribes[tribeID].initialMoveOrderGiven = 1; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + return; + } + ushort const moveOrder = this->tribes[tribeID].initialMoveOrderGiven; + if (moveOrder == 0) { + int const targetUnitID = this->tribes[tribeID].selectionTargetUnitID; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].initialMoveOrderGiven = 2; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + DAT_UnitsState::instance.units[targetUnitID].x, DAT_UnitsState::instance.units[targetUnitID].y, 0, + 0, Map::Units::Instructions::UMSE_0); + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (moveOrder == 1) { + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + this->tribes[tribeID].initialMoveOrderGiven = 2; + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 0); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][0], + this->tribes[tribeID].rallyPointArray[this->tribes[tribeID].currentRallyPointIndex][1], 0, 0, + Map::Units::Instructions::UMSE_0); + ++this->tribes[tribeID].currentRallyPointIndex; + if (this->tribes[tribeID].currentRallyPointIndex >= this->tribes[tribeID].rallyPointCount) { + this->tribes[tribeID].rallyPointCount = 0; + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + } + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + this->tribes[tribeID].unknownCounter01 = 0; + return; + } + if (this->tribes[tribeID].tribeBehaviorType == 0) { + if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter++ == 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 0); + if (this->tribes[tribeID].rallyPointCount > 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::applyLadderDestructionToTribeUnits, this)( + tribeID); + } + } else if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter == 150) { + if (this->tribes[tribeID].unknownBool02 == 0) { + short const lastRallyPoint = this->tribes[tribeID].rallyPointCount; + if (lastRallyPoint > 0) { + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveUnitSelectionMoveInstructionNoMatchedSpeed, this)( + tribeID, this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][0], + this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][1], 0, 0); + } + } + } else if (noTunnelers) { + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } else if (this->tribes[tribeID].tribeBehaviorType == Map::Units::STBT_1) { + ++this->tribes[tribeID].unknownAttackRelatedUpdateCounter; + if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter == 300) { + this->tribes[tribeID].tribeBehaviorType = 0; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/updateRabbitTribeBehavior.cpp b/src/OpenSHC/Map/Units/TribesState/updateRabbitTribeBehavior.cpp new file mode 100644 index 0000000000..64124fd208 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/updateRabbitTribeBehavior.cpp @@ -0,0 +1,115 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/SomeTribeBehaviorType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052B390 + void TribesState::updateRabbitTribeBehavior(int tribeID) + { + int const targetUnitID = this->tribes[tribeID].selectionTargetUnitID; + int const rockyTiles = DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .rockyTiles; + int const marshTiles = DAT_WildlifeState::instance + .grid[DAT_UnitsState::instance.units[targetUnitID].x / Map::MC_MAP_SECTOR_SIZE] + [DAT_UnitsState::instance.units[targetUnitID].y / Map::MC_MAP_SECTOR_SIZE] + .marshTiles; + BOOLEnum const noTunnelers = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::isTribeFreeOfTunnelingUnits, this)(tribeID, this->tribes[tribeID].uid); + this->tribes[tribeID].unkIsAnimalTribe = 1; + int spawnInterval = 80; + if (DAT_GameState::instance.mapAndTime.eventCountdownRabbitInfestation) { + spawnInterval = 3; + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnDeerLionOrRabbit, this)( + tribeID, spawnInterval, Map::Units::UT_RABBIT); + if (this->tribes[tribeID].initialMoveOrderGiven == 0) { + int const unitID = this->tribes[tribeID].selectionTargetUnitID; + this->tribes[tribeID].initialMoveOrderGiven = 1; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveTribeMoveInstruction, this)(tribeID, + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, 0, 0, + Map::Units::Instructions::UMSE_0); + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + this->tribes[tribeID].unknownCounter01 = 0; + return; + } + ushort const predatorNearby = this->tribes[tribeID].predatorNearby; + if (predatorNearby != 0) { + if (predatorNearby == 1) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 3, 0); + if (this->tribes[tribeID].rallyPointCount <= 0) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 3, 1); + } + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::scatterTribeUnitsRandomly, this)(tribeID); + } + ++this->tribes[tribeID].predatorNearby; + if ((short)this->tribes[tribeID].predatorNearby >= 3000) { + this->tribes[tribeID].predatorNearby = 0; + } + return; + } + if (this->tribes[tribeID].tribeBehaviorType == 0) { + if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter++ == 0) { + if (!MACRO_CALL_MEMBER( + Map::WildlifeState_Func::buildRallyPointPathForTribe, DAT_WildlifeState::ptr)(tribeID, 4)) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::findAndSetNewRallyPointForDeerAndLions, + DAT_WildlifeState::ptr)(tribeID, 2, 1); + } + if (this->tribes[tribeID].rallyPointCount > 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::standUpAllTribeUnits, this)(tribeID); + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::applyLadderDestructionToTribeUnits, this)( + tribeID); + } + } else if (this->tribes[tribeID].unknownAttackRelatedUpdateCounter == 150) { + short const lastRallyPoint = this->tribes[tribeID].rallyPointCount; + if (lastRallyPoint > 0) { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::giveUnitSelectionMoveInstructionNoMatchedSpeed, + this)(tribeID, this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][0], + this->tribes[tribeID].rallyPointArray[lastRallyPoint - 1][1], 0, 0); + } + } else if (noTunnelers) { + this->tribes[tribeID].tribeBehaviorType = Map::Units::STBT_1; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } else if (this->tribes[tribeID].tribeBehaviorType == Map::Units::STBT_1) { + if (marshTiles != 0) { + this->tribes[tribeID].wanderIntervalTicks = 20; + } else if (rockyTiles > 20) { + this->tribes[tribeID].wanderIntervalTicks = 20; + } else { + this->tribes[tribeID].wanderIntervalTicks = 400; + } + ++this->tribes[tribeID].unknownAttackRelatedUpdateCounter; + if ((short)this->tribes[tribeID].unknownAttackRelatedUpdateCounter + >= this->tribes[tribeID].wanderIntervalTicks) { + this->tribes[tribeID].tribeBehaviorType = 0; + this->tribes[tribeID].unknownAttackRelatedUpdateCounter = 0; + } + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Units/TribesState/upgradeTribeArrayLayoutForMapVersion.cpp b/src/OpenSHC/Map/Units/TribesState/upgradeTribeArrayLayoutForMapVersion.cpp new file mode 100644 index 0000000000..611e0671b6 --- /dev/null +++ b/src/OpenSHC/Map/Units/TribesState/upgradeTribeArrayLayoutForMapVersion.cpp @@ -0,0 +1,32 @@ +#include "../TribesState.func.hpp" + +#include "OpenSHC/OS.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Units { + + // Map versions below 169 store each tribe in 620 bytes: a 100-word unit bitmask, and the rest of the + // record (364 bytes) at offset 256. + // FUNCTION: STRONGHOLDCRUSADER 0x00523EF0 + void TribesState::upgradeTribeArrayLayoutForMapVersion( + PackagedFileMagicNum receivedMapVersion, PackagedFileMagicNum packagerMapVersion) + { + if (receivedMapVersion != packagerMapVersion && receivedMapVersion < 169) { + for (int tribeIndex = countof(this->tribes) - 1; tribeIndex >= 0; --tribeIndex) { + char* const oldRecord = (char*)this->tribes + tribeIndex * 620; + Tribe* const tribe = &this->tribes[tribeIndex]; + if ((void*)tribe != oldRecord) { + MACRO_CALL(OpenSHC::OS_Func::_memmove)(tribe, oldRecord, 620); + } + MACRO_CALL(OpenSHC::OS_Func::_memmove)(&tribe->field_0x1c8, oldRecord + 256, 364); + for (int wordIndex = 100; wordIndex < countof(tribe->unitSelectionBitMasked); ++wordIndex) { + tribe->unitSelectionBitMasked[wordIndex] = 0; + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index caffa45278..7adcf3c508 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -46387,7 +46387,7 @@ SHC_3BB0A8C1_0x00521210 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00521240 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00521280 | 0.0% | Pending +SHC_3BB0A8C1_0x00521280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00521500 | 0.0% | Pending @@ -46395,7 +46395,7 @@ SHC_3BB0A8C1_0x00521690 | 0.0% | Pending SHC_3BB0A8C1_0x00521720 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005217E0 | 0.0% | Pending +SHC_3BB0A8C1_0x005217E0 | 92.4% | Register allocation differs SHC_3BB0A8C1_0x00521A48 | 0.0% | Pending @@ -46505,7 +46505,7 @@ SHC_3BB0A8C1_0x00521A8E | 0.0% | Pending SHC_3BB0A8C1_0x00521A8F | 0.0% | Pending -SHC_3BB0A8C1_0x00521A90 | 0.0% | Pending +SHC_3BB0A8C1_0x00521A90 | 94.4% | Register allocation differs SHC_3BB0A8C1_0x00521E50 | 0.0% | Pending @@ -46635,7 +46635,7 @@ SHC_3BB0A8C1_0x00521EA6 | 0.0% | Pending SHC_3BB0A8C1_0x00521EB0 | 82.4% | pop esi scheduling -SHC_3BB0A8C1_0x00521EF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00521EF0 | 100.0% | Reimplemented (counted: only the playSpeechSFX tail-jump target differs; it goes through main's trampoline) SHC_3BB0A8C1_0x00522030 | 0.0% | Pending @@ -46763,7 +46763,7 @@ SHC_3BB0A8C1_0x00522082 | 0.0% | Pending SHC_3BB0A8C1_0x00522083 | 0.0% | Pending -SHC_3BB0A8C1_0x00522090 | 0.0% | Pending +SHC_3BB0A8C1_0x00522090 | 98.0% | Register allocation differs SHC_3BB0A8C1_0x00522110 | 100.0% | Reimplemented @@ -46781,7 +46781,7 @@ SHC_3BB0A8C1_0x005222B0 | 0.0% | Pending SHC_3BB0A8C1_0x00522360 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522390 | 0.0% | Pending +SHC_3BB0A8C1_0x00522390 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522410 | 0.0% | Pending @@ -46791,15 +46791,15 @@ SHC_3BB0A8C1_0x00522520 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522550 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522590 | 0.0% | Pending +SHC_3BB0A8C1_0x00522590 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522630 | 0.0% | Pending +SHC_3BB0A8C1_0x00522630 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522720 | 0.0% | Pending +SHC_3BB0A8C1_0x00522720 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005227E0 | 0.0% | Pending +SHC_3BB0A8C1_0x005227E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522890 | 0.0% | Pending +SHC_3BB0A8C1_0x00522890 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522950 | 100.0% | Reimplemented @@ -46815,11 +46815,11 @@ SHC_3BB0A8C1_0x00522C20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522C50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522CA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00522CA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522DD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00522EF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00522EF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00522F70 | 100.0% | Reimplemented @@ -46871,7 +46871,7 @@ SHC_3BB0A8C1_0x00523E30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00523EB0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00523EF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00523EF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00523F70 | 100.0% | Reimplemented @@ -46945,13 +46945,13 @@ SHC_3BB0A8C1_0x00525870 | 97.1% | Reimplemented, asm differs SHC_3BB0A8C1_0x00525970 | 97.1% | Reimplemented, asm differs -SHC_3BB0A8C1_0x00525A70 | 0.0% | Pending +SHC_3BB0A8C1_0x00525A70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00525B70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00525BA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00525BA0 | 96.5% | Register allocation differs -SHC_3BB0A8C1_0x00525F20 | 0.0% | Pending +SHC_3BB0A8C1_0x00525F20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005260B0 | 100.0% | Reimplemented @@ -46967,7 +46967,7 @@ SHC_3BB0A8C1_0x005266F0 | 0.0% | Pending SHC_3BB0A8C1_0x00526D50 | 0.0% | Pending -SHC_3BB0A8C1_0x00526F00 | 0.0% | Pending +SHC_3BB0A8C1_0x00526F00 | 90.3% | Register allocation differs SHC_3BB0A8C1_0x005270F0 | 0.0% | Pending @@ -48877,7 +48877,7 @@ SHC_3BB0A8C1_0x0052A638 | 0.0% | Pending SHC_3BB0A8C1_0x0052A640 | 98.4% | Reimplemented, one instruction off: MSVC anchors the strength-reduced loop pointer on XYPair::x where the original anchors on ::y, so the loop sentinel immediate differs -SHC_3BB0A8C1_0x0052A700 | 0.0% | Pending +SHC_3BB0A8C1_0x0052A700 | 100.0% | Reimplemented (counted: only the loop-end symbol differs) SHC_3BB0A8C1_0x0052A7D0 | 0.0% | Pending @@ -49141,13 +49141,13 @@ SHC_3BB0A8C1_0x0052AD41 | 0.0% | Pending SHC_3BB0A8C1_0x0052AD42 | 0.0% | Pending -SHC_3BB0A8C1_0x0052AD50 | 0.0% | Pending +SHC_3BB0A8C1_0x0052AD50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052B110 | 0.0% | Pending +SHC_3BB0A8C1_0x0052B110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052B390 | 0.0% | Pending +SHC_3BB0A8C1_0x0052B390 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052B630 | 0.0% | Pending +SHC_3BB0A8C1_0x0052B630 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052B860 | 0.0% | Pending