From d7bbe43ba7734da2e28614debeaf521b4bcb5013 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Fri, 20 May 2022 19:54:47 +0200 Subject: [PATCH] Document `eventChkInf` usage of freed carpenters flags (#1210) * Document `eventChkInf` usage of freed carpenters flags * +`()` --- include/z64save.h | 25 +++++++++---------- src/code/z_map_exp.c | 9 ++----- .../ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c | 7 ++---- src/overlays/actors/ovl_En_Daiku/z_en_daiku.c | 18 ++++++------- src/overlays/actors/ovl_En_Ge1/z_en_ge1.c | 10 +++----- src/overlays/actors/ovl_En_Ge2/z_en_ge2.c | 7 +++--- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 7 ++---- src/overlays/actors/ovl_En_Mm2/z_en_mm2.c | 3 +-- src/overlays/actors/ovl_En_Toryo/z_en_toryo.c | 3 +-- 9 files changed, 36 insertions(+), 53 deletions(-) diff --git a/include/z64save.h b/include/z64save.h index ae2d7de2f5..7ff3d212e4 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -338,19 +338,18 @@ typedef enum { #define EVENTCHKINF_8F 0x8F // 0x90-0x93 -#define EVENTCHKINF_90_91_92_93_INDEX 9 -#define EVENTCHKINF_90_SHIFT 0 -#define EVENTCHKINF_91_SHIFT 1 -#define EVENTCHKINF_92_SHIFT 2 -#define EVENTCHKINF_93_SHIFT 3 -#define EVENTCHKINF_90_MASK (1 << EVENTCHKINF_90_SHIFT) -#define EVENTCHKINF_91_MASK (1 << EVENTCHKINF_91_SHIFT) -#define EVENTCHKINF_92_MASK (1 << EVENTCHKINF_92_SHIFT) -#define EVENTCHKINF_93_MASK (1 << EVENTCHKINF_93_SHIFT) -#define EVENTCHKINF_90 ((EVENTCHKINF_90_91_92_93_INDEX << 4) | EVENTCHKINF_90_SHIFT) -#define EVENTCHKINF_91 ((EVENTCHKINF_90_91_92_93_INDEX << 4) | EVENTCHKINF_91_SHIFT) -#define EVENTCHKINF_92 ((EVENTCHKINF_90_91_92_93_INDEX << 4) | EVENTCHKINF_92_SHIFT) -#define EVENTCHKINF_93 ((EVENTCHKINF_90_91_92_93_INDEX << 4) | EVENTCHKINF_93_SHIFT) +// carpenters freed from the gerudo +#define EVENTCHKINF_CARPENTERS_FREE_INDEX 9 +#define EVENTCHKINF_CARPENTERS_FREE_SHIFT(n) (0 + (n)) +#define EVENTCHKINF_CARPENTERS_FREE_MASK(n) (1 << EVENTCHKINF_CARPENTERS_FREE_SHIFT(n)) +#define EVENTCHKINF_CARPENTERS_FREE(n) ((EVENTCHKINF_CARPENTERS_FREE_INDEX << 4) | EVENTCHKINF_CARPENTERS_FREE_SHIFT(n)) +#define EVENTCHKINF_CARPENTERS_FREE_MASK_ALL (\ + EVENTCHKINF_CARPENTERS_FREE_MASK(0) \ + | EVENTCHKINF_CARPENTERS_FREE_MASK(1) \ + | EVENTCHKINF_CARPENTERS_FREE_MASK(2) \ + | EVENTCHKINF_CARPENTERS_FREE_MASK(3) ) +#define GET_EVENTCHKINF_CARPENTERS_FREE_ALL() \ + CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_CARPENTERS_FREE_INDEX], EVENTCHKINF_CARPENTERS_FREE_MASK_ALL) #define EVENTCHKINF_94 0x94 #define EVENTCHKINF_95 0x95 diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c index 1e0e818e2e..144f830ecc 100644 --- a/src/code/z_map_exp.c +++ b/src/code/z_map_exp.c @@ -118,16 +118,11 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) { extendedMapIndex = 0x15; } } else if (globalCtx->sceneNum == SCENE_SPOT09) { - if ((LINK_AGE_IN_YEARS == YEARS_ADULT) && - !CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | - EVENTCHKINF_93_MASK)) { + if ((LINK_AGE_IN_YEARS == YEARS_ADULT) && !GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { extendedMapIndex = 0x16; } } else if (globalCtx->sceneNum == SCENE_SPOT12) { - if (CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | - EVENTCHKINF_93_MASK)) { + if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { extendedMapIndex = 0x17; } } diff --git a/src/overlays/actors/ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c b/src/overlays/actors/ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c index bddc4f7036..5c3f1a1ca0 100644 --- a/src/overlays/actors/ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c +++ b/src/overlays/actors/ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c @@ -63,9 +63,7 @@ s32 func_808B1AE0(BgSpot09Obj* this, GlobalContext* globalCtx) { return this->dyna.actor.params == 0; } - carpentersRescued = - CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK); + carpentersRescued = GET_EVENTCHKINF_CARPENTERS_FREE_ALL(); if (LINK_AGE_IN_YEARS == YEARS_ADULT) { switch (this->dyna.actor.params) { @@ -140,8 +138,7 @@ void BgSpot09Obj_Init(Actor* thisx, GlobalContext* globalCtx) { BgSpot09Obj* this = (BgSpot09Obj*)thisx; osSyncPrintf("Spot09 Object [arg_data : 0x%04x](大工救出フラグ 0x%x)\n", this->dyna.actor.params, - gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX] & - (EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)); + gSaveContext.eventChkInf[EVENTCHKINF_CARPENTERS_FREE_INDEX] & EVENTCHKINF_CARPENTERS_FREE_MASK_ALL); this->dyna.actor.params &= 0xFF; if ((this->dyna.actor.params < 0) || (this->dyna.actor.params >= 5)) { osSyncPrintf("Error : Spot 09 object の arg_data が判別出来ない(%s %d)(arg_data 0x%04x)\n", diff --git a/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c b/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c index 5485bab99e..8c518cf602 100644 --- a/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c +++ b/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c @@ -152,13 +152,13 @@ void EnDaiku_Init(Actor* thisx, GlobalContext* globalCtx) { s32 noKill = true; s32 isFree = false; - if ((this->actor.params & 3) == 0 && GET_EVENTCHKINF(EVENTCHKINF_90)) { + if ((this->actor.params & 3) == 0 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(0))) { isFree = true; - } else if ((this->actor.params & 3) == 1 && GET_EVENTCHKINF(EVENTCHKINF_91)) { + } else if ((this->actor.params & 3) == 1 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(1))) { isFree = true; - } else if ((this->actor.params & 3) == 2 && GET_EVENTCHKINF(EVENTCHKINF_92)) { + } else if ((this->actor.params & 3) == 2 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(2))) { isFree = true; - } else if ((this->actor.params & 3) == 3 && GET_EVENTCHKINF(EVENTCHKINF_93)) { + } else if ((this->actor.params & 3) == 3 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(3))) { isFree = true; } @@ -271,8 +271,8 @@ void EnDaiku_UpdateText(EnDaiku* this, GlobalContext* globalCtx) { if (this->stateFlags & ENDAIKU_STATEFLAG_GERUDODEFEATED) { freedCount = 0; for (carpenterType = 0; carpenterType < 4; carpenterType++) { - if (gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX] & - (1 << (carpenterType + EVENTCHKINF_90_SHIFT))) { + if (gSaveContext.eventChkInf[EVENTCHKINF_CARPENTERS_FREE_INDEX] & + EVENTCHKINF_CARPENTERS_FREE_MASK(carpenterType)) { freedCount++; } } @@ -400,7 +400,8 @@ void EnDaiku_InitEscape(EnDaiku* this, GlobalContext* globalCtx) { EnDaiku_ChangeAnim(this, ENDAIKU_ANIM_RUN, &this->currentAnimIndex); this->stateFlags &= ~(ENDAIKU_STATEFLAG_1 | ENDAIKU_STATEFLAG_2); - gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX] |= 1 << ((this->actor.params & 3) + EVENTCHKINF_90_SHIFT); + gSaveContext.eventChkInf[EVENTCHKINF_CARPENTERS_FREE_INDEX] |= + EVENTCHKINF_CARPENTERS_FREE_MASK(this->actor.params & 3); this->actor.gravity = -1.0f; this->escapeSubCamTimer = sEscapeSubCamParams[this->actor.params & 3].maxFramesActive; @@ -495,8 +496,7 @@ void EnDaiku_EscapeSuccess(EnDaiku* this, GlobalContext* globalCtx) { Play_ChangeCameraStatus(globalCtx, CAM_ID_MAIN, CAM_STAT_ACTIVE); this->subCamActive = false; - if (CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { Matrix_RotateY(BINANG_TO_RAD(this->initRot.y), MTXMODE_NEW); Matrix_MultVec3f(&D_809E4148, &vec); gerudoGuard = diff --git a/src/overlays/actors/ovl_En_Ge1/z_en_ge1.c b/src/overlays/actors/ovl_En_Ge1/z_en_ge1.c index 59ba65b313..30f0ba391a 100644 --- a/src/overlays/actors/ovl_En_Ge1/z_en_ge1.c +++ b/src/overlays/actors/ovl_En_Ge1/z_en_ge1.c @@ -209,13 +209,11 @@ void EnGe1_SetAnimationIdle(EnGe1* this) { } s32 EnGe1_CheckCarpentersFreed(void) { - u16 carpenterFlags = gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX]; - - if (!((carpenterFlags & EVENTCHKINF_90_MASK) && (carpenterFlags & EVENTCHKINF_91_MASK) && - (carpenterFlags & EVENTCHKINF_92_MASK) && (carpenterFlags & EVENTCHKINF_93_MASK))) { - return 0; + if (!(GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(0)) && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(1)) && + GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(2)) && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(3)))) { + return false; } - return 1; + return true; } /** diff --git a/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c b/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c index 8421157ef8..1adb43a525 100644 --- a/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c +++ b/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c @@ -223,10 +223,9 @@ s32 Ge2_DetectPlayerInUpdate(GlobalContext* globalCtx, EnGe2* this, Vec3f* pos, } s32 EnGe2_CheckCarpentersFreed(void) { - if (CHECK_FLAG_ALL( - gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX] & - (EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK | 0xF0), - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_CARPENTERS_FREE_INDEX] & + (EVENTCHKINF_CARPENTERS_FREE_MASK_ALL | 0xF0), + EVENTCHKINF_CARPENTERS_FREE_MASK_ALL)) { return 1; } return 0; diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index f3f052b8fe..c5af12f99e 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -461,8 +461,7 @@ s32 EnHorse_BgCheckBridgeJumpPoint(EnHorse* this, GlobalContext* globalCtx) { if (this->actor.speedXZ < 12.8f) { return false; } - if (CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { return false; } @@ -3578,9 +3577,7 @@ void EnHorse_Update(Actor* thisx, GlobalContext* globalCtx2) { this->stateFlags &= ~ENHORSE_FLAG_24; } - if (globalCtx->sceneNum == SCENE_SPOT09 && - !CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (globalCtx->sceneNum == SCENE_SPOT09 && !GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { EnHorse_CheckBridgeJumps(this, globalCtx); } diff --git a/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c b/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c index 3874979ddd..9ed89f7991 100644 --- a/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c +++ b/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c @@ -100,8 +100,7 @@ void EnMm2_ChangeAnim(EnMm2* this, s32 index, s32* currentIndex) { } void func_80AAEF70(EnMm2* this, GlobalContext* globalCtx) { - if (!CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (!GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { this->actor.textId = 0x6086; } else if (GET_INFTABLE(INFTABLE_17F)) { if (GET_EVENTINF(EVENTINF_10)) { diff --git a/src/overlays/actors/ovl_En_Toryo/z_en_toryo.c b/src/overlays/actors/ovl_En_Toryo/z_en_toryo.c index 109574b205..a606b526ff 100644 --- a/src/overlays/actors/ovl_En_Toryo/z_en_toryo.c +++ b/src/overlays/actors/ovl_En_Toryo/z_en_toryo.c @@ -259,8 +259,7 @@ s32 func_80B206A0(EnToryo* this, GlobalContext* globalCtx) { if (textId == 0) { if (this->stateFlags & 1) { - if (CHECK_FLAG_ALL(gSaveContext.eventChkInf[EVENTCHKINF_90_91_92_93_INDEX], - EVENTCHKINF_90_MASK | EVENTCHKINF_91_MASK | EVENTCHKINF_92_MASK | EVENTCHKINF_93_MASK)) { + if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { ret = 0x606C; } else if (GET_INFTABLE(INFTABLE_170)) { ret = 0x606B;