From 5a6e4eb01e1bff679968a2fe34271315803604fc Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:25 +0100 Subject: [PATCH 01/18] Entities: /GL and visibility entries for the matched projectile/fire functions angleToRotationFrameIndex and updateProjectileHeightAndCollision are built with /GL so their callers see their register use, and IgniteFireAtMiniTile is built with /GL with getFireEntityIDAtTile made visible to it. Taken from draft #527. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- cmake/compiler-flags-gl.txt | 3 + cmake/function-visibility.txt | 2 + .../EntityState/angleToRotationFrameIndex.cpp | 44 ++ .../EntityState/calculateEntityDrawOffset.cpp | 44 ++ .../handleProjectileWallBounce.cpp | 382 ++++++++++++++++++ .../initializeProjectileVelocities.cpp | 187 +++++++++ .../spawnProjectileImpactDebris.cpp | 323 +++++++++++++++ .../Entities/EntityState/updateEntities.cpp | 284 +++++++++++++ .../updateProjectileHeightAndCollision.cpp | 30 ++ .../Map/Entities/IgniteFireAtMiniTile.cpp | 88 ++++ .../Map/Entities/UpdateEntity_CowFlying.cpp | 47 +++ 11 files changed, 1434 insertions(+) create mode 100644 src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp create mode 100644 src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp create mode 100644 src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp create mode 100644 src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index cc2e343848..5df6d77f40 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -448,5 +448,8 @@ 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 diff --git a/cmake/function-visibility.txt b/cmake/function-visibility.txt index b5531cf747..6a941bb236 100644 --- a/cmake/function-visibility.txt +++ b/cmake/function-visibility.txt @@ -360,3 +360,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/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/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; + } + } + +} +} From 86830adc2fd8c73eed485b02edfc5febf36ac94c Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:26 +0100 Subject: [PATCH 02/18] reimplement: SHC_3BB0A8C1_0x00402180 UpdateEntity_CowFlying 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x00402180 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp | 12 ++++++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp index a55b80959d..a65de640ae 100644 --- a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -1,4 +1,3 @@ -#include "../../Map.func.hpp" #include "../Entities.func.hpp" #include "OpenSHC/Globals/DAT_CurrentEntityID.hpp" @@ -18,13 +17,14 @@ namespace Map { if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 120) { DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 119; } + // Decrementing the field directly instead of through this pointer measured 86.4% instead of 100% short* const counter = &DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround; - *counter = *counter - 1; + (*counter)--; 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].unknownAnimationFrameRelated - 100) / 4 + 12 + DAT_EntityState::instance.entityArray[entityID].graphicType2RelatedOffset; DAT_EntityState::instance.entityArray[entityID].imageID = 0; } else { @@ -35,10 +35,10 @@ namespace Map { = 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); + = (short)(DAT_EntityState::instance.entityArray[entityID].graphicType2 + 17); } - if (DAT_EntityState::instance.entityArray[entityID].orientation == 0x4c) { - DAT_EntityState::instance.entityArray[entityID].orientation = 0x3c; + if (DAT_EntityState::instance.entityArray[entityID].orientation == 76) { + DAT_EntityState::instance.entityArray[entityID].orientation = 60; DAT_EntityState::instance.entityArray[entityID].logicalState = 7; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b31ea5fc2b..913e67dae7 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 From 3caaae991f4891eb2f3cb9c60d8112b528fa9901 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:26 +0100 Subject: [PATCH 03/18] reimplement: SHC_3BB0A8C1_0x00402BD0 angleToRotationFrameIndex 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x00402BD0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Entities/EntityState/angleToRotationFrameIndex.cpp | 4 +--- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp index 16b8aebd69..e333edeeb9 100644 --- a/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp @@ -1,6 +1,4 @@ -#include "../../../Map.func.hpp" - -#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "../EntityState.func.hpp" namespace OpenSHC { namespace Map { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 913e67dae7..30810292b9 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -517,7 +517,7 @@ 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 From c8bb4c9a80c405b22573f2531525b7c82705338b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:27 +0100 Subject: [PATCH 04/18] reimplement: SHC_3BB0A8C1_0x004036F0 calculateEntityDrawOffset 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x004036F0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../EntityState/calculateEntityDrawOffset.cpp | 12 +++++++----- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index 9302030f8b..e230bedfe8 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -1,6 +1,7 @@ -#include "../../../Map.func.hpp" #include "../EntityState.func.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -13,19 +14,20 @@ namespace Map { { uint x = (byte)this->entityArray[entityID].microX & 7; uint y = (byte)this->entityArray[entityID].microY & 7; - if (DAT_TileMapState::instance.mapOrientation == 4) { + // The gotos keep the original's two shared blocks (rotate, lookup) emitted once. + if (DAT_TileMapState::instance.mapOrientation == Enums::MO_SOUTH) { x = 7 - x; y = 7 - y; } else { - if (DAT_TileMapState::instance.mapOrientation == 2) { + if (DAT_TileMapState::instance.mapOrientation == Enums::MO_EAST) { x = 7 - x; goto rotate; } - if (DAT_TileMapState::instance.mapOrientation == 6) { + if (DAT_TileMapState::instance.mapOrientation == Enums::MO_WEST) { y = 7 - y; goto rotate; } - if (DAT_TileMapState::instance.mapOrientation) { + if (DAT_TileMapState::instance.mapOrientation != Enums::MO_NORTH) { rotate: x = x << 4; y = y * 2; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 30810292b9..b49adde23b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -527,7 +527,7 @@ SHC_3BB0A8C1_0x00402E20 | 0.0% | Pending SHC_3BB0A8C1_0x00403200 | 0.0% | Pending -SHC_3BB0A8C1_0x004036F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004036F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403790 | 100.0% | Pending From a1b1124282e2e3e5b772a3179609a596772b429b Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:27 +0100 Subject: [PATCH 05/18] reimplement: SHC_3BB0A8C1_0x00403A20 initializeProjectileVelocities 100.0% From draft #527. Measured 98.5% raw / 94.4% normalized on main 46f21c5b9; the only differences are the float constant labels and the _CIcos/_CIsin call targets. Status: SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../initializeProjectileVelocities.cpp | 19 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index b3062f084f..3a528492b5 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -1,6 +1,5 @@ -#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" -#include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" @@ -11,8 +10,6 @@ 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) @@ -113,7 +110,7 @@ namespace Map { } 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; + this->entityArray[entityID].velocityUnk = (rng & 7) + 21; } else if (curveType == 4) { this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 20 + 16); if (this->entityArray[entityID].rng_1 & 0x80) { @@ -149,27 +146,25 @@ namespace Map { } 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; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 35; } 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; + 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; + this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 35; } 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; + 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) { + && height + 54 < targetZ && this->entityArray[entityID].rng_1 % 10 == 5) { this->entityArray[entityID].hasDoneEffectUnk = 1; } int const angle = this->entityArray[entityID].startingAngle; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b49adde23b..471352c889 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ 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 From 98f5ae43455464955531521aaa3a39008aa7d56d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:28 +0100 Subject: [PATCH 06/18] reimplement: SHC_3BB0A8C1_0x00403FF0 handleProjectileWallBounce 100.0% From draft #527. Measured 99.7% raw / 94.9% normalized on main 46f21c5b9; the only differences are the float constant labels and the _CIcos/_CIsin call targets. Status: SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../handleProjectileWallBounce.cpp | 358 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 181 insertions(+), 179 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp index 05b3b4d608..3996750b9a 100644 --- a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -1,10 +1,10 @@ -#include "../../../Map.func.hpp" +#include "../EntityState.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/Map/Enums/NeighbourMask.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" #include "OpenSHC/Globals/DAT_SFXState.hpp" @@ -16,365 +16,367 @@ namespace OpenSHC { namespace Map { namespace Entities { - using DE::SHCDE::eSFX; - // FUNCTION: STRONGHOLDCRUSADER 0x00403FF0 - void EntityState::handleProjectileWallBounce(int param_1) + void EntityState::handleProjectileWallBounce(int entityID) { - int const microY = this->entityArray[param_1].microY; - int const microX = this->entityArray[param_1].microX; + int const microY = this->entityArray[entityID].microY; + int const microX = this->entityArray[entityID].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: + // orientation - 60 is one of sixteen directions; 60, 64, 68 and 72 run along an axis and keep + // their target, the others bounce off the wall side the sub-tile position is closer to. + // The diagonal cases jump back to "straight" when both walls are set: the original shares that block. + switch (this->entityArray[entityID].orientation) { + case 60: + case 64: + case 68: + case 72: straight: - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; break; - case 0x3d: + case 61: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0xa) { - case 2: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_WEST: subX = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: subY = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x3e: + case 62: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0xa) { - case 2: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_WEST: subX = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: subY = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x3f: + case 63: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0xa) { - case 8: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_SOUTH: subY = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: subX = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x41: + case 65: if (subX == subY) { - switch (wallFlags & 0x82) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_NORTH: subX = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: subY = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x42: + case 66: if (subX == subY) { - switch (wallFlags & 0x82) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_NORTH: subX = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: subY = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x43: + case 67: if (subX == subY) { - switch (wallFlags & 0x82) { - case 2: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_WEST: subY = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: subX = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x45: + case 69: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & 0xa0) { - case 0x20: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_EAST: subX = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: subY = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x46: + case 70: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & 0xa0) { - case 0x20: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_EAST: subX = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: subY = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x47: + case 71: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & 0xa0) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_NORTH: subY = 100; break; - case 0: - case 0x20: + case Enums::NM_NONE: + case Enums::NM_EAST: subX = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x49: + case 73: subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0x28) { - case 8: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_SOUTH: subY = 100; break; - case 0: - case 0x20: + case Enums::NM_NONE: + case Enums::NM_EAST: subX = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x4a: + case 74: subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0x28) { - case 0x20: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_EAST: subX = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: subY = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x4b: + case 75: subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & 0x28) { - case 0x20: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_EAST: subX = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: subY = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].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; + this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; if (microY > targetY) { - this->entityArray[param_1].pathDeltaY = (short)(microY - targetY); + this->entityArray[entityID].pathDeltaY = (short)(microY - targetY); } else { - this->entityArray[param_1].pathDeltaY = (short)(targetY - microY); + this->entityArray[entityID].pathDeltaY = (short)(targetY - microY); } if (microX > targetX) { - this->entityArray[param_1].pathDeltaX = (short)(microX - targetX); + this->entityArray[entityID].pathDeltaX = (short)(microX - targetX); } else { - this->entityArray[param_1].pathDeltaX = (short)(targetX - microX); + this->entityArray[entityID].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; + this->entityArray[entityID].pathTargetX = (short)targetX; + this->entityArray[entityID].someMicroX = microX <= targetX ? 1 : -1; + this->entityArray[entityID].pathTargetY = (short)targetY; + this->entityArray[entityID].someMicroY = microY <= targetY ? 1 : -1; + 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[param_1].pathAxisCase = 4; + this->entityArray[entityID].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; + 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; } - word const rotation = this->entityArray[param_1].graphicRotationUnk; - this->entityArray[param_1].startingAngle = rotation; + word const rotation = this->entityArray[entityID].graphicRotationUnk; + this->entityArray[entityID].startingAngle = rotation; if ((short)rotation < -80) { - this->entityArray[param_1].startingAngle = -80; + this->entityArray[entityID].startingAngle = -80; } - int const angle = this->entityArray[param_1].startingAngle; - this->entityArray[param_1].speedUnk = 0; + int const angle = this->entityArray[entityID].startingAngle; + this->entityArray[entityID].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 const velocity = (short)(this->entityArray[entityID].velocityUnk / 8); + this->entityArray[entityID].velocityUnk = velocity; + this->entityArray[entityID].startingHeight = this->entityArray[entityID].height; + this->entityArray[entityID].travelledDistance = 0; + this->entityArray[entityID].vCos = (float)(this->entityArray[entityID].velocityUnk * cos(radians)); + this->entityArray[entityID].vSin = (float)(this->entityArray[entityID].velocityUnk * sin(radians)); + this->entityArray[entityID].rotationFrameIndex = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); - this->entityArray[param_1].gmLookupValue = 0; + this->entityArray[entityID].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); + this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, + DE::SHCDE::FX_ARROW_BOUNCE); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 471352c889..9ff9ebac46 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -545,7 +545,7 @@ SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented 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 From 74e00857ebbcf094a887659ce1f37284acd96c66 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:28 +0100 Subject: [PATCH 07/18] reimplement: SHC_3BB0A8C1_0x004052E0 IgniteFireAtMiniTile 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x004052E0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Entities/IgniteFireAtMiniTile.cpp | 19 ++++++++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index 65e6c18824..1b69879080 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -1,4 +1,3 @@ -#include "../../Map.func.hpp" #include "../Entities.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" @@ -6,6 +5,7 @@ #include "OpenSHC/Map/LandscapeState.func.hpp" #include "OpenSHC/Random/RNG.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" @@ -18,12 +18,16 @@ 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) { + // Tiles that cannot catch fire + enum { + NON_FLAMMABLE_LOGIC = LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE + | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD + | LogicHelpers::L_KEEP_NON_MANOR_HOUSE + }; 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]; @@ -37,7 +41,7 @@ namespace Map { return 0; } int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; - if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x10300131U)) { + if (!(DAT_TileMapState::instance.LogicLayer[tile] & NON_FLAMMABLE_LOGIC)) { short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; if (buildingID) { switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { @@ -65,15 +69,16 @@ namespace Map { MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)( buildingID, playerID, fireIntensity); } - if (DAT_TileMapState::instance.LogicLayer[tile] & 0x1000U) { + if (DAT_TileMapState::instance.LogicLayer[tile] & LogicHelpers::L_TREE) { 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); + MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, + playerID, 0, miniTileX, miniTileY, tileHeightMin8, 0, 0, 0, + Map::Entities::EntityTypeInt__ET_EXPLOSION, 0); } if (entityID) { DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = (short)two; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9ff9ebac46..ac668508f1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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 From 687759761c8712edd71f6064e3e93ccf9d645778 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:29 +0100 Subject: [PATCH 08/18] reimplement: SHC_3BB0A8C1_0x00405DA0 spawnProjectileImpactDebris 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x00405DA0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../spawnProjectileImpactDebris.cpp | 278 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 141 insertions(+), 139 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp index 28cf5ad4a0..3866aa3a13 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -1,8 +1,8 @@ -#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" -#include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Enums/NeighbourMask.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -10,312 +10,314 @@ namespace OpenSHC { namespace Map { namespace Entities { - using Map::Entities::EntityType; - // FUNCTION: STRONGHOLDCRUSADER 0x00405DA0 - void EntityState::spawnProjectileImpactDebris(int param_1) + void EntityState::spawnProjectileImpactDebris(int entityID) { - int const microX = this->entityArray[param_1].microX; - int const microY = this->entityArray[param_1].microY; + int const microX = this->entityArray[entityID].microX; + int const microY = this->entityArray[entityID].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: + // orientation - 60 is one of sixteen directions; 60, 64, 68 and 72 run along an axis and keep + // their target, the others bounce off the wall side the sub-tile position is closer to. + // The diagonal cases jump back to "straight" when both walls are set: the original shares that block. + switch (this->entityArray[entityID].orientation) { + case 60: + case 64: + case 68: + case 72: straight: - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; break; - case 0x3d: + case 61: y = 7 - y; if (x == y) { - switch (wallFlags & 0xa) { - case 2: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_WEST: x = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: y = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x3e: + case 62: y = 7 - y; if (x == y) { - switch (wallFlags & 0xa) { - case 2: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_WEST: x = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: y = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x3f: + case 63: y = 7 - y; if (x == y) { - switch (wallFlags & 0xa) { - case 8: + switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { + case Enums::NM_SOUTH: y = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: x = 100; break; - case 0xa: + case (Enums::NM_WEST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x41: + case 65: if (x == y) { - switch (wallFlags & 0x82) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_NORTH: x = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: y = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x42: + case 66: if (x == y) { - switch (wallFlags & 0x82) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_NORTH: x = 100; break; - case 0: - case 2: + case Enums::NM_NONE: + case Enums::NM_WEST: y = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x43: + case 67: if (x == y) { - switch (wallFlags & 0x82) { - case 2: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { + case Enums::NM_WEST: y = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: x = 100; break; - case 0x82: + case (Enums::NM_NORTH | Enums::NM_WEST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x45: + case 69: x = 7 - x; if (x == y) { - switch (wallFlags & 0xa0) { - case 0x20: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_EAST: x = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: y = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x46: + case 70: x = 7 - x; if (x == y) { - switch (wallFlags & 0xa0) { - case 0x20: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_EAST: x = 100; break; - case 0: - case 0x80: + case Enums::NM_NONE: + case Enums::NM_NORTH: y = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x47: + case 71: x = 7 - x; if (x == y) { - switch (wallFlags & 0xa0) { - case 0x80: + switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { + case Enums::NM_NORTH: y = 100; break; - case 0: - case 0x20: + case Enums::NM_NONE: + case Enums::NM_EAST: x = 100; break; - case 0xa0: + case (Enums::NM_NORTH | Enums::NM_EAST): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x49: + case 73: x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & 0x28) { - case 8: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_SOUTH: y = 100; break; - case 0: - case 0x20: + case Enums::NM_NONE: + case Enums::NM_EAST: x = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x4a: + case 74: x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & 0x28) { - case 0x20: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_EAST: x = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: y = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; - case 0x4b: + case 75: x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & 0x28) { - case 0x20: + switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { + case Enums::NM_EAST: x = 100; break; - case 0: - case 8: + case Enums::NM_NONE: + case Enums::NM_SOUTH: y = 100; break; - case 0x28: + case (Enums::NM_EAST | Enums::NM_SOUTH): 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; + targetX = this->entityArray[entityID].microX * 2 - this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].y_2; } else { - targetX = this->entityArray[param_1].x_2; - targetY = this->entityArray[param_1].microY * 2 - this->entityArray[param_1].y_2; + targetX = this->entityArray[entityID].x_2; + targetY = this->entityArray[entityID].microY * 2 - this->entityArray[entityID].y_2; } break; } - for (int i = 0; i < this->entityArray[param_1].rng_1 % 8 + 5; i++) { + // 5 to 12 pieces of debris; entity type 27 has no name yet + for (int i = 0; i < this->entityArray[entityID].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); + this->entityArray[entityID].height, targetX, targetY, 8, (EntityType)27, 0); } - int const height = this->entityArray[param_1].height; + int const height = this->entityArray[entityID].height; MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)( - 0, 0, 0, microX, microY, height, microX + 1, microY + 1, height, ((EntityType)0x1e), 0); + 0, 0, 0, microX, microY, height, microX + 1, microY + 1, height, ET_UNKNOWN_30, 0); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ac668508f1..440d75864d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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 From a2e2d817b451edf489194f6a8b4b034d72304bf9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:29 +0100 Subject: [PATCH 09/18] reimplement: SHC_3BB0A8C1_0x004081E0 updateProjectileHeightAndCollision 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x004081E0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../updateProjectileHeightAndCollision.cpp | 12 +++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp index ac8e3047a9..a1365169ec 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -1,6 +1,4 @@ -#include "../../../Map.func.hpp" - -#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "../EntityState.func.hpp" namespace OpenSHC { namespace Map { @@ -8,10 +6,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004081E0 void EntityState::updateProjectileHeightAndCollision( - uint entityID, undefined4 param_2, int param_3, int param_4) + uint entityID, undefined4 heightOffset, int angle, int skipCollision) { - this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + (short)param_2; - if (this->entityArray[entityID].height <= 2 && !param_4) { + this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + (short)heightOffset; + if (this->entityArray[entityID].height <= 2 && !skipCollision) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); } @@ -21,7 +19,7 @@ namespace Map { return; } this->entityArray[entityID].rotationFrameIndex - = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(param_3); + = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); this->entityArray[entityID].height_2 = currentHeight; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 440d75864d..c8d1b9a151 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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 From 71c4ee8006429faef2a70b2448c2c65e7c652719 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 15:39:30 +0100 Subject: [PATCH 10/18] reimplement: SHC_3BB0A8C1_0x004087C0 updateEntities 100.0% From draft #527. Measured 100.0% raw on main 46f21c5b9. Status: SHC_3BB0A8C1_0x004087C0 | 100.0% | Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Entities/EntityState/updateEntities.cpp | 98 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 35 insertions(+), 65 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index 33512efc62..bb60900421 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -1,6 +1,5 @@ -#include "../../../Map.func.hpp" +#include "../EntityState.func.hpp" -#include "OpenSHC/Map/Entities/EntityState.func.hpp" #include "OpenSHC/Random/RNG.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" @@ -14,8 +13,6 @@ namespace OpenSHC { namespace Map { namespace Entities { - using Map::Entities::EntityType; - // FUNCTION: STRONGHOLDCRUSADER 0x004087C0 void EntityState::updateEntities() { @@ -25,12 +22,12 @@ namespace Map { this->totalEntityCount = 0; int newMaxEntityCount = 0; for (DAT_CurrentEntityID::instance = 1; (int)DAT_CurrentEntityID::instance < this->maxEntityCount; - DAT_CurrentEntityID::instance = DAT_CurrentEntityID::instance + 1) { + DAT_CurrentEntityID::instance++) { if (this->entityArray[DAT_CurrentEntityID::instance].logicalState == 0) { continue; } newMaxEntityCount = DAT_CurrentEntityID::instance + 1; - this->totalEntityCount = this->totalEntityCount + 1; + this->totalEntityCount++; switch (this->entityArray[DAT_CurrentEntityID::instance].logicalState) { case 1: this->entityArray[DAT_CurrentEntityID::instance].logicalState = 2; @@ -63,12 +60,10 @@ namespace Map { } 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].unknownAnimationFrameRelated++; this->entityArray[DAT_CurrentEntityID::instance].field_0x12 = 0; } - this->entityArray[DAT_CurrentEntityID::instance].field_0x12 - = this->entityArray[DAT_CurrentEntityID::instance].field_0x12 + 1; + this->entityArray[DAT_CurrentEntityID::instance].field_0x12++; if (this->entityArray[DAT_CurrentEntityID::instance].logicalState != 6) { switch (this->entityArray[DAT_CurrentEntityID::instance].entityType) { case Map::Entities::ET_FIRE: @@ -78,31 +73,26 @@ namespace Map { 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; + this->entityArray[DAT_CurrentEntityID::instance].height++; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX--; } } else if (frameX % stepX == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microX++; } 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; + this->entityArray[DAT_CurrentEntityID::instance].microY--; } } else if (frameY % stepY == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY++; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(DAT_CurrentEntityID::instance); @@ -113,31 +103,26 @@ namespace Map { 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; + this->entityArray[DAT_CurrentEntityID::instance].height++; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX--; } } else if (frameX % stepX == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microX++; } 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; + this->entityArray[DAT_CurrentEntityID::instance].microY--; } } else if (frameY % stepY == 0) { - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY++; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(DAT_CurrentEntityID::instance); @@ -151,19 +136,17 @@ namespace Map { 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; + this->entityArray[DAT_CurrentEntityID::instance].height++; break; case Map::Entities::ET_COW_POISON_CLOUD: - this->entityArray[DAT_CurrentEntityID::instance].velocityUnk - = this->entityArray[DAT_CurrentEntityID::instance].velocityUnk + 1; + this->entityArray[DAT_CurrentEntityID::instance].velocityUnk++; 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; + this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk--; if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk <= 0) { + // the original reads the second byte of the random number on its own this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); this->entityArray[DAT_CurrentEntityID::instance].startingAngle @@ -174,44 +157,32 @@ namespace Map { 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; + this->entityArray[DAT_CurrentEntityID::instance].microY--; break; case 4: - this->entityArray[DAT_CurrentEntityID::instance].microY - = this->entityArray[DAT_CurrentEntityID::instance].microY + 1; + this->entityArray[DAT_CurrentEntityID::instance].microY++; break; case 2: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX + 1; + this->entityArray[DAT_CurrentEntityID::instance].microX++; break; case 6: - this->entityArray[DAT_CurrentEntityID::instance].microX - = this->entityArray[DAT_CurrentEntityID::instance].microX - 1; + this->entityArray[DAT_CurrentEntityID::instance].microX--; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX--; + this->entityArray[DAT_CurrentEntityID::instance].microY--; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX++; + this->entityArray[DAT_CurrentEntityID::instance].microY--; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX--; + this->entityArray[DAT_CurrentEntityID::instance].microY++; 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; + this->entityArray[DAT_CurrentEntityID::instance].microX++; + this->entityArray[DAT_CurrentEntityID::instance].microY++; break; } MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)( @@ -239,15 +210,14 @@ namespace Map { 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; + -= (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; + 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) { + // effect entity types 5 and 6 have no EntityType name yet if (this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 3) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( this->entityArray[DAT_CurrentEntityID::instance].microX, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c8d1b9a151..0cec88f229 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -2453,7 +2453,7 @@ SHC_3BB0A8C1_0x004084A0 | 0.0% | Pending SHC_3BB0A8C1_0x00408770 | 0.0% | Pending -SHC_3BB0A8C1_0x004087C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004087C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00408D90 | 0.0% | Pending From 5ff059db9e7adcc22550a4e49b51fcb57943268a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:29:39 +0100 Subject: [PATCH 11/18] reimplement: SHC_3BB0A8C1_0x00402900 UpdateFlag_1_2_4_Entity 68.2% From draft #527. Measured 68.2% raw / 68.2% normalized on main 592a17d94. The original keeps 0 in edi: it compares against edi instead of 0, stores di for 0, builds 3 as lea edx, [edi + 3], and pushes/pops edi. Ours uses immediates and test reg, reg, and pops esi before the jump table. Block order, stores and computation are the same, so nothing differs in behaviour. Status: SHC_3BB0A8C1_0x00402900 | 68.2% | Register allocation differs Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Entities/UpdateFlag_1_2_4_Entity.cpp | 78 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp 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..d3c44584b7 --- /dev/null +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -0,0 +1,78 @@ +#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 { + + // 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 { + AI::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; + // the animation table follows the tracker; tracker 3 also advances the frame every tick instead of every third + 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 += frame - 1; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0cec88f229..8498326414 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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% | Register allocation differs SHC_3BB0A8C1_0x00402A0C | 0.0% | Pending From eed437efc943bcfffdb0352fc9780992b304fb14 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:01:51 +0100 Subject: [PATCH 12/18] Entities: add the PathAxisCase enum Names the five values of Entity::pathAxisCase, the axis a projectile's Bresenham walk steps along: none, vertical (dX == 0), horizontal (dY == 0), Y-major and X-major. Used by initializeProjectileVelocities and handleProjectileWallBounce. PathAxisCaseShort is the sized alias for the short field; the field itself keeps its generated type. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/Entities/Enums/PathAxisCase.hpp | 29 +++++++++++++++++++ .../Map/Entities/Enums/PathAxisCaseShort.hpp | 23 +++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/OpenSHC/Map/Entities/Enums/PathAxisCase.hpp create mode 100644 src/OpenSHC/Map/Entities/Enums/PathAxisCaseShort.hpp diff --git a/src/OpenSHC/Map/Entities/Enums/PathAxisCase.hpp b/src/OpenSHC/Map/Entities/Enums/PathAxisCase.hpp new file mode 100644 index 0000000000..505b97d7cd --- /dev/null +++ b/src/OpenSHC/Map/Entities/Enums/PathAxisCase.hpp @@ -0,0 +1,29 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Entities/Enums/PathAxisCase.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Map { + namespace Entities { + namespace Enums { + typedef enum PathAxisCase { + + PAC_NONE = 0, // 0x00000000 + PAC_VERTICAL = 1, // 0x00000001 + PAC_HORIZONTAL = 2, // 0x00000002 + PAC_Y_MAJOR = 3, // 0x00000003 + PAC_X_MAJOR = 4 // 0x00000004 + + } PathAxisCase; + + static_assert_cpp98_obj(sizeof(PathAxisCase) == 4, PathAxisCase); + } // namespace Enums + } // namespace Entities +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/Entities/Enums/PathAxisCaseShort.hpp b/src/OpenSHC/Map/Entities/Enums/PathAxisCaseShort.hpp new file mode 100644 index 0000000000..044433ff5c --- /dev/null +++ b/src/OpenSHC/Map/Entities/Enums/PathAxisCaseShort.hpp @@ -0,0 +1,23 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Map/Entities/Enums/PathAxisCaseShort.hpp' +*/ + +#pragma once + +#include "OpenSHC/Map/Entities/Enums/PathAxisCase.hpp" + +namespace OpenSHC { +namespace Map { + namespace Entities { + namespace Enums { + typedef short PathAxisCaseShort; + + static_assert_cpp98_obj(sizeof(PathAxisCaseShort) == 2, PathAxisCaseShort); + } // namespace Enums + } // namespace Entities +} // namespace Map +} // namespace OpenSHC From 199ebb6ee395feb18f7d8efa71ffedd1975194e8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 17:01:51 +0100 Subject: [PATCH 13/18] review: pre-review pass for Map::Entities functions - PathAxisCase names for pathAxisCase, MC_MAP_XY_LIMIT(_INCLUSIVE) for the map bounds, and the Logic1 flags written inline instead of a local enum in IgniteFireAtMiniTile. - Map::Enums:: qualified now that Map::Entities::Enums exists. - Dropped redundant casts: whole-expression (short) on stores to short fields, (short)/(double) on call arguments, (byte) before & masks, the function-pointer cast on EntityCallbacks, and the char-pointer read of the random number's second byte (now >> 8). - short instead of word for graphicRotationUnk, fireParameter instead of two. - Removed code comments that explained match-driven forms (moved to the PR thread) and comments that restated the code. All 10 functions measure as before: 9 at 100% (two counted), UpdateFlag_1_2_4_Entity 68.2%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../EntityState/calculateEntityDrawOffset.cpp | 21 ++- .../handleProjectileWallBounce.cpp | 156 +++++++++--------- .../initializeProjectileVelocities.cpp | 94 +++++------ .../spawnProjectileImpactDebris.cpp | 122 +++++++------- .../Entities/EntityState/updateEntities.cpp | 12 +- .../updateProjectileHeightAndCollision.cpp | 4 +- .../Map/Entities/IgniteFireAtMiniTile.cpp | 30 ++-- .../Map/Entities/UpdateEntity_CowFlying.cpp | 3 +- .../Map/Entities/UpdateFlag_1_2_4_Entity.cpp | 2 +- 9 files changed, 215 insertions(+), 229 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index e230bedfe8..d6f07ac254 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -12,30 +12,29 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004036F0 void EntityState::calculateEntityDrawOffset(int entityID) { - uint x = (byte)this->entityArray[entityID].microX & 7; - uint y = (byte)this->entityArray[entityID].microY & 7; - // The gotos keep the original's two shared blocks (rotate, lookup) emitted once. - if (DAT_TileMapState::instance.mapOrientation == Enums::MO_SOUTH) { + uint x = this->entityArray[entityID].microX & 7; + uint y = this->entityArray[entityID].microY & 7; + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { x = 7 - x; y = 7 - y; } else { - if (DAT_TileMapState::instance.mapOrientation == Enums::MO_EAST) { + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { x = 7 - x; goto rotate; } - if (DAT_TileMapState::instance.mapOrientation == Enums::MO_WEST) { + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { y = 7 - y; goto rotate; } - if (DAT_TileMapState::instance.mapOrientation != Enums::MO_NORTH) { + if (DAT_TileMapState::instance.mapOrientation != Map::Enums::MO_NORTH) { rotate: - x = x << 4; - y = y * 2; + x <<= 4; + y *= 2; goto lookup; } } - x = x << 1; - y = y << 4; + x <<= 1; + 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/handleProjectileWallBounce.cpp b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp index 3996750b9a..580de645f8 100644 --- a/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/handleProjectileWallBounce.cpp @@ -4,6 +4,7 @@ #include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" #include "OpenSHC/Map/TileMapState.func.hpp" #include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Map/Entities/Enums/PathAxisCase.hpp" #include "OpenSHC/Map/Enums/NeighbourMask.hpp" #include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" @@ -29,7 +30,6 @@ namespace Map { DAT_TileMapState::ptr)(microX / 8, microY / 8); // orientation - 60 is one of sixteen directions; 60, 64, 68 and 72 run along an axis and keep // their target, the others bounce off the wall side the sub-tile position is closer to. - // The diagonal cases jump back to "straight" when both walls are set: the original shares that block. switch (this->entityArray[entityID].orientation) { case 60: case 64: @@ -42,15 +42,15 @@ namespace Map { case 61: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_WEST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: subY = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -65,15 +65,15 @@ namespace Map { case 62: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_WEST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: subY = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -88,15 +88,15 @@ namespace Map { case 63: subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_SOUTH: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_SOUTH: subY = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: subX = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -110,15 +110,15 @@ namespace Map { break; case 65: if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_NORTH: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: subY = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -132,15 +132,15 @@ namespace Map { break; case 66: if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_NORTH: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: subY = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -154,15 +154,15 @@ namespace Map { break; case 67: if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_WEST: subY = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: subX = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -177,15 +177,15 @@ namespace Map { case 69: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_EAST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: subY = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -200,15 +200,15 @@ namespace Map { case 70: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_EAST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: subY = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -223,15 +223,15 @@ namespace Map { case 71: subX = 7 - subX; if (subX == subY) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_NORTH: subY = 100; break; - case Enums::NM_NONE: - case Enums::NM_EAST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_EAST: subX = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -247,15 +247,15 @@ namespace Map { subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_SOUTH: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_SOUTH: subY = 100; break; - case Enums::NM_NONE: - case Enums::NM_EAST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_EAST: subX = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -271,15 +271,15 @@ namespace Map { subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_EAST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: subY = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -295,15 +295,15 @@ namespace Map { subX = 7 - subX; subY = 7 - subY; if (subX == subY) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_EAST: subX = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: subY = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -320,59 +320,59 @@ namespace Map { DAT_DirectionAlgorithmState::ptr)(microX, microY, targetX, targetY); this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation; if (microY > targetY) { - this->entityArray[entityID].pathDeltaY = (short)(microY - targetY); + this->entityArray[entityID].pathDeltaY = microY - targetY; } else { - this->entityArray[entityID].pathDeltaY = (short)(targetY - microY); + this->entityArray[entityID].pathDeltaY = targetY - microY; } if (microX > targetX) { - this->entityArray[entityID].pathDeltaX = (short)(microX - targetX); + this->entityArray[entityID].pathDeltaX = microX - targetX; } else { - this->entityArray[entityID].pathDeltaX = (short)(targetX - microX); + this->entityArray[entityID].pathDeltaX = targetX - microX; } - this->entityArray[entityID].pathTargetX = (short)targetX; + this->entityArray[entityID].pathTargetX = targetX; this->entityArray[entityID].someMicroX = microX <= targetX ? 1 : -1; - this->entityArray[entityID].pathTargetY = (short)targetY; + this->entityArray[entityID].pathTargetY = targetY; this->entityArray[entityID].someMicroY = microY <= targetY ? 1 : -1; if (this->entityArray[entityID].pathDeltaX == 0 && this->entityArray[entityID].pathDeltaY == 0) { - this->entityArray[entityID].pathAxisCase = 0; + this->entityArray[entityID].pathAxisCase = Enums::PAC_NONE; } else if (this->entityArray[entityID].pathDeltaX == 0) { - this->entityArray[entityID].pathAxisCase = 1; + this->entityArray[entityID].pathAxisCase = Enums::PAC_VERTICAL; } else if (this->entityArray[entityID].pathDeltaY == 0) { - this->entityArray[entityID].pathAxisCase = 2; + this->entityArray[entityID].pathAxisCase = Enums::PAC_HORIZONTAL; } else if (this->entityArray[entityID].pathDeltaY > this->entityArray[entityID].pathDeltaX) { - this->entityArray[entityID].pathAxisCase = 3; + this->entityArray[entityID].pathAxisCase = Enums::PAC_Y_MAJOR; } else { - this->entityArray[entityID].pathAxisCase = 4; + this->entityArray[entityID].pathAxisCase = Enums::PAC_X_MAJOR; } - if (this->entityArray[entityID].pathAxisCase == 3) { + if (this->entityArray[entityID].pathAxisCase == Enums::PAC_Y_MAJOR) { 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) { + } else if (this->entityArray[entityID].pathAxisCase == Enums::PAC_X_MAJOR) { 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; } - word const rotation = this->entityArray[entityID].graphicRotationUnk; + short const rotation = this->entityArray[entityID].graphicRotationUnk; this->entityArray[entityID].startingAngle = rotation; - if ((short)rotation < -80) { + if (rotation < -80) { this->entityArray[entityID].startingAngle = -80; } int const angle = this->entityArray[entityID].startingAngle; this->entityArray[entityID].speedUnk = 0; double const radians = angle * 3.1415926535 / 180.0; - short const velocity = (short)(this->entityArray[entityID].velocityUnk / 8); + short const velocity = (this->entityArray[entityID].velocityUnk / 8); this->entityArray[entityID].velocityUnk = velocity; this->entityArray[entityID].startingHeight = this->entityArray[entityID].height; this->entityArray[entityID].travelledDistance = 0; this->entityArray[entityID].vCos = (float)(this->entityArray[entityID].velocityUnk * cos(radians)); this->entityArray[entityID].vSin = (float)(this->entityArray[entityID].velocityUnk * sin(radians)); this->entityArray[entityID].rotationFrameIndex - = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); this->entityArray[entityID].gmLookupValue = 0; MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( this->entityArray[entityID].xPosition, this->entityArray[entityID].yPosition, diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index 3a528492b5..789346f61f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -1,6 +1,7 @@ #include "../EntityState.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Entities/Enums/PathAxisCase.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" @@ -31,80 +32,75 @@ namespace Map { 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].pathTargetX = targetX; + this->entityArray[entityID].pathTargetY = 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; + this->entityArray[entityID].pathAxisCase = Enums::PAC_NONE; } else if (this->entityArray[entityID].pathDeltaX == 0) { - this->entityArray[entityID].pathAxisCase = 1; + this->entityArray[entityID].pathAxisCase = Enums::PAC_VERTICAL; } else if (this->entityArray[entityID].pathDeltaY == 0) { - this->entityArray[entityID].pathAxisCase = 2; + this->entityArray[entityID].pathAxisCase = Enums::PAC_HORIZONTAL; } else if (this->entityArray[entityID].pathDeltaY > this->entityArray[entityID].pathDeltaX) { - this->entityArray[entityID].pathAxisCase = 3; + this->entityArray[entityID].pathAxisCase = Enums::PAC_Y_MAJOR; } else { - this->entityArray[entityID].pathAxisCase = 4; + this->entityArray[entityID].pathAxisCase = Enums::PAC_X_MAJOR; } - if (this->entityArray[entityID].pathAxisCase == 3) { + if (this->entityArray[entityID].pathAxisCase == Enums::PAC_Y_MAJOR) { 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) { + } else if (this->entityArray[entityID].pathAxisCase == Enums::PAC_X_MAJOR) { 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]; + int const curveType = DAT_EntityDefinedData::instance + .EntityArrayCurveTypeForProjectileType[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].field_0x94 = distanceRaw; + this->entityArray[entityID].totalFlightDistance = 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); + short const distance = distanceRaw; + this->entityArray[entityID].startingAngle = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::math_atan_1, this)(this->entityArray[entityID].entityType, + 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].field_0x94 = distanceRaw; + this->entityArray[entityID].totalFlightDistance = 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); + short const distance = distanceRaw; + this->entityArray[entityID].velocityUnk = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)(this->entityArray[entityID].entityType, + 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].field_0x94 = distanceRaw; + this->entityArray[entityID].totalFlightDistance = distanceRaw; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - short const distance = (short)distanceRaw; + short const distance = 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); + this->entityArray[entityID].velocityUnk = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::computeVelocity, this)(this->entityArray[entityID].entityType, + this->entityArray[entityID].startingAngle, distance, heightDifference); if (this->entityArray[entityID].velocityUnk <= 0) { - int const type = (short)this->entityArray[entityID].entityType; + int const type = this->entityArray[entityID].entityType; this->entityArray[entityID].startingAngle = 15; - this->entityArray[entityID].velocityUnk = (short)MACRO_CALL_MEMBER( + this->entityArray[entityID].velocityUnk = MACRO_CALL_MEMBER( Map::Entities::EntityState_Func::computeVelocity, this)(type, 15.0, distance, heightDifference); } } else if (curveType == 3) { @@ -112,11 +108,11 @@ namespace Map { this->entityArray[entityID].startingAngle = (rng & 0xf) + 8; this->entityArray[entityID].velocityUnk = (rng & 7) + 21; } else if (curveType == 4) { - this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 20 + 16); + this->entityArray[entityID].startingAngle = (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); + this->entityArray[entityID].velocityUnk = ((this->entityArray[entityID].rng_1 >> 8) % 20 + 16); if (this->entityArray[entityID].rng_1 & 0x8000) { this->entityArray[entityID].velocityUnk = -this->entityArray[entityID].velocityUnk; } @@ -124,23 +120,21 @@ namespace Map { } 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); + this->entityArray[entityID].graphicRotationUnk = ((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].field_0x94 = distanceRaw; + this->entityArray[entityID].totalFlightDistance = distanceRaw; this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; - short const distance = (short)distanceRaw; + short const distance = 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); + this->entityArray[entityID].startingAngle = MACRO_CALL_MEMBER( + Map::Entities::EntityState_Func::math_atan_1, this)(this->entityArray[entityID].entityType, + this->entityArray[entityID].velocityUnk, distance, this->entityArray[entityID].heightDifference); } else if (curveType == 7 || curveType == 10) { return; } else if (curveType == 8) { @@ -171,10 +165,10 @@ namespace Map { 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].vCos = (float)(cos(radians) * this->entityArray[entityID].velocityUnk); + this->entityArray[entityID].vSin = (float)(sin(radians) * this->entityArray[entityID].velocityUnk); this->entityArray[entityID].rotationFrameIndex - = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); } } diff --git a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp index 3866aa3a13..c2d97d375b 100644 --- a/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/spawnProjectileImpactDebris.cpp @@ -23,7 +23,6 @@ namespace Map { DAT_TileMapState::ptr)(microX / 8, microY / 8); // orientation - 60 is one of sixteen directions; 60, 64, 68 and 72 run along an axis and keep // their target, the others bounce off the wall side the sub-tile position is closer to. - // The diagonal cases jump back to "straight" when both walls are set: the original shares that block. switch (this->entityArray[entityID].orientation) { case 60: case 64: @@ -36,15 +35,15 @@ namespace Map { case 61: y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_WEST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: y = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -59,15 +58,15 @@ namespace Map { case 62: y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_WEST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: y = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -82,15 +81,15 @@ namespace Map { case 63: y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_WEST | Enums::NM_SOUTH)) { - case Enums::NM_SOUTH: + switch (wallFlags & (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_SOUTH: y = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: x = 100; break; - case (Enums::NM_WEST | Enums::NM_SOUTH): + case (Map::Enums::NM_WEST | Map::Enums::NM_SOUTH): goto straight; } } @@ -104,15 +103,15 @@ namespace Map { break; case 65: if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_NORTH: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: y = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -126,15 +125,15 @@ namespace Map { break; case 66: if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_NORTH: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_WEST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_WEST: y = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -148,15 +147,15 @@ namespace Map { break; case 67: if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_WEST)) { - case Enums::NM_WEST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_WEST)) { + case Map::Enums::NM_WEST: y = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: x = 100; break; - case (Enums::NM_NORTH | Enums::NM_WEST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_WEST): goto straight; } } @@ -171,15 +170,15 @@ namespace Map { case 69: x = 7 - x; if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_EAST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: y = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -194,15 +193,15 @@ namespace Map { case 70: x = 7 - x; if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_EAST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_NORTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_NORTH: y = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -217,15 +216,15 @@ namespace Map { case 71: x = 7 - x; if (x == y) { - switch (wallFlags & (Enums::NM_NORTH | Enums::NM_EAST)) { - case Enums::NM_NORTH: + switch (wallFlags & (Map::Enums::NM_NORTH | Map::Enums::NM_EAST)) { + case Map::Enums::NM_NORTH: y = 100; break; - case Enums::NM_NONE: - case Enums::NM_EAST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_EAST: x = 100; break; - case (Enums::NM_NORTH | Enums::NM_EAST): + case (Map::Enums::NM_NORTH | Map::Enums::NM_EAST): goto straight; } } @@ -241,15 +240,15 @@ namespace Map { x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_SOUTH: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_SOUTH: y = 100; break; - case Enums::NM_NONE: - case Enums::NM_EAST: + case Map::Enums::NM_NONE: + case Map::Enums::NM_EAST: x = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -265,15 +264,15 @@ namespace Map { x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_EAST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: y = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -289,15 +288,15 @@ namespace Map { x = 7 - x; y = 7 - y; if (x == y) { - switch (wallFlags & (Enums::NM_EAST | Enums::NM_SOUTH)) { - case Enums::NM_EAST: + switch (wallFlags & (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH)) { + case Map::Enums::NM_EAST: x = 100; break; - case Enums::NM_NONE: - case Enums::NM_SOUTH: + case Map::Enums::NM_NONE: + case Map::Enums::NM_SOUTH: y = 100; break; - case (Enums::NM_EAST | Enums::NM_SOUTH): + case (Map::Enums::NM_EAST | Map::Enums::NM_SOUTH): goto straight; } } @@ -310,7 +309,6 @@ namespace Map { } break; } - // 5 to 12 pieces of debris; entity type 27 has no name yet for (int i = 0; i < this->entityArray[entityID].rng_1 % 8 + 5; i++) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, this)(0, 0, 0, microX, microY, this->entityArray[entityID].height, targetX, targetY, 8, (EntityType)27, 0); diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index bb60900421..49acf9267f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -145,12 +145,11 @@ namespace Map { this)(DAT_CurrentEntityID::instance); if (this->entityArray[DAT_CurrentEntityID::instance].velocityUnk != 1000) { this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk--; - if ((short)this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk <= 0) { - // the original reads the second byte of the random number on its own + if (this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk <= 0) { this->entityArray[DAT_CurrentEntityID::instance].graphicRotationUnk - = (short)(char)((*((char*)&SEC_RNG::instance.currentNumber2 + 1)) & 0x3f); + = (SEC_RNG::instance.currentNumber2 >> 8) & 0x3f; this->entityArray[DAT_CurrentEntityID::instance].startingAngle - = ((char)SEC_RNG::instance.currentNumber2 >> 4) & 7U; + = (SEC_RNG::instance.currentNumber2 >> 4) & 7; MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); } } @@ -217,7 +216,6 @@ namespace Map { 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) { - // effect entity types 5 and 6 have no EntityType name yet if (this->entityArray[DAT_CurrentEntityID::instance].gmLookupValue != 3) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnEntityEffect2, this)( this->entityArray[DAT_CurrentEntityID::instance].microX, @@ -239,8 +237,8 @@ namespace Map { } } } - ((void (*)())DAT_EntityDefinedData::instance - .EntityCallbacks[this->entityArray[DAT_CurrentEntityID::instance].entityType])(); + 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); diff --git a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp index a1365169ec..1b2c239bfc 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp @@ -8,7 +8,7 @@ namespace Map { void EntityState::updateProjectileHeightAndCollision( uint entityID, undefined4 heightOffset, int angle, int skipCollision) { - this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + (short)heightOffset; + this->entityArray[entityID].height = this->entityArray[entityID].startingHeight + heightOffset; if (this->entityArray[entityID].height <= 2 && !skipCollision) { MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::doSomethingWithOtherEntitiesOnTile, this)(entityID); MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::processEntityHitBuildingOrUnit, this)(entityID); @@ -19,7 +19,7 @@ namespace Map { return; } this->entityArray[entityID].rotationFrameIndex - = (short)MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); + = MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::angleToRotationFrameIndex, this)(angle); this->entityArray[entityID].height_2 = currentHeight; } diff --git a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp index 1b69879080..988f580007 100644 --- a/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp +++ b/src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp @@ -6,6 +6,7 @@ #include "OpenSHC/Random/RNG.func.hpp" #include "OpenSHC/Map/Entities/EntityType.hpp" #include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/MapConstants.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_EntityDefinedData.hpp" @@ -20,28 +21,25 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004052E0 uint Entities::IgniteFireAtMiniTile( - int playerID, int miniTileX, int miniTileY, int tileHeightMin8, int two, int fireIntensity) + int playerID, int miniTileX, int miniTileY, int tileHeightMin8, int fireParameter, int fireIntensity) { - // Tiles that cannot catch fire - enum { - NON_FLAMMABLE_LOGIC = LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE - | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD - | LogicHelpers::L_KEEP_NON_MANOR_HOUSE - }; - uint const randomJitter = (uint)SEC_RNG::instance.currentNumber2; + uint const randomJitter = 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) { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { return 0; } - if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * 400 + x] == 0) { + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { return 0; } int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; - if (!(DAT_TileMapState::instance.LogicLayer[tile] & NON_FLAMMABLE_LOGIC)) { + if (!(DAT_TileMapState::instance.LogicLayer[tile] + & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE + | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD + | LogicHelpers::L_KEEP_NON_MANOR_HOUSE))) { short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; if (buildingID) { switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { @@ -59,8 +57,8 @@ namespace Map { = 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; + if (fireParameter > DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6) { + DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6 = fireParameter; } DAT_EntityState::instance.entityArray[fireID].unknownAnimationFrameRelated = 0; return 0; @@ -75,14 +73,14 @@ namespace Map { 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)) { + if (fireParameter >= 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, Map::Entities::EntityTypeInt__ET_EXPLOSION, 0); } if (entityID) { - DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = (short)two; - DAT_EntityState::instance.entityArray[entityID].fireIntensity = (short)fireIntensity; + DAT_EntityState::instance.entityArray[entityID].fireParameter_0xb6 = fireParameter; + DAT_EntityState::instance.entityArray[entityID].fireIntensity = fireIntensity; } return entityID; } diff --git a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp index a65de640ae..abedd8b9b2 100644 --- a/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp +++ b/src/OpenSHC/Map/Entities/UpdateEntity_CowFlying.cpp @@ -17,7 +17,6 @@ namespace Map { if (DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated >= 120) { DAT_EntityState::instance.entityArray[entityID].unknownAnimationFrameRelated = 119; } - // Decrementing the field directly instead of through this pointer measured 86.4% instead of 100% short* const counter = &DAT_EntityState::instance.entityArray[entityID].someCounter_OR_hitGround; (*counter)--; if (*counter <= 0) { @@ -35,7 +34,7 @@ namespace Map { = 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 + 17); + = (DAT_EntityState::instance.entityArray[entityID].graphicType2 + 17); } if (DAT_EntityState::instance.entityArray[entityID].orientation == 76) { DAT_EntityState::instance.entityArray[entityID].orientation = 60; diff --git a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp index d3c44584b7..fdb3f6caa6 100644 --- a/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp +++ b/src/OpenSHC/Map/Entities/UpdateFlag_1_2_4_Entity.cpp @@ -21,7 +21,7 @@ namespace Map { 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) + if ((DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].yPosition & 0x1f) >= DAT_LandscapeState::instance.wind.countdown) { nextTracker = DAT_LandscapeState::instance.wind.value; } From f7cd097bf4c3da98c11e59264bdfec183aab5835 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 18:42:06 +0100 Subject: [PATCH 14/18] status: IgniteFireAtMiniTile 94.2% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on The default build (visibility units off) gives 94.2 / 90.0: without the wrapper unit the original's reload of BuildingLayer[tile] after getFireEntityIDAtTile becomes a stack spill. With OPENSHC_FUNCTION_VISIBILITY_UNITS on it is 100.0 / 100.0. Same convention as main's other visibility-unit functions. No other function of this PR changes with the option. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 69003b3dff..4bd450c03e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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 | 100.0% | Reimplemented +SHC_3BB0A8C1_0x004052E0 | 94.2% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on SHC_3BB0A8C1_0x004054AC | 0.0% | Pending From 466642405f6d590c8ebd7691285a6e53d5b735da Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 22:45:02 +0100 Subject: [PATCH 15/18] calculateEntityDrawOffset: replace the gotos with structured control flow Flip the sub-tile coordinates in an if/else-if chain, then pick the shift pair with one test for the south and north orientations. Still 100.0% raw and normalized. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../EntityState/calculateEntityDrawOffset.cpp | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp index d6f07ac254..3ca08cfb5f 100644 --- a/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp @@ -17,25 +17,19 @@ namespace Map { if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { x = 7 - x; y = 7 - y; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { + x = 7 - x; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { + y = 7 - y; + } + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH + || DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_NORTH) { + x <<= 1; + y <<= 4; } else { - if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { - x = 7 - x; - goto rotate; - } - if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { - y = 7 - y; - goto rotate; - } - if (DAT_TileMapState::instance.mapOrientation != Map::Enums::MO_NORTH) { - rotate: - x <<= 4; - y *= 2; - goto lookup; - } + x <<= 4; + y *= 2; } - x <<= 1; - 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; } From eb2abbc703c9ea2e63f2805e093e120fb0b1747e Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 22:45:55 +0100 Subject: [PATCH 16/18] status: handleProjectileWallBounce 100.0% | Reimplemented The float constants and CRT helpers now pair through reccmp/float-literals.csv, so the counted remark is no longer needed. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 633f09485b..1385713bb6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -545,7 +545,7 @@ SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) -SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) +SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004044E4 | 0.0% | Pending From 8e2d8d47449997c80520a7a96078d0830e6bdca1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 23:08:20 +0100 Subject: [PATCH 17/18] status: initializeProjectileVelocities 100.0% | Reimplemented The 0.75 and 15.0 constants now pair through reccmp/float-literals.csv, so the counted remark is no longer needed. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c46feaea9f..1396f94e5d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -543,7 +543,7 @@ SHC_3BB0A8C1_0x004039B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004039F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented (counted: only float constant names and the CRT math helpers (_CIcos, _CIsin) differ) +SHC_3BB0A8C1_0x00403A20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00403FF0 | 100.0% | Reimplemented From c5794c6ade24d612be2ad66e6ca0f67317c36246 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 23:21:23 +0100 Subject: [PATCH 18/18] review: drop redundant casts Each removed cast leaves the generated code and the warnings unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../initializeProjectileVelocities.cpp | 20 +++++++++---------- .../Entities/EntityState/updateEntities.cpp | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp index 789346f61f..1adcc30cbe 100644 --- a/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/initializeProjectileVelocities.cpp @@ -67,7 +67,7 @@ namespace Map { this)(x, y, height, targetX, targetY, targetZ, 1); this->entityArray[entityID].field_0x94 = distanceRaw; this->entityArray[entityID].totalFlightDistance = distanceRaw; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + this->entityArray[entityID].clearanceStepsRemaining = this->lineOfSightClearanceSteps; short const distance = distanceRaw; this->entityArray[entityID].startingAngle = MACRO_CALL_MEMBER( Map::Entities::EntityState_Func::math_atan_1, this)(this->entityArray[entityID].entityType, @@ -77,7 +77,7 @@ namespace Map { this)(x, y, height, targetX, targetY, targetZ, 1); this->entityArray[entityID].field_0x94 = distanceRaw; this->entityArray[entityID].totalFlightDistance = distanceRaw; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + this->entityArray[entityID].clearanceStepsRemaining = this->lineOfSightClearanceSteps; short const distance = distanceRaw; this->entityArray[entityID].velocityUnk = MACRO_CALL_MEMBER( Map::Entities::EntityState_Func::computeVelocity, this)(this->entityArray[entityID].entityType, @@ -87,7 +87,7 @@ namespace Map { this)(x, y, height, targetX, targetY, targetZ, 1); this->entityArray[entityID].field_0x94 = distanceRaw; this->entityArray[entityID].totalFlightDistance = distanceRaw; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + this->entityArray[entityID].clearanceStepsRemaining = this->lineOfSightClearanceSteps; short const distance = distanceRaw; // from above, aim low first if (this->entityArray[entityID].height > this->entityArray[entityID].targetZ) { @@ -104,7 +104,7 @@ namespace Map { Map::Entities::EntityState_Func::computeVelocity, this)(type, 15.0, distance, heightDifference); } } else if (curveType == 3) { - ushort const rng = (ushort)this->entityArray[entityID].rng_1; + ushort const rng = this->entityArray[entityID].rng_1; this->entityArray[entityID].startingAngle = (rng & 0xf) + 8; this->entityArray[entityID].velocityUnk = (rng & 7) + 21; } else if (curveType == 4) { @@ -127,7 +127,7 @@ namespace Map { this)(x, y, height, targetX, targetY, targetZ, 1); this->entityArray[entityID].field_0x94 = distanceRaw; this->entityArray[entityID].totalFlightDistance = distanceRaw; - this->entityArray[entityID].clearanceStepsRemaining = (short)this->lineOfSightClearanceSteps; + this->entityArray[entityID].clearanceStepsRemaining = this->lineOfSightClearanceSteps; short const distance = distanceRaw; if (distance > 150) { this->entityArray[entityID].velocityUnk = 125; @@ -139,17 +139,17 @@ namespace Map { 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].startingAngle = this->entityArray[entityID].rng_1 % 60 + 8; this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 35; } else if (this->entityArray[entityID].unitID_OR_seaGullID == 4) { - this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 30) + 15; + this->entityArray[entityID].startingAngle = this->entityArray[entityID].rng_1 % 30 + 15; this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 15; 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].startingAngle = this->entityArray[entityID].rng_1 % 30 + 45; this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 35; } else { - this->entityArray[entityID].startingAngle = (short)(this->entityArray[entityID].rng_1 % 35) + 20; + this->entityArray[entityID].startingAngle = this->entityArray[entityID].rng_1 % 35 + 20; this->entityArray[entityID].velocityUnk = (this->entityArray[entityID].rng_1 & 7) + 25; this->entityArray[entityID]._elapsedTimeOrGravityAccumulator *= 0.75; } @@ -164,7 +164,7 @@ namespace Map { 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; + double const radians = angle * 3.1415926535 / 180.0; this->entityArray[entityID].vCos = (float)(cos(radians) * this->entityArray[entityID].velocityUnk); this->entityArray[entityID].vSin = (float)(sin(radians) * this->entityArray[entityID].velocityUnk); this->entityArray[entityID].rotationFrameIndex diff --git a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp index 49acf9267f..1878f4b8bd 100644 --- a/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp +++ b/src/OpenSHC/Map/Entities/EntityState/updateEntities.cpp @@ -207,9 +207,9 @@ namespace Map { break; default: this->entityArray[DAT_CurrentEntityID::instance].screenDirection - = (short)this->entityArray[DAT_CurrentEntityID::instance].orientation - 60; + = this->entityArray[DAT_CurrentEntityID::instance].orientation - 60; this->entityArray[DAT_CurrentEntityID::instance].screenDirection - -= (short)DAT_TileMapState::instance.mapOrientation * 2; + -= DAT_TileMapState::instance.mapOrientation * 2; if (this->entityArray[DAT_CurrentEntityID::instance].screenDirection < 0) { this->entityArray[DAT_CurrentEntityID::instance].screenDirection += 16; }