Files
dusklight/src/Z2AudioLib/Z2SoundObjMgr.cpp
T
Caroline Madsen 5650c7fe08 JAudio2 and Z2AudioLib work (#2223)
* JAudio2 and Z2AudioLib work

* check1stDynamicWave matched
2024-10-24 02:25:13 +03:00

405 lines
13 KiB
C++

//
// Generated By: dol2asm
// Translation Unit: Z2SoundObjMgr
//
#include "Z2AudioLib/Z2SoundObjMgr.h"
#include "Z2AudioLib/Z2Creature.h"
#include "Z2AudioLib/Z2SeqMgr.h"
#include "Z2AudioLib/Z2Calc.h"
#include "Z2AudioLib/Z2SceneMgr.h"
/* 802BF920-802BF980 2BA260 0060+00 0/0 1/1 0/0 .text __ct__13Z2SoundObjMgrFv */
Z2SoundObjMgr::Z2SoundObjMgr() : JASGlobalInstance<Z2SoundObjMgr>(this) {
mGhostEnemyState = 0;
mTwilightBattle = 0;
setBattleInit();
setForceBattleArea(false, 700, 1100, 1500);
}
/* 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;
}
/* 80455B80-80455B84 004180 0004+00 1/1 0/0 0/0 .sdata2 sAreaDefault */
static Z2EnemyArea const sAreaDefault = {true, 700, 1100, 1500};
/* 80455B88-80455B8C 004188 0004+00 1/1 0/0 0/0 .sdata2 sAreaFloating */
static Z2EnemyArea const sAreaFloating = {false, 700, 1100, 1500};
/* 80455B90-80455B94 004190 0004+00 1/1 0/0 0/0 .sdata2 sAreaWide */
static Z2EnemyArea const sAreaWide = {true, 700, 1500, 3300};
/* 80455B98-80455B9C 004198 0004+00 1/1 0/0 0/0 .sdata2 sAreaWideFloating */
static Z2EnemyArea const sAreaWideFloating = {false, 700, 1500, 3300};
/* 80455BA0-80455BA4 0041A0 0004+00 1/1 0/0 0/0 .sdata2 sAreaSmall */
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 {
char mName[8];
Z2EnemyArea mEnemyArea;
};
/* 803CAD70-803CB170 027E90 0400+00 3/3 0/0 0/0 .data mEnemyInfo */
static EnemyInfo mEnemyInfo[64] = {
{"Dummy", sAreaDefault},
{"E_s1", {true, 700, 1200, 2000}},
{"E_yk", sAreaSmallFloating},
{"E_yr", sAreaWideFloating},
{"E_yg", {true, 300, 500, 700}},
{"E_yc", sAreaWideFloating},
{"E_yd", {true, 500, 900, 1500}},
{"E_rdy", sAreaDefault},
{"E_ymb", {false, 10, 20, 30}},
{"", sAreaDefault},
{"E_wb", sAreaDefault},
{"E_rd", sAreaDefault},
{"E_dn", sAreaDefault},
{"E_kr", sAreaWideFloating},
{"E_st", sAreaDefault},
{"E_tk", {true, 700, 1500, 2500}},
{"E_tk2", {true, 700, 1500, 2500}},
{"E_cr", sAreaSmall},
{"E_df", sAreaDefault},
{"E_fs", sAreaDefault},
{"E_SB", sAreaDefault},
{"E_PM", sAreaDefault},
{"E_db", {true, 500, 900, 1800}},
{"E_kg", sAreaSmall},
{"E_sh", sAreaDefault},
{"E_sf", sAreaDefault},
{"E_bs", {true, 200, 400, 600}},
{"E_SM", sAreaDefault},
{"E_ba", sAreaSmallFloating},
{"E_bu", sAreaFloating},
{"E_HM", sAreaDefault},
{"E_ge", sAreaFloating},
{"E_hz", {false, 500, 800, 1300}},
{"E_ws", sAreaSmallFloating},
{"E_oc", sAreaDefault},
{"E_fz", sAreaDefault},
{"E_fb", sAreaDefault},
{"E_bg", sAreaSmall},
{"E_mm", {true, 500, 800, 1500}},
{"E_nz", {true, 500, 700, 1100}},
{"E_po", sAreaWide},
{"E_rb", sAreaDefault},
{"E_sg", {true, 500, 700, 900}},
{"E_hb", {true, 500, 900, 1500}},
{"E_gb", {true, 1600, 3000, 4000}},
{"E_ms", {true, 500, 700, 1100}},
{"E_dd", sAreaDefault},
{"E_bi", {true, 500, 700, 900}},
{"E_tt", sAreaSmallFloating},
{"E_ai", sAreaDefault},
{"E_dk", sAreaSmall},
{"E_ww", sAreaWide},
{"E_gi", sAreaDefault},
{"E_sm2", sAreaDefault},
{"E_sw", {true, 400, 600, 1500}},
{"E_rdb", {true, 500, 1000, 1500}},
{"E_kk", sAreaDefault},
{"E_hp", sAreaDefault},
{"E_zh", sAreaDefault},
{"E_gm", sAreaSmall},
{"B_GG", {false, 1000, 2000, 4000}},
{"E_mf", sAreaDefault},
{"E_zm", sAreaDefault},
{"B_tn", sAreaDefault},
};
/* 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) {
Z2GetSeqMgr()->stopBattleBgm(1, 1);
return;
}
bool bVar7 = false;
bool local_96 = false;
bool iVar8 = false;
if (Z2GetSeqMgr()->getMainBgmID() == Z2BGM_HOLY_FOREST) {
iVar8 = true;
}
u8 iVar16 = 0;
if (Z2GetSeqMgr()->getSubBgmID() == Z2BGM_HORSE_BATTLE) {
iVar16 = 1;
} else if (Z2GetSeqMgr()->getSubBgmID() == Z2BGM_FACE_OFF_BATTLE2) {
iVar16 = 2;
}
field_0x14 = 0;
mEnemyNumNear = 0;
field_0x16 = 0;
mEnemyNumVeryFar = 0;
field_0x1a = false;
field_0x18 = 0;
f32 dVar18 = Z2Calc::getParamByExp(
Z2GetLink()->getMoveSpeed(),
0.0f,
100.0f,
0.3f,
1.0f,
2.5f,
Z2Calc::CURVE_SIGN_1);
f32 dVar19 = 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) {
continue;
}
if (this_00->field_0xa1 < 1) {
continue;
}
bool bVar6 = false;
u8 enemyId = this_00->mEnemyID;
switch (enemyId) {
case 0x36:
if (Z2GetSceneMgr()->getCurrentSceneNum() == 0x1c)
continue;
break;
case 0x11:
if (Z2GetSceneMgr()->getCurrentSceneNum() == 0x1e)
continue;
break;
case 0x27:
case 0x28:
case 0x39:
bVar6 = true;
break;
case 0x37:
if (iVar16 == 0)
continue;
break;
case 0xa:
case 0xb:
if (iVar16 != 0)
continue;
case 0xc:
case 0x16:
case 0x1f:
case 0x22:
case 0x26:
case 0x29:
case 0x2b:
case 0x30:
case 0x35:
if (!Z2GetLink()->isRiding())
break;
if (Z2GetLink()->getMoveSpeed() <= 0x26)
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;
}
f32 fVar2 = 2.0f;
if (local_88.field_0x0 == true) {
fVar2 = 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) {
field_0x1a++;
if (dVar20 < local_88.field_0x4 * dVar18) {
mGhostEnemyState |= 1;
if (mGhostEnemyState >= 0x10) {
mEnemyNumNear++;
if (dVar20 < local_88.field_0x2 * dVar18) {
field_0x14++;
}
}
}
if (mGhostEnemyState >= 0x11) {
field_0x16++;
if (this_00->mLinkSearch) {
local_96 = true;
}
}
} else {
field_0x16++;
if (enemyId != 0 && enemyId < 9) {
if (mTwilightBattle == 0) {
mTwilightBattle = 1;
}
if (enemyId == 0x1 || enemyId == 0x5) {
mTwilightBattle = 2;
}
if (enemyId == 0x8) {
mTwilightBattle = 2;
} else {
Z2GetSeqMgr()->changeSubBgmStatus(mTwilightBattle);
}
}
if (enemyId != 0x2c && this_00->mLinkSearch) {
local_96 = true;
}
if (dVar20 < local_88.field_0x4 * dVar18)
{
mEnemyNumNear++;
if (dVar20 < local_88.field_0x2 * dVar18)
{
field_0x14++;
}
}
}
}
if (dVar20 < dVar19 * dVar18) {
mEnemyNumVeryFar++;
}
if (this_00->field_0xa3 != 0) {
bVar7 = true;
field_0x18++;
}
}
}
}
if (mGhostEnemyState == 0x11) {
if (field_0x1a >= field_0x16) {
Z2GetSeqMgr()->setBattleGhostMute(false);
} else {
Z2GetSeqMgr()->setBattleGhostMute(true);
}
} else if (mGhostEnemyState < 0x20 && field_0x1a == 0x0) {
setGhostEnemyState(0);
}
if (iVar16 == 1) {
if (field_0x14 != 0x0) {
Z2GetSeqMgr()->changeSubBgmStatus(1);
} else {
Z2GetSeqMgr()->changeSubBgmStatus(0);
}
} else if (iVar16 == 2) {
if (mEnemyNumNear != 0x0) {
Z2GetSeqMgr()->changeSubBgmStatus(1);
} else {
Z2GetSeqMgr()->changeSubBgmStatus(0);
}
} else if (iVar8) {
if (field_0x16 != 0x0) {
Z2GetSeqMgr()->changeBgmStatus(1);
} else {
Z2GetSeqMgr()->changeBgmStatus(0);
}
} else if (!bVar7) {
Z2GetSeqMgr()->setBattleSearched(local_96);
if (field_0x14 != 0x0) {
Z2GetSeqMgr()->setBattleDistState(0);
} else {
if (mEnemyNumNear != 0x0) {
Z2GetSeqMgr()->setBattleDistState(1);
} else {
if (field_0x16 != 0x0) {
Z2GetSeqMgr()->setBattleDistState(2);
} else {
Z2GetSeqMgr()->setBattleDistState(3);
}
}
}
}
}
void Z2SoundObjMgr::setGhostEnemyState(u8 p1) {
if (p1 == 0x20) {
if (field_0x1a >= field_0x16) {
JASGlobalInstance<Z2SeqMgr>::getInstance()->setBattleGhostMute(true);
}
} else {
if (field_0x1a == false) {
mGhostEnemyState = 0;
return;
}
}
mGhostEnemyState = p1 + (mGhostEnemyState & 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 < 0x40; uVar2++) {
if (strcmp(param_0, mEnemyInfo[(u32)uVar2].mName) == 0) {
append(param_1);
return uVar2;
}
}
}
return Z2_ENEMY_ID_0;
}
/* 802C0100-802C0120 2BAA40 0020+00 1/1 1/1 0/0 .text setBattleInit__13Z2SoundObjMgrFv */
void Z2SoundObjMgr::setBattleInit() {
field_0x14 = 0;
mEnemyNumNear = 0;
field_0x16 = 0;
mEnemyNumVeryFar = 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;
}
/* 802C013C-802C0190 2BAA7C 0054+00 0/0 1/1 0/0 .text deleteEnemyAll__13Z2SoundObjMgrFv
*/
void Z2SoundObjMgr::deleteEnemyAll() {
JSULink<Z2CreatureEnemy>* link;
// 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();
if (enemy == NULL) {
// setWarningMessage_f((JUTAssertion *)0x1,(ulong)"Z2SoundObjMgr.cpp",(char
// *)0x16f,(int)&*fill*,
// "[Z2SoundObjMgr::searchEnemy] remain remove enemy\n",in_r8);
} else {
enemy->deleteObject();
}
}
}
/* 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) {
return false;
}
Z2CreatureEnemy* enemy = param_0->getObject();
if (enemy->field_0xa3 != 0 && field_0x18 != 0) {
field_0x18--;
}
return remove(param_0);
}
/* 802C01E4-802C01EC 2BAB24 0008+00 0/0 4/4 0/0 .text isTwilightBattle__13Z2SoundObjMgrFv
*/
u8 Z2SoundObjMgr::isTwilightBattle() {
return mTwilightBattle;
}