diff --git a/src/OpenSHC/Map/Entities/AFireSpreadFunction.cpp b/src/OpenSHC/Map/Entities/AFireSpreadFunction.cpp new file mode 100644 index 0000000000..53bcfef91a --- /dev/null +++ b/src/OpenSHC/Map/Entities/AFireSpreadFunction.cpp @@ -0,0 +1,74 @@ +#include "../Entities.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004054E0 + void Entities::AFireSpreadFunction(int playerID, int x, int y, int height, int fireStrength, int fireIntensity) + { + int const random = SEC_RNG::instance.currentNumber2; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + x += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[random & 0x3f][0]; + y += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[random & 0x3f][1]; + uint const tileX = x / 8; + uint const tileY = y / 8; + if (tileX > 399 || tileY > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] == 0) { + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX; + int const fireID + = MACRO_CALL_MEMBER(Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(tile); + if (fireID != 0) { + DAT_EntityState::instance.entityArray[fireID].someTracker = 0; + if (fireStrength > DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6) { + DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6 = fireStrength; + } + DAT_EntityState::instance.entityArray[fireID].unknownAnimationFrameRelated = 0; + return; + } + if (DAT_TileMapState::instance.LogicLayer[tile] + & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE | LogicHelpers::L_ROCKY + | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD + | LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP + | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_KEEP_NON_MANOR_HOUSE)) { + return; + } + short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID != 0 + && !MACRO_CALL_MEMBER(Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( + buildingID, playerID, fireIntensity)) { + return; + } + if ((DAT_TileMapState::instance.LogicLayer[tile] & LogicHelpers::L_TREE) + && !MACRO_CALL_MEMBER(LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID)) { + return; + } + uint const newFireID = MACRO_CALL_MEMBER(Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, playerID, 0, x, y, height, 0, 0, 0, Entities::ET_FIRE, 0); + if (newFireID != 0) { + DAT_EntityState::instance.entityArray[newFireID].fireParameter_0xb6 = fireStrength; + DAT_EntityState::instance.entityArray[newFireID].fireIntensity = fireIntensity; + } + if (fireStrength >= 3 && (DAT_TileMapState::instance.RandomLayer[tile] & 3) == 0) { + MACRO_CALL_MEMBER(Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( + 0, playerID, 0, x, y, height, 0, 0, 0, Entities::EntityTypeInt__ET_EXPLOSION, 0); + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/drawEntityEffect.cpp b/src/OpenSHC/Map/Entities/EntityState/drawEntityEffect.cpp new file mode 100644 index 0000000000..f0bc2e0773 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/drawEntityEffect.cpp @@ -0,0 +1,32 @@ +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00401380 + void EntityState::drawEntityEffect(int entityID, undefined4 entityType, int graphicType1, int graphicType2) + { + this->entityArray[entityID].entityType = (EntityTypeShort)entityType; + this->entityArray[entityID].graphicType2 = graphicType2; + this->entityArray[entityID].gmID = (short)graphicType1; + this->entityArray[entityID].originX + = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[(short)graphicType1] + .originX; + this->entityArray[entityID].originY + = (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[(short)graphicType1] + .originY; + this->entityArray[entityID].unkOne_1 = (short)DAT_EntityDefinedData::instance.field_0x8b0; + this->entityArray[entityID].unkThree_1 = (short)DAT_EntityDefinedData::instance.field_0x7f8; + if (graphicType1 == 135) { + this->entityArray[entityID].unkOne_1 = 1; + this->entityArray[entityID].unkThree_1 = 3; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeSeagullMovementVector.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeSeagullMovementVector.cpp new file mode 100644 index 0000000000..5a3c3cc16f --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/initializeSeagullMovementVector.cpp @@ -0,0 +1,67 @@ +#include "../EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00403790 + void EntityState::initializeSeagullMovementVector(int seagullID, int x, int y, int targetX, int targetY) + { + int distanceY; + if (y > targetY) { + distanceY = y - targetY; + } else { + distanceY = targetY - y; + } + int distanceX; + if (x > targetX) { + distanceX = x - targetX; + } else { + distanceX = targetX - x; + } + if (x > targetX) { + this->seagullArray[seagullID].pathStepX = -1; + } else { + this->seagullArray[seagullID].pathStepX = 1; + } + if (y > targetY) { + this->seagullArray[seagullID].pathStepY = -1; + } else { + this->seagullArray[seagullID].pathStepY = 1; + } + if (distanceX == 0) { + if (distanceY == 0) { + this->seagullArray[seagullID].pathAxisCase = 0; + } else { + this->seagullArray[seagullID].pathAxisCase = 1; + } + } else if (distanceY == 0) { + this->seagullArray[seagullID].pathAxisCase = 2; + } else if (distanceY > distanceX) { + this->seagullArray[seagullID].pathAxisCase = 3; + } else { + this->seagullArray[seagullID].pathAxisCase = 4; + } + int majorLength; + if (distanceX > distanceY) { + majorLength = distanceX; + } else { + majorLength = distanceY; + } + this->seagullArray[seagullID].pathMajorLength = majorLength; + if (this->seagullArray[seagullID].pathAxisCase == 3) { + int const errorStep = distanceX * 2; + this->seagullArray[seagullID].pathErrorStepStraight = errorStep; + this->seagullArray[seagullID].pathErrorStepDiagonal = errorStep - distanceY * 2; + this->seagullArray[seagullID].pathError = errorStep - distanceY; + } else if (this->seagullArray[seagullID].pathAxisCase == 4) { + int const errorStep = distanceY * 2; + this->seagullArray[seagullID].pathErrorStepStraight = errorStep; + this->seagullArray[seagullID].pathErrorStepDiagonal = errorStep - distanceX * 2; + this->seagullArray[seagullID].pathError = errorStep - distanceX; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/setEntityParameters.cpp b/src/OpenSHC/Map/Entities/EntityState/setEntityParameters.cpp new file mode 100644 index 0000000000..8bc7479767 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/setEntityParameters.cpp @@ -0,0 +1,35 @@ +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004012F0 + void EntityState::setEntityParameters(int entityID, undefined4 entityType, int gmLookupValue) + { + this->entityArray[entityID].entityType = (EntityTypeShort)entityType; + this->entityArray[entityID].gmLookupValue = (short)gmLookupValue; + this->entityArray[entityID].gmID = (short)DAT_EntityDefinedData::instance.EntityGmIDs[gmLookupValue]; + this->entityArray[entityID].graphicType2RelatedOffset + = (short)DAT_EntityDefinedData::instance.EntityGraphicOffsets[gmLookupValue]; + this->entityArray[entityID].originX = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID] + .originX; + this->entityArray[entityID].originY = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID] + .originY; + this->entityArray[entityID].unkOne_1 = (short)DAT_EntityDefinedData::instance.field_0x8a4[gmLookupValue]; + this->entityArray[entityID].unkThree_1 = (short)DAT_EntityDefinedData::instance.field_0x7ec[gmLookupValue]; + if (gmLookupValue == 1) { + this->entityArray[entityID].unkThree_1 = 5; + this->entityArray[entityID].unkOne_1 = 3; + this->entityArray[entityID].unkMinusOne = 16; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/setProjectileEntityValues2.cpp b/src/OpenSHC/Map/Entities/EntityState/setProjectileEntityValues2.cpp new file mode 100644 index 0000000000..9ae111fe80 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/setProjectileEntityValues2.cpp @@ -0,0 +1,63 @@ +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004011D0 + void EntityState::setProjectileEntityValues2(int entityID, EntityType entityType) + { + this->entityArray[entityID].entityType = (EntityTypeShort)entityType; + this->entityArray[entityID].gmID = (short)DAT_EntityDefinedData::instance.EntityPropertyArray_1[entityType]; + this->entityArray[entityID].graphicType2RelatedOffset + = (short)DAT_EntityDefinedData::instance.EntityPropertyArray_2[entityType]; + this->entityArray[entityID].originX = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID] + .originX; + this->entityArray[entityID].originY = (short)DAT_TextureRenderCoreObject::instance + .gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID] + .originY; + this->entityArray[entityID].unkOne_1 + = (short)DAT_EntityDefinedData::instance.EntityPropertyArray_3[entityType]; + int const curveType = DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[entityType]; + if (curveType != 0 && curveType != 6 && curveType != 9) { + this->entityArray[entityID].startingAngle + = (short)DAT_EntityDefinedData::instance.EntityArrayProjectileVelocityForProjectileType[entityType]; + } else { + this->entityArray[entityID].velocityUnk + = (short)DAT_EntityDefinedData::instance.EntityArrayProjectileVelocityForProjectileType[entityType]; + } + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + = DAT_EntityDefinedData::instance.ProjectileGravityPerEntityType[entityType]; + this->entityArray[entityID].field_0x5a + = (short)DAT_EntityDefinedData::instance.field_0x2ac[entityType - 10]; + this->entityArray[entityID].gmLookupValue + = (short)DAT_EntityDefinedData::instance.field_0x75c[entityType - 10]; + switch (entityType) { + case 11: + this->entityArray[entityID].originX += -1; + this->entityArray[entityID].originY += -2; + break; + case 12: + this->entityArray[entityID].originX += 8; + this->entityArray[entityID].originY += -8; + break; + case 13: + this->entityArray[entityID].originX += 8; + this->entityArray[entityID].originY += -7; + break; + case 10: + case 14: + case 15: + this->entityArray[entityID].originX += -1; + this->entityArray[entityID].originY += -7; + break; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/setProjectileTargetPosition.cpp b/src/OpenSHC/Map/Entities/EntityState/setProjectileTargetPosition.cpp new file mode 100644 index 0000000000..fd37c81c5e --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/setProjectileTargetPosition.cpp @@ -0,0 +1,36 @@ +#include "../EntityState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00405CF0 + void EntityState::setProjectileTargetPosition( + int entityID, int x, int y, int height, int targetX, int targetY, int targetZ) + { + this->entityArray[entityID].microX = x; + this->entityArray[entityID].x_2 = x; + this->entityArray[entityID].microY = y; + this->entityArray[entityID].y_2 = y; + this->entityArray[entityID].height = height; + this->entityArray[entityID].startingHeight_2 = height; + this->entityArray[entityID].height_2 = height; + this->entityArray[entityID].startingHeight = height; + this->entityArray[entityID].targetX = targetX; + this->entityArray[entityID].targetY = targetY; + this->entityArray[entityID].targetZ = targetZ; + this->entityArray[entityID].heightDifference = targetZ - height; + MACRO_CALL_MEMBER(Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, + DAT_DirectionAlgorithmState::ptr)(x, y, targetX, targetY); + this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; + MACRO_CALL_MEMBER(EntityState_Func::initializeProjectileVelocities, this)( + entityID, x, y, height, targetX, targetY, targetZ); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntityMicroMovement.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntityMicroMovement.cpp new file mode 100644 index 0000000000..fd0631d9ec --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntityMicroMovement.cpp @@ -0,0 +1,49 @@ +#include "../EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402AE0 + void EntityState::updateEntityMicroMovement(int entityID) + { + if (this->entityArray[entityID].entityType == 29 && this->entityArray[entityID].targetZ == 0 + && this->entityArray[entityID].microX == this->entityArray[entityID].targetX + && this->entityArray[entityID].microY == this->entityArray[entityID].targetY) { + return; + } + switch (this->entityArray[entityID].pathAxisCase) { + case 0: + return; + case 2: + this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX; + break; + case 1: + this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY; + break; + case 4: + if (this->entityArray[entityID].pathError > 0) { + this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX; + this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY; + this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepDiagonal; + } else { + this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX; + this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepStraight; + } + break; + case 3: + if (this->entityArray[entityID].pathError > 0) { + this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX; + this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY; + this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepDiagonal; + } else { + this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY; + this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepStraight; + } + break; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateArrowEntity.cpp b/src/OpenSHC/Map/Entities/UpdateArrowEntity.cpp new file mode 100644 index 0000000000..eabc732445 --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateArrowEntity.cpp @@ -0,0 +1,32 @@ +#include "../Entities.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00401BA0 + void Entities::UpdateArrowEntity() + { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rotationFrameIndex * 16 + + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset + + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].screenDirection; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround != 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround -= 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_2 != 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround = 0; + } + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround <= 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7; + } + } + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation == 76) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation = 60; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7; + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateCrossbowArrowEntity.cpp b/src/OpenSHC/Map/Entities/UpdateCrossbowArrowEntity.cpp new file mode 100644 index 0000000000..dc6c53bb1c --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateCrossbowArrowEntity.cpp @@ -0,0 +1,29 @@ +#include "../Entities.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00401DB0 + void Entities::UpdateCrossbowArrowEntity() + { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rotationFrameIndex * 16 + + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset + + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].screenDirection; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround != 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround -= 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround <= 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7; + } + } + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation == 76) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation = 60; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7; + } + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/findTree.cpp b/src/OpenSHC/Map/LandscapeState/findTree.cpp new file mode 100644 index 0000000000..0e5c647c82 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/findTree.cpp @@ -0,0 +1,78 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3B90 + int LandscapeState::findTree(int playerID, uint unitXPosition, uint unitYPosition) + { + bool const onMap = unitXPosition <= 399 && unitYPosition <= 399 + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[unitYPosition * 400 + unitXPosition] != 0; + if (!onMap) { + return 0; + } + int closestDistance = 10000; + int closestTreeID = 0; + int const unitArea + = (short)DAT_TileMapState::instance + .PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[unitYPosition].addXgetTile + + unitXPosition]; + if (unitArea <= 0) { + return 0; + } + for (int treeID = 1; treeID < this->maxTreeCount; ++treeID) { + if (this->trees[treeID].stage >= 4) { + continue; + } + if (this->trees[treeID].state != 2) { + continue; + } + if (!MACRO_CALL_MEMBER(LandscapeState_Func::isTreeAdult, this)(treeID, this->trees[treeID].uid)) { + continue; + } + int const treeHeight = DAT_TileMapState::instance.HeightLayer[this->trees[treeID].tile]; + int direction = 0; + for (; direction < 8; ++direction) { + int const tile + = DAT_TileMapState::instance.directionTranslationMatrix[this->trees[treeID].yPosition][direction] + + this->trees[treeID].tile; + int height = DAT_TileMapState::instance.HeightLayer[tile]; + if (DAT_TileMapState::instance.BuildingLayer[tile] != 0) { + height += MACRO_CALL_MEMBER(Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer[tile]); + } + if (treeHeight > height + 16 || treeHeight < height - 16) { + continue; + } + if (MACRO_CALL_MEMBER(Navigation::PathFindingState_Func::calculateCanPlayerUnitsNavigateToAreaFromArea, + DAT_PathFindingState::ptr)( + playerID, unitArea, (short)DAT_TileMapState::instance.PathConnectionLayer[tile], 0)) { + break; + } + } + if (direction >= 8) { + continue; + } + MACRO_CALL_MEMBER( + Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, DAT_DirectionAlgorithmState::ptr)( + unitXPosition, unitYPosition, this->trees[treeID].xPosition, this->trees[treeID].yPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < closestDistance) { + closestDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + closestTreeID = treeID; + } + } + return closestTreeID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp b/src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp new file mode 100644 index 0000000000..0b4cfc5cd0 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp @@ -0,0 +1,39 @@ +#include "../LandscapeState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F1BE0 + undefined4 LandscapeState::getValueFrom0UpTo3ForTreeTypeAndTreeStage(undefined4 treeType, int treeStage) + { + if (treeStage <= 1) { + return 1; + } + switch (treeType) { + case 1: + return 3; + case 2: + return 3; + case 3: + return 2; + case 4: + return 2; + case 5: + return 1; + case 6: + return 1; + case 7: + return 1; + case 8: + return 1; + case 9: + return 1; + case 15: + return 2; + default: + return 0; + } + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/placeAppleTree.cpp b/src/OpenSHC/Map/LandscapeState/placeAppleTree.cpp new file mode 100644 index 0000000000..19b45c236a --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/placeAppleTree.cpp @@ -0,0 +1,37 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3560 + void LandscapeState::placeAppleTree(int buildingID, undefined4 treeX, undefined4 treeY) + { + int const treeID = MACRO_CALL_MEMBER(LandscapeState_Func::createTree, DAT_LandscapeState::ptr)( + treeX, treeY, Trees::TT_APPLEUnk, 1, 0, 0, 0); + if (treeID == 0) { + return; + } + DAT_LandscapeState::instance.trees[treeID].appleFarmID = (short)buildingID; + DAT_LandscapeState::instance.trees[treeID].appleFarmUID + = DAT_BuildingsState::instance.buildings[buildingID].uid; + DAT_LandscapeState::instance.trees[treeID].stageTracker + = DAT_LandscapeState::instance.trees[treeID].rng1 & 0x1f; + DAT_TileMapState::instance.LogicLayer[DAT_LandscapeState::instance.trees[treeID].tile] |= 0x1000; + DAT_TileMapState::instance.OrganismLayer[DAT_LandscapeState::instance.trees[treeID].tile] = (short)treeID; + MACRO_CALL_MEMBER(TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)(treeID, 0); + MACRO_CALL_MEMBER( + Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, DAT_PathFindingState::ptr)( + DAT_LandscapeState::instance.trees[treeID].yPosition, DAT_LandscapeState::instance.trees[treeID].tile); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/selectClosestAppleTree.cpp b/src/OpenSHC/Map/LandscapeState/selectClosestAppleTree.cpp new file mode 100644 index 0000000000..948140aca8 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/selectClosestAppleTree.cpp @@ -0,0 +1,48 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3610 + int LandscapeState::selectClosestAppleTree(int xPosition, int yPosition, int param_3) + { + int closestDistance = 1000; + int closestTreeID = 0; + for (int treeID = 1; treeID < this->maxTreeCount; ++treeID) { + if (this->trees[treeID].state == 2 && this->trees[treeID].treeType == Trees::TT_APPLEUnk + && this->trees[treeID].stage == 3) { + MACRO_CALL_MEMBER(Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)( + xPosition, yPosition, this->trees[treeID].xPosition, this->trees[treeID].yPosition); + if (DAT_DirectionAlgorithmState::instance.distanceHigh < closestDistance) { + closestDistance = DAT_DirectionAlgorithmState::instance.distanceHigh; + closestTreeID = treeID; + } + } + } + if (closestDistance >= 30) { + return 0; + } + if (closestTreeID <= 0) { + return 0; + } + this->x = this->trees[closestTreeID].xPosition; + this->y = this->trees[closestTreeID].yPosition; + if (param_3 == 0) { + this->x -= 2; + } else if (param_3 == 1) { + this->y += 2; + } else if (param_3 == 2) { + this->x += 2; + } else { + this->y -= 2; + } + return closestTreeID; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/setupBabyTreeLocation.cpp b/src/OpenSHC/Map/LandscapeState/setupBabyTreeLocation.cpp new file mode 100644 index 0000000000..436a6da085 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/setupBabyTreeLocation.cpp @@ -0,0 +1,86 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F2E00 + BOOLEnum LandscapeState::setupBabyTreeLocation(uint treeID, int treeType, uint x, uint y) + { + int direction = (byte)SEC_RNG::instance.currentNumber2 & 7; + int climbValueUnk = 3; + if (treeID & 1) { + climbValueUnk = 4; + } + DAT_PathFindingState::instance.ALG_ResultTile = 0; + DAT_PathFindingState::instance.ALG_ResultY = 0; + DAT_PathFindingState::instance.ALG_ResultX = 0; + bool const onMap + = x <= 399 && y <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] != 0; + if (!onMap) { + return FALSE; + } + int const height = DAT_TileMapState::instance + .HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + for (int i = 0; i < 8; ++i) { + uint const babyX = DAT_OrganismDefinedData::instance.TreeSpreadOffsets[direction].x + x; + uint const babyY = DAT_OrganismDefinedData::instance.TreeSpreadOffsets[direction].y + y; + direction += 1; + if (direction >= 8) { + direction = 0; + } + if (babyX > 399 || babyY > 399 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[babyY * 400 + babyX] == 0) { + continue; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[babyY].addXgetTile + babyX; + int const logic2 = DAT_TileMapState::instance.Logic2Layer[tile]; + if (DAT_TileMapState::instance.OrganismLayer[tile] != 0) { + continue; + } + if (DAT_TileMapState::instance.LogicLayer[tile] + & (LogicHelpers::L_SEA | LogicHelpers::L_PLAIN1_AND_FARM | LogicHelpers::L_BORDER + | LogicHelpers::L_BORDER_EDGE | LogicHelpers::L_ROCKY | LogicHelpers::L_WALL_OR_GATEHOUSE + | LogicHelpers::L_BUILDING | LogicHelpers::L_TREE_VARIATION | LogicHelpers::L_BOULDERS + | LogicHelpers::L_PEBBLES | LogicHelpers::L_IRON | LogicHelpers::L_RIVER | LogicHelpers::L_FORD + | LogicHelpers::L_KEEP_NON_MANOR_HOUSE | LogicHelpers::L_MARSH | LogicHelpers::L_MOAT)) { + continue; + } + if (DAT_TileMapState::instance.UnitLayer[tile] != 0) { + continue; + } + if (DAT_TileMapState::instance.BuildingLayer[tile] != 0) { + continue; + } + if (treeType == 1) { + if (logic2 & 0x90) { + continue; + } + } else if (!(logic2 & 0x90)) { + continue; + } + int const babyHeight = DAT_TileMapState::instance.HeightLayer[tile]; + if (babyHeight > height + 64 || babyHeight < height - 64) { + continue; + } + if (MACRO_CALL_MEMBER(Navigation::PathFindingState_Func::setupBabyTreeLocationInfo, + DAT_PathFindingState::ptr)(climbValueUnk, treeType, babyX, babyY)) { + DAT_PathFindingState::instance.ALG_ResultTile = tile; + DAT_PathFindingState::instance.ALG_ResultX = babyX; + DAT_PathFindingState::instance.ALG_ResultY = babyY; + return TRUE; + } + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/updateTrees.cpp b/src/OpenSHC/Map/LandscapeState/updateTrees.cpp new file mode 100644 index 0000000000..3c1482c296 --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/updateTrees.cpp @@ -0,0 +1,107 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_00ed31a0.hpp" +#include "OpenSHC/Globals/DAT_CurrentTreeID.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3D60 + void LandscapeState::updateTrees() + { + BOOLEnum updateStages = FALSE; + uint stageRng = 0; + DAT_GameState::instance.mapAndTime.burningTreeCount = 0; + DAT_00ed31a0::instance = timeGetTime(); + if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 8) { + this->maxTreeCount = 0; + for (DAT_CurrentTreeID::instance = 1; (int)DAT_CurrentTreeID::instance < 2000; + DAT_CurrentTreeID::instance += 1) { + if (this->trees[DAT_CurrentTreeID::instance].state != 0) { + this->maxTreeCount = DAT_CurrentTreeID::instance + 1; + } + } + } + if (DAT_GameState::instance.gameTicksLoadBalancer % 8 == 4) { + updateStages = TRUE; + stageRng = (byte)SEC_RNG::instance.currentNumber2 & 0x3f; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_EDITOR) { + updateStages = FALSE; + } + this->field_0x0 = 0; + if (DAT_TileMapState::instance.refreshRelatedOne == 0 || DAT_TileMapState::instance.flatViewToggleValue1 != 0) { + this->field_0x0 = 1; + } + DAT_GameState::instance.mapAndTime.newOrganisms = 0; + this->DAT_TotalOrganisms = 0; + for (DAT_CurrentTreeID::instance = 1; (int)DAT_CurrentTreeID::instance < this->maxTreeCount; + DAT_CurrentTreeID::instance += 1) { + switch (this->trees[DAT_CurrentTreeID::instance].state) { + case 0: + break; + case 1: + this->trees[DAT_CurrentTreeID::instance].state = 2; + break; + case 4: + if (this->field_0x0 != 0) { + this->trees[DAT_CurrentTreeID::instance].animationFrameUnk = 0; + } else { + this->trees[DAT_CurrentTreeID::instance].animationFrameUnk + = this->trees[DAT_CurrentTreeID::instance].animationFrame2Unk; + } + break; + case 3: + MACRO_CALL_MEMBER(LandscapeState_Func::removeTree, this)(DAT_CurrentTreeID::instance); + break; + case 2: + default: { + this->DAT_TotalOrganisms += 1; + if ((this->trees[DAT_CurrentTreeID::instance].yPosition & 0x1f) >= this->wind.countdown) { + this->trees[DAT_CurrentTreeID::instance].one = this->wind.value; + } + if (this->trees[DAT_CurrentTreeID::instance].one == 3 + && this->trees[DAT_CurrentTreeID::instance].zeroUpTo2 == 0) { + this->trees[DAT_CurrentTreeID::instance].zeroUpTo2 = 1; + this->trees[DAT_CurrentTreeID::instance].animationFrameIndex = 1; + this->trees[DAT_CurrentTreeID::instance].field_0x14 = DAT_00ed31a0::instance; + } + if ((int)(DAT_00ed31a0::instance - this->trees[DAT_CurrentTreeID::instance].field_0x14) + >= this->trees[DAT_CurrentTreeID::instance].treeTypeRelated2) { + this->trees[DAT_CurrentTreeID::instance].field_0x14 = DAT_00ed31a0::instance; + if (this->trees[DAT_CurrentTreeID::instance].one != 0) { + this->trees[DAT_CurrentTreeID::instance].animationFrameIndex += 1; + } + } + if (this->trees[DAT_CurrentTreeID::instance].rng200till300 != 0) { + this->trees[DAT_CurrentTreeID::instance].rng200till300 -= 1; + } + if (updateStages) { + // createTree inside updateTreeStage overwrites the current tree ID + int const savedTreeID = DAT_CurrentTreeID::instance; + MACRO_CALL_MEMBER(LandscapeState_Func::updateTreeStage, this)( + DAT_CurrentTreeID::instance, stageRng); + DAT_CurrentTreeID::instance = savedTreeID; + } + DAT_OrganismDefinedData::instance.UpdateTree[this->trees[DAT_CurrentTreeID::instance].treeType](); + if (this->trees[DAT_CurrentTreeID::instance].field_0x98 != 0) { + if (this->trees[DAT_CurrentTreeID::instance].treeType != Trees::TT_APPLEUnk) { + DAT_GameState::instance.mapAndTime.burningTreeCount += 1; + } + if (this->trees[DAT_CurrentTreeID::instance].field_0x98 > 1) { + this->trees[DAT_CurrentTreeID::instance].field_0x98 -= 1; + } + } + break; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/LandscapeState/updateWind.cpp b/src/OpenSHC/Map/LandscapeState/updateWind.cpp new file mode 100644 index 0000000000..5c759f69bf --- /dev/null +++ b/src/OpenSHC/Map/LandscapeState/updateWind.cpp @@ -0,0 +1,34 @@ +#include "../LandscapeState.func.hpp" + +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F3730 + void LandscapeState::updateWind() + { + this->wind.counter += 1; + if (this->wind.counter >= 2) { + this->wind.counter = 0; + this->wind.countdown -= 1; + this->wind.valueIs2 = 0; + this->wind.valueIs1 = 0; + if (this->wind.countdown < 0) { + this->wind.countdown = 32; + this->wind.value = DAT_OrganismDefinedData::instance.WindRelatedArray[this->wind.index]; + if (this->wind.value == 2) { + this->wind.valueIs2 = 1; + } else if (this->wind.value == 1) { + this->wind.valueIs1 = 1; + } + this->wind.index += 1; + if (this->wind.index >= 40) { + this->wind.index = 0; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/activateScenarioTypeEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/activateScenarioTypeEvents.cpp new file mode 100644 index 0000000000..82367aeeec --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/activateScenarioTypeEvents.cpp @@ -0,0 +1,23 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B7930 + void MapPropertiesState::activateScenarioTypeEvents() + { + for (int i = 0; i < DAT_MapPropertiesState::instance.eventsCount; ++i) { + if (DAT_MapPropertiesState::instance.scenarioEvents[i].header.tl_type == 3) { + int const eventType + = DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.ScenarioEventType; + if (eventType == 1 || eventType == 27 || eventType == 0 || eventType == 26) { + DAT_MapPropertiesState::instance.scenarioEvents[i].header.done = 1; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/commitBuildingAvailability.cpp b/src/OpenSHC/Map/MapPropertiesState/commitBuildingAvailability.cpp new file mode 100644 index 0000000000..bcd588ca4d --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/commitBuildingAvailability.cpp @@ -0,0 +1,50 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BAEC0 + void MapPropertiesState::commitBuildingAvailability() + { + for (int i = 0; i < 380; ++i) { + this->buildingAvailabilityRelatedFlags[i] = 1; + } + for (int i = 0; i < 10; ++i) { + this->buildingAvailabilityArray2[i] = 1; + } + for (int i = 10; i < 49; ++i) { + this->buildingAvailabilityArray2[i] = 0; + } + int row = 0; + for (; + DAT_MissionAestheticsDefinedData::instance.BuildingNameRelatedStructArray[row].nameNumberInTextGroup != -1; + ++row) { + int const available = this->buildingAvailability[row] != 0; + // the three sub entries are read as one list of nine IDs after the name number + for (int i = 1; i < 10; ++i) { + int const id + = ((int const*)&DAT_MissionAestheticsDefinedData::instance.BuildingNameRelatedStructArray[row])[i]; + if (id > 0) { + this->buildingAvailabilityRelatedFlags[id] = available; + } else if (id < 0) { + if (available) { + this->buildingAvailabilityArray2[-id] = available; + } + } else { + break; + } + } + } + this->buildingAvailabilityRowCount = row - 2; + this->buildingAvailabilityArray2[10] = 1; + this->buildingAvailabilityArray2[20] = 1; + this->buildingAvailabilityArray2[30] = 1; + this->buildingAvailabilityArray2[40] = 1; + this->buildingAvailabilityArray2[25] = 1; + this->buildingAvailabilityArray2[28] = 1; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/determineScenarioMissionTypeAndResetEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/determineScenarioMissionTypeAndResetEvents.cpp new file mode 100644 index 0000000000..c3c0ff734a --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/determineScenarioMissionTypeAndResetEvents.cpp @@ -0,0 +1,62 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B7980 + void MapPropertiesState::determineScenarioMissionTypeAndResetEvents() + { + BOOLEnum hasAttackers = FALSE; + BOOLEnum hasScenarioGoal = FALSE; + for (int i = 0; i < this->eventsCount; ++i) { + switch (this->scenarioEvents[i].header.tl_type) { + case 1: + hasAttackers = TRUE; + break; + case 3: { + int const scenarioEventType = this->scenarioEvents[i].data.scenario.ScenarioEventType; + if (scenarioEventType >= 0 && (scenarioEventType <= 1 || scenarioEventType == 26)) { + hasScenarioGoal = TRUE; + } + break; + } + } + } + for (int i = 1; i < 2500; ++i) { + if (DAT_UnitsState::instance.units[i].logicalState != 0 && DAT_UnitsState::instance.units[i].owner > 1) { + hasAttackers = TRUE; + break; + } + } + if (this->SEC_U3_MapType2_1 == 0) { + for (int i = 0; i < 20; ++i) { + if (this->SEC_SiegeInformation[i] != 0) { + hasAttackers = TRUE; + break; + } + } + for (int i = 0; i < 6; ++i) { + if (this->SEC_Section1067.siegeEngineCounts[i] != 0) { + hasAttackers = TRUE; + break; + } + } + } + if (hasAttackers) { + this->scenarionMissionType = (this->SEC_U3_MapType2_1 != 0) + 2; + } else { + this->scenarionMissionType = hasScenarioGoal != FALSE; + } + DAT_GameState::instance.mapAndTime.month = this->SEC_StartingMonth; + DAT_GameState::instance.mapAndTime.year = this->SEC_StartingYear; + for (int i = 0; i < this->eventsCount; ++i) { + this->scenarioEvents[i].header.done = 0; + this->scenarioEvents[i].header.pre_done = 0; + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/getDifficultyMultipliedValue.cpp b/src/OpenSHC/Map/MapPropertiesState/getDifficultyMultipliedValue.cpp new file mode 100644 index 0000000000..24a8ca24dc --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/getDifficultyMultipliedValue.cpp @@ -0,0 +1,22 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B7AB0 + int MapPropertiesState::getDifficultyMultipliedValue(int value) + { + if (DAT_GameCore::instance.gameMode_2 == 0 && DAT_GameCore::instance.missionNumber1to20 == 8) { + return value; + } + return DAT_MissionAestheticsDefinedData::instance + .DifficultyEventMultipliers[DAT_GameState::instance.mapAndTime.difficulty] + * value / 100; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/getEventIDForTimeUntilDefeatEventType.cpp b/src/OpenSHC/Map/MapPropertiesState/getEventIDForTimeUntilDefeatEventType.cpp new file mode 100644 index 0000000000..edc867ba7c --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/getEventIDForTimeUntilDefeatEventType.cpp @@ -0,0 +1,28 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B78D0 + int MapPropertiesState::getEventIDForTimeUntilDefeatEventType() + { + if (DAT_GameCore::instance.gameMode_2 != 0 && DAT_GameCore::instance.gameMode_2 != 5 + && DAT_GameCore::instance.gameMode_2 != 2) { + return -1; + } + for (int i = 0; i < DAT_MapPropertiesState::instance.eventsCount; ++i) { + if (DAT_MapPropertiesState::instance.scenarioEvents[i].header.tl_type == 3 + && (DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.ScenarioEventType == 1 + || DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.ScenarioEventType == 27) + && DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.conditions[0].enabled != 0) { + return i; + } + } + return -1; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/isMapperAvailable.cpp b/src/OpenSHC/Map/MapPropertiesState/isMapperAvailable.cpp new file mode 100644 index 0000000000..c8e23b0e04 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/isMapperAvailable.cpp @@ -0,0 +1,45 @@ +#include "../MapPropertiesState.func.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" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BB010 + BOOLEnum MapPropertiesState::isMapperAvailable(MappersEnum mapper) + { + if ((mapper == 178 || mapper == 179) && DAT_GameCore::instance.gameMode_2 != 1) { + return FALSE; + } + if (DAT_GameCore::instance.gameMode_2 == 1 && DAT_GameCore::instance.U2_mapType_singleOrMulti >= 1) { + if (mapper == 60 || (mapper > 61 && mapper <= 64)) { + return FALSE; + } + return TRUE; + } + if (DAT_GameCore::instance.gameMode_2 == 1) { + return TRUE; + } + if (mapper == 312) { + if (DAT_GameSynchronyState::instance.currentGameMode != 0 + && DAT_GameSynchronyState::instance.currentGameMode != 99 + && DAT_GameState::instance.mapAndTime.skirmishNoDogs != 0) { + return FALSE; + } + } else if (mapper == 78) { + if (DAT_GameSynchronyState::instance.currentGameMode != 0 + && DAT_GameState::instance.mapAndTime.rawDeerCount == 0) { + return FALSE; + } + } + return (BOOLEnum)this->buildingAvailabilityRelatedFlags[mapper]; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderSections.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderSections.cpp new file mode 100644 index 0000000000..14a8c99aa9 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderSections.cpp @@ -0,0 +1,35 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/IO/FilePackager.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" + +#include "OpenSHC/Globals/DAT_MapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/FilePackagerObj.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004C3110 + void MapPropertiesState::loadMapSiegeHeaderSections(char* mapName) + { + MACRO_CALL_MEMBER(IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + IO::FRT_MAPS, mapName); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapHeaderSectionByID, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray, 1063); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapHeaderSectionByID, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray, 1062); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapHeaderSectionByID, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray, 1064); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapHeaderSectionByID, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray, 1056); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapHeaderSectionByID, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray, 1057); + if (FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk < 154) { + MACRO_CALL_MEMBER(MapPropertiesState_Func::removeProcessedInvasionEvents, DAT_MapPropertiesState::ptr)(); + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/pruneInvalidEventTriggerLinks.cpp b/src/OpenSHC/Map/MapPropertiesState/pruneInvalidEventTriggerLinks.cpp new file mode 100644 index 0000000000..76b979a24b --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/pruneInvalidEventTriggerLinks.cpp @@ -0,0 +1,26 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BB990 + void MapPropertiesState::pruneInvalidEventTriggerLinks() + { + for (int i = 0; i < this->eventsCount; ++i) { + if (this->scenarioEvents[i].header.tl_type == 3 + && DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.conditions[0].enabled != 0) { + for (int condition = 1; condition < 40; ++condition) { + if (DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.conditions[condition].enabled + != 0) { + DAT_MapPropertiesState::instance.scenarioEvents[i].data.scenario.conditions[0].enabled = 0; + break; + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/removeEventAtIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/removeEventAtIndex.cpp new file mode 100644 index 0000000000..0bb2b5399a --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/removeEventAtIndex.cpp @@ -0,0 +1,16 @@ +#include "../MapPropertiesState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BA8B0 + void MapPropertiesState::removeEventAtIndex(int index) + { + this->eventsCount -= 1; + for (int i = index; i < this->eventsCount; ++i) { + memcpy(&this->scenarioEvents[i], &this->scenarioEvents[i + 1], sizeof(this->scenarioEvents[i])); + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/removeProcessedInvasionEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/removeProcessedInvasionEvents.cpp new file mode 100644 index 0000000000..3d94510fb3 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/removeProcessedInvasionEvents.cpp @@ -0,0 +1,36 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Map/ScenarioEventConditionsCopy.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004C1320 + void MapPropertiesState::removeProcessedInvasionEvents() + { + for (int i = 0; i < this->eventsCount; ++i) { + if (this->scenarioEvents[i].header.tl_type != 3) { + continue; + } + ScenarioEventConditionsCopy copy; + memcpy(©, &this->scenarioEvents[i], sizeof(copy)); + for (int condition = 0; condition < countof(this->scenarioEvents[i].data.scenario.conditions); + ++condition) { + this->scenarioEvents[i].data.scenario.conditions[condition].enabled = 0; + this->scenarioEvents[i].data.scenario.conditions[condition].value = 0; + this->scenarioEvents[i].data.scenario.conditions[condition].subType = 0; + } + for (int condition = 0; condition < 20; ++condition) { + this->scenarioEvents[i].data.scenario.conditions[condition].enabled + = (byte)copy.conditions[condition].value; + this->scenarioEvents[i].data.scenario.conditions[condition].value + = copy.conditions[condition + 20].value; + this->scenarioEvents[i].data.scenario.conditions[condition].subType + = copy.conditions[condition + 20].subType; + } + } + MACRO_CALL_MEMBER(MapPropertiesState_Func::pruneInvalidEventTriggerLinks, this)(); + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/resetEuroUnitRestrictions.cpp b/src/OpenSHC/Map/MapPropertiesState/resetEuroUnitRestrictions.cpp new file mode 100644 index 0000000000..50563fd99d --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/resetEuroUnitRestrictions.cpp @@ -0,0 +1,31 @@ +#include "../MapPropertiesState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BB900 + void MapPropertiesState::resetEuroUnitRestrictions() + { + for (int i = 0; i < this->eventsCount; ++i) { + switch (this->scenarioEvents[i].header.tl_type) { + case 1: + if (this->scenarioEvents[i].data.invasion.repeatMonths != 0) { + this->scenarioEvents[i].data.invasion.repeatMonths *= 12; + } + break; + } + } + this->SEC_XbowProducible_save = 1; + this->SEC_BowProducible_save = 1; + this->SEC_PikeProducible_save = 1; + this->SEC_SpearProducible_save = 1; + this->SEC_SwordProducible_save = 1; + this->SEC_MaceProducible_save = 1; + for (int i = 0; i < 7; ++i) { + this->barracksRecruitability.array.barracksRecruitability[i] = 1; + this->SEC_MercRecruitable[i] = 1; + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/sortEventsByDate.cpp b/src/OpenSHC/Map/MapPropertiesState/sortEventsByDate.cpp new file mode 100644 index 0000000000..89e1b28fd0 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/sortEventsByDate.cpp @@ -0,0 +1,30 @@ +#include "../MapPropertiesState.func.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::ScenarioEvents::IngameEventHeader; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BA7D0 + void MapPropertiesState::sortEventsByDate() + { + for (int pass = 0; pass < this->eventsCount - 1; ++pass) { + for (int i = 0; i < this->eventsCount - pass - 1; ++i) { + IngameEventHeader const& current = this->scenarioEvents[i].header; + IngameEventHeader const& next = this->scenarioEvents[i + 1].header; + if (current.year > next.year + || (current.year == next.year + && (current.month > next.month + || (current.month == next.month && current.tl_type > next.tl_type)))) { + // an int buffer: a copy of the event type itself would get a /GS cookie the original does not have + int swap[sizeof(InGameEventUnionVersion) / sizeof(int)]; + memcpy(&swap, &this->scenarioEvents[i], sizeof(swap)); + memcpy(&this->scenarioEvents[i], &this->scenarioEvents[i + 1], sizeof(swap)); + memcpy(&this->scenarioEvents[i + 1], &swap, sizeof(swap)); + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnAttackWaveForPlayer.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnAttackWaveForPlayer.cpp new file mode 100644 index 0000000000..82bffb2883 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/spawnAttackWaveForPlayer.cpp @@ -0,0 +1,230 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Units::UnitType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BC1C0 + void MapPropertiesState::spawnAttackWaveForPlayer( + int playerID, int unitType1, int unitCount1, int unitType2, int unitCount2, undefined4 spawnParameterUnk) + { + int const signpostCount = DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter; + int signpostIndex = 0; + DAT_TroopValueState::instance.attackInfo.inv_count += 1; + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER(Units::TroopValueState_Func::initializeAttackWaveSlot, DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, 0); + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] = (byte)playerID; + // fixme: an unknown unit type leaves these uninitialized (the original happens to hold the player ID) + int tribeType; + int unitType; + int groupSizeDivisor; + for (int group = 0; group < 2; ++group) { + int requestedUnitType; + int unitCount; + if (group == 0) { + requestedUnitType = unitType1; + unitCount = unitCount1; + } else { + if (unitType2 <= 0) { + return; + } + requestedUnitType = unitType2; + unitCount = unitCount2; + } + switch (requestedUnitType) { + case 22: + tribeType = 3; + unitType = 22; + groupSizeDivisor = 10; + break; + case 23: + tribeType = 7; + unitType = 23; + groupSizeDivisor = 10; + break; + case 24: + tribeType = 5; + unitType = 24; + groupSizeDivisor = 10; + break; + case 25: + tribeType = 6; + unitType = 25; + groupSizeDivisor = 10; + break; + case 26: + tribeType = 9; + unitType = 26; + groupSizeDivisor = 10; + break; + case 27: + tribeType = 8; + unitType = 27; + groupSizeDivisor = 10; + break; + case 28: + tribeType = 10; + unitType = 28; + groupSizeDivisor = 10; + break; + case 29: + tribeType = 4; + unitType = 29; + groupSizeDivisor = 10; + break; + case 30: + tribeType = 11; + unitType = 30; + groupSizeDivisor = 10; + break; + case 39: + tribeType = 22; + unitType = 39; + groupSizeDivisor = 10; + break; + case 40: + tribeType = 23; + unitType = 40; + groupSizeDivisor = 10; + break; + case 59: + tribeType = 19; + unitType = 59; + groupSizeDivisor = 10; + break; + case 58: + tribeType = 20; + unitType = 58; + groupSizeDivisor = 10; + break; + case 60: + tribeType = 21; + unitType = 60; + groupSizeDivisor = 10; + break; + case 37: + tribeType = 12; + unitType = 37; + groupSizeDivisor = 10; + break; + case 5: + tribeType = 2; + unitType = 5; + groupSizeDivisor = 10; + break; + case 70: + tribeType = 25; + unitType = 70; + groupSizeDivisor = 10; + break; + case 71: + tribeType = 26; + unitType = 71; + groupSizeDivisor = 20; + break; + case 72: + tribeType = 27; + unitType = 72; + groupSizeDivisor = 20; + break; + case 73: + tribeType = 28; + unitType = 73; + groupSizeDivisor = 2; + break; + case 74: + tribeType = 29; + unitType = 74; + groupSizeDivisor = 10; + break; + case 75: + tribeType = 30; + unitType = 75; + groupSizeDivisor = 8; + break; + case 76: + tribeType = 31; + unitType = 76; + groupSizeDivisor = 4; + break; + case 77: + tribeType = 24; + unitType = 77; + groupSizeDivisor = 10; + break; + } + int difficultyPercent = 100; + switch (DAT_GameState::instance.mapAndTime.difficulty) { + case 0: + difficultyPercent = 50; + break; + case 2: + difficultyPercent = 140; + break; + case 3: + difficultyPercent = 200; + break; + } + int remaining = difficultyPercent * unitCount / 100; + if (tribeType == 22) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][0] += remaining; + } else if (tribeType == 23) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][1] += remaining; + } else if (tribeType == 19) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][2] += remaining; + } else if (tribeType == 20) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][3] += remaining; + } else if (tribeType == 21) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][4] += remaining; + } else if (tribeType == 24) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][8] += remaining; + } else { + int groupSize = remaining / (remaining / groupSizeDivisor + 1); + // a while loop: as a for loop with the subtraction as its step, the sub moves after the signpost update + while (remaining > 0) { + if (groupSize > remaining) { + groupSize = remaining; + } + MACRO_CALL_MEMBER(Units::TribesState_Func::spawnUnitsForAITribe, DAT_TribesState::ptr)( + (AI::Tribes::AITribeType)tribeType, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]] + [signpostIndex] + .x, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]] + [signpostIndex] + .y, + playerID, (UnitType)unitType, groupSize, spawnParameterUnk); + remaining -= groupSize; + signpostIndex += 1; + if (signpostIndex >= signpostCount) { + signpostIndex = 0; + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/sumUnitCounts.cpp b/src/OpenSHC/Map/MapPropertiesState/sumUnitCounts.cpp new file mode 100644 index 0000000000..3a2cfce151 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/sumUnitCounts.cpp @@ -0,0 +1,21 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B8000 + int MapPropertiesState::sumUnitCounts() + { + int sum = 0; + for (int i = 0; i < 25; ++i) { + sum += DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.invasion.unitCountsPerUnitType[i]; + } + this->DAT_InvasionEventItemUnitCountSum = sum; + return sum; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/sumUnitPoints.cpp b/src/OpenSHC/Map/MapPropertiesState/sumUnitPoints.cpp new file mode 100644 index 0000000000..0f88c9fa86 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/sumUnitPoints.cpp @@ -0,0 +1,23 @@ +#include "../MapPropertiesState.func.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B7FA0 + int MapPropertiesState::sumUnitPoints() + { + // the siege unit counts are summed as one array of 20 ints + int const* const unitCounts = (int const*)&this->SEC_SiegeInformation; + int sum = 0; + for (int i = 0; i < 20; ++i) { + sum += unitCounts[i]; + } + sum += this->SEC_Section1067.siegeEngineCounts[5] + this->SEC_Section1067.siegeEngineCounts[4] + + this->SEC_Section1067.siegeEngineCounts[3] + this->SEC_Section1067.siegeEngineCounts[2] + + this->SEC_Section1067.siegeEngineCounts[1] + this->SEC_Section1067.siegeEngineCounts[0]; + this->DAT_MapEditorUnitPointsSum = sum; + return sum; + } + +} +} diff --git a/src/OpenSHC/Map/ResetSomeValuesFunctionUnk.cpp b/src/OpenSHC/Map/ResetSomeValuesFunctionUnk.cpp new file mode 100644 index 0000000000..1a86096f02 --- /dev/null +++ b/src/OpenSHC/Map/ResetSomeValuesFunctionUnk.cpp @@ -0,0 +1,71 @@ +#include "../Map.func.hpp" + +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" +#include "OpenSHC/Globals/TIME_LastThanksBikPlaybackTime.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00431990 + void ResetSomeValuesFunctionUnk() + { + DAT_GameCore::instance.isBinkVideoPlaying = 0; + DAT_BuildingsState::instance.DAT_IsBuildingOrPeasantBinkPlaying = FALSE; + DAT_BuildingsState::instance.selectedBuildingID = 0; + DAT_BuildingsState::instance.selectedBuildingUID = 0; + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_PLAYER_INFO_ON_HOVER, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_WIN_DEFEAT_WINDOW, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_UNKNOWN_25, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_SOME_MULTIPLAYER_INFO_Unk_19, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_VICTORY, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_DEFEAT, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_SOME_MULTIPLAYER_INFO_Unk_28, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_PEOPLE_LEFT_TO_PLACE, 0); + if (DAT_MenuModalComposition2::instance.activeModalDialogID == UI::Enums::MMT_DISPLAY_AI_LORD_MESSAGE) { + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition2::ptr)( + UI::Enums::MMT_NONE, FALSE); + } + DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; + DAT_GameCore::instance.section1076 = 0; + DAT_TileMapState::instance.currentMapperCommand = Commands::M_MAPPER_NULL; + DAT_GameCore::instance.gamePausedLogical = 0; + MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, DAT_MouseState::ptr)(); + DAT_GameCore::instance.viewportFocusBeforeBarracksHotkey = -1; + DAT_GameCore::instance.viewportFocusBeforeMercenaryHotkey = -1; + DAT_GameCore::instance.viewportFocusBeforeGranaryHotkey = -1; + DAT_GameCore::instance.viewportFocusBeforeMarketHotkey = -1; + DAT_GameCore::instance.viewportFocusBeforeKeepHotkey = -1; + DAT_GameCore::instance.viewportFocusBeforeArmoryHotkey = -1; + DAT_BuildingsState::instance.siegeEngineCreationRelated01 = 0; + DAT_MinimapViewState::instance.spawnMomentCount = 0; + DAT_GameCore::instance.viewedKeepIndex = 0; + DAT_GameCore::instance.section1095 = 0; + DAT_GameCore::instance.solitaryAltUDungeon = FALSE; + TIME_LastThanksBikPlaybackTime::instance = 0; + } + +} +} diff --git a/src/OpenSHC/Map/Trees/UpdateTree5.cpp b/src/OpenSHC/Map/Trees/UpdateTree5.cpp new file mode 100644 index 0000000000..033650931a --- /dev/null +++ b/src/OpenSHC/Map/Trees/UpdateTree5.cpp @@ -0,0 +1,43 @@ +#include "../Trees.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentTreeID.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F2640 + void Trees::UpdateTree5() + { + if (DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].flag) { + if ((char)DAT_OrganismDefinedData::instance + .Tree_1_B[DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex] + <= 0) { + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex = 0; + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].flag + = DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].one == 2; + } + } else if ((char)DAT_OrganismDefinedData::instance + .Tree_1_A[DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex] + <= 0) { + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex = 0; + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].flag + = DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].one == 2; + } + if (DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].flag) { + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameUnk + = (char)DAT_OrganismDefinedData::instance + .Tree_1_B[DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex]; + } else { + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameUnk + = (char)DAT_OrganismDefinedData::instance + .Tree_1_A[DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameIndex]; + } + if (DAT_LandscapeState::instance.field_0x0 != 0) { + DAT_LandscapeState::instance.trees[DAT_CurrentTreeID::instance].animationFrameUnk = 0; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3a97b43162..fd26faa353 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -397,7 +397,7 @@ SHC_3BB0A8C1_0x00401120 | 0.0% | Pending SHC_3BB0A8C1_0x00401150 | 0.0% | Pending -SHC_3BB0A8C1_0x004011D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004011D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004012CC | 0.0% | Pending @@ -411,9 +411,9 @@ SHC_3BB0A8C1_0x004012DC | 0.0% | Pending SHC_3BB0A8C1_0x004012E0 | 0.0% | Pending -SHC_3BB0A8C1_0x004012F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004012F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00401380 | 0.0% | Pending +SHC_3BB0A8C1_0x00401380 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00401400 | 100.0% | Reimplemented @@ -451,7 +451,7 @@ SHC_3BB0A8C1_0x00401B20 | 0.0% | Pending SHC_3BB0A8C1_0x00401B60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00401BA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00401BA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00401C30 | 0.0% | Pending @@ -461,7 +461,7 @@ SHC_3BB0A8C1_0x00401D20 | 0.0% | Pending SHC_3BB0A8C1_0x00401D70 | 0.0% | Pending -SHC_3BB0A8C1_0x00401DB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00401DB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00401E20 | 0.0% | Pending @@ -505,7 +505,7 @@ SHC_3BB0A8C1_0x00402A20 | 0.0% | Pending SHC_3BB0A8C1_0x00402AB0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402AE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00402AE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00402BBC | 0.0% | Pending @@ -529,7 +529,7 @@ SHC_3BB0A8C1_0x00403200 | 0.0% | Pending SHC_3BB0A8C1_0x004036F0 | 0.0% | Pending -SHC_3BB0A8C1_0x00403790 | 0.0% | Pending +SHC_3BB0A8C1_0x00403790 | 100.0% | Pending SHC_3BB0A8C1_0x004038A0 | 100.0% | Reimplemented @@ -1697,7 +1697,7 @@ SHC_3BB0A8C1_0x004054D4 | 0.0% | Pending SHC_3BB0A8C1_0x004054D5 | 0.0% | Pending -SHC_3BB0A8C1_0x004054E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004054E0 | 100.0% | Pending SHC_3BB0A8C1_0x00405680 | 0.0% | Pending @@ -1705,7 +1705,7 @@ SHC_3BB0A8C1_0x00405B70 | 0.0% | Pending SHC_3BB0A8C1_0x00405C00 | 0.0% | Pending -SHC_3BB0A8C1_0x00405CF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00405CF0 | 100.0% | Pending SHC_3BB0A8C1_0x00405DA0 | 0.0% | Pending @@ -11075,7 +11075,7 @@ SHC_3BB0A8C1_0x00431989 | 0.0% | Pending SHC_3BB0A8C1_0x0043198A | 0.0% | Pending -SHC_3BB0A8C1_0x00431990 | 0.0% | Pending +SHC_3BB0A8C1_0x00431990 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00431A90 | 100.0% | Reimplemented @@ -27083,15 +27083,15 @@ SHC_3BB0A8C1_0x004B7800 | 0.0% | Pending SHC_3BB0A8C1_0x004B7890 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B78D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B78D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B7930 | 0.0% | Pending +SHC_3BB0A8C1_0x004B7930 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B7980 | 0.0% | Pending +SHC_3BB0A8C1_0x004B7980 | 100.0% | Pending SHC_3BB0A8C1_0x004B79A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004B7AB0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B7AB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B7AF0 | 100.0% | Reimplemented @@ -27099,9 +27099,9 @@ SHC_3BB0A8C1_0x004B7C90 | 0.0% | Pending SHC_3BB0A8C1_0x004B7F60 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B7FA0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B7FA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B8000 | 0.0% | Pending +SHC_3BB0A8C1_0x004B8000 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B8050 | 100.0% | Reimplemented @@ -29085,9 +29085,9 @@ SHC_3BB0A8C1_0x004BA5C0 | 0.0% | Pending SHC_3BB0A8C1_0x004BA780 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BA7D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BA7D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BA8B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BA8B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BA910 | 100.0% | Reimplemented @@ -29115,9 +29115,9 @@ SHC_3BB0A8C1_0x004BAE30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BAE80 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BAEC0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BAEC0 | 100.0% | Pending -SHC_3BB0A8C1_0x004BB010 | 0.0% | Pending +SHC_3BB0A8C1_0x004BB010 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BB0B0 | 100.0% | Reimplemented @@ -29311,9 +29311,9 @@ SHC_3BB0A8C1_0x004BB8F8 | 0.0% | Pending SHC_3BB0A8C1_0x004BB8FC | 0.0% | Pending -SHC_3BB0A8C1_0x004BB900 | 0.0% | Pending +SHC_3BB0A8C1_0x004BB900 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BB990 | 0.0% | Pending +SHC_3BB0A8C1_0x004BB990 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BB9F0 | 100.0% | Reimplemented @@ -29883,7 +29883,7 @@ SHC_3BB0A8C1_0x004BC104 | 0.0% | Pending SHC_3BB0A8C1_0x004BC110 | 0.0% | Pending -SHC_3BB0A8C1_0x004BC1C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BC1C0 | 100.0% | Pending SHC_3BB0A8C1_0x004BC4FC | 0.0% | Pending @@ -33189,7 +33189,7 @@ SHC_3BB0A8C1_0x004C0CF0 | 0.0% | Pending SHC_3BB0A8C1_0x004C1070 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C1320 | 0.0% | Pending +SHC_3BB0A8C1_0x004C1320 | 100.0% | Pending SHC_3BB0A8C1_0x004C1370 | 0.0% | Pending @@ -33899,7 +33899,7 @@ SHC_3BB0A8C1_0x004C2270 | 0.0% | Pending SHC_3BB0A8C1_0x004C2280 | 0.0% | Pending -SHC_3BB0A8C1_0x004C3110 | 0.0% | Pending +SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C31A0 | 0.0% | Pending @@ -38283,7 +38283,7 @@ SHC_3BB0A8C1_0x004F1BD3 | 0.0% | Pending SHC_3BB0A8C1_0x004F1BD4 | 0.0% | Pending -SHC_3BB0A8C1_0x004F1BE0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F1BE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F1C18 | 0.0% | Pending @@ -38445,7 +38445,7 @@ SHC_3BB0A8C1_0x004F262C | 0.0% | Pending SHC_3BB0A8C1_0x004F2630 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2640 | 0.0% | Pending +SHC_3BB0A8C1_0x004F2640 | 100.0% | Pending SHC_3BB0A8C1_0x004F26C0 | 0.0% | Pending @@ -38557,7 +38557,7 @@ SHC_3BB0A8C1_0x004F2CC0 | 0.0% | Pending SHC_3BB0A8C1_0x004F2DA0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F2E00 | 0.0% | Pending +SHC_3BB0A8C1_0x004F2E00 | 100.0% | Pending SHC_3BB0A8C1_0x004F2E90 | 0.0% | Pending @@ -38575,13 +38575,13 @@ SHC_3BB0A8C1_0x004F3150 | 0.0% | Pending SHC_3BB0A8C1_0x004F3180 | 0.0% | Pending -SHC_3BB0A8C1_0x004F3560 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3560 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3610 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3610 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3700 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3730 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3730 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F37B0 | 100.0% | Reimplemented @@ -38595,13 +38595,13 @@ SHC_3BB0A8C1_0x004F3930 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F3960 | 0.0% | Pending -SHC_3BB0A8C1_0x004F3B90 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3B90 | 100.0% | Pending SHC_3BB0A8C1_0x004F3C50 | 0.0% | Pending SHC_3BB0A8C1_0x004F3D30 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F3D60 | 0.0% | Pending +SHC_3BB0A8C1_0x004F3D60 | 100.0% | Pending SHC_3BB0A8C1_0x004F3DC0 | 0.0% | Pending