Skip to content

Commit

Permalink
EntityStoneDoor (#1616)
Browse files Browse the repository at this point in the history
Thanks to sonicdcer
  • Loading branch information
sozud authored Sep 16, 2024
1 parent 005f5ca commit 7adbf52
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/symbols.us.bomar.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
g_InitializeData0 = 0x8018039C;
g_eInitGeneric2 = 0x801803E4;
g_StoneDoorTiles = 0x801812DC;
EntityUnkId12 = 0x8018ACD4;
EntityBreakable = 0x8018AE90;
EntityMariaCutscene = 0x8018B850;
Expand Down Expand Up @@ -91,6 +92,8 @@ EntityClockRoomController = 0x80197FEC;
EntityClockHands = 0x80198574;
EntityBirdcageDoor = 0x80198688;
EntityStatue = 0x80198944;
EntityStatueGear = 0x80198C74;
EntityStoneDoor = 0x80198F24;
UnkPolyFunc2 = 0x80199868;
PrimDecreaseBrightness = 0x801998E8;
EntityLifeUpSpawn = 0x8019994C;
Expand Down
6 changes: 6 additions & 0 deletions include/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,11 @@ typedef struct {
/* 0x7E */ u16 step;
} ET_Statue;

typedef struct {
/* 0x7C */ s32 flag;
/* 0x80 */ u16 unk80;
} ET_StoneDoor;

// ====== RIC ENTITIES ======

// ==========================
Expand Down Expand Up @@ -1944,6 +1949,7 @@ typedef union { // offset=0x7C
ET_ClockRoom clockRoom;
ET_Birdcage birdcage;
ET_Statue statue;
ET_StoneDoor stoneDoor;
} Ext;

#define SYNC_FIELD(struct1, struct2, field_name) \
Expand Down
155 changes: 152 additions & 3 deletions src/boss/mar/17FEC.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,159 @@ void EntityStatue(Entity* self) {
entity->posX.i.hi = self->posX.i.hi;
}

INCLUDE_ASM("boss/mar/nonmatchings/17FEC", func_us_80198C74);
extern u8 D_us_801812C4[];
extern u8 D_us_801812D0[];
extern u16 D_us_80181290[];

INCLUDE_ASM("boss/mar/nonmatchings/17FEC", func_us_80198E84);
// Gears that spin while the statues are moving Entity ID 0x1A
void EntityStatueGear(Entity* self) {
u16 params = self->params;
Primitive* prim;
s16 primIndex;

switch (self->step) {
case 0:
if (self->step_s == 0) {
InitializeEntity(g_eInitGeneric2);
self->animSet = ANIMSET_OVL(1);
self->animCurFrame = 17;
self->zPriority = 0x80;
self->posX.i.hi += D_us_80181290[params];
self->posY.i.hi -= 44;
self->step = 0;
self->step_s++;
}

primIndex = g_api.AllocPrimitives(PRIM_TILE, 1);
if (primIndex == -1) {
return;
}
self->primIndex = primIndex;
self->flags |= FLAG_HAS_PRIMS;
prim = &g_PrimBuf[primIndex];
prim->r0 = prim->g0 = prim->b0 = 0;
prim->x0 = self->posX.i.hi - 6;
prim->y0 = self->posY.i.hi - 16;
prim->u0 = 12;
prim->v0 = 32;
prim->priority = 0x7F;
prim->blendMode = 0;
self->step++;
break;

case 1:
if (self->ext.statue.step == self->step) {
self->step = 2;
self->animFrameIdx = self->animCurFrame - 17;
}
if (self->ext.statue.step == 2) {
self->step = 3;
self->animFrameIdx = 20 - self->animCurFrame;
}
self->animFrameDuration = 0;
break;

case 2:
AnimateEntity(D_us_801812C4, self);
if (self->ext.statue.step == 0) {
self->step = 1;
}
break;

INCLUDE_ASM("boss/mar/nonmatchings/17FEC", func_us_80198F24);
case 3:
AnimateEntity(D_us_801812D0, self);
if (self->ext.statue.step == 0) {
self->step = 1;
}
break;
}
}

extern s16 g_StoneDoorTiles[];

void UpdateStoneDoorTiles(bool doorState) {
s32 tilePos;
s16 i, j;

for (tilePos = 0xC4, i = 0; i < 2; i++) {
for (j = 0; j < 8; j++) {
if (doorState) {
// Open stone doors
g_Tilemap.fg[tilePos] = 0x597;
tilePos++;
} else {
// Close stone doors
g_Tilemap.fg[tilePos] = g_StoneDoorTiles[j];
tilePos++;
}
}
tilePos += 8;
}
}

// todo overlapping?
extern s16 D_us_80181294[];
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) {
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];
break;

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

case 2:
if ((self->ext.stoneDoor.unk80 % 32) == 0) {
PlaySfxPositional(0x607);
}

if (++self->ext.stoneDoor.unk80 % 2) {
if (params != 0) {
self->posX.i.hi++;
} else {
self->posX.i.hi--;
}
if (self->ext.stoneDoor.unk80 % 2) {
g_backbufferY = 1;
} else {
g_backbufferY = 0;
}
} else {
g_backbufferY = 0;
}

if (self->ext.stoneDoor.unk80 > 96) {
UpdateStoneDoorTiles(false);
g_backbufferY = 0;
self->step--;
}
break;
}
}

void func_us_80199114(void) {}

0 comments on commit 7adbf52

Please sign in to comment.