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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
|
/*
* File: z_en_eiyer.c
* Overlay: ovl_En_Eiyer
* Description: Stinger (Ground)
*/
#include "z_en_eiyer.h"
#include "libc64/qrand.h"
#include "gfx.h"
#include "gfx_setupdl.h"
#include "ichain.h"
#include "sfx.h"
#include "z_en_item00.h"
#include "z_lib.h"
#include "effect.h"
#include "play_state.h"
#include "player.h"
#include "assets/objects/object_ei/object_ei.h"
#define FLAGS (ACTOR_FLAG_ATTENTION_ENABLED | ACTOR_FLAG_HOSTILE)
void EnEiyer_Init(Actor* thisx, PlayState* play);
void EnEiyer_Destroy(Actor* thisx, PlayState* play);
void EnEiyer_Update(Actor* thisx, PlayState* play);
void EnEiyer_Draw(Actor* thisx, PlayState* play);
void EnEiyer_SetupAppearFromGround(EnEiyer* this);
void EnEiyer_SetupUnderground(EnEiyer* this);
void EnEiyer_SetupInactive(EnEiyer* this);
void EnEiyer_SetupAmbush(EnEiyer* this, PlayState* play);
void EnEiyer_SetupGlide(EnEiyer* this);
void EnEiyer_SetupStartAttack(EnEiyer* this);
void EnEiyer_SetupDiveAttack(EnEiyer* this, PlayState* play);
void EnEiyer_SetupLand(EnEiyer* this);
void EnEiyer_SetupHurt(EnEiyer* this);
void EnEiyer_SetupDie(EnEiyer* this);
void EnEiyer_SetupDead(EnEiyer* this);
void EnEiyer_SetupStunned(EnEiyer* this);
void EnEiyer_AppearFromGround(EnEiyer* this, PlayState* play);
void EnEiyer_WanderUnderground(EnEiyer* this, PlayState* play);
void EnEiyer_CircleUnderground(EnEiyer* this, PlayState* play);
void EnEiyer_Inactive(EnEiyer* this, PlayState* play);
void EnEiyer_Ambush(EnEiyer* this, PlayState* play);
void EnEiyer_Glide(EnEiyer* this, PlayState* play);
void EnEiyer_StartAttack(EnEiyer* this, PlayState* play);
void EnEiyer_DiveAttack(EnEiyer* this, PlayState* play);
void EnEiyer_Land(EnEiyer* this, PlayState* play);
void EnEiyer_Hurt(EnEiyer* this, PlayState* play);
void EnEiyer_Die(EnEiyer* this, PlayState* play);
void EnEiyer_Dead(EnEiyer* this, PlayState* play);
void EnEiyer_Stunned(EnEiyer* this, PlayState* play);
ActorProfile En_Eiyer_Profile = {
/**/ ACTOR_EN_EIYER,
/**/ ACTORCAT_ENEMY,
/**/ FLAGS,
/**/ OBJECT_EI,
/**/ sizeof(EnEiyer),
/**/ EnEiyer_Init,
/**/ EnEiyer_Destroy,
/**/ EnEiyer_Update,
/**/ EnEiyer_Draw,
};
static ColliderCylinderInit sColliderCylinderInit = {
{
COL_MATERIAL_HIT0,
AT_ON | AT_TYPE_ENEMY,
AC_ON | AC_TYPE_PLAYER,
OC1_ON | OC1_TYPE_ALL,
OC2_TYPE_1,
COLSHAPE_CYLINDER,
},
{
ELEM_MATERIAL_UNK0,
{ 0xFFCFFFFF, HIT_SPECIAL_EFFECT_KNOCKBACK, 0x08 },
{ 0x00000019, HIT_BACKLASH_NONE, 0x00 },
ATELEM_ON | ATELEM_SFX_HARD,
ACELEM_ON,
OCELEM_ON,
},
{ 27, 17, -10, { 0, 0, 0 } },
};
static CollisionCheckInfoInit sColChkInfoInit = { 2, 45, 15, 100 };
static DamageTable sDamageTable = {
/* Deku nut */ DMG_ENTRY(0, 0x1),
/* Deku stick */ DMG_ENTRY(2, 0x0),
/* Slingshot */ DMG_ENTRY(1, 0x0),
/* Explosive */ DMG_ENTRY(2, 0x0),
/* Boomerang */ DMG_ENTRY(0, 0x1),
/* Normal arrow */ DMG_ENTRY(2, 0x0),
/* Hammer swing */ DMG_ENTRY(2, 0x0),
/* Hookshot */ DMG_ENTRY(2, 0x0),
/* Kokiri sword */ DMG_ENTRY(1, 0x0),
/* Master sword */ DMG_ENTRY(2, 0x0),
/* Giant's Knife */ DMG_ENTRY(4, 0x0),
/* Fire arrow */ DMG_ENTRY(2, 0x0),
/* Ice arrow */ DMG_ENTRY(2, 0x0),
/* Light arrow */ DMG_ENTRY(2, 0x0),
/* Unk arrow 1 */ DMG_ENTRY(2, 0x0),
/* Unk arrow 2 */ DMG_ENTRY(2, 0x0),
/* Unk arrow 3 */ DMG_ENTRY(2, 0x0),
/* Fire magic */ DMG_ENTRY(0, 0x0),
/* Ice magic */ DMG_ENTRY(4, 0x0),
/* Light magic */ DMG_ENTRY(4, 0x0),
/* Shield */ DMG_ENTRY(0, 0x0),
/* Mirror Ray */ DMG_ENTRY(0, 0x0),
/* Kokiri spin */ DMG_ENTRY(1, 0x0),
/* Giant spin */ DMG_ENTRY(4, 0x0),
/* Master spin */ DMG_ENTRY(2, 0x0),
/* Kokiri jump */ DMG_ENTRY(2, 0x0),
/* Giant jump */ DMG_ENTRY(8, 0x0),
/* Master jump */ DMG_ENTRY(4, 0x0),
/* Unknown 1 */ DMG_ENTRY(0, 0x0),
/* Unblockable */ DMG_ENTRY(0, 0x0),
/* Hammer jump */ DMG_ENTRY(4, 0x0),
/* Unknown 2 */ DMG_ENTRY(0, 0x0),
};
static InitChainEntry sInitChain[] = {
ICHAIN_S8(naviEnemyId, NAVI_ENEMY_STINGER, ICHAIN_CONTINUE),
ICHAIN_VEC3F_DIV1000(scale, 5, ICHAIN_CONTINUE),
ICHAIN_F32(lockOnArrowOffset, 2500, ICHAIN_STOP),
};
/**
* params 0: Spawn 3 clones and circle around spawn point
* params 1-3: Clone, spawn another clone for the main Eiyer if params < 3
* params 10: Normal Eiyer, wander around spawn point
*/
void EnEiyer_Init(Actor* thisx, PlayState* play) {
EnEiyer* this = (EnEiyer*)thisx;
s32 pad;
Actor_ProcessInitChain(&this->actor, sInitChain);
ActorShape_Init(&this->actor.shape, 600.0f, ActorShadow_DrawCircle, 65.0f);
SkelAnime_Init(play, &this->skelanime, &gStingerSkel, &gStingerIdleAnim, this->jointTable, this->morphTable, 19);
Collider_InitCylinder(play, &this->collider);
Collider_SetCylinder(play, &this->collider, &this->actor, &sColliderCylinderInit);
CollisionCheck_SetInfo(&this->actor.colChkInfo, &sDamageTable, &sColChkInfoInit);
if (this->actor.params < 3) {
// Each clone spawns another clone
if (Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_EN_EIYER, this->actor.home.pos.x,
this->actor.home.pos.y, this->actor.home.pos.z, 0, this->actor.shape.rot.y + 0x4000, 0,
this->actor.params + 1) == NULL) {
Actor_Kill(&this->actor);
return;
}
if (this->actor.params == 0) {
Actor* child = this->actor.child;
s32 clonesSpawned;
for (clonesSpawned = 0; clonesSpawned != 3; clonesSpawned++) {
if (child == NULL) {
break;
}
child = child->child;
}
if (clonesSpawned != 3) {
for (child = &this->actor; child != NULL; child = child->child) {
Actor_Kill(child);
}
return;
} else {
this->actor.child->parent = &this->actor;
this->actor.child->child->parent = &this->actor;
this->actor.child->child->child->parent = &this->actor;
}
}
}
if (this->actor.params == 0 || this->actor.params == 10) {
EnEiyer_SetupAppearFromGround(this);
} else {
EnEiyer_SetupInactive(this);
}
}
void EnEiyer_Destroy(Actor* thisx, PlayState* play) {
EnEiyer* this = (EnEiyer*)thisx;
Collider_DestroyCylinder(play, &this->collider);
}
void EnEiyer_RotateAroundHome(EnEiyer* this) {
this->actor.world.pos.x = Math_SinS(this->actor.world.rot.y) * 80.0f + this->actor.home.pos.x;
this->actor.world.pos.z = Math_CosS(this->actor.world.rot.y) * 80.0f + this->actor.home.pos.z;
this->actor.shape.rot.y = this->actor.world.rot.y + 0x4000;
}
void EnEiyer_SetupAppearFromGround(EnEiyer* this) {
this->collider.elem.acDmgInfo.dmgFlags = DMG_BOOMERANG | DMG_EXPLOSIVE | DMG_DEKU_NUT;
Animation_PlayLoop(&this->skelanime, &gStingerIdleAnim);
this->actor.world.pos.x = this->actor.home.pos.x;
this->actor.world.pos.y = this->actor.home.pos.y - 40.0f;
this->actor.world.pos.z = this->actor.home.pos.z;
this->actor.velocity.y = 0.0f;
this->actor.speed = 0.0f;
if (this->actor.params != 0xA) {
if (this->actor.params == 0) {
this->actor.world.rot.y = Rand_ZeroOne() * 0x10000;
} else {
this->actor.world.rot.y = this->actor.parent->world.rot.y + this->actor.params * 0x4000;
}
EnEiyer_RotateAroundHome(this);
} else {
this->actor.world.rot.y = this->actor.shape.rot.y = Rand_ZeroOne() * 0x10000;
}
this->collider.base.atFlags &= ~AT_ON;
this->collider.base.acFlags &= ~AC_ON;
this->actor.flags &= ~(ACTOR_FLAG_ATTENTION_ENABLED | ACTOR_FLAG_IGNORE_QUAKE);
this->actor.shape.shadowScale = 0.0f;
this->actor.shape.yOffset = 0.0f;
this->actionFunc = EnEiyer_AppearFromGround;
}
void EnEiyer_SetupUnderground(EnEiyer* this) {
if (this->actor.params == 0xA) {
this->actor.speed = -0.5f;
this->actionFunc = EnEiyer_WanderUnderground;
} else {
this->actionFunc = EnEiyer_CircleUnderground;
}
this->collider.base.acFlags |= AC_ON;
this->actor.flags &= ~ACTOR_FLAG_UPDATE_CULLING_DISABLED;
this->actor.flags |= ACTOR_FLAG_ATTENTION_ENABLED;
}
void EnEiyer_SetupInactive(EnEiyer* this) {
this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
this->actor.world.rot.y = this->actor.shape.rot.y;
this->actionFunc = EnEiyer_Inactive;
}
void EnEiyer_SetupAmbush(EnEiyer* this, PlayState* play) {
this->actor.speed = 0.0f;
Animation_PlayOnce(&this->skelanime, &gStingerBackflipAnim);
this->collider.elem.acDmgInfo.dmgFlags = DMG_DEFAULT;
this->basePos = this->actor.world.pos;
this->actor.world.rot.y = this->actor.shape.rot.y;
this->actor.flags |= ACTOR_FLAG_IGNORE_QUAKE;
this->collider.base.acFlags &= ~AC_ON;
this->actor.shape.shadowScale = 65.0f;
this->actor.shape.yOffset = 600.0f;
Actor_PlaySfx(&this->actor, NA_SE_EN_OCTAROCK_JUMP);
EffectSsGSplash_Spawn(play, &this->actor.world.pos, NULL, NULL, 1, 700);
this->actionFunc = EnEiyer_Ambush;
}
void EnEiyer_SetupGlide(EnEiyer* this) {
this->targetYaw = this->actor.shape.rot.y;
this->basePos.y = (cosf(-M_PI / 8) * 5.0f) + this->actor.world.pos.y;
Animation_MorphToLoop(&this->skelanime, &gStingerHitAnim, -5.0f);
this->timer = 60;
this->actionFunc = EnEiyer_Glide;
}
void EnEiyer_SetupStartAttack(EnEiyer* this) {
this->actionFunc = EnEiyer_StartAttack;
}
void EnEiyer_SetupDiveAttack(EnEiyer* this, PlayState* play) {
Player* player = GET_PLAYER(play);
this->actor.velocity.y = 0.0f;
this->basePos.y = player->actor.world.pos.y + 15.0f;
this->collider.base.atFlags |= AT_ON;
this->collider.base.atFlags &= ~AT_HIT;
this->actionFunc = EnEiyer_DiveAttack;
}
void EnEiyer_SetupLand(EnEiyer* this) {
Animation_MorphToPlayOnce(&this->skelanime, &gStingerDiveAnim, -3.0f);
this->collider.base.atFlags &= ~AT_ON;
this->actor.flags |= ACTOR_FLAG_UPDATE_CULLING_DISABLED;
// Update BgCheck info, play sound, and spawn effect on the first frame of the land action
this->timer = -1;
this->actor.gravity = 0.0f;
this->collider.dim.height = sColliderCylinderInit.dim.height;
this->actionFunc = EnEiyer_Land;
}
void EnEiyer_SetupHurt(EnEiyer* this) {
this->basePos.y = this->actor.world.pos.y;
Animation_Change(&this->skelanime, &gStingerHitAnim, 2.0f, 0.0f, 0.0f, 0, -3.0f);
this->timer = 40;
this->actor.gravity = 0.0f;
this->actor.velocity.y = 0.0f;
this->actor.speed = 5.0f;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_RED, 200, COLORFILTER_BUFFLAG_OPA, 40);
this->collider.base.acFlags &= ~AC_ON;
this->actionFunc = EnEiyer_Hurt;
}
void EnEiyer_SetupDie(EnEiyer* this) {
this->timer = 20;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_RED, 200, COLORFILTER_BUFFLAG_OPA, 40);
if (this->collider.elem.acDmgInfo.dmgFlags != (DMG_BOOMERANG | DMG_EXPLOSIVE | DMG_DEKU_NUT)) {
this->actor.speed = 6.0f;
Animation_MorphToLoop(&this->skelanime, &gStingerHitAnim, -3.0f);
} else {
this->actor.speed -= 6.0f;
}
this->collider.elem.acDmgInfo.dmgFlags = DMG_DEFAULT;
this->collider.base.atFlags &= ~AT_ON;
this->collider.base.acFlags &= ~AC_ON;
this->actionFunc = EnEiyer_Die;
}
void EnEiyer_SetupDead(EnEiyer* this) {
this->actor.speed = 0.0f;
this->actor.velocity.y = 0.0f;
this->actor.colorFilterParams |= 0x2000;
this->actionFunc = EnEiyer_Dead;
}
void EnEiyer_SetupStunned(EnEiyer* this) {
Animation_Change(&this->skelanime, &gStingerPopOutAnim, 2.0f, 0.0f, 0.0f, 0, -8.0f);
this->timer = 80;
this->actor.speed = 0.0f;
this->actor.velocity.y = 0.0f;
this->actor.gravity = -1.0f;
this->collider.dim.height = sColliderCylinderInit.dim.height + 8;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_BLUE, 200, COLORFILTER_BUFFLAG_OPA, 80);
this->collider.base.atFlags &= ~AT_ON;
Actor_PlaySfx(&this->actor, NA_SE_EN_GOMA_JR_FREEZE);
this->actionFunc = EnEiyer_Stunned;
}
void EnEiyer_AppearFromGround(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
if (Math_StepToF(&this->actor.world.pos.y, this->actor.home.pos.y, 0.75f)) {
EnEiyer_SetupUnderground(this);
}
}
void EnEiyer_CheckPlayerCollision(EnEiyer* this, PlayState* play) {
if (this->collider.base.ocFlags2 & OC2_HIT_PLAYER) {
this->collider.base.ocFlags2 &= ~OC2_HIT_PLAYER;
EnEiyer_SetupAmbush(this, play);
}
}
void EnEiyer_CircleUnderground(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
this->actor.world.rot.y += -0x60;
EnEiyer_RotateAroundHome(this);
EnEiyer_CheckPlayerCollision(this, play);
// Clones disappear when the main Eiyer leaves the ground
if (this->actor.params != 0 && ((EnEiyer*)this->actor.parent)->actionFunc != EnEiyer_CircleUnderground) {
EnEiyer_SetupInactive(this);
}
}
void EnEiyer_WanderUnderground(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
if (Actor_WorldDistXZToPoint(&this->actor, &this->actor.home.pos) > 100.0f) {
this->targetYaw = Actor_WorldYawTowardPoint(&this->actor, &this->actor.home.pos) + 0x8000;
} else if (this->targetYaw == this->actor.world.rot.y && Rand_ZeroOne() > 0.99f) {
this->targetYaw =
this->actor.world.rot.y + (Rand_ZeroOne() < 0.5f ? -1 : 1) * (Rand_ZeroOne() * 0x2000 + 0x2000);
}
Math_ScaledStepToS(&this->actor.world.rot.y, this->targetYaw, 0xB6);
EnEiyer_CheckPlayerCollision(this, play);
}
void EnEiyer_Inactive(EnEiyer* this, PlayState* play) {
EnEiyer* parent;
if (this->actor.home.pos.y - 50.0f < this->actor.world.pos.y) {
this->actor.world.pos.y -= 0.5f;
}
parent = (EnEiyer*)this->actor.parent;
if (parent->actionFunc == EnEiyer_Dead) {
Actor_Kill(&this->actor);
} else if (parent->actionFunc == EnEiyer_AppearFromGround) {
EnEiyer_SetupAppearFromGround(this);
}
}
void EnEiyer_Ambush(EnEiyer* this, PlayState* play) {
s32 animFinished;
f32 curFrame;
f32 xzOffset;
s32 bgId;
animFinished = SkelAnime_Update(&this->skelanime);
curFrame = this->skelanime.curFrame;
if (this->skelanime.curFrame < 12.0f) {
this->actor.world.pos.y = ((1.0f - cosf((0.996f * M_PI / 12.0f) * curFrame)) * 40.0f) + this->actor.home.pos.y;
xzOffset = sinf((0.996f * M_PI / 12.0f) * curFrame) * -40.0f;
this->actor.world.pos.x = (Math_SinS(this->actor.shape.rot.y) * xzOffset) + this->basePos.x;
this->actor.world.pos.z = (Math_CosS(this->actor.shape.rot.y) * xzOffset) + this->basePos.z;
} else {
Math_StepToF(&this->actor.world.pos.y, this->actor.home.pos.y + 80.0f, 0.5f);
this->actor.speed = 0.8f;
}
if (animFinished) {
this->collider.base.acFlags |= AC_ON;
EnEiyer_SetupGlide(this);
} else {
this->actor.floorHeight = BgCheck_EntityRaycastDown4(&play->colCtx, &this->actor.floorPoly, &bgId, &this->actor,
&this->actor.world.pos);
}
}
void EnEiyer_Glide(EnEiyer* this, PlayState* play) {
f32 curFrame;
s32 pad;
s16 yawChange;
SkelAnime_Update(&this->skelanime);
if (this->timer != 0) {
this->timer--;
}
curFrame = this->skelanime.curFrame;
Math_ApproachF(&this->basePos.y, this->actor.floorHeight + 80.0f + 5.0f, 0.3f, this->actor.speed);
this->actor.world.pos.y = this->basePos.y - cosf((curFrame - 5.0f) * (M_PI / 40)) * 5.0f;
if (curFrame <= 45.0f) {
Math_StepToF(&this->actor.speed, 1.0f, 0.03f);
} else {
Math_StepToF(&this->actor.speed, 1.5f, 0.03f);
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
this->targetYaw = this->actor.wallYaw;
}
if (Math_ScaledStepToS(&this->actor.world.rot.y, this->targetYaw, 0xB6)) {
if (this->timer != 0 || Rand_ZeroOne() > 0.05f) {
this->actor.world.rot.y += 0x100;
} else {
yawChange = Rand_S16Offset(0x2000, 0x2000);
this->targetYaw = (Rand_ZeroOne() < 0.5f ? -1 : 1) * yawChange + this->actor.world.rot.y;
}
}
if (this->timer == 0 && this->actor.yDistToPlayer < 0.0f && this->actor.xzDistToPlayer < 120.0f) {
EnEiyer_SetupStartAttack(this);
}
Actor_PlaySfx_Flagged(&this->actor, NA_SE_EN_EIER_FLY - SFX_FLAG);
}
void EnEiyer_StartAttack(EnEiyer* this, PlayState* play) {
Player* player = GET_PLAYER(play);
Vec3f focus;
SkelAnime_Update(&this->skelanime);
if (this->actor.shape.rot.x > 0 && this->actor.shape.rot.x < 0x8000) {
focus.x = player->actor.world.pos.x;
focus.y = player->actor.world.pos.y + 20.0f;
focus.z = player->actor.world.pos.z;
if (Math_ScaledStepToS(&this->actor.shape.rot.x, Actor_WorldPitchTowardPoint(&this->actor, &focus), 0x1000)) {
EnEiyer_SetupDiveAttack(this, play);
}
} else {
this->actor.shape.rot.x -= 0x1000;
}
this->actor.world.rot.x = -this->actor.shape.rot.x;
Math_StepToF(&this->actor.speed, 5.0f, 0.3f);
Math_ApproachS(&this->actor.world.rot.y, this->actor.yawTowardsPlayer, 2, 0x71C);
Actor_PlaySfx_Flagged(&this->actor, NA_SE_EN_EIER_FLY - SFX_FLAG);
}
void EnEiyer_DiveAttack(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
this->actor.speed *= 1.1f;
if ((this->actor.bgCheckFlags & BGCHECKFLAG_WALL) || (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND)) {
EnEiyer_SetupLand(this);
}
if (this->collider.base.atFlags & AT_HIT) {
this->collider.base.atFlags &= ~(AT_ON | AT_HIT);
}
Actor_PlaySfx_Flagged(&this->actor, NA_SE_EN_EIER_FLY - SFX_FLAG);
}
void EnEiyer_Land(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
Math_ScaledStepToS(&this->actor.world.rot.x, -0x4000, 0x450);
Math_StepToF(&this->actor.speed, 7.0f, 1.0f);
if (this->timer == -1) {
if ((this->actor.bgCheckFlags & BGCHECKFLAG_WALL) || (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND)) {
this->timer = 10;
SfxSource_PlaySfxAtFixedWorldPos(play, &this->actor.world.pos, 30, NA_SE_EN_OCTAROCK_SINK);
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
EffectSsGSplash_Spawn(play, &this->actor.world.pos, NULL, NULL, 1, 700);
}
}
} else {
if (this->timer != 0) {
this->timer--;
}
if (this->timer == 0) {
this->actor.shape.rot.x = 0;
this->actor.world.rot.x = 0;
EnEiyer_SetupAppearFromGround(this);
}
}
}
void EnEiyer_Hurt(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
if (this->timer != 0) {
this->timer--;
}
Math_ApproachF(&this->basePos.y, this->actor.floorHeight + 80.0f + 5.0f, 0.5f, this->actor.speed);
this->actor.world.pos.y = this->basePos.y - 5.0f;
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
this->targetYaw = this->actor.wallYaw;
} else {
this->targetYaw = this->actor.yawTowardsPlayer + 0x8000;
}
Math_ScaledStepToS(&this->actor.world.rot.y, this->targetYaw, 0x38E);
Math_ScaledStepToS(&this->actor.shape.rot.x, 0, 0x200);
this->actor.shape.rot.z = sinf(this->timer * (M_PI / 5)) * 5120.0f;
if (this->timer == 0) {
this->actor.shape.rot.x = 0;
this->actor.shape.rot.z = 0;
this->collider.base.acFlags |= AC_ON;
EnEiyer_SetupGlide(this);
}
this->actor.world.rot.x = -this->actor.shape.rot.x;
}
void EnEiyer_Die(EnEiyer* this, PlayState* play) {
SkelAnime_Update(&this->skelanime);
if (this->actor.speed > 0.0f) {
Math_ScaledStepToS(&this->actor.shape.rot.x, -0x4000, 0x400);
} else {
Math_ScaledStepToS(&this->actor.shape.rot.x, 0x4000, 0x400);
}
this->actor.shape.rot.z += 0x1000;
if (this->timer != 0) {
this->timer--;
}
this->actor.world.rot.x = -this->actor.shape.rot.x;
if (this->timer == 0 || this->actor.bgCheckFlags & BGCHECKFLAG_CEILING) {
EnEiyer_SetupDead(this);
}
}
void EnEiyer_Dead(EnEiyer* this, PlayState* play) {
this->actor.shape.shadowAlpha = CLAMP_MIN((s16)(this->actor.shape.shadowAlpha - 5), 0);
this->actor.world.pos.y -= 2.0f;
if (this->actor.shape.shadowAlpha == 0) {
Item_DropCollectibleRandom(play, &this->actor, &this->actor.world.pos,
COLLECTIBLE_DROP_RANDOM_PARAMS(COLLECTIBLE_DROP_TABLE_5, false));
Actor_Kill(&this->actor);
}
}
void EnEiyer_Stunned(EnEiyer* this, PlayState* play) {
if (this->timer != 0) {
this->timer--;
}
Math_ScaledStepToS(&this->actor.shape.rot.x, 0, 0x200);
SkelAnime_Update(&this->skelanime);
if (Animation_OnFrame(&this->skelanime, 0.0f)) {
Actor_PlaySfx(&this->actor, NA_SE_EN_EIER_FLUTTER);
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND_TOUCH) {
Actor_PlaySfx(&this->actor, NA_SE_EN_DODO_M_GND);
}
if (this->timer == 0) {
this->actor.gravity = 0.0f;
this->actor.velocity.y = 0.0f;
this->collider.dim.height = sColliderCylinderInit.dim.height;
EnEiyer_SetupGlide(this);
}
}
void EnEiyer_UpdateDamage(EnEiyer* this, PlayState* play) {
if (this->collider.base.acFlags & AC_HIT) {
this->collider.base.acFlags &= ~AC_HIT;
Actor_SetDropFlag(&this->actor, &this->collider.elem, true);
if (this->actor.colChkInfo.damageReaction != 0 || this->actor.colChkInfo.damage != 0) {
if (Actor_ApplyDamage(&this->actor) == 0) {
Enemy_StartFinishingBlow(play, &this->actor);
Actor_PlaySfx(&this->actor, NA_SE_EN_EIER_DEAD);
this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
}
// If underground, one hit kill
if (this->collider.elem.acDmgInfo.dmgFlags == (DMG_BOOMERANG | DMG_EXPLOSIVE | DMG_DEKU_NUT)) {
if (this->actor.colChkInfo.damage == 0) {
EnEiyer_SetupAmbush(this, play);
} else {
EnEiyer_SetupDie(this);
}
} else if (this->actor.colChkInfo.damageReaction == 1) {
if (this->actionFunc != EnEiyer_Stunned) {
EnEiyer_SetupStunned(this);
}
} else if (this->actor.colChkInfo.health != 0) {
Actor_PlaySfx(&this->actor, NA_SE_EN_EIER_DAMAGE);
EnEiyer_SetupHurt(this);
} else {
this->collider.dim.height = sColliderCylinderInit.dim.height;
EnEiyer_SetupDie(this);
}
}
}
}
void EnEiyer_Update(Actor* thisx, PlayState* play) {
EnEiyer* this = (EnEiyer*)thisx;
s32 pad;
EnEiyer_UpdateDamage(this, play);
this->actionFunc(this, play);
if (this->actor.world.rot.x == 0 || this->actionFunc == EnEiyer_Stunned) {
Actor_MoveXZGravity(&this->actor);
} else {
Actor_MoveXYZ(&this->actor);
}
if (this->actionFunc == EnEiyer_Glide || this->actionFunc == EnEiyer_DiveAttack ||
this->actionFunc == EnEiyer_Stunned || this->actionFunc == EnEiyer_Die || this->actionFunc == EnEiyer_Hurt ||
(this->actionFunc == EnEiyer_Land && this->timer == -1)) {
Actor_UpdateBgCheckInfo(play, &this->actor, 5.0f, 27.0f, 30.0f,
UPDBGCHECKINFO_FLAG_0 | UPDBGCHECKINFO_FLAG_1 | UPDBGCHECKINFO_FLAG_2);
}
if (this->actor.params == 0xA ||
(this->actionFunc != EnEiyer_AppearFromGround && this->actionFunc != EnEiyer_CircleUnderground)) {
this->actor.shape.rot.y = this->actor.world.rot.y;
}
// only the main Eiyer can ambush the player
if (this->actor.params == 0 || this->actor.params == 0xA) {
Collider_UpdateCylinder(&this->actor, &this->collider);
if (this->collider.base.atFlags & AT_ON) {
CollisionCheck_SetAT(play, &play->colChkCtx, &this->collider.base);
}
if (this->collider.base.acFlags & AC_ON) {
CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base);
}
if (this->actionFunc != EnEiyer_Ambush) {
CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base);
}
}
if (this->actor.flags & ACTOR_FLAG_ATTENTION_ENABLED) {
this->actor.focus.pos.x = this->actor.world.pos.x + Math_SinS(this->actor.shape.rot.y) * 12.5f;
this->actor.focus.pos.z = this->actor.world.pos.z + Math_CosS(this->actor.shape.rot.y) * 12.5f;
this->actor.focus.pos.y = this->actor.world.pos.y;
}
}
s32 EnEiyer_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx,
Gfx** gfx) {
EnEiyer* this = (EnEiyer*)thisx;
if (limbIndex == 1) {
pos->z += 2500.0f;
}
if (this->collider.elem.acDmgInfo.dmgFlags == (DMG_BOOMERANG | DMG_EXPLOSIVE | DMG_DEKU_NUT) && limbIndex != 9 &&
limbIndex != 10) {
*dList = NULL;
}
return 0;
}
void EnEiyer_Draw(Actor* thisx, PlayState* play) {
EnEiyer* this = (EnEiyer*)thisx;
OPEN_DISPS(play->state.gfxCtx, "../z_en_eiyer.c", 1494);
if (this->actionFunc != EnEiyer_Dead) {
Gfx_SetupDL_25Opa(play->state.gfxCtx);
gSPSegment(POLY_OPA_DISP++, 0x08, &D_80116280[2]);
gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 255, 255);
POLY_OPA_DISP = SkelAnime_Draw(play, this->skelanime.skeleton, this->skelanime.jointTable,
EnEiyer_OverrideLimbDraw, NULL, this, POLY_OPA_DISP);
} else {
Gfx_SetupDL_25Xlu(play->state.gfxCtx);
gSPSegment(POLY_XLU_DISP++, 0x08, D_80116280);
gDPSetEnvColor(POLY_XLU_DISP++, 255, 255, 255, this->actor.shape.shadowAlpha);
POLY_XLU_DISP = SkelAnime_Draw(play, this->skelanime.skeleton, this->skelanime.jointTable,
EnEiyer_OverrideLimbDraw, NULL, this, POLY_XLU_DISP);
}
CLOSE_DISPS(play->state.gfxCtx, "../z_en_eiyer.c", 1541);
}
|