Skip to content

Commit

Permalink
More fun with flags (#2186)
Browse files Browse the repository at this point in the history
Added inverted castle flags, cleaned up some names for consistency, and
added a couple missing normal castle flags.

Converted stage name entities and stage headers to use g_CastleFlags
instead of CASTLE_FLAG_BANK.

This will need to be rebased when pending approved changes have been
merged.
  • Loading branch information
ProjectOblivion authored Feb 7, 2025
1 parent b27bf3b commit 4cd22b7
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 197 deletions.
483 changes: 338 additions & 145 deletions include/castle_flags.h

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/dra/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ u8 g_StageSelectOrder[] = {
STAGE_RBO8, STAGE_TOP_ALT, STAGE_ENDING,
};

// The effect of this array is unknown
// 0: 25% of chance
// 1: 62.5% of chance
// 2: 12.5% of chance
u8 g_RandomizeCastleFlag13[] = {
// A value is selected at random on every overlay change (including to/from
// bosses) The selected value + 0x80 is then assigned to
// g_CastleFlags[NO1_WEATHER]
u8 g_NO1WeatherOptions[] = {
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
};

Expand Down Expand Up @@ -94,7 +93,7 @@ void HandlePlay(void) {
g_CastleFlags[i] = 0;
}
g_CastleFlags[INTRO_VIDEO] = 1;
g_CastleFlags[ST0_BANNER] = 1;
g_CastleFlags[ST0_STAGE_FLAG] = 1;
if (g_PlayableCharacter != 0) {
g_CastleFlags[IVE_BEEN_ROBBED] = 1;
g_CastleFlags[MET_MARIA_AFTER_HIPPOGRYPH] = 1;
Expand Down Expand Up @@ -181,7 +180,7 @@ void HandlePlay(void) {
func_801024DC();
if (g_CastleFlags[NO1_WEATHER] & 0x80) {
g_CastleFlags[NO1_WEATHER] =
g_RandomizeCastleFlag13[rand() & 0xF] + 0x80;
g_NO1WeatherOptions[rand() & 0xF] + 0x80;
}
g_GameStep++;
break;
Expand Down
2 changes: 0 additions & 2 deletions src/st/cen/cen.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#define OVL_EXPORT(x) CEN_##x

#define CASTLE_FLAG_BANK 0x00

typedef enum EntityIDs {
/* 0x00 */ E_NONE,
/* 0x01 */ E_ID_01,
Expand Down
2 changes: 1 addition & 1 deletion src/st/chi/chi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define OVL_EXPORT(x) CHI_##x

#define CASTLE_FLAG_BANK 0x52
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

typedef enum {
/* 0x00 */ E_NONE,
Expand Down
8 changes: 4 additions & 4 deletions src/st/chi/en_breakable_wall.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void EntityBreakableWall(Entity* self) {

// Determine tile indices to use
pSrcTile = BreakableWallTilesCollision;
if (g_CastleFlags[CHI_SECRET_WALL_BROKEN]) {
if (g_CastleFlags[CHI_SECRET_WALL_OPEN]) {
pSrcTile += 0xC; // No collision
}

Expand All @@ -190,7 +190,7 @@ void EntityBreakableWall(Entity* self) {
}
}

if (g_CastleFlags[CHI_SECRET_WALL_BROKEN]) {
if (g_CastleFlags[CHI_SECRET_WALL_OPEN]) {
DestroyEntity(self);
return;
}
Expand Down Expand Up @@ -334,11 +334,11 @@ void EntityBreakableWall(Entity* self) {
prim = self->ext.prim;
prim->drawMode = DRAW_HIDE;
self->hitboxState = 0;
g_CastleFlags[CHI_SECRET_WALL_BROKEN] = 1;
g_CastleFlags[CHI_SECRET_WALL_OPEN] = 1;
// Update the map "explored" state
// This is read from an array of data in DRA, and in
// this case results in exploring the room to the left
g_api.func_800F1FC4(CHI_SECRET_WALL_BROKEN);
g_api.func_800F1FC4(CHI_SECRET_WALL_OPEN);
DestroyEntity(self);
return;

Expand Down
12 changes: 6 additions & 6 deletions src/st/chi/en_demon_switch_wall.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ void EntityDemonSwitch(Entity* self) {
self->hitboxWidth = 6;
self->hitboxHeight = 8;

if (g_CastleFlags[DEMON_SWITCH] != 0) {
if (g_CastleFlags[CHI_DEMON_SWITCH] != 0) {
self->animCurFrame = 4;
}
// fallthrough
case PRESS:
if (self->hitParams == 7) {
g_api.PlaySfx(SFX_ANIME_SWORD_B);
g_CastleFlags[DEMON_SWITCH] = 1;
g_CastleFlags[CHI_DEMON_SWITCH] = 1;
// Update the map "explored" state
// This is read from an array of data in DRA, and in
// this case results in exploring the room to the right
g_api.func_800F1FC4(DEMON_SWITCH);
g_api.func_800F1FC4(CHI_DEMON_SWITCH);
self->animCurFrame = 4;
self->step++; // Inactive
}
Expand Down Expand Up @@ -133,7 +133,7 @@ void EntityDemonSwitchWall(Entity* self) {

// Determine tilemap collision adjustments based on current map flags
pSrcTile = WallTiles;
if (g_CastleFlags[DEMON_SWITCH]) {
if (g_CastleFlags[CHI_DEMON_SWITCH]) {
pSrcTile += 0xC; // No collision (opened)
}

Expand All @@ -146,14 +146,14 @@ void EntityDemonSwitchWall(Entity* self) {
}

// Update internal state
if (g_CastleFlags[DEMON_SWITCH]) {
if (g_CastleFlags[CHI_DEMON_SWITCH]) {
self->animCurFrame = 0;
self->step = IDLE_OPEN;
break;
}
// Fallthrough
case IDLE_CLOSED: // Never set directly
if (g_CastleFlags[DEMON_SWITCH]) {
if (g_CastleFlags[CHI_DEMON_SWITCH]) {
self->step++; // PrepToOpen
}
break;
Expand Down
3 changes: 1 addition & 2 deletions src/st/dre/dre.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#define STAGE_IS_DRE

#define OVL_EXPORT(x) DRE_##x

#define CASTLE_FLAG_BANK 0xD3
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

typedef enum EntityIDs {
/* 0x00 */ E_NONE,
Expand Down
8 changes: 4 additions & 4 deletions src/st/e_stage_name.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "stage.h"

#ifndef CASTLE_FLAG_BANK
#define CASTLE_FLAG_BANK 0
#ifndef STAGE_FLAG
#define STAGE_FLAG NULL_STAGE_FLAG
#endif

s32 PrimDecreaseBrightness(Primitive* prim, u8 arg1);
Expand Down Expand Up @@ -68,7 +68,7 @@ void EntityStageNamePopup(Entity* self) {

switch (self->step) {
case 0:
if (g_DemoMode != Demo_None || g_CastleFlags[CASTLE_FLAG_BANK + 2]) {
if (g_DemoMode != Demo_None || g_CastleFlags[STAGE_FLAG]) {
DestroyEntity(self);
return;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ void EntityStageNamePopup(Entity* self) {
self->ext.stpopup.unk80 = 0x40;
self->step = 2;
self->step_s = 0;
g_CastleFlags[CASTLE_FLAG_BANK + 2] = 1;
g_CastleFlags[STAGE_FLAG] = 1;
break;
}
break;
Expand Down
8 changes: 6 additions & 2 deletions src/st/entity_stage_name_popup_jp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
extern u32 D_91CE570;

#ifndef STAGE_FLAG
#define STAGE_FLAG NULL_STAGE_FLAG
#endif

#ifdef VERSION_PSP
#define NUM_PRIMS 183
#else
Expand All @@ -27,7 +31,7 @@ void EntityStageNamePopup(Entity* self) {

switch (self->step) {
case 0:
if (g_CastleFlags[CASTLE_FLAG_BANK + 2]) {
if (g_CastleFlags[STAGE_FLAG]) {
DestroyEntity(self);
return;
}
Expand Down Expand Up @@ -449,7 +453,7 @@ void EntityStageNamePopup(Entity* self) {
break;
case 32:
if (!--self->ext.stpopupj.unk80) {
g_CastleFlags[CASTLE_FLAG_BANK + 2] = 1;
g_CastleFlags[STAGE_FLAG] = 1;
self->step_s = 0;
self->step = 0x12;
}
Expand Down
2 changes: 1 addition & 1 deletion src/st/lib/e_shop.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void func_us_801B2BE4(Entity* self) {
if (g_CastleFlags[INVERTED_CASTLE_UNLOCKED]) {
FntPrint("REV ");
}
if (g_CastleFlags[CASTLE_FLAG_220]) {
if (g_CastleFlags[DEATH_FIGHT_CS]) {
FntPrint("DET ");
}
if (g_api.TimeAttackController(
Expand Down
2 changes: 1 addition & 1 deletion src/st/lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define STAGE_IS_LIB
#define OVL_EXPORT(x) LIB_##x
#define CASTLE_FLAG_BANK 0x6F
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

typedef enum EntityIDs {
// /* 0x00 */ E_NONE,
Expand Down
2 changes: 1 addition & 1 deletion src/st/no1/no1.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define STAGE_IS_NO1

#define OVL_EXPORT(x) NO1_##x
#define CASTLE_FLAG_BANK 0x13
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

void EntityExplosionVariants(Entity* entity);
void EntityGreyPuff(Entity* entity);
Expand Down
4 changes: 2 additions & 2 deletions src/st/no1/unk_381E8.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ void func_us_801BA034(Entity* self) {
switch (self->step) {
case 0:
InitializeEntity(D_us_80180A04);
if (g_CastleFlags[CASTLE_FLAG_17]) {
if (g_CastleFlags[NO1_UNKNOWN_FLAG]) {
self->posY.i.hi = 0xC3;
self->step = 3;
}
Expand All @@ -758,7 +758,7 @@ void func_us_801BA034(Entity* self) {
}
if (self->posY.i.hi > 0xC2) {
g_api.func_80102CD8(1);
g_CastleFlags[CASTLE_FLAG_17] = 1;
g_CastleFlags[NO1_UNKNOWN_FLAG] = 1;
self->step++;
}
if (g_Timer % 10 == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/st/no1/unk_3FA34.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ void func_us_801C05DC(Entity* self) {
switch (self->step) {
case 0:
InitializeEntity(D_us_80180A10);
if (g_CastleFlags[CASTLE_FLAG_17]) {
if (g_CastleFlags[NO1_UNKNOWN_FLAG]) {
max = 4;
self->animCurFrame = 0;
self->step = 3;
}
break;

case 1:
if (g_CastleFlags[CASTLE_FLAG_17]) {
if (g_CastleFlags[NO1_UNKNOWN_FLAG]) {
self->zPriority -= 8;
self->step++;
tempEntity = AllocEntity(&g_Entities[64], &g_Entities[256]);
Expand Down Expand Up @@ -478,7 +478,7 @@ void func_us_801C05DC(Entity* self) {
break;

case 3:
if (g_CastleFlags[CASTLE_FLAG_17]) {
if (g_CastleFlags[NO1_UNKNOWN_FLAG]) {
max = 4;
} else {
max = 0;
Expand Down Expand Up @@ -506,7 +506,7 @@ void func_us_801C0A40(Entity* self) {
case 0:
InitializeEntity(D_us_80180A10);
self->animCurFrame = 0;
if (!g_CastleFlags[CASTLE_FLAG_17]) {
if (!g_CastleFlags[NO1_UNKNOWN_FLAG]) {
self->step = 2;
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/st/no3/no3.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#define STAGE_IS_NO3

#define OVL_EXPORT(x) NO3_##x

#define CASTLE_FLAG_BANK 0x34
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

// NO3 Sound IDs
#define SE_MERMAN_DEATH 0x71D
Expand Down
2 changes: 1 addition & 1 deletion src/st/np3/np3.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "stage.h"

#define OVL_EXPORT(x) NP3_##x
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

#define CASTLE_FLAG_BANK 0x34
#define E_PUFF_OPAQUE_PALETTE_OFFSET 0xD0

typedef enum EntityIDs {
Expand Down
12 changes: 6 additions & 6 deletions src/st/nz0/311C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void EntityLeftSecretRoomWall(Entity* self, u16* tileLayoutPtr, s32 tilePos) {
self->hitboxHeight = 32;
self->hitboxState = 2;

cond = g_CastleFlags[NZ0_SECRET_WALL_BROKEN] != 0;
cond = g_CastleFlags[NZ0_SECRET_WALL_OPEN] != 0;
tileLayoutPtr = D_80180E54 + (-cond & 24);

tilePos = 0x260;
Expand All @@ -110,7 +110,7 @@ void EntityLeftSecretRoomWall(Entity* self, u16* tileLayoutPtr, s32 tilePos) {
tileLayoutPtr += 2;
}

if (g_CastleFlags[NZ0_SECRET_WALL_BROKEN] != 0) {
if (g_CastleFlags[NZ0_SECRET_WALL_OPEN] != 0) {
DestroyEntity(self);
break;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ void EntityLeftSecretRoomWall(Entity* self, u16* tileLayoutPtr, s32 tilePos) {
self->step++;

if (self->ext.nz0311c0.unk84 == 3) {
g_CastleFlags[NZ0_SECRET_WALL_BROKEN] = 1;
g_CastleFlags[NZ0_SECRET_WALL_OPEN] = 1;
g_api.func_800F1FC4(0x81);

for (i = 0; i < 8; i++) {
Expand Down Expand Up @@ -181,7 +181,7 @@ void EntityBottomSecretRoomFloor(
self->hitboxWidth = 16;
self->hitboxHeight = 16;
self->hitboxState = 2;
flag = (g_CastleFlags[NZ0_SECRET_FLOOR_BROKEN] != 0);
flag = (g_CastleFlags[NZ0_SECRET_FLOOR_OPEN] != 0);
tileLayoutPtr = D_80180E94 + (-flag & 12);

tilePos = 0x2E7;
Expand All @@ -192,7 +192,7 @@ void EntityBottomSecretRoomFloor(
tilePos += 0x10;
}

if (g_CastleFlags[NZ0_SECRET_FLOOR_BROKEN] != 0) {
if (g_CastleFlags[NZ0_SECRET_FLOOR_OPEN] != 0) {
DestroyEntity(self);
break;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ void EntityBottomSecretRoomFloor(
self->step++;

if (self->ext.nz0311c0.unk84 == 3) {
g_CastleFlags[NZ0_SECRET_FLOOR_BROKEN] = 1;
g_CastleFlags[NZ0_SECRET_FLOOR_OPEN] = 1;
g_api.func_800F1FC4(0x82);
DestroyEntity(self);
}
Expand Down
3 changes: 1 addition & 2 deletions src/st/nz0/nz0.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#define STAGE_IS_NZ0

#define OVL_EXPORT(x) NZ0_##x

#define CASTLE_FLAG_BANK 0x7E
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

typedef enum EntityIDs {
/* 0x00 */ E_NONE,
Expand Down
3 changes: 1 addition & 2 deletions src/st/rwrp/rwrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "stage.h"

#define OVL_EXPORT(x) RWRP_##x

#define CASTLE_FLAG_BANK 0x1E0
#define STAGE_FLAG OVL_EXPORT(STAGE_FLAG)

typedef enum EntityIDs {
E_NONE,
Expand Down
2 changes: 0 additions & 2 deletions src/st/wrp/wrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#define OVL_EXPORT(x) WRP_##x

#define CASTLE_FLAG_BANK 0x00

typedef enum EntityIDs {
E_NONE,
E_BREAKABLE,
Expand Down

0 comments on commit 4cd22b7

Please sign in to comment.