tunnel_ruins.c
The tunnel ruins, in two scenes of Psynergy puzzles: pillars to push or Move, blocks, bushes for Whirlwind, sinking pillars and puddles for Frost in the first; a pillar for Douse, balance platforms, statues that vanish under Reveal and more pillars in the other.
games/tbs/src/scene/tunnel_ruins.c on GitHub
The tunnel ruins, in two scenes of Psynergy puzzles: pillars to push or Move, blocks, bushes for Whirlwind, sinking pillars and puddles for Frost in the first; a pillar for Douse, balance platforms, statues that vanish under Reveal and more pillars in the other.
Functions
TunnelRuins_RefreshActorAfterShrinking
static s32 TunnelRuins_RefreshActorAfterShrinking(struct ScriptInterpreter *interpreter)
Refreshes the actor presentation after its shrink script finishes.
Used by gTunnelRuins_ShrinkScript.
TunnelRuins_GetLandingPixel
static __inline__ s32 TunnelRuins_GetLandingPixel(s32 coordinate)
Later patches land at the tile center; the base release uses the target pixel.
Used by TunnelRuins_HopLeaderTo.
TunnelRuins_HopLeaderTo
static s32 TunnelRuins_HopLeaderTo(struct FieldPosition *target)
The leader hops over the cell ahead to the target, when that cell is no wall and the target is clear; returns 1 when there is no hop.
Used by Event_HopEast, Event_HopNorth, Event_HopSouth, Event_HopSouthOrPushBlocks, Event_HopWest.
Event_HopSouth
static void Event_HopSouth(void)
Walking south into a gap: the leader hops 32 pixels across it. Reached by walking south into cell codes 29, 30 and 50 in the first ruins and 29 in the other ruins.
Used by gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
Event_HopNorth
static void Event_HopNorth(void)
Walking north into a gap: the leader hops 32 pixels across it. Reached by walking north into cell codes 29 and 30 in the first ruins and 29 in the other ruins.
Used by Event_HopNorthUnlessAtCell30x52, gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
TunnelRuins_UpdateTrackedActor
static void TunnelRuins_UpdateTrackedActor(void)
The fade overlay follows the leader only south of a depth set per room.
Used by TunnelRuins_Initialize.
TunnelRuins_WaitForActorToLand
static void TunnelRuins_WaitForActorToLand(struct FieldActor *actor)
Waits up to 60 frames for landing, then stops vertical motion at the terrain.
Used by Event_SetBlockOnBalance.
Event_HopDownStep
static void Event_HopDownStep(void)
Walking south off a step: the leader hops 12 pixels forward and slides 16 pixels down, kicking up dust behind. Reached by walking south into cell code 25 in the first ruins and 27 in the other ruins.
Used by gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
TunnelRuins_GetEntrances
const struct SceneEntrance *TunnelRuins_GetEntrances(void)
The entrances of the first ruins, the second, or the rooms beyond.
TunnelRuins_GetPlacements
const struct ScenePlacement *TunnelRuins_GetPlacements(void)
The first ruins' actors or the other ruins' (the enums above), each prepared to appear only when it lies in the view.
Event_PushFirstPillars
static void Event_PushFirstPillars(void)
Walking into the first pair of pillars pushes them along. Reached by walking into cell code 24 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_HopWest
static void Event_HopWest(void)
Walking west into a gap: the leader hops 32 pixels across it. Reached by walking west into the gaps' cells: codes 23, 31 and 32 in the first ruins (31 until puddle A is frozen), 26 and 30 in the other ruins.
Used by Event_HopWestUnlessAtCell32x50, gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
Event_PushSecondPillars
static void Event_PushSecondPillars(void)
Walking into the second pair of pillars pushes them along. Reached by walking into cell code 26 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_JumpDownLedge
static void Event_JumpDownLedge(void)
Walking south off a ledge: the leader jumps down. Reached by walking south into cell codes 23 and 27 (first ruins) and 26 (the other ruins).
Used by gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
Event_HopEast
static void Event_HopEast(void)
Walking east into a gap: the leader hops 32 pixels across it. Reached by walking east into the gaps' cells: codes 27, 29, 31, 32 and 50 in the first ruins, some only until the puddle beside them is frozen, and 30 in the other ruins.
Used by gTunnelRuinsEvents1, gTunnelRuinsEventsOther.
Event_PushBlocks
static void Event_PushBlocks(void)
Walking into the blocks pushes the one in front along. Reached by walking into cell code 28 in the first ruins.
Used by Event_HopSouthOrPushBlocks, gTunnelRuinsEvents1.
Event_HopSouthOrPushBlocks
static void Event_HopSouthOrPushBlocks(void)
Walking south at the blocks: the leader hops a gap if there is one, and pushes the block in front otherwise. Reached by walking south into cell code 28 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_BlowAwayBushA
static void Event_BlowAwayBushA(void)
Whirlwind on bush A blows it away. Block C changes state with the bushes: with one of bushes A and B gone its rise counter is 1 and its collision bit 3 is set; with both gone, 0 and clear. Reached by Whirlwind on bush A until FLAG_SCENE_TEMP_00 is set; sets it.
Used by gTunnelRuinsEvents1.
Event_BlowAwayBushB
static void Event_BlowAwayBushB(void)
Whirlwind on bush B blows it away, as for bush A. Reached by Whirlwind on bush B until FLAG_SCENE_TEMP_01 is set; sets it.
Used by gTunnelRuinsEvents1.
Event_BlowAwayBushC
static void Event_BlowAwayBushC(void)
Whirlwind on bush C blows it away for good. Reached by Whirlwind on bush C until it is gone; sets FLAG_TUNNEL_RUINS_BUSH_BLOWN_AWAY.
Used by gTunnelRuinsEvents1.
Event_HopWestUnlessAtCell32x50
static void Event_HopWestUnlessAtCell32x50(void)
Hops west as Event_HopWest, except from cell (32, 50). Reached by walking west into cell code 50 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_HopNorthUnlessAtCell30x52
static void Event_HopNorthUnlessAtCell30x52(void)
Hops north as Event_HopNorth, except from cell (30, 52). Reached by walking north into cell code 50 in the first ruins.
Used by gTunnelRuinsEvents1.
TunnelRuins_AnimateLoweringImpact
static __inline__ void TunnelRuins_AnimateLoweringImpact(s32 sourceColumn, s32 column, s32 row)
Draws an impact frame of the passage and starts a decaying vertical shake.
Used by Event_SinkPillarA, Event_SinkPillarB.
Event_SinkPillarA
static void Event_SinkPillarA(void)
Moving sinking pillar A into column 46: it sinks 16 pixels into the floor in a cloud of dust, puddle A appears on it, and the floor beside it changes in two jolts that shake the screen. Reached by Move on sinking pillar A until it has sunk, and called by Event_PushSinkingPillarA; sets FLAG_TUNNEL_RUINS_PILLAR_A_SUNK when it sinks.
Used by Event_PushSinkingPillarA, gTunnelRuinsEvents1.
Event_PushSinkingPillarA
static void Event_PushSinkingPillarA(void)
Walking into sinking pillar A pushes it, and it sinks if it reaches column 46 (until FLAG_TUNNEL_RUINS_PILLAR_A_SUNK). Reached by walking into cell code 29 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_FreezePuddleA
static void Event_FreezePuddleA(void)
Frost on puddle A freezes it into a pillar of ice. Reached by Frost on puddle A until FLAG_SCENE_TEMP_00 is set; sets it.
Used by gTunnelRuinsEvents1.
Event_SinkPillarB
static void Event_SinkPillarB(void)
Moving sinking pillar B into column 48 once Douse has soaked it: it sinks as pillar A does, and puddle B appears on it. Reached by Move on sinking pillar B until it has sunk, and called by Event_PushSinkingPillarB and Event_DousePillarB; sets FLAG_TUNNEL_RUINS_PILLAR_B_SUNK when it sinks.
Used by Event_DousePillarB, Event_PushSinkingPillarB, gTunnelRuinsEvents1.
Event_PushSinkingPillarB
static void Event_PushSinkingPillarB(void)
Walking into sinking pillar B pushes it, and it sinks if it is soaked and reaches column 48. Reached by walking into cell code 30, or east into 32 before Douse has soaked it, in the first ruins.
Used by gTunnelRuinsEvents1.
Event_DouseBeginsOnPillarB
static void Event_DouseBeginsOnPillarB(void)
As Douse begins on sinking pillar B, water splashes on it. Reached by Douse's first phase on sinking pillar B until it is soaked.
Used by gTunnelRuinsEvents1.
Event_DousePillarB
static void Event_DousePillarB(void)
Douse soaks sinking pillar B, which sinks at once if it is in column 48. Reached by Douse on sinking pillar B until it is soaked; sets FLAG_SCENE_TEMP_02.
Used by gTunnelRuinsEvents1.
Event_FreezePuddleB
static void Event_FreezePuddleB(void)
Frost on puddle B freezes it into a pillar of ice. Reached by Frost on puddle B until FLAG_SCENE_TEMP_01 is set; sets it.
Used by gTunnelRuinsEvents1.
Event_ReadFirstStatue
static void Event_ReadFirstStatue(void)
Searching the first statue: it speaks to the leader's soul of the lady whose leave opens the way up Venus Lighthouse, or, once the statue at Venus Lighthouse has answered (flag 0x982 or 0x983), that the path will not open here. Reached by searching cell code 40 in the first ruins.
Used by gTunnelRuinsEvents1.
Event_MoveDousePillar
static void Event_MoveDousePillar(void)
Moving the Douse pillar (until its puddle is frozen): nothing more happens. Reached by Move on the Douse pillar until FLAG_SCENE_TEMP_04 is set.
Used by Event_PushDousePillar, gTunnelRuinsEventsOther.
Event_PushDousePillar
static void Event_PushDousePillar(void)
Walking into the Douse pillar pushes it along. Reached by walking into cell code 25 in the other ruins.
Used by gTunnelRuinsEventsOther.
Event_DouseBeginsOnPillar
static void Event_DouseBeginsOnPillar(void)
As Douse begins on the pillar, water splashes on it and it is soaked; its puddle follows it from then on. Reached by Douse's first phase on the Douse pillar until it is soaked; sets FLAG_SCENE_TEMP_03 and gives the puddle its update hook.
Used by gTunnelRuinsEventsOther.
Event_FreezeDousePuddle
static void Event_FreezeDousePuddle(void)
Frost on the pillar's puddle freezes it into a pillar of ice where it stands. Reached by Frost on the Douse pillar's puddle until FLAG_SCENE_TEMP_04 is set; sets it.
Used by gTunnelRuinsEventsOther.
TunnelRuins_SettleBalance
static void TunnelRuins_SettleBalance(s32 wait)
The balance platforms move to the heights their weights give them (their timers index gTunnelRuins_BalanceHeights), with sounds when wait is not 0; whatever then stands less than 30 pixels down can be walked on.
Used by Event_SetBlockOnBalance, TunnelRuins_Initialize.
TunnelRuins_DropBlockOnStack
static void TunnelRuins_DropBlockOnStack(s32 actorId)
A carried block drops onto the highest platform or block in its cell and lands with a thud and a ring of dust.
Used by Event_SetBlockOnBalance.
Event_SetBlockOnBalance
static void Event_SetBlockOnBalance(void)
Setting down a block with Carry: one dropped into a pit is gone; one set in row 9 drops onto the balance platform below it, which sinks a step while the other rises. Reached by Carry on any of the three blocks; sets FLAG_SCENE_TEMP_00 to _02, one for each block that rests on the balance.
Used by gTunnelRuinsEventsOther.
Event_PushObject
static void Event_PushObject(void)
Walking into a pushable object pushes it along. Reached by walking into cell codes 28 and 30 in the other ruins.
Used by gTunnelRuinsEventsOther.
Event_MoveEastPillar
static void Event_MoveEastPillar(void)
Moving either east pillar: whether each stands a cell west of its place is kept for the next visit. Reached by Move on either east pillar; sets or clears FLAG_TUNNEL_RUINS_EAST_PILLAR_A_PUSHED_WEST and _B_PUSHED_WEST.
Used by Event_PushEastPillar, gGomaCaveEntranceEvents, gGomaCavePillar_Events, gTunnelRuinsEventsOther.
Event_PushEastPillar
static void Event_PushEastPillar(void)
Walking into an east pillar pushes it along, and its place is kept. Reached by walking east into cell code 29 in the other ruins.
Used by gGomaCavePillar_Events, gTunnelRuinsEventsOther.
Event_ShowFalseStatues
static void Event_ShowFalseStatues(void)
The two false statues stand, blocking their cells: on entering their rooms and at Reveal's phase 4. Reached by Reveal's phase 4, and called by TunnelRuins_Initialize in room 12.
Used by TunnelRuins_Initialize, gTunnelRuinsEventsOther.
Event_HideFalseStatues
static void Event_HideFalseStatues(void)
At Reveal's phase 5 the two false statues vanish and their cells can be walked through. Reached by Reveal's phase 5 anywhere in the other ruins.
Used by gTunnelRuinsEventsOther.
Event_MoveLadyStatue
static void Event_MoveLadyStatue(void)
Moving a statue of the lady: with all five on their marks (cells (25, 49), (23, 49), (25, 47), (23, 47) and (24, 48)) the camera turns to the door as it opens; moving one off again closes it. Reached by Move on any of the five statues, and called by Event_PushLadyStatue; sets FLAG_TUNNEL_RUINS_STATUE_DOOR_OPEN as the door opens and clears it as it closes.
Used by Event_PushLadyStatue, gTunnelRuinsEventsOther.
Event_PushLadyStatue
static void Event_PushLadyStatue(void)
Walking into a statue of the lady pushes it along, then checks the door. Reached by walking into cell code 41 in the other ruins.
Used by gTunnelRuinsEventsOther.
Event_ReadSecondStatue
static void Event_ReadSecondStatue(void)
Searching the second statue. "The statue seems to speak to your soul..." Reached by searching cell code 42 in the other ruins.
Used by gTunnelRuinsEventsOther.
Event_SearchLockedDoor
static void Event_SearchLockedDoor(void)
Searching the door: it is tightly locked. Reached by searching cell code 20 in the other ruins.
Used by gTunnelRuinsEventsOther, gVenusLighthouseEvents4, gVenusLighthouseEvents5, gVenusLighthouseEvents6.
TunnelRuins_GetEvents
const struct SceneEvent *TunnelRuins_GetEvents(void)
The first ruins' events, or the other ruins'.
TunnelRuins_UpdateFirstPillarCells
static void TunnelRuins_UpdateFirstPillarCells(void)
After the first pillars move: redraw their room's cells and mark the cells the pillars stand on. Reached by Move on either of the first pillars, and called by Event_PushFirstPillars.
Used by Event_PushFirstPillars, TunnelRuins_Initialize, gTunnelRuinsEvents1.
TunnelRuins_UpdateSecondPillarCells
static void TunnelRuins_UpdateSecondPillarCells(void)
After the second pillars move: the same for their room. Reached by Move on either of the second pillars, and called by Event_PushSecondPillars.
Used by Event_PushSecondPillars, TunnelRuins_Initialize, gTunnelRuinsEvents1.
TunnelRuins_UpdateBlockCells
static void TunnelRuins_UpdateBlockCells(void)
After the blocks move: redraw their room's cells and mark the cells the blocks stand on. Reached by Move on any of the three blocks, and called by Event_PushBlocks.
Used by Event_PushBlocks, TunnelRuins_Initialize, gTunnelRuinsEvents1.
TunnelRuins_MarkPushPillarCells
static void TunnelRuins_MarkPushPillarCells(void)
Redraws the east pillars' row and marks the cells they stand on.
Used by Event_MoveEastPillar, TunnelRuins_Initialize.
TunnelRuins_Initialize
s32 TunnelRuins_Initialize(void)
On entering a room: the puzzle as it was left, and the route the statue at Venus Lighthouse chose (flag 0x982 or 0x983). Retreat leads back to the first ruins' entrance 1, or from the other ruins' first rooms to Babi Lighthouse. The scene's initialization. Entering rooms 8 to 11 sets flag 0x973. XXX: no other code of the game reads flag 0x973; a reader elsewhere would say what it records.
Also, functions without a comment: TunnelRuins_SplashDousedPillar, TunnelRuins_PuddleFollowsPillar, TunnelRuins_GetRegions, TunnelRuins_GetExits, TunnelRuins_RideBlockBelow.
Macros
DIRECTION_STEP
#define DIRECTION_STEP(dx, dz) (((dx) << 16) | ((dz) & 0xffff))
Pixel step by direction: X in the upper halfword, Z in the lower.
Used by gBilibinCave_PushSteps, gBilibin_FacingCellSteps, gColossoRiver_DirectionSteps, gColossoWall_DirectionSteps, gStagedActor_DirectionSteps.
Also, macros without a comment: FIELD_STAGED_ACTOR_IMPORTS, ACTOR_UPDATE_IDLE, ACTOR_UPDATE_IDLE, ACTOR_UPDATE_RIDE_BLOCK, ACTOR_UPDATE_RIDE_BLOCK.
Globals
gTunnelRuins_BalanceHeights
u32 gTunnelRuins_BalanceHeights[]
A balance platform's height by its weight (its timer): each block on it takes it 16 pixels further down, and the other platform up as far.
Used by TunnelRuins_SettleBalance.
gTunnelRuins_StretchScript
s32 gTunnelRuins_StretchScript[]
The bushes stand 8/5 as tall as their sprite.
Used by gTunnelRuinsPlacements1.
gTunnelRuins_DouseSplashScript
s32 gTunnelRuins_DouseSplashScript[]
Douse: splashes on the pillar from frame 35 for 130 frames.
Used by Event_DouseBeginsOnPillar, Event_DouseBeginsOnPillarB.
Also, globals without a comment: gStagedActor_DirectionSteps, gStagedActor_FootprintKinds, gStagedActor_FootprintBounds, gEffectScript0, gEffectScript1, gEffectScript2, gEffectScripts, gTunnelRuins_ShrinkScript, gTunnelRuins_DoorOpenSteps, gTunnelRuins_DoorCloseSteps, gTunnelRuinsEntrancesOther, gTunnelRuinsEntrances1, gTunnelRuinsEntrances2, gTunnelRuinsRegions2, gTunnelRuinsExits, gTunnelRuinsPlacements1, gTunnelRuinsPlacementsOther, gTunnelRuinsEvents1, gTunnelRuinsEventsOther.