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
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
|
/*
* File: z_en_firefly.c
* Overlay: ovl_En_Firefly
* Description: Keese (Normal, Fire, Ice)
*/
#include "z_en_firefly.h"
#include "overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.h"
#include "libc64/qrand.h"
#include "array_count.h"
#include "gfx.h"
#include "gfx_setupdl.h"
#include "ichain.h"
#include "rand.h"
#include "sfx.h"
#include "sys_matrix.h"
#include "versions.h"
#include "z_en_item00.h"
#include "z_lib.h"
#include "effect.h"
#include "play_state.h"
#include "player.h"
#include "assets/objects/object_firefly/object_firefly.h"
#define FLAGS \
(ACTOR_FLAG_ATTENTION_ENABLED | ACTOR_FLAG_HOSTILE | ACTOR_FLAG_IGNORE_QUAKE | ACTOR_FLAG_CAN_ATTACH_TO_ARROW)
void EnFirefly_Init(Actor* thisx, PlayState* play);
void EnFirefly_Destroy(Actor* thisx, PlayState* play);
void EnFirefly_Update(Actor* thisx, PlayState* play2);
void EnFirefly_Draw(Actor* thisx, PlayState* play);
void EnFirefly_DrawInvisible(Actor* thisx, PlayState* play);
void EnFirefly_FlyIdle(EnFirefly* this, PlayState* play);
void EnFirefly_Fall(EnFirefly* this, PlayState* play);
void EnFirefly_Die(EnFirefly* this, PlayState* play);
void EnFirefly_DiveAttack(EnFirefly* this, PlayState* play);
void EnFirefly_Rebound(EnFirefly* this, PlayState* play);
void EnFirefly_FlyAway(EnFirefly* this, PlayState* play);
void EnFirefly_Stunned(EnFirefly* this, PlayState* play);
void EnFirefly_FrozenFall(EnFirefly* this, PlayState* play);
void EnFirefly_Perch(EnFirefly* this, PlayState* play);
void EnFirefly_DisturbDiveAttack(EnFirefly* this, PlayState* play);
typedef enum KeeseAuraType {
/* 0 */ KEESE_AURA_NONE,
/* 1 */ KEESE_AURA_FIRE,
/* 2 */ KEESE_AURA_ICE
} KeeseAuraType;
ActorProfile En_Firefly_Profile = {
/**/ ACTOR_EN_FIREFLY,
/**/ ACTORCAT_ENEMY,
/**/ FLAGS,
/**/ OBJECT_FIREFLY,
/**/ sizeof(EnFirefly),
/**/ EnFirefly_Init,
/**/ EnFirefly_Destroy,
/**/ EnFirefly_Update,
/**/ EnFirefly_Draw,
};
static ColliderJntSphElementInit sJntSphElementsInit[] = {
{
{
ELEM_MATERIAL_UNK0,
{ 0xFFCFFFFF, HIT_SPECIAL_EFFECT_FIRE, 0x08 },
{ 0xFFCFFFFF, HIT_BACKLASH_NONE, 0x00 },
ATELEM_ON | ATELEM_SFX_HARD,
ACELEM_ON,
OCELEM_ON,
},
{ 1, { { 0, 1000, 0 }, 15 }, 100 },
},
};
static ColliderJntSphInit sJntSphInit = {
{
COL_MATERIAL_HIT3,
AT_ON | AT_TYPE_ENEMY,
AC_ON | AC_TYPE_PLAYER,
OC1_ON | OC1_TYPE_ALL,
OC2_TYPE_1,
COLSHAPE_JNTSPH,
},
ARRAY_COUNT(sJntSphElementsInit),
sJntSphElementsInit,
};
static CollisionCheckInfoInit sColChkInfoInit = { 1, 10, 10, 30 };
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(1, 0x0),
/* 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, 0xF),
/* Ice arrow */ DMG_ENTRY(4, 0x3),
/* 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, 0x2),
/* Ice magic */ DMG_ENTRY(4, 0x3),
/* Light magic */ DMG_ENTRY(0, 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_VEC3F_DIV1000(scale, 5, ICHAIN_CONTINUE), ICHAIN_F32_DIV1000(gravity, -500, ICHAIN_CONTINUE),
ICHAIN_F32(minVelocityY, -4, ICHAIN_CONTINUE), ICHAIN_U8(attentionRangeType, ATTENTION_RANGE_2, ICHAIN_CONTINUE),
ICHAIN_F32(lockOnArrowOffset, 4000, ICHAIN_STOP),
};
void EnFirefly_Extinguish(EnFirefly* this) {
this->actor.params += 2;
this->collider.elements[0].base.atDmgInfo.hitSpecialEffect = HIT_SPECIAL_EFFECT_NONE;
this->auraType = KEESE_AURA_NONE;
this->onFire = false;
this->actor.naviEnemyId = NAVI_ENEMY_KEESE;
}
void EnFirefly_Ignite(EnFirefly* this) {
if (this->actor.params == KEESE_ICE_FLY) {
this->actor.params = KEESE_FIRE_FLY;
} else {
this->actor.params -= 2;
}
this->collider.elements[0].base.atDmgInfo.hitSpecialEffect = HIT_SPECIAL_EFFECT_FIRE;
this->auraType = KEESE_AURA_FIRE;
this->onFire = true;
this->actor.naviEnemyId = NAVI_ENEMY_FIRE_KEESE;
}
void EnFirefly_Init(Actor* thisx, PlayState* play) {
EnFirefly* this = (EnFirefly*)thisx;
Actor_ProcessInitChain(&this->actor, sInitChain);
ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 25.0f);
SkelAnime_Init(play, &this->skelAnime, &gKeeseSkeleton, &gKeeseFlyAnim, this->jointTable, this->morphTable, 28);
Collider_InitJntSph(play, &this->collider);
Collider_SetJntSph(play, &this->collider, &this->actor, &sJntSphInit, this->colliderElements);
CollisionCheck_SetInfo(&this->actor.colChkInfo, &sDamageTable, &sColChkInfoInit);
if (PARAMS_GET_NOSHIFT(this->actor.params, 15, 1) != 0) {
this->actor.flags |= ACTOR_FLAG_REACT_TO_LENS;
if (1) {}
this->actor.draw = EnFirefly_DrawInvisible;
this->actor.params &= 0x7FFF;
}
if (this->actor.params <= KEESE_FIRE_PERCH) {
this->onFire = true;
} else {
this->onFire = false;
}
if (this->onFire) {
this->actionFunc = EnFirefly_FlyIdle;
this->timer = Rand_S16Offset(20, 60);
this->actor.shape.rot.x = 0x1554;
this->auraType = KEESE_AURA_FIRE;
this->actor.naviEnemyId = NAVI_ENEMY_FIRE_KEESE;
this->maxAltitude = this->actor.home.pos.y;
} else {
if (this->actor.params == KEESE_NORMAL_PERCH) {
this->actionFunc = EnFirefly_Perch;
} else {
this->actionFunc = EnFirefly_FlyIdle;
}
if (this->actor.params == KEESE_ICE_FLY) {
this->collider.elements[0].base.atDmgInfo.hitSpecialEffect = HIT_SPECIAL_EFFECT_ICE;
this->actor.naviEnemyId = NAVI_ENEMY_ICE_KEESE;
} else {
this->collider.elements[0].base.atDmgInfo.hitSpecialEffect = HIT_SPECIAL_EFFECT_NONE;
this->actor.naviEnemyId = NAVI_ENEMY_KEESE;
}
this->maxAltitude = this->actor.home.pos.y + 100.0f;
if (this->actor.params == KEESE_ICE_FLY) {
this->auraType = KEESE_AURA_ICE;
} else {
this->auraType = KEESE_AURA_NONE;
}
}
this->collider.elements[0].dim.worldSphere.radius = sJntSphInit.elements[0].dim.modelSphere.radius;
}
void EnFirefly_Destroy(Actor* thisx, PlayState* play) {
EnFirefly* this = (EnFirefly*)thisx;
Collider_DestroyJntSph(play, &this->collider);
}
void EnFirefly_SetupFlyIdle(EnFirefly* this) {
this->timer = Rand_S16Offset(70, 100);
this->actor.speed = (Rand_ZeroOne() * 1.5f) + 1.5f;
Math_ScaledStepToS(&this->actor.shape.rot.y, Actor_WorldYawTowardPoint(&this->actor, &this->actor.home.pos), 0x300);
this->targetPitch = ((this->maxAltitude < this->actor.world.pos.y) ? 0xC00 : -0xC00) + 0x1554;
this->skelAnime.playSpeed = 1.0f;
this->actionFunc = EnFirefly_FlyIdle;
}
void EnFirefly_SetupFall(EnFirefly* this) {
this->timer = 40;
this->actor.velocity.y = 0.0f;
Animation_Change(&this->skelAnime, &gKeeseFlyAnim, 0.5f, 0.0f, 0.0f, ANIMMODE_LOOP_INTERP, -3.0f);
Actor_PlaySfx(&this->actor, NA_SE_EN_FFLY_DEAD);
this->actor.flags |= ACTOR_FLAG_UPDATE_CULLING_DISABLED;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_RED, 255, COLORFILTER_BUFFLAG_OPA, 40);
this->actionFunc = EnFirefly_Fall;
}
void EnFirefly_SetupDie(EnFirefly* this) {
this->timer = 15;
this->actor.speed = 0.0f;
this->actionFunc = EnFirefly_Die;
}
void EnFirefly_SetupRebound(EnFirefly* this) {
this->actor.world.rot.x = 0x7000;
this->timer = 18;
this->skelAnime.playSpeed = 1.0f;
this->actor.speed = 2.5f;
this->actionFunc = EnFirefly_Rebound;
}
void EnFirefly_SetupDiveAttack(EnFirefly* this) {
this->timer = Rand_S16Offset(70, 100);
this->skelAnime.playSpeed = 1.0f;
this->targetPitch = ((this->actor.yDistToPlayer > 0.0f) ? -0xC00 : 0xC00) + 0x1554;
this->actionFunc = EnFirefly_DiveAttack;
}
void EnFirefly_SetupFlyAway(EnFirefly* this) {
this->timer = 150;
this->skelAnime.playSpeed = 1.0f;
this->targetPitch = 0x954;
this->actionFunc = EnFirefly_FlyAway;
}
void EnFirefly_SetupStunned(EnFirefly* this) {
this->timer = 80;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_BLUE, 255, COLORFILTER_BUFFLAG_OPA, 80);
this->auraType = KEESE_AURA_NONE;
this->actor.velocity.y = 0.0f;
this->skelAnime.playSpeed = 3.0f;
Actor_PlaySfx(&this->actor, NA_SE_EN_GOMA_JR_FREEZE);
this->actionFunc = EnFirefly_Stunned;
}
void EnFirefly_SetupFrozenFall(EnFirefly* this, PlayState* play) {
s32 i;
Vec3f iceParticlePos;
this->actor.flags |= ACTOR_FLAG_UPDATE_CULLING_DISABLED;
this->auraType = KEESE_AURA_NONE;
this->actor.speed = 0.0f;
Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_BLUE, 255, COLORFILTER_BUFFLAG_OPA, 255);
Actor_PlaySfx(&this->actor, NA_SE_EN_FFLY_DEAD);
for (i = 0; i <= 7; i++) {
iceParticlePos.x = (i & 1 ? 7.0f : -7.0f) + this->actor.world.pos.x;
iceParticlePos.y = (i & 2 ? 7.0f : -7.0f) + this->actor.world.pos.y;
iceParticlePos.z = (i & 4 ? 7.0f : -7.0f) + this->actor.world.pos.z;
EffectSsEnIce_SpawnFlyingVec3f(play, &this->actor, &iceParticlePos, 150, 150, 150, 250, 235, 245, 255,
(Rand_ZeroOne() * 0.15f) + 0.85f);
}
this->actionFunc = EnFirefly_FrozenFall;
}
void EnFirefly_SetupPerch(EnFirefly* this) {
this->timer = 1;
this->actor.speed = 0.0f;
this->actionFunc = EnFirefly_Perch;
}
void EnFirefly_SetupDisturbDiveAttack(EnFirefly* this) {
this->skelAnime.playSpeed = 3.0f;
this->actor.shape.rot.x = 0x1554;
this->actor.shape.rot.y = this->actor.yawTowardsPlayer;
this->timer = 50;
this->actor.speed = 3.0f;
this->actionFunc = EnFirefly_DisturbDiveAttack;
}
s32 EnFirefly_ReturnToPerch(EnFirefly* this, PlayState* play) {
Player* player = GET_PLAYER(play);
f32 distFromHome;
if (this->actor.params != KEESE_NORMAL_PERCH) {
return 0;
}
if (Actor_WorldDistXZToPoint(&player->actor, &this->actor.home.pos) > 300.0f) {
distFromHome = Actor_WorldDistXYZToPoint(&this->actor, &this->actor.home.pos);
if (distFromHome < 5.0f) {
EnFirefly_SetupPerch(this);
return 1;
}
distFromHome *= 0.05f;
if (distFromHome < 1.0f) {
this->actor.speed *= distFromHome;
}
Math_ScaledStepToS(&this->actor.shape.rot.y, Actor_WorldYawTowardPoint(&this->actor, &this->actor.home.pos),
0x300);
Math_ScaledStepToS(&this->actor.shape.rot.x,
Actor_WorldPitchTowardPoint(&this->actor, &this->actor.home.pos) + 0x1554, 0x100);
return 1;
}
return 0;
}
s32 EnFirefly_SeekTorch(EnFirefly* this, PlayState* play) {
ObjSyokudai* findTorch;
ObjSyokudai* closestTorch;
f32 torchDist;
f32 currentMinDist;
Vec3f flamePos;
findTorch = (ObjSyokudai*)play->actorCtx.actorLists[ACTORCAT_PROP].head;
closestTorch = NULL;
currentMinDist = 35000.0f;
while (findTorch != NULL) {
if ((findTorch->actor.id == ACTOR_OBJ_SYOKUDAI) && (findTorch->litTimer != 0)) {
torchDist = Actor_WorldDistXYZToActor(&this->actor, &findTorch->actor);
if (torchDist < currentMinDist) {
currentMinDist = torchDist;
closestTorch = findTorch;
}
}
findTorch = (ObjSyokudai*)findTorch->actor.next;
}
if (closestTorch != NULL) {
flamePos.x = closestTorch->actor.world.pos.x;
flamePos.y = closestTorch->actor.world.pos.y + 52.0f + 15.0f;
flamePos.z = closestTorch->actor.world.pos.z;
if (Actor_WorldDistXYZToPoint(&this->actor, &flamePos) < 15.0f) {
EnFirefly_Ignite(this);
return 1;
} else {
Math_ScaledStepToS(&this->actor.shape.rot.y, Actor_WorldYawTowardActor(&this->actor, &closestTorch->actor),
0x300);
Math_ScaledStepToS(&this->actor.shape.rot.x, Actor_WorldPitchTowardPoint(&this->actor, &flamePos) + 0x1554,
0x100);
return 1;
}
}
return 0;
}
void EnFirefly_FlyIdle(EnFirefly* this, PlayState* play) {
s32 skelanimeUpdated;
f32 rand;
SkelAnime_Update(&this->skelAnime);
if (this->timer != 0) {
this->timer--;
}
skelanimeUpdated = Animation_OnFrame(&this->skelAnime, 0.0f);
this->actor.speed = (Rand_ZeroOne() * 1.5f) + 1.5f;
if (this->onFire || (this->actor.params == KEESE_ICE_FLY) ||
((EnFirefly_ReturnToPerch(this, play) == 0) && (EnFirefly_SeekTorch(this, play) == 0))) {
if (skelanimeUpdated) {
rand = Rand_ZeroOne();
if (rand < 0.5f) {
Math_ScaledStepToS(&this->actor.shape.rot.y,
Actor_WorldYawTowardPoint(&this->actor, &this->actor.home.pos), 0x300);
} else if (rand < 0.8f) {
this->actor.shape.rot.y += Rand_CenteredFloat(1536.0f);
}
// Climb if too close to ground
if (this->actor.world.pos.y < (this->actor.floorHeight + 20.0f)) {
this->targetPitch = 0x954;
// Descend if above maxAltitude
} else if (this->maxAltitude < this->actor.world.pos.y) {
this->targetPitch = 0x2154;
// Otherwise ascend or descend at random, biased towards ascending
} else if (0.35f < Rand_ZeroOne()) {
this->targetPitch = 0x954;
} else {
this->targetPitch = 0x2154;
}
} else {
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
this->targetPitch = 0x954;
} else if ((this->actor.bgCheckFlags & BGCHECKFLAG_CEILING) ||
(this->maxAltitude < this->actor.world.pos.y)) {
this->targetPitch = 0x2154;
}
}
Math_ScaledStepToS(&this->actor.shape.rot.x, this->targetPitch, 0x100);
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.wallYaw, 2, 0xC00, 0x300);
}
if ((this->timer == 0) && (this->actor.xzDistToPlayer < 200.0f) && (Player_GetMask(play) != PLAYER_MASK_SKULL)) {
EnFirefly_SetupDiveAttack(this);
}
}
// Fall to the ground after being hit
void EnFirefly_Fall(EnFirefly* this, PlayState* play) {
if (Animation_OnFrame(&this->skelAnime, 6.0f)) {
this->skelAnime.playSpeed = 0.0f;
}
this->actor.colorFilterTimer = 40;
SkelAnime_Update(&this->skelAnime);
Math_StepToF(&this->actor.speed, 0.0f, 0.5f);
if (this->actor.flags & ACTOR_FLAG_ATTACHED_TO_ARROW) {
this->actor.colorFilterTimer = 40;
} else {
Math_ScaledStepToS(&this->actor.shape.rot.x, 0x6800, 0x200);
this->actor.shape.rot.y -= 0x300;
if (this->timer != 0) {
this->timer--;
}
if ((this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) || (this->timer == 0)) {
EnFirefly_SetupDie(this);
}
}
}
// Hit the ground or burn up, spawn drops
void EnFirefly_Die(EnFirefly* this, PlayState* play) {
if (this->timer != 0) {
this->timer--;
}
Math_StepToF(&this->actor.scale.x, 0.0f, 0.00034f);
this->actor.scale.y = this->actor.scale.z = this->actor.scale.x;
if (this->timer == 0) {
Item_DropCollectibleRandom(play, &this->actor, &this->actor.world.pos,
COLLECTIBLE_DROP_RANDOM_PARAMS(COLLECTIBLE_DROP_TABLE_14, false));
Actor_Kill(&this->actor);
}
}
void EnFirefly_DiveAttack(EnFirefly* this, PlayState* play) {
Player* player = GET_PLAYER(play);
Vec3f preyPos;
SkelAnime_Update(&this->skelAnime);
if (this->timer != 0) {
this->timer--;
}
Math_StepToF(&this->actor.speed, 4.0f, 0.5f);
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.wallYaw, 2, 0xC00, 0x300);
Math_ScaledStepToS(&this->actor.shape.rot.x, this->targetPitch, 0x100);
} else if (Actor_IsFacingPlayer(&this->actor, 0x2800)) {
if (Animation_OnFrame(&this->skelAnime, 4.0f)) {
this->skelAnime.playSpeed = 0.0f;
this->skelAnime.curFrame = 4.0f;
}
Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.yawTowardsPlayer, 2, 0xC00, 0x300);
preyPos.x = player->actor.world.pos.x;
preyPos.y = player->actor.world.pos.y + 20.0f;
preyPos.z = player->actor.world.pos.z;
Math_SmoothStepToS(&this->actor.shape.rot.x, Actor_WorldPitchTowardPoint(&this->actor, &preyPos) + 0x1554, 2,
0x400, 0x100);
} else {
this->skelAnime.playSpeed = 1.5f;
if (this->actor.xzDistToPlayer > 80.0f) {
Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.yawTowardsPlayer, 2, 0xC00, 0x300);
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
this->targetPitch = 0x954;
}
if ((this->actor.bgCheckFlags & BGCHECKFLAG_CEILING) || (this->maxAltitude < this->actor.world.pos.y)) {
this->targetPitch = 0x2154;
} else {
this->targetPitch = 0x954;
}
Math_ScaledStepToS(&this->actor.shape.rot.x, this->targetPitch, 0x100);
}
if ((this->timer == 0) || (Player_GetMask(play) == PLAYER_MASK_SKULL)) {
EnFirefly_SetupFlyAway(this);
}
}
// Knockback after hitting player
void EnFirefly_Rebound(EnFirefly* this, PlayState* play) {
SkelAnime_Update(&this->skelAnime);
Math_ScaledStepToS(&this->actor.shape.rot.x, 0, 0x100);
Math_StepToF(&this->actor.velocity.y, 0.0f, 0.4f);
if (Math_StepToF(&this->actor.speed, 0.0f, 0.15f)) {
if (this->timer != 0) {
this->timer--;
}
if (this->timer == 0) {
EnFirefly_SetupFlyAway(this);
}
}
}
void EnFirefly_FlyAway(EnFirefly* this, PlayState* play) {
SkelAnime_Update(&this->skelAnime);
if (this->timer != 0) {
this->timer--;
}
if (((fabsf(this->actor.world.pos.y - this->maxAltitude) < 10.0f) &&
(Math_Vec3f_DistXZ(&this->actor.world.pos, &this->actor.home.pos) < 20.0f)) ||
(this->timer == 0)) {
EnFirefly_SetupFlyIdle(this);
return;
}
Math_StepToF(&this->actor.speed, 3.0f, 0.3f);
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
this->targetPitch = 0x954;
} else if ((this->actor.bgCheckFlags & BGCHECKFLAG_CEILING) || (this->maxAltitude < this->actor.world.pos.y)) {
this->targetPitch = 0x2154;
} else {
this->targetPitch = 0x954;
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.wallYaw, 2, 0xC00, 0x300);
} else {
Math_ScaledStepToS(&this->actor.shape.rot.y, Actor_WorldYawTowardPoint(&this->actor, &this->actor.home.pos),
0x300);
}
Math_ScaledStepToS(&this->actor.shape.rot.x, this->targetPitch, 0x100);
}
void EnFirefly_Stunned(EnFirefly* this, PlayState* play) {
SkelAnime_Update(&this->skelAnime);
Math_StepToF(&this->actor.speed, 0.0f, 0.5f);
Math_ScaledStepToS(&this->actor.shape.rot.x, 0x1554, 0x100);
if (this->timer != 0) {
this->timer--;
}
if (this->timer == 0) {
if (this->onFire) {
this->auraType = KEESE_AURA_FIRE;
} else if (this->actor.params == KEESE_ICE_FLY) {
this->auraType = KEESE_AURA_ICE;
}
EnFirefly_SetupFlyIdle(this);
}
}
void EnFirefly_FrozenFall(EnFirefly* this, PlayState* play) {
#if OOT_VERSION < NTSC_1_1
if ((this->actor.bgCheckFlags & BGCHECKFLAG_GROUND_TOUCH) || (this->actor.floorHeight == BGCHECK_Y_MIN))
#else
if ((this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) || (this->actor.floorHeight == BGCHECK_Y_MIN))
#endif
{
this->actor.colorFilterTimer = 0;
EnFirefly_SetupDie(this);
} else {
this->actor.colorFilterTimer = 255;
}
}
// When perching, sit on collision and flap at random intervals
void EnFirefly_Perch(EnFirefly* this, PlayState* play) {
Math_ScaledStepToS(&this->actor.shape.rot.x, 0, 0x100);
if (this->timer != 0) {
SkelAnime_Update(&this->skelAnime);
if (Animation_OnFrame(&this->skelAnime, 6.0f)) {
this->timer--;
}
} else if (Rand_ZeroOne() < 0.02f) {
this->timer = 1;
}
if (this->actor.xzDistToPlayer < 120.0f) {
EnFirefly_SetupDisturbDiveAttack(this);
}
}
void EnFirefly_DisturbDiveAttack(EnFirefly* this, PlayState* play) {
Player* player = GET_PLAYER(play);
Vec3f preyPos;
SkelAnime_Update(&this->skelAnime);
if (this->timer != 0) {
this->timer--;
}
if (this->timer < 40) {
Math_ScaledStepToS(&this->actor.shape.rot.x, -0xAAC, 0x100);
} else {
preyPos.x = player->actor.world.pos.x;
preyPos.y = player->actor.world.pos.y + 20.0f;
preyPos.z = player->actor.world.pos.z;
Math_ScaledStepToS(&this->actor.shape.rot.x, Actor_WorldPitchTowardPoint(&this->actor, &preyPos) + 0x1554,
0x100);
Math_ScaledStepToS(&this->actor.shape.rot.y, this->actor.yawTowardsPlayer, 0x300);
}
if (this->timer == 0) {
EnFirefly_SetupFlyIdle(this);
}
}
void EnFirefly_Combust(EnFirefly* this, PlayState* play) {
s32 i;
for (i = 0; i <= 2; i++) {
EffectSsEnFire_SpawnVec3f(play, &this->actor, &this->actor.world.pos, 40, 0, 0, i);
}
this->auraType = KEESE_AURA_NONE;
}
void EnFirefly_UpdateDamage(EnFirefly* this, PlayState* play) {
u8 damageReaction;
if (this->collider.base.acFlags & AC_HIT) {
this->collider.base.acFlags &= ~AC_HIT;
Actor_SetDropFlag(&this->actor, &this->collider.elements[0].base, true);
if ((this->actor.colChkInfo.damageReaction != 0) || (this->actor.colChkInfo.damage != 0)) {
if (Actor_ApplyDamage(&this->actor) == 0) {
Enemy_StartFinishingBlow(play, &this->actor);
this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
}
damageReaction = this->actor.colChkInfo.damageReaction;
if (damageReaction == 2) { // Din's Fire
if (this->actor.params == KEESE_ICE_FLY) {
this->actor.colChkInfo.health = 0;
Enemy_StartFinishingBlow(play, &this->actor);
EnFirefly_Combust(this, play);
EnFirefly_SetupFall(this);
} else if (!this->onFire) {
EnFirefly_Ignite(this);
if (this->actionFunc == EnFirefly_Perch) {
EnFirefly_SetupFlyIdle(this);
}
}
} else if (damageReaction == 3) { // Ice Arrows or Ice Magic
if (this->actor.params == KEESE_ICE_FLY) {
EnFirefly_SetupFall(this);
} else {
EnFirefly_SetupFrozenFall(this, play);
}
} else if (damageReaction == 1) { // Deku Nuts
if (this->actionFunc != EnFirefly_Stunned) {
EnFirefly_SetupStunned(this);
}
} else { // Fire Arrows
if ((damageReaction == 0xF) && (this->actor.params == KEESE_ICE_FLY)) {
EnFirefly_Combust(this, play);
}
EnFirefly_SetupFall(this);
}
}
}
}
void EnFirefly_Update(Actor* thisx, PlayState* play2) {
EnFirefly* this = (EnFirefly*)thisx;
PlayState* play = play2;
if (this->collider.base.atFlags & AT_HIT) {
this->collider.base.atFlags &= ~AT_HIT;
Actor_PlaySfx(&this->actor, NA_SE_EN_FFLY_ATTACK);
if (this->onFire) {
EnFirefly_Extinguish(this);
}
if (this->actionFunc != EnFirefly_DisturbDiveAttack) {
EnFirefly_SetupRebound(this);
}
}
EnFirefly_UpdateDamage(this, play);
this->actionFunc(this, play);
if (!(this->actor.flags & ACTOR_FLAG_ATTACHED_TO_ARROW)) {
if ((this->actor.colChkInfo.health == 0) || (this->actionFunc == EnFirefly_Stunned)) {
Actor_MoveXZGravity(&this->actor);
} else {
if (this->actionFunc != EnFirefly_Rebound) {
this->actor.world.rot.x = 0x1554 - this->actor.shape.rot.x;
}
Actor_MoveXYZ(&this->actor);
}
}
Actor_UpdateBgCheckInfo(play, &this->actor, 10.0f, 10.0f, 15.0f,
UPDBGCHECKINFO_FLAG_0 | UPDBGCHECKINFO_FLAG_1 | UPDBGCHECKINFO_FLAG_2);
this->collider.elements[0].dim.worldSphere.center.x = this->actor.world.pos.x;
this->collider.elements[0].dim.worldSphere.center.y = this->actor.world.pos.y + 10.0f;
this->collider.elements[0].dim.worldSphere.center.z = this->actor.world.pos.z;
if ((this->actionFunc == EnFirefly_DiveAttack) || (this->actionFunc == EnFirefly_DisturbDiveAttack)) {
CollisionCheck_SetAT(play, &play->colChkCtx, &this->collider.base);
}
if (this->actor.colChkInfo.health != 0) {
CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base);
this->actor.world.rot.y = this->actor.shape.rot.y;
if (Animation_OnFrame(&this->skelAnime, 5.0f)) {
Actor_PlaySfx(&this->actor, NA_SE_EN_FFLY_FLY);
}
}
CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base);
this->actor.focus.pos.x =
(10.0f * Math_SinS(this->actor.shape.rot.x) * Math_SinS(this->actor.shape.rot.y)) + this->actor.world.pos.x;
this->actor.focus.pos.y = (10.0f * Math_CosS(this->actor.shape.rot.x)) + this->actor.world.pos.y;
this->actor.focus.pos.z =
(10.0f * Math_SinS(this->actor.shape.rot.x) * Math_CosS(this->actor.shape.rot.y)) + this->actor.world.pos.z;
}
s32 EnFirefly_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx,
Gfx** gfx) {
EnFirefly* this = (EnFirefly*)thisx;
if ((this->actor.draw == EnFirefly_DrawInvisible) && !play->actorCtx.lensActive) {
*dList = NULL;
} else if (limbIndex == 1) {
pos->y += 2300.0f;
}
return false;
}
void EnFirefly_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx, Gfx** gfx) {
static Color_RGBA8 fireAuraPrimColor = { 255, 255, 100, 255 };
static Color_RGBA8 fireAuraEnvColor = { 255, 50, 0, 0 };
static Color_RGBA8 iceAuraPrimColor = { 100, 200, 255, 255 };
static Color_RGBA8 iceAuraEnvColor = { 0, 0, 255, 0 };
static Vec3f effVelocity = { 0.0f, 0.5f, 0.0f };
static Vec3f effAccel = { 0.0f, 0.5f, 0.0f };
static Vec3f limbSrc = { 0.0f, 0.0f, 0.0f };
Vec3f effPos;
Vec3f* limbDest;
Color_RGBA8* effPrimColor;
Color_RGBA8* effEnvColor;
MtxF mtx;
s16 effScaleStep;
s16 effLife;
EnFirefly* this = (EnFirefly*)thisx;
if (!this->onFire && (limbIndex == 27)) {
gSPDisplayList((*gfx)++, gKeeseEyesDL);
} else {
if ((this->auraType == KEESE_AURA_FIRE) || (this->auraType == KEESE_AURA_ICE)) {
if ((limbIndex == 15) || (limbIndex == 21)) {
if (this->actionFunc != EnFirefly_Die) {
Matrix_Get(&mtx);
effPos.x = (Rand_ZeroOne() * 5.0f) + mtx.xw;
effPos.y = (Rand_ZeroOne() * 5.0f) + mtx.yw;
effPos.z = (Rand_ZeroOne() * 5.0f) + mtx.zw;
effScaleStep = -40;
effLife = 3;
} else {
if (limbIndex == 15) {
effPos.x = (Math_SinS(9100 * this->timer) * this->timer) + this->actor.world.pos.x;
effPos.z = (Math_CosS(9100 * this->timer) * this->timer) + this->actor.world.pos.z;
} else {
effPos.x = this->actor.world.pos.x - (Math_SinS(9100 * this->timer) * this->timer);
effPos.z = this->actor.world.pos.z - (Math_CosS(9100 * this->timer) * this->timer);
}
effPos.y = this->actor.world.pos.y + ((15 - this->timer) * 1.5f);
effScaleStep = -5;
effLife = 10;
}
if (this->auraType == KEESE_AURA_FIRE) {
effPrimColor = &fireAuraPrimColor;
effEnvColor = &fireAuraEnvColor;
} else {
effPrimColor = &iceAuraPrimColor;
effEnvColor = &iceAuraEnvColor;
}
func_8002843C(play, &effPos, &effVelocity, &effAccel, effPrimColor, effEnvColor, 250, effScaleStep,
effLife);
}
}
}
if ((limbIndex == 15) || (limbIndex == 21) || (limbIndex == 10)) {
if (limbIndex == 15) {
limbDest = &this->bodyPartsPos[0];
} else if (limbIndex == 21) {
limbDest = &this->bodyPartsPos[1];
} else {
limbDest = &this->bodyPartsPos[2];
}
Matrix_MultVec3f(&limbSrc, limbDest);
limbDest->y -= 5.0f;
}
}
void EnFirefly_Draw(Actor* thisx, PlayState* play) {
EnFirefly* this = (EnFirefly*)thisx;
OPEN_DISPS(play->state.gfxCtx, "../z_en_firefly.c", 1733);
Gfx_SetupDL_25Opa(play->state.gfxCtx);
if (this->onFire) {
gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0);
} else {
gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255);
}
POLY_OPA_DISP = SkelAnime_Draw(play, this->skelAnime.skeleton, this->skelAnime.jointTable,
EnFirefly_OverrideLimbDraw, EnFirefly_PostLimbDraw, &this->actor, POLY_OPA_DISP);
CLOSE_DISPS(play->state.gfxCtx, "../z_en_firefly.c", 1763);
}
void EnFirefly_DrawInvisible(Actor* thisx, PlayState* play) {
EnFirefly* this = (EnFirefly*)thisx;
OPEN_DISPS(play->state.gfxCtx, "../z_en_firefly.c", 1775);
Gfx_SetupDL_25Xlu(play->state.gfxCtx);
if (this->onFire) {
gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 0);
} else {
gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 255);
}
POLY_XLU_DISP = SkelAnime_Draw(play, this->skelAnime.skeleton, this->skelAnime.jointTable,
EnFirefly_OverrideLimbDraw, EnFirefly_PostLimbDraw, this, POLY_XLU_DISP);
CLOSE_DISPS(play->state.gfxCtx, "../z_en_firefly.c", 1805);
}
|