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 (4/?): Haggling Townsfolk #2395

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 20 additions & 6 deletions include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,12 +964,26 @@ typedef enum IngoRaceState {
#define EVENTINF_MARATHON_ACTIVE 0x10

// EVENTINF 0x20-0x24
#define EVENTINF_INDEX_20_21_22_23_24 2
#define EVENTINF_20_MASK (1 << 0)
#define EVENTINF_21_MASK (1 << 1)
#define EVENTINF_22_MASK (1 << 2)
#define EVENTINF_23_MASK (1 << 3)
#define EVENTINF_24_MASK (1 << 4)
#define EVENTINF_INDEX_HAGGLING_TOWNSFOLK 0x2
#define EVENTINF_HAGGLING_TOWNSFOLK_MESG_0 0x20
#define EVENTINF_HAGGLING_TOWNSFOLK_MESG_1 0x21
#define EVENTINF_HAGGLING_TOWNSFOLK_MESG_2 0x22
#define EVENTINF_HAGGLING_TOWNSFOLK_MESG_3 0x23
#define EVENTINF_HAGGLING_TOWNSFOLK_MESG_4 0x24

#define EVENTINF_HAGGLING_TOWNSFOLK_MASK \
(EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_0) | EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_1) | \
EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_2) | EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_3) | \
EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_4))

#define ENMU_GET_TALK_FLAGS() \
gSaveContext.eventInf[EVENTINF_INDEX_HAGGLING_TOWNSFOLK] & EVENTINF_HAGGLING_TOWNSFOLK_MASK

#define ENMU_SET_TALK_FLAGS(talkFlags) \
gSaveContext.eventInf[EVENTINF_INDEX_HAGGLING_TOWNSFOLK] |= (talkFlags);

#define ENMU_RESET_TALK_FLAGS() \
gSaveContext.eventInf[EVENTINF_INDEX_HAGGLING_TOWNSFOLK] &= ~(EVENTINF_HAGGLING_TOWNSFOLK_MASK);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should these justbe local en_mu defines? the system name at the front of the macro suggests so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dunno but fwiw, there is currently ENDAIKU_IS_CARPENTER_RESCUED and similar currently in z64save.h that works on carpenterType

Copy link
Collaborator

@fig02 fig02 Dec 30, 2024

Choose a reason for hiding this comment

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

we can keep going like this for now, but to me they do kinda make sense in the actor headers (or C file, idk)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I should say that part of the original plan was to move all uses eventInf and similar (except for like flg_set) into z64save so that all access is done through z64save macros, but i'm less confident on doing so anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think I care too much either way right now, but if they are going to be grouped all together in here, I would prefer if the naming convention was EVENTINF_THING consistently (replace the flag table name in the front for which ever it corresponds to, ofc)


#define EVENTINF_30 0x30

Expand Down
24 changes: 12 additions & 12 deletions src/overlays/actors/ovl_En_Mu/z_en_mu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ void EnMu_SetupAction(EnMu* this, EnMuActionFunc actionFunc) {
void EnMu_Interact(EnMu* this, PlayState* play) {
u8 textIdOffset[] = { 0x42, 0x43, 0x3F, 0x41, 0x3E };
u8 bitmask[] = {
EVENTINF_20_MASK, EVENTINF_21_MASK, EVENTINF_22_MASK, EVENTINF_23_MASK, EVENTINF_24_MASK,
EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_0), EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_1),
EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_2), EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_3),
EVENTINF_MASK(EVENTINF_HAGGLING_TOWNSFOLK_MESG_4),
};
u8 textFlags;
u8 talkFlags;
s32 randomIndex;
s32 i;

textFlags = gSaveContext.eventInf[EVENTINF_INDEX_20_21_22_23_24] &
(EVENTINF_20_MASK | EVENTINF_21_MASK | EVENTINF_22_MASK | EVENTINF_23_MASK | EVENTINF_24_MASK);
gSaveContext.eventInf[EVENTINF_INDEX_20_21_22_23_24] &=
~(EVENTINF_20_MASK | EVENTINF_21_MASK | EVENTINF_22_MASK | EVENTINF_23_MASK | EVENTINF_24_MASK);
talkFlags = ENMU_GET_TALK_FLAGS();
ENMU_RESET_TALK_FLAGS();
randomIndex = (play->state.frames + (s32)(Rand_ZeroOne() * 5.0f)) % 5;

// Starting at randomIndex, scan sequentially for the next unspoken message
for (i = 0; i < 5; i++) {

if (!(textFlags & bitmask[randomIndex])) {
if (!(talkFlags & bitmask[randomIndex])) {
break;
}

Expand All @@ -82,20 +82,20 @@ void EnMu_Interact(EnMu* this, PlayState* play) {
}
}

// If all 5 messages have been spoken, we reset but make sure the last message isn't repeated again
if (i == 5) {
if (this->defaultTextId == (textIdOffset[randomIndex] | 0x7000)) {
randomIndex++;
if (randomIndex >= 5) {
randomIndex = 0;
}
}
textFlags = 0;
talkFlags = 0;
}

textFlags |= bitmask[randomIndex];
talkFlags |= (u8)bitmask[randomIndex];
this->defaultTextId = textIdOffset[randomIndex] | 0x7000;
textFlags &= EVENTINF_20_MASK | EVENTINF_21_MASK | EVENTINF_22_MASK | EVENTINF_23_MASK | EVENTINF_24_MASK | 0xE0;
gSaveContext.eventInf[EVENTINF_INDEX_20_21_22_23_24] |= textFlags;
ENMU_SET_TALK_FLAGS(talkFlags);
}

u16 EnMu_GetTextId(PlayState* play, Actor* thisx) {
Expand Down