Skip to content

Commit

Permalink
Create enum for g_CastleFlags (#1624)
Browse files Browse the repository at this point in the history
I went through every use of g_CastleFlags and created enum members for
the different flags. This will allow us to better keep track of what
flags exist and how they are used. This will also aid in tracking the
arrangement of the overlays in the flags, as there seems to be some
level of organization. As we add more gameplay overlays we can hopefully
learn how these all work together.

Some functions were using local `const int` declarations to give names
to flags. For example, there was `const int jewelSwordRoomUnlock = 51;`.
For these ones, which had flag purposes identified in code, I went ahead
and gave their global castle flag a similar name (in this case,
`JEWEL_SWORD_ROOM`). For all other flags, I kept the name as a
placeholder of `CASTLE_FLAG_###`; later someone else can identify what
the individual flags are.

This should be a good step in making the castle flags more
understandable, as well as to connect the different functions across the
game and properly see which ones are touching the same flags. When a
castle flag is written as 0x32 in some places, and 50 in others, it
makes it harder to search. Now that we can use CASTLE_FLAG_50, hopefully
we will have better understanding of all the uses of the flag.
  • Loading branch information
bismurphy authored Sep 18, 2024
1 parent 666113f commit 77f0f5e
Show file tree
Hide file tree
Showing 35 changed files with 196 additions and 143 deletions.
42 changes: 42 additions & 0 deletions include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,48 @@ extern s32 g_IsTimeAttackUnlocked;
// prevents the player to enter in the warp room. When g_CastleFlags[0x32] the
// column will disappear.
extern u8 g_CastleFlags[0x300]; // starts at 0x8003BDEC
typedef enum {
CLOCK_ROOM_DOORS, // opened by gold and silver ring; drops down to CEN
CASTLE_FLAG_2 = 2,
CASTLE_FLAG_19 = 19, // Randomized by g_RandomizeCastleFlag13; unused
// Start NO3/NP3 flags
CASTLE_FLAG_48 = 48,
CASTLE_FLAG_49,
CASTLE_FLAG_50,
JEWEL_SWORD_ROOM,
CASTLE_FLAG_52,
CASTLE_FLAG_53,
CASTLE_FLAG_54, // Unused
CASTLE_FLAG_55,
DEATH_STAIRWAY_BROKEN, // Piece of stairs right before Death room
SG_RETR_ENTR, // Slogra/Gaibon retreated from Entrance encounter
CASTLE_FLAG_58,
CASTLE_FLAG_98 = 98, // Set in DRA, unused
CASTLE_FLAG_99, // Set in DRA, unused
// Start NZ0 flags
CASTLE_FLAG_129 = 129,
CASTLE_FLAG_130,
CASTLE_FLAG_131,
SG_KILL_ALCH, // Slogra & Gaibon were killed in Alchemy Lab
CASTLE_FLAG_133,
CASTLE_FLAG_149 = 149,
CASTLE_FLAG_150,
CASTLE_FLAG_155 = 155,
CASTLE_FLAG_185 = 185,
// WRP
CASTLE_FLAG_208 = 208,
// RWRP
CASTLE_FLAG_209,
// Cutscenes the player has finished seeing
SUCC_CS_DONE = 212, // Succubus cutscene (as Lisa)
HG_CS_DONE = 216, // Holy Glasses cutscene (in CEN)
HEART_FLAGS_START = 256,
MAD_COLLISION_FLAGS_START = 288,
MAD_RAREDROP_FLAGS_START = 320,
COLLISION_FLAGS_START = 400,
COLLECT_FLAGS_START = 432,
} CastleFlagOffsets;

extern s32 D_8003C0EC[4];
extern s32 D_8003C0F8;
extern s32 D_8003C100;
Expand Down
9 changes: 4 additions & 5 deletions src/boss/mar/17FEC.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,33 +499,32 @@ extern s16 D_us_80181298[];
// Stone doors on the floor leading to CEN Entity ID 0x1B
void EntityStoneDoor(Entity* self) {
u16 params = self->params;
const int centerCubeDoor = 0;

switch (self->step) {
case 0:
InitializeEntity(g_eInitGeneric2);
self->animSet = ANIMSET_OVL(1);
self->animCurFrame = params + 27;
self->zPriority = 0x40;
if (g_CastleFlags[centerCubeDoor] == 0) {
if (g_CastleFlags[CLOCK_ROOM_DOORS] == 0) {
self->posX.i.hi += D_us_80181294[params];
UpdateStoneDoorTiles(true);
} else {
self->posX.i.hi += D_us_80181298[params];
UpdateStoneDoorTiles(false);
}
self->posY.i.hi += 88;
self->ext.stoneDoor.flag = g_CastleFlags[centerCubeDoor];
self->ext.stoneDoor.flag = g_CastleFlags[CLOCK_ROOM_DOORS];
break;

case 1:
if (self->ext.stoneDoor.flag == NULL) {
if (g_CastleFlags[centerCubeDoor]) {
if (g_CastleFlags[CLOCK_ROOM_DOORS]) {
self->ext.stoneDoor.unk80 = 0;
self->step++;
}
}
self->ext.stoneDoor.flag = g_CastleFlags[centerCubeDoor];
self->ext.stoneDoor.flag = g_CastleFlags[CLOCK_ROOM_DOORS];
break;

case 2:
Expand Down
2 changes: 1 addition & 1 deletion src/dra/loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void HandleNowLoading(void) {
}
if (g_StageId == STAGE_NO3 && g_PlayableCharacter != PLAYER_ALUCARD) {
D_8006C374 = 0x11;
g_CastleFlags[0x34] = 1;
g_CastleFlags[CASTLE_FLAG_52] = 1;
}
D_800978C4 = 1;
SetGameState(Game_Play);
Expand Down
21 changes: 11 additions & 10 deletions src/dra/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ void HandlePlay(void) {
for (i = 0; i < LEN(g_CastleFlags); i++) {
g_CastleFlags[i] = 0;
}
g_CastleFlags[0xB9] = 1;
g_CastleFlags[0x9B] = 1;
g_CastleFlags[CASTLE_FLAG_185] = 1;
g_CastleFlags[CASTLE_FLAG_155] = 1;
if (g_PlayableCharacter != 0) {
g_CastleFlags[0x35] = 1;
g_CastleFlags[0x62] = 1;
g_CastleFlags[0x63] = 1;
g_CastleFlags[0x85] = 1;
g_CastleFlags[0x95] = 1;
g_CastleFlags[0x96] = 1;
g_CastleFlags[CASTLE_FLAG_53] = 1;
g_CastleFlags[CASTLE_FLAG_98] = 1;
g_CastleFlags[CASTLE_FLAG_99] = 1;
g_CastleFlags[CASTLE_FLAG_133] = 1;
g_CastleFlags[CASTLE_FLAG_149] = 1;
g_CastleFlags[CASTLE_FLAG_150] = 1;
}

for (i = 0, ptr = &g_MenuNavigation; i < sizeof(MenuNavigation);
Expand Down Expand Up @@ -179,8 +179,9 @@ void HandlePlay(void) {
DestroyAllPrimitives();
func_800EDAE4();
func_801024DC();
if (g_CastleFlags[0x13] & 0x80) {
g_CastleFlags[0x13] = g_RandomizeCastleFlag13[rand() & 0xF] + 0x80;
if (g_CastleFlags[CASTLE_FLAG_19] & 0x80) {
g_CastleFlags[CASTLE_FLAG_19] =
g_RandomizeCastleFlag13[rand() & 0xF] + 0x80;
}
g_GameStep++;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/st/cen/F890.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void EntityPlatform(Entity* self) {
self->animCurFrame = 9;
self->zPriority = 0x80;

if (g_CastleFlags[216] != 0) {
if (g_CastleFlags[HG_CS_DONE] != 0) {
self->step = 9;
}

Expand Down Expand Up @@ -276,7 +276,7 @@ void EntityRoomDarkness(Entity* self) {
switch (self->step) {
case 0:
/* Has player seen Maria Holy Glasses Cutscene? */
if (g_CastleFlags[216] != 0) {
if (g_CastleFlags[HG_CS_DONE] != 0) {
DestroyEntity(self);
return;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ void EntityRoomDarkness(Entity* self) {
void EntityMaria(Entity* self) {
if (self->step == 0) {
/* Has player seen Maria Holy Glasses Cutscene? */
if (g_CastleFlags[216] != 0) {
if (g_CastleFlags[HG_CS_DONE] != 0) {
DestroyEntity(self);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/st/cen/entity_heart_drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void EntityHeartDrop(Entity* self) {

if (!self->step) {
index = self->ext.heartDrop.unkB4 = self->params + 0xC0;
value = g_CastleFlags[(index >> 3) + 0x100] >> (index & 7);
value = g_CastleFlags[(index >> 3) + HEART_FLAGS_START] >> (index & 7);
if (value & 1) {
DestroyEntity(self);
return;
Expand All @@ -29,7 +29,8 @@ void EntityHeartDrop(Entity* self) {
index = self->ext.heartDrop.unkB4;
if (self->step < 5) {
if (self->hitFlags) {
g_CastleFlags[(index >> 3) + 0x100] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + HEART_FLAGS_START] |=
1 << (index & 7);
self->step = 5;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/st/cen/holyglassescutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void EntityHolyGlassesCutscene(Entity* self) {
}
switch (self->step) {
case 0:
if (g_CastleFlags[216] != 0) {
if (g_CastleFlags[HG_CS_DONE] != 0) {
DestroyEntity(self);
return;
}
Expand Down Expand Up @@ -667,7 +667,7 @@ void EntityHolyGlassesCutscene(Entity* self) {

case 7:
DestroyEntity(self);
g_CastleFlags[216] = 1;
g_CastleFlags[HG_CS_DONE] = 1;
g_api.TimeAttackController(
TIMEATTACK_EVENT_GET_HOLYGLASSES, TIMEATTACK_SET_RECORD);
D_8003C704 = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/st/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ void HitDetection(void) {
if (miscVar1) {
miscVar1--;
miscVar3 = 1 << (miscVar1 & 7);
g_CastleFlags[(miscVar1 >> 3) + 0x190] |= miscVar3;
g_CastleFlags[(miscVar1 >> 3) + COLLISION_FLAGS_START] |=
miscVar3;
}
if ((g_Status.relics[RELIC_FAERIE_SCROLL] & 2) &&
!(entFrom5C->flags & FLAG_NOT_AN_ENEMY)) {
Expand Down
5 changes: 3 additions & 2 deletions src/st/dre/entity_heart_drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void EntityHeartDrop(Entity* self) {

if (!self->step) {
index = self->ext.heartDrop.unkB4 = self->params + 0x118;
value = g_CastleFlags[(index >> 3) + 0x100] >> (index & 7);
value = g_CastleFlags[(index >> 3) + HEART_FLAGS_START] >> (index & 7);
if (value & 1) {
DestroyEntity(self);
return;
Expand All @@ -28,7 +28,8 @@ void EntityHeartDrop(Entity* self) {
index = self->ext.heartDrop.unkB4;
if (self->step < 5) {
if (self->hitFlags) {
g_CastleFlags[(index >> 3) + 0x100] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + HEART_FLAGS_START] |=
1 << (index & 7);
self->step = 5;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/st/dre/succubus.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ typedef enum {
extern s32 D_80180660; // clones counter

void EntitySuccubus(Entity* self) {
const int SeenCutscene = 212;
u8* clonesShootOrder;
s32 sideToPlayer;
Entity* entity;
Expand Down Expand Up @@ -113,7 +112,7 @@ void EntitySuccubus(Entity* self) {
CreateEntityFromCurrentEntity(E_SUCCUBUS_WING_OVERLAY, &self[1]);

case SUCCUBUS_CS_1: // Disguised as Lisa
if (g_CastleFlags[SeenCutscene] || (g_DemoMode != Demo_None)) {
if (g_CastleFlags[SUCC_CS_DONE] || (g_DemoMode != Demo_None)) {
self->facingLeft = 0;
self->posX.i.hi = 416 - g_Tilemap.scrollX.i.hi;
self->posY.i.hi = 175 - g_Tilemap.scrollY.i.hi;
Expand Down
7 changes: 4 additions & 3 deletions src/st/dre/succubuscutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ void EntitySuccubusCutscene(Entity* self) {
}
switch (self->step) {
case 0:
if ((g_CastleFlags[212]) || (g_PlayableCharacter != PLAYER_ALUCARD) ||
if ((g_CastleFlags[SUCC_CS_DONE]) ||
(g_PlayableCharacter != PLAYER_ALUCARD) ||
(g_DemoMode != Demo_None)) {
if (!self->params) {
DestroyEntity(self);
Expand All @@ -227,7 +228,7 @@ void EntitySuccubusCutscene(Entity* self) {
self->primIndex = g_Dialogue.primIndex[2];
self->step++;
}
if ((g_CastleFlags[212] != 0) ||
if ((g_CastleFlags[SUCC_CS_DONE] != 0) ||
(g_PlayableCharacter != PLAYER_ALUCARD) ||
(g_DemoMode != Demo_None)) {
D_801A3ED4 = 1;
Expand Down Expand Up @@ -654,7 +655,7 @@ void EntitySuccubusCutscene(Entity* self) {

case 7:
if (self->params) {
g_CastleFlags[212] = 1;
g_CastleFlags[SUCC_CS_DONE] = 1;
g_Settings.D_8003CB04 |= 0x2000;
} else {
g_Settings.D_8003CB04 |= 0x1000;
Expand Down
6 changes: 4 additions & 2 deletions src/st/e_collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ void EntityPrizeDrop(Entity* self) {
index = self->ext.equipItemDrop.castleFlag;
if (index) {
index--;
g_CastleFlags[(index >> 3) + 0x1b0] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + COLLECT_FLAGS_START] |=
1 << (index & 7);
}
#endif
}
Expand Down Expand Up @@ -669,7 +670,8 @@ void EntityEquipItemDrop(Entity* self) {
index = self->ext.equipItemDrop.castleFlag;
if (index) {
index--;
g_CastleFlags[(index >> 3) + 0x1b0] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + COLLECT_FLAGS_START] |=
1 << (index & 7);
}
#endif
primIndex = g_api.AllocPrimitives(PRIM_GT4, 1);
Expand Down
5 changes: 3 additions & 2 deletions src/st/e_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void EntityHeartDrop(Entity* self) {
if (!self->step) {
index = self->ext.heartDrop.unkB4 =
self->params + 0x118 + CASTLE_FLAG_BANK;
value = g_CastleFlags[(index >> 3) + 0x100] >> (index & 7);
value = g_CastleFlags[(index >> 3) + HEART_FLAGS_START] >> (index & 7);
if (value & 1) {
DestroyEntity(self);
return;
Expand All @@ -36,7 +36,8 @@ void EntityHeartDrop(Entity* self) {
index = self->ext.heartDrop.unkB4;
if (self->step < 5) {
if (self->hitFlags) {
g_CastleFlags[(index >> 3) + 0x100] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + HEART_FLAGS_START] |=
1 << (index & 7);
self->step = 5;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/st/mad/15520.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ void EntityHeartDrop(Entity* self) {

if (self->step == 0) {
index = self->ext.heartDrop.unkB4 = self->params;
if ((g_CastleFlags[(index >> 3) + 0x100] >> (index & 7)) & 1) {
if ((g_CastleFlags[(index >> 3) + HEART_FLAGS_START] >> (index & 7)) &
1) {
DestroyEntity(self);
return;
}
Expand All @@ -24,7 +25,8 @@ void EntityHeartDrop(Entity* self) {
index = self->ext.heartDrop.unkB4;
if (self->step < 5) {
if (self->hitFlags) {
g_CastleFlags[(index >> 3) + 0x100] |= 1 << (index & 7);
g_CastleFlags[(index >> 3) + HEART_FLAGS_START] |=
1 << (index & 7);
self->step = 5;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/st/mad/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ void HitDetection(void) {
if (miscVar1) {
miscVar1--;
miscVar3 = 1 << (miscVar1 & 7);
g_CastleFlags[(miscVar1 >> 3) + 0x120] |= miscVar3;
g_CastleFlags[(miscVar1 >> 3) +
MAD_COLLISION_FLAGS_START] |= miscVar3;
}
if ((g_Status.relics[RELIC_FAERIE_SCROLL] & 2) &&
!(entFrom5C->flags & FLAG_NOT_AN_ENEMY)) {
Expand Down Expand Up @@ -493,8 +494,10 @@ void HitDetection(void) {
if (miscVar1) {
miscVar1--;
flaggy_flags = (1 << (miscVar1 & 7));
g_CastleFlags[(miscVar1 >> 3) +
0x140] |= flaggy_flags;
g_CastleFlags
[(miscVar1 >> 3) +
MAD_RAREDROP_FLAGS_START] |=
flaggy_flags;
}
} else {
miscVar3 -= sp3C->rareItemDropRate;
Expand Down
Loading

0 comments on commit 77f0f5e

Please sign in to comment.