summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorDerek Hensley <hensley.derek58@gmail.com>2022-01-03 23:28:25 -0800
committerGitHub <noreply@github.com>2022-01-04 07:28:25 +0000
commit7611d833d9db0883ecfd94630c0e2a86cf089aa7 (patch)
treecaf6cfaf4c7a591dd075115f02625dcf6c8d40a9 /src/code
parentbe952305d81eb50ffd3d6e7c1361de2f02881b0d (diff)
SubS Actor Getters OK (#475)
* Bring over matching actor getters * Add arg names * Rename functions * Adjust rename_sym script to update sizes csvs * Fix wrong function prototype * whitespace * Rename functions * Fix actorfixer * Format * Add function comments and file header * Fix merge * format * Fix merge * format * Move D_0407D590 down * Fix merge * Steal idea from z_actor PR to return directly * Swap function name order * Fix merge
Diffstat (limited to 'src/code')
-rw-r--r--src/code/z_en_hy.c2
-rw-r--r--src/code/z_sub_s.c110
2 files changed, 107 insertions, 5 deletions
diff --git a/src/code/z_en_hy.c b/src/code/z_en_hy.c
index 73adc5fa5..323dc14f8 100644
--- a/src/code/z_en_hy.c
+++ b/src/code/z_en_hy.c
@@ -66,7 +66,7 @@ Actor* EnHy_FindNearestDoor(Actor* actor, GlobalContext* globalCtx) {
f32 minDist = 0.0f;
do {
- doorIter = func_ActorCategoryIterateById(globalCtx, doorIter, ACTORCAT_DOOR, ACTOR_EN_DOOR);
+ doorIter = SubS_FindActor(globalCtx, doorIter, ACTORCAT_DOOR, ACTOR_EN_DOOR);
door = doorIter;
dist = Actor_DistanceBetweenActors(actor, door);
if (!isSetup || (dist < minDist)) {
diff --git a/src/code/z_sub_s.c b/src/code/z_sub_s.c
index 1ab44acc1..3255b86d8 100644
--- a/src/code/z_sub_s.c
+++ b/src/code/z_sub_s.c
@@ -1,6 +1,40 @@
+/*
+ * File: z_sub_s.c
+ * Description: Various miscellaneous helpers
+ */
+
#include "global.h"
+#include "overlays/actors/ovl_En_Door/z_en_door.h"
+
+/**
+ * Finds the first EnDoor instance with unk_1A4 == 5 and the specified unk_1A5.
+ */
+EnDoor* SubS_FindDoor(GlobalContext* globalCtx, s32 unk_1A5) {
+ Actor* actor = NULL;
+ EnDoor* door;
+
+ while (true) {
+ actor = SubS_FindActor(globalCtx, actor, ACTORCAT_DOOR, ACTOR_EN_DOOR);
+ door = (EnDoor*)actor;
+
+ if (actor == NULL) {
+ break;
+ }
+
+ if ((door->unk_1A4 == 5) && (door->unk_1A5 == (u8)unk_1A5)) {
+ break;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013A7C0.s")
+ if (actor->next == NULL) {
+ door = NULL;
+ break;
+ }
+
+ actor = actor->next;
+ }
+
+ return door;
+}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013A860.s")
@@ -26,7 +60,40 @@
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013BB34.s")
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013BB7C.s")
+/**
+ * Finds the nearest actor instance of a specified Id and category to an actor.
+ */
+Actor* SubS_FindNearestActor(Actor* actor, GlobalContext* globalCtx, u8 actorCategory, s16 actorId) {
+ Actor* actorIter = NULL;
+ Actor* actorTmp;
+ f32 dist;
+ Actor* closestActor = NULL;
+ f32 minDist = 99999.0f;
+ s32 isSetup = false;
+
+ do {
+ actorIter = SubS_FindActor(globalCtx, actorIter, actorCategory, actorId);
+
+ actorTmp = actorIter;
+ if (actorTmp == NULL) {
+ break;
+ }
+ actorIter = actorTmp;
+
+ if (actorIter != actor) {
+ dist = Actor_DistanceBetweenActors(actor, actorIter);
+ if (!isSetup || dist < minDist) {
+ closestActor = actorIter;
+ minDist = dist;
+ isSetup = true;
+ }
+ }
+
+ actorIter = actorIter->next;
+ } while (actorIter != NULL);
+
+ return closestActor;
+}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013BC6C.s")
@@ -68,7 +135,22 @@
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013D924.s")
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_ActorCategoryIterateById.s")
+/**
+ * Finds the first actor instance of a specified Id and category.
+ */
+Actor* SubS_FindActor(GlobalContext* globalCtx, Actor* actorListStart, u8 actorCategory, s16 actorId) {
+ Actor* actor = actorListStart;
+
+ if (actor == NULL) {
+ actor = globalCtx->actorCtx.actorList[actorCategory].first;
+ }
+
+ while (actor != NULL && actorId != actor->id) {
+ actor = actor->next;
+ }
+
+ return actor;
+}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013D9C8.s")
@@ -100,7 +182,27 @@
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013E5CC.s")
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013E640.s")
+/**
+ * Finds the first actor instance of a specified Id and category verified with a custom callback.
+ * The callback should return `true` when the actor is succesfully verified.
+ */
+Actor* SubS_FindActorCustom(GlobalContext* globalCtx, Actor* actor, Actor* actorListStart, u8 actorCategory,
+ s16 actorId, void* verifyData, VerifyActor verifyActor) {
+ Actor* actorIter = actorListStart;
+
+ if (actorListStart == NULL) {
+ actorIter = globalCtx->actorCtx.actorList[actorCategory].first;
+ }
+
+ while (actorIter != NULL && (actorId != actorIter->id ||
+ (actorId == actorIter->id &&
+ (verifyActor == NULL ||
+ (verifyActor != NULL && !verifyActor(globalCtx, actor, actorIter, verifyData)))))) {
+ actorIter = actorIter->next;
+ }
+
+ return actorIter;
+}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sub_s/func_8013E748.s")