Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
169d263
Copy 16 functions from gynt's catch-all branches to reimpl/entities-p…
gynt Nov 28, 2026
42b7a63
Fix compile errors against main's headers
gynt Nov 28, 2026
10ebb3a
reimplement: status of 16 ported functions
gynt Nov 28, 2026
de33513
Entities: CowFlying, flag and projectile height fixed against the binary
gynt Nov 28, 2026
9bd7b11
Entities: IgniteFireAtMiniTile and math_atan_1
gynt Nov 28, 2026
d75b72a
Entities: reimplement angleToRotationFrameIndex
gynt Nov 28, 2026
5526418
Entities: build updateProjectileHeightAndCollision with /GL
gynt Nov 28, 2026
cfcfdfa
status: updateProjectileHeightAndCollision 100% under /GL
gynt Nov 28, 2026
6200da3
Entities: calculateEntityDrawOffset keeps one variable per axis
gynt Nov 28, 2026
36faa23
Entities: spawnProjectileEntity slot search rebuilt from the asm
gynt Nov 28, 2026
ddd9175
Entities: spawnProjectileImpactDebris rebuilt from the jump tables
gynt Nov 28, 2026
196f701
types: Entity::speedUnk is a float
gynt Nov 28, 2026
f1dbf63
Entities: handleProjectileWallBounce rebuilt from the jump tables
gynt Nov 28, 2026
ec832fd
Entities: initializeProjectileVelocities path setup as the original
gynt Nov 28, 2026
569841e
Entities: computeLineOfSightDistance rebuilt from the asm
gynt Nov 28, 2026
bd303b9
Entities: math_atan_1 with the original's int scaling and min/max
gynt Nov 28, 2026
5bcc8df
Entities: processSeaGulls rebuilt from the asm, angle wrap fixed
gynt Nov 28, 2026
377658c
Entities: UpdateFlag_1_2_4_Entity indexes by the current-entity global
gynt Nov 28, 2026
233f702
Entities: IgniteFireAtMiniTile jitters its parameters in place
gynt Nov 28, 2026
60b0e3c
Entities: moveProjectileEntity trajectory rebuilt from the FPU stack
gynt Nov 28, 2026
d7c175c
types: Entity.graphicRotationUnk is short, spawnEntityEffect1 takes i…
gynt Nov 29, 2026
970edc7
Entities: updateEntities rebuilt from its jump tables
gynt Nov 29, 2026
ce2b1cc
Entities: moveProjectileEntity tail as an else-if chain with one return
gynt Nov 29, 2026
126b9eb
Entities: processEntityHitBuildingOrUnit rebuilt from the asm
gynt Nov 29, 2026
1a946b4
Entities: processEntityHitBuildingOrUnit position, bounds and rock flags
gynt Nov 29, 2026
679bd71
Entities: UpdateFireEntity rebuilt from the asm
gynt Nov 29, 2026
2c44ef8
Entities: processSeaGulls steps x before y on the diagonal axis
gynt Nov 29, 2026
fa8dfe9
Entities: computeLineOfSightDistance tests the blocking flag as bit 7
gynt Nov 29, 2026
edb02fe
Entities: initializeProjectileVelocities rebuilt from the asm
gynt Nov 29, 2026
ec5a3cf
Entities: processSeaGulls computes the new tile y before the new x
gynt Nov 29, 2026
b88c8c8
Entities: computeLineOfSightDistance computes the start tile x before y
gynt Nov 29, 2026
8bd846d
Entities: processEntityHitBuildingOrUnit reads microX before microY
gynt Nov 29, 2026
3508b2f
Entities: spawnProjectileEntity stores targetY before the unit id
gynt Nov 29, 2026
ee25914
Entities: processEntityHitBuildingOrUnit reads the entity's microY be…
gynt Nov 29, 2026
e3ae2a6
Entities: computeLineOfSightDistance tests for an exhausted clearance…
gynt Nov 29, 2026
427ef30
Merge origin/main into reimpl/entities-projectiles-fire
gynt Dec 2, 2026
d0aab40
Entities: follow main's entity headers
gynt Dec 2, 2026
e5927dd
Merge origin/main into reimpl/entities-projectiles-fire
gynt Dec 3, 2026
0591884
reimplement: SHC_3BB0A8C1_0x004052E0 100% Reimplemented
gynt Dec 3, 2026
deb67f6
reimplement: SHC_3BB0A8C1_0x00405DA0 100% Reimplemented
gynt Dec 3, 2026
8c1157b
reimplement: SHC_3BB0A8C1_0x00403FF0 100% Reimplemented (counted: onl…
gynt Dec 3, 2026
69624a2
reimplement: SHC_3BB0A8C1_0x00403A20 100% Reimplemented (counted: onl…
gynt Dec 3, 2026
506a560
reimplement: SHC_3BB0A8C1_0x00402180 100% Reimplemented
gynt Dec 3, 2026
19f8b63
reimplement: SHC_3BB0A8C1_0x004036F0 100% Reimplemented
gynt Dec 4, 2026
93c7619
reimplement: SHC_3BB0A8C1_0x00407190 80.8% entityType cached in ebp a…
gynt Dec 4, 2026
e0cb24e
reimplement: SHC_3BB0A8C1_0x00406900 87.3% newY takes ebp where the o…
gynt Dec 4, 2026
daf0c69
reimplement: SHC_3BB0A8C1_0x00402E20 57.8% loop layout matches; heigh…
gynt Dec 4, 2026
8b446ce
Merge remote-tracking branch 'origin/main' into reimpl/entities-proje…
gynt Dec 5, 2026
4cb0a6f
status: SHC_3BB0A8C1_0x004084A0 93.1% after the main merge
gynt Dec 5, 2026
2971ce9
reimplement: SHC_3BB0A8C1_0x00406900 90.8% microY read through a refe…
gynt Dec 5, 2026
234af6c
reimplement: SHC_3BB0A8C1_0x00407190 84.2% entityType switch, no cach…
gynt Dec 5, 2026
5c73e5e
status: SHC_3BB0A8C1_0x00402C50 72.6% after the main merge
gynt Dec 5, 2026
b6ee8eb
status: SHC_3BB0A8C1_0x00402E20 57.8%, dispatch rewrite measured
gynt Dec 5, 2026
14a0eeb
Merge remote-tracking branch 'origin/main' into reimpl/entities-proje…
gynt Dec 5, 2026
01749f0
status: math_atan_1 79.2%, moveProjectileEntity 94.8% with the float-…
gynt Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,11 @@ src/OpenSHC/Map/Units/UpdateHunter.cpp
src/OpenSHC/Map/Units/UpdateAppleFarmer.cpp
src/OpenSHC/Map/Units/UpdateJester.cpp
src/OpenSHC/Map/Units/UpdateSlave.cpp
src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp
src/OpenSHC/Map/Entities/EntityState/updateProjectileHeightAndCollision.cpp
src/OpenSHC/Map/Units/UpdateHealer.cpp
src/OpenSHC/Map/Units/UpdateSpearman.cpp
src/OpenSHC/Map/Entities/IgniteFireAtMiniTile.cpp
src/OpenSHC/Map/Units/UpdateSlinger.cpp
src/OpenSHC/Map/Units/UpdateWoodcutter.cpp
src/OpenSHC/Map/Units/UpdateFletcher.cpp
Expand Down
2 changes: 2 additions & 0 deletions cmake/function-visibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,5 @@ OpenSHC::Map::Units::UpdateFireBallista
OpenSHC::Map::Units::UnitsState::deselectUnit
OpenSHC::Map::Units::UpdateHorseArcher
OpenSHC::Map::Units::UnitsState::hasUnitReachedDestination
OpenSHC::Map::Entities::IgniteFireAtMiniTile
OpenSHC::Map::Entities::EntityState::getFireEntityIDAtTile
44 changes: 44 additions & 0 deletions src/OpenSHC/Map/Entities/EntityState/angleToRotationFrameIndex.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
}
44 changes: 44 additions & 0 deletions src/OpenSHC/Map/Entities/EntityState/calculateEntityDrawOffset.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
}
280 changes: 280 additions & 0 deletions src/OpenSHC/Map/Entities/EntityState/computeLineOfSightDistance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
#include "../../../Map.func.hpp"
#include "../EntityState.func.hpp"

#include "OpenSHC/Map/TileMapState.func.hpp"

#include "OpenSHC/Globals/DAT_TileMapState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

#include <stdlib.h>

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00402E20
uint EntityState::computeLineOfSightDistance(
int x, int y, int height, int targetX, int targetY, int targetHeight, int param_7)
{
int lastTile = -1;
int building = -1;
int steps = 100000;
int lastHeight = 0;
int clearance = 0;
BOOL clear = TRUE;
BOOL blocked = FALSE;
if (height > targetHeight + 54) {
clearance = 100;
}
int curX = x;
int curY = y;
int const tileX = x / 8;
int const tileY = y / 8;
int const startTile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX;
if (DAT_TileMapState::instance.LogicLayer[startTile] & 0x10000000) {
height = height + 10;
}
if (DAT_TileMapState::instance.BuildingLayer[startTile] != 0) {
building = DAT_TileMapState::instance.BuildingLayer[startTile];
}
int dY;
if (y > targetY) {
dY = y - targetY;
} else {
dY = targetY - y;
}
int dX;
if (x > targetX) {
dX = x - targetX;
} else {
dX = targetX - x;
}
int const stepX = x <= targetX ? 1 : -1;
int const stepY = y <= targetY ? 1 : -1;
int twoD;
int error;
int diagStep;
// Set-up and stepping are two separate dispatches; mode picks the stepping loop.
int mode;
if (dX == 0) {
if (dY != 0) {
if (clearance >= 28) {
clearance = 28;
}
this->lineOfSightClearanceSteps = clearance;
clearance = clearance / 2;
mode = 0;
} else {
mode = 4;
}
} else if (dY != 0) {
if (dY > dX) {
twoD = dX * 2;
error = twoD - dY;
diagStep = twoD - dY * 2;
if (height > targetHeight && clearance != 0) {
int n = abs(targetY - y) / 8 - 1;
if (n > 4) {
n = 4;
}
for (int i = 1; i < n; i++) {
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(
DAT_ViewportRenderState::instance.translationMatrix[targetY / 8 - stepY * i].addXgetTile
+ targetX / 8,
1);
if (lastHeight > targetHeight) {
clearance = 28;
}
}
}
this->lineOfSightClearanceSteps = clearance;
clearance = clearance / 2;
mode = 1;
} else {
twoD = dY * 2;
diagStep = twoD - dX * 2;
error = twoD - dX;
if (height > targetHeight && clearance != 0) {
int n = abs(targetX - x) / 8 - 1;
if (n > 4) {
n = 4;
}
for (int i = 1; i < n; i++) {
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(targetX / 8 - stepX * i
+ DAT_ViewportRenderState::instance.translationMatrix[targetY / 8].addXgetTile,
1);
if (lastHeight > targetHeight) {
clearance = 28;
}
}
}
this->lineOfSightClearanceSteps = clearance;
clearance = clearance / 2;
mode = 2;
}
} else {
if (clearance >= 28) {
clearance = 28;
}
this->lineOfSightClearanceSteps = clearance;
clearance = clearance / 2;
mode = 3;
}

if (mode == 3) {
for (steps = 0; steps < 1000; steps++) {
curX += stepX;
if ((steps & 1) && param_7 == 0) {
int const tile
= curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile;
if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) {
clear = FALSE;
this->lineOfSightClearanceSteps = steps;
}
if (clearance != 0) {
clearance--;
} else if (lastTile != tile) {
blocked = FALSE;
uint const flags = DAT_TileMapState::instance.LogicLayer[tile];
if ((flags & 0x80) != 0
|| (building != DAT_TileMapState::instance.BuildingLayer[tile]
&& (!clear || !(flags & 0x400200)))) {
blocked = TRUE;
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1);
if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) {
return 0;
}
}
} else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) {
return 0;
}
lastTile = tile;
}
if (curX == targetX && y == targetY) {
break;
}
}
} else if (mode == 0) {
for (steps = 0; steps < 1000; steps++) {
curY += stepY;
if ((steps & 1) && param_7 == 0) {
int const tile
= DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile + tileX;
if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) {
clear = FALSE;
this->lineOfSightClearanceSteps = steps;
}
if (clearance != 0) {
clearance--;
} else if (lastTile != tile) {
blocked = FALSE;
uint const flags = DAT_TileMapState::instance.LogicLayer[tile];
if ((flags & 0x80) != 0
|| (building != DAT_TileMapState::instance.BuildingLayer[tile]
&& (!clear || !(flags & 0x400200)))) {
blocked = TRUE;
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1);
if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) {
return 0;
}
}
} else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) {
return 0;
}
lastTile = tile;
}
if (x == targetX && curY == targetY) {
break;
}
}
} else if (mode == 2) {
for (steps = 0; steps < 1000; steps++) {
curX += stepX;
if (error > 0) {
curY += stepY;
error += diagStep;
} else {
error += twoD;
}
if ((steps & 1) && param_7 == 0) {
int const tile
= curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile;
if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) {
clear = FALSE;
this->lineOfSightClearanceSteps = steps;
}
if (clearance != 0) {
clearance--;
} else if (lastTile != tile) {
blocked = FALSE;
uint const flags = DAT_TileMapState::instance.LogicLayer[tile];
if ((flags & 0x80) != 0
|| (building != DAT_TileMapState::instance.BuildingLayer[tile]
&& (!clear || !(flags & 0x400200)))) {
blocked = TRUE;
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1);
if (abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) {
return 0;
}
}
} else if (blocked && abs(curX - x) * (targetHeight - height) / dX + height < lastHeight) {
return 0;
}
lastTile = tile;
}
if (curX == targetX && curY == targetY) {
break;
}
}
} else if (mode == 1) {
for (steps = 0; steps < 1000; steps++) {
curY += stepY;
if (error > 0) {
curX += stepX;
error += diagStep;
} else {
error += twoD;
}
if ((steps & 1) && param_7 == 0) {
int const tile
= curX / 8 + DAT_ViewportRenderState::instance.translationMatrix[curY / 8].addXgetTile;
if (!(DAT_TileMapState::instance.LogicLayer[tile] & 0x400300)) {
clear = FALSE;
this->lineOfSightClearanceSteps = steps;
}
if (clearance != 0) {
clearance--;
} else if (lastTile != tile) {
blocked = FALSE;
uint const flags = DAT_TileMapState::instance.LogicLayer[tile];
if ((flags & 0x80) != 0
|| (building != DAT_TileMapState::instance.BuildingLayer[tile]
&& (!clear || !(flags & 0x400200)))) {
blocked = TRUE;
lastHeight = MACRO_CALL_MEMBER(
Map::TileMapState_Func::returnSomeHeight, DAT_TileMapState::ptr)(tile, 1);
if (abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) {
return 0;
}
}
} else if (blocked && abs(curY - y) * (targetHeight - height) / dY + height < lastHeight) {
return 0;
}
lastTile = tile;
}
if (curX == targetX && curY == targetY) {
break;
}
}
}
return steps;
}

} // namespace Entities
} // namespace Map
} // namespace OpenSHC
Loading