1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include "boss.h"
const char* TLCarcNameList [] = {
"tcloud",
NULL
};
class dThunderCloud : public dEn_c {
int onCreate();
int onDelete();
int onExecute();
int onDraw();
mHeapAllocator_c allocator;
m3d::mdl_c bodyModel;
nw4r::g3d::ResFile resFile;
m3d::anmChr_c anm;
mEf::es2 bolt;
mEf::es2 charge;
float Baseline;
u32 timer;
int dying;
char killFlag;
u64 eventFlag;
ActivePhysics Lightning;
void dieFall_Begin();
void dieFall_Execute();
static dThunderCloud *build();
void updateModelMatrices();
void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat5_Mario(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat11_PipeCannon(ActivePhysics *apThis, ActivePhysics *apOther);
void bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate);
void _vf148();
void _vf14C();
bool CreateIceActors();
USING_STATES(dThunderCloud);
DECLARE_STATE(Follow);
DECLARE_STATE(Lightning);
};
dThunderCloud *dThunderCloud::build() {
void *buffer = AllocFromGameHeap1(sizeof(dThunderCloud));
return new(buffer) dThunderCloud;
}
CREATE_STATE(dThunderCloud, Follow);
CREATE_STATE(dThunderCloud, Lightning);
// Collision Callbacks
extern "C" void dAcPy_vf3F4(void* mario, void* other, int t);
extern "C" void BigHanaFireball(dEn_c* t, ActivePhysics *apThis, ActivePhysics *apOther);
extern "C" void *dAcPy_c__ChangePowerupWithAnimation(void * Player, int powerup);
extern "C" int CheckExistingPowerup(void * Player);
void dThunderCloud::playerCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
if (apThis->info.category2 == 0x9) {
int p = CheckExistingPowerup(apOther->owner);
if (p != 0 && p != 3) { // Powerups - 0 = small; 1 = big; 2 = fire; 3 = mini; 4 = prop; 5 = peng; 6 = ice; 7 = hammer
dAcPy_c__ChangePowerupWithAnimation(apOther->owner, 3);
}
else { dAcPy_vf3F4(apOther->owner, this, 9); }
}
else { dAcPy_vf3F4(apOther->owner, this, 9); }
}
void dThunderCloud::yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCat5_Mario(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCat11_PipeCannon(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
void dThunderCloud::collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther) { BigHanaFireball(this, apThis, apOther); }
void dThunderCloud::collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther) { BigHanaFireball(this, apThis, apOther); }
void dThunderCloud::collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther) {
if (apThis->info.category2 == 0x9) { return; }
PlaySound(this, SE_EMY_DOWN);
doStateChange(&StateID_DieFall); }
void dThunderCloud::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) { this->collisionCat13_Hammer(apThis, apOther); }
void dThunderCloud::collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther) {
if (apThis->info.category2 == 0x9) { return; }
dEn_c::collisionCat3_StarPower(apThis, apOther);
this->collisionCat13_Hammer(apThis, apOther); }
// These handle the ice crap
void dThunderCloud::_vf148() {
dEn_c::_vf148();
doStateChange(&StateID_DieFall);
}
void dThunderCloud::_vf14C() {
dEn_c::_vf14C();
doStateChange(&StateID_DieFall);
}
extern "C" void sub_80024C20(void);
extern "C" void __destroy_arr(void*, void(*)(void), int, int);
//extern "C" __destroy_arr(struct DoSomethingCool, void(*)(void), int cnt, int bar);
bool dThunderCloud::CreateIceActors() {
struct DoSomethingCool my_struct = { 0, (Vec){pos.x, pos.y - 16.0, pos.z}, {1.75, 1.4, 1.5}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
this->frzMgr.Create_ICEACTORs( (void*)&my_struct, 1 );
__destroy_arr( (void*)&my_struct, sub_80024C20, 0x3C, 1 );
return true;
}
void dThunderCloud::dieFall_Begin() {
this->Lightning.removeFromList();
this->timer = 0;
this->dEn_c::dieFall_Begin();
}
void dThunderCloud::dieFall_Execute() {
if (this->killFlag == 1) { return; }
this->timer = this->timer + 1;
this->dying = this->dying + 0.15;
this->pos.x = this->pos.x + 0.15;
this->pos.y = this->pos.y - ((-0.2 * (this->dying*this->dying)) + 5);
this->dEn_c::dieFall_Execute();
if (this->timer > 450) {
if ((this->settings >> 28) > 0) {
this->kill();
this->pos.y = this->pos.y + 800.0;
this->killFlag = 1;
return;
}
dStageActor_c *Player = GetSpecificPlayerActor(0);
if (Player == 0) { Player = GetSpecificPlayerActor(1); }
if (Player == 0) { Player = GetSpecificPlayerActor(2); }
if (Player == 0) { Player = GetSpecificPlayerActor(3); }
if (Player == 0) {
this->pos.x = 0;
doStateChange(&StateID_Follow); }
else {
Player->pos;
this->pos.x = Player->pos.x - 300;
}
this->pos.y = this->Baseline;
this->aPhysics.addToList();
doStateChange(&StateID_Follow);
}
}
void dThunderCloud::bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate) {
nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr(name);
this->anm.bind(&this->bodyModel, anmChr, unk);
this->bodyModel.bindAnim(&this->anm, unk2);
this->anm.setUpdateRate(rate);
}
int dThunderCloud::onCreate() {
// Setup the model
allocator.link(-1, GameHeaps[0], 0, 0x20);
this->resFile.data = getResource("tcloud", "g3d/tcloud.brres");
nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("cloud");
bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
SetupTextures_Enemy(&bodyModel, 0);
bool ret;
nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr("wait_cloud");
ret = this->anm.setup(mdl, anmChr, &this->allocator, 0);
allocator.unlink();
// Scale and Physics
ActivePhysics::Info Cloud;
Cloud.xDistToCenter = 0.0;
Cloud.yDistToCenter = 0.0;
Cloud.category1 = 0x3;
Cloud.category2 = 0x0;
Cloud.bitfield1 = 0x4F;
Cloud.bitfield2 = 0xffbafffe;
Cloud.xDistToEdge = 18.0;
Cloud.yDistToEdge = 12.0;
Cloud.unkShort1C = 0;
Cloud.callback = &dEn_c::collisionCallback;
this->aPhysics.initWithStruct(this, &Cloud);
this->aPhysics.addToList();
ActivePhysics::Info Shock;
Shock.xDistToCenter = 0.0;
Shock.yDistToCenter = -104.0;
Shock.category1 = 0x3;
Shock.category2 = 0x9;
Shock.bitfield1 = 0x4F;
Shock.bitfield2 = 0xffbafffe;
Shock.xDistToEdge = 12.0;
Shock.yDistToEdge = 90.0;
Shock.unkShort1C = 0;
Shock.callback = &dEn_c::collisionCallback;
this->Lightning.initWithStruct(this, &Shock);
// Some Settings
this->Baseline = this->pos.y;
this->dying = -5;
this->killFlag = 0;
this->pos.z = 5750.0f; // sun
char eventNum = (this->settings >> 16) & 0xFF;
this->eventFlag = (u64)1 << (eventNum - 1);
// State Change!
doStateChange(&StateID_Follow);
this->onExecute();
return true;
}
int dThunderCloud::onDelete() {
return true;
}
int dThunderCloud::onExecute() {
acState.execute();
updateModelMatrices();
bodyModel._vf1C();
if (dFlagMgr_c::instance->flags & this->eventFlag) {
if (this->killFlag == 0) {
this->kill();
this->pos.y = this->pos.y + 800.0;
this->killFlag = 1;
doStateChange(&StateID_DieFall);
}
}
return true;
}
int dThunderCloud::onDraw() {
bodyModel.scheduleForDrawing();
return true;
}
void dThunderCloud::updateModelMatrices() {
// This won't work with wrap because I'm lazy.
matrix.translation(pos.x, pos.y, pos.z);
matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
bodyModel.setDrawMatrix(matrix);
bodyModel.setScale(&scale);
bodyModel.calcWorld(false);
}
// Follow State
void dThunderCloud::beginState_Follow() {
this->timer = 0;
this->bindAnimChr_and_setUpdateRate("wait_cloud", 1, 0.0, 1.0);
this->rot.x = 0;
this->rot.y = 0;
this->rot.z = 0;
PlaySound(this, SE_AMB_THUNDER_CLOUD);
}
void dThunderCloud::executeState_Follow() {
charge.spawn("Wm_mr_electricshock_biri02_s", 0, &pos, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
if(this->anm.isAnimationDone()) {
this->anm.setCurrentFrame(0.0); }
if (this->timer > 200) { this->doStateChange(&StateID_Lightning); }
this->direction = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos);
float speedDelta;
speedDelta = 0.05;
if (this->direction == 0) {
this->speed.x = this->speed.x + speedDelta;
if (this->speed.x < 0) { this->speed.x = this->speed.x + (speedDelta / 1.5); }
if (this->speed.x < 6.0) { this->speed.x = this->speed.x + (speedDelta); }
}
else {
this->speed.x = this->speed.x - speedDelta;
if (this->speed.x > 0) { this->speed.x = this->speed.x - (speedDelta / 1.5); }
if (this->speed.x > 6.0) { this->speed.x = this->speed.x - (speedDelta); }
}
this->HandleXSpeed();
float yDiff;
yDiff = (this->Baseline - this->pos.y) / 8;
this->speed.y = yDiff;
this->HandleYSpeed();
this->UpdateObjectPosBasedOnSpeedValuesReal();
this->timer = this->timer + 1;
}
void dThunderCloud::endState_Follow() {
this->speed.y = 0;
}
// Wait State
void dThunderCloud::beginState_Lightning() {
this->timer = 0;
this->speed.x = 0.0;
}
void dThunderCloud::executeState_Lightning() {
switch (timer) {
case 0:
charge.spawn("Wm_en_birikyu", 0, &(Vec){pos.x, pos.y, pos.z}, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
break;
case 1:
charge.spawn("Wm_en_birikyu", 0, &(Vec){pos.x, pos.y, pos.z}, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
break;
case 2:
this->Lightning.addToList();
PlaySound(this, SE_BOSS_JR_ELEC_APP);
PlaySound(this, SE_BOSS_JR_DAMAGE_ELEC);
PlaySound(this, SE_OBJ_KAZAN_ERUPTION);
bolt.spawn("Wm_jr_electricline", 0, &(Vec){pos.x, pos.y - 98.0, 0}, &(S16Vec){0,0,0}, &(Vec){1.0, 2.5, 1.0});
break;
case 3:
this->Lightning.removeFromList();
charge.spawn("Wm_mr_electricshock_biri02_s", 0, &pos, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
break;
case 4:
charge.spawn("Wm_mr_electricshock_biri02_s", 0, &pos, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
break;
case 5:
this->doStateChange(&StateID_Follow);
break;
default:
charge.spawn("Wm_mr_electricshock_biri02_s", 0, &pos, &(S16Vec){0,0,0}, &(Vec){1.5, 1.5, 1.5});
break;
}
if(this->anm.isAnimationDone() && this->anm.getCurrentFrame() != 0.0) {
this->timer += 1;
if (timer == 2) { this->bindAnimChr_and_setUpdateRate("thundershoot", 1, 0.0, 1.0); }
if (timer == 3) { this->bindAnimChr_and_setUpdateRate("cloud_wait", 1, 0.0, 1.0); }
this->anm.setCurrentFrame(0.0); }
}
void dThunderCloud::endState_Lightning() {
this->timer = 0;
}
|