eyerok.inc.c (19060B)
1 // eyerok.inc.c 2 3 struct ObjectHitbox sEyerokHitbox = { 4 /* interactType: */ INTERACT_BOUNCE_TOP, 5 /* downOffset: */ 0, 6 /* damageOrCoinValue: */ 0, 7 /* health: */ 4, 8 /* numLootCoins: */ 0, 9 /* radius: */ 150, 10 /* height: */ 100, 11 /* hurtboxRadius: */ 1, 12 /* hurtboxHeight: */ 1, 13 }; 14 15 s8 D_80331BA4[] = { 0, 1, 3, 2, 1, 0 }; 16 17 static s32 eyerok_check_mario_relative_z(s32 arg0) { 18 if (gMarioObject->oPosZ - o->oHomeZ < arg0) { 19 return TRUE; 20 } else { 21 return FALSE; 22 } 23 } 24 25 static void eyerok_spawn_hand(s16 side, s32 model, const BehaviorScript *behavior) { 26 struct Object *hand = spawn_object_relative_with_scale(side, -500 * side, 0, 300, 1.5f, 27 o, model, behavior); 28 if (hand != NULL) { 29 hand->oFaceAngleYaw -= 0x4000 * side; 30 } 31 } 32 33 static void eyerok_boss_act_sleep(void) { 34 if (o->oTimer == 0) { 35 eyerok_spawn_hand(-1, MODEL_EYEROK_LEFT_HAND, bhvEyerokHand); 36 eyerok_spawn_hand(1, MODEL_EYEROK_RIGHT_HAND, bhvEyerokHand); 37 } else if (o->oDistanceToMario < 500.0f) { 38 cur_obj_play_sound_2(SOUND_OBJ_EYEROK_EXPLODE); 39 o->oAction = EYEROK_BOSS_ACT_WAKE_UP; 40 } 41 } 42 43 static void eyerok_boss_act_wake_up(void) { 44 if (o->oEyerokBossNumHands == 2) { 45 if (o->oTimer > 5) { 46 if (o->oSubAction == 0) { 47 seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); 48 o->oSubAction++; 49 } 50 51 if (o->oEyerokBossUnk110 == 0.0f && mario_ready_to_speak()) { 52 o->oAction = EYEROK_BOSS_ACT_SHOW_INTRO_TEXT; 53 } else if (o->oTimer > 150) { 54 if (approach_f32_ptr(&o->oEyerokBossUnk110, 0.0f, 10.0f)) { 55 o->oTimer = 0; 56 } 57 } else if (o->oTimer > 90) { 58 approach_f32_ptr(&o->oEyerokBossUnk110, 300.0f, 10.0f); 59 } 60 } 61 } else { 62 o->oTimer = 0; 63 } 64 } 65 66 static void eyerok_boss_act_show_intro_text(void) { 67 if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_NONE, CUTSCENE_DIALOG, DIALOG_117)) { 68 o->oAction = EYEROK_BOSS_ACT_FIGHT; 69 } 70 } 71 72 static void eyerok_boss_act_fight(void) { 73 if (o->oEyerokBossNumHands == 0) { 74 o->oAction = EYEROK_BOSS_ACT_DIE; 75 } else if (o->oEyerokBossUnk1AC == 0 && o->oEyerokBossActiveHand == 0) { 76 if (o->oEyerokBossUnk104 != 0) { 77 if (approach_f32_ptr(&o->oEyerokBossUnk110, 1.0f, 0.02f)) { 78 if (o->oEyerokBossUnk104 < 0) { 79 if (!eyerok_check_mario_relative_z(400) && ++o->oEyerokBossUnk104 == 0) { 80 o->oEyerokBossUnk104 = 1; 81 } 82 } else { 83 o->oEyerokBossUnk104--; 84 } 85 86 if (o->oEyerokBossUnk104 != 0 && o->oEyerokBossUnk104 != 1) { 87 o->oEyerokBossUnkFC++; 88 if ((o->oEyerokBossActiveHand = o->oEyerokBossUnkFC & 0x1) == 0) { 89 o->oEyerokBossActiveHand = -1; 90 } 91 } 92 } 93 } else { 94 o->oEyerokBossUnkFC++; 95 96 if (eyerok_check_mario_relative_z(400)) { 97 o->oEyerokBossUnk104 = -8; 98 o->oEyerokBossUnk110 = 1.0f; 99 o->oEyerokBossUnk108 = 0.0f; 100 } else if (o->oEyerokBossNumHands == 2 && o->oEyerokBossUnkFC % 6 == 0) { 101 o->oEyerokBossUnk104 = 8; 102 o->oEyerokBossUnk110 = 0.0f; 103 104 if ((o->oEyerokBossUnkFC = random_u16() & 0x1) != 0) { 105 o->oEyerokBossUnk108 = -1.0f; 106 } else { 107 o->oEyerokBossUnk108 = 1.0f; 108 } 109 110 o->oEyerokBossUnk10C = gMarioObject->oPosZ; 111 clamp_f32(&o->oEyerokBossUnk10C, o->oPosZ + 400.0f, o->oPosZ + 1600.0f); 112 } else if ((o->oEyerokBossActiveHand = o->oEyerokBossUnkFC & 0x1) == 0) { 113 o->oEyerokBossActiveHand = -1; 114 } 115 } 116 } 117 } 118 119 static void eyerok_boss_act_die(void) { 120 if (o->oTimer == 60) { 121 if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_NONE, CUTSCENE_DIALOG, DIALOG_118)) { 122 spawn_default_star(0.0f, -900.0f, -3700.0f); 123 } else { 124 o->oTimer--; 125 } 126 } else if (o->oTimer > 120) { 127 stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); 128 obj_mark_for_deletion(o); 129 } 130 } 131 132 void bhv_eyerok_boss_loop(void) { 133 switch (o->oAction) { 134 case EYEROK_BOSS_ACT_SLEEP: 135 eyerok_boss_act_sleep(); 136 break; 137 case EYEROK_BOSS_ACT_WAKE_UP: 138 eyerok_boss_act_wake_up(); 139 break; 140 case EYEROK_BOSS_ACT_SHOW_INTRO_TEXT: 141 eyerok_boss_act_show_intro_text(); 142 break; 143 case EYEROK_BOSS_ACT_FIGHT: 144 eyerok_boss_act_fight(); 145 break; 146 case EYEROK_BOSS_ACT_DIE: 147 eyerok_boss_act_die(); 148 break; 149 } 150 } 151 152 static s32 eyerok_hand_check_attacked(void) { 153 if (o->oEyerokReceivedAttack != 0 && abs_angle_diff(o->oAngleToMario, o->oFaceAngleYaw) < 0x3000) { 154 cur_obj_play_sound_2(SOUND_OBJ2_EYEROK_SOUND_SHORT); 155 156 if (--o->oHealth >= 2) { 157 o->oAction = EYEROK_HAND_ACT_ATTACKED; 158 o->oVelY = 30.0f; 159 } else { 160 o->parentObj->oEyerokBossNumHands--; 161 o->oAction = EYEROK_HAND_ACT_DIE; 162 o->oVelY = 50.0f; 163 } 164 165 o->oForwardVel *= 0.2f; 166 o->oMoveAngleYaw = o->oFaceAngleYaw + 0x8000; 167 o->oMoveFlags = 0; 168 o->oGravity = -4.0f; 169 o->oAnimState = 3; 170 171 return TRUE; 172 } else { 173 return FALSE; 174 } 175 } 176 177 static void eyerok_hand_pound_ground(void) { 178 cur_obj_play_sound_2(SOUND_OBJ_POUNDING_LOUD); 179 set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); 180 spawn_mist_from_global(); 181 } 182 183 static void eyerok_hand_act_sleep(void) { 184 if (o->parentObj->oAction != EYEROK_BOSS_ACT_SLEEP 185 && ++o->oEyerokHandWakeUpTimer > -3 * o->oBhvParams2ndByte) { 186 if (cur_obj_check_if_near_animation_end()) { 187 o->parentObj->oEyerokBossNumHands++; 188 o->oAction = EYEROK_HAND_ACT_IDLE; 189 o->collisionData = segmented_to_virtual(&ssl_seg7_collision_07028274); 190 } else { 191 approach_f32_ptr(&o->oPosX, o->oHomeX, 15.0f); 192 o->oPosY = o->oHomeY 193 + (200 * o->oBhvParams2ndByte + 400) 194 * sins((s16)(absf(o->oPosX - o->oHomeX) / 724.0f * 0x8000)); 195 obj_face_yaw_approach(o->oMoveAngleYaw, 400); 196 } 197 } else { 198 if (o->oBhvParams2ndByte < 0) { 199 o->collisionData = segmented_to_virtual(&ssl_seg7_collision_070284B0); 200 } else { 201 o->collisionData = segmented_to_virtual(&ssl_seg7_collision_07028370); 202 } 203 204 cur_obj_reverse_animation(); 205 o->oPosX = o->oHomeX + 724.0f * o->oBhvParams2ndByte; 206 } 207 } 208 209 static void eyerok_hand_act_idle(void) { 210 cur_obj_init_animation_with_sound(2); 211 212 if (o->parentObj->oAction == EYEROK_BOSS_ACT_FIGHT) { 213 if (o->parentObj->oEyerokBossUnk104 != 0) { 214 if (o->parentObj->oEyerokBossUnk104 != 1) { 215 o->oAction = EYEROK_HAND_ACT_BEGIN_DOUBLE_POUND; 216 o->oGravity = 0.0f; 217 } 218 } else if (o->parentObj->oEyerokBossUnk1AC == 0 && o->parentObj->oEyerokBossActiveHand != 0) { 219 if (o->parentObj->oEyerokBossActiveHand == o->oBhvParams2ndByte) { 220 if (eyerok_check_mario_relative_z(400) || random_u16() % 2 != 0) { 221 o->oAction = EYEROK_HAND_ACT_TARGET_MARIO; 222 o->oMoveAngleYaw = o->oAngleToMario; 223 o->oGravity = 0.0f; 224 } else { 225 o->oAction = EYEROK_HAND_ACT_FIST_PUSH; 226 if (o->parentObj->oPosX - gMarioObject->oPosX < 0.0f) { 227 o->oMoveAngleYaw = -0x800; 228 } else { 229 o->oMoveAngleYaw = 0x800; 230 } 231 232 o->oMoveAngleYaw += o->oAngleToMario; 233 o->oGravity = -4.0f; 234 } 235 } else { 236 o->oAction = EYEROK_HAND_ACT_OPEN; 237 } 238 } 239 } else { 240 o->oPosY = o->oHomeY + o->parentObj->oEyerokBossUnk110; 241 } 242 } 243 244 static void eyerok_hand_act_open(void) { 245 o->parentObj->oEyerokBossUnk1AC = o->oBhvParams2ndByte; 246 247 if (cur_obj_init_anim_and_check_if_end(4)) { 248 o->oAction = EYEROK_HAND_ACT_SHOW_EYE; 249 o->oEyerokHandUnkFC = 2; 250 o->oEyerokHandUnk100 = 60; 251 252 o->collisionData = segmented_to_virtual(ssl_seg7_collision_070282F8); 253 254 if (o->parentObj->oEyerokBossNumHands != 2) { 255 s16 sp1E = o->oAngleToMario; 256 clamp_s16(&sp1E, -0x3000, 0x3000); 257 o->oMoveAngleYaw = sp1E; 258 o->oForwardVel = 50.0f; 259 } else { 260 o->oMoveAngleYaw = 0; 261 } 262 } 263 } 264 265 static void eyerok_hand_act_show_eye(void) { 266 cur_obj_init_animation_with_sound(5); 267 cur_obj_play_sound_at_anim_range(0, 0, SOUND_OBJ_EYEROK_SHOW_EYE); 268 269 if (!eyerok_hand_check_attacked()) { 270 if (o->parentObj->oEyerokBossActiveHand == 0) { 271 if (o->oAnimState < 3) { 272 o->oAnimState++; 273 } else if (cur_obj_check_if_near_animation_end()) { 274 UNUSED s16 val06 = (s16)(o->oAngleToMario - o->oFaceAngleYaw) * o->oBhvParams2ndByte; 275 o->oAction = EYEROK_HAND_ACT_CLOSE; 276 } 277 } else { 278 if (o->oEyerokHandUnk100--) { 279 if (o->oEyerokHandUnkFC != 0) { 280 o->oEyerokHandUnkFC--; 281 } 282 o->oAnimState = D_80331BA4[o->oEyerokHandUnkFC]; 283 } else { 284 o->oEyerokHandUnkFC = 5; 285 o->oEyerokHandUnk100 = random_linear_offset(20, 50); 286 } 287 288 if (o->parentObj->oEyerokBossNumHands != 2) { 289 obj_face_yaw_approach(o->oMoveAngleYaw, 0x800); 290 if (o->oTimer > 10 291 && (o->oPosZ - gMarioObject->oPosZ > 0.0f || (o->oMoveFlags & OBJ_MOVE_HIT_EDGE))) { 292 o->parentObj->oEyerokBossActiveHand = 0; 293 o->oForwardVel = 0.0f; 294 } 295 } 296 } 297 } 298 } 299 300 static void eyerok_hand_act_close(void) { 301 if (cur_obj_init_anim_check_frame(7, 1)) { 302 o->collisionData = segmented_to_virtual(ssl_seg7_collision_07028274); 303 304 if (o->parentObj->oEyerokBossNumHands != 2) { 305 o->oAction = EYEROK_HAND_ACT_RETREAT; 306 o->parentObj->oEyerokBossActiveHand = o->oBhvParams2ndByte; 307 } else if (o->parentObj->oEyerokBossActiveHand == 0) { 308 o->oAction = EYEROK_HAND_ACT_IDLE; 309 o->parentObj->oEyerokBossUnk1AC = 0; 310 } 311 } 312 } 313 314 static void eyerok_hand_act_attacked(void) { 315 if (cur_obj_init_anim_and_check_if_end(3)) { 316 o->oAction = EYEROK_HAND_ACT_RECOVER; 317 o->collisionData = segmented_to_virtual(ssl_seg7_collision_07028274); 318 } 319 320 if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { 321 o->oForwardVel = 0.0f; 322 } 323 } 324 325 static void eyerok_hand_act_recover(void) { 326 if (cur_obj_init_anim_and_check_if_end(0)) { 327 o->oAction = EYEROK_HAND_ACT_BECOME_ACTIVE; 328 } 329 } 330 331 static void eyerok_hand_act_become_active(void) { 332 if (o->parentObj->oEyerokBossActiveHand == 0 || o->parentObj->oEyerokBossNumHands != 2) { 333 o->oAction = EYEROK_HAND_ACT_RETREAT; 334 o->parentObj->oEyerokBossActiveHand = o->oBhvParams2ndByte; 335 } 336 } 337 338 static void eyerok_hand_act_die(void) { 339 if (cur_obj_init_anim_and_check_if_end(1)) { 340 o->parentObj->oEyerokBossUnk1AC = 0; 341 obj_explode_and_spawn_coins(150.0f, 1); 342 create_sound_spawner(SOUND_OBJ2_EYEROK_SOUND_LONG); 343 } 344 345 if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { 346 cur_obj_play_sound_2(SOUND_OBJ_POUNDING_LOUD); 347 o->oForwardVel = 0.0f; 348 } 349 } 350 351 static void eyerok_hand_act_retreat(void) { 352 f32 distToHome = cur_obj_lateral_dist_to_home(); 353 s16 angleToHome = cur_obj_angle_to_home(); 354 355 if ((distToHome -= 40.0f) < 0.0f) { 356 distToHome = 0.0f; 357 } 358 359 o->oPosX = o->oHomeX - distToHome * sins(angleToHome); 360 o->oPosZ = o->oHomeZ - distToHome * coss(angleToHome); 361 362 obj_face_yaw_approach(0, 400); 363 364 if (approach_f32_ptr(&o->oPosY, o->oHomeY, 20.0f) && distToHome == 0.0f && o->oFaceAngleYaw == 0) { 365 o->oAction = EYEROK_HAND_ACT_IDLE; 366 o->parentObj->oEyerokBossActiveHand -= o->oBhvParams2ndByte; 367 368 if (o->parentObj->oEyerokBossUnk1AC == o->oBhvParams2ndByte) { 369 o->parentObj->oEyerokBossUnk1AC = 0; 370 } 371 } 372 } 373 374 static void eyerok_hand_act_target_mario(void) { 375 if (eyerok_check_mario_relative_z(400) || o->oPosZ - gMarioObject->oPosZ > 0.0f 376 || o->oPosZ - o->parentObj->oPosZ > 1700.0f || absf(o->oPosX - o->parentObj->oPosX) > 900.0f 377 || (o->oMoveFlags & OBJ_MOVE_HIT_WALL)) { 378 o->oForwardVel = 0.0f; 379 if (approach_f32_ptr(&o->oPosY, o->oHomeY + 300.0f, 20.0f)) { 380 o->oAction = EYEROK_HAND_ACT_SMASH; 381 } 382 } else { 383 obj_forward_vel_approach(50.0f, 5.0f); 384 approach_f32_ptr(&o->oPosY, o->oHomeY + 300.0f, 20.0f); 385 cur_obj_rotate_yaw_toward(o->oAngleToMario, 4000); 386 } 387 } 388 389 static void eyerok_hand_act_smash(void) { 390 if (o->oTimer > 20) { 391 if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { 392 if (o->oGravity < -4.0f) { 393 eyerok_hand_pound_ground(); 394 o->oGravity = -4.0f; 395 } else { 396 s16 sp1E = abs_angle_diff(o->oFaceAngleYaw, o->oAngleToMario); 397 if (o->oDistanceToMario < 300.0f && sp1E > 0x2000 && sp1E < 0x6000) { 398 o->oAction = EYEROK_HAND_ACT_FIST_SWEEP; 399 if ((s16)(o->oFaceAngleYaw - o->oAngleToMario) < 0) { 400 o->oMoveAngleYaw = 0x4000; 401 } else { 402 o->oMoveAngleYaw = -0x4000; 403 } 404 } else { 405 o->oAction = EYEROK_HAND_ACT_RETREAT; 406 } 407 } 408 } else { 409 o->oGravity = -20.0f; 410 } 411 } 412 } 413 414 static void eyerok_hand_act_fist_push(void) { 415 if (o->oTimer > 5 && (o->oPosZ - gMarioObject->oPosZ > 0.0f || (o->oMoveFlags & OBJ_MOVE_HIT_EDGE))) { 416 o->oAction = EYEROK_HAND_ACT_FIST_SWEEP; 417 o->oForwardVel = 0.0f; 418 419 if (o->oPosX - gMarioObject->oPosX < 0.0f) { 420 o->oMoveAngleYaw = 0x4000; 421 } else { 422 o->oMoveAngleYaw = -0x4000; 423 } 424 } else { 425 o->oForwardVel = 50.0f; 426 } 427 } 428 429 static void eyerok_hand_act_fist_sweep(void) { 430 if (o->oPosZ - o->parentObj->oPosZ < 1000.0f || (o->oMoveFlags & OBJ_MOVE_HIT_EDGE)) { 431 o->oAction = EYEROK_HAND_ACT_RETREAT; 432 o->oForwardVel = 0.0f; 433 } else { 434 obj_forward_vel_approach(5.0f, 0.02f); 435 o->oForwardVel *= 1.08f; 436 o->oTimer = 0; 437 } 438 } 439 440 static void eyerok_hand_act_begin_double_pound(void) { 441 if (o->parentObj->oEyerokBossUnk104 < 0 442 || o->parentObj->oEyerokBossActiveHand == o->oBhvParams2ndByte) { 443 o->oAction = EYEROK_HAND_ACT_DOUBLE_POUND; 444 o->oMoveAngleYaw = (s32)(o->oFaceAngleYaw - 0x4000 * o->parentObj->oEyerokBossUnk108); 445 } else { 446 f32 sp4 = o->parentObj->oPosX + 400.0f * o->parentObj->oEyerokBossUnk108 447 - 180.0f * o->oBhvParams2ndByte; 448 449 o->oPosX = o->oHomeX + (sp4 - o->oHomeX) * o->parentObj->oEyerokBossUnk110; 450 o->oPosY = o->oHomeY + 300.0f * o->parentObj->oEyerokBossUnk110; 451 o->oPosZ = 452 o->oHomeZ + (o->parentObj->oEyerokBossUnk10C - o->oHomeZ) * o->parentObj->oEyerokBossUnk110; 453 } 454 } 455 456 static void eyerok_hand_act_double_pound(void) { 457 if (o->parentObj->oEyerokBossNumHands != 2) { 458 o->parentObj->oEyerokBossActiveHand = o->oBhvParams2ndByte; 459 } 460 461 if (o->parentObj->oEyerokBossUnk104 == 1) { 462 o->oAction = EYEROK_HAND_ACT_RETREAT; 463 o->parentObj->oEyerokBossUnk1AC = o->oBhvParams2ndByte; 464 } else if (o->parentObj->oEyerokBossActiveHand == o->oBhvParams2ndByte) { 465 if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { 466 if (o->oGravity < -15.0f) { 467 o->parentObj->oEyerokBossActiveHand = 0; 468 eyerok_hand_pound_ground(); 469 o->oForwardVel = 0.0f; 470 o->oGravity = -15.0f; 471 } else { 472 o->oForwardVel = 30.0f * absf(o->parentObj->oEyerokBossUnk108); 473 o->oVelY = 100.0f; 474 o->oMoveFlags = 0; 475 } 476 } else if (o->oVelY <= 0.0f) { 477 o->oGravity = -20.0f; 478 } 479 } 480 } 481 482 void bhv_eyerok_hand_loop(void) { 483 o->header.gfx.scale[0] = 1.5f; 484 485 if (o->oAction == EYEROK_HAND_ACT_SLEEP) { 486 eyerok_hand_act_sleep(); 487 } else { 488 cur_obj_update_floor_and_walls(); 489 490 switch (o->oAction) { 491 case EYEROK_HAND_ACT_IDLE: 492 eyerok_hand_act_idle(); 493 break; 494 case EYEROK_HAND_ACT_OPEN: 495 eyerok_hand_act_open(); 496 break; 497 case EYEROK_HAND_ACT_SHOW_EYE: 498 eyerok_hand_act_show_eye(); 499 break; 500 case EYEROK_HAND_ACT_CLOSE: 501 eyerok_hand_act_close(); 502 break; 503 case EYEROK_HAND_ACT_RETREAT: 504 eyerok_hand_act_retreat(); 505 break; 506 case EYEROK_HAND_ACT_TARGET_MARIO: 507 eyerok_hand_act_target_mario(); 508 break; 509 case EYEROK_HAND_ACT_SMASH: 510 eyerok_hand_act_smash(); 511 break; 512 case EYEROK_HAND_ACT_FIST_PUSH: 513 eyerok_hand_act_fist_push(); 514 break; 515 case EYEROK_HAND_ACT_FIST_SWEEP: 516 eyerok_hand_act_fist_sweep(); 517 break; 518 case EYEROK_HAND_ACT_BEGIN_DOUBLE_POUND: 519 eyerok_hand_act_begin_double_pound(); 520 break; 521 case EYEROK_HAND_ACT_DOUBLE_POUND: 522 eyerok_hand_act_double_pound(); 523 break; 524 case EYEROK_HAND_ACT_ATTACKED: 525 eyerok_hand_act_attacked(); 526 break; 527 case EYEROK_HAND_ACT_RECOVER: 528 eyerok_hand_act_recover(); 529 break; 530 case EYEROK_HAND_ACT_BECOME_ACTIVE: 531 eyerok_hand_act_become_active(); 532 break; 533 case EYEROK_HAND_ACT_DIE: 534 eyerok_hand_act_die(); 535 break; 536 } 537 538 o->oEyerokReceivedAttack = obj_check_attacks(&sEyerokHitbox, o->oAction); 539 cur_obj_move_standard(-78); 540 } 541 542 load_object_collision_model(); 543 o->header.gfx.scale[0] = 1.5f * o->oBhvParams2ndByte; 544 }