diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 17882af542..768bde34b8 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -280,6 +280,17 @@ 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/floodFillCasDisFromSignpost.cpp +src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp +src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp +src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp +src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp +src/OpenSHC/Map/WildlifeState/updateWildlife.cpp +src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp +src/OpenSHC/Map/LandscapeState/updateTreeStage.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/Map/LandscapeState/createRock.cpp b/src/OpenSHC/Map/LandscapeState/createRock.cpp new file mode 100644 index 0000000000..291637bee7 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/createRock.cpp @@ -0,0 +1,42 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentRockID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F2140 + int LandscapeState::createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation) + { + // find a free rock slot + int _rockID; + for (_rockID = 1; _rockID < 4000; _rockID++) { + if (this->rocks[_rockID].one == 0) { + break; + } + if (_rockID >= 3999) { + return 0; + } + } + this->rocks[_rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + this->rocks[_rockID].size = (short)size; + this->rocks[_rockID].y = (ushort)y; + this->rocks[_rockID].one = 1; + this->rocks[_rockID].type = (short)rockType; + this->rocks[_rockID].x = (ushort)x; + this->rocks[_rockID].tile + = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; + this->rocks[_rockID].orientation = (short)orientation; + this->rocks[_rockID].unknownGMID = (short)DAT_OrganismDefinedData::instance.Rock_field0xe[rockType]; + DAT_CurrentRockID::instance = _rockID; + (*DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[_rockID].type])(); + return _rockID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/createTree.cpp b/src/OpenSHC/Map/LandscapeState/createTree.cpp new file mode 100644 index 0000000000..9eb91c327c --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/createTree.cpp @@ -0,0 +1,184 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTreeID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + using Map::Trees::TreeTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F1CE0 + int LandscapeState::createTree(undefined4 x, undefined4 y, TreeType treeType, undefined4 size, + int stageRelatedValue, undefined4 param_6, int stage) + { + undefined2 uVar1; + undefined4 uVar3; + int uVar4; + uint _tile; + /* + *** Find a free tree slot *** + */ + int _treeID; + for (_treeID = 1; _treeID < 2000; _treeID++) { + if (!this->trees[_treeID].state) { + break; + } + if (_treeID >= 1999) { + return 0; + } + } + /* + *** Increment the max tree count on this map *** + */ + if (_treeID >= this->maxTreeCount) { + this->maxTreeCount = _treeID + 1; + } + /* + *** Assign uid to tree *** + */ + this->trees[_treeID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + /* + *** Set initial state of tree *** + */ + switch (treeType) { + case (TreeType)16: + case (TreeType)17: + case (TreeType)18: + case (TreeType)19: + this->trees[_treeID].state = 4; + break; + default: + this->trees[_treeID].state = 1; + } + /* + *** Set (initial) values for tree *** + */ + this->trees[_treeID].size = (short)size; + this->trees[_treeID].xPosition = (ushort)x; + this->trees[_treeID].treeType = (TreeTypeShort)treeType; + _tile + = (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile; + this->trees[_treeID].microX = (ushort)x * 8 + 3; + this->trees[_treeID].microY = (ushort)y * 8 + 3; + this->trees[_treeID].tile = _tile; + this->trees[_treeID].rng1 = DAT_TileMapState::instance.RandomLayer[_tile] & 0x7ff; + this->trees[_treeID].appleTreeColorVariation = stageRelatedValue; + this->trees[_treeID].param_6 = (short)param_6; + this->trees[_treeID].yPosition = (ushort)y; + this->trees[_treeID].treeTypeBasedValue1 + = (short)DAT_OrganismDefinedData::instance.TreeTypeBasedValueMapping[treeType]; + uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated1[treeType][stage]; + this->trees[_treeID].stageRelated4 = uVar1; + this->trees[_treeID].treeAdultHoodStageRelatedVisual3 = uVar1; + uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated2[treeType][stage]; + this->trees[_treeID].stageRelated2 = uVar1; + this->trees[_treeID].stageRelated1 = uVar1; + this->trees[_treeID].gmOriginX = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1] + .originX; + this->trees[_treeID].gmOriginY = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1] + .originY; + this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field_0x854[treeType]; + this->trees[_treeID].zero = 0; + this->trees[_treeID].animationFrameIndex = DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f; + this->trees[_treeID].one = 1; + this->trees[_treeID].stage = stage; + this->trees[_treeID].stageTracker = DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][stage]; + DAT_CurrentTreeID::instance = _treeID; + /* + *** Set tree type dependent values *** + */ + switch (treeType) { + case ((TreeType)1): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (uVar4 >= 15) { + this->trees[_treeID].appleTreeColorVariation = 4; + break; + } + if (uVar4 >= 13) { + this->trees[_treeID].appleTreeColorVariation = 6; + break; + } + if (uVar4 >= 11) { + this->trees[_treeID].appleTreeColorVariation = 1; + break; + } + if (uVar4 <= 8) { + break; + } + goto noColourVariation; + case ((TreeType)2): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (8 < uVar4) { + this->trees[_treeID].appleTreeColorVariation = 8; + } + break; + case ((TreeType)3): + this->trees[_treeID].appleTreeColorVariation = _treeID % 9; + break; + case ((TreeType)4): + uVar4 = this->trees[_treeID].rng1 & 0xf; + this->trees[_treeID].appleTreeColorVariation = uVar4; + if (uVar4 >= 15) { + this->trees[_treeID].appleTreeColorVariation = 4; + } else if (uVar4 >= 13) { + this->trees[_treeID].appleTreeColorVariation = 6; + } else if (uVar4 >= 11) { + this->trees[_treeID].appleTreeColorVariation = 1; + } else if (uVar4 > 8) { + this->trees[_treeID].appleTreeColorVariation = 0; + } + if (this->trees[_treeID].appleTreeColorVariation <= 8) { + break; + } + goto noColourVariation; + case ((TreeType)6): + this->trees[_treeID].appleTreeColorVariation = 3; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)7): + this->trees[_treeID].appleTreeColorVariation = 4; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)8): + this->trees[_treeID].appleTreeColorVariation = 7; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)9): + this->trees[_treeID].appleTreeColorVariation = 8; + this->trees[_treeID].stage = 4; + break; + case ((TreeType)5): + case ((TreeType)10): + case ((TreeType)0x10): + case ((TreeType)0x11): + case ((TreeType)0x12): + case ((TreeType)0x13): + this->trees[_treeID].stage = 4; + noColourVariation: + this->trees[_treeID].appleTreeColorVariation = 0; + break; + } + uVar3 = this->field_0x0; + this->field_0x0 = 0; + /* + *** Update the tree state *** + */ + (*DAT_OrganismDefinedData::instance.UpdateTree[(short)this->trees[_treeID].treeType])(); + this->field_0x0 = uVar3; + return _treeID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp new file mode 100644 index 0000000000..4be201989b --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp @@ -0,0 +1,94 @@ +#include "../../Map.func.hpp" +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Game/Player/PlayerData.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using DE::SHCDE::eSFX; + using Game::Player::PlayerData; + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3150 + void LandscapeState::spawnCrowFromNearbyTree(int unitID) + { + BOOL playedSound = FALSE; + for (int direction = 0; direction < 8; direction++) { + int const y = DAT_UnitsState::instance.units[unitID].y; + short const treeID = DAT_TileMapState::instance + .OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[y][direction] + + DAT_UnitsState::instance.units[unitID].tile]; + if (treeID == 0 || treeID >= this->maxTreeCount) { + continue; + } + if (this->trees[treeID].state != 2 || this->trees[treeID].hasCrow == 0 + || this->trees[treeID].rng200till300 != 0) { + continue; + } + int const playerID = DAT_UnitsState::instance.units[unitID].owner; + int targetX = 0; + int targetY = 0; + int closestDistance = 10000; + for (int keepPlayerID = 1; keepPlayerID < 9; keepPlayerID++) { + if (keepPlayerID == playerID + || !DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id) { + continue; + } + int const distanceX = abs(DAT_UnitsState::instance.units[unitID].x + - DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .xEntry); + int const distanceY = abs(y + - DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .yEntry); + int const distance = distanceX > distanceY ? distanceX : distanceY; + if (distance < closestDistance) { + targetX = SEC_RNG::instance.currentNumber2 % 5 - 2 + + DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .xEntry; + targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 5 - 2 + + DAT_GameState::instance.playerDataArray[keepPlayerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .yEntry; + closestDistance = distance; + } + } + if (closestDistance == 10000) { + targetX = DAT_UnitsState::instance.units[unitID].x - 50 + SEC_RNG::instance.currentNumber2 % 100; + targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 100 - 50 + y; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID, + DAT_UnitsState::instance.units[unitID].owner, 0, this->trees[treeID].xPosition * 8, + this->trees[treeID].yPosition * 8, + DAT_TileMapState::instance.HeightLayer[this->trees[treeID].tile] + 30, targetX * 8, targetY * 8, 250, + Map::Entities::EntityTypeInt__ET_CROW, 0); + this->trees[treeID].rng200till300 = SEC_RNG::instance.currentNumber2 % 100 + 200; + if (!playedSound) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->trees[treeID].xPosition, this->trees[treeID].yPosition, DE::SHCDE::FX_CROW); + playedSound = TRUE; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp new file mode 100644 index 0000000000..9b0d5fb0b4 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp @@ -0,0 +1,110 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.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_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + using Map::Trees::TreeTypeShort; + using UI::Enums::DisplayElementID; + using UI::Enums::MenuViewType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3960 + void LandscapeState::updateTreeStage(uint treeID, uint rng) + { + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + if (DAT_GameCore::instance.isTimeHalted) { + return; + } + if (MACRO_CALL(UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)( + UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO)) { + return; + } + } + if ((this->trees[treeID].rng1 & 0x3fU) != rng) { + return; + } + int const treeType = this->trees[treeID].treeType; + if (treeType >= 5 && treeType <= 19) { + return; + } + if (this->trees[treeID].zeroUpTo2 != 0) { + return; + } + if (this->trees[treeID].stageRelated1 < (short)this->trees[treeID].stageRelated2) { + return; + } + if (!this->field_0x4) { + return; + } + if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + return; + } + this->trees[treeID].stageTracker = this->trees[treeID].stageTracker + 1; + if (this->trees[treeID].stageTracker + < DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][this->trees[treeID].stage + 1]) { + return; + } + this->trees[treeID].stage = this->trees[treeID].stage + 1; + MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage); + if (this->trees[treeID].stage >= 6) { + this->trees[treeID].state = 3; + return; + } + if (this->trees[treeID].stage < 4) { + return; + } + DAT_GameState::instance.mapAndTime.treeSpreadCounter = DAT_GameState::instance.mapAndTime.treeSpreadCounter + 1; + if (DAT_GameState::instance.mapAndTime.treeSpreadCounter + > DAT_GameState::instance.mapAndTime.treeSpreadInterval) { + DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0; + this->trees[treeID].stage = 5; + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][5]; + return; + } + // set the spread counter to the lowest value for the tree type + this->trees[treeID].stageTracker + = DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][3]; + this->trees[treeID].stage = 3; + DAT_GameState::instance.mapAndTime.newOrganismsValue2 + = DAT_GameState::instance.mapAndTime.newOrganismsValue2 + 1; + if (!MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)( + treeID, this->trees[treeID].treeType, this->trees[treeID].xPosition, this->trees[treeID].yPosition)) { + return; + } + int const size = MACRO_CALL_MEMBER(Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, + DAT_LandscapeState::ptr)(this->trees[treeID].treeType, 0); + int const newTreeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, DAT_LandscapeState::ptr)( + DAT_PathFindingState::instance.ALG_ResultX, DAT_PathFindingState::instance.ALG_ResultY, + (TreeType)this->trees[treeID].treeType, size, 0, 0, 0); + DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] + = DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] | 0x1000; + DAT_TileMapState::instance.OrganismLayer[DAT_PathFindingState::instance.ALG_ResultTile] = (short)newTreeID; + MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)(newTreeID, 0); + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(this->trees[newTreeID].yPosition, this->trees[newTreeID].tile); + DAT_GameState::instance.mapAndTime.newOrganisms = DAT_GameState::instance.mapAndTime.newOrganisms + 1; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp new file mode 100644 index 0000000000..15fb10ae23 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp @@ -0,0 +1,131 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using WindowsHelper::Enums::BOOLEnum; + + /* + Takes a tribe index (param_1) and builds a rally point path for that tribe. First BFS-floods field20_0x50 + outward from the tribe's unit position (derived from selectionTargetUnitID), restricted to cells in the same + separateAreaID. Then greedily traces a path from the start cell by always stepping to the highest-scoring + unvisited neighbour, recording each step as a rally point in the tribe's rallyPointArray. Returns 1 on success, + 0 if the start cell has no field20_0x50 value (unreachable or unscored area). renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0052CFE0 + BOOLEnum WildlifeState::buildRallyPointPathForTribe(int param_1, int param_2) + { + // one pair of cell coordinates serves both the flood fill and the walk, as in the original: its stack + // slots are shared that way + int cellY; + int cellX; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[param_1].selectionTargetUnitID].y / 10; + this->casDisRelated = param_2; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + if (this->grid[x][y].field_0x50 == 0) { + return FALSE; + } + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x3c = 0; + } + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + this->grid[x][y].casDisRelated2 = this->grid[x][y].field_0x50; + int const areaID = this->grid[x][y].separateAreaID; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && areaID == this->grid[neighbourX][neighbourY].separateAreaID + && this->grid[neighbourX][neighbourY].field_0x50 > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 == 0) { + this->grid[neighbourX][neighbourY].casDisRelated2 = this->grid[neighbourX][neighbourY].field_0x50; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + cellY = y; + cellX = x; + uint const rng = (byte)SEC_RNG::instance.currentNumber2; + DAT_TribesState::instance.tribes[param_1].currentRallyPointIndex = 0; + DAT_TribesState::instance.tribes[param_1].rallyPointCount = 0; + this->grid[cellX][cellY].field_0x3c = 1; + this->grid[cellX][cellY].casDisRelated2 = 0; + while (true) { + int bestDirection = -1; + for (int k = 0; k < 8; k++) { + int direction = (rng & 7) + k; + if (direction >= 8) { + direction = direction - 8; + } + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 > param_2) { + int const distance = this->grid[neighbourX][neighbourY].casDisRelated2; + this->grid[neighbourX][neighbourY].casDisRelated2 = 0; + param_2 = distance; + bestDirection = direction; + } + } + if (bestDirection <= -1) { + return TRUE; + } + cellX = cellX + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + cellY = cellY + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[cellX][cellY].field_0x3c = 1; + uint const tileY = cellY * 10 + 5; + uint const tileX = cellX * 10 + 5; + if (tileX <= 399 && tileY <= 399 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][0] + = (short)cellX * 10 + 5; + DAT_TribesState::instance.tribes[param_1] + .rallyPointArray[DAT_TribesState::instance.tribes[param_1].rallyPointCount][1] + = (short)cellY * 10 + 5; + DAT_TribesState::instance.tribes[param_1].rallyPointCount + = DAT_TribesState::instance.tribes[param_1].rallyPointCount + 1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp new file mode 100644 index 0000000000..03b00f4fba --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp @@ -0,0 +1,154 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/AI/Tribes/AITribeType.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using AI::Tribes::AITribeType; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052CAB0 + void WildlifeState::findAndSetNewRallyPointForDeerAndLions(int tribeID, int always2or3or5, int always0or1) + { + // one pair of cell coordinates serves both the flood fill and the walk, as in the original: its stack + // slots are shared that way + int cellY; + int cellX; + int x = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].x / 10; + int y = DAT_UnitsState::instance.units[DAT_TribesState::instance.tribes[tribeID].selectionTargetUnitID].y / 10; + this->casDisRelated = always2or3or5; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x3c = 0; + } + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + int const areaID = this->grid[x][y].separateAreaID; + this->grid[x][y].casDisRelated2 = always2or3or5; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].casDisRelated2; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || areaID != this->grid[neighbourX][neighbourY].separateAreaID) { + continue; + } + if (!always0or1) { + if (this->grid[neighbourX][neighbourY].field_0x34 != 0) { + continue; + } + // 13: the wildlife tribe + if (DAT_TribesState::instance.tribes[tribeID].tribeType == 13) { + if (this->grid[neighbourX][neighbourY].deerCount != 0) { + continue; + } + if (this->grid[neighbourX][neighbourY].lionCount != 0) { + continue; + } + } + } else { + if (this->grid[neighbourX][neighbourY].unstalkedUnitCount != 0 + || this->grid[neighbourX][neighbourY].buildingTiles != 0) { + continue; + } + if (this->grid[neighbourX][neighbourY].lionCount != 0) { + continue; + } + } + if (this->grid[neighbourX][neighbourY].casDisRelated2 < level) { + this->grid[neighbourX][neighbourY].casDisRelated2 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + cellY = y; + cellX = x; + uint const rng = (byte)SEC_RNG::instance.currentNumber2; + int threshold = always2or3or5; + DAT_TribesState::instance.tribes[tribeID].currentRallyPointIndex = 0; + DAT_TribesState::instance.tribes[tribeID].rallyPointCount = 0; + this->grid[cellX][cellY].field_0x3c = 1; + this->grid[cellX][cellY].casDisRelated2 = 0; + while (true) { + int bestDirection = -1; + for (int k = 0; k < 8; k++) { + int direction = (rng & 7) + k; + if (direction >= 8) { + direction = direction - 8; + } + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX <= 39 && neighbourY <= 39 && this->grid[neighbourX][neighbourY].firstMember > 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 != 0 + && this->grid[neighbourX][neighbourY].casDisRelated2 < threshold) { + int const distance = this->grid[neighbourX][neighbourY].casDisRelated2; + this->grid[neighbourX][neighbourY].casDisRelated2 = 0; + threshold = distance; + bestDirection = direction; + } + } + if (bestDirection <= -1) { + return; + } + cellX = cellX + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.xOffset; + cellY = cellY + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[bestDirection].int_.yOffset; + this->grid[cellX][cellY].field_0x3c = 1; + uint const tileX = cellX * 10 + 5; + uint const tileY = cellY * 10 + 5; + if (tileX <= 399 && tileY <= 399 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] != '\0') { + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::pathFindingDeerAndLionsUnk, + DAT_PathFindingState::ptr)(areaID, tileX, tileY); + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][0] + = (short)DAT_PathFindingState::instance.climbX; + DAT_TribesState::instance.tribes[tribeID] + .rallyPointArray[DAT_TribesState::instance.tribes[tribeID].rallyPointCount][1] + = (short)DAT_PathFindingState::instance.climbY; + DAT_TribesState::instance.tribes[tribeID].rallyPointCount + = DAT_TribesState::instance.tribes[tribeID].rallyPointCount + 1; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp new file mode 100644 index 0000000000..76ae410137 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp @@ -0,0 +1,74 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D9D0 + void WildlifeState::floodFillCasDisFromSignpost() + { + int const x = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .x + / 10; + int const y = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .y + / 10; + this->casDisRelated = 1; + this->candidateIndex = 0; + this->candidateIndex2 = 1; + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + this->grid[column][row].casDisRelated2 = 0; + this->grid[column][row].field_0x74 = 0; + } + } + this->DAT_Y10_Array_Section1034[0] = (short)y; + this->DAT_X10_Array_Section1034[0] = (short)x; + int const areaID = this->grid[x][y].separateAreaID; + this->grid[x][y].casDisRelated2 = 1; + while (this->candidateIndex != this->candidateIndex2) { + int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[candidateX][candidateY].casDisRelated2; + if (this->casDisRelated >= 100) { + break; + } + int const level = this->casDisRelated + 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + candidateX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + candidateY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || areaID != this->grid[neighbourX][neighbourY].separateAreaID + || this->grid[neighbourX][neighbourY].unknownNonZero01 != 0 + || this->grid[neighbourX][neighbourY].casDisRelated2 != 0) { + continue; + } + this->grid[neighbourX][neighbourY].casDisRelated2 = level; + this->grid[neighbourX][neighbourY].field_0x74 = this->grid[neighbourX][neighbourY].field_0x74 + 1; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp new file mode 100644 index 0000000000..a7bdb9dd5b --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp @@ -0,0 +1,54 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052C570 + void WildlifeState::floodFillField13FromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].field_0x34 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].field_0x34; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].field_0x34 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].field_0x34 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp new file mode 100644 index 0000000000..17b6c68200 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp @@ -0,0 +1,54 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052C810 + void WildlifeState::floodFillField20FromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].field_0x50 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].field_0x50; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].field_0x50 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].field_0x50 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp new file mode 100644 index 0000000000..4c77c3c940 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp @@ -0,0 +1,55 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D720 + void WildlifeState::floodFillZoneProximityFromCell(int cellX, int cellY, int strength) + { + this->candidateIndex2 = 1; + this->casDisRelated = 1; + this->DAT_X10_Array_Section1034[0] = (short)cellX; + this->DAT_Y10_Array_Section1034[0] = (short)cellY; + this->candidateIndex = 0; + this->grid[cellX][cellY].unknownNonZero01 = strength; + while (this->candidateIndex != this->candidateIndex2) { + cellX = this->DAT_X10_Array_Section1034[this->candidateIndex]; + cellY = this->DAT_Y10_Array_Section1034[this->candidateIndex]; + this->casDisRelated = this->grid[cellX][cellY].unknownNonZero01; + if (this->casDisRelated <= 1) { + break; + } + int const level = this->casDisRelated - 1; + for (int direction = 0; direction < 8; direction++) { + uint const neighbourX + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + + cellX; + uint const neighbourY + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + + cellY; + if (neighbourX > 39 || neighbourY > 39 || this->grid[neighbourX][neighbourY].firstMember <= 0 + || this->grid[neighbourX][neighbourY].unclaimedArea > 10 + || this->grid[neighbourX][neighbourY].unknownNonZero01 >= level) { + continue; + } + this->grid[neighbourX][neighbourY].unknownNonZero01 = level; + this->DAT_X10_Array_Section1034[this->candidateIndex2] = (short)neighbourX; + this->DAT_Y10_Array_Section1034[this->candidateIndex2] = (short)neighbourY; + this->candidateIndex2 = this->candidateIndex2 + 1; + if (this->candidateIndex2 >= 1600) { + this->candidateIndex2 = 0; + } + } + this->candidateIndex = this->candidateIndex + 1; + if (this->candidateIndex >= 1600) { + this->candidateIndex = 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp new file mode 100644 index 0000000000..ba31ff8c20 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp @@ -0,0 +1,28 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D620 + BOOLEnum WildlifeState::hasAdjacentCellWithField24Or25(int param_1, int param_2) + { + // the four cardinal directions + for (int direction = 0; direction < 8; direction += 2) { + uint const x + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + param_1; + uint const y + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + param_2; + if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 + && (this->grid[x][y].field_0x60 != 0 || this->grid[x][y].field_0x64 != 0)) { + return TRUE; + } + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp new file mode 100644 index 0000000000..ed5d5721ef --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp @@ -0,0 +1,36 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x0052D690 + BOOLEnum WildlifeState::isAttackStagingCandidateCell(int cellX, int cellY) + { + if (this->grid[cellX][cellY].unclaimedArea > 8) { + return FALSE; + } + if (this->grid[cellX][cellY].trees > 4) { + return FALSE; + } + if (this->grid[cellX][cellY].firstMember < 50) { + return FALSE; + } + // the four cardinal directions + for (int direction = 0; direction < 8; direction += 2) { + uint const x + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset + cellX; + uint const y + = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset + cellY; + if (x <= 39 && y <= 39 && this->grid[x][y].firstMember > 0 && this->grid[x][y].unknownNonZero01 != 0) { + return TRUE; + } + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp new file mode 100644 index 0000000000..914d97d89e --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp @@ -0,0 +1,333 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/COL_BLUE.hpp" +#include "OpenSHC/Globals/COL_BRIGHT_YELLOW.hpp" +#include "OpenSHC/Globals/COL_DARK_CYAN_GREY.hpp" +#include "OpenSHC/Globals/COL_DARK_GREEN.hpp" +#include "OpenSHC/Globals/COL_LIME.hpp" +#include "OpenSHC/Globals/COL_MODERATE_GREEN.hpp" +#include "OpenSHC/Globals/COL_RED.hpp" +#include "OpenSHC/Globals/COL_VERY_DARK_GREY.hpp" +#include "OpenSHC/Globals/COL_VIVID_BLUE.hpp" +#include "OpenSHC/Globals/COL_WHITE.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace Map { + + using Text::TextAlignment; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052BF40 + void WildlifeState::renderDebugDataMapData(int x, int y, int width, int height) + { + int const x1 = x + 2; + if (this->DAT_DebugDataMapDataDisplayType == 0) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Connect ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 1) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Chimps ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Farmland ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Humans ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Mankind ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Deer ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Route ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Panic ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Siege ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } else if (this->DAT_DebugDataMapDataDisplayType == 9) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + "Slink ", x1 + 420, y + 4, Text::TTA_LEFT, 0xffffff, 17, FALSE, 0); + } + // render the squares + for (int line = 0; line < 41; line++) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x1, y + line * 10, x1 + 400, y + line * 10, COL_WHITE::instance.shortValue); + } + for (int line = 0; line < 41; line++) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x1 + line * 10, y, x1 + line * 10, y + 400, COL_WHITE::instance.shortValue); + } + for (int row = 0; row < 40; row++) { + for (int column = 0; column < 40; column++) { + if (this->grid[column][row].firstMember <= 0) { + continue; + } + if (this->DAT_DebugDataMapDataDisplayType == 0) { + int const areaColour = this->grid[column][row].separateAreaID & 7; + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (areaColour == 1) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (areaColour == 2) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); + } else if (areaColour == 3) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_MODERATE_GREEN::instance.shortValue); + } else if (areaColour == 4) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); + } else if (areaColour == 5) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_CYAN_GREY::instance.shortValue); + } else if (areaColour == 6) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } else if (areaColour == 7) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VERY_DARK_GREY::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 1) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].chimps) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 2) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].farmFieldTiles) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_GREEN::instance.shortValue); + } else if (this->grid[column][row].rabbitCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].field_0x3c) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); + } else if (this->grid[column][row].field_0x50) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_DARK_CYAN_GREY::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 3) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].unstalkedUnitCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 4) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].unstalkedUnitCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].buildingTiles) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].field_0x34) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 5) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].unstalkedUnitCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].buildingTiles) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].lionCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); + } else if (this->grid[column][row].camelCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); + } else if (this->grid[column][row].deerCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_MODERATE_GREEN::instance.shortValue); + } else if (this->grid[column][row].field_0x34) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 6) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].deerCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].lionCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); + } else if (this->grid[column][row].field_0x3c) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); + } else if (this->grid[column][row].casDisRelated2) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); + } else if (this->grid[column][row].field_0x34) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 7) { + if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].field_0x48) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); + } else if (this->grid[column][row].deerCount) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].field_0x34) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 8) { + if (this->grid[column][row].field_0x60) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_WHITE::instance.shortValue); + } else if (this->grid[column][row].field_0x64) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLACK::instance.shortValue); + } else if (this->grid[column][row].castlebuildings) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BRIGHT_YELLOW::instance.shortValue); + } else if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else if (this->grid[column][row].unknownNonZero01) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); + } else if (this->grid[column][row].field_0x6c) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } else if (this->DAT_DebugDataMapDataDisplayType == 9) { + if (this->grid[column][row].field_0x74) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_RED::instance.shortValue); + } else if (this->grid[column][row].unknownNonZero01) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_VIVID_BLUE::instance.shortValue); + } else if (!this->grid[column][row].separateAreaID) { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_BLUE::instance.shortValue); + } else { + MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawColorBox, + DAT_PencilRenderCore::ptr)(x1 + column * 10 + 1, y + row * 10 + 1, x1 + column * 10 + 9, + y + row * 10 + 9, COL_LIME::instance.shortValue); + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp new file mode 100644 index 0000000000..fd1f651569 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp @@ -0,0 +1,109 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052E120 + void WildlifeState::updateNofFpoints() + { + uint const signX = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .x; + uint const signY = DAT_GameState::instance.mapAndTime + .signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4] + .y; + if (signX > 399 || signY > 399) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[signY * 400 + signX] == '\0') { + return; + } + int const separateAreaID + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[signY].addXgetTile + signX]; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillCasDisFromSignpost, this)(); + DAT_TroopValueState::instance.attackInfo.nof_fpoints = 0; + for (int i = 0; i < 100; i++) { + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][3] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][2] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][1] = 0; + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][0] = 0; + } + for (int gridY = 0, y = 5; y < 405; gridY++, y += 10) { + for (int gridX = 0; gridX < 40; gridX++) { + int const x = gridX * 10 + 5; + if (!this->grid[gridX][gridY].field_0x6c || this->grid[gridX][gridY].firstMember <= 0) { + continue; + } + int const areaID + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (separateAreaID != areaID || x < 0 || x > 399 || y < 0 || y > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == '\0') { + continue; + } + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][0] = (short)x; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][1] = (short)y; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][2] = 0; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][3] = (short)areaID; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4] + = (short)this->grid[gridX][gridY].field_0x70; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + = (short)this->grid[gridX][gridY].casDisRelated2; + DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][6] + = (DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][5] + + 4) + * 50 + - DAT_TroopValueState::instance.attackInfo + .nof_fpointsArray[DAT_TroopValueState::instance.attackInfo.nof_fpoints][4]; + DAT_TroopValueState::instance.attackInfo.nof_fpoints + = DAT_TroopValueState::instance.attackInfo.nof_fpoints + 1; + } + } + BOOL swapped; + do { + swapped = FALSE; + for (int i = 0; i < DAT_TroopValueState::instance.attackInfo.nof_fpoints - 1; i++) { + if (DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1][6] + < DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i][6]) { + swapped = TRUE; + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i], + DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1], + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i]); + MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(16, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArrayCopy, + DAT_TroopValueState::instance.attackInfo.nof_fpointsArray[i + 1]); + } + } + } while (swapped); + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp new file mode 100644 index 0000000000..8470e2eb37 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp @@ -0,0 +1,52 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052E020 + void WildlifeState::updateSection1034Info() + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + // the volatile read keeps the pass counter counting up in its stack slot; a plain `pass++` lets MSVC + // reverse the unused counter into a count-down loop, which the original does not do + for (int pass = 0; pass < 20; pass = *(int volatile*)&pass + 1) { + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; 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) + != 0) { + this->grid[x][y].field_0x64 = this->grid[x][y].field_0x64 + 1; + } + } + } + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; 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 < 40; y++) { + for (int x = 0; x < 40; x++) { + if (this->grid[x][y].unknownNonZero01 == 0 + && MACRO_CALL_MEMBER(Map::WildlifeState_Func::isAttackStagingCandidateCell, this)(x, y) != 0) { + this->grid[x][y].field_0x6c = this->grid[x][y].field_0x6c + 1; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp new file mode 100644 index 0000000000..f1bd01b239 --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateWildlife.cpp @@ -0,0 +1,53 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052DF30 + void WildlifeState::updateWildlife() + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + this->grid[x][y].field_0x34 = 0; + this->grid[x][y].field_0x50 = 0; + this->grid[x][y].field_0x60 = 0; + this->grid[x][y].field_0x64 = 0; + this->grid[x][y].field_0x70 = this->grid[x][y].field_0x70 / 100; + if (this->grid[x][y].chimps) { + if (this->grid[x][y].keeps) { + this->grid[x][y].field_0x60 = 1; + } + if (this->grid[x][y].castlebuildings) { + this->grid[x][y].field_0x60 = this->grid[x][y].field_0x60 + 1; + } + } + } + } + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 40; x++) { + if (this->grid[x][y].unstalkedUnitCount) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 2); + } else if (this->grid[x][y].buildingTiles) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 2); + } else if (this->grid[x][y].lionCount) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField13FromCell, this)(x, y, 3); + } + if (this->grid[x][y].farmFieldTiles) { + MACRO_CALL_MEMBER(Map::WildlifeState_Func::floodFillField20FromCell, this)(x, y, 6); + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp new file mode 100644 index 0000000000..1a0cd30ecb --- /dev/null +++ b/src/OpenSHC/Map/WildlifeState/updateWildlifeGrid.cpp @@ -0,0 +1,238 @@ +#include "../../Map.func.hpp" +#include "../WildlifeState.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Trees/TreeType.hpp" +#include "OpenSHC/Map/Trees/TreeTypeShort.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode; + using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; + using Map::Trees::TreeType; + using Map::Trees::TreeTypeShort; + using Map::Units::UnitType; + using Map::Units::UnitTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x0052BA10 + void WildlifeState::updateWildlifeGrid(int _y10) + { + int const tileY10 = _y10 * 10; + // indexed by player ID, slot 0 unused + int campgroundAreaIDs[9]; + for (int playerID = 1; playerID < 9; playerID++) { + campgroundAreaIDs[playerID] = -1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1) { + campgroundAreaIDs[playerID] + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry]; + } + } + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + return; + } + for (int x = 0; x < 400; x += 10) { + int const gridX = x / 10; + this->grid[gridX][_y10].firstMember = 0; + this->grid[gridX][_y10].separateAreaID = 0; + this->grid[gridX][_y10].unclaimedArea = 0; + this->grid[gridX][_y10].buildingTiles = 0; + this->grid[gridX][_y10].keeps = 0; + this->grid[gridX][_y10].wallTiles = 0; + this->grid[gridX][_y10].trees = 0; + this->grid[gridX][_y10].unitCount = 0; + this->grid[gridX][_y10].unstalkedUnitCount = 0; + this->grid[gridX][_y10].stalkedUnitCount = 0; + this->grid[gridX][_y10].camelCount = 0; + this->grid[gridX][_y10].lionCount = 0; + this->grid[gridX][_y10].deerCount = 0; + this->grid[gridX][_y10].rabbitCount = 0; + this->grid[gridX][_y10].marshTiles = 0; + this->grid[gridX][_y10].rockyTiles = 0; + this->grid[gridX][_y10].field_0x48 = 0; + this->grid[gridX][_y10].farmFieldTiles = 0; + this->grid[gridX][_y10].chimps = 0; + this->grid[gridX][_y10].castlebuildings = 0; + this->grid[gridX][_y10].field_0x70 = 0; + int areaCounts[100][2]; + for (int k = 0; k < 100; k++) { + areaCounts[k][0] = -1; + areaCounts[k][1] = 0; + } + for (int dy = 0; dy < 10; dy++) { + // the volatile read keeps the row from being strength-reduced across the dy loop, as in the original + int const row = *(int volatile*)&dy; + uint const tileY = row + tileY10; + for (int dx = 0; dx < 10; dx++) { + uint const tileX = dx + x; + if (tileX > 399 || tileY > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] == '\0') { + continue; + } + this->grid[gridX][_y10].firstMember = this->grid[gridX][_y10].firstMember + 1; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + dx + x; + int const areaID = (short)DAT_TileMapState::instance.PathConnectionLayer[tile]; + if (areaID == 0) { + this->grid[gridX][_y10].unclaimedArea = this->grid[gridX][_y10].unclaimedArea + 1; + } + for (int k = 0; k < 100; k++) { + if (areaCounts[k][0] == areaID) { + areaCounts[k][1] = areaCounts[k][1] + 1; + break; + } + if (areaCounts[k][0] == -1) { + areaCounts[k][0] = areaID; + areaCounts[k][1] = 1; + break; + } + } + if (areaID != 0) { + for (int playerID = 1; playerID < 9; playerID++) { + if (areaID == campgroundAreaIDs[playerID]) { + this->grid[gridX][_y10].chimps = this->grid[gridX][_y10].chimps + 1; + } + } + } + this->grid[gridX][_y10].field_0x70 + = this->grid[gridX][_y10].field_0x70 + DAT_TileMapState::instance.HeightLayer[tile]; + uint const logic = DAT_TileMapState::instance.LogicLayer[tile]; + if (logic & 0x100) { + this->grid[gridX][_y10].wallTiles = this->grid[gridX][_y10].wallTiles + 1; + this->grid[gridX][_y10].castlebuildings = this->grid[gridX][_y10].castlebuildings + 1; + } + if (logic & 0x20000000) { + this->grid[gridX][_y10].marshTiles = this->grid[gridX][_y10].marshTiles + 1; + } + if (logic & 0x20000) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; + } + if (logic & 0x80) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; + } + if (logic & 0x40000) { + this->grid[gridX][_y10].rockyTiles = this->grid[gridX][_y10].rockyTiles + 1; + } + if (logic & 0x1000000) { + this->grid[gridX][_y10].farmFieldTiles = this->grid[gridX][_y10].farmFieldTiles + 1; + } + if (logic & 0x2000000) { + this->grid[gridX][_y10].farmFieldTiles = this->grid[gridX][_y10].farmFieldTiles + 1; + } + int const treeID = DAT_TileMapState::instance.OrganismLayer[tile]; + if (treeID > 0 && treeID < 2000) { + TreeTypeShort const treeType = DAT_LandscapeState::instance.trees[treeID].treeType; + if (treeType == (TreeType)1 || treeType == (TreeType)2 || treeType == (TreeType)3 + || treeType == (TreeType)4) { + this->grid[gridX][_y10].trees = this->grid[gridX][_y10].trees + 1; + } + } + int const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_MANORHOUSE) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_STONEKEEP) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_STRONGHOLD) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_KEEPFOUR) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_KEEPFIVE) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_CAMPGROUND) { + this->grid[gridX][_y10].keeps = this->grid[gridX][_y10].keeps + 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_GATEHOUSELARGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_GATEHOUSESMALL + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_WOODGATE1 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_WOODGATE2 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_DRAWBRIDGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER1 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER2 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER3 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER4 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == Map::Buildings::BT_TOWER5) { + this->grid[gridX][_y10].castlebuildings = this->grid[gridX][_y10].castlebuildings + 1; + } + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + != Map::Buildings::BT_SIGNPOST) { + this->grid[gridX][_y10].buildingTiles = this->grid[gridX][_y10].buildingTiles + 1; + } + } + int const unitID = DAT_TileMapState::instance.UnitLayer[tile]; + if (unitID == 0) { + continue; + } + this->grid[gridX][_y10].unitCount = this->grid[gridX][_y10].unitCount + 1; + if (DAT_UnitsState::instance.units[unitID].isStalked != 0) { + this->grid[gridX][_y10].stalkedUnitCount = this->grid[gridX][_y10].stalkedUnitCount + 1; + UnitTypeShort const unitType = DAT_UnitsState::instance.units[unitID].unitType; + if (unitType == Map::Units::UT_ANTELOPESHDEER) { + this->grid[gridX][_y10].deerCount = this->grid[gridX][_y10].deerCount + 1; + if (DAT_TribesState::instance.tribes[DAT_UnitsState::instance.units[unitID].tribeID] + .predatorNearby + != 0) { + this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; + } + } else if (unitType == Map::Units::UT_RABBIT) { + this->grid[gridX][_y10].rabbitCount = this->grid[gridX][_y10].rabbitCount + 1; + } else if (unitType == Map::Units::UT_CAMELSHBEAR) { + this->grid[gridX][_y10].camelCount = this->grid[gridX][_y10].camelCount + 1; + } else if (unitType == Map::Units::UT_LIONSHWOLF) { + this->grid[gridX][_y10].lionCount = this->grid[gridX][_y10].lionCount + 1; + } + } else { + this->grid[gridX][_y10].unstalkedUnitCount = this->grid[gridX][_y10].unstalkedUnitCount + 1; + this->grid[gridX][_y10].field_0x48 = this->grid[gridX][_y10].field_0x48 + 1; + } + } + } + int separateAreaID = 0; + int bestCount = 0; + for (int k = 0; k < 100; k++) { + if (areaCounts[k][0] == -1) { + break; + } + if (areaCounts[k][1] > bestCount) { + separateAreaID = areaCounts[k][0]; + bestCount = areaCounts[k][1]; + } + } + this->grid[gridX][_y10].separateAreaID = separateAreaID; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..5511b10064 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38317,7 +38317,7 @@ SHC_3BB0A8C1_0x004F1C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F1C60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F1CE0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F1CE0 | 89.6% | Tile sum computed straight into edi; the original builds it in ebx and copies, which shifts the jump table SHC_3BB0A8C1_0x004F1FDC | 0.0% | Pending @@ -38383,7 +38383,7 @@ SHC_3BB0A8C1_0x004F2070 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F20E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2140 | 0.0% | Pending +SHC_3BB0A8C1_0x004F2140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F2220 | 100.0% | Reimplemented @@ -38571,7 +38571,7 @@ SHC_3BB0A8C1_0x004F3080 | 0.0% | Pending SHC_3BB0A8C1_0x004F30D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F3150 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3150 | 98.3% | Register allocation of two loads SHC_3BB0A8C1_0x004F3180 | 0.0% | Pending @@ -38593,7 +38593,7 @@ SHC_3BB0A8C1_0x004F3900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3960 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3960 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending @@ -49235,23 +49235,23 @@ SHC_3BB0A8C1_0x0052B9E8 | 0.0% | Pending SHC_3BB0A8C1_0x0052B9F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052BA10 | 0.0% | Pending +SHC_3BB0A8C1_0x0052BA10 | 87.5% | ebx/ebp swap between the shared zero constant and tile (tile is colored first and takes ebx on the tie) SHC_3BB0A8C1_0x0052BB40 | 0.0% | Pending SHC_3BB0A8C1_0x0052BEA0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052BF40 | 0.0% | Pending +SHC_3BB0A8C1_0x0052BF40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052C570 | 0.0% | Pending +SHC_3BB0A8C1_0x0052C570 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C5D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052C810 | 0.0% | Pending +SHC_3BB0A8C1_0x0052C810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052C870 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CAB0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052CAB0 | 96.1% | x/cell slot swap SHC_3BB0A8C1_0x0052CBB0 | 0.0% | Pending @@ -49259,7 +49259,7 @@ SHC_3BB0A8C1_0x0052CD40 | 0.0% | Pending SHC_3BB0A8C1_0x0052CD60 | 0.0% | Pending -SHC_3BB0A8C1_0x0052CFE0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052CFE0 | 98.0% | param_2 copy scheduling SHC_3BB0A8C1_0x0052D090 | 0.0% | Pending @@ -49269,15 +49269,15 @@ SHC_3BB0A8C1_0x0052D100 | 0.0% | Pending SHC_3BB0A8C1_0x0052D3C0 | 0.0% | Pending -SHC_3BB0A8C1_0x0052D620 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D620 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052D690 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D690 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052D720 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052D780 | 0.0% | Pending -SHC_3BB0A8C1_0x0052D9D0 | 0.0% | Pending +SHC_3BB0A8C1_0x0052D9D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052DA40 | 0.0% | Pending @@ -49291,15 +49291,15 @@ SHC_3BB0A8C1_0x0052DDF0 | 0.0% | Pending SHC_3BB0A8C1_0x0052DF10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0052DF30 | 0.0% | Pending +SHC_3BB0A8C1_0x0052DF30 | 100.0% | Reimplemented 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 +SHC_3BB0A8C1_0x0052E120 | 86.6% | Binary-map base folded into the y*400 induction variable; this kept in esi across the flood-fill call SHC_3BB0A8C1_0x0052E1A0 | 0.0% | Pending