Alchemy
Loading...
Searching...
No Matches

encounter.c

Go to the documentation of this file.
1/// @file
2/// A whole battle, Battle_RunEncounter, and the lists of the units in it.
3/// Part of battle.c, the battle object, compiled only through it.
4
6
7/// BattleWork.partyStatus: how the party status window draws, with the
8/// Summon command offered or not.
9#define PARTY_STATUS_NO_SUMMONS 1
10#define PARTY_STATUS_SUMMONS 3
11
12/// Battle_RunEncounter's results besides the number of enemies defeated.
13#define ENCOUNTER_PARTY_LOST -1
14#define ENCOUNTER_FLED 999
15
16// BattleWork.defeatState: whether the last enemy fell alone, or with others
17// before it; 3 when a party member's action ended the battle with a single
18// defeat. The messages are "has been downed!" and "'s party goes down!".
19#define DEFEAT_ONE 0
20#define DEFEAT_SEVERAL 1
21#define DEFEAT_BY_PARTY_MEMBER 3
22
23/// The size of the block a link battle copies its field state into.
24#define LINK_OWNER_STATES_SIZE 0x7c8
25
26/// Fights the battle against the enemy formation enemyGroup, from the
27/// opening transition to the end, and returns how it ended: the number of
28/// enemies defeated when the party won (or the link broke), ENCOUNTER_FLED
29/// when the party ran, or ENCOUNTER_PARTY_LOST.
30///
31/// Each round, the party's commands are chosen (or chosen automatically
32/// under FLAG_AUTO_BATTLE), every unit acts in turn order, and the round ends
33/// with the turn-end effects; the Djinn tutorial adds its two messages
34/// after each round.
35///
36/// Reached through its far stub from Game_ResetForNewGame's scene switch
37/// (SCENE_BATTLE, with the entrance as enemyGroup), and from
38/// DebugBattle_RunMenu. Allocates the battle's work slots (the camera,
39/// gBattleWork, the link copy, the background transition, the display and
40/// others), sets FLAG_IN_BATTLE, and on its way out resets the party's
41/// battle state, sets gGameState.battleStart back to 0 and releases heap
42/// block 10. A broken link also sets flag 0x3e8, which the link lobby reads
43/// (LinkLobby_RunRoundResult).
45 struct BattleCamera *camera;
46 s32 *focus;
47 struct BattleWork *battle;
48 u8 *ownerStates;
49 struct BattlePresentationTransition *transition;
50 struct BattleDisplayWork *display;
51 s32 enemyCount;
52 u8 *ownerStateDestination;
53 s32 actionCount;
54 s32 i;
55 s32 result;
56 struct UiWindow *tutorialWindow;
57 s32 linkWaitFrames;
58 u32 copyIndex;
59 u32 actingUnit;
60 s16 cue;
61 UNUSED u8 unused[48]; // never used: the native frame keeps these 48 bytes
62 // The fill word Dma_Fill32Cell reads its zero from.
63 volatile u32 fill;
64
65 // The battle's work areas. Slot 54 holds the link battle's copy of the
66 // field state; slot 37 the display work.
67 camera = Runtime_AllocateBlock(HEAP_SLOT_CAMERA, sizeof(struct BattleCamera));
68 battle = Runtime_AllocateBlock(HEAP_SLOT_BATTLE, sizeof(struct BattleWork));
71 Runtime_AllocateBlock(11, 0x280);
72 focus = camera->pos;
73 /* FAKEMATCH(dead): result set to 0, a store no read sees, whose register
74 * CSE takes the setup's zeros from; without it, 122 of 645 instructions
75 * differ in tbs-en. */
76 result = 0;
79 // The transition owns the background (flag) until the entry transition
80 // is over; yaws are in 1/65536 turns, 0x2000 an eighth.
81 transition->frames = 0;
82 transition->targetYaw = 0x2000;
83 transition->flag = 1;
84 transition->unk18 = 0;
85 transition->unk1c = 0;
88 // XXX: what flag 0x169 marks; nothing in the source reads it by number,
89 // so a reader through another name or a script would settle it.
90 GameFlag_SetBitFar(0x169);
92
93 Dma_Fill32Cell(fill, 0, camera, sizeof(struct BattleCamera));
94 Dma_Fill32Cell(fill, 0, battle, sizeof(struct BattleWork));
95 battle->promptSlot = -1;
96 battle->enemyGroup = enemyGroup;
97 display = Runtime_AllocateBlock(37, sizeof(struct BattleDisplayWork));
98 Dma_Fill32Cell(fill, 0, display, sizeof(struct BattleDisplayWork));
100 Runtime_AllocateBlock(4, 0xe00);
101 Runtime_AllocateBlock(3, 0x600);
105 else
107
108 // The camera's starting view, and the enemies.
109 SET_VECTOR(focus, 0, 0x400000, 0);
110 SET_VECTOR(camera->eye, 0, 0xb40000, 0x400000);
111 camera->yaw = 0x2800;
112 camera->pitch = 0x5000;
113 camera->distance = 0x1000000;
114 enemyCount = BattleFormation_BuildEnemyList(battle->enemyGroup);
115
116 // A link battle: wait for the connection, take this console's side, keep
117 // a copy of the field state, and fight as the formation's first type.
118 // Both consoles start from seed 0 so their rolls agree; the opponent's
119 // party size is the enemy count.
121 battle->twoSided = 1;
123 }
124 if (battle->twoSided != 0) {
125 /* FAKEMATCH(one-pass): the seed's store in a one-pass block, which keeps
126 * it ahead of linkWaitFrames' zero; as a plain assignment, 7 of 645
127 * instructions differ in tbs-en. */
128 do {
130 } while (0);
131 for (linkWaitFrames = 0;;) {
133 break;
134 WaitFrames(1);
135 linkWaitFrames++;
136 if (linkWaitFrames > LINK_MAX_MISSED_FRAMES) {
137 battle->linkPaused = 1;
138 break;
139 }
140 }
141 battle->linkSide = SIO_MULTI_PLAYER_ID();
142 ownerStateDestination = gBattleOwnerStates;
143 for (copyIndex = 0; copyIndex < LINK_OWNER_STATES_SIZE; copyIndex++)
144 *ownerStateDestination++ = gActorSpriteSlots[copyIndex];
148 }
150
151 // The battle music: the scene's own cue, or the usual battle songs.
152 cue = gGameState.sceneCue;
153 if (cue != 0) {
158 }
159 } else {
162 }
163
164 // The units, the windows and the background.
171 ->availableMask != 0)
173 else
177 BattleObjPut();
179 BattleBackground_Load(1, battle->background, 0);
180 BattleCamera_SetRange(0xa00000, 0x500000, 0, 0, 0x20000);
183 REG_BLDCNT = 0;
185 battle->promptSlot = VramCache_AllocEntry(128);
186
187 // A random encounter may open with a first strike (1 in 16) or a
188 // surprise (1 in 32 of the rest); the Djinn tutorial always strikes first.
192 } else if (gGameState.battleStart == 0) {
193 if ((BattleRandomFar() & 15) == 0)
195 else if ((BattleRandomFar() & 31) == 0)
197 }
198 // After the entry transition the camera callback owns the background
199 // again, and the sprite priorities are sorted every frame.
200 BattlePres_RunEntryTransition(enemyCount, enemyGroup);
201 transition->flag = 0;
204
205 // The rounds.
206 for (;;) {
211 ->availableMask != 0)
213 else
215 // The camera eases back to its starting yaw over 60 frames.
216 transition->targetYaw = 0x2800;
217 transition->frames = 60;
219
220 // Every unit's action for the round, in turn order.
221 Iwram_ClearWords(battle->actions, sizeof(battle->actions));
224 // XXX: likely free-memory probes left from debugging, because no
225 // caller here reads their results.
228 actionCount = BattlePresentation_BuildActions(battle->actions);
231 } else {
233 }
234 battle->promptSlot = VramCache_AllocEntry(128);
236 if (actionCount < 0)
237 goto aborted;
238
239 // Each action, until one side is down or the party runs. The round's
240 // first action waits 10 frames facing the party first.
241 for (i = 0; i < actionCount; i++) {
242 actingUnit = battle->actions[i].unitId;
247 i == 0 ? 10 : 0) == 1)
248 goto fled;
249 } else {
250 if (BattlePres_RunAction(&battle->actions[i]) == 1)
251 goto fled;
252 }
256 goto party_lost;
258 // Unit ids 0 to 7 are party members.
259 if (actingUnit <= 7 && battle->spoils.defeated == 1)
261 goto won;
262 }
263 if (BattlePres_SyncTurn() < 0)
264 goto aborted;
265 }
266
267 // The end of the round.
272 if (battle->twoSided != 0) {
273 if (BattlePres_SyncTurn() < 0)
274 goto aborted;
275 } else {
276 WaitFrames(20);
277 }
279 continue;
280
281 // The Djinn tutorial explains unleashing and standby.
282 tutorialWindow = UiText_OpenMessageWindowFar(MsgTutorialUnleashed, 0, 4, 1);
283 while (UiWork_IsCompleteFar() == 0)
284 WaitFrames(1);
285 UiWork_FinalizeFar(tutorialWindow, 1);
286 WaitFrames(1);
287 tutorialWindow = UiText_OpenMessageWindowFar(MsgTutorialStandby, 10, 4, 1);
289 UiWork_FinalizeFar(tutorialWindow, 1);
290 WaitFrames(1);
291 }
292
293won:
294 // Name the defeat ("X has been downed!" or "X's party goes down!") after
295 // the first enemy class to fall, then hand out the spoils.
298 if (battle->twoSided != 0)
300 if (battle->spoils.defeated != 0) {
302 if (battle->defeatState <= DEFEAT_SEVERAL) {
304 battle->enemyClasses[battle->firstDefeated], 26);
309 }
310 }
312 }
314 Fade_ToBlack(30);
315 Fade_Wait();
316 result = battle->spoils.defeated;
317 goto finished;
318
319aborted:
320 // The link broke, or no actions could be gathered. Flag 0x3e8 tells the
321 // link lobby (LinkLobby_RunRoundResult) the battle did not finish.
325 result = battle->spoils.defeated;
326 GameFlag_SetBitFar(0x3e8);
327 goto finished;
328
329party_lost:
330 // "X goes down in defeat..." for a lone member, else "X's party has been
331 // defeated!".
337 UiText_ShowMessageAndWaitCoreFar(MsgGoesDownInDefeat);
338 else
339 UiText_ShowMessageAndWaitCoreFar(MsgPartyDefeated);
342 Fade_ToBlack(30);
343 result = ENCOUNTER_PARTY_LOST;
344 Fade_Wait();
345 goto finished;
346
347fled:
349 Fade_ToBlack(30);
350 Fade_Wait();
351 result = ENCOUNTER_FLED;
352
353finished:
354 // Every way out: Djinn recover one step, the next battle starts normally,
355 // and the per-frame sorting and the affine scanlines (block 10) go.
362 return result;
363}
364
365/// Lists the party members who fight (the first four of the party, three in
366/// a link battle) and marks each unit as a party member. owners, if not
367/// null, receives their ids ended by BATTLE_UNIT_LIST_END. Returns how many
368/// fight. Called across the battle parts whenever they need the party, and
369/// through its far stub by the party status window (party_status.c). Sets
370/// each fighting member's side to BATTLE_UNIT_PARTY.
372 s32 limit;
373 s32 count;
374 s32 index;
375
376 limit = PARTY_BATTLE_SIZE;
377 if (gBattleWork->twoSided != 0)
378 limit = LINK_PARTY_SIZE;
379
381 if (count > limit)
382 count = limit;
383
384 for (index = 0; index < count; index++) {
385 s32 owner = gGameState.activeOwners[index];
386
387 if (owners != 0)
388 *owners++ = owner;
390 }
391
392 if (owners != 0)
393 *owners = BATTLE_UNIT_LIST_END;
394 return count;
395}
396
397/// Lists the enemy units present, ended by BATTLE_UNIT_LIST_END, and returns
398/// how many there are (0 when unitIds is null). A link battle looks only at
399/// the opponent's three places. Called by BattleIntro_AnnounceEncounter,
400/// BattleParty_CollectUnitList and BattleTargetExec.
402 s16 *output;
403 s32 count;
404 s32 id;
405 s32 lastId;
406 s32 listed;
407
408 output = unitIds;
409 listed = 0;
410 lastId = ENEMY_BATTLE_SIZE;
411 count = 0;
412 if (output != NULL) {
414 lastId = LINK_PARTY_SIZE;
415 }
416 id = FIRST_ENEMY_UNIT;
417 lastId += FIRST_ENEMY_UNIT;
418 for (; id < lastId; id += 1) {
419 if (UnitGetFar(id)->side != BATTLE_UNIT_ABSENT) {
420 *output = id;
421 listed += 1;
422 output += 1;
423 }
424 }
426 count = listed;
427 }
428 return count;
429}
430
431/// Lists the units still standing (HP above 0) on the sides in sideMask
432/// (BATTLE_SIDE_PARTY, BATTLE_SIDE_ENEMIES or both), party first. unitIds,
433/// if not null, receives them ended by BATTLE_UNIT_LIST_END. Returns how
434/// many there are. Called across the battle parts (the round, staging, auto
435/// battle, turn end and spoils) to test whether a side still stands and to
436/// pick targets.
438 u16 activeMembers[8];
439 u16 *base;
440 s32 remaining;
441 s32 lastEnemy;
442 u16 *output;
443 s32 livingCount;
444 s32 enemyCapacity;
445 u16 *member;
446 s32 unitId;
447 s16 hp;
448 s32 activeCount;
449 struct BattleUnit *unit;
450
451 output = unitIds;
452 livingCount = 0;
453 enemyCapacity = ENEMY_BATTLE_SIZE;
455 enemyCapacity = LINK_PARTY_SIZE;
456 }
457 // The party, in its battle order; then every enemy unit id that is
458 // present, which a link battle limits to the opponent's three.
459 if (sideMask & BATTLE_SIDE_PARTY) {
460 base = activeMembers;
461 activeCount = BattleParty_PrepareActiveOwners(base);
462 if (livingCount < activeCount) {
463 member = base;
464 remaining = activeCount;
465 do {
466 unitId = *member;
467 member += 1;
468 hp = UnitGetFar(unitId)->hp;
469 if (hp > 0) {
470 if (output != NULL) {
471 *output = unitId;
472 output += 1;
473 }
474 livingCount += 1;
475 }
476 remaining -= 1;
477 } while (remaining != 0);
478 }
479 }
480 if (sideMask & BATTLE_SIDE_ENEMIES) {
481 // remaining walks the enemy unit ids here.
482 remaining = FIRST_ENEMY_UNIT;
483 lastEnemy = enemyCapacity + FIRST_ENEMY_UNIT;
484 if (remaining < lastEnemy) {
485 do {
486 unit = UnitGetFar(remaining);
487 if ((unit->side != BATTLE_UNIT_ABSENT) && (unit->hp > 0)) {
488 if (output != NULL) {
489 *output = remaining;
490 output += 1;
491 }
492 livingCount += 1;
493 }
494 remaining += 1;
495 } while (remaining < lastEnemy);
496 }
497 }
498 if (output != NULL) {
499 *output = BATTLE_UNIT_LIST_END;
500 }
501 return livingCount;
502}
503
504/// Lists the units in the battle's unit lists on the sides in sideMask,
505/// party first, skipping those removed from the battle. unitIds, if not
506/// null, receives them ended by BATTLE_UNIT_LIST_END. Returns how many
507/// there are. Unlike BattleParty_ListLivingUnits, it does not test HP.
508/// Called across the battle parts that draw or target units, and through
509/// its far stub by the command windows (command_row.c, party_commands.c).
510s32 BattleParty_ListActorIds(s32 sideMask, u16 *unitIds) {
511 struct BattleWork *battle;
512 s32 count;
513 s32 i;
514
515 battle = gBattleWork;
516 count = 0;
517 if (sideMask & BATTLE_SIDE_PARTY) {
518 for (i = 0; battle->partyUnits[i] != BATTLE_UNIT_LIST_END; i++) {
519 if (battle->partyUnits[i] != BATTLE_UNIT_REMOVED) {
520 if (unitIds != NULL)
521 *unitIds++ = battle->partyUnits[i];
522 count++;
523 }
524 }
525 }
526 if (sideMask & BATTLE_SIDE_ENEMIES) {
527 for (i = 0; battle->enemyIds[i] != BATTLE_UNIT_LIST_END; i++) {
528 if (battle->enemyIds[i] != BATTLE_UNIT_REMOVED) {
529 if (unitIds != NULL)
530 *unitIds++ = battle->enemyIds[i];
531 count++;
532 }
533 }
534 }
535 if (unitIds != NULL)
536 *unitIds = BATTLE_UNIT_LIST_END;
537 return count;
538}
s32 BattlePresentation_BuildSortedUnitEntries(struct BattleActionRecord *entries)
Auto battle: gives every living unit a plain attack and sorts them into turn order.
Definition auto_battle.c:12
s32 BattlePres_RunAction(struct BattleActionRecord *action)
Auto battle: plays one action.
Definition auto_battle.c:90
void BattlePresentation_InitializeWorkAndResetState(void)
Allocates the perspective plane's scanline work (heap slot 10) cleared, and sets the background's mod...
Definition background.c:145
void Runtime_ReleaseHeapBlock10(void)
Frees the perspective plane's scanline work (heap slot 10); called by Battle_RunEncounter as the batt...
Definition background.c:156
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....
Definition background.c:170
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 ...
Definition background.c:359
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....
Definition background.c:224
#define PARTY_STATUS_SUMMONS
Definition encounter.c:10
s32 BattleParty_ListLivingUnits(s32 sideMask, u16 *unitIds)
Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY,...
Definition encounter.c:437
s32 BattleEnemyList(s16 *unitIds)
Lists the enemy units present, ended by BATTLE_UNIT_LIST_END, and returns how many there are (0 when ...
Definition encounter.c:401
s32 Battle_RunEncounter(s32 enemyGroup)
Fights the battle against the enemy formation enemyGroup, from the opening transition to the end,...
Definition encounter.c:44
#define PARTY_STATUS_NO_SUMMONS
BattleWork.partyStatus: how the party status window draws, with the Summon command offered or not.
Definition encounter.c:9
#define ENCOUNTER_FLED
Definition encounter.c:14
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...
Definition encounter.c:510
#define LINK_OWNER_STATES_SIZE
The size of the block a link battle copies its field state into.
Definition encounter.c:24
#define DEFEAT_BY_PARTY_MEMBER
Definition encounter.c:21
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...
Definition encounter.c:371
#define ENCOUNTER_PARTY_LOST
Battle_RunEncounter's results besides the number of enemies defeated.
Definition encounter.c:13
#define DEFEAT_SEVERAL
Definition encounter.c:20
s32 BattlePresentation_WaitForPromptAt(s32 x, s32 y)
Shows the cursor bobbing at (x, y) and waits for one of KEY_ADVANCE.
Definition events.c:152
s32 BattlePresentation_WaitForAdvance(void)
Shows the bobbing arrow at the message window and waits for the player to go on (B,...
Definition events.c:90
void Camera_InitDefaultTransform(void)
Puts the battle camera at its default view of the battlefield's centre.
Definition objects.c:644
void BattleActor_UpdateSpritePriorities(void)
Runs each frame of a battle: advances every unit's status icon, lifts an airborne unit's effect sprit...
Definition objects.c:16
void * BattleMotion_DestroyAllSlotObjects(void)
Releases the object of every unit marked by BattleObj_MarkForRelease, leaving its battle object with ...
Definition objects.c:557
void BattleParty_CollectUnitList(void)
Fills the battle's two unit lists, each ended by BATTLE_UNIT_LIST_END: the party members in their ord...
Definition setup.c:135
void BattlePresentation_UpdateCamera(void)
Runs each frame of a battle.
Definition setup.c:18
struct BattleSummonState * BattleSummon_UpdateAvailability(void)
Works out which summons the party can call: one whose Djinn requirement of every element is met by th...
Definition setup.c:337
void Party_ReservedNoOp5B14(s32 unused)
Does nothing; Battle_RunEncounter calls it with 1 as the battle is set up.
Definition setup.c:188
s32 BattleParty_ReconcileDjinnRecovery(void)
Brings the Djinn recovery list up to date as a battle starts: every Djinni a party member has on stan...
Definition setup.c:260
s32 BattleParty_ResetActiveRuntimeFields(void)
Clears every battle-only state of the party members (stat stages and their turns, statuses,...
Definition setup.c:197
void BattleObjPut(void)
Readies the sprite of every unit in the battle (releasing those of units that left) and sets each one...
Definition sprites.c:13
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...
Definition transition.c:272
u8 * gBattleOwnerStates
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 VALUE_UNIT_NAME
#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 LINK_PARTY_SIZE
#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
@ BATTLE_UNIT_ABSENT
@ BATTLE_UNIT_PARTY
@ BATTLE_SIDE_PARTY
@ BATTLE_SIDE_ENEMIES
s32 gBattleRandomSeed
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...
Definition dma.h:42
void Fade_ToBlack(s32 frames)
Fades out to black.
Definition fade.c:76
void Fade_Wait(void)
Waits a frame at a time until the running fade has finished.
Definition fade.c:108
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.
Definition flags.h:21
#define FLAG_LINK_BATTLE
Definition flags.h:68
#define FLAG_DJINN_TUTORIAL
Definition flags.h:69
#define FLAG_LINK_PARTY_COUNT
the members the linked opponent sent
Definition flags.h:85
#define FLAG_AUTO_BATTLE
Definition flags.h:66
s32 BattleFormation_BuildEnemyList(s32 recordId)
Builds the battle's enemies from formation recordId and returns how many there are.
Definition formation.c:451
s32 Sound_LoadPresetParameters(s32 preset)
Copies the mixer code for sound preset preset (0 to 4; anything else is 0) from ROM into IwramSoundPr...
Definition frame.c:439
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
volatile u8 gCpuLoadDisplayEnabled
Debug: WaitFrames measures the CPU load into gCpuLoadPeak when set.
#define Battle_SetStart(mode)
Sets the battle start type.
Definition game_state.h:164
struct GameState gGameState
u8 gActorSpriteSlots[]
s32 Runtime_GetRemainingIwram(void)
Returns the IWRAM bytes left to allocate, up to gCartridgeResetMarker (0x03007800),...
Definition heap.c:26
s32 Runtime_GetRemainingEwram(void)
Returns the EWRAM bytes left to allocate, up to the end of EWRAM.
Definition heap.c:34
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
@ HEAP_SLOT_BATTLE_BACKGROUND
Definition heap_state.h:45
@ HEAP_SLOT_CAMERA
Definition heap_state.h:38
@ HEAP_SLOT_BATTLE
Definition heap_state.h:37
@ DISPCNT_MODE_1
BG0 and BG1 text, BG2 affine.
Definition io_reg.h:37
#define REG_DISPCNT
Definition io_reg.h:9
#define REG_BLDCNT
Definition io_reg.h:119
static s32 Iwram_ClearWords(void *destination, s32 size)
Definition iwram_call.h:55
#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,...
Definition macros.h:12
void BattleUnit_RefreshPlacement(void)
Places every unit at the start of a battle: numbers the places (party members 0 up in their order,...
Definition placement.c:379
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...
Definition round.c:620
void Battle_ReservedNoOp9B2C(void)
Does nothing; Battle_RunEncounter calls it at the start of each round.
Definition round.c:752
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...
Definition scheduler.c:102
void Scheduler_ResetTaskTable(void)
Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.
Definition scheduler.c:19
s32 Scheduler_SuspendTasks(SchedulerCallback callback)
Suspends the task running callback, or every task when callback is null, by setting bit 0 of its orde...
Definition scheduler.c:172
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
volatile u16 gLinkStatus
Link status, updated by the VBlank exchange handler.
#define MUS_051
Definition songs.h:55
#define MUS_059
Definition songs.h:63
#define MUS_055
Definition songs.h:59
#define MUS_017
Definition songs.h:27
#define MUS_058
Definition songs.h:62
#define MUS_076
Definition songs.h:78
void BattleSpoils_Clear(void)
Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem.
Definition spoils.c:33
void Battle_AwardSpoils(void)
Hands out the spoils after a victory: the experience to each party member still standing,...
Definition spoils.c:194
#define NULL
Definition bilibin.h:6
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...
Definition staging.c:18
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
u16 pitch
1/65536 turns
s32 distance
eye to focus, 16.16 fixed-point pixels
u16 yaw
1/65536 turns
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.
Definition battle_work.h:38
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 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,...
Definition battle_work.h:71
u8 partyStatus
PARTY_STATUS_SUMMONS or PARTY_STATUS_NO_SUMMONS.
Definition battle_work.h:86
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.
Definition battle_work.h:83
u16 background
the battle background's id
u8 twoSided
1 in a link battle
Definition battle_work.h:90
s32 enemyGroup
the encounter's enemy formation
Definition battle_work.h:72
u8 encounterMode
BATTLE_ENCOUNTER_: who strikes first.
Definition battle_work.h:91
u16 enemyClasses[6]
The enemy classes met so far, for their name letters, and the first class to fall (firstDefeated).
Definition battle_work.h:76
s16 partyUnits[7]
ends with BATTLE_UNIT_LIST_END
u16 defeatState
DEFEAT_ONE, DEFEAT_SEVERAL or DEFEAT_BY_PARTY_MEMBER.
Definition battle_work.h:84
u8 battleType
FORMATION_SHUFFLED or FORMATION_INTERLEAVED.
Definition battle_work.h:87
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
Definition battle_work.h:98
struct BattleSpoils spoils
s16 enemyIds[BATTLE_ENEMY_CAPACITY+1]
ends with BATTLE_UNIT_LIST_END
s16 sceneCue
the battle music chosen for the encounter
Definition game_state.h:55
u8 activeOwners[8]
the party in order
Definition game_state.h:60
u8 battleStart
how the next battle starts (Battle_SetStart)
Definition game_state.h:92
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
struct RenderOutputList output
the sprites the window carries
Definition uiwindow.h:12
void Render_ResetTransformState(void)
Allocates the one-level save area (heap slot HEAP_SLOT_TRANSFORM_STACK), clears gTransformStackDepth ...
Definition transform.c:19
s32 Battle_ProcessRoundEnd(void)
Ends a round: sets recovered Djinn, then gives each unit its regeneration and counts down its stat ch...
Definition turn_end.c:298
s32 DjinnRecovery_Tick(void)
Brings the party's recovering Djinn one turn nearer, setting each whose turns reach 0,...
Definition turn_end.c:221
void Battle_ReservedNoOpF674(void)
Does nothing; Battle_RunEncounter calls it at the end of each round and of the battle.
Definition turn_end.c:282
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11
s32 VramCache_AllocEntry(s32 size)
Takes a free cache entry, gives it size bytes of sprite VRAM and returns its number.
Definition vram_cache.c:227
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106