Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/OpenSHC/Map/Units/UnitsState.func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ namespace Map {
&UnitsState::getEnemyUnitIDNearby)
getEnemyUnitIDNearby;

MACRO_FUNCTION_RESOLVER(int (UnitsState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x0053CBD0,
MACRO_FUNCTION_RESOLVER(void (UnitsState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x0053CBD0,
&UnitsState::prepareProjectileTarget)
prepareProjectileTarget;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSHC/Map/Units/UnitsState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ namespace Map {

int getEnemyUnitIDNearby(int unitID, int tileUnk, int unitHeight);

int prepareProjectileTarget(int shooterID, int targetID, int param_3);
void prepareProjectileTarget(int shooterID, int targetID, int leadDistanceUnk);

BOOLEnum harassBuildingsWithSiegeAI(int unitID);

Expand Down
63 changes: 25 additions & 38 deletions src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ namespace Map {
namespace Units {

// FUNCTION: STRONGHOLDCRUSADER 0x0053CBD0
int UnitsState::prepareProjectileTarget(int shooterID, int targetID, int leadDistanceUnk)
void UnitsState::prepareProjectileTarget(int shooterID, int targetID, int leadDistanceUnk)
{
uint _targetFixedRng = 0;
int _targetFixedRng = 0;
if (targetID == -1) {
MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::setRandomShootLocation, this)(shooterID,
this->units[shooterID].shootTargetMicroX, this->units[shooterID].shootTargetMicroY,
this->units[shooterID].shootTargetZ);
} else {
_targetFixedRng = this->units[targetID].fixedRng;
// the three stores stand in both arms (once above the if loses the match)
if (this->units[targetID].tunnelerFinishedDigging != 2) {
this->units[shooterID].shootTargetMicroX = this->units[targetID].x * 8 + 4;
this->units[shooterID].shootTargetMicroY = this->units[targetID].y * 8 + 4;
this->units[shooterID].shootTargetZ
= this->units[targetID].buildingHeight + this->units[targetID].terrainOrClimbHeight;
} else {
int _lead = (leadDistanceUnk * 133) / 100;
int _adjustment;
int _adjustment = 0;
/* todo:fixme:ucp: this if-else should be improved to also trigger when the
targetID has negative height (walking in pitch or moat) */
if (this->units[targetID].stateBasedSpeed != 0) {
Expand Down Expand Up @@ -64,12 +65,8 @@ namespace Map {
}
}
}
/* the original returns whatever the switch below left in the return register on
the paths that adjust nothing, which is the type's index into it; the value is
not a meaningful result, but callers of those paths are given it */
int _scatter;
/* The original's jump tables carry entries for the archers that end up in the same place as
every other unhandled type, so their arms did something that was optimised away. */
int _scatter = 0;
// a dead store: it keeps the archer entries in both jump tables (without it they start at the catapult)
BOOLEnum _archerScatter;
if (this->units[shooterID].terrainOrClimbHeight > this->units[shooterID].shootTargetZ) {
switch (this->units[shooterID].unitType) {
Expand All @@ -89,9 +86,9 @@ namespace Map {
case OpenSHC::Map::Units::UT_E_ARCHER:
case OpenSHC::Map::Units::UT_E_ARCHER_DEBUG:
_archerScatter = FALSE;
return this->units[shooterID].unitType - 22;
return;
default:
return this->units[shooterID].unitType - 22;
return;
}
} else {
_scatter = this->units[shooterID].shootTargetZ - this->units[shooterID].terrainOrClimbHeight;
Expand All @@ -118,53 +115,43 @@ namespace Map {
break;
}
if (_scatter <= 0) {
return this->units[shooterID].unitType - 22;
return;
}
if (_scatter > 280) {
_scatter = 280;
}
}
int _rng = SEC_RNG::instance.currentNumber2;
MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
int _unhandledTypeResult = (_rng / 300) * 300;
if (_rng % 300 >= _scatter) {
return _unhandledTypeResult;
return;
}
if ((_rng & 7) < 2) {
_scatter /= 4;
if (_scatter == 0) {
_scatter = 1;
}
int _horizontalRng = abs((_rng / 512) + this->units[shooterID].fixedRng);
this->units[shooterID].shootTargetMicroX += ((_horizontalRng % _scatter) - (_scatter / 2));
int _verticalRng = abs(_rng + _targetFixedRng);
this->units[shooterID].shootTargetMicroY += ((_verticalRng % _scatter) - (_scatter / 2));
return _verticalRng / _scatter;
}
if ((_rng & 7) < 6) {
this->units[shooterID].shootTargetMicroX
+= ((abs((_rng / 512) + this->units[shooterID].fixedRng) % _scatter) - (_scatter / 2));
this->units[shooterID].shootTargetMicroY += ((abs(_rng + _targetFixedRng) % _scatter) - (_scatter / 2));
} else if ((_rng & 7) < 6) {
_scatter /= 6;
if (_scatter == 0) {
_scatter = 1;
}
int _heightRng = abs(this->units[shooterID].fixedRng + _rng);
int _heightOffset = _heightRng % _scatter + 20;
int const _z = (ushort)this->units[shooterID].shootTargetZ;
if ((short)_z < _heightOffset + 8) {
_unhandledTypeResult = _z + _heightOffset;
this->units[shooterID].shootTargetZ = _unhandledTypeResult;
return _unhandledTypeResult;
int _heightOffset = abs(this->units[shooterID].fixedRng + _rng) % _scatter + 20;
if (this->units[shooterID].shootTargetZ < _heightOffset + 8) {
this->units[shooterID].shootTargetZ += _heightOffset;
} else {
this->units[shooterID].shootTargetZ -= _heightOffset;
}
_unhandledTypeResult = _z - _heightOffset;
this->units[shooterID].shootTargetZ = _unhandledTypeResult;
return _unhandledTypeResult;
}
_scatter /= 6;
if (_scatter == 0) {
_scatter = 1;
} else {
_scatter /= 6;
if (_scatter == 0) {
_scatter = 1;
}
this->units[shooterID].shootTargetZ += (abs(_rng + _targetFixedRng) % _scatter) + 40;
}
int _heightRng = abs(_rng + _targetFixedRng);
this->units[shooterID].shootTargetZ = this->units[shooterID].shootTargetZ + (_heightRng % _scatter) + 40;
return _heightRng / _scatter;
}

}
Expand Down
2 changes: 1 addition & 1 deletion status/addresses-SHC-3BB0A8C1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59673,7 +59673,7 @@ SHC_3BB0A8C1_0x0053CAC0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x0053CAE0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x0053CBD0 | 85.8% | Style pass, asm differs
SHC_3BB0A8C1_0x0053CBD0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x0053CF84 | 0.0% | Pending

Expand Down
Loading