diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 17882af542..dc717a444f 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -448,8 +448,11 @@ src/OpenSHC/Map/Units/UpdateHunter.cpp src/OpenSHC/Map/Units/UpdateAppleFarmer.cpp src/OpenSHC/Map/Units/UpdateJester.cpp src/OpenSHC/Map/Units/UpdateSlave.cpp +src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp +src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp src/OpenSHC/Map/Units/UpdateHealer.cpp src/OpenSHC/Map/Units/UpdateSpearman.cpp +src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp src/OpenSHC/Map/Units/UpdateSlinger.cpp src/OpenSHC/Map/Units/UpdateWoodcutter.cpp src/OpenSHC/Map/Units/UpdateFletcher.cpp diff --git a/cmake/function-visibility.txt b/cmake/function-visibility.txt index 9349d9bb13..eb4fe06406 100644 --- a/cmake/function-visibility.txt +++ b/cmake/function-visibility.txt @@ -456,3 +456,5 @@ OpenSHC::Map::Units::UpdateFireBallista OpenSHC::Map::Units::UnitsState::deselectUnit OpenSHC::Map::Units::UpdateHorseArcher OpenSHC::Map::Units::UnitsState::hasUnitReachedDestination +OpenSHC::Map::Entities::IgniteFireAtMiniTile + OpenSHC::Map::Entities::EntityState::getFireEntityIDAtTile diff --git a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp new file mode 100644 index 0000000000..16b8aebd69 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp @@ -0,0 +1,44 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402BD0 + int EntityState::angleToRotationFrameIndex(int angle) + { + if (angle <= 5) { + if (angle <= -50) { + return 0; + } + if (angle <= -35) { + return 1; + } + if (angle <= -17) { + return 2; + } + if (angle <= -5) { + return 3; + } + } else { + if (angle <= 20) { + return 5; + } + if (angle <= 35) { + return 6; + } + if (angle <= 50) { + return 7; + } + if (angle <= 90) { + return 8; + } + } + return 4; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp new file mode 100644 index 0000000000..9302030f8b --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -0,0 +1,44 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004036F0 + void EntityState::calculateEntityDrawOffset(int entityID) + { + uint x = (byte)this->entityArray[entityID].microX & 7; + uint y = (byte)this->entityArray[entityID].microY & 7; + if (DAT_TileMapState::instance.mapOrientation == 4) { + x = 7 - x; + y = 7 - y; + } else { + if (DAT_TileMapState::instance.mapOrientation == 2) { + x = 7 - x; + goto rotate; + } + if (DAT_TileMapState::instance.mapOrientation == 6) { + y = 7 - y; + goto rotate; + } + if (DAT_TileMapState::instance.mapOrientation) { + rotate: + x = x << 4; + y = y * 2; + goto lookup; + } + } + x = x << 1; + y = y << 4; + lookup: + this->entityArray[entityID].x1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x].x; + this->entityArray[entityID].y1 = DAT_EntityDefinedData::instance.EntitySubTileDrawOffsets[y + x + 1].x; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp new file mode 100644 index 0000000000..3d3f1e226e --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp @@ -0,0 +1,280 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +#include + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402E20 + uint EntityState::computeLineOfSightDistance( + int x, int y, int height, int targetX, int targetY, int targetHeight, int param_7) + { + int lastTile = -1; + int building = -1; + int steps = 100000; + int lastHeight = 0; + int clearance = 0; + BOOL clear = TRUE; + BOOL blocked = FALSE; + if (height > targetHeight + 54) { + clearance = 100; + } + int curX = x; + int curY = y; + int const tileX = x / 8; + int const tileY = y / 8; + int const startTile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX; + if (DAT_TileMapState::instance.LogicLayer[startTile] & 0x10000000) { + height = height + 10; + } + if (DAT_TileMapState::instance.BuildingLayer[startTile] != 0) { + building = DAT_TileMapState::instance.BuildingLayer[startTile]; + } + int dY; + if (y > targetY) { + dY = y - targetY; + } else { + dY = targetY - y; + } + int dX; + if (x > targetX) { + dX = x - targetX; + } else { + dX = targetX - x; + } + int const stepX = x <= targetX ? 1 : -1; + int const stepY = y <= targetY ? 1 : -1; + int twoD; + int error; + int diagStep; + // Set-up and stepping are two separate dispatches; mode picks the stepping loop. + int mode; + if (dX == 0) { + if (dY != 0) { + if (clearance >= 28) { + clearance = 28; + } + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + mode = 0; + } else { + mode = 4; + } + } else if (dY != 0) { + if (dY > dX) { + twoD = dX * 2; + error = twoD - dY; + diagStep = twoD - dY * 2; + if (height > targetHeight && clearance != 0) { + int n = abs(targetY - y) / 8 - 1; + if (n > 4) { + n = 4; + } + for (int i = 1; i < n; i++) { + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)( + DAT_ViewportRenderState::instance.translationMatrix[targetY / 8 - stepY * i].addXgetTile + + targetX / 8, + 1); + if (lastHeight > targetHeight) { + clearance = 28; + } + } + } + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + mode = 1; + } else { + twoD = dY * 2; + diagStep = twoD - dX * 2; + error = twoD - dX; + if (height > targetHeight && clearance != 0) { + int n = abs(targetX - x) / 8 - 1; + if (n > 4) { + n = 4; + } + for (int i = 1; i < n; i++) { + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(targetX / 8 - stepX * i + + DAT_ViewportRenderState::instance.translationMatrix[targetY / 8].addXgetTile, + 1); + if (lastHeight > targetHeight) { + clearance = 28; + } + } + } + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + mode = 2; + } + } else { + if (clearance >= 28) { + clearance = 28; + } + this->lineOfSightClearanceSteps = clearance; + clearance = clearance / 2; + mode = 3; + } + + if (mode == 3) { + for (steps = 0; steps < 1000; steps++) { + curX += stepX; + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (curX == targetX && y == targetY) { + break; + } + } + } else if (mode == 0) { + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if ((steps & 1) && param_7 == 0) { + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile + tileX; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (x == targetX && curY == targetY) { + break; + } + } + } else if (mode == 2) { + for (steps = 0; steps < 1000; steps++) { + curX += stepX; + if (error > 0) { + curY += stepY; + error += diagStep; + } else { + error += twoD; + } + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (curX == targetX && curY == targetY) { + break; + } + } + } else if (mode == 1) { + for (steps = 0; steps < 1000; steps++) { + curY += stepY; + if (error > 0) { + curX += stepX; + error += diagStep; + } else { + error += twoD; + } + if ((steps & 1) && param_7 == 0) { + int const tile + = curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) { + clear = FALSE; + this->lineOfSightClearanceSteps = steps; + } + if (clearance != 0) { + clearance--; + } else if (lastTile != tile) { + blocked = FALSE; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + if ((flags & 0x80) != 0 + || (building != DAT_TileMapState::instance.BuildingLayer[tile] + && (!clear || !(flags & 0x400200)))) { + blocked = TRUE; + lastHeight = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1); + if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + } + } else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) { + return 0; + } + lastTile = tile; + } + if (curX == targetX && curY == targetY) { + break; + } + } + } + return steps; + } + + } // namespace Entities +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp new file mode 100644 index 0000000000..05b3b4d608 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -0,0 +1,382 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + + // FUNCTION: STRONGHOLDCRUSADER 0x00403FF0 + void EntityState::handleProjectileWallBounce(int param_1) + { + int const microY = this->entityArray[param_1].microY; + int const microX = this->entityArray[param_1].microX; + int subX = microX & 7; + int targetX = 0; + int targetY = 0; + int subY = microY & 7; + uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, + DAT_TileMapState::ptr)(microX / 8, microY / 8); + switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + break; + case 0x3d: + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { + case 2: + subX = 100; + break; + case 0: + case 8: + subY = 100; + break; + case 0xa: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3e: + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { + case 2: + subX = 100; + break; + case 0: + case 8: + subY = 100; + break; + case 0xa: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3f: + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0xa) { + case 8: + subY = 100; + break; + case 0: + case 2: + subX = 100; + break; + case 0xa: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x41: + if (subX == subY) { + switch (wallFlags & 0x82) { + case 0x80: + subX = 100; + break; + case 0: + case 2: + subY = 100; + break; + case 0x82: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x42: + if (subX == subY) { + switch (wallFlags & 0x82) { + case 0x80: + subX = 100; + break; + case 0: + case 2: + subY = 100; + break; + case 0x82: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x43: + if (subX == subY) { + switch (wallFlags & 0x82) { + case 2: + subY = 100; + break; + case 0: + case 0x80: + subX = 100; + break; + case 0x82: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x45: + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { + case 0x20: + subX = 100; + break; + case 0: + case 0x80: + subY = 100; + break; + case 0xa0: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x46: + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { + case 0x20: + subX = 100; + break; + case 0: + case 0x80: + subY = 100; + break; + case 0xa0: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x47: + subX = 7 - subX; + if (subX == subY) { + switch (wallFlags & 0xa0) { + case 0x80: + subY = 100; + break; + case 0: + case 0x20: + subX = 100; + break; + case 0xa0: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x49: + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { + case 8: + subY = 100; + break; + case 0: + case 0x20: + subX = 100; + break; + case 0x28: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x4a: + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { + case 0x20: + subX = 100; + break; + case 0: + case 8: + subY = 100; + break; + case 0x28: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x4b: + subX = 7 - subX; + subY = 7 - subY; + if (subX == subY) { + switch (wallFlags & 0x28) { + case 0x20: + subX = 100; + break; + case 0: + case 8: + subY = 100; + break; + case 0x28: + goto straight; + } + } + if (subX > subY) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + } + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, + DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); + this->entityArray[param_1].orientation = DAT_DirectionAlgorithmState::instance.orientation; + if (microY > targetY) { + this->entityArray[param_1].pathDeltaY = (short)(microY - targetY); + } else { + this->entityArray[param_1].pathDeltaY = (short)(targetY - microY); + } + if (microX > targetX) { + this->entityArray[param_1].pathDeltaX = (short)(microX - targetX); + } else { + this->entityArray[param_1].pathDeltaX = (short)(targetX - microX); + } + this->entityArray[param_1].pathTargetX = (short)targetX; + this->entityArray[param_1].someMicroX = microX <= targetX ? 1 : -1; + this->entityArray[param_1].pathTargetY = (short)targetY; + this->entityArray[param_1].someMicroY = microY <= targetY ? 1 : -1; + if (this->entityArray[param_1].pathDeltaX == 0 && this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathAxisCase = 0; + } else if (this->entityArray[param_1].pathDeltaX == 0) { + this->entityArray[param_1].pathAxisCase = 1; + } else if (this->entityArray[param_1].pathDeltaY == 0) { + this->entityArray[param_1].pathAxisCase = 2; + } else if (this->entityArray[param_1].pathDeltaY > this->entityArray[param_1].pathDeltaX) { + this->entityArray[param_1].pathAxisCase = 3; + } else { + this->entityArray[param_1].pathAxisCase = 4; + } + if (this->entityArray[param_1].pathAxisCase == 3) { + this->entityArray[param_1].pathErrorStepStraight = this->entityArray[param_1].pathDeltaX * 2; + this->entityArray[param_1].pathErrorStepDiagonal + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathError + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaY; + } else if (this->entityArray[param_1].pathAxisCase == 4) { + this->entityArray[param_1].pathErrorStepStraight = this->entityArray[param_1].pathDeltaY * 2; + this->entityArray[param_1].pathErrorStepDiagonal + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaX * 2; + this->entityArray[param_1].pathError + = this->entityArray[param_1].pathErrorStepStraight - this->entityArray[param_1].pathDeltaX; + } + word const rotation = this->entityArray[param_1].graphicRotationUnk; + this->entityArray[param_1].startingAngle = rotation; + if ((short)rotation < -80) { + this->entityArray[param_1].startingAngle = -80; + } + int const angle = this->entityArray[param_1].startingAngle; + this->entityArray[param_1].speedUnk = 0; + double const radians = angle * 3.1415926535 / 180.0; + short const velocity = (short)(this->entityArray[param_1].velocityUnk / 8); + this->entityArray[param_1].velocityUnk = velocity; + this->entityArray[param_1].startingHeight = this->entityArray[param_1].height; + this->entityArray[param_1].travelledDistance = 0; + this->entityArray[param_1].vCos = (float)(this->entityArray[param_1].velocityUnk * cos(radians)); + this->entityArray[param_1].vSin = (float)(this->entityArray[param_1].velocityUnk * sin(radians)); + this->entityArray[param_1].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); + this->entityArray[param_1].gmLookupValue = 0; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[param_1].xPosition, this->entityArray[param_1].yPosition, DE::SHCDE::FX_ARROW_BOUNCE); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp new file mode 100644 index 0000000000..b3062f084f --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -0,0 +1,187 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00403A20 + void EntityState::initializeProjectileVelocities( + int entityID, int x, int y, int height, int targetX, int targetY, int targetZ) + { + if (y > targetY) { + this->entityArray[entityID].pathDeltaY = y - targetY; + } else { + this->entityArray[entityID].pathDeltaY = targetY - y; + } + if (x > targetX) { + this->entityArray[entityID].pathDeltaX = x - targetX; + } else { + this->entityArray[entityID].pathDeltaX = targetX - x; + } + if (this->entityArray[entityID].height >= this->entityArray[entityID].targetZ) { + this->entityArray[entityID].pathDeltaZ + = this->entityArray[entityID].height - this->entityArray[entityID].targetZ; + } else { + this->entityArray[entityID].pathDeltaZ + = this->entityArray[entityID].targetZ - this->entityArray[entityID].height; + } + this->entityArray[entityID].pathTargetX = (short)targetX; + this->entityArray[entityID].pathTargetY = (short)targetY; + this->entityArray[entityID].someMicroX = x <= targetX ? 1 : -1; + this->entityArray[entityID].someMicroY = y <= targetY ? 1 : -1; + // which axis the Bresenham walk steps along + if (this->entityArray[entityID].pathDeltaX == 0 && this->entityArray[entityID].pathDeltaY == 0) { + this->entityArray[entityID].pathAxisCase = 0; + } else if (this->entityArray[entityID].pathDeltaX == 0) { + this->entityArray[entityID].pathAxisCase = 1; + } else if (this->entityArray[entityID].pathDeltaY == 0) { + this->entityArray[entityID].pathAxisCase = 2; + } else if (this->entityArray[entityID].pathDeltaY > this->entityArray[entityID].pathDeltaX) { + this->entityArray[entityID].pathAxisCase = 3; + } else { + this->entityArray[entityID].pathAxisCase = 4; + } + if (this->entityArray[entityID].pathAxisCase == 3) { + this->entityArray[entityID].pathErrorStepStraight = this->entityArray[entityID].pathDeltaX * 2; + this->entityArray[entityID].pathErrorStepDiagonal + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathError + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaY; + } else if (this->entityArray[entityID].pathAxisCase == 4) { + this->entityArray[entityID].pathErrorStepStraight = this->entityArray[entityID].pathDeltaY * 2; + this->entityArray[entityID].pathErrorStepDiagonal + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaX * 2; + this->entityArray[entityID].pathError + = this->entityArray[entityID].pathErrorStepStraight - this->entityArray[entityID].pathDeltaX; + } + int const curveType + = DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[(short)this->entityArray[entityID].entityType]; + if (curveType == 0) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + this->entityArray[entityID].startingAngle + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].velocityUnk, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 1) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + this->entityArray[entityID].velocityUnk = (short)MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].startingAngle, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 2) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + // from above, aim low first + if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { + this->entityArray[entityID].startingAngle = 3; + } + int const heightDifference = this->entityArray[entityID].heightDifference; + this->entityArray[entityID].velocityUnk + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeVelocity, this)( + (short)this->entityArray[entityID].entityType, + (double)this->entityArray[entityID].startingAngle, distance, heightDifference); + if (this->entityArray[entityID].velocityUnk <= 0) { + int const type = (short)this->entityArray[entityID].entityType; + this->entityArray[entityID].startingAngle = 15; + this->entityArray[entityID].velocityUnk = (short)MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)(type, 15.0, distance, heightDifference); + } + } else if (curveType == 3) { + ushort const rng = (ushort)this->entityArray[entityID].rng_1; + this->entityArray[entityID].startingAngle = (rng & 0xf) + 8; + this->entityArray[entityID].velocityUnk = (rng & 7) + 0x15; + } else if (curveType == 4) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 20 + 16); + if (this->entityArray[entityID].rng_1 & 0x80) { + this->entityArray[entityID].startingAngle = -this->entityArray[entityID].startingAngle; + } + this->entityArray[entityID].velocityUnk = (short)((this->entityArray[entityID].rng_1 >> 8) % 20 + 16); + if (this->entityArray[entityID].rng_1 & 0x8000) { + this->entityArray[entityID].velocityUnk = -this->entityArray[entityID].velocityUnk; + } + return; + } else if (curveType == 5) { + this->entityArray[entityID].velocityUnk = 0; + this->entityArray[entityID].startingAngle = this->entityArray[entityID].rng_1 & 7; + this->entityArray[entityID].graphicRotationUnk + = (short)((this->entityArray[entityID].rng_1 >> 8) & 0x3f); + return; + } else if (curveType == 6) { + int const distanceRaw = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::computeLineOfSightDistance, + this)(x, y, height, targetX, targetY, targetZ, 1); + this->entityArray[entityID].field_0x94 = (short)distanceRaw; + this->entityArray[entityID].totalFlightDistance = (short)distanceRaw; + this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + short const distance = (short)distanceRaw; + if (distance > 150) { + this->entityArray[entityID].velocityUnk = 125; + } + this->entityArray[entityID].startingAngle + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::math_atan_1, this)( + (short)this->entityArray[entityID].entityType, (double)this->entityArray[entityID].velocityUnk, + distance, this->entityArray[entityID].heightDifference); + } else if (curveType == 7 || curveType == 10) { + return; + } else if (curveType == 8) { + if (this->entityArray[entityID].unitID_OR_seaGullID == 0) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 60) + 8; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 0x23; + } else if (this->entityArray[entityID].unitID_OR_seaGullID == 4) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 30) + 15; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 15; + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator * 0.75; + } else if (this->entityArray[entityID].unitID_OR_seaGullID == 5) { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 30) + 45; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 0x23; + } else { + this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 35) + 20; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 25; + this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator * 0.75; + } + } else if (curveType == 9) { + this->entityArray[entityID].startingAngle = 0; + } + if ((this->entityArray[entityID].entityType == Map::Entities::ET_ARROW_AND_DEFAULT + || this->entityArray[entityID].entityType == Map::Entities::ET_CROSSBOWARROW) + && height + 0x36 < targetZ && this->entityArray[entityID].rng_1 % 10 == 5) { + this->entityArray[entityID].hasDoneEffectUnk = 1; + } + int const angle = this->entityArray[entityID].startingAngle; + this->entityArray[entityID].speedUnk = 0; + this->entityArray[entityID].travelledDistance = 0; + double const radians = (double)angle * 3.1415926535 / 180.0; + this->entityArray[entityID].vCos = (float)(cos(radians) * (double)this->entityArray[entityID].velocityUnk); + this->entityArray[entityID].vSin = (float)(sin(radians) * (double)this->entityArray[entityID].velocityUnk); + this->entityArray[entityID].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp new file mode 100644 index 0000000000..5c5d186fc7 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/math_atan_1.cpp @@ -0,0 +1,52 @@ +#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" + +#include "OpenSHC/Globals/DOUBLE_00b941c0.hpp" + +#include "float.h" +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402C50 + int EntityState::math_atan_1(int entityType, double param_3, int param_4, int heightDifference) + { + double const v = param_3 * param_3; + param_4 = param_4 * 4; + heightDifference = heightDifference / 2; + double const d = param_4; + double const low = v / (d * 9.812); + double const root + = sqrt(v * v / (96.275344 * (d * d)) - (v + v) * heightDifference / (d * d * 9.812) - 1.0); + double tangent = low - root; + int angleLow; + if (tangent == DOUBLE_00b941c0::instance || _isnan(tangent)) { + angleLow = 1000; + } else { + angleLow = (long)(atan(tangent) * 180.0 / 3.1415926535 + 0.4999000132083893); + } + tangent = root + low; + int angleHigh; + if (tangent == DOUBLE_00b941c0::instance || _isnan(tangent)) { + angleHigh = 1000; + } else { + angleHigh = (long)(atan(tangent) * 180.0 / 3.1415926535 + 0.4999000132083893); + } + int angle = angleLow < angleHigh ? angleLow : angleHigh; + if (angle < -90) { + angle = angleLow > angleHigh ? angleLow : angleHigh; + if (angle < -90) { + return 45; + } + } + if (angle > 90) { + return 45; + } + return angle; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp new file mode 100644 index 0000000000..aaa0844b66 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/moveProjectileEntity.cpp @@ -0,0 +1,124 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" + +#include "math.h" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + using Map::Entities::EntityType; + using WindowsHelper::Enums::BOOLEnum; + + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 Note that Ghidra is bad at x87 extended precision + instructions. This function likely does: float dx = vCos * speed * 0.25f; float dy = vSin * speed * + 0.25f; float t = vSin - gravityAccum; float slope = (height - (4.906f * t - t * t * velocity)) + / (distance - dx * t); float angle = atan(slope) * 180.0f / PI; + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004084A0 + BOOLEnum EntityState::moveProjectileEntity(int entityID) + { + double const speed = this->entityArray[entityID].speedUnk; + double const vCos = this->entityArray[entityID].vCos; + double const vSin = this->entityArray[entityID].vSin; + int height = this->entityArray[entityID].height - this->entityArray[entityID].startingHeight; + int heightStep = 0; + if (this->entityArray[entityID].someCounter_OR_hitGround != 0) { + return FALSE; + } + if (this->entityArray[entityID].pathAxisCase == 0) { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + } + double const distance = vCos * speed; + double const rise = vSin * speed - speed * speed * 4.906; + int const dx = (long)(distance * 0.25); + int const targetHeight = (long)(rise + rise); + double angle; + if (speed != 0) { + double const before = speed - this->entityArray[entityID]._elapsedTimeOrGravityAccumulator; + angle = atan((rise - (vSin * before - before * before * 4.906)) / (distance - vCos * before) * 3.0) + * 180.0 / 3.1415926535; + } else { + angle = this->entityArray[entityID].startingAngle; + } + this->entityArray[entityID].graphicRotationUnk = (long)angle; + this->entityArray[entityID].speedUnk + = this->entityArray[entityID]._elapsedTimeOrGravityAccumulator + this->entityArray[entityID].speedUnk; + int const remaining = dx - this->entityArray[entityID].travelledDistance; + if (remaining != 0) { + heightStep = (targetHeight - height) / remaining; + } + while (this->entityArray[entityID].travelledDistance < dx) { + this->entityArray[entityID].travelledDistance = this->entityArray[entityID].travelledDistance + 1; + this->entityArray[entityID].clearanceStepsRemaining + = this->entityArray[entityID].clearanceStepsRemaining - 1; + if (entityID != 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + entityID); + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateEntityMicroMovement, this)(entityID); + if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + != 9 + && DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + != 10) { + height = height + heightStep; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + entityID, height, (long)angle, 1); + } + if (!MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + entityID)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); + return TRUE; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); + if (this->entityArray[entityID].someCounter_OR_hitGround != 0) { + break; + } + } + this->entityArray[entityID].travelledDistance = dx; + if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + == 9) { + if (this->entityArray[entityID].height < this->entityArray[entityID].targetZ) { + this->entityArray[entityID].height = this->entityArray[entityID].height + 1; + } else if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { + this->entityArray[entityID].height = this->entityArray[entityID].height - 8; + if (this->entityArray[entityID].height <= 0) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + this->entityArray[entityID].someMicroY = 0; + this->entityArray[entityID].someMicroX = 0; + this->entityArray[entityID].height = 0; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( + 0, 0, 0, microX, microY, 0, microX, microY, 0, ((EntityType)0x1f), 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL_DIVE); + } + } + } else if (DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[this->entityArray[entityID].entityType] + == 10) { + this->entityArray[entityID].height = this->entityArray[entityID].height + 1; + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::updateProjectileHeightAndCollision, this)( + entityID, targetHeight, (long)angle, 0); + } + return TRUE; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp new file mode 100644 index 0000000000..0113db724f --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/processEntityHitBuildingOrUnit.cpp @@ -0,0 +1,583 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +#include + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Commands::MappersEnum; + using DE::SHCDE::eSFX; + using Game::GameMode2; + using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; + using Map::Entities::EntityType; + using Map::Units::UnitType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00407190 + undefined4 EntityState::processEntityHitBuildingOrUnit(int entityID) + { + this->entityArray[entityID].xPosition = this->entityArray[entityID].microX / 8; + this->entityArray[entityID].yPosition = this->entityArray[entityID].microY / 8; + uint const y = this->entityArray[entityID].yPosition; + uint const x = this->entityArray[entityID].xPosition; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int result = 1; + this->entityArray[entityID].tile = tile; + if (this->entityArray[entityID].entityType == Map::Entities::ET_SEAGULLUnk) { + if (x <= 399 && y <= 399 && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] != 0 + && !(DAT_TileMapState::instance.LogicLayer[tile] & 0x30) + && this->entityArray[entityID].height > 0) { + this->entityArray[entityID].nextEntityOnThisTileByID = DAT_TileMapState::instance.EntityLayer[tile]; + DAT_TileMapState::instance.EntityLayer[tile] = entityID; + return 1; + } + this->entityArray[entityID].tile = 0; + return 0; + } + if (x > 399 || y > 399) { + this->entityArray[entityID].logicalState = 3; + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + this->entityArray[entityID].logicalState = 3; + return 0; + } + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x30) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return 0; + } + switch (this->entityArray[entityID].entityType) { + case Map::Entities::ET_FLAG_1: + case Map::Entities::ET_FLAG_4: + case Map::Entities::ET_FLAG_2: + case Map::Entities::ET_FLAG_3: + case Map::Entities::ET_BRAZIER: + case Map::Entities::ET_HEADS_ON_SPIKES: + DAT_TileMapState::instance.MiscDisplayLayer[tile] + = DAT_TileMapState::instance.MiscDisplayLayer[tile] | 0x1000; + if (this->entityArray[entityID].entityType != Map::Entities::ET_BRAZIER + && this->entityArray[entityID].entityType != Map::Entities::ET_HEADS_ON_SPIKES) { + int const flagTile = this->entityArray[entityID].tile; + uint const flags = DAT_TileMapState::instance.LogicLayer[flagTile]; + if (flags != 0) { + if (DAT_TileMapState::instance.DamageLayer[flagTile] != 0) { + if (flags & 0x400000) { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[flagTile] + 20; + } else if (flags & 0x200) { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[flagTile] + 10; + } else { + this->entityArray[entityID].height = DAT_TileMapState::instance.HeightLayer[flagTile]; + } + } + } else if (DAT_TileMapState::instance.BuildingLayer[flagTile] == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + } + } else { + int const brazierTile = this->entityArray[entityID].tile; + short const building = DAT_TileMapState::instance.BuildingLayer[brazierTile]; + if (building != 0) { + switch (DAT_BuildingsState::instance.buildings[building].buildingType) { + case Map::Buildings::BT_STONEKEEP: + case Map::Buildings::BT_STRONGHOLD: + case Map::Buildings::BT_KEEPFOUR: + case Map::Buildings::BT_KEEPFIVE: + case Map::Buildings::BT_GATEHOUSELARGE: + case Map::Buildings::BT_GATEHOUSESMALL: + case Map::Buildings::BT_TOWER1: + case Map::Buildings::BT_TOWER2: + case Map::Buildings::BT_TOWER3: + case Map::Buildings::BT_TOWER4: + case Map::Buildings::BT_TOWER5: + this->entityArray[entityID].height = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(brazierTile); + goto linkEntity; + } + } else if (DAT_TileMapState::instance.LogicLayer[brazierTile] & 0x100) { + if (DAT_TileMapState::instance.DamageLayer[brazierTile] != 0) { + this->entityArray[entityID].height + = DAT_TileMapState::instance.HeightLayer[brazierTile] + 15; + } else { + this->entityArray[entityID].height = DAT_TileMapState::instance.HeightLayer[brazierTile]; + } + goto linkEntity; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_SIEGE_THAT) { + int stone; + int gold; + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingCost, + DAT_BuildingsState::ptr)(Commands::M_MAPPER_BRAZIER, &stone, &gold); + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .startResources[15] += gold; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + } + goto linkEntity; + } + { + int unit = DAT_TileMapState::instance.UnitLayer[tile]; + if (this->entityArray[entityID].entityType != Map::Entities::ET_ARROW_AND_DEFAULT + || this->entityArray[entityID].rng_2 != 2) { + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD + || this->entityArray[entityID].entityType == Map::Entities::ET_TREBUCHET + || this->entityArray[entityID].entityType == Map::Entities::ET_CATAPULT + || this->entityArray[entityID].entityType == Map::Entities::ET_MANGONEL + || this->entityArray[entityID].velocityUnk > 80) { + for (; unit != 0; unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (this->entityArray[entityID].logicalState == 2 + && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(unit, entityID, 0)) { + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_FLYING) { + this->entityArray[entityID].height = MACRO_CALL_MEMBER( + Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); + goto cowSplat; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return 0; + } + } + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_TREBUCHET + || this->entityArray[entityID].entityType == Map::Entities::ET_CATAPULT + || this->entityArray[entityID].entityType == Map::Entities::ET_MANGONEL + || this->entityArray[entityID].velocityUnk > 80) { + for (int direction = 1; direction < 8; direction += 2) { + for (int neighbour = DAT_TileMapState::instance + .UnitLayer[DAT_TileMapState::instance.directionTranslationMatrix + [this->entityArray[entityID].yPosition][direction] + + tile]; + neighbour != 0; + neighbour = DAT_UnitsState::instance.units[neighbour].nextUnitOnTheSameTile) { + if (DAT_UnitsState::instance.units[neighbour].field_0x90 != 0 + && this->entityArray[entityID].logicalState == 2 + && MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(neighbour, entityID, 1)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)( + entityID); + return 0; + } + } + } + } + } + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_COW_POISON_CLOUD) { + int const cloudHeight + = MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(tile); + for (int direction = 0; direction < 8; direction++) { + int const neighbourTile + = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][direction] + + tile; + for (int unit = DAT_TileMapState::instance.UnitLayer[neighbourTile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (abs(cloudHeight + - MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(neighbourTile)) + < 120 + && this->entityArray[entityID].logicalState == 2) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(unit, entityID, 1); + } + } + } + for (int i = 0; i < 16; i++) { + int const blastTile = MACRO_CALL_MEMBER(Map::TileMapState_Func::computeTileAlongAxisOffset, + DAT_TileMapState::ptr)(tile, DAT_EntityDefinedData::instance.EntityBlastTileOffsets[i].xOffset, + DAT_EntityDefinedData::instance.EntityBlastTileOffsets[i].yOffset); + for (int unit = DAT_TileMapState::instance.UnitLayer[blastTile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + if (abs(cloudHeight + - MACRO_CALL_MEMBER( + Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)(blastTile)) + < 120 + && this->entityArray[entityID].logicalState == 2) { + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::processEntityDamageToUnit, + DAT_UnitsState::ptr)(unit, entityID, 2); + } + } + } + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_FIRE + && (DAT_TileMapState::instance.LogicLayer[this->entityArray[entityID].tile] & 8)) { + int const ditch = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(this->entityArray[entityID].tile); + if (ditch != 0 && DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)(this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance.HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], 3); + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; + } + } + { + int groundHeight; + groundHeight + = MACRO_CALL_MEMBER(Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 0); + int building; + building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (building != 0) { + int const buildingType = DAT_BuildingsState::instance.buildings[building].buildingType; + if ((buildingType == Map::Buildings::BT_TOWER + || (uint)(buildingType - Map::Buildings::BT_TOWER1) <= 4) + && (this->entityArray[entityID].rng_1 & 4)) { + groundHeight = groundHeight + 20; + } + } + short height; + height = this->entityArray[entityID].height; + if (groundHeight <= height) { + goto linkEntity; + } + short hitType; + hitType = this->entityArray[entityID].entityType; + if (hitType == ((EntityType)0x20)) { + if (height < DAT_TileMapState::instance.DefaultHeightLayer[tile]) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x10000100) + && DAT_TileMapState::instance.DefaultHeightLayer[tile] + < this->entityArray[entityID].startingHeight_2 + 50) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile_Convenience)( + this->entityArray[entityID].owner, this->entityArray[entityID].microX, + this->entityArray[entityID].microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] - 8, 2); + if (DAT_TileMapState::instance.LogicLayer[tile] & 8) { + int const ditch = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(tile); + if (ditch != 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)(this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], + 3); + if (DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; + } + } + } + } + } + } else if (hitType == ((EntityType)0x1b)) { + if (height <= DAT_TileMapState::instance.DefaultHeightLayer[tile]) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + if ((DAT_TileMapState::instance.LogicLayer[tile] & 0x40100001) + && this->entityArray[entityID].unitID_OR_seaGullID == 0) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, 0, 0, + microX, microY, splashHeight, microX, microY, splashHeight, ((EntityType)0x1f), 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_MED_PLOP); + } + } + } else if (hitType == ((EntityType)8)) { + if (abs(height - this->entityArray[entityID].targetZ) < 20 || height <= 8) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } + } else if (hitType == Map::Entities::ET_ARROW_AND_DEFAULT || hitType == Map::Entities::ET_CROSSBOWARROW + || hitType == Map::Entities::ET_BALLISTA || hitType == Map::Entities::ET_SLINGER + || hitType == Map::Entities::ET_FIRETHROWER) { + int ditch; + int building; + uint flags; + if (this->entityArray[entityID].rng_2 == 2) { + for (int direction = 0; direction < 8; direction++) { + int const neighbourTile + = DAT_TileMapState::instance + .directionTranslationMatrix[this->entityArray[entityID].yPosition][direction] + + tile; + if (DAT_TileMapState::instance.LogicLayer[neighbourTile] & 8) { + ditch = MACRO_CALL_MEMBER(Map::TileMapState_Func::getPitchDitchIDForTile, + DAT_TileMapState::ptr)(neighbourTile); + if (ditch != 0) { + goto ignitePitch; + } + } + } + } + building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (this->entityArray[entityID].travelledDistance + > this->entityArray[entityID].totalFlightDistance / 2) { + flags = DAT_TileMapState::instance.LogicLayer[tile]; + if (flags & 0x40100001) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, 0, 0, + microX, microY, splashHeight, microX, microY, splashHeight, ((EntityType)0x1f), 0); + this->entityArray[entityID].logicalState = 3; + result = 0; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_LITTLE_PLOP); + } else if (!(flags & 0x10000100) + && (building == 0 + || (DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_STONEKEEP + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_STRONGHOLD + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_KEEPFOUR + && DAT_BuildingsState::instance.buildings[building].buildingType + != Map::Buildings::BT_KEEPFIVE))) { + if (flags & 8) { + if (this->entityArray[entityID].rng_2 == 2) { + ditch = MACRO_CALL_MEMBER( + Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(tile); + if (ditch != 0) { + ignitePitch: + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, DE::SHCDE::FX_IGNITE_PITCH); + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + this->entityArray[entityID].owner, + DAT_TileMapState::instance.pitchDitches[ditch].x * 8, + DAT_TileMapState::instance.pitchDitches[ditch].y * 8, + DAT_TileMapState::instance + .HeightLayer[DAT_TileMapState::instance.pitchDitches[ditch].tile], + 3); + if (DAT_TileMapState::instance.pitchDitches[ditch].state == 1) { + DAT_TileMapState::instance.pitchDitches[ditch].state = 2; + } + } + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + result = 0; + } else if (building == 0) { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + result = 0; + } else { + int const unitID = this->entityArray[entityID].unitID_OR_seaGullID; + int const buildingType = DAT_BuildingsState::instance.buildings[building].buildingType; + if ((buildingType < Map::Buildings::BT_TOWER1 + || buildingType > Map::Buildings::BT_TOWER5) + && DAT_BuildingsState::instance.buildings[building].currentHealth != 0 + && !(flags & 0xf000000)) { + if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_S_FBALLISTA) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 10, 0, + this->entityArray[entityID].owner, FALSE, unitID); + if (MACRO_CALL_MEMBER( + Map::TileMapState_Func::getNonFarmFieldBuildingHealthAtTileOr1000, + DAT_TileMapState::ptr)(tile) + < 50) { + MACRO_CALL(Map::Entities_Func::SetPlaceOnFire)( + this->entityArray[entityID].owner, + this->entityArray[entityID].xPosition * 8, + this->entityArray[entityID].yPosition * 8, + DAT_TileMapState::instance + .HeightLayer[this->entityArray[entityID].tile], + 3); + } + } else if (this->entityArray[entityID].entityType == Map::Entities::ET_BALLISTA) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 2, 0, + this->entityArray[entityID].owner, FALSE, unitID); + } else { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, 1, 0, + this->entityArray[entityID].owner, FALSE, unitID); + } + this->entityArray[entityID].someCounter_OR_hitGround = 1; + result = 0; + } + } + } else if ((this->entityArray[entityID].rotationFrameIndex >= 3 + || this->entityArray[entityID].startingAngle >= 0) + && this->entityArray[entityID].hasDoneEffectUnk == 0 + && this->entityArray[entityID].clearanceStepsRemaining <= 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::handleProjectileWallBounce, this)( + entityID); + result = 0; + } + } + } else if (hitType == Map::Entities::ET_TREBUCHET || hitType == Map::Entities::ET_CATAPULT + || hitType == Map::Entities::ET_MANGONEL) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + uint const flags = DAT_TileMapState::instance.LogicLayer[tile]; + int damage = 10; + int collateral = 10; + if (flags & 0x40100001) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_SPLASH); + } + if (!(flags & 0x100) && !(flags & 0x10000400) + && DAT_TileMapState::instance.BuildingLayer[tile] == 0) { + DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 + = DAT_UnitsState::instance.units[this->entityArray[entityID].unitID_OR_seaGullID].field_0xd2 + + 1; + if (flags & 0x4a5014b1) { + if (flags & 0x40100001) { + for (int i = 0; i < this->entityArray[entityID].rng_1 % 16 + 10; i++) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(1, + 0, 0, microX, microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, + SEC_RNG::instance.currentNumber2 % 80 - 40 + microX, + (SEC_RNG::instance.currentNumber2 >> 8) % 80 - 40 + microY, 8, + ((EntityType)0x1b), 0); + } + { + int const splashHeight + = DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2; + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, + 0, 0, microX, microY, splashHeight, microX, microY, splashHeight, + ((EntityType)0x1f), 0); + } + } + } else { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_HIT_GROUND); + this->entityArray[entityID].someCounter_OR_hitGround = 40; + for (int i = 0; i < this->entityArray[entityID].rng_1 % 8 + 5; i++) { + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].microX; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(2, 0, 0, + microX, microY, + DAT_TileMapState::instance.HeightLayer[this->entityArray[entityID].tile] + 2, + SEC_RNG::instance.currentNumber2 % 80 - 40 + microX, + (SEC_RNG::instance.currentNumber2 >> 8) % 80 - 40 + microY, 8, ((EntityType)0x1b), + 0); + } + } + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileImpactDebris, this)(entityID); + short const rockType = this->entityArray[entityID].entityType; + if (rockType == Map::Entities::ET_TREBUCHET) { + damage = 60; + collateral = 30; + } else if (rockType == Map::Entities::ET_CATAPULT) { + damage = 20; + } else if (rockType == Map::Entities::ET_MANGONEL) { + damage = 5; + collateral = 0; + } + int const building = DAT_TileMapState::instance.BuildingLayer[tile]; + if (building != 0) { + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[building].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner]) { + damage = 0; + collateral = 0; + } + } else if ((flags & 0x100) + && DAT_GameState::instance.mapAndTime.playerTeams[this->entityArray[entityID].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[(DAT_TileMapState::instance.WallOwnerLayer[tile] & 7) + 1]) { + damage = 0; + collateral = 0; + } + if (rockType == Map::Entities::ET_MANGONEL) { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + tile, this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + damage, 0, -this->entityArray[entityID].owner, FALSE, + this->entityArray[entityID].unitID_OR_seaGullID); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateral, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, collateral, -this->entityArray[entityID].owner, + 0, this->entityArray[entityID].unitID_OR_seaGullID); + } else { + MACRO_CALL_MEMBER(Map::TileMapState_Func::processDamageToBuilding, DAT_TileMapState::ptr)( + tile, this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + damage, 0, this->entityArray[entityID].owner, FALSE, + this->entityArray[entityID].unitID_OR_seaGullID); + MACRO_CALL_MEMBER(Map::TileMapState_Func::processEntityDamageToBuildingCollateralThunk, + DAT_TileMapState::ptr)(tile, this->entityArray[entityID].xPosition, + this->entityArray[entityID].yPosition, collateral, this->entityArray[entityID].owner, + 0); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ROCK_HIT_WALL); + } + result = 0; + } else if (hitType == Map::Entities::ET_COW_FLYING) { + cowSplat: + if (this->entityArray[entityID].hasDoneEffectUnk == 0) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_COW_SPLAT); + this->entityArray[entityID].hasDoneEffectUnk = 1; + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x401000b1) { + this->entityArray[entityID].someCounter_OR_hitGround = 1; + } else { + this->entityArray[entityID].someCounter_OR_hitGround = 40; + DAT_GameCore::instance.cowPoisonTrackerUnk + = DAT_GameCore::instance.cowPoisonTrackerUnk + 500; + for (int i = SEC_RNG::instance.currentNumber2 % 5 - 2; i < 8; i++) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, this->entityArray[entityID].owner, 0, + this->entityArray[entityID].microX, this->entityArray[entityID].microY, + this->entityArray[entityID].height, 0, 0, 0, Map::Entities::ET_COW_POISON_CLOUD, 0); + } + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_FLIES); + } + } + result = 0; + } + } + linkEntity: + if (entityID != 0) { + if (entityID < 25) { + this->entityArray[entityID].nextEntityOnThisTileByID + = (byte)DAT_TileMapState::instance.EntityLayerLT25[tile]; + DAT_TileMapState::instance.EntityLayerLT25[tile] = (char)entityID; + return result; + } + this->entityArray[entityID].nextEntityOnThisTileByID = DAT_TileMapState::instance.EntityLayer[tile]; + DAT_TileMapState::instance.EntityLayer[tile] = entityID; + } + return result; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp new file mode 100644 index 0000000000..509fd382be --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/processSeaGulls.cpp @@ -0,0 +1,222 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +#include "math.h" +#include + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using DE::SHCDE::eSFX; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00406900 + void EntityState::processSeaGulls(int seagullID) + { + int const entityID = this->seagullArray[seagullID].entityID; + if (this->seagullArray[seagullID].someCountDown != 0) { + this->seagullArray[seagullID].someCountDown = this->seagullArray[seagullID].someCountDown - 1; + if (this->seagullArray[seagullID].someCountDown != 0) { + return; + } + this->entityArray[entityID].targetX = this->entityArray[entityID].microX; + this->entityArray[entityID].targetY = this->entityArray[entityID].microY; + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL_SURFACE); + } + if (abs(this->entityArray[entityID].microX - this->entityArray[entityID].targetX) < 3 + && abs(this->entityArray[entityID].microY - this->entityArray[entityID].targetY) < 3) { + if ((this->seagullArray[seagullID].randomNumber ^ this->entityArray[entityID].rng_1 + ^ SEC_RNG::instance.currentNumber2) + % 500 + == 123) { + int const newMicroX = this->entityArray[entityID].someMicroX + this->entityArray[entityID].microX; + short const& microYRef = this->entityArray[entityID].microY; + int const newMicroY = this->entityArray[entityID].someMicroY + microYRef; + int const newY = newMicroY / 8; + int const newX = newMicroX / 8; + if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(newX, newY)) { + int const oldY = this->entityArray[entityID].microY / 8; + int const oldX = this->entityArray[entityID].microX / 8; + if (MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(oldX, oldY) + && (DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[newY].addXgetTile + + newX] + & 1) + && (DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[oldY].addXgetTile + + oldX] + & 1)) { + this->seagullArray[seagullID].someCountDown = 160; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)( + entityID, this->entityArray[entityID].microX, this->entityArray[entityID].microY, 250, + newMicroX, newMicroY, 0); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL); + return; + } + } + } + double radians = (this->seagullArray[seagullID].angle - 180) * 3.1415926535 / 180.0; + this->seagullArray[seagullID].angle + = this->seagullArray[seagullID].someAngle * 20 + this->seagullArray[seagullID].angle; + if (this->seagullArray[seagullID].angle >= 360) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + if (SEC_RNG::instance.currentNumber1 % 5 == 1) { + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_GULL); + } + this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle - 360; + if (this->seagullArray[seagullID].field_0x1a < 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + 1; + } else if (this->seagullArray[seagullID].field_0x1a > 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 - 1; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 < 24) { + this->seagullArray[seagullID].unknownCounter_0x16 = 24; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 > 80) { + this->seagullArray[seagullID].unknownCounter_0x16 = 80; + } + this->seagullArray[seagullID].field_0x1a = this->seagullArray[seagullID].field_0x1a + 1; + if (this->seagullArray[seagullID].field_0x1a >= 20) { + this->seagullArray[seagullID].field_0x1a = -20; + } + } + if (this->seagullArray[seagullID].angle < 0) { + this->seagullArray[seagullID].angle = this->seagullArray[seagullID].angle + 360; + if (this->seagullArray[seagullID].field_0x1a < 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 + 1; + } else if (this->seagullArray[seagullID].field_0x1a > 0) { + this->seagullArray[seagullID].unknownCounter_0x16 + = this->seagullArray[seagullID].unknownCounter_0x16 - 1; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 < 24) { + this->seagullArray[seagullID].unknownCounter_0x16 = 24; + } + if (this->seagullArray[seagullID].unknownCounter_0x16 > 80) { + this->seagullArray[seagullID].unknownCounter_0x16 = 80; + } + this->seagullArray[seagullID].field_0x1a = this->seagullArray[seagullID].field_0x1a + 1; + if (this->seagullArray[seagullID].field_0x1a >= 20) { + this->seagullArray[seagullID].field_0x1a = -20; + } + } + double const radius = this->seagullArray[seagullID].unknownCounter_0x16; + int const circleX = (long)(sin(radians) * radius); + int const circleY = (long)(cos(radians) * radius); + radians = (this->seagullArray[seagullID].angle_2 - 180) * 3.1415926535 / 180.0; + this->seagullArray[seagullID].angle_2 + = this->seagullArray[seagullID].angleStep + this->seagullArray[seagullID].angle_2; + if (this->seagullArray[seagullID].angle_2 >= 360) { + this->seagullArray[seagullID].angle_2 = this->seagullArray[seagullID].angle_2 - 360; + } + if (this->seagullArray[seagullID].angle_2 < 0) { + this->seagullArray[seagullID].angle_2 = this->seagullArray[seagullID].angle_2 + 360; + } + double const radius2 = this->seagullArray[seagullID].numberBetween60And100; + this->seagullArray[seagullID].x_2 + = (short)(long)(sin(radians) * radius2) + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].y_2 + = (short)(long)(cos(radians) * radius2) + this->seagullArray[seagullID].y; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileTargetPosition, this)(entityID, + this->entityArray[entityID].microX, this->entityArray[entityID].microY, + this->entityArray[entityID].height, this->seagullArray[seagullID].x_2 + circleX, + this->seagullArray[seagullID].y_2 + circleY, 250); + } + if ((abs(this->seagullArray[seagullID].x - this->seagullArray[seagullID].x_3) < 2 + && abs(this->seagullArray[seagullID].y - this->seagullArray[seagullID].y_3) < 2) + || this->seagullArray[seagullID].pathMajorLength <= 0) { + if (this->seagullArray[seagullID].rngMax799_countdown > 0) { + this->seagullArray[seagullID].rngMax799_countdown + = this->seagullArray[seagullID].rngMax799_countdown - 1; + return; + } + this->seagullArray[seagullID].rngMax799_countdown = SEC_RNG::instance.currentNumber2 % 400 + 400; + MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::findFurthestSeaTile, + DAT_PathFindingState::ptr)((SEC_RNG::instance.currentNumber2 >> 4) % 200 + 400, + this->seagullArray[seagullID].x / 8, this->seagullArray[seagullID].y / 8); + this->seagullArray[seagullID].x_3 = (short)DAT_PathFindingState::instance.ALG_ResultX * 8; + this->seagullArray[seagullID].y_3 = (short)DAT_PathFindingState::instance.ALG_ResultY * 8; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeSeagullMovementVector, this)(seagullID, + this->seagullArray[seagullID].x, this->seagullArray[seagullID].y, this->seagullArray[seagullID].x_3, + this->seagullArray[seagullID].y_3); + this->seagullArray[seagullID].pathStepDelay = 10; + return; + } + this->seagullArray[seagullID].pathStepDelay = this->seagullArray[seagullID].pathStepDelay - 1; + if (this->seagullArray[seagullID].pathStepDelay > 0) { + return; + } + this->seagullArray[seagullID].pathStepDelay = 10; + this->seagullArray[seagullID].pathMajorLength = this->seagullArray[seagullID].pathMajorLength - 1; + short const axisCase = this->seagullArray[seagullID].pathAxisCase; + if (axisCase == 0) { + return; + } + if (axisCase == 2) { + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + return; + } + if (axisCase == 1) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + return; + } + if (axisCase == 4) { + if (this->seagullArray[seagullID].pathError > 0) { + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + this->seagullArray[seagullID].pathError; + return; + } + this->seagullArray[seagullID].x + = this->entityArray[entityID].someMicroX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepStraight + this->seagullArray[seagullID].pathError; + return; + } + if (axisCase == 3) { + this->seagullArray[seagullID].y + = this->seagullArray[seagullID].y + this->seagullArray[seagullID].pathStepY; + if (this->seagullArray[seagullID].pathError > 0) { + this->seagullArray[seagullID].x + = this->seagullArray[seagullID].pathStepX + this->seagullArray[seagullID].x; + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepDiagonal + this->seagullArray[seagullID].pathError; + return; + } + this->seagullArray[seagullID].pathError + = this->seagullArray[seagullID].pathErrorStepStraight + this->seagullArray[seagullID].pathError; + } + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp new file mode 100644 index 0000000000..f046c7b81d --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileEntity.cpp @@ -0,0 +1,280 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00404AE0 + uint EntityState::spawnProjectileEntity(int unitID, undefined4 playerID1, uint ownerColorUnk, int microX, + int microY, int totalHeight, int targetX, int targetY, int targetZUnk, EntityType entityType, int param_11) + { + BOOL bVar1; + dword dVar2; + uint uVar5; + uint uVar6; + short sVar7; + uint entityID; + bVar1 = FALSE; + if (((0x2b < (int)entityType) && ((int)entityType < 0x5b)) || (0x5e < (int)entityType)) { + return 0; + } + if (entityType != ~Map::Entities::ET_UNKNOWN) { + if ((uint)(entityType - ((EntityType)0x28)) <= 7) { + for (entityID = 1; (int)entityID < 25; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { + break; + } + if ((int)entityID >= 24) { + return 0; + } + } + } else { + for (entityID = this->everyTenTicks; (int)entityID < 3000; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { + break; + } + if ((int)entityID >= 2999) { + switch (entityType) { + case Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_CATAPULT: + case Map::Entities::ET_TREBUCHET: + case Map::Entities::ET_MANGONEL: + case Map::Entities::ET_CROSSBOWARROW: + case ((EntityType)8): + case Map::Entities::ET_COW_POISON_CLOUD: + case Map::Entities::ET_COW_FLYING: + case ((EntityType)0x18): + case ((EntityType)0x19): + case Map::Entities::EntityTypeInt__ET_EXPLOSION: + case Map::Entities::ET_SLINGER: + case Map::Entities::ET_FIRETHROWER: + case Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_FIRETHROWER_UNTARGETED: + case Map::Entities::ET_FIREBALLISTA: + case ((EntityType)0x5b): + case ((EntityType)0x5c): + case ((EntityType)0x5d): + case ((EntityType)0x5e): + this->maxEntityCount = 3000; + for (entityID = 25; (int)entityID < 3000; entityID++) { + if (this->entityArray[entityID].logicalState == 0) { + goto found; + } + switch (this->entityArray[entityID].entityType) { + case Map::Entities::ET_FIRE: + case Map::Entities::ET_DUST_CLOUD: + case ((EntityType)0x1b): + case ((EntityType)0x1e): + case ((EntityType)0x1f): + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + entityID); + goto found; + } + } + } + this->everyTenTicks = 2999; + return 0; + } + } + if ((int)entityID >= this->maxEntityCount) { + this->maxEntityCount = entityID + 1; + } + this->everyTenTicks = entityID; + } + } else { + entityID = 0; + entityType = ((EntityType)8); + } + found: + this->entityArray[entityID].rng_2 = 0; + if (entityType == ((EntityType)0x5b)) { + bVar1 = TRUE; + this->entityArray[entityID].rng_2 = 1; + entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } else if (entityType == Map::Entities::ET_FIREBALLISTA) { + bVar1 = TRUE; + this->entityArray[entityID].field_0xd0 = 1; + entityType = Map::Entities::ET_BALLISTA; + } else { + if ((entityType == Map::Entities::ET_FIRETHROWER) + || (entityType == Map::Entities::ET_FIRETHROWER_UNTARGETED)) { + bVar1 = TRUE; + } + if (entityType == ((EntityType)0x5c)) { + bVar1 = TRUE; + this->entityArray[entityID].rng_2 = 1; + entityType = ((EntityType)0x18); + } else if (entityType == ((EntityType)0x5d)) { + bVar1 = TRUE; + this->entityArray[entityID].rng_2 = 2; + entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } else if (entityType == ((EntityType)0x5e)) { + bVar1 = TRUE; + this->entityArray[entityID].rng_2 = 2; + entityType = ((EntityType)0x18); + } else if (entityType == ((EntityType)0x1b)) { + targetX = targetX + -0xa0 + ((int)SEC_RNG::instance.currentNumber2 % 0x50) * 4; + targetY = targetY + -0xa0 + (((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x50) * 4; + } else if (entityType == ((EntityType)0x20)) { + targetX = targetX + -0x18 + (int)SEC_RNG::instance.currentNumber2 % 0x30; + targetY = targetY + -0x18 + ((int)SEC_RNG::instance.currentNumber2 >> 8) % 0x30; + } + } + switch (entityType) { + case Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_CATAPULT: + case Map::Entities::ET_TREBUCHET: + case Map::Entities::ET_MANGONEL: + case Map::Entities::ET_CROSSBOWARROW: + case Map::Entities::ET_BALLISTA: + case Map::Entities::ET_COW_FLYING: + case ((EntityType)0x18): + case ((EntityType)0x19): + case ((EntityType)0x1b): + case ((EntityType)0x20): + case Map::Entities::ET_SLINGER: + case Map::Entities::ET_FIRETHROWER: + case Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT: + case Map::Entities::ET_FIRETHROWER_UNTARGETED: + case Map::Entities::ET_FIREBALLISTA: + case ((EntityType)0x5b): + case ((EntityType)0x5c): + case ((EntityType)0x5d): + case ((EntityType)0x5e): + uVar6 = microY / 8; + uVar5 = microX / 8; + if (((399 < uVar5) || (399 < uVar6)) || (*(char*)(uVar6 * 400 + 0x21aec98 + uVar5) == '\0')) { + return 0; + } + uVar6 = targetY / 8; + uVar5 = targetX / 8; + if (399 < uVar5) { + return 0; + } + if (399 < uVar6) { + return 0; + } + if (*(char*)(uVar6 * 400 + 0x21aec98 + uVar5) == '\0') { + return 0; + } + } + if ((int)entityID < 0x19) { + this->entityArray[entityID].uid = 0; + } else { + this->entityArray[entityID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1; + } + dVar2 = DAT_GameCore::instance.mapTimeInTicks; + this->entityArray[entityID].targetY = (short)targetY; + this->entityArray[entityID].unitID_OR_seaGullID = (short)unitID; + this->entityArray[entityID].targetZ = (short)targetZUnk; + this->entityArray[entityID].field_0x34 = dVar2; + this->entityArray[entityID].unitID = (short)param_11; + this->entityArray[entityID].owner = (short)playerID1; + this->entityArray[entityID].microX = (short)microX; + this->entityArray[entityID].heightDifference = targetZUnk - totalHeight; + this->entityArray[entityID].x_2 = (short)microX; + this->entityArray[entityID].logicalState = 1; + this->entityArray[entityID].microY = (short)microY; + this->entityArray[entityID].targetX = (short)targetX; + this->entityArray[entityID].y_2 = (short)microY; + sVar7 = (short)totalHeight; + this->entityArray[entityID].height = sVar7; + this->entityArray[entityID].startingHeight_2 = sVar7; + this->entityArray[entityID].height_2 = sVar7; + this->entityArray[entityID].startingHeight = sVar7; + this->entityArray[entityID].blendStrength = 0; + /* + sets DAT_TempBuildingOrientation + */ + MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance, + DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); + this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; + if (DAT_GameSynchronyState::instance.currentGameMode != 0) { + this->entityArray[entityID].colorUnk = 0; + } else { + this->entityArray[entityID].colorUnk = 0; + } + if ((((entityType == Map::Entities::ET_FLAG_1) || (entityType == Map::Entities::ET_FLAG_4)) + || (entityType == Map::Entities::ET_FLAG_2)) + || (entityType == Map::Entities::ET_FLAG_3)) { + this->entityArray[entityID].colorUnk = ownerColorUnk; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::setProjectileEntityValues2, this)(entityID, entityType); + if (this->entityArray[entityID].rng_2 != 0) { + this->entityArray[entityID].gmID = 0x91; + } + this->entityArray[entityID].field_0x12 = 0; + this->entityArray[entityID].unknownAnimationFrameRelated = 0; + if (entityType == Map::Entities::ET_DUST_CLOUD) { + if (param_11 == 1) { + this->entityArray[entityID].unknownAnimationFrameRelated = 200; + } + } + if (entityType == ((EntityType)8)) { + this->entityArray[entityID].rng_1 = DAT_UnitsState::instance.units[unitID].fixedRng; + } else { + this->entityArray[entityID].rng_1 = (int)SEC_RNG::instance.currentNumber2; + if ((int)entityID >= 25) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + if (entityType == Map::Entities::ET_SEAGULLUnk) { + this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 100 + 120; + } else if (entityType == ((EntityType)0x1f)) { + if (unitID) { + this->entityArray[entityID].unkOne_1 = 2; + } + } else if (entityType == Map::Entities::ET_HEADS_ON_SPIKES) { + this->entityArray[entityID].rng_2 = SEC_RNG::instance.currentNumber2 % 500 + 300; + this->entityArray[entityID].rng_1 = ownerColorUnk; + } + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::initializeProjectileVelocities, this)( + entityID, microX, microY, totalHeight, targetX, targetY, targetZUnk); + if (this->entityArray[entityID].entityType == ((EntityType)0x18)) { + this->entityArray[entityID].entityType = Map::Entities::ET_ARROW_AND_DEFAULT; + } + if (this->entityArray[entityID].entityType == ((EntityType)0x19)) { + this->entityArray[entityID].entityType = Map::Entities::ET_CROSSBOWARROW; + } + if (this->entityArray[entityID].entityType + == (Map::Entities::ET_FIRETHROWER | Map::Entities::ET_ARROW_AND_DEFAULT)) { + this->entityArray[entityID].entityType = Map::Entities::ET_SLINGER; + } + if (this->entityArray[entityID].entityType == Map::Entities::ET_FIRETHROWER_UNTARGETED) { + this->entityArray[entityID].entityType = Map::Entities::ET_FIRETHROWER; + } + if (bVar1) { + this->entityArray[entityID].gmLookupValue = 1; + } + if (entityID) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)(entityID); + uVar5 = DAT_CurrentEntityID::instance; + DAT_CurrentEntityID::instance = entityID; + ((void (*)())DAT_EntityDefinedData::instance + .EntityCallbacks[(short)this->entityArray[entityID].entityType])(); + DAT_CurrentEntityID::instance = uVar5; + } + return entityID; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp new file mode 100644 index 0000000000..28cf5ad4a0 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -0,0 +1,323 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x00405DA0 + void EntityState::spawnProjectileImpactDebris(int param_1) + { + int const microX = this->entityArray[param_1].microX; + int const microY = this->entityArray[param_1].microY; + int targetX = 0; + int targetY = 0; + int y = microY & 7; + int x = microX & 7; + uint const wallFlags = MACRO_CALL_MEMBER(Map::TileMapState_Func::setBitFlagBasedOnWallTowerGatehouseOrKeep, + DAT_TileMapState::ptr)(microX / 8, microY / 8); + switch (this->entityArray[param_1].orientation) { + case 0x3c: + case 0x40: + case 0x44: + case 0x48: + straight: + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + break; + case 0x3d: + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { + case 2: + x = 100; + break; + case 0: + case 8: + y = 100; + break; + case 0xa: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3e: + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { + case 2: + x = 100; + break; + case 0: + case 8: + y = 100; + break; + case 0xa: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x3f: + y = 7 - y; + if (x == y) { + switch (wallFlags & 0xa) { + case 8: + y = 100; + break; + case 0: + case 2: + x = 100; + break; + case 0xa: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x41: + if (x == y) { + switch (wallFlags & 0x82) { + case 0x80: + x = 100; + break; + case 0: + case 2: + y = 100; + break; + case 0x82: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x42: + if (x == y) { + switch (wallFlags & 0x82) { + case 0x80: + x = 100; + break; + case 0: + case 2: + y = 100; + break; + case 0x82: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x43: + if (x == y) { + switch (wallFlags & 0x82) { + case 2: + y = 100; + break; + case 0: + case 0x80: + x = 100; + break; + case 0x82: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x45: + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { + case 0x20: + x = 100; + break; + case 0: + case 0x80: + y = 100; + break; + case 0xa0: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x46: + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { + case 0x20: + x = 100; + break; + case 0: + case 0x80: + y = 100; + break; + case 0xa0: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x47: + x = 7 - x; + if (x == y) { + switch (wallFlags & 0xa0) { + case 0x80: + y = 100; + break; + case 0: + case 0x20: + x = 100; + break; + case 0xa0: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x49: + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { + case 8: + y = 100; + break; + case 0: + case 0x20: + x = 100; + break; + case 0x28: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x4a: + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { + case 0x20: + x = 100; + break; + case 0: + case 8: + y = 100; + break; + case 0x28: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + case 0x4b: + x = 7 - x; + y = 7 - y; + if (x == y) { + switch (wallFlags & 0x28) { + case 0x20: + x = 100; + break; + case 0: + case 8: + y = 100; + break; + case 0x28: + goto straight; + } + } + if (x > y) { + targetX = this->entityArray[param_1].microX * 2 - this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].y_2; + } else { + targetX = this->entityArray[param_1].x_2; + targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + } + break; + } + for (int i = 0; i < this->entityArray[param_1].rng_1 % 8 + 5; i++) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, microX, microY, + this->entityArray[param_1].height, targetX, targetY, 8, ((EntityType)0x1b), 0); + } + int const height = this->entityArray[param_1].height; + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( + 0, 0, 0, microX, microY, height, microX + 1, microY + 1, height, ((EntityType)0x1e), 0); + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp new file mode 100644 index 0000000000..33512efc62 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -0,0 +1,284 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004087C0 + void EntityState::updateEntities() + { + if (DAT_GameState::instance.gameTicksLoadBalancer % 10 == 0) { + this->everyTenTicks = 25; + } + this->totalEntityCount = 0; + int newMaxEntityCount = 0; + for (DAT_CurrentEntityID::instance = 1; (int)DAT_CurrentEntityID::instance < this->maxEntityCount; + DAT_CurrentEntityID::instance = DAT_CurrentEntityID::instance + 1) { + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 0) { + continue; + } + newMaxEntityCount = DAT_CurrentEntityID::instance + 1; + this->totalEntityCount = this->totalEntityCount + 1; + switch (this->entityArray[DAT_CurrentEntityID::instance].logicalState) { + case 1: + this->entityArray[DAT_CurrentEntityID::instance].logicalState = 2; + break; + case 5: + this->entityArray[DAT_CurrentEntityID::instance].logicalState = 6; + break; + case 4: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::activateProjectileEntity, this)( + DAT_CurrentEntityID::instance); + break; + case 7: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + continue; + case 8: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::tickEntityDecayCounter, this)( + DAT_CurrentEntityID::instance); + break; + case 3: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + DAT_CurrentEntityID::instance); + continue; + } + if (DAT_CurrentEntityID::instance + == this->entityArray[DAT_CurrentEntityID::instance].nextEntityOnThisTileByID) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::deleteEntity, this)( + DAT_CurrentEntityID::instance); + continue; + } + if (this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + >= this->entityArray[DAT_CurrentEntityID::instance].unkOne_1) { + this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated + 1; + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 = 0; + } + this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + = this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].logicalState != 6) { + switch (this->entityArray[DAT_CurrentEntityID::instance].entityType) { + case Map::Entities::ET_FIRE: + break; + case Map::Entities::ET_DUST_CLOUD: + if (this->entityArray[DAT_CurrentEntityID::instance].unitID != 2) { + if (this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + short const stepX = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + int const frameX + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepX < 0) { + if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + } + } else if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + } + short const stepY = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + int const frameY + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepY < 0) { + if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + } + } else if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); + } + } else { + if (this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated & 1) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + int const frameX + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + short const stepX = this->entityArray[DAT_CurrentEntityID::instance].startingAngle; + if (stepX < 0) { + if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + } + } else if (frameX % stepX == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + } + short const stepY = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk; + int const frameY + = this->entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated; + if (stepY < 0) { + if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + } + } else if (frameY % stepY == 0) { + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, + this)(DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); + } + } + break; + case Map::Entities::EntityTypeInt__ET_EXPLOSION: + case Map::Entities::ET_GOLD_POPUP: + case Map::Entities::ET_POPULARITY_POPUP: + case Map::Entities::ET_TRADE_BUY_POPUP: + case Map::Entities::ET_TRADE_SELL_POPUP: + this->entityArray[DAT_CurrentEntityID::instance].height + = this->entityArray[DAT_CurrentEntityID::instance].height + 1; + break; + case Map::Entities::ET_COW_POISON_CLOUD: + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk > 30) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, + this)(DAT_CurrentEntityID::instance); + if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - 1; + if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk <= 0) { + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk + = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); + this->entityArray[DAT_CurrentEntityID::instance].startingAngle + = ((char)SEC_RNG::instance.currentNumber2 >> 4) & 7U; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + } + } + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk = 0; + switch (this->entityArray[DAT_CurrentEntityID::instance].startingAngle) { + case 0: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 4: + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 2: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + break; + case 6: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + break; + case 7: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 1: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY - 1; + break; + case 5: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + case 3: + this->entityArray[DAT_CurrentEntityID::instance].microX + = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY + = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + break; + } + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::calculateEntityDrawOffset, this)( + DAT_CurrentEntityID::instance); + } + this->entityArray[DAT_CurrentEntityID::instance].height + = DAT_TileMapState::instance + .HeightLayer[this->entityArray[DAT_CurrentEntityID::instance].tile] + + 20; + break; + case Map::Entities::ET_FLAG_1: + case Map::Entities::ET_FLAG_4: + case Map::Entities::ET_FLAG_2: + case Map::Entities::ET_FLAG_3: + case Map::Entities::ET_BRAZIER: + case Map::Entities::ET_HEADS_ON_SPIKES: + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)( + DAT_CurrentEntityID::instance); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( + DAT_CurrentEntityID::instance); + break; + default: + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = (short)this->entityArray[DAT_CurrentEntityID::instance].orientation - 60; + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = this->entityArray[DAT_CurrentEntityID::instance].screenDirection + - (short)DAT_TileMapState::instance.mapOrientation * 2; + if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { + this->entityArray[DAT_CurrentEntityID::instance].screenDirection + = this->entityArray[DAT_CurrentEntityID::instance].screenDirection + 16; + } + if (this->entityArray[DAT_CurrentEntityID::instance].speedUnk != 0.0 + && this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 0 + && this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + if (this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 3) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( + this->entityArray[DAT_CurrentEntityID::instance].microX, + this->entityArray[DAT_CurrentEntityID::instance].microY, + this->entityArray[DAT_CurrentEntityID::instance].height, (EntityType)5, + this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue); + } else { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect1, this)( + this->entityArray[DAT_CurrentEntityID::instance].microX, + this->entityArray[DAT_CurrentEntityID::instance].microY, + this->entityArray[DAT_CurrentEntityID::instance].height, (EntityType)6, + this->entityArray[DAT_CurrentEntityID::instance].gmID, + this->entityArray[DAT_CurrentEntityID::instance].graphicType2); + } + } + if (this->entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 0) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::moveProjectileEntity, this)( + DAT_CurrentEntityID::instance); + } + } + } + ((void (*)())DAT_EntityDefinedData::instance + .EntityCallbacks[this->entityArray[DAT_CurrentEntityID::instance].entityType])(); + if (this->entityArray[DAT_CurrentEntityID::instance].entityType == Map::Entities::ET_SEAGULLUnk) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processSeaGulls, this)( + this->entityArray[DAT_CurrentEntityID::instance].unitID_OR_seaGullID); + } + } + this->maxEntityCount = newMaxEntityCount; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp new file mode 100644 index 0000000000..ac8e3047a9 --- /dev/null +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -0,0 +1,30 @@ +#include "../../../Map.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + + // FUNCTION: STRONGHOLDCRUSADER 0x004081E0 + void EntityState::updateProjectileHeightAndCollision( + uint entityID, undefined4 param_2, int param_3, int param_4) + { + this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + (short)param_2; + if (this->entityArray[entityID].height <= 2 && !param_4) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); + } + short const currentHeight = this->entityArray[entityID].height; + if (currentHeight > 10000) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::markEntityDestroyed, this)(entityID); + return; + } + this->entityArray[entityID].rotationFrameIndex + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); + this->entityArray[entityID].height_2 = currentHeight; + } + + } +} +} diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp new file mode 100644 index 0000000000..65e6c18824 --- /dev/null +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -0,0 +1,88 @@ +#include "../../Map.func.hpp" +#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/Entities/EntityType.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 { + + using Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004052E0 + uint Entities::IgniteFireAtMiniTile( + int playerID, int miniTileX, int miniTileY, int tileHeightMin8, int two, int fireIntensity) + { + uint const randomJitter = (uint)SEC_RNG::instance.currentNumber2; + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + miniTileX += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][0]; + miniTileY += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[randomJitter & 0x3f][1]; + uint const x = miniTileX / 8; + uint const y = miniTileY / 8; + if (x > 399 || y > 399) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + return 0; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x10300131U)) { + short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID) { + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case Map::Buildings::BT_GATEHOUSELARGE: + case Map::Buildings::BT_GATEHOUSESMALL: + case Map::Buildings::BT_TOWER1: + case Map::Buildings::BT_TOWER2: + case Map::Buildings::BT_TOWER3: + case Map::Buildings::BT_TOWER4: + case Map::Buildings::BT_TOWER5: + return 0; + } + } + int const fireID + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(tile); + if (fireID) { + DAT_EntityState::instance.entityArray[fireID].someTracker = 0; + if (two > DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6) { + DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6 = (short)two; + } + DAT_EntityState::instance.entityArray[fireID].unknownAnimationFrameRelated = 0; + return 0; + } + if (buildingID) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( + buildingID, playerID, fireIntensity); + } + if (DAT_TileMapState::instance.LogicLayer[tile] & 0x1000U) { + MACRO_CALL_MEMBER(Map::LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID); + } + uint const entityID + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( + 0, playerID, 0, miniTileX, miniTileY, tileHeightMin8, 0, 0, 0, Map::Entities::ET_FIRE, 0); + if (two >= 3 && !(DAT_TileMapState::instance.RandomLayer[tile] & 3)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)( + 0, playerID, 0, miniTileX, miniTileY, tileHeightMin8, 0, 0, 0, (EntityType)26, 0); + } + if (entityID) { + DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = (short)two; + DAT_EntityState::instance.entityArray[entityID].fireIntensity = (short)fireIntensity; + } + return entityID; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp new file mode 100644 index 0000000000..a55b80959d --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -0,0 +1,47 @@ +#include "../../Map.func.hpp" +#include "../Entities.func.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00402180 + void Entities::UpdateEntity_CowFlying() + { + int const entityID = DAT_CurrentEntityID::instance; + if (DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround != 0) { + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated < 100) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 100; + } + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 120) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 119; + } + short* const counter = &DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround; + *counter = *counter - 1; + if (*counter <= 0) { + DAT_EntityState::instance.entityArray[entityID].logicalState = 7; + } + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated - 100) / 4 + 0xc + + DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset; + DAT_EntityState::instance.entityArray[entityID].imageID = 0; + } else { + if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 12) { + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 0; + } + DAT_EntityState::instance.entityArray[entityID].graphicType2 + = DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset + + DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated; + DAT_EntityState::instance.entityArray[entityID].imageID + = (short)(DAT_EntityState::instance.entityArray[entityID].graphicType2 + 0x11); + } + if (DAT_EntityState::instance.entityArray[entityID].orientation == 0x4c) { + DAT_EntityState::instance.entityArray[entityID].orientation = 0x3c; + DAT_EntityState::instance.entityArray[entityID].logicalState = 7; + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp new file mode 100644 index 0000000000..e923db68bf --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateFireEntity.cpp @@ -0,0 +1,256 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +#include + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00405680 + void Entities::UpdateFireEntity() + { + short const fireParameter + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6; + if (fireParameter == 5) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 8; + } else if (fireParameter == 4) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 9; + } else if (fireParameter == 3) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 12; + } else if (fireParameter == 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 14; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 16; + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x76; + short const tracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + int frame = 0; + if (tracker < 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].blendStrength = 32; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker + 1; + frame = 1; + } else if (tracker == 0) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames3[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames5[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } + } else if (tracker == 1) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames7[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames8[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } + } else if (tracker == 2) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 >= 3) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_1 & 0x80) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames4[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].gmID = 0x90; + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames6[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } else { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 == 2) { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } else { + frame + = (char)DAT_EntityDefinedData::instance + .FireAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + } + } + } + if (frame <= 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + short const state = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + if (state == 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 1; + } else if (state == 1) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround == 6 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 > 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 = 2; + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + 1; + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround > 8) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; + } + if (DAT_TileMapState::instance + .BuildingLayer[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile] + != 0 + && MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::getBuildingFlammabilityFactor, + DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile])) { + if (DAT_BuildingsState::instance + .buildings[DAT_TileMapState::instance.BuildingLayer + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile]] + .fireDuration + != 0) { + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 + < 3) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 = 3; + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 1; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround + = 0; + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = 2; + } + } + } else if (state == 2) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 3; + } + } else { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 = frame; + } + if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker == 0 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated == 1) { + short const direction = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8; + int const tile = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile; + int const height = DAT_TileMapState::instance.HeightLayer[tile]; + if (direction < 4 + && DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 > 1) { + if (direction == 0) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + tile - 1)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX - 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 1) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + tile + 1)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX + 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 2) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + + 1] + .addXgetTile)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY + 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } else if (direction == 3) { + if (abs(height + - MACRO_CALL_MEMBER(Map::TileMapState_Func::getTotalHeightAtTile, DAT_TileMapState::ptr)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].xPosition + + DAT_ViewportRenderState::instance + .translationMatrix + [DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition + - 1] + .addXgetTile)) + < 25) { + MACRO_CALL(Map::Entities_Func::IgniteFireAtMiniTile)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microX, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].microY - 8, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].height, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireParameter_0xb6 - 1, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].field_0xb8 + 1; + } + } + if (!(DAT_TileMapState::instance + .LogicLayer[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile] + & 0xba7001b1)) { + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processFireDamageToUnitsAtTile, DAT_EntityState::ptr)( + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].tile, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner, + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].fireIntensity); + } + } + +} +} diff --git a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp new file mode 100644 index 0000000000..50a72a2821 --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -0,0 +1,83 @@ +#include "../../Map.func.hpp" +#include "../Entities.func.hpp" + +#include "OpenSHC/AI/AIRecruitUnitChoice.hpp" +#include "OpenSHC/AI/AIRecruitUnitChoiceInt.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" +#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" + +namespace OpenSHC { +namespace Map { + + using AI::AIRecruitUnitChoice; + using AI::AIRecruitUnitChoiceInt; + using Game::GameMode; + + // FUNCTION: STRONGHOLDCRUSADER 0x00402900 + void Entities::UpdateFlag_1_2_4_Entity() + { + int nextTracker = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker; + int const owner = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].owner; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset; + if (((byte)DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition & 0x1f) + >= DAT_LandscapeState::instance.wind.countdown) { + nextTracker = DAT_LandscapeState::instance.wind.value; + } + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentPlayerFullIDArray[owner] == -1 + && DAT_GameSynchronyState::instance.currentAIArray[owner] != 0) { + if (DAT_GameState::instance.playerDataArray[owner].aiBuildingDestroyChoiceTracker != 0) { + nextTracker = 3; + } else if (DAT_GameState::instance.playerDataArray[owner].aiNervousActionsTracker != 0) { + nextTracker = 3; + } else { + AIRecruitUnitChoiceInt const recruitChoice + = DAT_GameState::instance.playerDataArray[owner].aiRecruitUnitChoiceState; + nextTracker = 0; + if (recruitChoice != AI::AIRUC_DEFENSIVE) { + nextTracker = (recruitChoice != AI::AIRUC_RAIDING) + 1; + } + } + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkOne_1 = 3; + int frame; + switch (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker) { + case 0: + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames1[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + break; + case 1: + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames2[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + break; + case 3: + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unkOne_1 = 1; + /* falls through into case 2 */ + case 2: + frame = DAT_EntityDefinedData::instance + .FlagAnimationFrames3[DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance] + .unknownAnimationFrameRelated]; + break; + default: + return; + } + if (frame <= 0) { + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].unknownAnimationFrameRelated = 0; + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someTracker = nextTracker; + return; + } + DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + = DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2 + frame - 1; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..706b969265 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -469,7 +469,7 @@ SHC_3BB0A8C1_0x00401EA0 | 0.0% | Pending SHC_3BB0A8C1_0x00401FF0 | 0.0% | Pending -SHC_3BB0A8C1_0x00402180 | 0.0% | Pending +SHC_3BB0A8C1_0x00402180 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00402260 | 0.0% | Pending @@ -491,7 +491,7 @@ SHC_3BB0A8C1_0x00402730 | 0.0% | Pending SHC_3BB0A8C1_0x00402820 | 0.0% | Pending -SHC_3BB0A8C1_0x00402900 | 0.0% | Pending +SHC_3BB0A8C1_0x00402900 | 68.2% | original keeps 0 in edi, ours uses immediates SHC_3BB0A8C1_0x00402A0C | 0.0% | Pending @@ -517,17 +517,17 @@ SHC_3BB0A8C1_0x00402BC8 | 0.0% | Pending SHC_3BB0A8C1_0x00402BCC | 0.0% | Pending -SHC_3BB0A8C1_0x00402BD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402C50 | 0.0% | Pending +SHC_3BB0A8C1_0x00402C50 | 79.2% | the original spills param_4 * 4 and heightDifference / 2 into their own parameter slots (fild/fimul from [ebp+0x14]/[ebp+0x18]), we use a temp SHC_3BB0A8C1_0x00402DA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00402E20 | 0.0% | Pending +SHC_3BB0A8C1_0x00402E20 | 57.8% | frame/register allocation: the original keeps clearance in ebp and adds 10 to height in its parameter slot, ours keeps height in ebp; slot order differs (slot_map: ours 19 slots, original 17). The separate set-up/stepping dispatch is right: inlining each stepping loop into its set-up branch drops to 32.6, because the original lays the loop bodies out in dispatch order 3, 0, 2, 1 SHC_3BB0A8C1_0x00403200 | 0.0% | Pending -SHC_3BB0A8C1_0x004036F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004036F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403790 | 100.0% | Pending @@ -543,9 +543,9 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 0.0% | Pending +SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) -SHC_3BB0A8C1_0x00403FF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) SHC_3BB0A8C1_0x004044E4 | 0.0% | Pending @@ -1183,7 +1183,7 @@ SHC_3BB0A8C1_0x00404A10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00404A70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00404AE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00404AE0 | 98.4% | entityID and the constant 1 swap edi/ebp; field-store scheduling (targetX before targetY measured worse) SHC_3BB0A8C1_0x00404B70 | 0.0% | Pending @@ -1623,7 +1623,7 @@ SHC_3BB0A8C1_0x00405125 | 0.0% | Pending SHC_3BB0A8C1_0x00405130 | 100.0% | Reimplemented (counted: only the constant 0x10300131 is shown as an address label in ours) -SHC_3BB0A8C1_0x004052E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004052E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004054AC | 0.0% | Pending @@ -1699,7 +1699,7 @@ SHC_3BB0A8C1_0x004054D5 | 0.0% | Pending SHC_3BB0A8C1_0x004054E0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405680 | 0.0% | Pending +SHC_3BB0A8C1_0x00405680 | 85.3% | IgniteFireAtMiniTile argument scheduling picks different tail-merge points SHC_3BB0A8C1_0x00405B70 | 100.0% | Reimplemented @@ -1707,7 +1707,7 @@ SHC_3BB0A8C1_0x00405C00 | 0.0% | Pending SHC_3BB0A8C1_0x00405CF0 | 100.0% | Pending -SHC_3BB0A8C1_0x00405DA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00405DA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0040612C | 0.0% | Pending @@ -2343,7 +2343,7 @@ SHC_3BB0A8C1_0x00406648 | 0.0% | Pending SHC_3BB0A8C1_0x00406650 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00406900 | 0.0% | Pending +SHC_3BB0A8C1_0x00406900 | 90.8% | newY takes ebp where the original spills it and keeps newMicroX in ebp; the microY reload comes from reading it through a reference SHC_3BB0A8C1_0x00406FD0 | 0.0% | Pending @@ -2351,7 +2351,7 @@ SHC_3BB0A8C1_0x00407130 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00407160 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00407190 | 0.0% | Pending +SHC_3BB0A8C1_0x00407190 | 84.2% | register rotation in the height arms (the original keeps both plain HeightLayer stores, we tail-merge them); unit-loop entry jumps SHC_3BB0A8C1_0x00407570 | 0.0% | Pending @@ -2441,7 +2441,7 @@ SHC_3BB0A8C1_0x004081D4 | 0.0% | Pending SHC_3BB0A8C1_0x004081D5 | 0.0% | Pending -SHC_3BB0A8C1_0x004081E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004081E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00408250 | 100.0% | Reimplemented @@ -2449,11 +2449,11 @@ SHC_3BB0A8C1_0x004082A0 | 0.0% | Pending SHC_3BB0A8C1_0x004083A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004084A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004084A0 | 94.8% | x87 operand order in the atan argument; loop-top alignment pad from the function address SHC_3BB0A8C1_0x00408770 | 0.0% | Pending -SHC_3BB0A8C1_0x004087C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004087C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00408D90 | 0.0% | Pending