Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure event flags in z64save.h (2/?): Carpenters #2385

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,18 +572,38 @@ typedef enum LinkAge {
#define EVENTCHKINF_PAID_BACK_BUNNY_HOOD 0x8F

// EVENTCHKINF 0x90-0x93
// carpenters freed from the gerudo
#define EVENTCHKINF_INDEX_CARPENTERS_FREE 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_INDEX_CARPENTERS_FREE << 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.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_FREE], EVENTCHKINF_CARPENTERS_FREE_MASK_ALL)
// Carpenters rescued from Gerudo Fortress
#define EVENTCHKINF_INDEX_CARPENTERS_RESCUED 0x9
#define EVENTCHKINF_CARPENTER_0_RESCUED 0x90
#define EVENTCHKINF_CARPENTER_1_RESCUED 0x91
#define EVENTCHKINF_CARPENTER_2_RESCUED 0x92
#define EVENTCHKINF_CARPENTER_3_RESCUED 0x93

#define EVENTCHKINF_CARPENTERS_ALL_RESCUED_MASK \
(EVENTCHKINF_MASK(EVENTCHKINF_CARPENTER_0_RESCUED) | EVENTCHKINF_MASK(EVENTCHKINF_CARPENTER_1_RESCUED) | \
EVENTCHKINF_MASK(EVENTCHKINF_CARPENTER_2_RESCUED) | EVENTCHKINF_MASK(EVENTCHKINF_CARPENTER_3_RESCUED))

#define GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED() \
CHECK_FLAG_ALL(gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_RESCUED], \
EVENTCHKINF_CARPENTERS_ALL_RESCUED_MASK)

#define GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED2() \
CHECK_FLAG_ALL(gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_RESCUED] & \
(EVENTCHKINF_CARPENTERS_ALL_RESCUED_MASK | 0xF0), \
EVENTCHKINF_CARPENTERS_ALL_RESCUED_MASK)

#define ENDAIKU_CARPENTER_RESCUED_MASK(carpenterType) (1 << (carpenterType))

#define ENDAIKU_IS_CARPENTER_RESCUED(carpenterType) \
gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_RESCUED] & \
ENDAIKU_CARPENTER_RESCUED_MASK(carpenterType)

#define ENDAIKU_SET_CARPENTER_RESCUED(carpenterType) \
gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_RESCUED] |= \
ENDAIKU_CARPENTER_RESCUED_MASK((carpenterType))

#define GET_EVENTCHKINF_CARPENTERS_RESCUED_FLAGS() \
gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_RESCUED] & EVENTCHKINF_CARPENTERS_ALL_RESCUED_MASK

#define EVENTCHKINF_94 0x94
#define EVENTCHKINF_95 0x95
Expand Down
4 changes: 2 additions & 2 deletions src/code/z_map_exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ void Map_InitData(PlayState* play, s16 room) {
extendedMapIndex = 0x15;
}
} else if (play->sceneId == SCENE_GERUDO_VALLEY) {
if ((LINK_AGE_IN_YEARS == YEARS_ADULT) && !GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) {
if ((LINK_AGE_IN_YEARS == YEARS_ADULT) && !GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED()) {
extendedMapIndex = 0x16;
}
} else if (play->sceneId == SCENE_GERUDOS_FORTRESS) {
if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) {
if (GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED()) {
extendedMapIndex = 0x17;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/overlays/actors/ovl_Bg_Spot09_Obj/z_bg_spot09_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ s32 func_808B1AE0(BgSpot09Obj* this, PlayState* play) {
return this->dyna.actor.params == 0;
}

carpentersRescued = GET_EVENTCHKINF_CARPENTERS_FREE_ALL();
carpentersRescued = GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED();

if (LINK_AGE_IN_YEARS == YEARS_ADULT) {
switch (this->dyna.actor.params) {
Expand Down Expand Up @@ -138,8 +138,7 @@ void BgSpot09Obj_Init(Actor* thisx, PlayState* play) {
BgSpot09Obj* this = (BgSpot09Obj*)thisx;

PRINTF("Spot09 Object [arg_data : 0x%04x](大工救出フラグ 0x%x)\n", this->dyna.actor.params,
gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_FREE] &
EVENTCHKINF_CARPENTERS_FREE_MASK_ALL);
GET_EVENTCHKINF_CARPENTERS_RESCUED_FLAGS());
this->dyna.actor.params &= 0xFF;
if ((this->dyna.actor.params < 0) || (this->dyna.actor.params >= 5)) {
PRINTF("Error : Spot 09 object の arg_data が判別出来ない(%s %d)(arg_data 0x%04x)\n", "../z_bg_spot09_obj.c",
Expand Down
76 changes: 38 additions & 38 deletions src/overlays/actors/ovl_En_Daiku/z_en_daiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#define FLAGS (ACTOR_FLAG_ATTENTION_ENABLED | ACTOR_FLAG_FRIENDLY | ACTOR_FLAG_UPDATE_CULLING_DISABLED)

#define ENDAIKU_GET_TYPE(thisx) PARAMS_GET_U((thisx)->params, 0, 2)

typedef struct EnDaikuEscapeSubCamParam {
Vec3f eyePosDeltaLocal;
s32 maxFramesActive;
Expand Down Expand Up @@ -150,21 +152,21 @@ void EnDaiku_Init(Actor* thisx, PlayState* play) {
EnDaiku* this = (EnDaiku*)thisx;
s32 pad;
s32 noKill = true;
s32 isFree = false;

if (PARAMS_GET_U(this->actor.params, 0, 2) == 0 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(0))) {
isFree = true;
} else if (PARAMS_GET_U(this->actor.params, 0, 2) == 1 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(1))) {
isFree = true;
} else if (PARAMS_GET_U(this->actor.params, 0, 2) == 2 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(2))) {
isFree = true;
} else if (PARAMS_GET_U(this->actor.params, 0, 2) == 3 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTERS_FREE(3))) {
isFree = true;
s32 isRescued = false;

if (ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE0 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_0_RESCUED)) {
isRescued = true;
} else if (ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE1 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_1_RESCUED)) {
isRescued = true;
} else if (ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE2 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_2_RESCUED)) {
isRescued = true;
} else if (ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE3 && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_3_RESCUED)) {
isRescued = true;
}

if (isFree == true && play->sceneId == SCENE_THIEVES_HIDEOUT) {
if (isRescued == true && play->sceneId == SCENE_THIEVES_HIDEOUT) {
noKill = false;
} else if (!isFree && play->sceneId == SCENE_CARPENTERS_TENT) {
} else if (!isRescued && play->sceneId == SCENE_CARPENTERS_TENT) {
noKill = false;
}

Expand Down Expand Up @@ -200,7 +202,7 @@ void EnDaiku_Init(Actor* thisx, PlayState* play) {
this->stateFlags |= ENDAIKU_STATEFLAG_1 | ENDAIKU_STATEFLAG_2;
this->actionFunc = EnDaiku_Jailed;
} else {
if (PARAMS_GET_U(this->actor.params, 0, 2) == 1 || PARAMS_GET_U(this->actor.params, 0, 2) == 3) {
if (ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE1 || ENDAIKU_GET_TYPE(&this->actor) == ENDAIKU_TYPE3) {
EnDaiku_ChangeAnim(this, ENDAIKU_ANIM_SIT, &this->currentAnimIndex);
this->stateFlags |= ENDAIKU_STATEFLAG_1;
} else {
Expand Down Expand Up @@ -254,7 +256,7 @@ s32 EnDaiku_UpdateTalking(EnDaiku* this, PlayState* play) {

void EnDaiku_UpdateText(EnDaiku* this, PlayState* play) {
s32 carpenterType;
s32 freedCount;
s32 rescuedCount;
s16 sp2E;
s16 sp2C;

Expand All @@ -268,15 +270,14 @@ void EnDaiku_UpdateText(EnDaiku* this, PlayState* play) {
Actor_OfferTalk(&this->actor, play, 100.0f) == 1) {
if (play->sceneId == SCENE_THIEVES_HIDEOUT) {
if (this->stateFlags & ENDAIKU_STATEFLAG_GERUDODEFEATED) {
freedCount = 0;
rescuedCount = 0;
for (carpenterType = 0; carpenterType < 4; carpenterType++) {
if (gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_FREE] &
EVENTCHKINF_CARPENTERS_FREE_MASK(carpenterType)) {
freedCount++;
if (ENDAIKU_IS_CARPENTER_RESCUED(carpenterType)) {
rescuedCount++;
}
}

switch (freedCount) {
switch (rescuedCount) {
case 0:
this->actor.textId = 0x605B;
break;
Expand All @@ -295,15 +296,15 @@ void EnDaiku_UpdateText(EnDaiku* this, PlayState* play) {
this->actor.textId = 0x6007;
}
} else if (play->sceneId == SCENE_CARPENTERS_TENT) {
switch (PARAMS_GET_U(this->actor.params, 0, 2)) {
case 0:
switch (ENDAIKU_GET_TYPE(&this->actor)) {
case ENDAIKU_TYPE0:
if (CHECK_QUEST_ITEM(QUEST_MEDALLION_SPIRIT)) {
this->actor.textId = 0x6060;
} else {
this->actor.textId = 0x605F;
}
break;
case 1:
case ENDAIKU_TYPE1:
if (CHECK_QUEST_ITEM(QUEST_MEDALLION_SPIRIT)) {
this->actor.textId = 0x6063;
} else {
Expand All @@ -314,7 +315,7 @@ void EnDaiku_UpdateText(EnDaiku* this, PlayState* play) {
}
}
break;
case 2:
case ENDAIKU_TYPE2:
if (CHECK_QUEST_ITEM(QUEST_MEDALLION_SPIRIT)) {
this->actor.textId = 0x6066;
} else {
Expand All @@ -325,7 +326,7 @@ void EnDaiku_UpdateText(EnDaiku* this, PlayState* play) {
}
}
break;
case 3:
case ENDAIKU_TYPE3:
if (CHECK_QUEST_ITEM(QUEST_MEDALLION_SPIRIT)) {
this->actor.textId = 0x6068;
} else {
Expand Down Expand Up @@ -385,7 +386,7 @@ void EnDaiku_WaitFreedom(EnDaiku* this, PlayState* play) {
}

/**
* The carpenter is free, initializes his running away animation
* The carpenter is rescued, initializes his running away animation
*/
void EnDaiku_InitEscape(EnDaiku* this, PlayState* play) {
Path* path;
Expand All @@ -399,11 +400,10 @@ void EnDaiku_InitEscape(EnDaiku* this, PlayState* play) {
EnDaiku_ChangeAnim(this, ENDAIKU_ANIM_RUN, &this->currentAnimIndex);
this->stateFlags &= ~(ENDAIKU_STATEFLAG_1 | ENDAIKU_STATEFLAG_2);

gSaveContext.save.info.eventChkInf[EVENTCHKINF_INDEX_CARPENTERS_FREE] |=
EVENTCHKINF_CARPENTERS_FREE_MASK(PARAMS_GET_U(this->actor.params, 0, 2));
ENDAIKU_SET_CARPENTER_RESCUED(ENDAIKU_GET_TYPE(&this->actor));

this->actor.gravity = -1.0f;
this->escapeSubCamTimer = sEscapeSubCamParams[PARAMS_GET_U(this->actor.params, 0, 2)].maxFramesActive;
this->escapeSubCamTimer = sEscapeSubCamParams[ENDAIKU_GET_TYPE(&this->actor)].maxFramesActive;
EnDaiku_InitSubCamera(this, play);

exitLoop = false;
Expand Down Expand Up @@ -444,11 +444,11 @@ void EnDaiku_InitSubCamera(EnDaiku* this, PlayState* play) {
Vec3f eyePosDeltaWorld;

this->subCamActive = true;
this->escapeSubCamTimer = sEscapeSubCamParams[PARAMS_GET_U(this->actor.params, 0, 2)].maxFramesActive;
this->escapeSubCamTimer = sEscapeSubCamParams[ENDAIKU_GET_TYPE(&this->actor)].maxFramesActive;

eyePosDeltaLocal.x = sEscapeSubCamParams[PARAMS_GET_U(this->actor.params, 0, 2)].eyePosDeltaLocal.x;
eyePosDeltaLocal.y = sEscapeSubCamParams[PARAMS_GET_U(this->actor.params, 0, 2)].eyePosDeltaLocal.y;
eyePosDeltaLocal.z = sEscapeSubCamParams[PARAMS_GET_U(this->actor.params, 0, 2)].eyePosDeltaLocal.z;
eyePosDeltaLocal.x = sEscapeSubCamParams[ENDAIKU_GET_TYPE(&this->actor)].eyePosDeltaLocal.x;
eyePosDeltaLocal.y = sEscapeSubCamParams[ENDAIKU_GET_TYPE(&this->actor)].eyePosDeltaLocal.y;
eyePosDeltaLocal.z = sEscapeSubCamParams[ENDAIKU_GET_TYPE(&this->actor)].eyePosDeltaLocal.z;
Matrix_RotateY(BINANG_TO_RAD(this->actor.world.rot.y), MTXMODE_NEW);
Matrix_MultVec3f(&eyePosDeltaLocal, &eyePosDeltaWorld);

Expand Down Expand Up @@ -493,7 +493,7 @@ void EnDaiku_EscapeSuccess(EnDaiku* this, PlayState* play) {
Play_ChangeCameraStatus(play, CAM_ID_MAIN, CAM_STAT_ACTIVE);
this->subCamActive = false;

if (GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) {
if (GET_EVENTCHKINF_CARPENTERS_ALL_RESCUED()) {
Actor* gerudoGuard;
Vec3f vec;

Expand Down Expand Up @@ -594,13 +594,13 @@ void EnDaiku_Draw(Actor* thisx, PlayState* play) {

Gfx_SetupDL_25Opa(play->state.gfxCtx);

if (PARAMS_GET_U(thisx->params, 0, 2) == 0) {
if (ENDAIKU_GET_TYPE(thisx) == ENDAIKU_TYPE0) {
gDPSetEnvColor(POLY_OPA_DISP++, 170, 10, 70, 255);
} else if (PARAMS_GET_U(thisx->params, 0, 2) == 1) {
} else if (ENDAIKU_GET_TYPE(thisx) == ENDAIKU_TYPE1) {
gDPSetEnvColor(POLY_OPA_DISP++, 170, 200, 255, 255);
} else if (PARAMS_GET_U(thisx->params, 0, 2) == 2) {
} else if (ENDAIKU_GET_TYPE(thisx) == ENDAIKU_TYPE2) {
gDPSetEnvColor(POLY_OPA_DISP++, 0, 230, 70, 255);
} else if (PARAMS_GET_U(thisx->params, 0, 2) == 3) {
} else if (ENDAIKU_GET_TYPE(thisx) == ENDAIKU_TYPE3) {
gDPSetEnvColor(POLY_OPA_DISP++, 200, 0, 150, 255);
}

Expand Down Expand Up @@ -637,7 +637,7 @@ void EnDaiku_PostLimbDraw(PlayState* play, s32 limb, Gfx** dList, Vec3s* rot, vo

if (limb == 15) { // head
Matrix_MultVec3f(&targetPosHeadLocal, &this->actor.focus.pos);
gSPDisplayList(POLY_OPA_DISP++, hairDLists[PARAMS_GET_U(this->actor.params, 0, 2)]);
gSPDisplayList(POLY_OPA_DISP++, hairDLists[ENDAIKU_GET_TYPE(&this->actor)]);
}

CLOSE_DISPS(play->state.gfxCtx, "../z_en_daiku.c", 1330);
Expand Down
7 changes: 7 additions & 0 deletions src/overlays/actors/ovl_En_Daiku/z_en_daiku.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ struct EnDaiku;

typedef void (*EnDaikuActionFunc)(struct EnDaiku*, PlayState*);

typedef enum EnDaikuType {
ENDAIKU_TYPE0,
ENDAIKU_TYPE1,
ENDAIKU_TYPE2,
ENDAIKU_TYPE3
} EnDaikuType;

typedef struct EnDaiku {
/* 0x0000 */ Actor actor;
/* 0x014C */ SkelAnime skelAnime;
Expand Down
16 changes: 8 additions & 8 deletions src/overlays/actors/ovl_En_Ge1/z_en_ge1.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void EnGe1_Destroy(Actor* thisx, PlayState* play);
void EnGe1_Update(Actor* thisx, PlayState* play);
void EnGe1_Draw(Actor* thisx, PlayState* play);

s32 EnGe1_CheckCarpentersFreed(void);
s32 EnGe1_CheckAllCarpentersRescued(void);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo dont even need "check" in this case, "if all carpenters resuced" reads nicely

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same would apply to ge2 if you do change it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, I think it's better as-is. AllCarpentersRescued in a vacuum reads more towards being the event of having rescued all carpenters.

void EnGe1_WatchForPlayerFrontOnly(EnGe1* this, PlayState* play);
void EnGe1_SetNormalText(EnGe1* this, PlayState* play);
void EnGe1_WatchForAndSensePlayer(EnGe1* this, PlayState* play);
Expand Down Expand Up @@ -114,7 +114,7 @@ void EnGe1_Init(Actor* thisx, PlayState* play) {
case GE1_TYPE_GATE_OPERATOR:
this->hairstyle = GE1_HAIR_STRAIGHT;

if (EnGe1_CheckCarpentersFreed()) {
if (EnGe1_CheckAllCarpentersRescued()) {
this->actionFunc = EnGe1_CheckGate_GateOp;
} else {
this->actionFunc = EnGe1_WatchForPlayerFrontOnly;
Expand All @@ -124,7 +124,7 @@ void EnGe1_Init(Actor* thisx, PlayState* play) {
case GE1_TYPE_NORMAL:
this->hairstyle = GE1_HAIR_STRAIGHT;

if (EnGe1_CheckCarpentersFreed()) {
if (EnGe1_CheckAllCarpentersRescued()) {
this->actionFunc = EnGe1_SetNormalText;
} else {
this->actionFunc = EnGe1_WatchForAndSensePlayer;
Expand Down Expand Up @@ -154,7 +154,7 @@ void EnGe1_Init(Actor* thisx, PlayState* play) {

if (GET_EVENTINF(EVENTINF_HORSES_08)) {
this->actionFunc = EnGe1_TalkAfterGame_Archery;
} else if (EnGe1_CheckCarpentersFreed()) {
} else if (EnGe1_CheckAllCarpentersRescued()) {
this->actionFunc = EnGe1_Wait_Archery;
} else {
this->actionFunc = EnGe1_WatchForPlayerFrontOnly;
Expand All @@ -164,7 +164,7 @@ void EnGe1_Init(Actor* thisx, PlayState* play) {
case GE1_TYPE_TRAINING_GROUNDS_GUARD:
this->hairstyle = GE1_HAIR_STRAIGHT;

if (EnGe1_CheckCarpentersFreed()) {
if (EnGe1_CheckAllCarpentersRescued()) {
this->actionFunc = EnGe1_CheckForCard_GTGGuard;
} else {
this->actionFunc = EnGe1_WatchForPlayerFrontOnly;
Expand Down Expand Up @@ -208,9 +208,9 @@ void EnGe1_SetAnimationIdle(EnGe1* this) {
this->animFunc = EnGe1_CueUpAnimation;
}

s32 EnGe1_CheckCarpentersFreed(void) {
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)))) {
s32 EnGe1_CheckAllCarpentersRescued(void) {
if (!(GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_0_RESCUED) && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_1_RESCUED) &&
GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_2_RESCUED) && GET_EVENTCHKINF(EVENTCHKINF_CARPENTER_3_RESCUED))) {
return false;
}
return true;
Expand Down
Loading