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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
#include <stage.h>
#include "boss.h"
extern "C" void *StageScreen;
// const char* effects_name_list [] = {
// "Wm_jr_electricline", // cool
// "Wm_jr_fireattack", // cool
// "Wm_jr_firehit", // cool
// "Wm_jr_fireplace", // cool
// "Wm_jr_fireplace_ind", // cool
// "Wm_jr_shot",
// "Wm_jr_sweat",
// "Wm_ko_fireattack", // cool
// "Wm_ko_firehit", // cool
// "Wm_ko_firehitdie01", // cool
// "Wm_ko_firehitdie02", // cool
// "Wm_ko_firehitdie03", // cool
// "Wm_ko_magmapocha",
// "Wm_ko_magmapochabig",
// "Wm_ko_shout", // cool
// "Wm_ko_shout02", // cool
// "Wm_seacloudout", // cool
// };
const char* CBarcNameList [] = {
"KoopaShip",
"koopa",
"choropoo",
"koopa_clown_bomb",
"dossun",
NULL
};
class daCaptainBowser : public daBoss {
public:
int onCreate();
int onDelete();
int onExecute();
int onDraw();
mHeapAllocator_c allocator;
nw4r::g3d::ResFile resFile;
nw4r::g3d::ResFile shipFile;
m3d::mdl_c bodyModel;
m3d::mdl_c shipModel;
m3d::anmChr_c chrAnimation;
m3d::anmChr_c shipAnm;
static const int SHIP_COLL_COUNT = 7;
ActivePhysics shipCollisions[SHIP_COLL_COUNT];
ActivePhysics Roar;
mEf::es2 effect;
mEf::es2 shipDmgA;
mEf::es2 shipDmgB;
mEf::es2 shipDmgC;
mEf::es2 shipDmgD;
mEf::es2 shipDmgE;
char isAngry;
char isInvulnerable;
char isIntro;
float scaleIncreaser;
int homingBillCountdown;
int homingBillSlot;
int maxDamage;
int playerCount;
float sinTimer;
float roarLen;
static daCaptainBowser *build();
void bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate);
void spriteCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void addScoreWhenHit(void *other);
USING_STATES(daCaptainBowser);
DECLARE_STATE(Wait);
DECLARE_STATE(Throw);
DECLARE_STATE(Fire);
DECLARE_STATE(Roar);
DECLARE_STATE(Damage);
DECLARE_STATE(Intro);
DECLARE_STATE(Outro);
};
daCaptainBowser *daCaptainBowser::build() {
void *buffer = AllocFromGameHeap1(sizeof(daCaptainBowser));
return new(buffer) daCaptainBowser;
}
///////////////////////
// Externs and States
///////////////////////
CREATE_STATE(daCaptainBowser, Wait);
CREATE_STATE(daCaptainBowser, Throw);
CREATE_STATE(daCaptainBowser, Fire);
CREATE_STATE(daCaptainBowser, Roar);
CREATE_STATE(daCaptainBowser, Damage);
CREATE_STATE(daCaptainBowser, Intro);
CREATE_STATE(daCaptainBowser, Outro);
////////////////////////
// Collision Functions
////////////////////////
void daCaptainBowser::addScoreWhenHit(void *other) { };
void daCaptainBowser::spriteCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
if (apOther->owner->name == 657) { //time to get hurt
if (this->isInvulnerable) {
return;
}
this->damage -= 1;
spawnHitEffectAtPosition((Vec2){apOther->owner->pos.x, apOther->owner->pos.y});
SpawnEffect("Wm_en_burst_m", 0, &apOther->owner->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0});
PlaySound(apOther->owner, SE_BOSS_CMN_STOMPED);
apOther->owner->Delete(1);
if (this->damage == this->maxDamage/2) { doStateChange(&StateID_Roar); }
else if (this->damage < 0) { doStateChange(&StateID_Outro); }
else { doStateChange(&StateID_Damage); }
}
}
void ShipAPhysicsCallback(ActivePhysics *apThis, ActivePhysics *apOther) {
daCaptainBowser *self = (daCaptainBowser*)apThis->owner;
if (apOther->owner->name == 657) {
OSReport("CANNON COLLISION");
if (self->isInvulnerable) {
return;
}
self->damage -= 1;
SpawnEffect("Wm_en_burst_m", 0, &apOther->owner->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0});
PlaySound(apOther->owner, SE_OBJ_TARU_BREAK);
apOther->owner->Delete(1);
if (self->damage == self->maxDamage/2) { self->doStateChange(&daCaptainBowser::StateID_Roar); }
else if (self->damage < 0) { self->doStateChange(&daCaptainBowser::StateID_Outro); }
apThis->someFlagByte |= 2;
}
}
void daCaptainBowser::playerCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
DamagePlayer(this, apThis, apOther);
}
void daCaptainBowser::bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate) {
nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr(name);
this->chrAnimation.bind(&this->bodyModel, anmChr, unk);
this->bodyModel.bindAnim(&this->chrAnimation, unk2);
this->chrAnimation.setUpdateRate(rate);
}
int daCaptainBowser::onCreate() {
// Model creation
allocator.link(-1, GameHeaps[0], 0, 0x20);
// B-b-b-bad boy Bowsaa
this->resFile.data = getResource("koopa", "g3d/koopa.brres");
nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("koopa");
bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
SetupTextures_Boss(&bodyModel, 0);
nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr("kp_wait");
this->chrAnimation.setup(mdl, anmChr, &this->allocator, 0);
// A ship off the ol' block
this->shipFile.data = getResource("KoopaShip", "g3d/KoopaShip.brres");
nw4r::g3d::ResMdl mdlShip = this->shipFile.GetResMdl("KoopaShip");
shipModel.setup(mdlShip, &allocator, 0x224, 1, 0);
SetupTextures_MapObj(&shipModel, 0);
nw4r::g3d::ResAnmChr anmChrShip = this->shipFile.GetResAnmChr("KoopaShip");
this->shipAnm.setup(mdlShip, anmChrShip, &this->allocator, 0);
this->shipAnm.bind(&this->shipModel, anmChrShip, 1);
this->shipModel.bindAnim(&this->shipAnm, 0.0);
this->shipAnm.setUpdateRate(1.0);
allocator.unlink();
// Prep the goods
this->playerCount = GetActivePlayerCount();
this->maxDamage = (20 * this->playerCount) + 10;
pos.z = 8000.0;
this->scale = (Vec){0.57, 0.57, 0.57};
this->homingBillCountdown = 270;
this->homingBillSlot = 0;
this->damage = this->maxDamage;
for (int i = 0; i < SHIP_COLL_COUNT; i++) {
shipCollisions[i].owner = this;
shipCollisions[i].info.category1 = 3;
shipCollisions[i].info.category2 = 0;
shipCollisions[i].info.bitfield1 = 0x4F;
shipCollisions[i].info.bitfield2 = 0x8028E;
shipCollisions[i].info.unkShort1C = 0;
shipCollisions[i].info.callback = &ShipAPhysicsCallback;
}
static const float xToCentres[] = {-56.541185, 161.824968, 106.258581};
static const float yToCentres[] = {-91.176745, -66.957921, 57.935231};
static const float xToEdges[] = {39.481380, 11.698187, 24.371222};
static const float yToEdges[] = {37.040555, 12.821730, 21.844430};
static const float trpValues0[] = {-39.481380, -11.698187, -24.371222};
static const float trpValues1[] = {-39.481380, -11.698187, 24.371222};
static const float trpValues2[] = {-39.481380, -11.698187, -24.371222};
static const float trpValues3[] = {39.481380, 11.698187, -24.371222};
static const float scX1[] = {-176.447600, 64.340078, -157.925471, -157.925471};
static const float scY1[] = {-128.217300, 112.570378, -109.695171, -109.695171};
static const float scX2[] = {-176.447600, 64.340078, -157.925471, -157.925471};
static const float scY2[] = {-128.217300, 112.570378, -109.695171, -109.695171};
for (int i = 0; i < SHIP_COLL_COUNT; i++) {
shipCollisions[i].info.xDistToCenter = xToCentres[i];
shipCollisions[i].info.yDistToCenter = yToCentres[i];
shipCollisions[i].info.xDistToEdge = xToEdges[i];
shipCollisions[i].info.yDistToEdge = yToEdges[i];
if (i >= 4) {
int xi = i - 4;
shipCollisions[i].trpValue0 = trpValues0[xi];
shipCollisions[i].trpValue1 = trpValues1[xi];
shipCollisions[i].trpValue2 = trpValues2[xi];
shipCollisions[i].trpValue3 = trpValues3[xi];
shipCollisions[i].collisionCheckType = 3;
}
}
// Bowser Physics!
ActivePhysics::Info BowserPhysics;
BowserPhysics.xDistToCenter = -152.0;
BowserPhysics.yDistToCenter = 152.0;
BowserPhysics.xDistToEdge = 38.0;
BowserPhysics.yDistToEdge = 38.0;
BowserPhysics.category1 = 0x3;
BowserPhysics.category2 = 0x0;
BowserPhysics.bitfield1 = 0x4F;
BowserPhysics.bitfield2 = 0x8028E;
BowserPhysics.unkShort1C = 0;
BowserPhysics.callback = &dEn_c::collisionCallback;
this->aPhysics.initWithStruct(this, &BowserPhysics);
// Roar Physics!
ActivePhysics::Info RoarStruct;
RoarStruct.xDistToCenter = -186.0;
RoarStruct.yDistToCenter = 138.0;
RoarStruct.xDistToEdge = 20.0;
RoarStruct.yDistToEdge = 20.0;
RoarStruct.category1 = 0x3;
RoarStruct.category2 = 0x0;
RoarStruct.bitfield1 = 0x4F;
RoarStruct.bitfield2 = 0x8028E;
RoarStruct.unkShort1C = 0;
RoarStruct.callback = &dEn_c::collisionCallback;
this->Roar.initWithStruct(this, &RoarStruct);
// State Changers
this->isIntro = 3;
doStateChange(&StateID_Intro);
return true;
}
int daCaptainBowser::onDelete() {
return true;
}
int daCaptainBowser::onExecute() {
acState.execute();
PlaySound(this, SE_BOSS_SHIP_PRPL);
bodyModel._vf1C();
shipModel._vf1C();
if(this->isIntro == 0) {
float xmod = sin(this->sinTimer * 3.14 / 180.0) * 60.0;
float ymod = sin(this->sinTimer * 3.14 / 130.0) * 84.0;
pos.x = ClassWithCameraInfo::instance->screenCentreX + 200.0 + xmod;
pos.y = ClassWithCameraInfo::instance->screenCentreY - 180.0 + ymod;
this->sinTimer++;
}
// this->homingBillCountdown--;
// if (this->homingBillCountdown == 0) {
// Vec tempPos;
// switch (this->homingBillSlot) {
// case 0:
// this->homingBillSlot++;
// tempPos.x = this->pos.x - 26.0;
// tempPos.y = this->pos.y + 40.0;
// tempPos.z = this->pos.z + 2000.0;
// break;
// case 1:
// this->homingBillSlot++;
// tempPos.x = this->pos.x + 22.0;
// tempPos.y = this->pos.y + 40.0;
// tempPos.z = this->pos.z + 2000.0;
// break;
// case 2:
// this->homingBillSlot = 0;
// tempPos.x = this->pos.x + 70.0;
// tempPos.y = this->pos.y + 40.0;
// tempPos.z = this->pos.z + 2000.0;
// break;
// }
// SpawnEffect("Wm_en_killervanish", 0, &tempPos, &(S16Vec){0,0,0}, &(Vec){0.1, 0.1, 0.1});
// PlaySoundAsync(this, SE_EMY_SR_KILLER_SHOT);
// CreateActor(EN_SEARCH_KILLER, 0, tempPos, 0, 0);
// this->homingBillCountdown = (isAngry) ? 90: 180;
// }
if(this->shipAnm.isAnimationDone()) {
this->shipAnm.setCurrentFrame(0.0);
}
return true;
}
int daCaptainBowser::onDraw() {
if(this->isIntro > 2) { return false; }
matrix.translation(pos.x-146.0, pos.y+122.0, pos.z-200.0); // 136.0 is the bottom of the platform footing
short newrot = rot.y + 0xD800;
matrix.applyRotationYXZ(&rot.x, &newrot, &rot.z);
bodyModel.setDrawMatrix(matrix);
bodyModel.setScale(&(Vec){1.0, 1.0, 1.0});
bodyModel.calcWorld(false);
bodyModel.scheduleForDrawing();
matrix.translation(pos.x, pos.y, pos.z);
newrot = rot.y + 0x4000;
matrix.applyRotationYXZ(&rot.x, &newrot, &rot.z);
shipModel.setDrawMatrix(matrix);
shipModel.setScale(&scale);
shipModel.calcWorld(false);
shipModel.scheduleForDrawing();
return true;
}
//////////////////
// State Intro
//////////////////
void daCaptainBowser::beginState_Intro() {
this->timer = 0;
bindAnimChr_and_setUpdateRate("kp_wait", 1, 0.0, 1.5);
this->isInvulnerable = 1;
roarLen = 300;
}
void daCaptainBowser::executeState_Intro() {
if (this->chrAnimation.isAnimationDone()) {
// End the intro
if (this->isIntro == 1) {
OSReport("We're done: %d", this->timer);
doStateChange(&StateID_Wait);
return;
}
this->chrAnimation.setCurrentFrame(0.0); }
// Screen Rumble
if ((this->timer > 180) && (this->timer < 420)) {
// if (this->timer == 180) {
// Do Rumbly - 807CD3AC
pos.x = ClassWithCameraInfo::instance->screenCentreX;
pos.y = ClassWithCameraInfo::instance->screenCentreY;
ShakeScreen(StageScreen, 2, 1, 0, 0);
PlaySoundAsync(this, SE_BOSS_KOOPA_RUMBLE1); // 0x5D4
// Stage80::instance->ShakeScreen(self, 5, 1, 0);
}
// Bowser Flies In
if (this->timer == 422) { this->isIntro = 2; }
if ((this->timer > 420) && (this->timer < (420 + roarLen))) {
pos.x = ClassWithCameraInfo::instance->screenCentreX + ((this->timer - 420.0) * 1.5) - ((roarLen * 1.5) - 200.0);
pos.y = ClassWithCameraInfo::instance->screenCentreY - 380.0 + ((this->timer - 420.0) * 1.5) - ((roarLen * 1.5) - 200.0);
}
// Bowser does a shitty roar
if (this->timer == (roarLen - 190 + 420)) {
this->isIntro = 1;
bindAnimChr_and_setUpdateRate("kp_roar3", 1, 0.0, 1.0);
}
if (this->timer > (roarLen - 190 + 420)) {
if (this->chrAnimation.getCurrentFrame() == 53.0) {
PlaySound(this, SE_VOC_KP_L_SHOUT);
}
if (this->chrAnimation.getCurrentFrame() > 53.0) {
ShakeScreen(StageScreen, 2, 2, 0, 0);
effect.spawn("Wm_ko_shout", 0, &(Vec){pos.x-182.0, pos.y+132.0, pos.z}, &(S16Vec){0,0,0x7000}, &(Vec){1.0, 1.0, 1.0});
}
}
this->timer++;
}
void daCaptainBowser::endState_Intro() {
for (int i = 0; i < SHIP_COLL_COUNT; i++)
shipCollisions[i].addToList();
this->aPhysics.addToList();
this->isInvulnerable = 0;
this->isIntro = 0;
}
//////////////////
// State Wait
//////////////////
void daCaptainBowser::beginState_Wait() {
if (this->isAngry == 0) {
bindAnimChr_and_setUpdateRate("kp_wait", 1, 0.0, 1.5);
}
else {
bindAnimChr_and_setUpdateRate("kp_wait", 1, 0.0, 2.0);
}
}
void daCaptainBowser::executeState_Wait() {
if (this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
int num = GenerateRandomNumber(4);
if (num == 0) {
doStateChange(&StateID_Fire);
}
else{
doStateChange(&StateID_Throw);
}
}
}
void daCaptainBowser::endState_Wait() { }
//////////////////
// State Throw
//////////////////
void daCaptainBowser::beginState_Throw() {
bindAnimChr_and_setUpdateRate("break", 1, 0.0, 1.0);
this->timer = 0;
}
void daCaptainBowser::executeState_Throw() {
if (this->chrAnimation.getCurrentFrame() == 60.0) { // throw back
int num = GenerateRandomNumber(4);
CreateActor(0x29F, 0x101 + ((num + 1) * 0x10), (Vec){pos.x-146.0, pos.y+122.0, pos.z}, 0, 0);
}
if (this->chrAnimation.getCurrentFrame() == 126.0) { // throw front
int num = GenerateRandomNumber(4);
CreateActor(0x29F, ((num + 1) * 0x10) + 1, (Vec){pos.x-146.0, pos.y+122.0, pos.z}, 0, 0);
}
if (this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
if (this->isAngry == 1) {
if (this->timer == 1) {
doStateChange(&StateID_Wait);
}
}
else {
doStateChange(&StateID_Wait);
}
this->timer++;
}
}
void daCaptainBowser::endState_Throw() { }
//////////////////
// State Fire
//////////////////
void daCaptainBowser::beginState_Fire() {
bindAnimChr_and_setUpdateRate("fire1", 1, 0.0, 1.5);
this->timer = 0;
}
void daCaptainBowser::executeState_Fire() {
if (this->chrAnimation.getCurrentFrame() == 70.5) { // spit fire
PlaySound(this, SE_BOSS_KOOPA_L_FIRE_SHOT);
CreateActor(WM_ANTLION, 0, (Vec){pos.x-172.0, pos.y+152.0, pos.z}, 0, 0);
}
if (this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
if (this->isAngry == 1) {
if (this->timer == 1) {
doStateChange(&StateID_Wait);
}
}
else {
doStateChange(&StateID_Wait);
}
this->timer++;
}
}
void daCaptainBowser::endState_Fire() { }
//////////////////
// State Roar
//////////////////
void daCaptainBowser::beginState_Roar() {
bindAnimChr_and_setUpdateRate("kp_roar3", 1, 0.0, 1.0);
this->isInvulnerable = 1;
this->timer = 0;
this->scaleIncreaser = 0.5;
// this->Roar.info.xDistToEdge = 70.0 * scaleIncreaser;
// this->Roar.info.yDistToEdge = 70.0 * scaleIncreaser;
// this->Roar.addToList();
}
void daCaptainBowser::executeState_Roar() {
if (this->chrAnimation.getCurrentFrame() == 53.0) { // This is where the smackdown starts
PlaySound(this, SE_VOC_KP_L_SHOUT);
}
if (this->chrAnimation.getCurrentFrame() > 53.0) { // This is where the smackdown starts
scaleIncreaser += 0.014285;
effect.spawn("Wm_ko_shout", 0, &(Vec){pos.x-186.0+(scaleIncreaser*16.0), pos.y+138.0+(scaleIncreaser*16.0), pos.z}, &(S16Vec){0,0,0x7000}, &(Vec){scaleIncreaser, scaleIncreaser, scaleIncreaser});
// this->Roar.info.xDistToEdge = 70.0 * scaleIncreaser;
// this->Roar.info.yDistToEdge = 70.0 * scaleIncreaser;
}
// if (this->chrAnimation.getCurrentFrame() == 197.0) { // This is where the smackdown ends
// this->Roar.removeFromList();
// }
if (this->chrAnimation.isAnimationDone()) {
doStateChange(&StateID_Wait);
}
}
void daCaptainBowser::endState_Roar() {
this->isInvulnerable = 0;
this->isAngry = 1;
}
//////////////////
// State Damage
//////////////////
void daCaptainBowser::beginState_Damage() {
bindAnimChr_and_setUpdateRate("grow_big", 1, 0.0, 1.0);
this->isInvulnerable = 1;
this->chrAnimation.setCurrentFrame(9.0);
PlaySound(this, SE_VOC_KP_DAMAGE_HPDP);
}
void daCaptainBowser::executeState_Damage() {
if (this->chrAnimation.getCurrentFrame() == 65.0) { // stop it here before it's too late
doStateChange(&StateID_Wait);
}
}
void daCaptainBowser::endState_Damage() { this->isInvulnerable = 0; }
//////////////////
// State Outro
//////////////////
void daCaptainBowser::beginState_Outro() {
}
void daCaptainBowser::executeState_Outro() {
}
void daCaptainBowser::endState_Outro() { }
|