Skip to content

Commit f6f1789

Browse files
committed
Rewrite/clean some of the dragon loading code
1 parent a6e97cc commit f6f1789

16 files changed

+1020
-948
lines changed

AzelLib/battle/BTL_A3/BTL_A3.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "kernel/vdp1Allocator.h"
1111
#include "battle/battleEngine.h"
1212
#include "BTL_A3_data.h"
13+
#include "dragonData.h"
14+
#include "dragonRider.h"
1315

1416
#include "BTL_A3_BaldorFormation.h"
1517
#include "audio/soundDriver.h"
@@ -31,27 +33,38 @@ void battle_A3_initMusic(p_workArea pThis)
3133

3234
static const char* assetList[] = {
3335
"BATTLE.MCB",
34-
"BATTLE.CGB",
36+
"BATTLE.CGB",
37+
3538
"TUP.MCB",
36-
"TUP.CGB",
39+
"TUP.CGB",
40+
3741
"ENCAM.BDB",
42+
(char*)-1,
43+
3844
(char*)-1,
39-
(char*)-1,
40-
"A3CMN.CGB",
45+
"A3CMN.CGB",
46+
4147
"KEIKOKU.MCB",
42-
"KEIKOKU.CGB",
48+
"KEIKOKU.CGB",
49+
4350
"HEBIMUSI.MCB",
44-
"HEBIMUSI.CGB",
51+
"HEBIMUSI.CGB",
52+
4553
"KURAGE.MCB",
46-
"KURAGE.CGB",
54+
"KURAGE.CGB",
55+
4756
"BENITATE.MCB",
48-
"BENITATE.CGB",
57+
"BENITATE.CGB",
58+
4959
"HEBISU.MCB",
50-
"HEBISU.CGB",
60+
"HEBISU.CGB",
61+
5162
"FLD_A3.MCB",
52-
"FLD_A3.CGB",
63+
"FLD_A3.CGB",
64+
5365
"BTFALLA3.MCB",
54-
"BTFALLA3.CGB",
66+
"BTFALLA3.CGB",
67+
5568
nullptr,
5669
nullptr,
5770
};

AzelLib/battle/BTL_A3/BTL_A3_UrchinFormation.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ bool BTL_A3_UrchinFormation_Update_Mode1Sub2(BTL_A3_UrchinFormation* pThis)
205205
if (pThis->m18.m4[cVar1])
206206
{
207207
int uVar6 = enemyQuadrantsTable[pThis->m18.mD[0] + cVar1][gBattleManager->m10_battleOverlay->m4_battleEngine->m22C_dragonCurrentQuadrant];
208-
sSaturnPtr iVar5 = pThis->m30_config->m4_perTypeParams[cVar1]->m1C + pThis->m18.m7[cVar1] * 0x24;
209-
sSaturnPtr iVar9 = readSaturnEA(iVar5 + uVar6 * 4 + 4);
208+
sGenericFormationPerTypeDataSub1C& iVar5 = pThis->m30_config->m4_perTypeParams[cVar1]->m1C[pThis->m18.m7[cVar1]];
209+
sSaturnPtr iVar9 = iVar5.m4[uVar6];
210210
if (!iVar9.isNull())
211211
{
212-
if (readSaturnU8(iVar5 + uVar6 * 4 + 0x14))
212+
if (iVar5.m14[uVar6])
213213
{
214214
assert(0);
215215
}
@@ -310,7 +310,36 @@ bool BTL_A3_UrchinFormation_UpdateSub0(BTL_A3_UrchinFormation* pThis)
310310
// This is responsible to setup the quadrant danger/safety
311311
void BTL_A3_UrchinFormation_UpdateSub1(BTL_A3_UrchinFormation* pThis)
312312
{
313-
FunctionUnimplemented();
313+
for (int i=0; i<4; i++)
314+
{
315+
int uVar3 = 0;
316+
for (int j = 0; j < 3; j++)
317+
{
318+
if (pThis->m18.m4[j] && pThis->m30_config->m4_perTypeParams[j])
319+
{
320+
static const std::array<s8, 4> tempArray =
321+
{
322+
6,4,2,0
323+
};
324+
int uVar1 = rotateRightR0ByR1(pThis->m30_config->m4_perTypeParams[j]->m1C[pThis->m18.m7[j]].m1E, tempArray[enemyQuadrantsTable[pThis->m18.mD[j]][i]]);
325+
uVar3 |= uVar1 & 3;
326+
}
327+
}
328+
329+
switch (uVar3)
330+
{
331+
case 0:
332+
battleEngine_FlagQuadrantForDanger(i);
333+
break;
334+
case 1:
335+
case 3:
336+
battleEngine_FlagQuadrantForSafety(i);
337+
break;
338+
default:
339+
assert(0);
340+
break;
341+
}
342+
}
314343
}
315344

316345
void BTL_A3_UrchinFormation_Update(BTL_A3_UrchinFormation* pThis)

AzelLib/battle/BTL_A3/BTL_A3_UrchinFormation.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#pragma once
22

3+
struct sGenericFormationPerTypeDataSub1C
4+
{
5+
sSaturnPtr m0;
6+
std::array<sSaturnPtr, 4> m4;
7+
std::array<s8, 4> m14;
8+
u16 m1C_animationOffset;
9+
s8 m1E;
10+
// size 0x24
11+
};
12+
313
struct sGenericFormationPerTypeData
414
{
515
s8 m0;
@@ -8,10 +18,11 @@ struct sGenericFormationPerTypeData
818
s16 m4;
919
u16 m8_modelOffset;
1020
u16 mA_poseOffset;
11-
std::vector<s_hotpointDefinition>* mC_hotspotDefinitions;
21+
sHotpointBundle* mC_hotspotDefinitions;
1222
s8 m18;
13-
sSaturnPtr m1C;
23+
std::vector<sGenericFormationPerTypeDataSub1C> m1C;
1424
u32 m24;
25+
std::array<s8, 4> m28;
1526
s8 m38;
1627
};
1728

AzelLib/battle/BTL_A3/BTL_A3_data.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,14 @@ void BTL_A3_data::invoke(sSaturnPtr Func, p_workArea pParent)
4949
}
5050
}
5151

52-
std::vector<s_hotpointDefinition>* readRiderDefinitionSub(sSaturnPtr ptrEA, int numEntry)
52+
sHotpointBundle* readRiderDefinitionSub(sSaturnPtr ptrEA)
5353
{
5454
if (ptrEA.isNull())
5555
{
5656
return nullptr;
5757
}
5858

59-
std::vector<s_hotpointDefinition>* pNewVector = new std::vector<s_hotpointDefinition>;
60-
for (int i=0; i<numEntry; i++)
61-
{
62-
s_hotpointDefinition newValue;
63-
newValue.m0_ptr = readSaturnEA(ptrEA + 8 * i);
64-
newValue.m4_count = readSaturnU32(ptrEA + 8 * i + 4);
65-
pNewVector->push_back(newValue);
66-
}
67-
68-
return pNewVector;
59+
return new sHotpointBundle(ptrEA);
6960
}
7061

7162
sGenericFormationData* readUrchinFormation(sSaturnPtr ptrEA)
@@ -90,10 +81,33 @@ sGenericFormationData* readUrchinFormation(sSaturnPtr ptrEA)
9081
pSubEntry->m4 = readSaturnS16(subEntry + 4);
9182
pSubEntry->m8_modelOffset = readSaturnU16(subEntry + 8);
9283
pSubEntry->mA_poseOffset = readSaturnU16(subEntry + 0xA);
93-
pSubEntry->mC_hotspotDefinitions = readRiderDefinitionSub(readSaturnEA(subEntry + 0xC), 0x18);
84+
pSubEntry->mC_hotspotDefinitions = readRiderDefinitionSub(readSaturnEA(subEntry + 0xC));
9485
pSubEntry->m18 = readSaturnS8(subEntry + 0x18);
95-
pSubEntry->m1C = readSaturnEA(subEntry + 0x1C);
86+
87+
sSaturnPtr ptrTo1C = readSaturnEA(subEntry + 0x1C);
88+
for (int j=0; j<1; j++)
89+
{
90+
sGenericFormationPerTypeDataSub1C subData1C;
91+
92+
subData1C.m0 = readSaturnEA(ptrTo1C + 0);
93+
subData1C.m4[0] = readSaturnEA(ptrTo1C + 0x4 + 0);
94+
subData1C.m4[1] = readSaturnEA(ptrTo1C + 0x4 + 4);
95+
subData1C.m4[2] = readSaturnEA(ptrTo1C + 0x4 + 8);
96+
subData1C.m4[3] = readSaturnEA(ptrTo1C + 0x4 + 0xC);
97+
subData1C.m14[0] = readSaturnS8(ptrTo1C + 0x14 + 0);
98+
subData1C.m14[1] = readSaturnS8(ptrTo1C + 0x14 + 1);
99+
subData1C.m14[2] = readSaturnS8(ptrTo1C + 0x14 + 2);
100+
subData1C.m14[3] = readSaturnS8(ptrTo1C + 0x14 + 3);
101+
subData1C.m1C_animationOffset = readSaturnU16(ptrTo1C + 0x1C);
102+
subData1C.m1E = readSaturnS8(ptrTo1C + 0x1E);
103+
pSubEntry->m1C.push_back(subData1C);
104+
}
105+
96106
pSubEntry->m24 = readSaturnU32(subEntry + 0x24);
107+
pSubEntry->m28[0] = readSaturnS8(subEntry + 0x28 + 0);
108+
pSubEntry->m28[1] = readSaturnS8(subEntry + 0x28 + 1);
109+
pSubEntry->m28[2] = readSaturnS8(subEntry + 0x28 + 2);
110+
pSubEntry->m28[3] = readSaturnS8(subEntry + 0x28 + 3);
97111
pSubEntry->m38 = readSaturnS8(subEntry + 0x38);
98112
pNewData->m4_perTypeParams[i] = pSubEntry;
99113
}

AzelLib/battle/BTL_A3/baldor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ s_3dModel* Baldor_create3dModel(sBaldor* pThis, sSaturnPtr dataPtr, s32 arg)
5656

5757

5858
sSaturnPtr hotSpotDataEA = animData + readSaturnU32(animData + 4);
59-
std::vector<s_hotpointDefinition> * pHotSpotsData = nullptr;
59+
sHotpointBundle* pHotSpotsData = nullptr;
6060
assert(animData == hotSpotDataEA); // else we need to load the data
6161

6262
init3DModelRawData(pThis, pOutputModel, 0, pFileBundle, readSaturnU16(animData), 0, pFileBundle->getStaticPose(readSaturnU16(animData + 2), pHierarchy->countNumberOfBones()), nullptr, pHotSpotsData);
@@ -879,9 +879,9 @@ void Baldor_initSub0Sub1(p_workArea pThis, s_3dModel* pModel, s16* param3, std::
879879
{
880880
param4[currentEntryIndex].m4_pPosition = nullptr;
881881

882-
sSaturnPtr puVar1 = (*pModel->m40)[i].m0_ptr + (i * 20);
882+
s_hotpoinEntry& puVar1 = (*pModel->m40)[i].m0[i];
883883

884-
Baldor_initSub1(&param4[currentEntryIndex], nullptr, &param5[currentEntryIndex], readSaturnS32(puVar1 + 4 * 4), readSaturnS32(puVar1), 0, 0, 10);
884+
Baldor_initSub1(&param4[currentEntryIndex], nullptr, &param5[currentEntryIndex], puVar1.m10, puVar1.m0, 0, 0, 10);
885885

886886
currentEntryIndex++;
887887
}

AzelLib/battle/BTL_A3/urchin.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ void Urchin_init(sUrchin* pThis, sGenericFormationPerTypeData* pConfig)
9898

9999
init3DModelRawData(pThis, &pThis->m5C_model, 0, pThis->m0_fileBundle, pConfig->m8_modelOffset, nullptr, pStaticPose, nullptr, pConfig->mC_hotspotDefinitions);
100100
Baldor_initSub0Sub1(pThis, &pThis->m5C_model, &pThis->mB6_numTargetables, pThis->mC0_targetable, pThis->mC4_position);
101-
updateUrchinAnimationSequence(pThis, readSaturnS16(pConfig->m1C + 0x1C), 0, 1, 1);
101+
updateUrchinAnimationSequence(pThis, pConfig->m1C[0].m1C_animationOffset, 0, 1, 1);
102102
pThis->mC8 = createBaldorSubTask0(&pThis->m8, 0, &pThis->mB4, pConfig->m0);
103103

104-
if (!readSaturnEA(pConfig->m1C).isNull())
104+
if (!pConfig->m1C[0].m0.isNull())
105105
{
106106
FunctionUnimplemented();
107107
}
@@ -148,7 +148,7 @@ void urchinUpdateSub0(sUrchin* pThis)
148148
{
149149
if ((pThis->mB0_flags & 0x10) == 0)
150150
{
151-
if ((cVar1 != 0) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38C_battleMode == 0) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38D_battleSubMode == 4))
151+
if ((cVar1 != 0) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38C_battleMode == eBattleModes::m0_shootEnemyWithGun) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38D_battleSubMode == 4))
152152
{
153153
for (int i = 0; i < pThis->mB6_numTargetables; i++)
154154
{
@@ -237,7 +237,43 @@ void urchinUpdateSub0(sUrchin* pThis)
237237

238238
void urchinUpdateSub1(sUrchin* pThis)
239239
{
240-
FunctionUnimplemented();
240+
s8 cVar1 = enemyQuadrantsTable[pThis->mD0->mD[pThis->mAF]][gBattleManager->m10_battleOverlay->m4_battleEngine->m22C_dragonCurrentQuadrant];
241+
242+
if ((pThis->mB0_flags & 8) == 0)
243+
{
244+
if ((pThis->mB0_flags & 0x10) == 0)
245+
{
246+
if ((cVar1 != 0) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38C_battleMode == eBattleModes::m3_shootEnemeyWithHomingLaser) && (gBattleManager->m10_battleOverlay->m4_battleEngine->m38D_battleSubMode == 4))
247+
{
248+
for (int i = 0; i < pThis->mB6_numTargetables; i++)
249+
{
250+
if ((pThis->mC0_targetable[i].m5A <= gBattleManager->m10_battleOverlay->m4_battleEngine->m394) && (pThis->mC0_targetable[i].m5A != 0))
251+
{
252+
pThis->mB8_delay = gBattleManager->m10_battleOverlay->m4_battleEngine->m394 * 4 + 0xF;
253+
pThis->mB0_flags |= 8;
254+
return;
255+
}
256+
}
257+
}
258+
}
259+
else
260+
{
261+
stepAnimation(&pThis->m5C_model);
262+
if (pThis->mB8_delay-- < 0)
263+
{
264+
for (int i = 0; i < pThis->mB6_numTargetables; i++)
265+
{
266+
pThis->mC0_targetable[i].m50_flags &= ~0x100000;
267+
}
268+
pThis->mB0_flags &= ~0x10;
269+
pThis->mD0->m14[pThis->mAE].m18 |= 0x20;
270+
}
271+
}
272+
}
273+
else
274+
{
275+
assert(0);
276+
}
241277
}
242278

243279
void urchinUpdateSub2(sUrchin* pThis)
@@ -255,12 +291,30 @@ void urchinUpdateSub2(sUrchin* pThis)
255291

256292
void urchinUpdateSub3(s_3dModel* pModel, std::vector<sVec3_FP>& pPosition)
257293
{
258-
FunctionUnimplemented();
294+
if (pModel->m40)
295+
{
296+
int outputIndex = 0;
297+
for (int i=0; i<pModel->m12_numBones; i++)
298+
{
299+
if (pModel->m44_hotpointData[i].size())
300+
{
301+
for (int j = 0; j < (*pModel->m40)[i].m4_count; j++)
302+
{
303+
pPosition[outputIndex++] = pModel->m44_hotpointData[i][j];
304+
}
305+
}
306+
}
307+
}
259308
}
260309

261310
void urchinUpdateSub4(sUrchin* pThis)
262311
{
263-
FunctionUnimplemented();
312+
int uVar1 = pThis->mCC->m28[enemyQuadrantsTable[pThis->mD0->mD[pThis->mAF]][gBattleManager->m10_battleOverlay->m4_battleEngine->m22C_dragonCurrentQuadrant]];
313+
314+
for (int i = 0; i < pThis->mB6_numTargetables; i++)
315+
{
316+
pThis->mC0_targetable[i].m60 = uVar1;
317+
}
264318
}
265319

266320
void Urchin_update(sUrchin* pThis)
@@ -350,7 +404,7 @@ void Urchin_update(sUrchin* pThis)
350404
{
351405
pThis->mB0_flags &= ~4;
352406
}
353-
else if (updateUrchinAnimationSequence(pThis, readSaturnS32(pThis->mCC->m1C + pThis->mB1 * 0x24 + 0x1C), 1, 1, 1))
407+
else if (updateUrchinAnimationSequence(pThis, pThis->mCC->m1C[pThis->mB1].m1C_animationOffset, 1, 1, 1))
354408
{
355409
pThis->mB0_flags &= ~4;
356410
}

0 commit comments

Comments
 (0)