33#include "text/msg_ids.h"
82#define NULL ((void *)0)
120 0x00880001, ¶ms);
259 mapObjectId = mapObjectId + 1;
260 }
while (mapObjectId <= 107);
328 for (i = 100; i <= 107; i++) {
358 for (tries = 0; tries <= 2; tries++) {
360 member = (
u32)((random << 1) + random) >> 16;
363 if (alreadySpoke == 0) {
372 MSGNO(MsgFuchinTempleIDoNotThinkMasterHama));
420 s32 dx = (*secondPosition++ - *firstPosition++) >> 16;
421 s32 dz = (*secondPosition - firstPosition[1]) >> 16;
422 s32 squaredDeltaZ = dz * dz;
423 s32 squaredDeltaX = dx * dx;
425 return Iwram_Sqrt(squaredDeltaX + squaredDeltaZ);
456 register s32 offset
asm(
"r6");
491 if (distance <= best) {
493 nearest = left - count;
496 point = (
const s32 *)((
const u8 *)points + offset);
497 }
while (--count != 0);
538 if (*progress != 0) {
540 if (*progress <= 0) {
542 }
else if (frames == 0) {
547 }
while (frames != 0);
566 *(
u16 *)(
work + 0xcba) = frames;
581 if (actor->
targetX == 0x80000000) {
588 if (actor->
speed <= 0x10000) {
598 dx = 0x20000 - ((((z >> 20) & 1) * 5) << 16);
602 Effect_Spawn(actor->
x.
fixed + dx, actor->
y.
fixed, z, 0, 0, 0, 0x880001,
683 record->
z.
part.pixel);
712 center =
event->viewCenter;
716 probePosition.
x = actor->
x.
fixed;
717 probePosition.
y = actor->
y.
fixed;
718 probePosition.
z = actor->
z.
fixed + 0x18000;
725 Effect_Spawn(x, actor->
y.
fixed, actor->
z.
fixed, 0, phase,
733 actor->
z.
fixed + 0x80000);
744 probePosition.
x = actor->
x.
fixed;
745 probePosition.
y = actor->
y.
fixed;
746 probePosition.
z = actor->
z.
fixed + 0x80000;
751 probePosition.
x = actor->
x.
fixed + 0x5b333;
752 probePosition.
y = actor->
y.
fixed;
753 probePosition.
z = actor->
z.
fixed + 0x5b333;
758 probePosition.
x = actor->
x.
fixed - 0x5b333;
759 probePosition.
y = actor->
y.
fixed;
760 probePosition.
z = actor->
z.
fixed + 0x5b333;
765 center->
z.
fixed += 0x18000;
766 actor->
z.
fixed += 0x18000;
787 holdTimer = (
u16 *)(eventBytes + 0xcba);
789 *holdTimer = holdFrames;
805 backwardOffset.
x = paused;
807 backwardOffset.
y = paused;
808 backwardOffset.
z = paused;
814 backwardOffset.
z / 0x10000);
826 *holdTimer = holdFrames;
933 if (display !=
NULL) {
934 s16 *line = (
s16 *)(display + display[0x539] * 644);
935 s32 shift = (
s16)(counter << 3);
937 line = (
s16 *)((
u8 *)line + 38);
938 for (i = 0; i < 144; i++) {
947 colors = (
s16 *)(buffer + 12);
949 for (i = 6; i < 12; i++) {
953 green = (value >> 5) & 31;
954 blue = ((value >> 10) & 31) - 20;
957 blue = blue - level / 6 + 20;
959 green = green + (level << 6) / 120 - 32;
970 *color++ = (blue << 10) | (green << 5) | red;
972 palette = (
u32 *)0x050003cc;
973 word = (
u32 *)(buffer + 12);
993 column = (
u32 *)(buffer + 80);
1002 column[0] = ((
u32 *)buffer)[0];
1003 column[8] = ((
u32 *)buffer)[8];
1005 destination = buffer;
1006 source = buffer + 0x480;
1007 for (i = 0; i < 0x480; i++) {
1008 u8 value = *source++;
1011 *destination = value;
1018 attributes = 0x80008000;
1020 for (i = 0, offset = 0, x = 8; i < 5; i++) {
1024 attributes = 0x40000000;
1027 sprite->
oam.word.attr01 = (y << 16) | x | attributes;
1028 sprite->
oam.word.attr23 = 0xe400 | tile;
1053 *slotAddress = slot;
1107 { 0,
CONDITION_ALWAYS, 256, 0, 100,
FACING_SOUTH, 0, -1, -1, -1, -1, 0 },
1108 { 1,
CONDITION_ALWAYS, 256, 0, 100,
FACING_SOUTH, 0, 0, 0, 0, 0, 0 },
1113 { 0,
CONDITION_ALWAYS, 256, 0, 100,
FACING_SOUTH, 0, -1, -1, -1, -1, 0 },
1114 { 1,
CONDITION_ALWAYS, 984, 0, 952,
FACING_WEST, 0, 0, 0, 1016, 1016, 0 },
1115 { 2,
CONDITION_ALWAYS, 400, 0, 24,
FACING_SOUTH, 0, 0, 0, 1016, 1016, 0 },
1120 { 0,
CONDITION_ALWAYS, 256, 0, 100,
FACING_SOUTH, 0, -1, -1, -1, -1, 0 },
1121 { 1,
CONDITION_ALWAYS, 912, 0, 1000,
FACING_NORTH, 0, 0, 0, 1016, 1016, 0 },
1122 { 2,
CONDITION_ALWAYS, 24, 0, 584,
FACING_EAST, 0, 0, 0, 1016, 1016, 0 },
1127 { 0,
CONDITION_ALWAYS, 256, 0, 100,
FACING_SOUTH, 0, -1, -1, -1, -1, 0 },
1128 { 1,
CONDITION_ALWAYS, 1511, 0, 104,
FACING_WEST, 0, 0, 8, 1528, 504, 0 },
1129 { 2,
CONDITION_ALWAYS, 727, 0, 104,
FACING_SOUTH, 0, 0, 8, 1528, 504, 0 },
1130 { 3,
CONDITION_ALWAYS, 599, 0, 296,
FACING_SOUTH, 0, 0, 8, 1528, 504, 0 },
1131 { 4,
CONDITION_ALWAYS, 167, 0, 120,
FACING_SOUTH, 0, 0, 8, 1528, 504, 0 },
1132 { 5,
CONDITION_ALWAYS, 167, 0, 136,
FACING_NORTH, 0, 0, 8, 1528, 504, 0 },
1137 { 0,
CONDITION_ALWAYS, 424, 0, 824,
FACING_WEST, 0, -1, -1, -1, -1, 0 },
1138 { 1,
CONDITION_ALWAYS, 424, 0, 968,
FACING_NORTH, 0, 304, 560, 624, 1024, 0 },
1139 { 2,
CONDITION_ALWAYS, 552, 0, 776,
FACING_NORTH, 0, 304, 560, 624, 1024, 0 },
1140 { 3,
CONDITION_ALWAYS, 440, 0, 312,
FACING_NORTH, 0, 32, 16, 496, 320, 0 },
1141 { 4,
CONDITION_ALWAYS, 136, 0, 296,
FACING_NORTH, 0, 32, 16, 496, 320, 0 },
Ability numbers, named from the English release.
void Object_SetActionById(u32 objectId, s32 steps)
Sets the animation timer steps of each of an actor's sprites (AnimationObjects_SetActiveTimerSteps).
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
const s32 * gEffectScripts[]
The task scheduler: tasks, their order and the scheduler's state.
The engine calls the debug menus import, and their palette swatch tiles.
void Djinn_JoinParty(s32 slot, s32 element, s32 djinn)
A Djinni joins the party: djinn (0 to 19) of element goes to the member with the fewest Djinn,...
DMA channel registers, and the DMA and CPU fills.
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
static s32 FieldScheduler_AddCallback(SchedulerCallback callback, s32 priority)
Registers a main-image scheduler callback.
static s32 FieldResource_DecodeType01(const void *source, void *destination)
Decodes type-01 compressed data.
static s32 FieldObject_CheckMovementCollision(struct FieldActor *actor, struct FieldPosition *position)
static void DisplayScroll_StartHBlankDma(s32 mode, s32 freqX, s32 stepX, s32 ampX, s32 freqY, s32 stepY, s32 ampY)
u8 gLamakanDesert_SandEffectTiles[]
u16 gLamakanDesert_SandPhase
const u16 gLamakanDesert_SandPalette[16]
u16 gLamakanDesert_SandVramSlot
struct MenuSprite gLamakanDesert_SandWork[]
u8 gLamakanDesert_SandTileBuffer[]
Field effects, their scripts and the flags that spawn them.
@ EFFECT_USE_START_SCALE
options.startScaleX and startScaleY
@ EFFECT_SCALE_TO_TARGET
Grows from the start scale, or full size, to the target scale over the script's repeat count.
@ EFFECT_USE_TYPE
options.type, else object type 222
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
void Engine_ObjectSetPosition(struct FieldActor *object, s32 fixed_x, s32 fixed_y, s32 fixed_z)
void Engine_ActorFaceActor(s32 actor, s32 target, s32 frames)
void Engine_MapCopyCellAttributes(s32 srcX, s32 srcY, s32 width, s32 height, s32 destX, s32 destY)
void Object_SetMode(struct FieldActor *object, s32 animation)
static void Actor_WalkToAndWait(s32 actor, s32 x, s32 z)
static void Actor_SetDestinationOffset(s32 actor, s32 dx, s32 dz)
void Engine_ActorSetDestination(s32 actor, s32 x, s32 z)
static void Actor_FaceActor(s32 actor, s32 target, s32 frames)
s32 Engine_VramLoad(s32 block, s32 size, const void *data)
static void Actor_ShowEmote(s32 actor, s32 emote, s32 frames)
void Engine_MapCopyCellsLayered(s32 srcX, s32 srcY, s32 destX, s32 destY, s32 width, s32 height)
void Engine_GameFlagSet(s32 flag)
void Engine_GameFlagClear(s32 flag)
void Engine_ActorWaitForMove(s32 actor)
static void Map_CopyCellAttributes(s32 srcX, s32 srcY, s32 width, s32 height, s32 destX, s32 destY)
void Engine_ActorRunRepeatedMotion(s32 actor, s32 repeats)
static void Event_PlayCue(s32 cue)
static void Map_CopyCells(s32 srcX, s32 srcY, s32 width, s32 height, s32 destX, s32 destY)
void Engine_MapObjectSetPosition(s32 object, s32 fixed_x, s32 fixed_z)
s32 Engine_GameFlagIsSet(s32 flag)
void Engine_ActorStartRepeatedMotion(s32 actor, s32 repeats)
static void MapObject_SetPosition(s32 object, s32 fixed_x, s32 fixed_z)
static void Actor_SetSpeed(s32 actor, s32 speed, s32 acceleration)
static void Actor_SetPosition(s32 actor, s32 fixed_x, s32 fixed_z)
void Engine_EventWait(s32 frames)
static void Actor_SetAttachedEffect(s32 actor, s32 effect)
static struct FieldActor * Actor_Get(s32 actor)
void Marker_MoveLeaderAway(void)
Keeps the party leader off the markers: a leader within 16 pixels of a marker cell's centre is moved ...
Field objects and actors, and the scene transition styles.
@ TRANSITION_BACKDROP_FADE
#define SCENE_TRANSITION(style, variant)
@ ACTOR_FACES_MOTION
turns toward its velocity, 1/16 turn a frame
The field's runtime work: map cells, scene records and regions, map markers and FieldWork.
The scene table formats: entrances, exits, placements and events, and the macros that write them.
#define SCENE_EXITS(scene)
#define PSYNERGY_IN_AREA(ability, phase)
#define FIND_PSYNERGY_STONE
#define SCENE_EXIT(exit, scene, entrance)
#define EVENT_SCRIPT(script)
#define FIND_COINS(coins)
The scene service layer: one typed inline for each engine service a scene calls by its own name,...
static void Task_Wait(s32 frames)
static void FieldVector_AddPolarOffset(s32 radius, s32 heading, struct FieldPosition *probe)
static void Actor_SetAnimation(s32 actor, s32 animation)
static void Event_Wait(s32 frames)
static void FieldObject_SetPosition(struct FieldActor *object, s32 fixed_x, s32 fixed_y, s32 fixed_z)
FixedPointPosition, a position in 16.16 fixed point.
Game flags, named where their meaning is shown.
#define FLAG_REACHED_KALAY
Set whenever Kalay is entered; Vale's villagers then talk of the party's journey.
#define FLAG_SCENE_TEMP_00
#define FLAG_HSU_RESCUED_WITHOUT_PARTY
Hsu was freed without the party: set with FLAG_HSU_RESCUED when the party comes back from Lama Temple...
#define FLAG_LAMAKAN_SAND_MONSTER_BEATEN
on the third map
#define FLAG_SCENE_TEMP_01
volatile u32 gFrameCount
Frames WaitFrames has finished.
GameState, the game's state: play time, coins, the scene and the leader's position,...
#define Battle_SetStart(mode)
Sets the battle start type.
struct GameState gGameState
The screen blend's globals and the graphics routines.
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
The heap's work slots and HeapState.
The main-image routines scene overlays import.
void IoWriteQueue_Store32(u32 address, u32 value)
Queues a word store.
The hardware's I/O registers and their bits, as pret names them.
The register write queue that VBlank carries out after each finished frame.
Item numbers, named from the English release.
The IWRAM call layer: the routines the game keeps resident in IWRAM, each at its fixed address,...
static s32 Iwram_Sqrt(s32 value)
static s32 Reveal_ShowSecrets(void)
Reveal (phase 5): the saved patches of sand come back, the pits and the monster stand where they are,...
static void TalkToSmog(void)
Smog, Jupiter Djinni 3, joins the party.
static void FallIntoPit(void)
Trigger 22, stepping near a hidden pit: the leader looks at the nearest pit, is pulled backwards into...
const u32 * LamakanDesert_GetExits(void)
All four desert maps share the packed exit table.
const s32 gLamakanDesertRecoveryPoints2[]
static void ComplainAboutHeat(s32 mark)
Raised trigger 1, 2 or 3 as the heat gauge passes a quarter, a half and three quarters: Garet,...
static void FightSandMonster(void)
Talking to the sand monster: its battle, returning to the third map's entrance 5.
static UNUSED void SandMonster_Return(void)
The monster sinks back to its spot; nothing calls this.
@ FLAG_HAZARDS_PAUSED
FLAG_SCENE_TEMP_00: a collapse, a pit or the monster is under way.
@ FLAG_HEAT_THREE_QUARTERS
@ FLAG_HEAT_QUARTER
the gauge has passed a quarter
@ FLAG_GARET_COMPLAINED
Who has complained since the gauge last passed a mark: one per member, in the order of their actors.
@ FLAG_SECRETS_REVEALED
FLAG_SCENE_TEMP_01: Reveal shows the pits.
static void HeatGauge_CountStep(void)
Walking on sand (triggers 21 and 100 to 107): each moving frame adds a step of heat and kicks up dust...
static void CollapseFromHeat(void)
Trigger 20, raised when the heat gauge fills: the leader drops at the nearest recovery point of the m...
static s32 DistanceInPixels(s32 *firstPosition, s32 *secondPosition)
The distance in whole pixels between two x, z positions.
const struct SceneRegion * LamakanDesert_GetRegions(void)
struct SceneEntrance gLamakanDesertEntrancesOther[]
struct ScenePlacement gLamakanDesertPlacements3[]
static void HeatGauge_Draw(void)
Every frame: draws the heat gauge.
const struct SceneEvent * LamakanDesert_GetEvents(void)
The desert's triggers, the same on every map.
struct SceneEntrance gLamakanDesertEntrances3[]
static void HeatGauge_SetHeld(u16 held)
While held (1), the gauge stays on screen.
const struct SceneEntrance * LamakanDesert_GetEntrances(void)
Where the party can enter each of the four maps.
static void SlideDownDune(void)
Trigger 30, on a slope of sand: the sand carries the leader south 1.5 pixels a frame,...
s32 LamakanDesert_Initialize(s32 a0, s32 a1)
Entering the desert: the heat gauge (600 steps) starts on the first three maps, the patches Reveal un...
const s32 gLamakanDesertRecoveryPoints1[]
Each map's recovery points, as x, z pairs.
s16 gHeatGaugeLevel
The gauge: how full it is (0 to 120), how far it has slid onto the screen, and a flash as it fills.
u32 gLamakanDesertExits[]
struct SceneEntrance gLamakanDesertEntrances1[]
const struct ScenePlacement * LamakanDesert_GetPlacements(void)
The pits and the monster of each map.
struct ScenePlacement gLamakanDesertPlacements1[]
const s32 gLamakanDesertRecoveryPointsOther[]
struct SceneEvent gLamakanDesertEvents[]
struct SceneEntrance gLamakanDesertEntrances2[]
void HeatGauge_Start(void)
Loads the gauge's tiles, claims VRAM for them and starts drawing it.
static void HeatGauge_RaiseQuarterTriggers(void)
Every frame: raises triggers 1 to 3 as the gauge passes each quarter, and clears each mark and the co...
struct SceneEntrance gLamakanDesertEntrances4[]
static s32 Reveal_HideSecrets(void)
Reveal's end (phase 4), and every entry: the pits and Smog vanish under the sand again (cells 70,...
static void MeetSandMonster(void)
Trigger 40 on the third map, until the monster is beaten: the leader stops and backs away as the mons...
@ SAND_MONSTER
sprite 0xc3; talking to it starts a battle
@ FIRST_PIT
9 to 12: the pits Reveal shows (sprite 0xc1)
struct ScenePlacement gLamakanDesertPlacementsOther[]
static s32 Leader_SpraySand(union FieldObject *fieldObject)
static void LeaveForTheWorldMap(void)
Trigger 9: back out to the world map.
struct ScenePlacement gLamakanDesertPlacements2[]
The heaps: allocating and freeing blocks.
void MemFree(void *buffer)
The reel game's title lettering.
Field object scripts: one s32 command word, then its operands, as gScriptObject_CommandTable runs the...
#define SC_LOOP(n, to)
Repeat up to n times.
#define SC_POS(x, y, z)
Set position.
#define SC_WAIT(n)
Wait n frames.
#define SC_TOP
Script start.
void FieldObject_WaitForMove(void *fieldObject)
Waits a frame at a time until a field object has arrived at its target, at most 600 frames.
static void SceneActor_WaitObjectBelowHeight(struct FieldActor *object, s32 height)
Waits until the object has come down to height (16.16), a second at most.
The work pointers in the gWorkSlot table, by name.
void Runtime_PushSlotEntry(void *slotEntry, s32 slot)
Links a sprite entry into depth slot slot (clamped to 0..255) for this frame.
void Field_RequestBattleFromEncounterTable(s32 zoneNo, s32 slotNo)
Sets up a battle with enemy group slot of encounter table zone.
void Event_SetNextDestination(s32 scene, s32 entrance)
Sets the scene and entrance that the field goes to next (gGameState.nextScene and nextEntrance).
void BattleFx_SetQueuedSoundAndPlay(s32 soundId)
Plays SE_298, then soundId (SE_289 for -1), and remembers soundId for BattleFx_PlayQueuedSound in the...
Scene numbers, named after their places.
char SceneId_LamakanDesert4
char SceneId_LamakanDesert1
char SceneId_LamakanDesert2
char SceneId_LamakanDesert3
Song and sound effect ids, indices into gSound_SongTable.
#define SE_JUMP
An actor jumps: ObjectMotion_Launch plays the high jump above 5 pixels a frame.
void Engine_ActorSetAnimation()
struct EventWork * gEventWork
void Engine_EventRequestExit()
void Engine_ActorSetPosition(u32 actor, s32 x, s32 z)
void Engine_EventEnd(void)
void Engine_AudioPlayCue()
void Engine_EventBegin(void)
void Engine_EventSetMessage()
void Engine_EventShowMessage()
The options of a spawned field effect, each used when its EFFECT_USE_ flag (or EFFECT_SCALE_TO_TARGET...
s16 type
the object type to create; 222 without the flag
s32 targetScaleY
16.16 fixed point, 0x10000 full size
s32 targetScaleX
16.16 fixed point, 0x10000 full size
s32 startScaleY
16.16 fixed point, 0x10000 full size
u16 spin
1/65536 turns per frame
s32 startScaleX
16.16 fixed point, 0x10000 full size
The running scene's event work: its placement and event tables, its actors, the triggers and exit it ...
s16 raisedTrigger
a raised event for Scene_RunRaisedEvent
s32 startTransition
SCENE_TRANSITION(style, variant).
s16 touchedTrigger
the step event a touch or exit event answers
A field actor: a person or thing on the field with a position, motion toward a target,...
s32 speed
speed limit, 16.16 fixed-point pixels per frame
s32 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
u8 steeringFlags
ActorSteeringFlag bits.
union FieldCoordinate x
16.16 fixed-point pixels
s32 targetZ
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
s32 velocityX
16.16 fixed-point pixels per frame
union FieldCoordinate y
16.16 fixed-point pixels
s32 terrainHeight
16.16 fixed-point pixels
union FieldCoordinate z
16.16 fixed-point pixels
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
u16 work
The side of the player's next footprint (2 after a stop), or scene scratch.
s32 velocityZ
16.16 fixed-point pixels per frame
s32 z
16.16 fixed-point pixels
s16 hazardLimit
Hazardous ground (the Lamakan Desert's heat): every hazardLimit steps the party takes hazardDamage (b...
s16 hazardSteps
reset on entering a new scene group
s32 selectedActor
the leader: its unit and its actor
s16 hazardMode
0 counts on hazard cells only; 1 counts every step
A halfword holding the zero the gauge's slide and phase are cleared with.
A recovery point: where a collapsed leader comes to.
A scene entrance: where and facing which way the party arrives, and the camera's bounds there (-1 for...
A scene event: its kind and detail, the trigger it answers, its condition and its value (a message or...
An actor a scene places: its sprite, the condition for placing it, how it behaves,...
A scene's exit region: the box that, while its condition holds, takes the party leader out through it...
u16 offset
bytes from the start of OBJ VRAM
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
The integer types, TRUE, UNUSED and the fixed-address macros.
struct FieldCoordinate::@024321007066302143002254325121164243234242211074 part
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
s32 VramCache_ReleaseVram(u32 no)
Gives back entry no's blocks but keeps the entry taken, with size 1, so a later VramCache_Load can re...
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
The sprite VRAM block cache and its owners.
struct VramBlockCacheEntry gVramBlockCache[]