|
1 | 1 | #include "PDS.h" |
2 | 2 | #include "campDragon.h" |
3 | 3 | #include "town/town.h" |
| 4 | +#include "town/townDragon.h" |
| 5 | +#include "kernel/fileBundle.h" |
| 6 | +#include "kernel/graphicalObject.h" |
4 | 7 |
|
5 | | -struct sCampDragon : public s_workAreaTemplateWithArg<sCampDragon, sSaturnPtr>, sTownObject |
| 8 | +void initDragonForTown(sTownDragon* pThis); // TODO: Cleanup |
| 9 | +void updateTownDragon(sTownDragon* pThis); // TODO: cleanup |
| 10 | +void EdgeUpdateSub0(struct sMainLogic_74* r14_pose); // TODO cleanup |
| 11 | + |
| 12 | +struct sCampDragon_F8 { |
| 13 | + sVec3_FP m4; |
| 14 | + sMainLogic_74 m10; |
| 15 | + // size 0x8C |
| 16 | +}; |
| 17 | + |
| 18 | +struct sCampDragon : public sTownDragon |
6 | 19 | { |
7 | | - s16 m16; |
8 | | - sSaturnPtr m48; |
9 | | - sVec3_FP m4C; |
10 | | - sVec3_FP m58; |
11 | | - sVec3_FP m64; |
| 20 | + //0-E8: sTownDragon |
| 21 | + sVec3_FP mE8; |
| 22 | + s32 mF4 = 0; // count of F8 |
| 23 | + std::array<sCampDragon_F8, 9> mF8; |
12 | 24 | //size: 0x624 |
13 | 25 | }; |
14 | 26 |
|
15 | | -void sCampDragon_Init(sCampDragon* pThis, sSaturnPtr arg) { |
| 27 | +s32 sCampDragon_InitSub1(sTownDragon* pThis) { |
| 28 | + |
| 29 | + fixedPoint X = readSaturnFP(*(npcData0.m120_stack.end() - 2)); |
| 30 | + fixedPoint Y = readSaturnFP(*(npcData0.m120_stack.end() - 1)); |
| 31 | + |
| 32 | + return atan2_FP(X - (pThis->m58).m0_X, Y - (pThis->m58).m8_Z); |
| 33 | +} |
| 34 | + |
| 35 | +void increaseGameResource(int param_1, int param_2) { |
| 36 | + switch (param_1) |
| 37 | + { |
| 38 | + case 0xB: |
| 39 | + mainGameState.gameStats.m7C_overallRating = mainGameState.gameStats.m7C_overallRating + param_2; |
| 40 | + if ((int)mainGameState.gameStats.m7C_overallRating < 0) { |
| 41 | + mainGameState.gameStats.m7C_overallRating = 0; |
| 42 | + } |
| 43 | + if (0x7c < (int)mainGameState.gameStats.m7C_overallRating) { |
| 44 | + mainGameState.gameStats.m7C_overallRating = 0x7c; |
| 45 | + } |
| 46 | + break; |
| 47 | + default: |
| 48 | + assert(0); |
| 49 | + break; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +s32 sCampDragon_InitSub0() { |
| 54 | + s32 uVar1; |
| 55 | + int iVar2; |
| 56 | + |
| 57 | + uVar1 = mainGameState.gameStats.m7C_overallRating; |
| 58 | + iVar2 = readPackedBits(mainGameState.bitField, 0x1347, 0x20); |
| 59 | + iVar2 = uVar1 - iVar2; |
| 60 | + if (iVar2 < -0xf) { |
| 61 | + return 2; |
| 62 | + } |
| 63 | + if (iVar2 < -5) { |
| 64 | + return 3; |
| 65 | + } |
| 66 | + if (0xf < iVar2) { |
| 67 | + return 6; |
| 68 | + } |
| 69 | + if (5 < iVar2) { |
| 70 | + return 5; |
| 71 | + } |
| 72 | + return 4; |
| 73 | +} |
| 74 | + |
| 75 | +void sCampDragon_InitSub2(sCampDragon* pThis) { |
| 76 | + u32 temp = updateAndInterpolateAnimation(&gDragonState->m28_dragon3dModel); |
| 77 | + if (pThis->m24) { |
| 78 | + assert(0); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +void sCampDragon_Init(sTownDragon* pThisBase, sSaturnPtr arg) { |
| 83 | + sCampDragon* pThis = (sCampDragon*)pThisBase; |
16 | 84 | pThis->m48 = arg; |
17 | 85 | pThis->m4C = pThis->m58 = readSaturnVec3(arg + 0x8); |
18 | 86 | pThis->m64 = readSaturnVec3(arg + 0x14); |
| 87 | + npcData0.m70_npcPointerArray[readSaturnU16(arg + 0x20)].workArea = pThis; |
19 | 88 | pThis->m16 = 0x3C; |
| 89 | + increaseGameResource(0xb, 0); |
| 90 | + pThis->mF = sCampDragon_InitSub0(); |
| 91 | + pThis->m40 = 0x8000000; |
| 92 | + pThis->m3C = 0x8000000; |
| 93 | + pThis->mD8 = 0x1000; |
| 94 | + s32 temp = 0x8000000; |
| 95 | + if (mainGameState.getBit(0x263, 0x20) == 0) { |
| 96 | + temp = 0x4000000; |
| 97 | + } |
| 98 | + else { |
| 99 | + temp += performDivision(0x19, mainGameState.gameStats.m7C_overallRating) * 0x2000000; |
| 100 | + } |
| 101 | + pThis->m64.m4_Y = sCampDragon_InitSub1(pThis) + temp; |
| 102 | + pThis->m70.m30_pPosition = &pThis->m58; |
| 103 | + pThis->m70.m34_pRotation = &pThis->m64; |
| 104 | + pThis->m70.m38_pOwner = pThis; |
| 105 | + pThis->m70.m3C_scriptEA = pThis->m20; |
| 106 | + pThis->m70.m40 = 0; |
| 107 | + mainLogicInitSub0(&pThis->m70, 3); |
20 | 108 |
|
21 | | - Unimplemented(); |
| 109 | + static const sVec3_FP param1 = { |
| 110 | + -0x1800, |
| 111 | + -0x1800, |
| 112 | + -0x1800, |
| 113 | + }; |
| 114 | + |
| 115 | + static const sVec3_FP param2 = { |
| 116 | + 0x1800, |
| 117 | + 0x1000, |
| 118 | + 0x1800, |
| 119 | + }; |
| 120 | + |
| 121 | + mainLogicInitSub1(&pThis->m70, param1, param2); |
| 122 | + |
| 123 | + for (int i = 0; i < 9; i++) { |
| 124 | + auto* psVar3 = &pThis->mF8[i]; |
| 125 | + (psVar3->m10).m30_pPosition = &psVar3->m4; |
| 126 | + (psVar3->m10).m34_pRotation = &pThis->mE8; |
| 127 | + (psVar3->m10).m38_pOwner = pThis; |
| 128 | + (psVar3->m10).m3C_scriptEA = sSaturnPtr::getNull(); |
| 129 | + (psVar3->m10).m40 = nullptr; |
| 130 | + } |
| 131 | + initDragonForTown(pThis); |
| 132 | + pThis->m14 = 1; |
| 133 | + |
| 134 | + playAnimation(&gDragonState->m28_dragon3dModel, pThis->m1C->m0_fileBundle->getAnimation(readSaturnU16(pThis->m20 + 2)), 0); |
| 135 | + sCampDragon_InitSub2(pThis); |
22 | 136 | } |
23 | 137 |
|
24 | | -void sCampDragon_Update(sCampDragon* pThis) { |
| 138 | +void sCampDragon_UpdateSub0(sTownDragon* pThis) { |
25 | 139 | Unimplemented(); |
26 | 140 | } |
27 | 141 |
|
28 | | -void sCampDragon_Draw(sCampDragon* pThis) { |
| 142 | +void sCampDragon_UpdateMode4(sTownDragon* pThis) { |
| 143 | + switch (pThis->m11) { |
| 144 | + case 0: |
| 145 | + pThis->m12 = 1; |
| 146 | + pThis->m11 = 1; |
| 147 | + break; |
| 148 | + case 1: |
| 149 | + Unimplemented(); |
| 150 | + break; |
| 151 | + default: |
| 152 | + assert(0); |
| 153 | + break; |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +void sCampDragon_Update(sTownDragon* pThisBase) { |
| 158 | + sCampDragon* pThis = (sCampDragon*)pThisBase; |
| 159 | + |
| 160 | + pThis->mD = 1; |
| 161 | + updateTownDragon(pThis); |
| 162 | + |
| 163 | + if ((gDragonState->mC_dragonType < 0) || (7 < gDragonState->mC_dragonType)) { |
| 164 | + return; |
| 165 | + } |
| 166 | + |
| 167 | + pThis->m58 = pThis->m4C; |
| 168 | + pThis->m58[1] += pThis->mD8; |
| 169 | + EdgeUpdateSub0(&pThis->m70); |
| 170 | + |
| 171 | + for (int i = 0; i < pThis->mF4; i++) { |
| 172 | + assert(0); |
| 173 | + } |
| 174 | + |
| 175 | + sCampDragon_UpdateSub0(pThis); |
| 176 | + |
| 177 | + if (pThis->mE == 0) { |
| 178 | + switch (pThis->mF + pThis->m10) { |
| 179 | + case 4: |
| 180 | + sCampDragon_UpdateMode4(pThis); |
| 181 | + break; |
| 182 | + default: |
| 183 | + assert(0); |
| 184 | + break; |
| 185 | + } |
| 186 | + } |
| 187 | + else if ((pThis->mE & 1) == 0) { |
| 188 | + assert(0); |
| 189 | + } |
| 190 | + else { |
| 191 | + assert(0); |
| 192 | + } |
| 193 | + |
| 194 | + if (pThis->m12 == 0) { |
| 195 | + Unimplemented(); |
| 196 | + } |
| 197 | + |
29 | 198 | Unimplemented(); |
30 | 199 | } |
31 | 200 |
|
32 | | -void sCampDragon_Delete(sCampDragon* pThis) { |
| 201 | +void updateAnimationMatricesSub1WithScale(s3DModelAnimData* r4, s_3dModel* r5) |
| 202 | +{ |
| 203 | + u32 r9 = r5->m12_numBones; |
| 204 | + if (r9) |
| 205 | + { |
| 206 | + std::vector<sMatrix4x3>::iterator r14 = r4->m4_boneMatrices->begin(); |
| 207 | + if (r5->m48_poseDataInterpolation.size()) |
| 208 | + { |
| 209 | + std::vector<sPoseDataInterpolation>::iterator r13 = r5->m48_poseDataInterpolation.begin(); |
| 210 | + |
| 211 | + do |
| 212 | + { |
| 213 | + initMatrixToIdentity(&(*r14)); |
| 214 | + translateMatrix(&r13->m0_translation, &(*r14)); |
| 215 | + rotateMatrixZYX(&r13->mC_rotation, &(*r14)); |
| 216 | + //scaleMatrixRow0(r13->m18_scale[0], &(*r14)); |
| 217 | + //scaleMatrixRow1(r13->m18_scale[1], &(*r14)); |
| 218 | + //scaleMatrixRow2(r13->m18_scale[2], &(*r14)); |
| 219 | + r13++; |
| 220 | + r14++; |
| 221 | + } while (--r9); |
| 222 | + } |
| 223 | + else |
| 224 | + { |
| 225 | + std::vector<sPoseData>::iterator r13 = r5->m2C_poseData.begin(); |
| 226 | + |
| 227 | + do |
| 228 | + { |
| 229 | + initMatrixToIdentity(&(*r14)); |
| 230 | + translateMatrix(&r13->m0_translation, &(*r14)); |
| 231 | + rotateMatrixZYX(&r13->mC_rotation, &(*r14)); |
| 232 | + //scaleMatrixRow0(r13->m18_scale[0], &(*r14)); |
| 233 | + //scaleMatrixRow1(r13->m18_scale[1], &(*r14)); |
| 234 | + //scaleMatrixRow2(r13->m18_scale[2], &(*r14)); |
| 235 | + r13++; |
| 236 | + r14++; |
| 237 | + } while (--r9); |
| 238 | + } |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +void updateAnimationMatricesSub2(s3DModelAnimData* r4); // todo: cleanup |
| 243 | + |
| 244 | +void sCampDragon_Draw(sTownDragon* pThisBase) { |
| 245 | + sCampDragon* pThis = (sCampDragon*)pThisBase; |
| 246 | + |
| 247 | + if ((-1 < gDragonState->mC_dragonType) && (gDragonState->mC_dragonType < 8)) |
| 248 | + { |
| 249 | + updateAnimationMatricesSub1WithScale(&gDragonState->m78_animData, &gDragonState->m28_dragon3dModel); |
| 250 | + updateAnimationMatricesSub2(&gDragonState->m78_animData); |
| 251 | + |
| 252 | + Unimplemented(); |
| 253 | + submitModelAndShadowModelToRendering(&gDragonState->m28_dragon3dModel, gDragonState->m14_modelIndex, gDragonState->m18_shadowModelIndex, &pThis->m58, &pThis->m64, 0); |
| 254 | + if (pThis->mD) |
| 255 | + { |
| 256 | + Unimplemented(); |
| 257 | + } |
| 258 | + if (enableDebugTask) { |
| 259 | + assert(0); |
| 260 | + } |
| 261 | + } |
| 262 | +} |
| 263 | + |
| 264 | +void sCampDragon_Delete(sTownDragon* pThis) { |
33 | 265 | Unimplemented(); |
34 | 266 | } |
35 | 267 |
|
36 | | -struct sTownObject* createCampDragon(p_workArea parent, sSaturnPtr arg) { |
| 268 | +sTownObject* createCampDragon(p_workArea parent, sSaturnPtr arg) { |
37 | 269 | static const sCampDragon::TypedTaskDefinition definition = { |
38 | 270 | &sCampDragon_Init, |
39 | 271 | &sCampDragon_Update, |
|
0 commit comments