diff --git a/src/OpenSHC/Map/Units/UnitsState.func.hpp b/src/OpenSHC/Map/Units/UnitsState.func.hpp index b5346f6f34..207445e069 100644 --- a/src/OpenSHC/Map/Units/UnitsState.func.hpp +++ b/src/OpenSHC/Map/Units/UnitsState.func.hpp @@ -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; diff --git a/src/OpenSHC/Map/Units/UnitsState.hpp b/src/OpenSHC/Map/Units/UnitsState.hpp index cc2d8c7abc..430b42cf76 100644 --- a/src/OpenSHC/Map/Units/UnitsState.hpp +++ b/src/OpenSHC/Map/Units/UnitsState.hpp @@ -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); diff --git a/src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp b/src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp index 74da8ad0e6..159df72497 100644 --- a/src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp @@ -10,15 +10,16 @@ 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; @@ -26,7 +27,7 @@ namespace Map { = 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) { @@ -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) { @@ -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; @@ -118,7 +115,7 @@ namespace Map { break; } if (_scatter <= 0) { - return this->units[shooterID].unitType - 22; + return; } if (_scatter > 280) { _scatter = 280; @@ -126,45 +123,35 @@ namespace Map { } 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; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 98c4514966..4385283746 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -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