From 42f515dd4c3b9d9d0c26bbb8bada69c56534c920 Mon Sep 17 00:00:00 2001 From: Egor Ananyin Date: Wed, 18 Mar 2020 16:01:00 +0300 Subject: [PATCH] z_actor.c: Some functions --- src/code/z_actor.c | 48 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 32620752db..832fc5b643 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1,7 +1,9 @@ #include #include -#define DECR(x) ((x) == 0 ? 0 : ((x) -= 1)) //From OOT +//From OOT +#define ABS(x) ((x) < 0 ? -(x) : (x)) +#define DECR(x) ((x) == 0 ? 0 : ((x) -= 1)) GLOBAL_ASM("asm/non_matchings/z_actor//Actor_PrintLists.asm") @@ -406,15 +408,51 @@ GLOBAL_ASM("asm/non_matchings/z_actor//func_800B72F8.asm") GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsLinkFacingActor.asm") -GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsActorFacedByActor.asm") +s32 Actor_IsActorFacedByActor(Actor* actor, Actor* other, s16 tolerance) { + s16 angle; + s16 dist; -GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsActorFacingLink.asm") + angle = Actor_YawBetweenActors(actor, other) + 0x8000; + dist = angle - other->shape.rot.y; + if (ABS(dist) < tolerance) { + return 1; + } + return 0; +} -GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsActorFacingActor.asm") +s32 Actor_IsActorFacingLink(Actor* actor, s16 angle) { + s16 dist; + + dist = actor->rotTowardsLinkY - actor->shape.rot.y; + if (ABS(dist) < angle) { + return 1; + } + return 0; +} + +s32 Actor_IsActorFacingActor(Actor* actor, Actor* other, s16 tolerance) { + s16 dist; + + dist = Actor_YawBetweenActors(actor, other) - actor->shape.rot.y; + if (ABS(dist) < tolerance) { + return 1; + } + return 0; +} GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsActorFacingLinkAndWithinRange.asm") -GLOBAL_ASM("asm/non_matchings/z_actor//Actor_IsActorFacingActorAndWithinRange.asm") +s32 Actor_IsActorFacingActorAndWithinRange(Actor* actor, Actor* other, f32 range, s16 tolerance) { + s16 dist; + + if (Actor_DistanceBetweenActors(actor, other) < range) { + dist = Actor_YawBetweenActors(actor, other) - actor->shape.rot.y; + if (ABS(dist) < tolerance) { + return 1; + } + } + return 0; +} GLOBAL_ASM("asm/non_matchings/z_actor//func_800B75A0.asm")