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
|
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
class daTopman : public dEn_c {
int onCreate();
int onDelete();
int onExecute();
int onDraw();
mHeapAllocator_c allocator;
nw4r::g3d::ResFile resFile;
m3d::mdl_c bodyModel;
m3d::anmChr_c chrAnimation;
int timer;
char damage;
char isDown;
float XSpeed;
u32 cmgr_returnValue;
bool isBouncing;
char isInSpace;
char fromBehind;
char isWaiting;
static daTopman *build();
void bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate);
void updateModelMatrices();
bool calculateTileCollisions();
// void spriteCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat7_WMWaggleWater(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat7_WMWaggleWaterYoshi(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther);
// bool collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther);
void collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther);
void _vf148();
void _vf14C();
bool CreateIceActors();
void addScoreWhenHit(void *other);
USING_STATES(daTopman);
DECLARE_STATE(Walk);
DECLARE_STATE(Turn);
DECLARE_STATE(Wait);
DECLARE_STATE(KnockBack);
DECLARE_STATE(Die);
};
daTopman *daTopman::build() {
void *buffer = AllocFromGameHeap1(sizeof(daTopman));
return new(buffer) daTopman;
}
///////////////////////
// Externs and States
///////////////////////
extern "C" void *PlaySound(dStageActor_c *, int soundID);
extern "C" void *PlaySoundAsync(dStageActor_c *, int soundID);
extern "C" void *EN_LandbarrelPlayerCollision(dEn_c* t, ActivePhysics *apThis, ActivePhysics *apOther);
extern "C" dStageActor_c *CreateActor(u16 classID, int settings, Vec pos, char rot, char layer);
extern "C" u8 dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(daTopman *, Vec pos);
//FIXME make this dEn_c->used...
extern "C" char usedForDeterminingStatePress_or_playerCollision(dEn_c* t, ActivePhysics *apThis, ActivePhysics *apOther, int unk1);
extern "C" int SmoothRotation(short* rot, u16 amt, int unk2);
CREATE_STATE(daTopman, Walk);
CREATE_STATE(daTopman, Turn);
CREATE_STATE(daTopman, Wait);
CREATE_STATE(daTopman, KnockBack);
CREATE_STATE(daTopman, Die);
// begoman_attack2" // wobble back and forth tilted forwards
// begoman_attack3" // Leaned forward, antennae extended
// begoman_damage" // Bounces back slightly
// begoman_damage2" // Stops spinning and wobbles to the ground like a top
// begoman_stand" // Stands still, waiting
// begoman_wait" // Dizzily Wobbles
// begoman_wait2" // spins around just slightly
// begoman_attack" // Rocks backwards, and then attacks to an upright position, pulsing out his antennae
////////////////////////
// Collision Functions
////////////////////////
// Collision callback to help shy guy not die at inappropriate times and ruin the dinner
void daTopman::playerCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
char hitType;
hitType = usedForDeterminingStatePress_or_playerCollision(this, apThis, apOther, 0);
if(hitType == 1) { // regular jump
this->_vf220(apOther->owner);
}
else if(hitType == 3) { // spinning jump or whatever?
this->_vf220(apOther->owner);
}
else if(hitType == 0) {
EN_LandbarrelPlayerCollision(this, apThis, apOther);
if (this->pos.x > apOther->owner->pos.x) {
this->direction = 1;
}
else {
this->direction = 0;
}
doStateChange(&StateID_KnockBack);
}
// fix multiple player collisions via megazig
this->isDead = 0;
this->flags_4FC |= (1<<(31-7));
this->counter_504[apOther->owner->which_player] = 0;
}
void daTopman::yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
this->playerCollision(apThis, apOther);
}
void daTopman::collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) {
this->dEn_c::playerCollision(apThis, apOther);
this->_vf220(apOther->owner);
this->isDead = 0;
this->flags_4FC |= (1<<(31-7));
this->counter_504[apOther->owner->which_player] = 0;
}
void daTopman::collisionCat7_WMWaggleWater(ActivePhysics *apThis, ActivePhysics *apOther) {
this->collisionCatD_GroundPound(apThis, apOther);
}
void daTopman::collisionCat7_WMWaggleWaterYoshi(ActivePhysics *apThis, ActivePhysics *apOther) {
this->collisionCatD_GroundPound(apThis, apOther);
}
void daTopman::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) {
doStateChange(&StateID_KnockBack);
}
void daTopman::collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther){
doStateChange(&StateID_Die);
}
void daTopman::collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther) {
doStateChange(&StateID_Die);
}
void daTopman::collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther){
doStateChange(&StateID_KnockBack);
}
void daTopman::collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther){
doStateChange(&StateID_KnockBack);
}
void daTopman::collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther) {
doStateChange(&StateID_KnockBack);
}
// void daTopman::collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther) {
// doStateChange(&StateID_DieFall);
// }
// These handle the ice crap
void daTopman::_vf148() {
dEn_c::_vf148();
doStateChange(&StateID_Die);
}
void daTopman::_vf14C() {
dEn_c::_vf14C();
doStateChange(&StateID_Die);
}
struct DoSomethingCool {
u32 unk_01; //0000
Vec3 pos; //0004
Vec3 scale; //0010
f32 unk_02; //001C
f32 unk_03; //0020
f32 unk_04; //0024
f32 unk_05; //0028
f32 unk_06; //002C
f32 unk_07; //0030
f32 unk_08; //0034
f32 unk_09; //0038
} my_struct;
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 daTopman::CreateIceActors()
{
struct DoSomethingCool my_struct = { 0, this->pos, {2.5, 2.5, 2.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 daTopman::addScoreWhenHit(void *other) {}
bool daTopman::calculateTileCollisions() {
// Returns true if sprite should turn, false if not.
HandleXSpeed();
HandleYSpeed();
doSpriteMovement();
cmgr_returnValue = collMgr.CollidedWithTile();
collMgr.execute();
if (isBouncing) {
stuffRelatingToCollisions(0.1875f, 1.0f, 0.5f);
if (speed.y != 0.0f)
isBouncing = false;
}
float xDelta = pos.x - last_pos.x;
if (xDelta >= 0.0f)
direction = 0;
else
direction = 1;
if (collMgr.CollidedWithTile()) {
// Walking into a tile branch
if (cmgr_returnValue == 0)
isBouncing = true;
if (speed.x != 0.0f) {
//playWmEnIronEffect();
}
speed.y = 0.0f;
// u32 blah = collMgr.s_80070760();
// u8 one = (blah & 0xFF);
// static const float incs[5] = {0.00390625f, 0.0078125f, 0.015625f, 0.0234375f, 0.03125f};
// x_speed_inc = incs[one];
max_speed.x = (direction == 1) ? -1.0f : 1.0f;
} else {
x_speed_inc = 0.0f;
}
// Bouncing checks
if (_34A & 4) {
Vec v = (Vec){0.0f, 1.0f, 0.0f};
collMgr.parent_speed_ptr = &v;
if (collMgr.SomethingSemiImportant(collMgr.bitfield_for_checks))
speed.y = 0.0f;
collMgr.parent_speed_ptr = &speed;
} else {
if (collMgr.SomethingSemiImportant(collMgr.bitfield_for_checks))
speed.y = 0.0f;
}
collMgr.s_8006FA40(0);
// Switch Direction
if (collMgr.bitfield_for_checks & (0x15 << direction)) {
if (collMgr.CollidedWithTile()) {
isBouncing = true;
}
return true;
}
return false;
}
void daTopman::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 daTopman::onCreate() {
// Model creation
allocator.link(-1, GameHeaps[0], 0, 0x20);
this->resFile.data = getResource("ben", "g3d/begoman_spike.brres");
nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("begoman");
bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
SetupTextures_Map(&bodyModel, 0);
// Animations start here
nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr("begoman_wait");
this->chrAnimation.setup(mdl, anmChr, &this->allocator, 0);
allocator.unlink();
// Stuff I do understand
this->scale = (Vec){0.2, 0.2, 0.2};
// this->pos.y = this->pos.y + 30.0; // X is vertical axis
this->rot.x = 0; // X is vertical axis
this->rot.y = 0xD800; // Y is horizontal axis
this->rot.z = 0; // Z is ... an axis >.>
this->direction = 1; // Heading left.
this->speed.x = 0.0;
this->speed.y = 0.0;
this->max_speed.x = 0.8;
this->x_speed_inc = 0.0;
this->XSpeed = 0.8;
this->isInSpace = this->settings & 0xF;
this->isWaiting = (this->settings >> 4) & 0xF;
this->fromBehind = 0;
ActivePhysics::Info HitMeBaby;
HitMeBaby.xDistToCenter = 0.0;
HitMeBaby.yDistToCenter = 12.0;
HitMeBaby.xDistToEdge = 14.0;
HitMeBaby.yDistToEdge = 12.0;
HitMeBaby.category1 = 0x3;
HitMeBaby.category2 = 0x0;
HitMeBaby.bitfield1 = 0x4F;
HitMeBaby.bitfield2 = 0xffbafffe;
HitMeBaby.unkShort1C = 0;
HitMeBaby.callback = &dEn_c::collisionCallback;
this->aPhysics.initWithStruct(this, &HitMeBaby);
this->aPhysics.addToList();
// Tile collider
// These fucking rects do something for the tile rect
spriteSomeRectX = 28.0f;
spriteSomeRectY = 32.0f;
_320 = 0.0f;
_324 = 16.0f;
// These structs tell stupid collider what to collide with - these are from koopa troopa
static const u8 one[16] = {0,0,0,1, 0,0,0xC0,0, 0,0,0x40,0, 0,0,0,0};
static const u8 two[12] = {0,0,0,0, 0,0,0,0, 0,0,0xC0,0};
static const u8 three[16] = {0,0,0,1, 0,0,0x60,0, 0,0,0x90,0, 0,0,0x60,0};
collMgr.Init(this, one, two, three);
collMgr.execute();
cmgr_returnValue = collMgr.CollidedWithTile();
if (collMgr.CollidedWithTile())
isBouncing = false;
else
isBouncing = true;
// State Changers
bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 1.0);
if (this->isWaiting == 0) {
doStateChange(&StateID_Walk); }
else {
doStateChange(&StateID_Wait); }
this->onExecute();
return true;
}
int daTopman::onDelete() {
return true;
}
int daTopman::onExecute() {
acState.execute();
updateModelMatrices();
return true;
}
int daTopman::onDraw() {
bodyModel.scheduleForDrawing();
return true;
}
void daTopman::updateModelMatrices() {
matrix.translation(pos.x, pos.y - 2.0, pos.z);
matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
bodyModel.setDrawMatrix(matrix);
bodyModel.setScale(&scale);
bodyModel.calcWorld(false);
}
///////////////
// Walk State
///////////////
void daTopman::beginState_Walk() {
this->max_speed.x = (this->direction) ? -this->XSpeed : this->XSpeed;
this->speed.x = (direction) ? -0.8f : 0.8f;
this->max_speed.y = (this->isInSpace) ? -2.0 : -4.0;
this->speed.y = (this->isInSpace) ? -2.0 : -4.0;
this->y_speed_inc = (this->isInSpace) ? -0.09375 : -0.1875;
}
void daTopman::executeState_Walk() {
PlaySound(this, SE_BOSS_JR_CROWN_JR_RIDE); // 5
bool ret = calculateTileCollisions();
if (ret) {
doStateChange(&StateID_Turn);
}
bodyModel._vf1C();
if(this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
}
}
void daTopman::endState_Walk() { this->timer += 1; }
///////////////
// Turn State
///////////////
void daTopman::beginState_Turn() {
this->direction ^= 1;
this->speed.x = 0.0;
}
void daTopman::executeState_Turn() {
bodyModel._vf1C();
if(this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
}
u16 amt = (this->direction == 0) ? 0x2800 : 0xD800;
int done = SmoothRotation(&this->rot.y, amt, 0x800);
if(done) {
this->doStateChange(&StateID_Walk);
}
}
void daTopman::endState_Turn() { }
///////////////
// Wait State
///////////////
void daTopman::beginState_Wait() {
this->max_speed.x = 0;
this->speed.x = 0;
this->max_speed.y = (this->isInSpace) ? -2.0 : -4.0;
this->speed.y = (this->isInSpace) ? -2.0 : -4.0;
this->y_speed_inc = (this->isInSpace) ? -0.09375 : -0.1875;
}
void daTopman::executeState_Wait() {
PlaySound(this, SE_BOSS_JR_CROWN_JR_RIDE); // 5
bool ret = calculateTileCollisions();
if (ret) {
doStateChange(&StateID_Turn);
}
bodyModel._vf1C();
if(this->chrAnimation.isAnimationDone()) {
this->chrAnimation.setCurrentFrame(0.0);
}
}
void daTopman::endState_Wait() { }
///////////////
// Die State
///////////////
void daTopman::beginState_Die() {
dEn_c::dieFall_Begin();
bindAnimChr_and_setUpdateRate("begoman_damage2", 1, 0.0, 1.0);
this->timer = 0;
}
void daTopman::executeState_Die() {
bodyModel._vf1C();
PlaySound(this, SE_EMY_MECHAKOOPA_DAMAGE);
if(this->chrAnimation.isAnimationDone()) {
this->kill();
this->Delete(1);
}
}
void daTopman::endState_Die() { }
///////////////
// Knockback State
///////////////
void daTopman::beginState_KnockBack() {
bindAnimChr_and_setUpdateRate("begoman_damage", 1, 0.0, 0.75);
this->max_speed.x = (this->direction) ? this->XSpeed*5.0 : -this->XSpeed*5.0;
this->speed.x = (this->direction) ? 4.0f : -4.0f;
}
void daTopman::executeState_KnockBack() {
bool ret = calculateTileCollisions();
this->speed.x = this->speed.x / 1.1;
bodyModel._vf1C();
if(this->chrAnimation.isAnimationDone()) {
if (this->isWaiting == 0) {
doStateChange(&StateID_Walk); }
else {
doStateChange(&StateID_Wait); }
}
}
void daTopman::endState_KnockBack() {
if (this->rot.y == 0x2800) {
this->direction = 0;
}
else {
this->direction = 1;
}
// this->direction ^= 1;
bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 1.0);
}
|