9#define PARTY_STATUS_NO_SUMMONS 1
10#define PARTY_STATUS_SUMMONS 3
13#define ENCOUNTER_PARTY_LOST -1
14#define ENCOUNTER_FLED 999
20#define DEFEAT_SEVERAL 1
21#define DEFEAT_BY_PARTY_MEMBER 3
24#define LINK_OWNER_STATES_SIZE 0x7c8
52 u8 *ownerStateDestination;
84 transition->
unk18 = 0;
85 transition->
unk1c = 0;
111 camera->
yaw = 0x2800;
112 camera->
pitch = 0x5000;
131 for (linkWaitFrames = 0;;) {
171 ->availableMask != 0)
201 transition->
flag = 0;
211 ->availableMask != 0)
241 for (i = 0; i < actionCount; i++) {
247 i == 0 ? 10 : 0) == 1)
259 if (actingUnit <= 7 && battle->spoils.defeated == 1)
384 for (index = 0; index < count; index++) {
418 for (;
id < lastId;
id += 1) {
438 u16 activeMembers[8];
460 base = activeMembers;
462 if (livingCount < activeCount) {
464 remaining = activeCount;
470 if (output !=
NULL) {
477 }
while (remaining != 0);
484 if (remaining < lastEnemy) {
488 if (output !=
NULL) {
495 }
while (remaining < lastEnemy);
498 if (output !=
NULL) {
s32 BattlePresentation_BuildSortedUnitEntries(struct BattleActionRecord *entries)
Auto battle: gives every living unit a plain attack and sorts them into turn order.
s32 BattlePres_RunAction(struct BattleActionRecord *action)
Auto battle: plays one action.
void BattlePresentation_InitializeWorkAndResetState(void)
Allocates the perspective plane's scanline work (heap slot 10) cleared, and sets the background's mod...
void Runtime_ReleaseHeapBlock10(void)
Frees the perspective plane's scanline work (heap slot 10); called by Battle_RunEncounter as the batt...
void BattleBackground_Load(s32 mode, s32 resourceId, s32 level)
Loads a battle background: its picture into character blocks 2 and 3, its palette into BattleWork....
void BattlePres_SetupTransitionScene(s32 x, s32 depth, s32 y, s32 zoom)
Points the battle camera at (x, depth, y) with a zoom in percent, and lines the perspective plane up ...
void BattleCamera_SetRange(s32 centerX, s32 centerY, s32 offsetX, s32 offsetY, s32 scale)
Builds the perspective plane's next page for a zoom of scale about centerX and centerY (all 16....
#define PARTY_STATUS_SUMMONS
s32 BattleParty_ListLivingUnits(s32 sideMask, u16 *unitIds)
Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY,...
s32 BattleEnemyList(s16 *unitIds)
Lists the enemy units present, ended by BATTLE_UNIT_LIST_END, and returns how many there are (0 when ...
s32 Battle_RunEncounter(s32 enemyGroup)
Fights the battle against the enemy formation enemyGroup, from the opening transition to the end,...
#define PARTY_STATUS_NO_SUMMONS
BattleWork.partyStatus: how the party status window draws, with the Summon command offered or not.
s32 BattleParty_ListActorIds(s32 sideMask, u16 *unitIds)
Lists the units in the battle's unit lists on the sides in sideMask, party first, skipping those remo...
#define LINK_OWNER_STATES_SIZE
The size of the block a link battle copies its field state into.
#define DEFEAT_BY_PARTY_MEMBER
s32 BattleParty_PrepareActiveOwners(u16 *owners)
Lists the party members who fight (the first four of the party, three in a link battle) and marks eac...
#define ENCOUNTER_PARTY_LOST
Battle_RunEncounter's results besides the number of enemies defeated.
s32 BattlePresentation_WaitForPromptAt(s32 x, s32 y)
Shows the cursor bobbing at (x, y) and waits for one of KEY_ADVANCE.
s32 BattlePresentation_WaitForAdvance(void)
Shows the bobbing arrow at the message window and waits for the player to go on (B,...
void Camera_InitDefaultTransform(void)
Puts the battle camera at its default view of the battlefield's centre.
void BattleActor_UpdateSpritePriorities(void)
Runs each frame of a battle: advances every unit's status icon, lifts an airborne unit's effect sprit...
void * BattleMotion_DestroyAllSlotObjects(void)
Releases the object of every unit marked by BattleObj_MarkForRelease, leaving its battle object with ...
void BattleParty_CollectUnitList(void)
Fills the battle's two unit lists, each ended by BATTLE_UNIT_LIST_END: the party members in their ord...
void BattlePresentation_UpdateCamera(void)
Runs each frame of a battle.
struct BattleSummonState * BattleSummon_UpdateAvailability(void)
Works out which summons the party can call: one whose Djinn requirement of every element is met by th...
void Party_ReservedNoOp5B14(s32 unused)
Does nothing; Battle_RunEncounter calls it with 1 as the battle is set up.
s32 BattleParty_ReconcileDjinnRecovery(void)
Brings the Djinn recovery list up to date as a battle starts: every Djinni a party member has on stan...
s32 BattleParty_ResetActiveRuntimeFields(void)
Clears every battle-only state of the party members (stat stages and their turns, statuses,...
void BattleObjPut(void)
Readies the sprite of every unit in the battle (releasing those of units that left) and sets each one...
void BattlePres_RunEntryTransition(s32 enemyCount, s32 encounterId)
Opens a battle: the curtain opening, or for the Fusion Dragon the storm on the Venus Lighthouse aerie...
What every part of the battle object shares: its includes, in their original order,...
#define PARTY_BATTLE_SIZE
The party fights four at a time, three in a link battle; six enemies at most, three in a link battle.
#define FORMATION_SHUFFLED
BattleWork.battleType, from the enemy formation (BattleFormation_BuildEnemyList): the random formatio...
#define FIRST_ENEMY_UNIT
Unit ids from 128 are the enemies'; in a link battle the opponent's party takes the first three.
#define SIO_MULTI_PLAYER_ID()
This console's number in a link session (SIOCNT bits 4 and 5, which the hardware sets in multi-player...
#define DJINN_RECOVERY_PARTY
The Djinn recovery list's two tables (Djinn_GetRecoveryTableFar): the party's and the link opponent's...
#define LINK_MAX_MISSED_FRAMES
The frames a link battle tolerates without a connection before it gives up.
#define LINK_BOTH_CONNECTED
gLinkStatus: both consoles are connected.
#define ENEMY_BATTLE_SIZE
@ BATTLE_ENCOUNTER_ENEMIES_FIRST
@ BATTLE_ENCOUNTER_NORMAL
@ BATTLE_ENCOUNTER_PARTY_FIRST
@ BATTLE_UNIT_LIST_END
ends the list
@ BATTLE_UNIT_REMOVED
a place whose unit has left the battle
struct BattleWork * gBattleWork
#define Dma_Fill32Cell(cell, value, destination, size)
Dma_Fill32 through the caller's own volatile word cell, so a function that fills several blocks keeps...
void Fade_ToBlack(s32 frames)
Fades out to black.
void Fade_Wait(void)
Waits a frame at a time until the running fade has finished.
void ObjectSystem_InitializeFar(s32 mode)
struct BattleUnit * UnitGetFar(u32 owner)
s32 BattleUnitSetFar(s32 unitId, s32 enemyId, s32 suffix)
s32 GameFlag_TestFar(s32 flag)
void * Djinn_GetRecoveryTableFar(s32 arg0)
s32 GameFlag_SetBitFar(s32 flag)
s32 Party_CountActiveOwnersFar(void)
s32 BattleRandomFar(void)
s32 GameFlag_GetByteFar(s32 flag)
s16 Event_GetSpecialValueFar(void)
void AudioCommand_PlayFar(s32 id)
void UiWindow_CreateWithLayoutBoundsFar(s32 flags)
void PartyStatusDrawFar(s32 flags)
void UiWork_FinalizeFar(struct UiWindow *work, s32 release)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
s32 UiWork_IsCompleteFar(void)
void UiText_ShowMessageAndWaitCoreFar(s32 argument)
void UiWork_InitializeFar(s32 kind)
void UiWork_ClearValueNameTablesFar(void)
struct UiWindow * UiText_OpenMessageWindowFar(s32 message, s32 x, s32 y, u32 packed)
#define FLAG_IN_BATTLE
Set as a battle starts, cleared as a field scene starts.
#define FLAG_DJINN_TUTORIAL
#define FLAG_LINK_PARTY_COUNT
the members the linked opponent sent
s32 Sound_LoadPresetParameters(s32 preset)
Copies the mixer code for sound preset preset (0 to 4; anything else is 0) from ROM into IwramSoundPr...
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
volatile u8 gCpuLoadDisplayEnabled
Debug: WaitFrames measures the CPU load into gCpuLoadPeak when set.
#define Battle_SetStart(mode)
Sets the battle start type.
struct GameState gGameState
s32 Runtime_GetRemainingIwram(void)
Returns the IWRAM bytes left to allocate, up to gCartridgeResetMarker (0x03007800),...
s32 Runtime_GetRemainingEwram(void)
Returns the EWRAM bytes left to allocate, up to the end of EWRAM.
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
@ HEAP_SLOT_BATTLE_BACKGROUND
@ DISPCNT_MODE_1
BG0 and BG1 text, BG2 affine.
static s32 Iwram_ClearWords(void *destination, s32 size)
s32 Battle_ClearSerialTransferPayload(void)
Clears the link transfer's payload, the signatures included.
s32 BattlePres_SyncTurn(void)
In a link battle, after each action and after the end of each round, steps both consoles through the ...
s32 BattleParty_AssignMemberSlots(void)
Records, for each party member, the unit id the link opponent knows them by (FIRST_ENEMY_UNIT plus th...
#define SET_VECTOR(v, x, y, z)
Sets the x, y and z of a three-part vector: a position about to be projected, a per-frame step,...
void BattleUnit_RefreshPlacement(void)
Places every unit at the start of a battle: numbers the places (party members 0 up in their order,...
s32 BattlePresentation_BuildActions(struct BattleActionRecord *actions)
Builds the turn's actions and sorts them into turn order: the party's commands, then the link opponen...
void Battle_ReservedNoOp9B2C(void)
Does nothing; Battle_RunEncounter calls it at the start of each round.
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
void Scheduler_ResetTaskTable(void)
Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.
s32 Scheduler_SuspendTasks(SchedulerCallback callback)
Suspends the task running callback, or every task when callback is null, by setting bit 0 of its orde...
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
volatile u16 gLinkStatus
Link status, updated by the VBlank exchange handler.
void BattleSpoils_Clear(void)
Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem.
void Battle_AwardSpoils(void)
Hands out the spoils after a victory: the experience to each party member still standing,...
s32 BattlePresentation_DispatchAction(struct BattleActionRecord *request, s32 delay)
Plays one action of the round, after delay frames facing the party: an enemy picks its ability now; t...
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
s32 distance
eye to focus, 16.16 fixed-point pixels
s32 pos[3]
the focus, 16.16 fixed-point pixels
s32 eye[3]
The eye, 16.16 fixed-point pixels: written each frame distance behind the focus along the turned view...
The battle message display: its window, its text channel and whether the next message is marked.
The battle background's work slot as the camera reads it: the yaw the camera eases toward and the fra...
s32 unk18
cleared when the battle starts; not read by name in TBS
s32 frames
frames left to ease the yaw, a sixteenth a frame
s32 flag
0 lets the camera update set the background's range each frame; 1 for a critical hit's zoom and once ...
s32 unk1c
cleared when the battle starts; not read by name in TBS
s32 targetYaw
1/65536 turns
s32 defeated
enemies defeated
The party's Djinn recovery table as summons read it: the mask of summons the party can call,...
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 side
BATTLE_UNIT_ABSENT (0), BATTLE_UNIT_ENEMY (1) or BATTLE_UNIT_PARTY (2).
s16 hp
current HP, 0 when downed
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
u8 partyStatus
PARTY_STATUS_SUMMONS or PARTY_STATUS_NO_SUMMONS.
s32 promptSlot
resource entry of the advance arrow's tiles; -1 for none
u16 firstDefeated
The enemyClasses index of the first class to fall; 6 for none.
u16 background
the battle background's id
u8 twoSided
1 in a link battle
s32 enemyGroup
the encounter's enemy formation
u8 encounterMode
BATTLE_ENCOUNTER_: who strikes first.
u16 enemyClasses[6]
The enemy classes met so far, for their name letters, and the first class to fall (firstDefeated).
s16 partyUnits[7]
ends with BATTLE_UNIT_LIST_END
u16 defeatState
DEFEAT_ONE, DEFEAT_SEVERAL or DEFEAT_BY_PARTY_MEMBER.
u8 battleType
FORMATION_SHUFFLED or FORMATION_INTERLEAVED.
struct BattleActionRecord actions[BATTLE_ACTION_CAPACITY]
The actions chosen for the turn.
u8 linkPaused
set when the link drops or the console's id changes
u8 linkSide
this console's multiplayer id
struct BattleSpoils spoils
s16 enemyIds[BATTLE_ENEMY_CAPACITY+1]
ends with BATTLE_UNIT_LIST_END
s16 sceneCue
the battle music chosen for the encounter
u8 activeOwners[8]
the party in order
u8 battleStart
how the next battle starts (Battle_SetStart)
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
struct RenderOutputList output
the sprites the window carries
s32 Battle_ProcessRoundEnd(void)
Ends a round: sets recovered Djinn, then gives each unit its regeneration and counts down its stat ch...
s32 DjinnRecovery_Tick(void)
Brings the party's recovering Djinn one turn nearer, setting each whose turns reach 0,...
void Battle_ReservedNoOpF674(void)
Does nothing; Battle_RunEncounter calls it at the end of each round and of the battle.
s32 VramCache_AllocEntry(s32 size)
Takes a free cache entry, gives it size bytes of sprite VRAM and returns its number.
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).