From 6edaebe88f236497a8ac56a4121a8eb15f4414ad Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 2 Dec 2026 07:02:05 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x00531220 100.0% Reimplemented UnitsState::processUnitAttackOtherUnit from 79.5% / 72.1% (gynt's text, on main since #238) to 100%. One `return TRUE` at the end instead of one in every arm (36 on main). With those MSVC keeps the constant 1 in ebx from `dying = 1` on and returns with `mov eax, ebx`; the original has the 1 in ecx for the word stores only (0x005313BC) and returns with `mov eax, 1`. The arms now leave through `break`: the special death sounds and the switch on the attacker's type stand in the `default:` of the switch on the victim's type, and `isStalked == 0` stands around both (an early return for a stalked victim gets an epilogue of its own with `mov eax, ecx`). quick_diff 0.8467 -> 0.9515. The block for a victim that is still alive stands last, as in the original (0x005317E8), with the rest inside `health <= 0`. The spear arm plays its hit sound and otherwise falls through into the pike arm: the original has the two death-spear sounds once (0x005316C4), reached from both arms, and hands out its calls' scratch registers in that order. The fire thrower has an arm of its own in the death-state chain and US_STONE_DEATH_01 stands in the last else, which gives the 32-bit `add edx, 0x71` (0x005314B4) for a 16-bit one. `tunnelerFinishedDigging = 1` stands in front of `_deathVariant` (the order of two stores, 0x005314D0), and the victim's type is read in the damage expression and declared behind it, so that `_unit2Type` takes the dead unitID parameter's stack slot (0x0053126F) and the flag the local one. The same listing as the original (quick_diff 1.0000). The body is gynt's (775d904ff6 56.1%, 017d972926 56.8%, 3c8da9cd74 57.0%, 398ea19fa9 79.5%). Measured with real builds of this text on main 0cea04dbf4 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off and in one with it on (500 functions each). With the option off no other function reads differently from the same build of main. The comment lines and `const` on `_deathVariant` came after those builds: the file compiled alone gives the same object code with them (compared section by section). Tried and not taken, each for the match (quick_diff): one test over the eleven attacker types for the death state 0.8204, a switch with grouped labels 0.8402; `UnitTypeShort const _unit2Type` 0.7453; `_hasSpecialDeathSound` declared in the arm that uses it 0.8958; `_deathVariant` declared at its first use 0.9000. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../UnitsState/processUnitAttackOtherUnit.cpp | 460 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 227 insertions(+), 235 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/processUnitAttackOtherUnit.cpp b/src/OpenSHC/Map/Units/UnitsState/processUnitAttackOtherUnit.cpp index 5daae26005..02da0b3249 100644 --- a/src/OpenSHC/Map/Units/UnitsState/processUnitAttackOtherUnit.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/processUnitAttackOtherUnit.cpp @@ -26,13 +26,15 @@ namespace Map { BOOLEnum UnitsState::processUnitAttackOtherUnit(int unitID, int unit2ID) { int _tribeID = this->units[unit2ID].tribeID; - int const _unit2Type = this->units[unit2ID].unitType; /* get the damage from the array based: row is unit1ID type, column is unit2ID type */ - int _damage - = DAT_UnitPropertiesDefinedData::instance.MELEE_DAMAGE[this->units[unitID].unitType][_unit2Type]; + int _damage = DAT_UnitPropertiesDefinedData::instance + .MELEE_DAMAGE[this->units[unitID].unitType][this->units[unit2ID].unitType]; + // for the match: _unit2Type is an int declared behind the damage, and the flag is declared up here + int const _unit2Type = this->units[unit2ID].unitType; BOOLEnum _hasSpecialDeathSound = FALSE; /* if unit 1 is not a lord */ if (this->units[unitID].unitType != OpenSHC::Map::Units::UT_LORD) { + // the owner through the global, as the original reads it: this-> loses the match _damage = MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::computeDamageFearFactorBonus, this)( _damage, DAT_UnitsState::instance.units[unitID].owner); } @@ -87,243 +89,233 @@ namespace Map { break; } } - if (this->units[unit2ID].health > 0) { - if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY - && DAT_UnitsState::instance.units[unit2ID].owner - == DAT_GameSynchronyState::instance.currentPlayerSlotID) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXWeAreUnderAttack, DAT_SFXState::ptr)(); - } - return FALSE; - } - this->units[unit2ID].dying = 1; - if (_tribeID > 0) { - DAT_TribesState::instance.tribes[_tribeID].predatorNearby = 1; - } - this->units[unit2ID].animationCycleNumber = 0; - if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_SWORD) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_KNIGHT) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_SPEAR) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_PIKE) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_XBOW) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_ARCHER) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_ARCHER) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_ASSASSIN) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_HARCHER) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_SWORDSMAN) { - this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; - } else { - this->units[unit2ID].state.generic - = (this->units[unitID].unitType != OpenSHC::Map::Units::UT_A_FIRETHROWER) - + OpenSHC::Map::Units::States::US_DEATH_03; - } - uint _deathVariant = this->units[unit2ID].fixedRng & 1; - this->units[unit2ID].tunnelerFinishedDigging = 1; - if (this->units[unit2ID].isStalked != 0) { - return TRUE; - } - switch (_unit2Type) { - case OpenSHC::Map::Units::UT_S_SHIELD: - if (this->units[unitID].digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 > 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT); - return TRUE; + // the victim that survives is handled last, as in the original: an early return for it loses the match + if (this->units[unit2ID].health <= 0) { + this->units[unit2ID].dying = 1; + if (_tribeID > 0) { + DAT_TribesState::instance.tribes[_tribeID].predatorNearby = 1; } - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SIEGE_DIE); - return TRUE; - case OpenSHC::Map::Units::UT_S_CATAPULT: - case OpenSHC::Map::Units::UT_S_MANGONEL: - case OpenSHC::Map::Units::UT_S_TOWER: - case OpenSHC::Map::Units::UT_S_BATTERINGRAM: - case OpenSHC::Map::Units::UT_S_BALLISTA: - case OpenSHC::Map::Units::UT_S_FBALLISTA: - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SIEGE_DIE); - return TRUE; - case OpenSHC::Map::Units::UT_S_TREBUCHET: - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_TR_DIE); - return TRUE; - } - if (_unit2Type == OpenSHC::Map::Units::UT_BREWER || _unit2Type == OpenSHC::Map::Units::UT_TANNER - || _unit2Type == OpenSHC::Map::Units::UT_LADY || _unit2Type == OpenSHC::Map::Units::UT_MOTHER - || (_unit2Type == OpenSHC::Map::Units::UT_CHILD && this->units[unitID].spriteID == 129)) { - _hasSpecialDeathSound = TRUE; - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_GIRL_DIE); - } - if (_unit2Type == OpenSHC::Map::Units::UT_LORD) { - if (this->units[unit2ID].owner == DAT_GameSynchronyState::instance.currentPlayerSlotID) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( - OpenSHC::Audio::SFX::SEID_PLAYER_LORD_DEATH); - if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { - MACRO_CALL_MEMBER( - OpenSHC::Audio::MSS::SoundSystem_Func::setSomeSoundTime, DAT_SoundSystemState::ptr)(); - } + this->units[unit2ID].animationCycleNumber = 0; + // one arm per attacker type: a single test over the eleven types loses the match + if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_SWORD) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_KNIGHT) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_SPEAR) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_PIKE) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_XBOW) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_E_ARCHER) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_ARCHER) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_ASSASSIN) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_HARCHER) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_SWORDSMAN) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; + } else if (this->units[unitID].unitType == OpenSHC::Map::Units::UT_A_FIRETHROWER) { + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_DEATH_03; } else { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( - OpenSHC::Audio::SFX::SEID_AI_LORD_DEATH); - } - _hasSpecialDeathSound = TRUE; - } else if (_unit2Type == OpenSHC::Map::Units::UT_JESTER) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_JESTER_DIE); - _hasSpecialDeathSound = TRUE; - } - switch (this->units[unitID].unitType) { - case OpenSHC::Map::Units::UT_WOODCUTTER: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_HIT); - return TRUE; - } - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_KILL); - return TRUE; - case OpenSHC::Map::Units::UT_LORD: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_HIT); - return TRUE; - } - if (this->units[unitID].unknownLordTypeBasedMissionSpecificValue_01 == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_KILL); - return TRUE; - } - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_ARAB_LORD_KILL); - return TRUE; - case OpenSHC::Map::Units::UT_E_SPEAR: - case OpenSHC::Map::Units::UT_A_ARCHER: - case OpenSHC::Map::Units::UT_A_SLINGER: - case OpenSHC::Map::Units::UT_A_HARCHER: - case OpenSHC::Map::Units::UT_A_FIRETHROWER: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SPEAR_HIT); - return TRUE; - } - if (_deathVariant == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SPEAR); - return TRUE; - } - if (_deathVariant == 1) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SPEAR2); - return TRUE; - } - return TRUE; - case OpenSHC::Map::Units::UT_E_PIKE: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_PIKE_HIT); - return TRUE; - } - if (_deathVariant == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SPEAR); - return TRUE; - } - if (_deathVariant == 1) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SPEAR2); - return TRUE; - } - return TRUE; - case OpenSHC::Map::Units::UT_E_MACE: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_MACE_HIT); - return TRUE; - } - if (_deathVariant == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_CLUB); - return TRUE; - } - if (_deathVariant == 1) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_CLUB2); - return TRUE; - } - return TRUE; - case OpenSHC::Map::Units::UT_E_SWORD: - case OpenSHC::Map::Units::UT_E_KNIGHT: - case OpenSHC::Map::Units::UT_A_ASSASSIN: - case OpenSHC::Map::Units::UT_A_SWORDSMAN: - if (_hasSpecialDeathSound) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SWORD_HIT); - return TRUE; - } - if (_deathVariant == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SWORD); - return TRUE; - } - if (_deathVariant == 1) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SWORD2); - return TRUE; - } - return TRUE; - default: - if (_hasSpecialDeathSound) { - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 0) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 1) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT2); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 2) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT3); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 3) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT4); - return TRUE; + this->units[unit2ID].state.generic = OpenSHC::Map::Units::States::US_STONE_DEATH_01; } - if ((this->units[unit2ID].fixedRng & 7) == 4) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT5); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 5) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT6); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 6) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT7); - return TRUE; - } - if ((this->units[unit2ID].fixedRng & 7) == 7) { - MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( - this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT8); - return TRUE; + this->units[unit2ID].tunnelerFinishedDigging = 1; + // read behind the flag store, as in the original: declared at its first use it loses the match + uint const _deathVariant = this->units[unit2ID].fixedRng & 1; + // no early return below: a second `return TRUE` loses the match + if (this->units[unit2ID].isStalked == 0) { + switch (_unit2Type) { + case OpenSHC::Map::Units::UT_S_SHIELD: + if (this->units[unitID].digTileX__OR__countCurrentlyManningEnginers__OR__forCowsRandomBelow300 + > 0) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_BODY_HIT); + } else { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SIEGE_DIE); + } + break; + case OpenSHC::Map::Units::UT_S_CATAPULT: + case OpenSHC::Map::Units::UT_S_MANGONEL: + case OpenSHC::Map::Units::UT_S_TOWER: + case OpenSHC::Map::Units::UT_S_BATTERINGRAM: + case OpenSHC::Map::Units::UT_S_BALLISTA: + case OpenSHC::Map::Units::UT_S_FBALLISTA: + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SIEGE_DIE); + break; + case OpenSHC::Map::Units::UT_S_TREBUCHET: + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_TR_DIE); + break; + default: + if (_unit2Type == OpenSHC::Map::Units::UT_BREWER || _unit2Type == OpenSHC::Map::Units::UT_TANNER + || _unit2Type == OpenSHC::Map::Units::UT_LADY + || _unit2Type == OpenSHC::Map::Units::UT_MOTHER + || (_unit2Type == OpenSHC::Map::Units::UT_CHILD && this->units[unitID].spriteID == 129)) { + _hasSpecialDeathSound = TRUE; + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_GIRL_DIE); + } + if (_unit2Type == OpenSHC::Map::Units::UT_LORD) { + if (this->units[unit2ID].owner == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, + DAT_SFXState::ptr)(OpenSHC::Audio::SFX::SEID_PLAYER_LORD_DEATH); + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::setSomeSoundTime, + DAT_SoundSystemState::ptr)(); + } + } else { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, + DAT_SFXState::ptr)(OpenSHC::Audio::SFX::SEID_AI_LORD_DEATH); + } + _hasSpecialDeathSound = TRUE; + } else if (_unit2Type == OpenSHC::Map::Units::UT_JESTER) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_JESTER_DIE); + _hasSpecialDeathSound = TRUE; + } + switch (this->units[unitID].unitType) { + case OpenSHC::Map::Units::UT_WOODCUTTER: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_HIT); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_KILL); + } + break; + case OpenSHC::Map::Units::UT_LORD: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_HIT); + } else if (this->units[unitID].unknownLordTypeBasedMissionSpecificValue_01 == 0) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_LORD_KILL); + } else { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_ARAB_LORD_KILL); + } + break; + case OpenSHC::Map::Units::UT_E_SPEAR: + case OpenSHC::Map::Units::UT_A_ARCHER: + case OpenSHC::Map::Units::UT_A_SLINGER: + case OpenSHC::Map::Units::UT_A_HARCHER: + case OpenSHC::Map::Units::UT_A_FIRETHROWER: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SPEAR_HIT); + break; + } + // falls through: the death sounds are the pike's + case OpenSHC::Map::Units::UT_E_PIKE: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_PIKE_HIT); + } else if (_deathVariant == 0) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SPEAR); + } else if (_deathVariant == 1) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_DEATH_SPEAR2); + } + break; + case OpenSHC::Map::Units::UT_E_MACE: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_MACE_HIT); + } else if (_deathVariant == 0) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_CLUB); + } else if (_deathVariant == 1) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_CLUB2); + } + break; + case OpenSHC::Map::Units::UT_E_SWORD: + case OpenSHC::Map::Units::UT_E_KNIGHT: + case OpenSHC::Map::Units::UT_A_ASSASSIN: + case OpenSHC::Map::Units::UT_A_SWORDSMAN: + if (_hasSpecialDeathSound) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_SWORD_HIT); + } else if (_deathVariant == 0) { + MACRO_CALL_MEMBER( + OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + this->units[unit2ID].x, this->units[unit2ID].y, OpenSHC::DE::SHCDE::FX_DEATH_SWORD); + } else if (_deathVariant == 1) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_DEATH_SWORD2); + } + break; + default: + if (!_hasSpecialDeathSound) { + // one of eight body-hit sounds, fixed per unit + uint const _hitSound = this->units[unit2ID].fixedRng & 7; + if (_hitSound == 0) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT); + } else if (_hitSound == 1) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT2); + } else if (_hitSound == 2) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT3); + } else if (_hitSound == 3) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT4); + } else if (_hitSound == 4) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT5); + } else if (_hitSound == 5) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT6); + } else if (_hitSound == 6) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT7); + } else if (_hitSound == 7) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, + DAT_SFXState::ptr)(this->units[unit2ID].x, this->units[unit2ID].y, + OpenSHC::DE::SHCDE::FX_BODY_HIT8); + } + } + break; + } + } } return TRUE; } + // the owner through the global, as the original reads it: this-> loses the match + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && DAT_UnitsState::instance.units[unit2ID].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXWeAreUnderAttack, DAT_SFXState::ptr)(); + } + return FALSE; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 98c4514966..d5eb0b322a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49665,7 +49665,7 @@ SHC_3BB0A8C1_0x00531000 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005311F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00531220 | 57.0% | Asm differs +SHC_3BB0A8C1_0x00531220 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00531814 | 0.0% | Pending