/
bully.inc.c
372 lines (308 loc) · 11 KB
/
bully.inc.c
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
// bully.inc.c
static struct ObjectHitbox sSmallBullyHitbox = {
/* interactType: */ INTERACT_BULLY,
/* downOffset: */ 0,
/* damageOrCoinValue: */ 1,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 73,
/* height: */ 123,
/* hurtboxRadius: */ 63,
/* hurtboxHeight: */ 113,
};
static struct ObjectHitbox sBigBullyHitbox = {
/* interactType: */ INTERACT_BULLY,
/* downOffset: */ 0,
/* damageOrCoinValue: */ 1,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 115,
/* height: */ 235,
/* hurtboxRadius: */ 105,
/* hurtboxHeight: */ 225,
};
void bhv_small_bully_init(void) {
cur_obj_init_animation(0);
o->oHomeX = o->oPosX;
o->oHomeZ = o->oPosZ;
o->oBhvParams2ndByte = BULLY_BP_SIZE_SMALL;
o->oGravity = 4.0;
o->oFriction = 0.91;
o->oBuoyancy = 1.3;
obj_set_hitbox(o, &sSmallBullyHitbox);
}
void bhv_big_bully_init(void) {
cur_obj_init_animation(0);
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
o->oBhvParams2ndByte = BULLY_BP_SIZE_BIG;
o->oGravity = 5.0;
o->oFriction = 0.93;
o->oBuoyancy = 1.3;
obj_set_hitbox(o, &sBigBullyHitbox);
}
void bully_check_mario_collision(void) {
if (
#if defined(VERSION_SH) || defined(VERSION_CN)
o->oAction != BULLY_ACT_LAVA_DEATH && o->oAction != BULLY_ACT_DEATH_PLANE_DEATH &&
#endif
o->oInteractStatus & INT_STATUS_INTERACTED) {
if (o->oBhvParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ2_BULLY_ATTACKED);
} else {
cur_obj_play_sound_2(SOUND_OBJ2_LARGE_BULLY_ATTACKED);
}
o->oInteractStatus &= ~INT_STATUS_INTERACTED;
o->oAction = BULLY_ACT_KNOCKBACK;
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
cur_obj_init_animation(3);
o->oBullyMarioCollisionAngle = o->oMoveAngleYaw;
}
}
void bully_act_chase_mario(void) {
f32 homeX = o->oHomeX;
f32 posY = o->oPosY;
f32 homeZ = o->oHomeZ;
if (o->oTimer < 10) {
o->oForwardVel = 3.0;
obj_turn_toward_object(o, gMarioObject, 16, 0x1000);
} else if (o->oBhvParams2ndByte == BULLY_BP_SIZE_SMALL) {
o->oForwardVel = 20.0;
if (o->oTimer > 30) {
o->oTimer = 0;
}
} else {
o->oForwardVel = 30.0;
if (o->oTimer > 35) {
o->oTimer = 0;
}
}
if (!is_point_within_radius_of_mario(homeX, posY, homeZ, 1000)) {
o->oAction = BULLY_ACT_PATROL;
cur_obj_init_animation(0);
}
}
void bully_act_knockback(void) {
if (o->oForwardVel < 10.0 && (s32) o->oVelY == 0) {
o->oForwardVel = 1.0;
o->oBullyKBTimerAndMinionKOCounter++;
o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oMoveAngleYaw = o->oFaceAngleYaw;
obj_turn_toward_object(o, gMarioObject, 16, 0x500);
} else {
o->header.gfx.animInfo.animFrame = 0;
}
if (o->oBullyKBTimerAndMinionKOCounter == 18) {
o->oAction = BULLY_ACT_CHASE_MARIO;
o->oBullyKBTimerAndMinionKOCounter = 0;
cur_obj_init_animation(1);
}
}
void bully_act_back_up(void) {
if (o->oTimer == 0) {
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oMoveAngleYaw += 0x8000;
}
o->oForwardVel = 5.0;
//! bully_backup_check() happens after this function, and has the potential to reset
// the bully's action to BULLY_ACT_BACK_UP. Because the back up action is only
// set to end when the timer EQUALS 15, if this happens on that frame, the bully
// will be stuck in BULLY_ACT_BACK_UP forever until Mario hits it or its death
// conditions are activated. However because its angle is set to its facing angle,
// it will walk forward instead of backing up.
if (o->oTimer == 15) {
o->oMoveAngleYaw = o->oFaceAngleYaw;
o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oAction = BULLY_ACT_PATROL;
}
}
void bully_backup_check(s16 collisionFlags) {
if (!(collisionFlags & OBJ_COL_FLAG_NO_Y_VEL) && o->oAction != BULLY_ACT_KNOCKBACK) {
o->oPosX = o->oBullyPrevX;
o->oPosZ = o->oBullyPrevZ;
o->oAction = BULLY_ACT_BACK_UP;
}
}
void bully_play_stomping_sound(void) {
s16 animFrame = o->header.gfx.animInfo.animFrame;
switch (o->oAction) {
case BULLY_ACT_PATROL:
if (animFrame == 0 || animFrame == 12) {
if (o->oBhvParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK);
} else {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING);
}
}
break;
case BULLY_ACT_CHASE_MARIO:
case BULLY_ACT_BACK_UP:
if (animFrame == 0 || animFrame == 5) {
if (o->oBhvParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK);
} else {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING);
}
}
break;
}
}
void bully_step(void) {
s16 collisionFlags = 0;
collisionFlags = object_step();
bully_backup_check(collisionFlags);
bully_play_stomping_sound();
obj_check_floor_death(collisionFlags, sObjFloor);
if (o->oBullySubtype & BULLY_STYPE_CHILL) {
if (o->oPosY < 1030.0f) {
o->oAction = BULLY_ACT_LAVA_DEATH;
}
}
}
void bully_spawn_coin(void) {
struct Object *coin = spawn_object(o, MODEL_YELLOW_COIN, bhvMovingYellowCoin);
cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT);
coin->oForwardVel = 10.0f;
coin->oVelY = 100.0f;
coin->oPosY = o->oPosY + 310.0f;
coin->oMoveAngleYaw = (f32)(o->oBullyMarioCollisionAngle + 0x8000) + random_float() * 1024.0f;
}
void bully_act_level_death(void) {
if (obj_lava_death() == TRUE) {
if (o->oBhvParams2ndByte == BULLY_BP_SIZE_SMALL) {
if (o->oBullySubtype == BULLY_STYPE_MINION) {
o->parentObj->oBullyKBTimerAndMinionKOCounter++;
}
bully_spawn_coin();
} else {
spawn_mist_particles();
if (o->oBullySubtype == BULLY_STYPE_CHILL) {
spawn_default_star(130.0f, 1600.0f, -4335.0f);
} else {
spawn_default_star(0, 950.0f, -6800.0f);
spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvLLLTumblingBridge,
0, 154, -5631, 0, 0, 0);
}
}
}
}
void bhv_bully_loop(void) {
o->oBullyPrevX = o->oPosX;
o->oBullyPrevY = o->oPosY;
o->oBullyPrevZ = o->oPosZ;
//! Because this function runs no matter what, Mario is able to interrupt the bully's
// death action by colliding with it. Since the bully hitbox is tall enough to collide
// with Mario even when it is under a lava floor, this can get the bully stuck OOB
// if there is nothing under the lava floor.
bully_check_mario_collision();
switch (o->oAction) {
case BULLY_ACT_PATROL:
o->oForwardVel = 5.0;
if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 800) == TRUE) {
o->oAction = BULLY_ACT_CHASE_MARIO;
cur_obj_init_animation(1);
}
bully_step();
break;
case BULLY_ACT_CHASE_MARIO:
bully_act_chase_mario();
bully_step();
break;
case BULLY_ACT_KNOCKBACK:
bully_act_knockback();
bully_step();
break;
case BULLY_ACT_BACK_UP:
bully_act_back_up();
bully_step();
break;
case BULLY_ACT_LAVA_DEATH:
bully_act_level_death();
break;
case BULLY_ACT_DEATH_PLANE_DEATH:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
break;
}
set_object_visibility(o, 3000);
}
void big_bully_spawn_minion(s32 x, s32 y, s32 z, s16 yaw) {
struct Object *bully =
spawn_object_abs_with_rot(o, 0, MODEL_BULLY, bhvSmallBully, x, y, z, 0, yaw, 0);
bully->oBullySubtype = BULLY_STYPE_MINION;
bully->oBhvParams2ndByte = BULLY_BP_SIZE_SMALL;
}
void bhv_big_bully_with_minions_init(void) {
big_bully_spawn_minion(4454, 307, -5426, 0);
big_bully_spawn_minion(3840, 307, -6041, 0);
big_bully_spawn_minion(3226, 307, -5426, 0);
o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
cur_obj_become_intangible();
o->oAction = BULLY_ACT_INACTIVE;
}
void big_bully_spawn_star(void) {
if (obj_lava_death() == TRUE) {
spawn_mist_particles();
spawn_default_star(3700.0f, 600.0f, -5500.0f);
}
}
void bhv_big_bully_with_minions_loop(void) {
s16 collisionFlags;
o->oBullyPrevX = o->oPosX;
o->oBullyPrevY = o->oPosY;
o->oBullyPrevZ = o->oPosZ;
bully_check_mario_collision();
switch (o->oAction) {
case BULLY_ACT_PATROL:
o->oForwardVel = 5.0;
if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 1000) == TRUE) {
o->oAction = BULLY_ACT_CHASE_MARIO;
cur_obj_init_animation(1);
}
bully_step();
break;
case BULLY_ACT_CHASE_MARIO:
bully_act_chase_mario();
bully_step();
break;
case BULLY_ACT_KNOCKBACK:
bully_act_knockback();
bully_step();
break;
case BULLY_ACT_BACK_UP:
bully_act_back_up();
bully_step();
break;
case BULLY_ACT_INACTIVE:
//! The Big Bully that spawns from killing its 3 minions uses the knockback timer
// for counting the number of dead minions. This means that when it activates,
// the knockback timer is at 3 instead of 0. So the bully knockback time will
// be reduced by 3 frames (16.67%) on the first hit.
if (o->oBullyKBTimerAndMinionKOCounter == 3) {
play_puzzle_jingle();
if (o->oTimer > 90) {
o->oAction = BULLY_ACT_ACTIVATE_AND_FALL;
}
}
break;
case BULLY_ACT_ACTIVATE_AND_FALL:
collisionFlags = object_step();
if ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) {
o->oAction = BULLY_ACT_PATROL;
}
if (collisionFlags == OBJ_COL_FLAG_GROUNDED) {
cur_obj_play_sound_2(SOUND_OBJ_THWOMP);
set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ);
spawn_mist_particles();
}
o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
cur_obj_become_tangible();
break;
case BULLY_ACT_LAVA_DEATH:
big_bully_spawn_star();
break;
case BULLY_ACT_DEATH_PLANE_DEATH:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
break;
}
}