summaryrefslogtreecommitdiff
path: root/src/overlays/actors/ovl_En_Mb/z_en_mb.c
blob: bc06afc2b20a5a5ca27b0d1743f6d86bde44334d (plain)
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
/*
 * File: z_en_mb.c
 * Overlay: ovl_En_Mb
 * Description: Moblins
 */

#include "z_en_mb.h"

#include "libc64/qrand.h"
#include "array_count.h"
#include "gfx.h"
#include "gfx_setupdl.h"
#include "ichain.h"
#include "rand.h"
#include "rumble.h"
#include "segmented_address.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_mb/object_mb.h"

/*
 * This actor can have three behaviors:
 * - "Spear Guard" (variable -1): uses a spear, walks around home point, charges player if too close
 * - "Club" (variable 0): uses a club, stands still and smashes its club on the ground when the player approaches
 * - "Spear Patrol" (variable 0xPP00 PP=pathId): uses a spear, patrols following a path, charges
 */

#define FLAGS (ACTOR_FLAG_ATTENTION_ENABLED | ACTOR_FLAG_HOSTILE | ACTOR_FLAG_UPDATE_CULLING_DISABLED)

typedef enum EnMbType {
    /* -1 */ ENMB_TYPE_SPEAR_GUARD = -1,
    /*  0 */ ENMB_TYPE_CLUB,
    /*  1 */ ENMB_TYPE_SPEAR_PATROL
} EnMbType;

#define ENMB_ATTACK_NONE 0
#define ENMB_ATTACK_SPEAR 1
#define ENMB_ATTACK_CLUB_RIGHT 1
#define ENMB_ATTACK_CLUB_MIDDLE 2
#define ENMB_ATTACK_CLUB_LEFT 3

/* Spear and Club moblins use a different skeleton but the limbs are organized the same */
typedef enum EnMbLimb {
    /*  1 */ ENMB_LIMB_ROOT = 1,
    /*  3 */ ENMB_LIMB_WAIST = 3,
    /*  6 */ ENMB_LIMB_CHEST = 6,
    /*  7 */ ENMB_LIMB_HEAD,
    /*  9 */ ENMB_LIMB_LSHOULDER = 9,
    /* 11 */ ENMB_LIMB_LFOREARM = 11,
    /* 12 */ ENMB_LIMB_LHAND,
    /* 14 */ ENMB_LIMB_RSHOULDER = 14,
    /* 16 */ ENMB_LIMB_RFOREARM = 16,
    /* 17 */ ENMB_LIMB_RHAND,
    /* 20 */ ENMB_LIMB_LTHIGH = 20,
    /* 21 */ ENMB_LIMB_LSHIN,
    /* 22 */ ENMB_LIMB_LFOOT,
    /* 25 */ ENMB_LIMB_RTHIGH = 25,
    /* 26 */ ENMB_LIMB_RSHIN,
    /* 27 */ ENMB_LIMB_RFOOT
} EnMbLimb;

void EnMb_Init(Actor* thisx, PlayState* play);
void EnMb_Destroy(Actor* thisx, PlayState* play);
void EnMb_Update(Actor* thisx, PlayState* play);
void EnMb_Draw(Actor* thisx, PlayState* play);

ActorProfile En_Mb_Profile = {
    /**/ ACTOR_EN_MB,
    /**/ ACTORCAT_ENEMY,
    /**/ FLAGS,
    /**/ OBJECT_MB,
    /**/ sizeof(EnMb),
    /**/ EnMb_Init,
    /**/ EnMb_Destroy,
    /**/ EnMb_Update,
    /**/ EnMb_Draw,
};

void EnMb_SetupSpearPatrolTurnTowardsWaypoint(EnMb* this, PlayState* play);
void EnMb_SetupClubWaitPlayerNear(EnMb* this);
void EnMb_SpearGuardLookAround(EnMb* this, PlayState* play);
void EnMb_SetupSpearGuardLookAround(EnMb* this);
void EnMb_SetupSpearDamaged(EnMb* this);
void EnMb_SpearGuardWalk(EnMb* this, PlayState* play);
void EnMb_SpearGuardPrepareAndCharge(EnMb* this, PlayState* play);
void EnMb_SpearPatrolPrepareAndCharge(EnMb* this, PlayState* play);
void EnMb_SpearEndChargeQuick(EnMb* this, PlayState* play);
void EnMb_Stunned(EnMb* this, PlayState* play);
void EnMb_ClubDead(EnMb* this, PlayState* play);
void EnMb_ClubDamagedWhileKneeling(EnMb* this, PlayState* play);
void EnMb_ClubWaitPlayerNear(EnMb* this, PlayState* play);
void EnMb_ClubAttack(EnMb* this, PlayState* play);
void EnMb_SpearDead(EnMb* this, PlayState* play);
void EnMb_SpearDamaged(EnMb* this, PlayState* play);
void EnMb_SetupSpearDead(EnMb* this);
void EnMb_SpearPatrolTurnTowardsWaypoint(EnMb* this, PlayState* play);
void EnMb_SpearPatrolWalkTowardsWaypoint(EnMb* this, PlayState* play);
void EnMb_SpearPatrolEndCharge(EnMb* this, PlayState* play);
void EnMb_SpearPatrolImmediateCharge(EnMb* this, PlayState* play);
void EnMb_ClubWaitAfterAttack(EnMb* this, PlayState* play);
void EnMb_ClubDamaged(EnMb* this, PlayState* play);

static ColliderCylinderInit sBodyColliderInit = {
    {
        COL_MATERIAL_HIT0,
        AT_NONE,
        AC_ON | AC_TYPE_PLAYER,
        OC1_ON | OC1_TYPE_ALL,
        OC2_TYPE_2,
        COLSHAPE_CYLINDER,
    },
    {
        ELEM_MATERIAL_UNK1,
        { 0x00000000, HIT_SPECIAL_EFFECT_NONE, 0x00 },
        { 0xFFCFFFFF, HIT_BACKLASH_NONE, 0x00 },
        ATELEM_NONE,
        ACELEM_ON,
        OCELEM_ON,
    },
    { 20, 70, 0, { 0, 0, 0 } },
};

static ColliderTrisElementInit sFrontShieldingTrisElementsInit[] = {
    {
        {
            ELEM_MATERIAL_UNK2,
            { 0x00000000, HIT_SPECIAL_EFFECT_NONE, 0x00 },
            { 0xFFCFFFFF, HIT_BACKLASH_NONE, 0x00 },
            ATELEM_NONE,
            ACELEM_ON | ACELEM_HOOKABLE | ACELEM_NO_AT_INFO,
            OCELEM_NONE,
        },
        { { { -10.0f, 14.0f, 2.0f }, { -10.0f, -6.0f, 2.0f }, { 9.0f, 14.0f, 2.0f } } },
    },
    {
        {
            ELEM_MATERIAL_UNK2,
            { 0x00000000, HIT_SPECIAL_EFFECT_NONE, 0x00 },
            { 0xFFCFFFFF, HIT_BACKLASH_NONE, 0x00 },
            ATELEM_NONE,
            ACELEM_ON | ACELEM_HOOKABLE | ACELEM_NO_AT_INFO,
            OCELEM_NONE,
        },
        { { { -10.0f, -6.0f, 2.0f }, { 9.0f, -6.0f, 2.0f }, { 9.0f, 14.0f, 2.0f } } },
    },
};

static ColliderTrisInit sFrontShieldingTrisInit = {
    {
        COL_MATERIAL_METAL,
        AT_NONE,
        AC_ON | AC_HARD | AC_TYPE_PLAYER,
        OC1_NONE,
        OC2_NONE,
        COLSHAPE_TRIS,
    },
    ARRAY_COUNT(sFrontShieldingTrisElementsInit),
    sFrontShieldingTrisElementsInit,
};

static ColliderQuadInit sAttackColliderQuadInit = {
    {
        COL_MATERIAL_NONE,
        AT_ON | AT_TYPE_ENEMY,
        AC_NONE,
        OC1_NONE,
        OC2_NONE,
        COLSHAPE_QUAD,
    },
    {
        ELEM_MATERIAL_UNK0,
        { 0xFFCFFFFF, HIT_SPECIAL_EFFECT_NONE, 0x08 },
        { 0x00000000, HIT_BACKLASH_NONE, 0x00 },
        ATELEM_ON | ATELEM_SFX_NORMAL,
        ACELEM_NONE,
        OCELEM_NONE,
    },
    { { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } } },
};

typedef enum EnMbDamageReaction {
    /* 0x0 */ ENMB_DMG_REACT_IGNORE,
    /* 0x1 */ ENMB_DMG_REACT_STUN,
    /* 0x5 */ ENMB_DMG_REACT_FREEZE = 0x5,
    /* 0x6 */ ENMB_DMG_REACT_STUN_ICE,
    /* 0xF */ ENMB_DMG_REACT_DEFAULT = 0xF
} EnMbDamageReaction;

static DamageTable sSpearMoblinDamageTable = {
    /* Deku nut      */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Deku stick    */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Slingshot     */ DMG_ENTRY(1, ENMB_DMG_REACT_DEFAULT),
    /* Explosive     */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Boomerang     */ DMG_ENTRY(0, ENMB_DMG_REACT_STUN),
    /* Normal arrow  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Hammer swing  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Hookshot      */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Kokiri sword  */ DMG_ENTRY(1, ENMB_DMG_REACT_DEFAULT),
    /* Master sword  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Giant's Knife */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Fire arrow    */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Ice arrow     */ DMG_ENTRY(4, ENMB_DMG_REACT_STUN_ICE),
    /* Light arrow   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 1   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 2   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 3   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Fire magic    */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Ice magic     */ DMG_ENTRY(3, ENMB_DMG_REACT_STUN_ICE),
    /* Light magic   */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Shield        */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Mirror Ray    */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Kokiri spin   */ DMG_ENTRY(1, ENMB_DMG_REACT_DEFAULT),
    /* Giant spin    */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Master spin   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Kokiri jump   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Giant jump    */ DMG_ENTRY(8, ENMB_DMG_REACT_DEFAULT),
    /* Master jump   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unknown 1     */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Unblockable   */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Hammer jump   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unknown 2     */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
};

static DamageTable sClubMoblinDamageTable = {
    /* Deku nut      */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Deku stick    */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Slingshot     */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Explosive     */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Boomerang     */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Normal arrow  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Hammer swing  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Hookshot      */ DMG_ENTRY(0, ENMB_DMG_REACT_STUN),
    /* Kokiri sword  */ DMG_ENTRY(1, ENMB_DMG_REACT_DEFAULT),
    /* Master sword  */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Giant's Knife */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Fire arrow    */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Ice arrow     */ DMG_ENTRY(4, ENMB_DMG_REACT_STUN_ICE),
    /* Light arrow   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 1   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 2   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Unk arrow 3   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Fire magic    */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Ice magic     */ DMG_ENTRY(3, ENMB_DMG_REACT_STUN_ICE),
    /* Light magic   */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Shield        */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Mirror Ray    */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Kokiri spin   */ DMG_ENTRY(1, ENMB_DMG_REACT_DEFAULT),
    /* Giant spin    */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Master spin   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Kokiri jump   */ DMG_ENTRY(2, ENMB_DMG_REACT_DEFAULT),
    /* Giant jump    */ DMG_ENTRY(8, ENMB_DMG_REACT_DEFAULT),
    /* Master jump   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unknown 1     */ DMG_ENTRY(0, ENMB_DMG_REACT_FREEZE),
    /* Unblockable   */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
    /* Hammer jump   */ DMG_ENTRY(4, ENMB_DMG_REACT_DEFAULT),
    /* Unknown 2     */ DMG_ENTRY(0, ENMB_DMG_REACT_IGNORE),
};

static InitChainEntry sInitChain[] = {
    ICHAIN_S8(naviEnemyId, NAVI_ENEMY_MOBLIN, ICHAIN_CONTINUE),
    ICHAIN_F32_DIV1000(gravity, -1000, ICHAIN_CONTINUE),
    ICHAIN_F32(lockOnArrowOffset, 5300, ICHAIN_STOP),
};

void EnMb_SetupAction(EnMb* this, EnMbActionFunc actionFunc) {
    this->actionFunc = actionFunc;
}

void EnMb_Init(Actor* thisx, PlayState* play) {
    EnMb* this = (EnMb*)thisx;
    s32 pad;
    Player* player = GET_PLAYER(play);
    s16 relYawFromPlayer;

    Actor_ProcessInitChain(&this->actor, sInitChain);
    ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 46.0f);
    this->actor.colChkInfo.mass = MASS_IMMOVABLE;
    this->actor.colChkInfo.damageTable = &sSpearMoblinDamageTable;
    Collider_InitCylinder(play, &this->bodyCollider);
    Collider_SetCylinder(play, &this->bodyCollider, &this->actor, &sBodyColliderInit);
    Collider_InitTris(play, &this->frontShieldingCollider);
    Collider_SetTris(play, &this->frontShieldingCollider, &this->actor, &sFrontShieldingTrisInit,
                     this->frontShieldingColliderElements);
    Collider_InitQuad(play, &this->attackCollider);
    Collider_SetQuad(play, &this->attackCollider, &this->actor, &sAttackColliderQuadInit);

    switch (this->actor.params) {
        case ENMB_TYPE_SPEAR_GUARD:
            SkelAnime_InitFlex(play, &this->skelAnime, &gEnMbSpearSkel, &gEnMbSpearStandStillAnim, this->jointTable,
                               this->morphTable, 28);
            this->actor.colChkInfo.health = 2;
            this->actor.colChkInfo.mass = MASS_HEAVY;
            this->maxHomeDist = 1000.0f;
            this->playerDetectionRange = 1750.0f;
            EnMb_SetupSpearGuardLookAround(this);
            break;
        case ENMB_TYPE_CLUB:
            SkelAnime_InitFlex(play, &this->skelAnime, &gEnMbClubSkel, &gEnMbClubStandStillClubDownAnim,
                               this->jointTable, this->morphTable, 28);

            this->actor.colChkInfo.health = 6;
            this->actor.colChkInfo.mass = MASS_IMMOVABLE;
            this->actor.colChkInfo.damageTable = &sClubMoblinDamageTable;
            Actor_SetScale(&this->actor, 0.02f);
            this->bodyCollider.dim.height = 170;
            this->bodyCollider.dim.radius = 45;
            this->actor.cullingVolumeDistance = 4000.0f;
            this->actor.cullingVolumeScale = 800.0f;
            this->actor.cullingVolumeDownward = 1800.0f;
            this->playerDetectionRange = 710.0f;
            this->attackCollider.elem.atDmgInfo.dmgFlags = DMG_UNBLOCKABLE;

            relYawFromPlayer =
                this->actor.world.rot.y - Math_Vec3f_Yaw(&this->actor.world.pos, &player->actor.world.pos);
            if (ABS(relYawFromPlayer) > 0x4000) {
                this->actor.world.rot.y = thisx->world.rot.y + 0x8000;
                this->actor.shape.rot.y = thisx->world.rot.y;
                this->actor.world.pos.z = thisx->world.pos.z + 600.0f;
            }

            ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawFeet, 90.0f);
            this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
            this->actor.naviEnemyId += NAVI_ENEMY_MOBLIN_CLUB - NAVI_ENEMY_MOBLIN;
            EnMb_SetupClubWaitPlayerNear(this);
            break;
        default: /* Spear Patrol */
            SkelAnime_InitFlex(play, &this->skelAnime, &gEnMbSpearSkel, &gEnMbSpearStandStillAnim, this->jointTable,
                               this->morphTable, 28);

            Actor_SetScale(&this->actor, 0.014f);
            this->path = PARAMS_GET_S(thisx->params, 8, 8);
            this->actor.params = ENMB_TYPE_SPEAR_PATROL;
            this->waypoint = 0;
            this->actor.colChkInfo.health = 1;
            this->actor.colChkInfo.mass = MASS_HEAVY;
            this->maxHomeDist = 350.0f;
            this->playerDetectionRange = 1750.0f;
            this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
            EnMb_SetupSpearPatrolTurnTowardsWaypoint(this, play);
            break;
    }
}

void EnMb_Destroy(Actor* thisx, PlayState* play) {
    EnMb* this = (EnMb*)thisx;

    Collider_DestroyTris(play, &this->frontShieldingCollider);
    Collider_DestroyCylinder(play, &this->bodyCollider);
    Collider_DestroyQuad(play, &this->attackCollider);
}

void EnMb_FaceWaypoint(EnMb* this, PlayState* play) {
    s16 yawToWaypoint = Math_Vec3f_Yaw(&this->actor.world.pos, &this->waypointPos);

    this->actor.shape.rot.y = yawToWaypoint;
    this->actor.world.rot.y = yawToWaypoint;
}

void EnMb_NextWaypoint(EnMb* this, PlayState* play) {
    Path* path;
    Vec3s* waypointPos;

    path = &play->pathList[this->path];

    if (this->waypoint == 0) {
        this->direction = 1;
    } else if (this->waypoint == (s8)(path->count - 1)) {
        this->direction = -1;
    }

    this->waypoint += this->direction;
    waypointPos = (Vec3s*)SEGMENTED_TO_VIRTUAL(path->points) + this->waypoint;
    this->waypointPos.x = waypointPos->x;
    this->waypointPos.y = waypointPos->y;
    this->waypointPos.z = waypointPos->z;
}

/**
 * Checks if the player is in a 800*74 units XZ area centered on this actor,
 * the area being directed along its line of sight snapped to a cardinal angle.
 * Note: the longest corridor in Sacred Forest Meadows is 800 units long,
 *       and they all are 100 units wide.
 */
s32 EnMb_IsPlayerInCorridor(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);
    f32 xFromPlayer;
    f32 zFromPlayer;
    f32 cos;
    f32 sin;
    f32 xFromPlayerAbs;
    f32 zFromPlayerAbs;
    s16 alignedYaw = 0;

    if ((this->actor.world.rot.y < -0x62A2) || (this->actor.world.rot.y > 0x62A2)) {
        alignedYaw = -0x8000;
    } else if (this->actor.world.rot.y < -0x20E0) {
        alignedYaw = -0x4000;
    } else if (this->actor.world.rot.y > 0x20E0) {
        alignedYaw = 0x4000;
    }

    cos = Math_CosS(alignedYaw);
    sin = Math_SinS(alignedYaw);
    cos = ABS(cos);
    sin = ABS(sin);
    xFromPlayer = this->actor.world.pos.x - player->actor.world.pos.x;
    zFromPlayer = this->actor.world.pos.z - player->actor.world.pos.z;
    xFromPlayerAbs = ABS(xFromPlayer);
    if (xFromPlayerAbs < (cos * 37.0f + sin * 400.0f)) {
        zFromPlayerAbs = ABS(zFromPlayer);
        if (zFromPlayerAbs < (sin * 37.0f + cos * 400.0f)) {
            return true;
        }
    }
    return false;
}

void EnMb_FindWaypointTowardsPlayer(EnMb* this, PlayState* play) {
    Path* path = &play->pathList[this->path];
    s16 yawToWaypoint;
    Vec3f waypointPosF;
    Vec3s* waypointPosS;
    s16 yawPlayerToWaypoint;
    s32 i;
    s32 waypoint;

    for (waypoint = 0, i = path->count - 1; i >= 0; i--, waypoint++) {
        waypointPosS = (Vec3s*)SEGMENTED_TO_VIRTUAL(path->points) + waypoint;
        waypointPosF.x = waypointPosS->x;
        waypointPosF.y = waypointPosS->y;
        waypointPosF.z = waypointPosS->z;
        yawToWaypoint = Math_Vec3f_Yaw(&this->actor.world.pos, &waypointPosF);
        yawPlayerToWaypoint = yawToWaypoint - this->actor.yawTowardsPlayer;
        if (ABS(yawPlayerToWaypoint) <= 0x1770) {
            this->actor.world.rot.y = yawToWaypoint;
            if (waypoint == this->waypoint) {
                this->direction = -this->direction;
            }
            this->waypointPos = waypointPosF;
            this->waypoint = waypoint;
            break;
        }
    }
}

void EnMb_SetupSpearGuardLookAround(EnMb* this) {
    Animation_MorphToLoop(&this->skelAnime, &gEnMbSpearLookLeftAndRightAnim, -4.0f);
    this->actor.speed = 0.0f;
    this->timer1 = Rand_S16Offset(30, 50);
    this->state = ENMB_STATE_IDLE;
    EnMb_SetupAction(this, EnMb_SpearGuardLookAround);
}

void EnMb_SetupClubWaitPlayerNear(EnMb* this) {
    Animation_PlayLoop(&this->skelAnime, &gEnMbClubStandStillClubDownAnim);
    this->actor.speed = 0.0f;
    this->timer1 = Rand_S16Offset(30, 50);
    this->state = ENMB_STATE_IDLE;
    EnMb_SetupAction(this, EnMb_ClubWaitPlayerNear);
}

void EnMb_SetupSpearPatrolTurnTowardsWaypoint(EnMb* this, PlayState* play) {
    Animation_MorphToLoop(&this->skelAnime, &gEnMbSpearLookLeftAndRightAnim, -4.0f);
    this->actor.speed = 0.0f;
    this->timer1 = Rand_S16Offset(40, 80);
    this->state = ENMB_STATE_IDLE;
    EnMb_NextWaypoint(this, play);
    EnMb_SetupAction(this, EnMb_SpearPatrolTurnTowardsWaypoint);
}

void EnMb_SetupSpearGuardWalk(EnMb* this) {
    Animation_Change(&this->skelAnime, &gEnMbSpearWalkAnim, 0.0f, 0.0f, Animation_GetLastFrame(&gEnMbSpearWalkAnim),
                     ANIMMODE_LOOP, -4.0f);
    this->actor.speed = 0.59999996f;
    this->timer1 = Rand_S16Offset(50, 70);
    this->unk_332 = 1;
    this->state = ENMB_STATE_WALK;
    EnMb_SetupAction(this, EnMb_SpearGuardWalk);
}

void EnMb_SetupSpearPatrolWalkTowardsWaypoint(EnMb* this) {
    f32 frameCount = Animation_GetLastFrame(&gEnMbSpearWalkAnim);

    this->actor.speed = 0.59999996f;
    this->timer1 = Rand_S16Offset(50, 70);
    this->unk_332 = 1;
    this->state = ENMB_STATE_WALK;
    Animation_Change(&this->skelAnime, &gEnMbSpearWalkAnim, 0.0f, 0.0f, frameCount, ANIMMODE_LOOP_INTERP, -4.0f);
    EnMb_SetupAction(this, EnMb_SpearPatrolWalkTowardsWaypoint);
}

void EnMb_SetupSpearPrepareAndCharge(EnMb* this) {
    f32 frameCount = Animation_GetLastFrame(&gEnMbSpearPrepareChargeAnim);

    Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbSpearPrepareChargeAnim, -4.0f);
    this->state = ENMB_STATE_ATTACK;
    this->actor.speed = 0.0f;
    this->timer3 = (s16)frameCount + 6;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_SPEAR_AT);
    if (this->actor.params == ENMB_TYPE_SPEAR_GUARD) {
        EnMb_SetupAction(this, EnMb_SpearGuardPrepareAndCharge);
    } else {
        EnMb_SetupAction(this, EnMb_SpearPatrolPrepareAndCharge);
    }
}

void EnMb_SetupSpearPatrolImmediateCharge(EnMb* this) {
    Animation_PlayLoop(&this->skelAnime, &gEnMbSpearChargeAnim);
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_ATTACK);
    this->attack = ENMB_ATTACK_SPEAR;
    this->state = ENMB_STATE_ATTACK;
    this->timer3 = 3;
    this->actor.speed = 10.0f;
    EnMb_SetupAction(this, EnMb_SpearPatrolImmediateCharge);
}

void EnMb_SetupClubAttack(EnMb* this) {
    f32 frames = Animation_GetLastFrame(&gEnMbClubLiftClubAnim);
    s16 relYawFromPlayer;

    this->state = ENMB_STATE_ATTACK;
    Animation_Change(&this->skelAnime, &gEnMbClubLiftClubAnim, 3.0f, 0.0f, frames, ANIMMODE_ONCE_INTERP, 0.0f);
    this->timer3 = 1;
    relYawFromPlayer = this->actor.world.rot.y - this->actor.yawTowardsPlayer;

    if (ABS(relYawFromPlayer) <= 0x258) {
        this->attack = ENMB_ATTACK_CLUB_MIDDLE;
    } else if (relYawFromPlayer >= 0) {
        this->attack = ENMB_ATTACK_CLUB_RIGHT;
    } else {
        this->attack = ENMB_ATTACK_CLUB_LEFT;
    }

    EnMb_SetupAction(this, EnMb_ClubAttack);
}

void EnMb_SetupSpearEndChargeQuick(EnMb* this) {
    Animation_PlayOnce(&this->skelAnime, &gEnMbSpearSlowDownAnim);
    this->state = ENMB_STATE_ATTACK_END;
    this->timer1 = 0;
    this->timer3 = 5;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_SLIDE);
    EnMb_SetupAction(this, EnMb_SpearEndChargeQuick);
}

void EnMb_SetupSpearPatrolEndCharge(EnMb* this) {
    Animation_PlayOnce(&this->skelAnime, &gEnMbSpearSlowDownAnim);
    this->state = ENMB_STATE_ATTACK_END;
    this->actor.bgCheckFlags &= ~BGCHECKFLAG_GROUND;
    this->timer1 = 0;
    this->timer3 = 50;
    this->actor.speed = -8.0f;
    this->actor.velocity.y = 6.0f;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_SLIDE);
    EnMb_SetupAction(this, EnMb_SpearPatrolEndCharge);
}

void EnMb_SetupClubWaitAfterAttack(EnMb* this) {
    f32 frameCount = Animation_GetLastFrame(&gEnMbClubStandStillClubDownAnim);

    this->state = ENMB_STATE_ATTACK_END;
    Animation_Change(&this->skelAnime, &gEnMbClubStandStillClubDownAnim, 5.0f, 0.0f, frameCount, ANIMMODE_ONCE_INTERP,
                     0.0f);
    EnMb_SetupAction(this, EnMb_ClubWaitAfterAttack);
}

void EnMb_SetupClubDamaged(EnMb* this) {
    Animation_PlayOnce(&this->skelAnime, &gEnMbClubDamagedKneelAnim);
    this->state = ENMB_STATE_CLUB_KNEELING;
    this->timer1 = 0;
    this->timer3 = 20;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DEAD);
    EnMb_SetupAction(this, EnMb_ClubDamaged);
}

void EnMb_SetupClubDamagedWhileKneeling(EnMb* this) {
    f32 frames = Animation_GetLastFrame(&gEnMbClubBeatenKneelingAnim);

    this->state = ENMB_STATE_CLUB_KNEELING_DAMAGED;
    this->timer1 = 0;
    this->timer3 = 6;
    Animation_Change(&this->skelAnime, &gEnMbClubBeatenKneelingAnim, 1.0f, 4.0f, frames, ANIMMODE_ONCE_INTERP, 0.0f);
    EnMb_SetupAction(this, EnMb_ClubDamagedWhileKneeling);
}

void EnMb_SetupClubDead(EnMb* this) {
    Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbClubFallOnItsBackAnim, -4.0f);
    this->state = ENMB_STATE_CLUB_DEAD;
    this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
    this->bodyCollider.dim.height = 80;
    this->bodyCollider.dim.radius = 95;
    this->timer1 = 30;
    this->actor.speed = 0.0f;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DEAD);
    EnMb_SetupAction(this, EnMb_ClubDead);
}

void EnMb_SetupStunned(EnMb* this) {
    this->state = ENMB_STATE_STUNNED;
    this->actor.speed = 0.0f;
    Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_BLUE, 120, COLORFILTER_BUFFLAG_OPA, 80);
    if (this->damageReaction == ENMB_DMG_REACT_STUN_ICE) {
        this->iceEffectTimer = 40;
    } else {
        if (this->actor.params != ENMB_TYPE_CLUB) {
            Animation_PlayOnceSetSpeed(&this->skelAnime, &gEnMbSpearDamagedFromFrontAnim, 0.0f);
        }
        Actor_PlaySfx(&this->actor, NA_SE_EN_GOMA_JR_FREEZE);
    }
    EnMb_SetupAction(this, EnMb_Stunned);
}

void EnMb_Stunned(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);

    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->stateFlags2 &= ~PLAYER_STATE2_7;
        player->actor.parent = NULL;
#if OOT_VERSION >= PAL_1_0
        player->av2.actionVar2 = 200;
#endif
        Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
        this->attack = ENMB_ATTACK_NONE;
    }

    if (this->actor.colorFilterTimer == 0) {
        if (this->actor.params == ENMB_TYPE_CLUB) {
            if (this->actor.colChkInfo.health == 0) {
                EnMb_SetupClubDead(this);
            } else if (this->state == ENMB_STATE_CLUB_KNEELING) {
                /* dead code: the setup for this action sets state to something else */
                EnMb_SetupClubDamagedWhileKneeling(this);
            } else {
                EnMb_SetupClubWaitPlayerNear(this);
            }
        } else {
            if (this->actor.colChkInfo.health == 0) {
                EnMb_SetupSpearDead(this);
            } else {
                EnMb_SetupSpearDamaged(this);
            }
        }
    }
}

void EnMb_SpearGuardLookAround(EnMb* this, PlayState* play) {
    s16 timer1;

    SkelAnime_Update(&this->skelAnime);
    if (this->timer1 == 0) {
        timer1 = 0;
    } else {
        this->timer1--;
        timer1 = this->timer1;
    }
    if (timer1 == 0 && Animation_OnFrame(&this->skelAnime, 0.0f)) {
        EnMb_SetupSpearGuardWalk(this);
    }
}

void EnMb_SpearPatrolTurnTowardsWaypoint(EnMb* this, PlayState* play) {
    s16 relYawFromPlayer;

    SkelAnime_Update(&this->skelAnime);

    if (this->timer1 == 0) {
        this->yawToWaypoint = Math_Vec3f_Yaw(&this->actor.world.pos, &this->waypointPos);
        if (Math_SmoothStepToS(&this->actor.shape.rot.y, this->yawToWaypoint, 1, 0x3E8, 0) == 0) {
            this->actor.world.rot.y = this->actor.shape.rot.y;
            EnMb_SetupSpearPatrolWalkTowardsWaypoint(this);
        }
    } else {
        this->timer1--;
        Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.home.rot.y, 1, 0x3E8, 0);
    }

    if (ABS(this->actor.yDistToPlayer) <= 20.0f && EnMb_IsPlayerInCorridor(this, play)) {
        relYawFromPlayer = this->actor.shape.rot.y - this->actor.yawTowardsPlayer;
        if (ABS(relYawFromPlayer) <= 0x4000 || (func_8002DDE4(play) && this->actor.xzDistToPlayer < 160.0f)) {
            EnMb_FindWaypointTowardsPlayer(this, play);
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_VOICE);
            EnMb_SetupSpearPrepareAndCharge(this);
        }
    }
}

/**
 * Slow down and resume walking.
 */
void EnMb_SpearEndChargeQuick(EnMb* this, PlayState* play) {
    s32 pad;

    Math_SmoothStepToF(&this->actor.speed, 0.0f, 0.5f, 1.0f, 0.0f);
    if (this->actor.speed > 1.0f) {
        Actor_SpawnFloorDustRing(play, &this->actor, &this->actor.world.pos, 5.0f, 3, 4.0f, 100, 15, false);
    }
    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer1 == 0) {
            this->timer3--;
            if (this->timer3 == 0) {
                /* Play the charge animation in reverse: let go of the spear and stand normally */
                Animation_Change(&this->skelAnime, &gEnMbSpearPrepareChargeAnim, -1.0f,
                                 Animation_GetLastFrame(&gEnMbSpearPrepareChargeAnim), 0.0f, ANIMMODE_ONCE, 0.0f);
                this->timer1 = 1;
                this->actor.speed = 0.0f;
                Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_SPEAR_NORM);
            }
        } else {
            if (this->actor.params <= ENMB_TYPE_SPEAR_GUARD) {
                EnMb_SetupSpearGuardWalk(this);
                this->timer1 = this->timer2 = this->timer3 = 80;
            } else {
                EnMb_SetupSpearPatrolTurnTowardsWaypoint(this, play);
            }
        }
    }
}

void EnMb_ClubWaitAfterAttack(EnMb* this, PlayState* play) {
    this->attack = ENMB_ATTACK_NONE;
    if (SkelAnime_Update(&this->skelAnime)) {
        EnMb_SetupClubWaitPlayerNear(this);
    }
}

/**
 * Slow down, charge again if the player is near, or resume walking.
 */
void EnMb_SpearPatrolEndCharge(EnMb* this, PlayState* play) {
#if OOT_VERSION >= PAL_1_0
    Player* player = GET_PLAYER(play);
#endif
    f32 lastFrame;
    s16 relYawFromPlayer;
    s16 yawPlayerToWaypoint;

#if OOT_VERSION >= PAL_1_0
    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->stateFlags2 &= ~PLAYER_STATE2_7;
        player->actor.parent = NULL;
        player->av2.actionVar2 = 200;
        Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
    }
#endif

    if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
        Math_SmoothStepToF(&this->actor.speed, 0.0f, 1.0f, 1.5f, 0.0f);

        if (this->actor.speed > 1.0f) {
            Actor_SpawnFloorDustRing(play, &this->actor, &this->actor.world.pos, 5.0f, 3, 4.0f, 100, 15, false);
        }

        if (this->timer1 != 0) {
            this->timer3--;
            if (this->timer3 == 0) {
                relYawFromPlayer = this->actor.shape.rot.y - this->actor.yawTowardsPlayer;

                if (ABS(this->actor.yDistToPlayer) <= 20.0f && EnMb_IsPlayerInCorridor(this, play) &&
                    ABS(relYawFromPlayer) <= 0x4000 && this->actor.xzDistToPlayer <= 200.0f) {
                    EnMb_SetupSpearPrepareAndCharge(this);
                } else {
                    lastFrame = Animation_GetLastFrame(&gEnMbSpearPrepareChargeAnim);
                    /* Play the charge animation in reverse: let go of the spear and stand normally */
                    Animation_Change(&this->skelAnime, &gEnMbSpearPrepareChargeAnim, -1.0f, lastFrame, 0.0f,
                                     ANIMMODE_ONCE, 0.0f);
                    this->actor.speed = 0.0f;
                    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_SPEAR_NORM);
                }
            } else {
                if (this->actor.xzDistToPlayer <= 160.0f) {
                    this->actor.speed = -5.0f;
                } else {
                    this->actor.speed = 0.0f;
                }
            }
        }

        if (SkelAnime_Update(&this->skelAnime)) {
            if (this->timer1 == 0) {
                lastFrame = Animation_GetLastFrame(&gEnMbSpearChargeAnim);
                Animation_Change(&this->skelAnime, &gEnMbSpearChargeAnim, 0.5f, 0.0f, lastFrame, ANIMMODE_LOOP_INTERP,
                                 0.0f);
                this->timer1 = 1;
            } else {
                yawPlayerToWaypoint =
                    Math_Vec3f_Yaw(&this->actor.world.pos, &this->waypointPos) - this->actor.yawTowardsPlayer;

                if (ABS(yawPlayerToWaypoint) <= 0x4000) {
                    EnMb_SetupSpearPatrolTurnTowardsWaypoint(this, play);
                } else {
                    EnMb_SetupSpearPatrolWalkTowardsWaypoint(this);
                }
            }
        }
    }
}

/**
 * Prepare charge (animation), then charge until the player isn't in front.
 */
void EnMb_SpearGuardPrepareAndCharge(EnMb* this, PlayState* play) {
    s32 prevFrame;
    s16 relYawTowardsPlayerAbs = this->actor.yawTowardsPlayer - this->actor.shape.rot.y;

    if (relYawTowardsPlayerAbs < 0) {
        relYawTowardsPlayerAbs = -relYawTowardsPlayerAbs;
    }

    prevFrame = this->skelAnime.curFrame;

    if (SkelAnime_Update(&this->skelAnime)) {
        Animation_PlayLoop(&this->skelAnime, &gEnMbSpearChargeAnim);
        Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_ATTACK);
    }

    if (this->timer3 != 0) {
        this->timer3--;
        Math_SmoothStepToS(&this->actor.world.rot.y, this->actor.yawTowardsPlayer, 1, 0xBB8, 0);
    } else {
        this->actor.speed = 10.0f;
        this->attack = ENMB_ATTACK_SPEAR;
        Actor_SpawnFloorDustRing(play, &this->actor, &this->actor.world.pos, 5.0f, 3, 4.0f, 100, 15, false);
        if (prevFrame != (s32)this->skelAnime.curFrame &&
            ((s32)this->skelAnime.curFrame == 2 || (s32)this->skelAnime.curFrame == 6)) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DASH);
        }
    }

    if (relYawTowardsPlayerAbs > 0x1388) {
        this->attack = ENMB_ATTACK_NONE;
        EnMb_SetupSpearEndChargeQuick(this);
    }
}

void EnMb_ClubAttack(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);
    s32 pad;
    Vec3f effSpawnPos;
    Vec3f effWhiteShockwaveDynamics = { 0.0f, 0.0f, 0.0f };
    f32 flamesParams[] = { 18.0f, 18.0f, 0.0f };
    s16 flamesUnused[] = { 20, 40, 0 };
    s16 relYawTarget[] = { -0x9C4, 0, 0xDAC };

    Math_SmoothStepToS(&this->actor.shape.rot.y, relYawTarget[this->attack - 1] + this->actor.world.rot.y, 1, 0x2EE, 0);

    if (this->attackCollider.base.atFlags & AT_HIT) {
        this->attackCollider.base.atFlags &= ~AT_HIT;
        if (this->attackCollider.base.at == &player->actor) {
            u8 prevPlayerInvincibilityTimer = player->invincibilityTimer;

            if (player->invincibilityTimer < 0) {
                if (player->invincibilityTimer <= -40) {
                    player->invincibilityTimer = 0;
                } else {
                    player->invincibilityTimer = 0;
                    play->damagePlayer(play, -8);
                }
            }

            Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor,
                                                  (650.0f - this->actor.xzDistToPlayer) * 0.04f + 4.0f,
                                                  this->actor.world.rot.y, 8.0f);

            player->invincibilityTimer = prevPlayerInvincibilityTimer;
        }
    }

    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer3 != 0) {
            this->timer3--;
            if (this->timer3 == 0) {
                f32 lastAnimFrame = Animation_GetLastFrame(&gEnMbClubStrikeDownAnim);
                Animation_Change(&this->skelAnime, &gEnMbClubStrikeDownAnim, 1.5f, 0.0f, lastAnimFrame,
                                 ANIMMODE_ONCE_INTERP, 0.0f);
            }
        } else {
            effSpawnPos = this->effSpawnPos;
            effSpawnPos.y = this->actor.floorHeight;
            Actor_PlaySfx(&this->actor, NA_SE_EN_MONBLIN_HAM_LAND);
            Rumble_Request(this->actor.xzDistToPlayer, 255, 20, 150);
            EffectSsBlast_SpawnWhiteShockwave(play, &effSpawnPos, &effWhiteShockwaveDynamics,
                                              &effWhiteShockwaveDynamics);
            func_80033480(play, &effSpawnPos, 2.0f, 3, 0x12C, 0xB4, 1);
            Camera_RequestQuake(&play->mainCamera, 2, 25, 5);
            func_800358DC(&this->actor, &effSpawnPos, &this->actor.world.rot, flamesParams, 20, flamesUnused, play, -1,
                          NULL);
            EnMb_SetupClubWaitAfterAttack(this);
        }
    } else {
        if (this->timer3 != 0 && this->skelAnime.curFrame == 6.0f) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MONBLIN_HAM_UP);

        } else if (this->timer3 == 0 && this->skelAnime.curFrame == 3.0f) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MONBLIN_HAM_DOWN);
        }
    }
}

/**
 * Prepare charge (animation), then charge to the end of the floor collision.
 */
void EnMb_SpearPatrolPrepareAndCharge(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);
    s32 prevFrame;
    s32 hasHitPlayer = false;
    s32 endCharge = !Actor_TestFloorInDirection(&this->actor, play, 110.0f, this->actor.world.rot.y);

    prevFrame = (s32)this->skelAnime.curFrame;
    if (SkelAnime_Update(&this->skelAnime)) {
        Animation_PlayLoop(&this->skelAnime, &gEnMbSpearChargeAnim);
        Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_ATTACK);
    }

    if (this->timer3 != 0) {
        this->timer3--;
        Math_SmoothStepToS(&this->actor.shape.rot.y, this->actor.world.rot.y, 1, 0x1F40, 0);
        endCharge = false;
    } else {
        this->actor.speed = 10.0f;
        this->attack = ENMB_ATTACK_SPEAR;
        Actor_SpawnFloorDustRing(play, &this->actor, &this->actor.world.pos, 5.0f, 3, 4.0f, 100, 15, false);
        if (prevFrame != (s32)this->skelAnime.curFrame &&
            ((s32)this->skelAnime.curFrame == 2 || (s32)this->skelAnime.curFrame == 6)) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DASH);
        }
    }

    if (this->attackCollider.base.atFlags & AT_HIT) {
        if (this->attackCollider.base.at == &player->actor) {
            if (!endCharge && !(player->stateFlags2 & PLAYER_STATE2_7)) {
                if (player->invincibilityTimer < 0) {
                    if (player->invincibilityTimer <= -40) {
                        player->invincibilityTimer = 0;
                    } else {
                        player->invincibilityTimer = 0;
                        play->damagePlayer(play, -8);
                    }
                }
                if (!(this->attackCollider.base.atFlags & AT_BOUNCED)) {
                    Actor_PlaySfx(&player->actor, NA_SE_PL_BODY_HIT);
                }
                if (play->grabPlayer(play, player)) {
                    player->actor.parent = &this->actor;
                }
            }
            hasHitPlayer = true;
        } else {
            this->attackCollider.base.atFlags &= ~AT_HIT;
        }
    }

    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->actor.world.pos.x = this->actor.world.pos.x + Math_CosS(this->actor.shape.rot.y) * 10.0f +
                                    Math_SinS(this->actor.shape.rot.y) * 89.0f;
        hasHitPlayer = true;
        player->actor.world.pos.z = this->actor.world.pos.z + Math_SinS(this->actor.shape.rot.y) * 10.0f +
                                    Math_CosS(this->actor.shape.rot.y) * 89.0f;
        player->av2.actionVar2 = 0;
        player->actor.speed = 0.0f;
        player->actor.velocity.y = 0.0f;
    }

    if (endCharge) {
        if (hasHitPlayer || (player->stateFlags2 & PLAYER_STATE2_7)) {
#if OOT_VERSION < PAL_1_0
            player->stateFlags2 &= ~PLAYER_STATE2_7;
            this->attackCollider.base.atFlags &= ~AT_HIT;
            player->actor.parent = NULL;
            Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
#elif OOT_VERSION < NTSC_1_2
            player->stateFlags2 &= ~PLAYER_STATE2_7;
            this->attackCollider.base.atFlags &= ~AT_HIT;
            player->actor.parent = NULL;
            player->av2.actionVar2 = 200;
            Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
#else
            this->attackCollider.base.atFlags &= ~AT_HIT;
            if (player->stateFlags2 & PLAYER_STATE2_7) {
                player->stateFlags2 &= ~PLAYER_STATE2_7;
                player->actor.parent = NULL;
                player->av2.actionVar2 = 200;
                Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
            }
#endif
        }
        this->attack = ENMB_ATTACK_NONE;
        this->actor.speed = -10.0f;
        EnMb_SetupSpearPatrolEndCharge(this);
    }
}

/**
 * Charge and follow the path, until hitting the player or, after some time, reaching home.
 */
void EnMb_SpearPatrolImmediateCharge(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);
    s32 prevFrame;
    s32 hasHitPlayer = false;
    s32 endCharge = !Actor_TestFloorInDirection(&this->actor, play, 110.0f, this->actor.world.rot.y);

    prevFrame = (s32)this->skelAnime.curFrame;
    SkelAnime_Update(&this->skelAnime);

    Actor_SpawnFloorDustRing(play, &this->actor, &this->actor.world.pos, 5.0f, 3, 4.0f, 100, 15, false);
    if (prevFrame != (s32)this->skelAnime.curFrame &&
        ((s32)this->skelAnime.curFrame == 2 || (s32)this->skelAnime.curFrame == 6)) {
        Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DASH);
    }

    if (this->attackCollider.base.atFlags & AT_HIT) {
        if (this->attackCollider.base.at == &player->actor) {
            if (!endCharge && !(player->stateFlags2 & PLAYER_STATE2_7)) {
                if (player->invincibilityTimer < 0) {
                    if (player->invincibilityTimer <= -40) {
                        player->invincibilityTimer = 0;
                    } else {
                        player->invincibilityTimer = 0;
                        play->damagePlayer(play, -8);
                    }
                }
                if (!(this->attackCollider.base.atFlags & AT_BOUNCED)) {
                    Actor_PlaySfx(&player->actor, NA_SE_PL_BODY_HIT);
                }
                if (play->grabPlayer(play, player)) {
                    player->actor.parent = &this->actor;
                }
            }
            hasHitPlayer = true;
        } else {
            this->attackCollider.base.atFlags &= ~AT_HIT;
        }
    }

    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->actor.world.pos.x = this->actor.world.pos.x + Math_CosS(this->actor.shape.rot.y) * 10.0f +
                                    Math_SinS(this->actor.shape.rot.y) * 89.0f;
        hasHitPlayer = true;
        player->actor.world.pos.z = this->actor.world.pos.z + Math_SinS(this->actor.shape.rot.y) * 10.0f +
                                    Math_CosS(this->actor.shape.rot.y) * 89.0f;
        player->av2.actionVar2 = 0;
        player->actor.speed = 0.0f;
        player->actor.velocity.y = 0.0f;
    }

    if (endCharge) {
        if (hasHitPlayer || (player->stateFlags2 & PLAYER_STATE2_7)) {
#if OOT_VERSION < PAL_1_0
            this->attackCollider.base.atFlags &= ~AT_HIT;
            player->stateFlags2 &= ~PLAYER_STATE2_7;
            player->actor.parent = NULL;
            Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
#elif OOT_VERSION < NTSC_1_2
            this->attackCollider.base.atFlags &= ~AT_HIT;
            player->stateFlags2 &= ~PLAYER_STATE2_7;
            player->actor.parent = NULL;
            player->av2.actionVar2 = 200;
            Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
#else
            this->attackCollider.base.atFlags &= ~AT_HIT;
            if (player->stateFlags2 & PLAYER_STATE2_7) {
                player->stateFlags2 &= ~PLAYER_STATE2_7;
                player->actor.parent = NULL;
                player->av2.actionVar2 = 200;
                Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
            }
#endif
            this->attack = ENMB_ATTACK_NONE;
            this->actor.speed = -10.0f;
            EnMb_SetupSpearPatrolEndCharge(this);
            this->timer3 = 1;
        } else {
            this->timer3--;
            EnMb_NextWaypoint(this, play);
        }
    }

    EnMb_FaceWaypoint(this, play);
    this->actor.shape.rot.y = this->actor.world.rot.y;

    if (this->timer3 == 0 && Math_Vec3f_DistXZ(&this->actor.home.pos, &this->actor.world.pos) < 80.0f) {
        this->attack = ENMB_ATTACK_NONE;
        EnMb_SetupSpearEndChargeQuick(this);
    }
}

void EnMb_ClubDamaged(EnMb* this, PlayState* play) {
    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer3 != 0) {
            Animation_PlayOnce(&this->skelAnime, &gEnMbClubStandUpAnim);
            this->timer3 = 0;
            Rumble_Request(this->actor.xzDistToPlayer, 255, 20, 150);
            Camera_RequestQuake(&play->mainCamera, 2, 25, 5);
        } else {
            EnMb_SetupClubWaitPlayerNear(this);
        }
    }
}

void EnMb_ClubDamagedWhileKneeling(EnMb* this, PlayState* play) {
    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer3 != 0) {
            this->timer3--;
            if (this->timer3 == 0) {
                if (this->timer1 == 0) {
                    s32 pad;

                    Animation_Change(&this->skelAnime, &gEnMbClubStandUpAnim, 3.0f, 0.0f,
                                     Animation_GetLastFrame(&gEnMbClubStandUpAnim), ANIMMODE_ONCE_INTERP, 0.0f);
                    this->timer1 = 1;
                    this->timer3 = 6;
                } else {
                    Animation_Change(&this->skelAnime, &gEnMbClubStandUpAnim, 3.0f, 0.0f,
                                     Animation_GetLastFrame(&gEnMbClubStandUpAnim), ANIMMODE_ONCE_INTERP, 0.0f);
                }
            }
        } else {
            EnMb_SetupClubWaitPlayerNear(this);
        }
    }
}

void EnMb_ClubDead(EnMb* this, PlayState* play) {
    Vec3f effPos;
    Vec3f effPosBase;

    effPos = this->actor.world.pos;
    effPos.x += Math_SinS(this->actor.shape.rot.y) * -70.0f;
    effPos.z += Math_CosS(this->actor.shape.rot.y) * -70.0f;
    Math_SmoothStepToF(&this->actor.speed, 0.0f, 1.0f, 0.5f, 0.0f);
    effPosBase = effPos;

    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer1 > 0) {
            Vec3f effZeroVec = { 0.0f, 0.0f, 0.0f };
            s32 i;

            this->timer1--;
            for (i = 4; i >= 0; i--) {
                effPos.x = Rand_CenteredFloat(240.0f) + effPosBase.x;
                effPos.y = Rand_CenteredFloat(15.0f) + (effPosBase.y + 20.0f);
                effPos.z = Rand_CenteredFloat(240.0f) + effPosBase.z;
                EffectSsDeadDb_Spawn(play, &effPos, &effZeroVec, &effZeroVec, 230, 7, 255, 255, 255, 255, 0, 255, 0, 1,
                                     9, true);
            }
        } else {
            Item_DropCollectibleRandom(play, &this->actor, &effPos,
                                       COLLECTIBLE_DROP_RANDOM_PARAMS(COLLECTIBLE_DROP_TABLE_12, false));
            Actor_Kill(&this->actor);
        }
    } else if ((s32)this->skelAnime.curFrame == 15 || (s32)this->skelAnime.curFrame == 22) {
        Rumble_Request(this->actor.xzDistToPlayer, 255, 20, 150);
        Actor_SpawnFloorDustRing(play, &this->actor, &effPos, 50.0f, 10, 3.0f, 400, 60, false);
        Actor_PlaySfx(&this->actor, NA_SE_EN_RIZA_DOWN);
        Camera_RequestQuake(&play->mainCamera, 2, 25, 5);
    }
}

/**
 * Walk around the home point, face and charge the player if close.
 */
void EnMb_SpearGuardWalk(EnMb* this, PlayState* play) {
    s32 prevFrame;
    s32 beforeCurFrame;
    s32 pad1;
    s32 pad2;
    Player* player = GET_PLAYER(play);
    s16 relYawTowardsPlayer = this->actor.yawTowardsPlayer - this->actor.shape.rot.y;
    s16 yawTowardsHome;
    f32 playSpeedAbs;

    relYawTowardsPlayer = ABS(relYawTowardsPlayer);
    Math_SmoothStepToF(&this->actor.speed, 0.59999996f, 0.1f, 1.0f, 0.0f);
    this->skelAnime.playSpeed = this->actor.speed;
    prevFrame = this->skelAnime.curFrame;
    SkelAnime_Update(&this->skelAnime);

    playSpeedAbs = ABS(this->skelAnime.playSpeed);
    beforeCurFrame = this->skelAnime.curFrame - playSpeedAbs;
    playSpeedAbs = ABS(this->skelAnime.playSpeed);
    if (this->timer3 == 0 &&
        Math_Vec3f_DistXZ(&this->actor.home.pos, &player->actor.world.pos) < this->playerDetectionRange) {
        Math_SmoothStepToS(&this->actor.world.rot.y, this->actor.yawTowardsPlayer, 1, 0x2EE, 0);
        this->actor.flags |= ACTOR_FLAG_ATTENTION_ENABLED;
        if (this->actor.xzDistToPlayer < 500.0f && relYawTowardsPlayer < 0x1388) {
            EnMb_SetupSpearPrepareAndCharge(this);
        }
    } else {
        this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
        if (Math_Vec3f_DistXZ(&this->actor.world.pos, &this->actor.home.pos) > this->maxHomeDist || this->timer2 != 0) {
            yawTowardsHome = Math_Vec3f_Yaw(&this->actor.world.pos, &this->actor.home.pos);
            Math_SmoothStepToS(&this->actor.world.rot.y, yawTowardsHome, 1, 0x2EE, 0);
        }
        if (this->timer2 != 0) {
            this->timer2--;
        }
        if (this->timer3 != 0) {
            this->timer3--;
        }
        if (this->timer2 == 0) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_VOICE);
        }
        this->timer1--;
        if (this->timer1 == 0) {
            if (Rand_ZeroOne() > 0.7f) {
                this->timer1 = Rand_S16Offset(50, 70);
                this->timer2 = Rand_S16Offset(15, 40);
            } else {
                EnMb_SetupSpearGuardLookAround(this);
            }
        }
    }

    if (prevFrame != (s32)this->skelAnime.curFrame) {
        if ((beforeCurFrame <= 1 && prevFrame + (s32)playSpeedAbs >= 1) ||
            (beforeCurFrame <= 20 && prevFrame + (s32)playSpeedAbs >= 20)) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_WALK);
        }
    }

    this->actor.shape.rot.y = this->actor.world.rot.y;
}

void EnMb_SpearPatrolWalkTowardsWaypoint(EnMb* this, PlayState* play) {
    s32 prevFrame;
    s32 beforeCurFrame;
    s16 relYawTowardsPlayer;
    f32 yDistToPlayerAbs;
    f32 playSpeedABS;

    if (Math_Vec3f_DistXZ(&this->waypointPos, &this->actor.world.pos) <= 8.0f ||
        (Rand_ZeroOne() < 0.1f && Math_Vec3f_DistXZ(&this->actor.home.pos, &this->actor.world.pos) <= 4.0f)) {
        EnMb_SetupSpearPatrolTurnTowardsWaypoint(this, play);
    } else {
        Math_SmoothStepToF(&this->actor.speed, 0.59999996f, 0.1f, 1.0f, 0.0f);
        this->skelAnime.playSpeed = 2.0f * this->actor.speed;
    }

    this->yawToWaypoint = Math_Vec3f_Yaw(&this->actor.world.pos, &this->waypointPos);
    Math_SmoothStepToS(&this->actor.world.rot.y, this->yawToWaypoint, 1, 0x5DC, 0);

    yDistToPlayerAbs = (this->actor.yDistToPlayer >= 0.0f) ? this->actor.yDistToPlayer : -this->actor.yDistToPlayer;
    if (yDistToPlayerAbs <= 20.0f && EnMb_IsPlayerInCorridor(this, play)) {
        relYawTowardsPlayer = (this->actor.shape.rot.y - this->actor.yawTowardsPlayer);
        if (ABS(relYawTowardsPlayer) <= 0x4000 || (func_8002DDE4(play) && this->actor.xzDistToPlayer < 160.0f)) {
            EnMb_FindWaypointTowardsPlayer(this, play);
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_VOICE);
            EnMb_SetupSpearPrepareAndCharge(this);
            return;
        }
    }

    if (this->timer2 != 0) {
        this->timer2--;
    }
    if (this->timer3 != 0) {
        this->timer3--;
    }
    if (this->timer2 == 0) {
        Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_VOICE);
        this->timer2 = Rand_S16Offset(30, 70);
    }

    prevFrame = this->skelAnime.curFrame;
    SkelAnime_Update(&this->skelAnime);
    playSpeedABS = ABS(this->skelAnime.playSpeed);
    beforeCurFrame = this->skelAnime.curFrame - playSpeedABS;
    playSpeedABS = (this->skelAnime.playSpeed >= 0.0f) ? this->skelAnime.playSpeed : -this->skelAnime.playSpeed;
    if (prevFrame != (s32)this->skelAnime.curFrame) {
        if ((beforeCurFrame <= 1 && (s32)playSpeedABS + prevFrame >= 1) ||
            (beforeCurFrame <= 20 && (s32)playSpeedABS + prevFrame >= 20)) {
            Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_WALK);
        }
    }

    this->actor.shape.rot.y = this->actor.world.rot.y;
}

void EnMb_ClubWaitPlayerNear(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);
    s32 pad;
    s16 relYawFromPlayer = this->actor.world.rot.y - this->actor.yawTowardsPlayer;

    SkelAnime_Update(&this->skelAnime);
    if (Math_Vec3f_DistXZ(&this->actor.home.pos, &player->actor.world.pos) < this->playerDetectionRange &&
        !(player->stateFlags1 & PLAYER_STATE1_26) && ABS(relYawFromPlayer) < 0x3E80) {
        EnMb_SetupClubAttack(this);
    }
}

void EnMb_SetupSpearDamaged(EnMb* this) {
    s16 relYawTowardsPlayer = this->actor.yawTowardsPlayer - this->actor.shape.rot.y;

    if (ABS(relYawTowardsPlayer) <= 0x4000) {
        Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbSpearDamagedFromFrontAnim, -4.0f);
        this->actor.speed = -8.0f;
    } else {
        Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbSpearDamagedFromBehindAnim, -4.0f);
        this->actor.speed = 8.0f;
    }

    this->timer1 = 30;
    this->state = ENMB_STATE_SPEAR_SPEARPATH_DAMAGED;
    this->actor.shape.rot.y = this->actor.world.rot.y;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DEAD);
    EnMb_SetupAction(this, EnMb_SpearDamaged);
}

void EnMb_SpearDamaged(EnMb* this, PlayState* play) {
    Math_SmoothStepToF(&this->actor.speed, 0.0f, 1.0f, 0.5f, 0.0f);
    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->actor.params <= ENMB_TYPE_SPEAR_GUARD) {
            EnMb_SetupSpearGuardLookAround(this);
        } else {
            EnMb_SetupSpearPatrolImmediateCharge(this);
        }
    }
}

void EnMb_SetupSpearDead(EnMb* this) {
    s16 relYawTowardsPlayer = this->actor.yawTowardsPlayer - this->actor.shape.rot.y;

    if (ABS(relYawTowardsPlayer) <= 0x4000) {
        Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbSpearFallOnItsBackAnim, -4.0f);
        this->actor.speed = -8.0f;
    } else {
        /* The gEnMbSpearFallFaceDownAnim animation was probably meant to be used here */
        Animation_MorphToPlayOnce(&this->skelAnime, &gEnMbSpearFallOnItsBackAnim, -4.0f);
        this->actor.speed = 8.0f;
    }

    this->actor.world.rot.y = this->actor.shape.rot.y;
    this->timer1 = 30;
    this->state = ENMB_STATE_SPEAR_SPEARPATH_DAMAGED;
    Actor_PlaySfx(&this->actor, NA_SE_EN_MORIBLIN_DEAD);
    this->actor.flags &= ~ACTOR_FLAG_ATTENTION_ENABLED;
    EnMb_SetupAction(this, EnMb_SpearDead);
}

void EnMb_SpearDead(EnMb* this, PlayState* play) {
#if OOT_VERSION >= NTSC_1_1
    Player* player = GET_PLAYER(play);
#endif

    Math_SmoothStepToF(&this->actor.speed, 0.0f, 1.0f, 0.5f, 0.0f);

#if OOT_VERSION < NTSC_1_1
    // Empty
#elif OOT_VERSION < PAL_1_0
    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->stateFlags2 &= ~PLAYER_STATE2_7;
        player->actor.parent = NULL;
        Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
        this->attack = ENMB_ATTACK_NONE;
    }
#else
    if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
        player->stateFlags2 &= ~PLAYER_STATE2_7;
        player->actor.parent = NULL;
        player->av2.actionVar2 = 200;
        Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 4.0f, this->actor.world.rot.y, 4.0f);
        this->attack = ENMB_ATTACK_NONE;
    }
#endif

    if (SkelAnime_Update(&this->skelAnime)) {
        if (this->timer1 > 0) {
            Vec3f zeroVec = { 0.0f, 0.0f, 0.0f };
            s32 i;
            Vec3f effPos;

            this->actor.shape.shadowScale = 0.0f;
            this->timer1--;
            for (i = 4; i >= 0; i--) {
                effPos.x = Rand_CenteredFloat(110.0f) + this->actor.world.pos.x;
                effPos.y = Rand_CenteredFloat(15.0f) + (this->actor.world.pos.y + 20.0f);
                effPos.z = Rand_CenteredFloat(110.0f) + this->actor.world.pos.z;

                EffectSsDeadDb_Spawn(play, &effPos, &zeroVec, &zeroVec, 100, 7, 255, 255, 255, 255, 0, 255, 0, 1, 9,
                                     true);
            }
        } else {
            Item_DropCollectibleRandom(play, &this->actor, &this->actor.world.pos,
                                       COLLECTIBLE_DROP_RANDOM_PARAMS(COLLECTIBLE_DROP_TABLE_14, false));
            Actor_Kill(&this->actor);
        }
    }
}

void EnMb_SpearUpdateAttackCollider(Actor* thisx, PlayState* play) {
    Vec3f quadModel0 = { 1000.0f, 1500.0f, 0.0f };
    Vec3f quadModel1 = { -1000.0f, 1500.0f, 0.0f };
    Vec3f quadModel2 = { 1000.0f, 1500.0f, 4500.0f };
    Vec3f quadModel3 = { -1000.0f, 1500.0f, 4500.0f };
    EnMb* this = (EnMb*)thisx;

    if (this->actor.params >= ENMB_TYPE_SPEAR_PATROL) {
        quadModel0.x += 2000.0f;
        quadModel0.z = -4000.0f;
        quadModel1.z = -4000.0f;
        quadModel2.x += 2000.0f;
        quadModel1.x -= 2000.0f;
        quadModel3.x -= 2000.0f;
        quadModel2.z += 4000.0f;
        quadModel3.z += 4000.0f;
    }
    Matrix_MultVec3f(&quadModel0, &this->attackCollider.dim.quad[1]);
    Matrix_MultVec3f(&quadModel1, &this->attackCollider.dim.quad[0]);
    Matrix_MultVec3f(&quadModel2, &this->attackCollider.dim.quad[3]);
    Matrix_MultVec3f(&quadModel3, &this->attackCollider.dim.quad[2]);
    Collider_SetQuadVertices(&this->attackCollider, &this->attackCollider.dim.quad[0],
                             &this->attackCollider.dim.quad[1], &this->attackCollider.dim.quad[2],
                             &this->attackCollider.dim.quad[3]);
}

void EnMb_ClubUpdateAttackCollider(Actor* thisx, PlayState* play) {
    static Vec3f quadModel[] = { { 1000.0f, 0.0f, 0.0f },
                                 { 1000.0f, 0.0f, 0.0f },
                                 { 1000.0f, -8000.0f, -1500.0f },
                                 { 1000.0f, -9000.0f, 2000.0f } };
    EnMb* this = (EnMb*)thisx;

    Matrix_MultVec3f(&quadModel[0], &this->attackCollider.dim.quad[1]);
    Matrix_MultVec3f(&quadModel[1], &this->attackCollider.dim.quad[0]);
    Matrix_MultVec3f(&quadModel[2], &this->attackCollider.dim.quad[3]);
    Matrix_MultVec3f(&quadModel[3], &this->attackCollider.dim.quad[2]);
    Collider_SetQuadVertices(&this->attackCollider, &this->attackCollider.dim.quad[0],
                             &this->attackCollider.dim.quad[1], &this->attackCollider.dim.quad[2],
                             &this->attackCollider.dim.quad[3]);
}

void EnMb_CheckColliding(EnMb* this, PlayState* play) {
    Player* player = GET_PLAYER(play);

    if (this->frontShieldingCollider.base.acFlags & AC_HIT) {
        this->frontShieldingCollider.base.acFlags &= ~(AC_HIT | AC_BOUNCED);
        this->bodyCollider.base.acFlags &= ~AC_HIT;
    } else if ((this->bodyCollider.base.acFlags & AC_HIT) && this->state >= ENMB_STATE_STUNNED) {
        this->bodyCollider.base.acFlags &= ~AC_HIT;
        if (this->actor.colChkInfo.damageReaction != ENMB_DMG_REACT_IGNORE &&
            this->actor.colChkInfo.damageReaction != ENMB_DMG_REACT_FREEZE) {
            if ((player->stateFlags2 & PLAYER_STATE2_7) && player->actor.parent == &this->actor) {
                player->stateFlags2 &= ~PLAYER_STATE2_7;
                player->actor.parent = NULL;
#if OOT_VERSION >= PAL_1_0
                player->av2.actionVar2 = 200;
#endif
                Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 6.0f, this->actor.world.rot.y, 6.0f);
            }
            this->damageReaction = this->actor.colChkInfo.damageReaction;
            this->attack = ENMB_ATTACK_NONE;
            Actor_SetDropFlag(&this->actor, &this->bodyCollider.elem, false);
            if (this->actor.colChkInfo.damageReaction == ENMB_DMG_REACT_STUN ||
                this->actor.colChkInfo.damageReaction == ENMB_DMG_REACT_STUN_ICE) {
                if (this->state != ENMB_STATE_STUNNED) {
                    Actor_ApplyDamage(&this->actor);
                    EnMb_SetupStunned(this);
                }
            } else {
                Actor_ApplyDamage(&this->actor);
                Actor_SetColorFilter(&this->actor, COLORFILTER_COLORFLAG_RED, 250, COLORFILTER_BUFFLAG_OPA, 12);
                if (this->actor.params == ENMB_TYPE_CLUB) {
                    if (this->actor.colChkInfo.health == 0) {
                        EnMb_SetupClubDead(this);
                    } else if (this->state != ENMB_STATE_CLUB_KNEELING) {
                        EnMb_SetupClubDamaged(this);
                    }
                } else {
                    if (this->actor.colChkInfo.health == 0) {
                        EnMb_SetupSpearDead(this);
                    } else {
                        EnMb_SetupSpearDamaged(this);
                    }
                }
            }
        }
    }
}

void EnMb_Update(Actor* thisx, PlayState* play) {
    EnMb* this = (EnMb*)thisx;
    s32 pad;

    EnMb_CheckColliding(this, play);
    if (thisx->colChkInfo.damageReaction != ENMB_DMG_REACT_FREEZE) {
        this->actionFunc(this, play);
        Actor_MoveXZGravity(thisx);
        Actor_UpdateBgCheckInfo(play, thisx, 40.0f, 40.0f, 70.0f,
                                UPDBGCHECKINFO_FLAG_0 | UPDBGCHECKINFO_FLAG_2 | UPDBGCHECKINFO_FLAG_3 |
                                    UPDBGCHECKINFO_FLAG_4);
        Actor_SetFocus(thisx, thisx->scale.x * 4500.0f);
        Collider_UpdateCylinder(thisx, &this->bodyCollider);
        if (thisx->colChkInfo.health <= 0) {
            this->bodyCollider.dim.pos.x += Math_SinS(thisx->shape.rot.y) * (-4400.0f * thisx->scale.y);
            this->bodyCollider.dim.pos.z += Math_CosS(thisx->shape.rot.y) * (-4400.0f * thisx->scale.y);
        }
        CollisionCheck_SetOC(play, &play->colChkCtx, &this->bodyCollider.base);
        if (this->state >= ENMB_STATE_STUNNED &&
            (thisx->params == ENMB_TYPE_CLUB || this->state != ENMB_STATE_ATTACK)) {
            CollisionCheck_SetAC(play, &play->colChkCtx, &this->bodyCollider.base);
        }
        if (this->state >= ENMB_STATE_IDLE) {
            CollisionCheck_SetAC(play, &play->colChkCtx, &this->frontShieldingCollider.base);
        }
        if (this->attack > ENMB_ATTACK_NONE) {
            CollisionCheck_SetAT(play, &play->colChkCtx, &this->attackCollider.base);
        }
    }
}

void EnMb_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx) {
    static Vec3f unused = { 1100.0f, -700.0f, 0.0f };
    static Vec3f feetPos = { 0.0f, 0.0f, 0.0f };
    static Vec3f effSpawnOffsetFromLeftHand = { 0.0f, -8000.0f, 0.0f };
    static Vec3f zeroVec = { 0.0f, 0.0f, 0.0f };
    s32 bodyPart = -1;
    EnMb* this = (EnMb*)thisx;
    Vec3f bodyPartPos;

    if (this->actor.params == ENMB_TYPE_CLUB) {
        if (limbIndex == ENMB_LIMB_LHAND) {
            Matrix_MultVec3f(&effSpawnOffsetFromLeftHand, &this->effSpawnPos);
            if (this->attack > ENMB_ATTACK_NONE) {
                EnMb_ClubUpdateAttackCollider(&this->actor, play);
            }
        }
        Actor_SetFeetPos(&this->actor, limbIndex, ENMB_LIMB_LFOOT, &feetPos, ENMB_LIMB_RFOOT, &feetPos);
    }

    if (this->iceEffectTimer != 0) {
        switch (limbIndex) {
            case ENMB_LIMB_HEAD:
                bodyPart = 0;
                break;
            case ENMB_LIMB_LHAND:
                bodyPart = 1;
                break;
            case ENMB_LIMB_RHAND:
                bodyPart = 2;
                break;
            case ENMB_LIMB_LSHOULDER:
                bodyPart = 3;
                break;
            case ENMB_LIMB_RSHOULDER:
                bodyPart = 4;
                break;
            case ENMB_LIMB_CHEST:
                bodyPart = 5;
                break;
            case ENMB_LIMB_LTHIGH:
                bodyPart = 6;
                break;
            case ENMB_LIMB_RTHIGH:
                bodyPart = 7;
                break;
            case ENMB_LIMB_LFOOT:
                bodyPart = 8;
                break;
            case ENMB_LIMB_RFOOT:
                bodyPart = 9;
                break;
        }
        if (bodyPart >= 0) {
            Matrix_MultVec3f(&zeroVec, &bodyPartPos);
            this->bodyPartsPos[bodyPart].x = bodyPartPos.x;
            this->bodyPartsPos[bodyPart].y = bodyPartPos.y;
            this->bodyPartsPos[bodyPart].z = bodyPartPos.z;
        }
    }
}

void EnMb_Draw(Actor* thisx, PlayState* play) {
    static Vec3f frontShieldingTriModel0[] = {
        { 4000.0f, 7000.0f, 3500.0f },
        { 4000.0f, 0.0f, 3500.0f },
        { -4000.0f, 7000.0f, 3500.0f },
    };
    static Vec3f frontShieldingTriModel1[] = {
        { -4000.0f, 7000.0f, 3500.0f },
        { -4000.0f, 0.0f, 3500.0f },
        { 4000.0f, 0.0f, 3500.0f },
    };
    s32 i;
    f32 scale;
    Vec3f frontShieldingTri0[3];
    Vec3f frontShieldingTri1[3];
    s32 bodyPartIdx;
    EnMb* this = (EnMb*)thisx;

    Gfx_SetupDL_25Opa(play->state.gfxCtx);
    SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, NULL,
                          EnMb_PostLimbDraw, thisx);

    if (thisx->params != ENMB_TYPE_CLUB) {
        if (this->attack > ENMB_ATTACK_NONE) {
            EnMb_SpearUpdateAttackCollider(thisx, play);
        }
        for (i = 0; i < 3; i++) {
            Matrix_MultVec3f(&frontShieldingTriModel0[i], &frontShieldingTri0[i]);
            Matrix_MultVec3f(&frontShieldingTriModel1[i], &frontShieldingTri1[i]);
        }
        Collider_SetTrisVertices(&this->frontShieldingCollider, 0, &frontShieldingTri0[0], &frontShieldingTri0[1],
                                 &frontShieldingTri0[2]);
        Collider_SetTrisVertices(&this->frontShieldingCollider, 1, &frontShieldingTri1[0], &frontShieldingTri1[1],
                                 &frontShieldingTri1[2]);
    }

    if (this->iceEffectTimer != 0) {
        thisx->colorFilterTimer++;
        if (this->iceEffectTimer >= 0) {
            this->iceEffectTimer--;
        }
        if ((this->iceEffectTimer % 4) == 0) {
            scale = 2.5f;
            if (thisx->params == ENMB_TYPE_CLUB) {
                scale = 4.0f;
            }
            bodyPartIdx = this->iceEffectTimer >> 2;
            EffectSsEnIce_SpawnFlyingVec3s(play, thisx, &this->bodyPartsPos[bodyPartIdx], 150, 150, 150, 250, 235, 245,
                                           255, scale);
        }
    }
}