diff options
Diffstat (limited to 'src/Z2AudioLib/Z2SoundObjMgr.cpp')
| -rw-r--r-- | src/Z2AudioLib/Z2SoundObjMgr.cpp | 260 |
1 files changed, 137 insertions, 123 deletions
diff --git a/src/Z2AudioLib/Z2SoundObjMgr.cpp b/src/Z2AudioLib/Z2SoundObjMgr.cpp index 7bd01335d2..6b3d29964b 100644 --- a/src/Z2AudioLib/Z2SoundObjMgr.cpp +++ b/src/Z2AudioLib/Z2SoundObjMgr.cpp @@ -1,8 +1,3 @@ -// -// Generated By: dol2asm -// Translation Unit: Z2SoundObjMgr -// - #include "Z2AudioLib/Z2SoundObjMgr.h" #include "Z2AudioLib/Z2Creature.h" #include "Z2AudioLib/Z2SeqMgr.h" @@ -11,9 +6,9 @@ #include "Z2AudioLib/Z2LinkMgr.h" /* 802BF920-802BF980 2BA260 0060+00 0/0 1/1 0/0 .text __ct__13Z2SoundObjMgrFv */ -Z2SoundObjMgr::Z2SoundObjMgr() : JASGlobalInstance<Z2SoundObjMgr>(this) { - mGhostEnemyState = 0; - mTwilightBattle = 0; +Z2SoundObjMgr::Z2SoundObjMgr() : JASGlobalInstance<Z2SoundObjMgr>(true) { + ghostEnemyState_ = 0; + twilightBattle_ = 0; setBattleInit(); setForceBattleArea(false, 700, 1100, 1500); } @@ -21,10 +16,10 @@ Z2SoundObjMgr::Z2SoundObjMgr() : JASGlobalInstance<Z2SoundObjMgr>(this) { /* 802BF980-802BF994 2BA2C0 0014+00 1/1 3/3 3/3 .text setForceBattleArea__13Z2SoundObjMgrFbUsUsUs */ void Z2SoundObjMgr::setForceBattleArea(bool forceBattle, u16 param_1, u16 param_2, u16 param_3) { - mForceBattle = forceBattle; - mEnemyArea.field_0x2 = param_1; - mEnemyArea.field_0x4 = param_2; - mEnemyArea.field_0x6 = param_3; + forceBattle_ = forceBattle; + enemyArea_.field_0x2 = param_1; + enemyArea_.field_0x4 = param_2; + enemyArea_.field_0x6 = param_3; } /* 80455B80-80455B84 004180 0004+00 1/1 0/0 0/0 .sdata2 sAreaDefault */ @@ -45,13 +40,13 @@ static Z2EnemyArea const sAreaSmall = {true, 300, 700, 1000}; /* 80455BA8-80455BAC 0041A8 0004+00 1/1 0/0 0/0 .sdata2 sAreaSmallFloating */ static Z2EnemyArea const sAreaSmallFloating = {false, 500, 800, 1200}; -struct EnemyInfo { +struct Z2EnemyInfo { char mName[8]; Z2EnemyArea mEnemyArea; }; /* 803CAD70-803CB170 027E90 0400+00 3/3 0/0 0/0 .data mEnemyInfo */ -static EnemyInfo mEnemyInfo[64] = { +static Z2EnemyInfo mEnemyInfo[64] = { {"Dummy", sAreaDefault}, {"E_s1", {true, 700, 1200, 2000}}, {"E_yk", sAreaSmallFloating}, @@ -120,72 +115,80 @@ static EnemyInfo mEnemyInfo[64] = { /* 802BF994-802BFFEC 2BA2D4 0658+00 1/0 1/1 0/0 .text searchEnemy__13Z2SoundObjMgrFv */ void Z2SoundObjMgr::searchEnemy() { - mTwilightBattle = 0; - Z2CreatureLink* link = Z2GetLink(); - if (link == 0) { + twilightBattle_ = 0; + + if (!Z2GetLink()) { Z2GetSeqMgr()->stopBattleBgm(1, 1); return; } bool bVar7 = false; bool local_96 = false; - bool iVar8 = false; + + bool isHolyForestBgm = false; if (Z2GetSeqMgr()->getMainBgmID() == Z2BGM_HOLY_FOREST) { - iVar8 = true; + isHolyForestBgm = true; } - u8 iVar16 = 0; + + u8 subBgmType = 0; if (Z2GetSeqMgr()->getSubBgmID() == Z2BGM_HORSE_BATTLE) { - iVar16 = 1; + subBgmType = 1; } else if (Z2GetSeqMgr()->getSubBgmID() == Z2BGM_FACE_OFF_BATTLE2) { - iVar16 = 2; + subBgmType = 2; } + field_0x14 = 0; - mEnemyNumNear = 0; + enemuNumNear_ = 0; field_0x16 = 0; - mEnemyNumVeryFar = 0; + enemuNumVeryFar_ = 0; field_0x1a = false; field_0x18 = 0; - f32 dVar18 = Z2Calc::getParamByExp( + + f32 linkDistScale = Z2Calc::getParamByExp( Z2GetLink()->getMoveSpeed(), 0.0f, 100.0f, 0.3f, 1.0f, 2.5f, - Z2Calc::CURVE_SIGN_1); - f32 dVar19 = 5000.0f; + Z2Calc::CURVE_POSITIVE); + f32 veryFarDist = 5000.0f; - for (JSULink<Z2CreatureEnemy>* local_8c = getFirst(); local_8c != NULL; local_8c = local_8c->getNext()) { - Z2CreatureEnemy* this_00 = local_8c->getObject(); - if (this_00 == NULL) { + for (JSULink<Z2CreatureEnemy>* i = getFirst(); i != NULL; i = i->getNext()) { + Z2CreatureEnemy* enemy = i->getObject(); + if (enemy == NULL) { + JUT_WARN_DEVICE(100, 1, "%s", "[Z2SoundObjMgr::searchEnemy] remain remove enemy\n"); continue; } - if (this_00->field_0xa1 < 1) { + + if (enemy->field_0xa1 < 1) { continue; } - bool bVar6 = false; - u8 enemyId = this_00->mEnemyID; + + bool isGhostEnemy = false; + + u8 enemyId = enemy->mEnemyID; switch (enemyId) { case Z2_ENEMY_SW: - if (Z2GetSceneMgr()->getCurrentSceneNum() == 0x1c) + if (Z2GetSceneMgr()->getCurrentSceneNum() == Z2SCENE_GERUDO_DESERT) continue; break; case Z2_ENEMY_CR: - if (Z2GetSceneMgr()->getCurrentSceneNum() == 0x1e) + if (Z2GetSceneMgr()->getCurrentSceneNum() == Z2SCENE_HYRULE_FIELD) continue; break; case Z2_ENEMY_NZ: case Z2_ENEMY_PO: case Z2_ENEMY_HP: - bVar6 = true; + isGhostEnemy = true; break; case Z2_ENEMY_RDB: - if (iVar16 == 0) + if (subBgmType == 0) continue; break; case Z2_ENEMY_WB: case Z2_ENEMY_RD: - if (iVar16 != 0) + if (subBgmType != 0) continue; #if VERSION == VERSION_GCN_JPN } @@ -208,77 +211,86 @@ void Z2SoundObjMgr::searchEnemy() { #endif if (!Z2GetLink()->isRiding()) break; - if (Z2GetLink()->getMoveSpeed() <= 0x26) + if (Z2GetLink()->getMoveSpeed() <= 38) break; continue; } - Vec* iVar10 = this_00->getCurrentPos(); - if (iVar10 != NULL) { - Vec* iVar14 = Z2GetLink()->getCurrentPos(); - if (iVar14 != NULL) { - Z2EnemyArea local_88 = mEnemyInfo[enemyId].mEnemyArea; - if (mForceBattle) { - local_88 = mEnemyArea; + + Vec* enemyPos = enemy->getCurrentPos(); + if (enemyPos != NULL) { + Vec* linkPos = Z2GetLink()->getCurrentPos(); + if (linkPos != NULL) { + Z2EnemyArea enemyArea = mEnemyInfo[enemyId].mEnemyArea; + if (forceBattle_) { + enemyArea = enemyArea_; } - f32 fVar2 = 2.0f; - if (local_88.field_0x0 == true) { - fVar2 = 4.0f; + + f32 y_scale = 2.0f; + if (enemyArea.field_0x0 == true) { + y_scale = 4.0f; } - Vec local_80 = {0.0f, 0.0f, 0.0f}; - VECSubtract(iVar10, iVar14, &local_80); - local_80.y *= fVar2; - f32 dVar20 = VECMag(&local_80); - if (dVar20 < local_88.field_0x6 * dVar18) { - if (bVar6) { + + Vec enemy_linkVec = {0.0f, 0.0f, 0.0f}; + VECSubtract(enemyPos, linkPos, &enemy_linkVec); + enemy_linkVec.y *= y_scale; + + f32 enemyDist = VECMag(&enemy_linkVec); + if (enemyDist < enemyArea.field_0x6 * linkDistScale) { + if (isGhostEnemy) { field_0x1a++; - if (dVar20 < local_88.field_0x4 * dVar18) { - mGhostEnemyState |= 1; - if (mGhostEnemyState >= 0x10) { - mEnemyNumNear++; - if (dVar20 < local_88.field_0x2 * dVar18) { + if (enemyDist < enemyArea.field_0x4 * linkDistScale) { + ghostEnemyState_ |= (u8)1; + if (ghostEnemyState_ >= 16) { + enemuNumNear_++; + if (enemyDist < enemyArea.field_0x2 * linkDistScale) { field_0x14++; } } } - if (mGhostEnemyState >= 0x11) { + + if (ghostEnemyState_ >= 17) { field_0x16++; - if (this_00->mLinkSearch) { + if (enemy->mLinkSearch) { local_96 = true; } } } else { field_0x16++; if (enemyId != 0 && enemyId < 9) { - if (mTwilightBattle == 0) { - mTwilightBattle = 1; + if (twilightBattle_ == 0) { + twilightBattle_ = 1; } - if (enemyId == 0x1 || enemyId == 0x5) { - mTwilightBattle = 2; + + if (enemyId == Z2_ENEMY_S1 || enemyId == Z2_ENEMY_YC) { + twilightBattle_ = 2; } - if (enemyId == 0x8) { - mTwilightBattle = 2; + + if (enemyId == Z2_ENEMY_YMB) { + twilightBattle_ = 2; } else { - Z2GetSeqMgr()->changeSubBgmStatus(mTwilightBattle); + Z2GetSeqMgr()->changeSubBgmStatus(twilightBattle_); } } - if (enemyId != 0x2c && this_00->mLinkSearch) { + + if (enemyId != Z2_ENEMY_GB && enemy->mLinkSearch) { local_96 = true; } - if (dVar20 < local_88.field_0x4 * dVar18) - { - mEnemyNumNear++; - if (dVar20 < local_88.field_0x2 * dVar18) - { + + if (enemyDist < enemyArea.field_0x4 * linkDistScale) { + enemuNumNear_++; + if (enemyDist < enemyArea.field_0x2 * linkDistScale) { field_0x14++; } } } } - if (dVar20 < dVar19 * dVar18) { - mEnemyNumVeryFar++; + + if (enemyDist < veryFarDist * linkDistScale) { + enemuNumVeryFar_++; } - if (this_00->field_0xa3 != 0) { + + if (enemy->field_0xa3 != 0) { bVar7 = true; field_0x18++; } @@ -286,108 +298,108 @@ void Z2SoundObjMgr::searchEnemy() { } } - if (mGhostEnemyState == 0x11) { + if (ghostEnemyState_ == 17) { if (field_0x1a >= field_0x16) { Z2GetSeqMgr()->setBattleGhostMute(false); } else { Z2GetSeqMgr()->setBattleGhostMute(true); } - } else if (mGhostEnemyState < 0x20 && field_0x1a == 0x0) { + } else if (ghostEnemyState_ < 32 && field_0x1a == 0) { setGhostEnemyState(0); } - if (iVar16 == 1) { - if (field_0x14 != 0x0) { + + if (subBgmType == 1) { + if (field_0x14 != 0) { Z2GetSeqMgr()->changeSubBgmStatus(1); } else { Z2GetSeqMgr()->changeSubBgmStatus(0); } - } else if (iVar16 == 2) { - if (mEnemyNumNear != 0x0) { + } else if (subBgmType == 2) { + if (enemuNumNear_ != 0) { Z2GetSeqMgr()->changeSubBgmStatus(1); } else { Z2GetSeqMgr()->changeSubBgmStatus(0); } - } else if (iVar8) { - if (field_0x16 != 0x0) { + } else if (isHolyForestBgm) { + if (field_0x16 != 0) { Z2GetSeqMgr()->changeBgmStatus(1); } else { Z2GetSeqMgr()->changeBgmStatus(0); } } else if (!bVar7) { Z2GetSeqMgr()->setBattleSearched(local_96); - if (field_0x14 != 0x0) { + + if (field_0x14 != 0) { Z2GetSeqMgr()->setBattleDistState(0); + } else if (enemuNumNear_ != 0) { + Z2GetSeqMgr()->setBattleDistState(1); + } else if (field_0x16 != 0) { + Z2GetSeqMgr()->setBattleDistState(2); } else { - if (mEnemyNumNear != 0x0) { - Z2GetSeqMgr()->setBattleDistState(1); - } else { - if (field_0x16 != 0x0) { - Z2GetSeqMgr()->setBattleDistState(2); - } else { - Z2GetSeqMgr()->setBattleDistState(3); - } - } + Z2GetSeqMgr()->setBattleDistState(3); } } } -void Z2SoundObjMgr::setGhostEnemyState(u8 p1) { - if (p1 == 0x20) { +void Z2SoundObjMgr::setGhostEnemyState(u8 state) { + if (state == 32) { if (field_0x1a >= field_0x16) { - JASGlobalInstance<Z2SeqMgr>::getInstance()->setBattleGhostMute(true); + Z2GetSeqMgr()->setBattleGhostMute(true); } } else { if (field_0x1a == false) { - mGhostEnemyState = 0; + ghostEnemyState_ = 0; return; } } - mGhostEnemyState = p1 + (mGhostEnemyState & 1); + ghostEnemyState_ = state + (ghostEnemyState_ & 1); } /* 802C0074-802C0100 2BA9B4 008C+00 0/0 1/1 0/0 .text * getEnemyID__13Z2SoundObjMgrFPCcP26JSULink<15Z2CreatureEnemy> */ -u8 Z2SoundObjMgr::getEnemyID(char const* param_0, JSULink<Z2CreatureEnemy>* param_1) { - if (param_0 != NULL) { - for (u8 uVar2 = 0; uVar2 < ARRAY_SIZEU(mEnemyInfo); uVar2++) { - if (strcmp(param_0, mEnemyInfo[(u32)uVar2].mName) == 0) { - append(param_1); - return uVar2; +u8 Z2SoundObjMgr::getEnemyID(const char* enemyName, JSULink<Z2CreatureEnemy>* enemyLink) { + if (enemyName != NULL) { + for (u8 i = 0; i < ARRAY_SIZEU(mEnemyInfo); i++) { + if (strcmp(enemyName, mEnemyInfo[(u32)i].mName) == 0) { + append(enemyLink); + return i; } } } + return Z2_ENEMY_NULL; } /* 802C0100-802C0120 2BAA40 0020+00 1/1 1/1 0/0 .text setBattleInit__13Z2SoundObjMgrFv */ void Z2SoundObjMgr::setBattleInit() { field_0x14 = 0; - mEnemyNumNear = 0; + enemuNumNear_ = 0; field_0x16 = 0; - mEnemyNumVeryFar = 0; + enemuNumVeryFar_ = 0; field_0x18 = 0; field_0x1a = false; } /* 802C0120-802C013C 2BAA60 001C+00 0/0 1/1 0/0 .text checkBattleFinish__13Z2SoundObjMgrFv */ bool Z2SoundObjMgr::checkBattleFinish() { - return mEnemyNumVeryFar - field_0x18 <= 0; + if (enemuNumVeryFar_ - field_0x18 > 0) { + return false; + } else { + return true; + } } /* 802C013C-802C0190 2BAA7C 0054+00 0/0 1/1 0/0 .text deleteEnemyAll__13Z2SoundObjMgrFv */ void Z2SoundObjMgr::deleteEnemyAll() { - JSULink<Z2CreatureEnemy>* link; + JSULink<Z2CreatureEnemy>* i; - // not moving the link pointer forward looks like a bug, but deleteObject() actually unlinks the - // enemy from its owning list - while (link = this->getFirst(), link != NULL) { - Z2CreatureEnemy* enemy = link->getObject(); + // not moving the pointer forward looks like a bug, but deleteObject() actually unlinks the enemy from its owning list + while (i = getFirst(), i != NULL) { + Z2CreatureEnemy* enemy = i->getObject(); if (enemy == NULL) { - // setWarningMessage_f((JUTAssertion *)0x1,(ulong)"Z2SoundObjMgr.cpp",(char - // *)0x16f,(int)&*fill*, - // "[Z2SoundObjMgr::searchEnemy] remain remove enemy\n",in_r8); + JUT_WARN_DEVICE(367, 1, "%s", "[Z2SoundObjMgr::searchEnemy] remain remove enemy\n"); } else { enemy->deleteObject(); } @@ -396,20 +408,22 @@ void Z2SoundObjMgr::deleteEnemyAll() { /* 802C0190-802C01E4 2BAAD0 0054+00 0/0 2/2 0/0 .text * removeEnemy__13Z2SoundObjMgrFP26JSULink<15Z2CreatureEnemy> */ -bool Z2SoundObjMgr::removeEnemy(JSULink<Z2CreatureEnemy>* param_0) { - if (param_0 == NULL) { +bool Z2SoundObjMgr::removeEnemy(JSULink<Z2CreatureEnemy>* enemyLink) { + if (enemyLink == NULL) { return false; } - Z2CreatureEnemy* enemy = param_0->getObject(); + Z2CreatureEnemy* enemy = enemyLink->getObject(); if (enemy->field_0xa3 != 0 && field_0x18 != 0) { field_0x18--; } - return remove(param_0); + + bool result = remove(enemyLink); + return result; } /* 802C01E4-802C01EC 2BAB24 0008+00 0/0 4/4 0/0 .text isTwilightBattle__13Z2SoundObjMgrFv */ u8 Z2SoundObjMgr::isTwilightBattle() { - return mTwilightBattle; + return twilightBattle_; } |
