forked from zeldaret/oot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz_actor.c
5658 lines (4811 loc) · 187 KB
/
z_actor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
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
#include "global.h"
#include "quake.h"
#include "terminal.h"
#include "overlays/actors/ovl_Arms_Hook/z_arms_hook.h"
#include "overlays/actors/ovl_En_Part/z_en_part.h"
#include "assets/objects/gameplay_keep/gameplay_keep.h"
#include "assets/objects/gameplay_dangeon_keep/gameplay_dangeon_keep.h"
#include "assets/objects/object_bdoor/object_bdoor.h"
static CollisionPoly* sCurCeilingPoly;
static s32 sCurCeilingBgId;
void ActorShape_Init(ActorShape* shape, f32 yOffset, ActorShadowFunc shadowDraw, f32 shadowScale) {
shape->yOffset = yOffset;
shape->shadowDraw = shadowDraw;
shape->shadowScale = shadowScale;
shape->shadowAlpha = 255;
}
void ActorShadow_Draw(Actor* actor, Lights* lights, PlayState* play, Gfx* dlist, Color_RGBA8* color) {
f32 temp1;
f32 temp2;
MtxF sp60;
if (actor->floorPoly != NULL) {
temp1 = actor->world.pos.y - actor->floorHeight;
if (temp1 >= -50.0f && temp1 < 500.0f) {
OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 1553);
POLY_OPA_DISP = Gfx_SetupDL(POLY_OPA_DISP, SETUPDL_44);
gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, COMBINED, 0, 0, 0,
COMBINED);
temp1 = (temp1 < 0.0f) ? 0.0f : ((temp1 > 150.0f) ? 150.0f : temp1);
temp2 = 1.0f - (temp1 * (1.0f / 350));
if (color != NULL) {
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, color->r, color->g, color->b,
(u32)(actor->shape.shadowAlpha * temp2) & 0xFF);
} else {
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, (u32)(actor->shape.shadowAlpha * temp2) & 0xFF);
}
func_80038A28(actor->floorPoly, actor->world.pos.x, actor->floorHeight, actor->world.pos.z, &sp60);
Matrix_Put(&sp60);
if (dlist != gCircleShadowDL) {
Matrix_RotateY(BINANG_TO_RAD(actor->shape.rot.y), MTXMODE_APPLY);
}
temp2 = (1.0f - (temp1 * (1.0f / 350))) * actor->shape.shadowScale;
Matrix_Scale(actor->scale.x * temp2, 1.0f, actor->scale.z * temp2, MTXMODE_APPLY);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_actor.c", 1588),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPDisplayList(POLY_OPA_DISP++, dlist);
CLOSE_DISPS(play->state.gfxCtx, "../z_actor.c", 1594);
}
}
}
void ActorShadow_DrawCircle(Actor* actor, Lights* lights, PlayState* play) {
ActorShadow_Draw(actor, lights, play, gCircleShadowDL, NULL);
}
void ActorShadow_DrawWhiteCircle(Actor* actor, Lights* lights, PlayState* play) {
static Color_RGBA8 white = { 255, 255, 255, 255 };
ActorShadow_Draw(actor, lights, play, gCircleShadowDL, &white);
}
void ActorShadow_DrawHorse(Actor* actor, Lights* lights, PlayState* play) {
ActorShadow_Draw(actor, lights, play, gHorseShadowDL, NULL);
}
void ActorShadow_DrawFoot(PlayState* play, Light* light, MtxF* arg2, s32 arg3, f32 arg4, f32 arg5, f32 arg6) {
s32 pad1;
f32 sp58;
s32 pad2[2];
OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 1661);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0,
(u32)(((arg3 * 0.00005f) > 1.0f ? 1.0f : (arg3 * 0.00005f)) * arg4) & 0xFF);
sp58 = Math_FAtan2F(light->l.dir[0], light->l.dir[2]);
arg6 *= (4.5f - (light->l.dir[1] * 0.035f));
arg6 = (arg6 < 1.0f) ? 1.0f : arg6;
Matrix_Put(arg2);
Matrix_RotateY(sp58, MTXMODE_APPLY);
Matrix_Scale(arg5, 1.0f, arg5 * arg6, MTXMODE_APPLY);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_actor.c", 1687), G_MTX_MODELVIEW | G_MTX_LOAD);
gSPDisplayList(POLY_OPA_DISP++, gFootShadowDL);
CLOSE_DISPS(play->state.gfxCtx, "../z_actor.c", 1693);
}
void ActorShadow_DrawFeet(Actor* actor, Lights* lights, PlayState* play) {
f32 distToFloor = actor->world.pos.y - actor->floorHeight;
if (distToFloor > 20.0f) {
f32 shadowScale = actor->shape.shadowScale;
u8 shadowAlpha = actor->shape.shadowAlpha;
f32 alphaRatio;
actor->shape.shadowScale *= 0.3f;
alphaRatio = (distToFloor - 20.0f) * 0.02f;
actor->shape.shadowAlpha = (f32)actor->shape.shadowAlpha * CLAMP_MAX(alphaRatio, 1.0f);
ActorShadow_DrawCircle(actor, lights, play);
actor->shape.shadowScale = shadowScale;
actor->shape.shadowAlpha = shadowAlpha;
}
if (distToFloor < 200.0f) {
MtxF floorMtx;
f32 floorHeight[2]; // One for each foot
f32 distToFloor;
f32 shadowAlpha;
f32 shadowScaleX;
f32 shadowScaleZ;
Light* lightPtr;
s32 lightNum;
s32 lightNumMax;
s32 i;
s32 j;
s32 numLights = lights->numLights - 2;
Light* firstLightPtr = &lights->l.l[0];
Vec3f* feetPosPtr = actor->shape.feetPos;
f32* floorHeightPtr = floorHeight;
OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 1741);
POLY_OPA_DISP = Gfx_SetupDL(POLY_OPA_DISP, SETUPDL_44);
// feetFloorFlag is temporarily a bitfield where the bits are set if the foot is on ground
// feetFloorFlag & 2 is left foot, feetFloorFlag & 1 is right foot
actor->shape.feetFloorFlag = 0;
for (i = 0; i < 2; i++) {
feetPosPtr->y += 50.0f;
*floorHeightPtr = func_800BFCB8(play, &floorMtx, feetPosPtr);
feetPosPtr->y -= 50.0f;
actor->shape.feetFloorFlag <<= 1;
distToFloor = feetPosPtr->y - *floorHeightPtr;
if ((-1.0f <= distToFloor) && (distToFloor < 500.0f)) {
if (distToFloor <= 0.0f) {
actor->shape.feetFloorFlag++;
}
distToFloor = CLAMP_MAX(distToFloor, 30.0f);
shadowAlpha = (f32)actor->shape.shadowAlpha * (1.0f - (distToFloor * (1.0f / 30.0f)));
distToFloor = CLAMP_MAX(distToFloor, 30.0f);
shadowScaleZ = 1.0f - (distToFloor * (1.0f / (30.0f + 40.0f)));
shadowScaleX = shadowScaleZ * actor->shape.shadowScale * actor->scale.x;
lightNumMax = 0;
lightPtr = firstLightPtr;
for (j = 0; j < numLights; j++) {
if (lightPtr->l.dir[1] > 0) {
lightNum =
(lightPtr->l.col[0] + lightPtr->l.col[1] + lightPtr->l.col[2]) * ABS(lightPtr->l.dir[1]);
if (lightNum > 0) {
lightNumMax += lightNum;
ActorShadow_DrawFoot(play, lightPtr, &floorMtx, lightNum, shadowAlpha, shadowScaleX,
shadowScaleZ);
}
}
lightPtr++;
}
for (j = 0; j < 2; j++) {
if (lightPtr->l.dir[1] > 0) {
lightNum =
((lightPtr->l.col[0] + lightPtr->l.col[1] + lightPtr->l.col[2]) * ABS(lightPtr->l.dir[1])) -
(lightNumMax * 8);
if (lightNum > 0) {
ActorShadow_DrawFoot(play, lightPtr, &floorMtx, lightNum, shadowAlpha, shadowScaleX,
shadowScaleZ);
}
}
lightPtr++;
}
}
feetPosPtr++;
floorHeightPtr++;
}
if (!(actor->bgCheckFlags & BGCHECKFLAG_GROUND)) {
actor->shape.feetFloorFlag = 0;
} else if (actor->shape.feetFloorFlag == 3) {
f32 footDistY = actor->shape.feetPos[FOOT_LEFT].y - actor->shape.feetPos[FOOT_RIGHT].y;
if ((floorHeight[FOOT_LEFT] + footDistY) < (floorHeight[FOOT_RIGHT] - footDistY)) {
actor->shape.feetFloorFlag = 2;
} else {
actor->shape.feetFloorFlag = 1;
}
}
CLOSE_DISPS(play->state.gfxCtx, "../z_actor.c", 1831);
}
}
void Actor_SetFeetPos(Actor* actor, s32 limbIndex, s32 leftFootIndex, Vec3f* leftFootPos, s32 rightFootIndex,
Vec3f* rightFootPos) {
if (limbIndex == leftFootIndex) {
Matrix_MultVec3f(leftFootPos, &actor->shape.feetPos[FOOT_LEFT]);
} else if (limbIndex == rightFootIndex) {
Matrix_MultVec3f(rightFootPos, &actor->shape.feetPos[FOOT_RIGHT]);
}
}
void Actor_ProjectPos(PlayState* play, Vec3f* src, Vec3f* xyzDest, f32* cappedInvWDest) {
SkinMatrix_Vec3fMtxFMultXYZW(&play->viewProjectionMtxF, src, xyzDest, cappedInvWDest);
*cappedInvWDest = (*cappedInvWDest < 1.0f) ? 1.0f : (1.0f / *cappedInvWDest);
}
typedef struct {
/* 0x00 */ Color_RGBA8 inner;
/* 0x04 */ Color_RGBA8 outer;
} NaviColor; // size = 0x8
NaviColor sNaviColorList[] = {
{ { 0, 255, 0, 255 }, { 0, 255, 0, 0 } }, { { 0, 255, 0, 255 }, { 0, 255, 0, 0 } },
{ { 255, 255, 255, 255 }, { 0, 0, 255, 0 } }, { { 0, 255, 0, 255 }, { 0, 255, 0, 0 } },
{ { 150, 150, 255, 255 }, { 150, 150, 255, 0 } }, { { 255, 255, 0, 255 }, { 200, 155, 0, 0 } },
{ { 0, 255, 0, 255 }, { 0, 255, 0, 0 } }, { { 0, 255, 0, 255 }, { 0, 255, 0, 0 } },
{ { 0, 255, 0, 255 }, { 0, 255, 0, 0 } }, { { 255, 255, 0, 255 }, { 200, 155, 0, 0 } },
{ { 0, 255, 0, 255 }, { 0, 255, 0, 0 } }, { { 0, 255, 0, 255 }, { 0, 255, 0, 0 } },
{ { 0, 255, 0, 255 }, { 0, 255, 0, 0 } },
};
// unused
Gfx D_80115FF0[] = {
gsSPEndDisplayList(),
};
void func_8002BE64(TargetContext* targetCtx, s32 index, f32 arg2, f32 arg3, f32 arg4) {
targetCtx->arr_50[index].pos.x = arg2;
targetCtx->arr_50[index].pos.y = arg3;
targetCtx->arr_50[index].pos.z = arg4;
targetCtx->arr_50[index].unk_0C = targetCtx->unk_44;
}
void func_8002BE98(TargetContext* targetCtx, s32 actorCategory, PlayState* play) {
TargetContextEntry* entry;
NaviColor* naviColor;
s32 i;
Math_Vec3f_Copy(&targetCtx->targetCenterPos, &play->view.eye);
targetCtx->unk_44 = 500.0f;
targetCtx->unk_48 = 0x100;
naviColor = &sNaviColorList[actorCategory];
entry = &targetCtx->arr_50[0];
for (i = 0; i < ARRAY_COUNT(targetCtx->arr_50); i++) {
func_8002BE64(targetCtx, i, 0.0f, 0.0f, 0.0f);
entry->color.r = naviColor->inner.r;
entry->color.g = naviColor->inner.g;
entry->color.b = naviColor->inner.b;
entry++;
}
}
void Actor_SetNaviToActor(TargetContext* targetCtx, Actor* actor, s32 actorCategory, PlayState* play) {
NaviColor* naviColor = &sNaviColorList[actorCategory];
targetCtx->naviRefPos.x = actor->focus.pos.x;
targetCtx->naviRefPos.y = actor->focus.pos.y + (actor->targetArrowOffset * actor->scale.y);
targetCtx->naviRefPos.z = actor->focus.pos.z;
targetCtx->naviInner.r = naviColor->inner.r;
targetCtx->naviInner.g = naviColor->inner.g;
targetCtx->naviInner.b = naviColor->inner.b;
targetCtx->naviInner.a = naviColor->inner.a;
targetCtx->naviOuter.r = naviColor->outer.r;
targetCtx->naviOuter.g = naviColor->outer.g;
targetCtx->naviOuter.b = naviColor->outer.b;
targetCtx->naviOuter.a = naviColor->outer.a;
}
void func_8002C0C0(TargetContext* targetCtx, Actor* actor, PlayState* play) {
targetCtx->arrowPointedActor = NULL;
targetCtx->targetedActor = NULL;
targetCtx->unk_40 = 0.0f;
targetCtx->unk_8C = NULL;
targetCtx->bgmEnemy = NULL;
targetCtx->unk_4B = 0;
targetCtx->unk_4C = 0;
Actor_SetNaviToActor(targetCtx, actor, actor->category, play);
func_8002BE98(targetCtx, actor->category, play);
}
void func_8002C124(TargetContext* targetCtx, PlayState* play) {
Actor* actor = targetCtx->targetedActor;
OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 2029);
if (targetCtx->unk_48 != 0) {
TargetContextEntry* entry;
Player* player;
s16 spCE;
f32 temp1;
Vec3f projTargetCenter;
s32 spB8;
f32 projTargetCappedInvW;
s32 spB0;
s32 spAC;
f32 var1;
f32 var2;
s32 i;
player = GET_PLAYER(play);
spCE = 0xFF;
var1 = 1.0f;
if (targetCtx->unk_4B != 0) {
spB8 = 1;
} else {
spB8 = 3;
}
if (actor != NULL) {
Math_Vec3f_Copy(&targetCtx->targetCenterPos, &actor->focus.pos);
var1 = (500.0f - targetCtx->unk_44) / 420.0f;
} else {
targetCtx->unk_48 -= 120;
if (targetCtx->unk_48 < 0) {
targetCtx->unk_48 = 0;
}
spCE = targetCtx->unk_48;
}
Actor_ProjectPos(play, &targetCtx->targetCenterPos, &projTargetCenter, &projTargetCappedInvW);
projTargetCenter.x = (160 * (projTargetCenter.x * projTargetCappedInvW)) * var1;
projTargetCenter.x = CLAMP(projTargetCenter.x, -320.0f, 320.0f);
projTargetCenter.y = (120 * (projTargetCenter.y * projTargetCappedInvW)) * var1;
projTargetCenter.y = CLAMP(projTargetCenter.y, -240.0f, 240.0f);
projTargetCenter.z = projTargetCenter.z * var1;
targetCtx->unk_4C--;
if (targetCtx->unk_4C < 0) {
targetCtx->unk_4C = 2;
}
func_8002BE64(targetCtx, targetCtx->unk_4C, projTargetCenter.x, projTargetCenter.y, projTargetCenter.z);
if (!(player->stateFlags1 & PLAYER_STATE1_6) || (actor != player->unk_664)) {
OVERLAY_DISP = Gfx_SetupDL(OVERLAY_DISP, SETUPDL_57);
for (spB0 = 0, spAC = targetCtx->unk_4C; spB0 < spB8; spB0++, spAC = (spAC + 1) % 3) {
entry = &targetCtx->arr_50[spAC];
if (entry->unk_0C < 500.0f) {
if (entry->unk_0C <= 120.0f) {
var2 = 0.15f;
} else {
var2 = ((entry->unk_0C - 120.0f) * 0.001f) + 0.15f;
}
Matrix_Translate(entry->pos.x, entry->pos.y, 0.0f, MTXMODE_NEW);
Matrix_Scale(var2, 0.15f, 1.0f, MTXMODE_APPLY);
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, entry->color.r, entry->color.g, entry->color.b, (u8)spCE);
Matrix_RotateZ((targetCtx->unk_4B & 0x7F) * (M_PI / 64), MTXMODE_APPLY);
for (i = 0; i < 4; i++) {
Matrix_RotateZ(M_PI / 2, MTXMODE_APPLY);
Matrix_Push();
Matrix_Translate(entry->unk_0C, entry->unk_0C, 0.0f, MTXMODE_APPLY);
gSPMatrix(OVERLAY_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_actor.c", 2116),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPDisplayList(OVERLAY_DISP++, gZTargetLockOnTriangleDL);
Matrix_Pop();
}
}
spCE -= 0xFF / 3;
if (spCE < 0) {
spCE = 0;
}
}
}
}
actor = targetCtx->unk_94;
if ((actor != NULL) && !(actor->flags & ACTOR_FLAG_27)) {
NaviColor* naviColor = &sNaviColorList[actor->category];
POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_7);
Matrix_Translate(actor->focus.pos.x, actor->focus.pos.y + (actor->targetArrowOffset * actor->scale.y) + 17.0f,
actor->focus.pos.z, MTXMODE_NEW);
Matrix_RotateY(BINANG_TO_RAD((u16)(play->gameplayFrames * 3000)), MTXMODE_APPLY);
Matrix_Scale((iREG(27) + 35) / 1000.0f, (iREG(28) + 60) / 1000.0f, (iREG(29) + 50) / 1000.0f, MTXMODE_APPLY);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, naviColor->inner.r, naviColor->inner.g, naviColor->inner.b, 255);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_actor.c", 2153),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPDisplayList(POLY_XLU_DISP++, gZTargetArrowDL);
}
CLOSE_DISPS(play->state.gfxCtx, "../z_actor.c", 2158);
}
void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, PlayState* play) {
s32 pad;
Actor* unkActor;
s32 actorCategory;
Vec3f projectedFocusPos;
f32 cappedInvWDest;
f32 temp1;
f32 temp2;
f32 temp3;
f32 temp4;
f32 temp5;
f32 temp6;
s32 lockOnSfxId;
unkActor = NULL;
if ((player->unk_664 != NULL) && (player->unk_84B[player->unk_846] == 2)) {
targetCtx->unk_94 = NULL;
} else {
func_80032AF0(play, &play->actorCtx, &unkActor, player);
targetCtx->unk_94 = unkActor;
}
if (targetCtx->unk_8C != NULL) {
unkActor = targetCtx->unk_8C;
targetCtx->unk_8C = NULL;
} else if (actorArg != NULL) {
unkActor = actorArg;
}
if (unkActor != NULL) {
actorCategory = unkActor->category;
} else {
actorCategory = player->actor.category;
}
if ((unkActor != targetCtx->arrowPointedActor) || (actorCategory != targetCtx->activeCategory)) {
targetCtx->arrowPointedActor = unkActor;
targetCtx->activeCategory = actorCategory;
targetCtx->unk_40 = 1.0f;
}
if (unkActor == NULL) {
unkActor = &player->actor;
}
if (Math_StepToF(&targetCtx->unk_40, 0.0f, 0.25f) == 0) {
temp1 = 0.25f / targetCtx->unk_40;
temp2 = unkActor->world.pos.x - targetCtx->naviRefPos.x;
temp3 = (unkActor->world.pos.y + (unkActor->targetArrowOffset * unkActor->scale.y)) - targetCtx->naviRefPos.y;
temp4 = unkActor->world.pos.z - targetCtx->naviRefPos.z;
targetCtx->naviRefPos.x += temp2 * temp1;
targetCtx->naviRefPos.y += temp3 * temp1;
targetCtx->naviRefPos.z += temp4 * temp1;
} else {
Actor_SetNaviToActor(targetCtx, unkActor, actorCategory, play);
}
if ((actorArg != NULL) && (targetCtx->unk_4B == 0)) {
Actor_ProjectPos(play, &actorArg->focus.pos, &projectedFocusPos, &cappedInvWDest);
if (((projectedFocusPos.z <= 0.0f) || (1.0f <= fabsf(projectedFocusPos.x * cappedInvWDest))) ||
(1.0f <= fabsf(projectedFocusPos.y * cappedInvWDest))) {
actorArg = NULL;
}
}
if (actorArg != NULL) {
if (actorArg != targetCtx->targetedActor) {
func_8002BE98(targetCtx, actorArg->category, play);
targetCtx->targetedActor = actorArg;
if (actorArg->id == ACTOR_EN_BOOM) {
targetCtx->unk_48 = 0;
}
lockOnSfxId = CHECK_FLAG_ALL(actorArg->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2) ? NA_SE_SY_LOCK_ON
: NA_SE_SY_LOCK_ON_HUMAN;
Lib_PlaySfx(lockOnSfxId);
}
targetCtx->targetCenterPos.x = actorArg->world.pos.x;
targetCtx->targetCenterPos.y = actorArg->world.pos.y - (actorArg->shape.yOffset * actorArg->scale.y);
targetCtx->targetCenterPos.z = actorArg->world.pos.z;
if (targetCtx->unk_4B == 0) {
temp5 = (500.0f - targetCtx->unk_44) * 3.0f;
temp6 = (temp5 < 30.0f) ? 30.0f : ((100.0f < temp5) ? 100.0f : temp5);
if (Math_StepToF(&targetCtx->unk_44, 80.0f, temp6) != 0) {
targetCtx->unk_4B++;
}
} else {
targetCtx->unk_4B = (targetCtx->unk_4B + 3) | 0x80;
targetCtx->unk_44 = 120.0f;
}
} else {
targetCtx->targetedActor = NULL;
Math_StepToF(&targetCtx->unk_44, 500.0f, 80.0f);
}
}
/**
* Tests if current scene switch flag is set.
*/
s32 Flags_GetSwitch(PlayState* play, s32 flag) {
if (flag < 0x20) {
return play->actorCtx.flags.swch & (1 << flag);
} else {
return play->actorCtx.flags.tempSwch & (1 << (flag - 0x20));
}
}
/**
* Sets current scene switch flag.
*/
void Flags_SetSwitch(PlayState* play, s32 flag) {
if (flag < 0x20) {
play->actorCtx.flags.swch |= (1 << flag);
} else {
play->actorCtx.flags.tempSwch |= (1 << (flag - 0x20));
}
}
/**
* Unsets current scene switch flag.
*/
void Flags_UnsetSwitch(PlayState* play, s32 flag) {
if (flag < 0x20) {
play->actorCtx.flags.swch &= ~(1 << flag);
} else {
play->actorCtx.flags.tempSwch &= ~(1 << (flag - 0x20));
}
}
/**
* Tests if unknown flag is set.
*/
s32 Flags_GetUnknown(PlayState* play, s32 flag) {
if (flag < 0x20) {
return play->actorCtx.flags.unk0 & (1 << flag);
} else {
return play->actorCtx.flags.unk1 & (1 << (flag - 0x20));
}
}
/**
* Sets unknown flag.
*/
void Flags_SetUnknown(PlayState* play, s32 flag) {
if (flag < 0x20) {
play->actorCtx.flags.unk0 |= (1 << flag);
} else {
play->actorCtx.flags.unk1 |= (1 << (flag - 0x20));
}
}
/**
* Unsets unknown flag.
*/
void Flags_UnsetUnknown(PlayState* play, s32 flag) {
if (flag < 0x20) {
play->actorCtx.flags.unk0 &= ~(1 << flag);
} else {
play->actorCtx.flags.unk1 &= ~(1 << (flag - 0x20));
}
}
/**
* Tests if current scene chest flag is set.
*/
s32 Flags_GetTreasure(PlayState* play, s32 flag) {
return play->actorCtx.flags.chest & (1 << flag);
}
/**
* Sets current scene chest flag.
*/
void Flags_SetTreasure(PlayState* play, s32 flag) {
play->actorCtx.flags.chest |= (1 << flag);
}
/**
* Tests if current scene clear flag is set.
*/
s32 Flags_GetClear(PlayState* play, s32 flag) {
return play->actorCtx.flags.clear & (1 << flag);
}
/**
* Sets current scene clear flag.
*/
void Flags_SetClear(PlayState* play, s32 flag) {
play->actorCtx.flags.clear |= (1 << flag);
}
/**
* Unsets current scene clear flag.
*/
void Flags_UnsetClear(PlayState* play, s32 flag) {
play->actorCtx.flags.clear &= ~(1 << flag);
}
/**
* Tests if current scene temp clear flag is set.
*/
s32 Flags_GetTempClear(PlayState* play, s32 flag) {
return play->actorCtx.flags.tempClear & (1 << flag);
}
/**
* Sets current scene temp clear flag.
*/
void Flags_SetTempClear(PlayState* play, s32 flag) {
play->actorCtx.flags.tempClear |= (1 << flag);
}
/**
* Unsets current scene temp clear flag.
*/
void Flags_UnsetTempClear(PlayState* play, s32 flag) {
play->actorCtx.flags.tempClear &= ~(1 << flag);
}
/**
* Tests if current scene collectible flag is set.
*/
s32 Flags_GetCollectible(PlayState* play, s32 flag) {
if (flag < 0x20) {
return play->actorCtx.flags.collect & (1 << flag);
} else {
return play->actorCtx.flags.tempCollect & (1 << (flag - 0x20));
}
}
/**
* Sets current scene collectible flag.
*/
void Flags_SetCollectible(PlayState* play, s32 flag) {
if (flag != 0) {
if (flag < 0x20) {
play->actorCtx.flags.collect |= (1 << flag);
} else {
play->actorCtx.flags.tempCollect |= (1 << (flag - 0x20));
}
}
}
void TitleCard_Init(PlayState* play, TitleCardContext* titleCtx) {
titleCtx->durationTimer = titleCtx->delayTimer = titleCtx->intensity = titleCtx->alpha = 0;
}
void TitleCard_InitBossName(PlayState* play, TitleCardContext* titleCtx, void* texture, s16 x, s16 y, u8 width,
u8 height) {
titleCtx->texture = texture;
titleCtx->x = x;
titleCtx->y = y;
titleCtx->width = width;
titleCtx->height = height;
titleCtx->durationTimer = 80;
titleCtx->delayTimer = 0;
}
void TitleCard_InitPlaceName(PlayState* play, TitleCardContext* titleCtx, void* texture, s32 x, s32 y, s32 width,
s32 height, s32 delay) {
SceneTableEntry* loadedScene = play->loadedScene;
u32 size = loadedScene->titleFile.vromEnd - loadedScene->titleFile.vromStart;
if ((size != 0) && (size <= 0x3000)) {
DmaMgr_RequestSyncDebug(texture, loadedScene->titleFile.vromStart, size, "../z_actor.c", 2765);
}
titleCtx->texture = texture;
titleCtx->x = x;
titleCtx->y = y;
titleCtx->width = width;
titleCtx->height = height;
titleCtx->durationTimer = 80;
titleCtx->delayTimer = delay;
}
void TitleCard_Update(PlayState* play, TitleCardContext* titleCtx) {
if (DECR(titleCtx->delayTimer) == 0) {
if (DECR(titleCtx->durationTimer) == 0) {
Math_StepToS(&titleCtx->alpha, 0, 30);
Math_StepToS(&titleCtx->intensity, 0, 70);
} else {
Math_StepToS(&titleCtx->alpha, 255, 10);
Math_StepToS(&titleCtx->intensity, 255, 20);
}
}
}
void TitleCard_Draw(PlayState* play, TitleCardContext* titleCtx) {
s32 width;
s32 height;
s32 unused;
s32 titleX;
s32 doubleWidth;
s32 titleY;
s32 titleSecondY;
s32 textureLanguageOffset;
if (titleCtx->alpha != 0) {
width = titleCtx->width;
height = titleCtx->height;
titleX = (titleCtx->x * 4) - (width * 2);
titleY = (titleCtx->y * 4) - (height * 2);
doubleWidth = width * 2;
OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 2824);
textureLanguageOffset = width * height * gSaveContext.language;
height = (width * height > 0x1000) ? 0x1000 / width : height;
titleSecondY = titleY + (height * 4);
OVERLAY_DISP = Gfx_SetupDL_52NoCD(OVERLAY_DISP);
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, (u8)titleCtx->intensity, (u8)titleCtx->intensity, (u8)titleCtx->intensity,
(u8)titleCtx->alpha);
gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + textureLanguageOffset, G_IM_FMT_IA, G_IM_SIZ_8b,
width, height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK,
G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gSPTextureRectangle(OVERLAY_DISP++, titleX, titleY, ((doubleWidth * 2) + titleX) - 4, titleY + (height * 4) - 1,
G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
height = titleCtx->height - height;
// If texture is bigger than 0x1000, display the rest
if (height > 0) {
gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + textureLanguageOffset + 0x1000, G_IM_FMT_IA,
G_IM_SIZ_8b, width, height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gSPTextureRectangle(OVERLAY_DISP++, titleX, titleSecondY, ((doubleWidth * 2) + titleX) - 4,
titleSecondY + (height * 4) - 1, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
}
CLOSE_DISPS(play->state.gfxCtx, "../z_actor.c", 2880);
}
}
s32 TitleCard_Clear(PlayState* play, TitleCardContext* titleCtx) {
if ((play->actorCtx.titleCtx.delayTimer != 0) || (play->actorCtx.titleCtx.alpha != 0)) {
titleCtx->durationTimer = 0;
titleCtx->delayTimer = 0;
return false;
}
return true;
}
void Actor_Kill(Actor* actor) {
actor->draw = NULL;
actor->update = NULL;
actor->flags &= ~ACTOR_FLAG_0;
}
void Actor_SetWorldToHome(Actor* actor) {
actor->world = actor->home;
}
void Actor_SetFocus(Actor* actor, f32 yOffset) {
actor->focus.pos.x = actor->world.pos.x;
actor->focus.pos.y = actor->world.pos.y + yOffset;
actor->focus.pos.z = actor->world.pos.z;
actor->focus.rot.x = actor->world.rot.x;
actor->focus.rot.y = actor->world.rot.y;
actor->focus.rot.z = actor->world.rot.z;
}
void Actor_SetWorldRotToShape(Actor* actor) {
actor->world.rot = actor->shape.rot;
}
void Actor_SetShapeRotToWorld(Actor* actor) {
actor->shape.rot = actor->world.rot;
}
void Actor_SetScale(Actor* actor, f32 scale) {
actor->scale.z = scale;
actor->scale.y = scale;
actor->scale.x = scale;
}
void Actor_SetObjectDependency(PlayState* play, Actor* actor) {
gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.status[actor->objBankIndex].segment);
}
void Actor_Init(Actor* actor, PlayState* play) {
Actor_SetWorldToHome(actor);
Actor_SetShapeRotToWorld(actor);
Actor_SetFocus(actor, 0.0f);
Math_Vec3f_Copy(&actor->prevPos, &actor->world.pos);
Actor_SetScale(actor, 0.01f);
actor->targetMode = 3;
actor->minVelocityY = -20.0f;
actor->xyzDistToPlayerSq = FLT_MAX;
actor->naviEnemyId = NAVI_ENEMY_NONE;
actor->uncullZoneForward = 1000.0f;
actor->uncullZoneScale = 350.0f;
actor->uncullZoneDownward = 700.0f;
CollisionCheck_InitInfo(&actor->colChkInfo);
actor->floorBgId = BGCHECK_SCENE;
ActorShape_Init(&actor->shape, 0.0f, NULL, 0.0f);
if (Object_IsLoaded(&play->objectCtx, actor->objBankIndex)) {
Actor_SetObjectDependency(play, actor);
actor->init(actor, play);
actor->init = NULL;
}
}
void Actor_Destroy(Actor* actor, PlayState* play) {
ActorOverlay* overlayEntry;
char* name;
if (actor->destroy != NULL) {
actor->destroy(actor, play);
actor->destroy = NULL;
} else {
overlayEntry = actor->overlayEntry;
name = overlayEntry->name != NULL ? overlayEntry->name : "";
// "No Actor class destruct [%s]"
osSyncPrintf("Actorクラス デストラクトがありません [%s]\n" VT_RST, name);
}
}
void func_8002D7EC(Actor* actor) {
f32 speedRate = R_UPDATE_RATE * 0.5f;
actor->world.pos.x += (actor->velocity.x * speedRate) + actor->colChkInfo.displacement.x;
actor->world.pos.y += (actor->velocity.y * speedRate) + actor->colChkInfo.displacement.y;
actor->world.pos.z += (actor->velocity.z * speedRate) + actor->colChkInfo.displacement.z;
}
void func_8002D868(Actor* actor) {
actor->velocity.x = Math_SinS(actor->world.rot.y) * actor->speedXZ;
actor->velocity.z = Math_CosS(actor->world.rot.y) * actor->speedXZ;
actor->velocity.y += actor->gravity;
if (actor->velocity.y < actor->minVelocityY) {
actor->velocity.y = actor->minVelocityY;
}
}
void Actor_MoveForward(Actor* actor) {
func_8002D868(actor);
func_8002D7EC(actor);
}
void func_8002D908(Actor* actor) {
f32 sp24 = Math_CosS(actor->world.rot.x) * actor->speedXZ;
actor->velocity.x = Math_SinS(actor->world.rot.y) * sp24;
actor->velocity.y = Math_SinS(actor->world.rot.x) * actor->speedXZ;
actor->velocity.z = Math_CosS(actor->world.rot.y) * sp24;
}
void func_8002D97C(Actor* actor) {
func_8002D908(actor);
func_8002D7EC(actor);
}
void func_8002D9A4(Actor* actor, f32 arg1) {
actor->speedXZ = Math_CosS(actor->world.rot.x) * arg1;
actor->velocity.y = -Math_SinS(actor->world.rot.x) * arg1;
}
void func_8002D9F8(Actor* actor, SkelAnime* skelAnime) {
Vec3f sp1C;
SkelAnime_UpdateTranslation(skelAnime, &sp1C, actor->shape.rot.y);
actor->world.pos.x += sp1C.x * actor->scale.x;
actor->world.pos.y += sp1C.y * actor->scale.y;
actor->world.pos.z += sp1C.z * actor->scale.z;
}
s16 Actor_WorldYawTowardActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_Yaw(&actorA->world.pos, &actorB->world.pos);
}
s16 Actor_FocusYawTowardActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_Yaw(&actorA->focus.pos, &actorB->focus.pos);
}
s16 Actor_WorldYawTowardPoint(Actor* actor, Vec3f* refPoint) {
return Math_Vec3f_Yaw(&actor->world.pos, refPoint);
}
s16 Actor_WorldPitchTowardActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_Pitch(&actorA->world.pos, &actorB->world.pos);
}
s16 Actor_FocusPitchTowardActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_Pitch(&actorA->focus.pos, &actorB->focus.pos);
}
s16 Actor_WorldPitchTowardPoint(Actor* actor, Vec3f* refPoint) {
return Math_Vec3f_Pitch(&actor->world.pos, refPoint);
}
f32 Actor_WorldDistXYZToActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_DistXYZ(&actorA->world.pos, &actorB->world.pos);
}
f32 Actor_WorldDistXYZToPoint(Actor* actor, Vec3f* refPoint) {
return Math_Vec3f_DistXYZ(&actor->world.pos, refPoint);
}
f32 Actor_WorldDistXZToActor(Actor* actorA, Actor* actorB) {
return Math_Vec3f_DistXZ(&actorA->world.pos, &actorB->world.pos);
}
f32 Actor_WorldDistXZToPoint(Actor* actor, Vec3f* refPoint) {
return Math_Vec3f_DistXZ(&actor->world.pos, refPoint);
}
/**
* Convert `pos` to be relative to the actor's position and yaw, store into `dest`.
* Actor_WorldToActorCoords
*/
void func_8002DBD0(Actor* actor, Vec3f* dest, Vec3f* pos) {
f32 cosY;
f32 sinY;
f32 deltaX;
f32 deltaZ;
cosY = Math_CosS(actor->shape.rot.y);
sinY = Math_SinS(actor->shape.rot.y);
deltaX = pos->x - actor->world.pos.x;
deltaZ = pos->z - actor->world.pos.z;
dest->x = (deltaX * cosY) - (deltaZ * sinY);
dest->z = (deltaX * sinY) + (deltaZ * cosY);
dest->y = pos->y - actor->world.pos.y;
}
f32 Actor_HeightDiff(Actor* actorA, Actor* actorB) {
return actorB->world.pos.y - actorA->world.pos.y;
}
f32 Player_GetHeight(Player* player) {
f32 offset = (player->stateFlags1 & PLAYER_STATE1_23) ? 32.0f : 0.0f;
if (LINK_IS_ADULT) {
return offset + 68.0f;
} else {
return offset + 44.0f;
}
}
f32 func_8002DCE4(Player* player) {
if (player->stateFlags1 & PLAYER_STATE1_23) {
return 8.0f;
} else if (player->stateFlags1 & PLAYER_STATE1_27) {
return (R_RUN_SPEED_LIMIT / 100.0f) * 0.6f;
} else {
return R_RUN_SPEED_LIMIT / 100.0f;
}
}
s32 func_8002DD6C(Player* player) {
return player->stateFlags1 & PLAYER_STATE1_3;
}
s32 func_8002DD78(Player* player) {
return func_8002DD6C(player) && player->unk_834;
}
s32 func_8002DDA8(PlayState* play) {
Player* player = GET_PLAYER(play);
return (player->stateFlags1 & PLAYER_STATE1_11) || func_8002DD78(player);
}
s32 func_8002DDE4(PlayState* play) {
Player* player = GET_PLAYER(play);
return player->stateFlags2 & PLAYER_STATE2_3;
}
s32 func_8002DDF4(PlayState* play) {
Player* player = GET_PLAYER(play);