Alchemy
Loading...
Searching...
No Matches

round.c File Reference

A round's actions: the party's commands, the enemies' or the link opponent's, and their turn order. More...

Go to the source code of this file.

Data Structures

struct  BattleLinkedActionState
 The header a link battle sends before its actions: how many there are, the next random number to check the consoles agree, and the parent's random seed for the round. More...

Macros

#define BG_PALETTE_14   ((u16 *)&BG_PLTT_COLOR(14, 0))
 Background palette 14, which takes palette 15 brightened.
#define BATTLE_START_NO_ESCAPE   2
 gGameState.battleStart of a battle the party cannot run from.
#define DJINN_FIRST_PRIORITY   10000
 A Djinni whose effect is a guard or Ground acts before everyone else.
#define LINK_PACKET_BYTES   20
 The link sends in packets of 20 bytes (the header is one), and a transfer may take 300 frames.
#define LINK_TRANSFER_TIMEOUT   300
#define LINK_ACTIONS_BYTES(count)
 The bytes of count actions, in whole packets.

Functions

void Palette_UpdatePulseBrightness (void)
 Pulses BG palette 14's colours: each takes the matching colour of palette 15 brightened by up to twelve steps, rising and falling with the frame count.
void Camera_ConfigureScene (s32 verticalOffset)
 Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels, with its projection and the background's perspective to match.
void BattleUnit_ResetGuardLevels (void)
 Ends every unit's guard (Defend and the like) and recalculates its stats.
s32 BattleEscape_CheckSuccess (void)
 Rolls whether the party gets away.
s32 BattlePres_BuildUnitEntries (struct BattleActionRecord *entries)
 The party's actions for the round, from the command menu: a member who is asleep, confused, charmed or stunned loses each of their turns (CMD_NONE); the others choose theirs (Battle_CollectPartyCommandsFar).
s32 BattlePres_BuildOpponentEntries (struct BattleActionRecord *entries)
 The enemies' actions for the round, in a shuffled order, each chosen by BattleCommand_SelectAutomatic; a sleeping or stunned enemy loses its turns.
void BattleQueue_SortByPriority (struct BattleActionRecord *entries, s32 count)
 Sorts the round's actions into turn order, fastest first, after moving the guarding and grounding Djinn to the front.
s32 BattlePresentation_AppendLinkedActions (struct BattleActionRecord *actions, s32 count)
 Link battle: exchanges the round's actions with the other console and appends the opponent's after the count of this console's.
void Palette_CopyBanksWithBrightnessOffset (s32 offset)
 Copies BG palette 15 to 14 and 5 to 4, brightened or darkened.
s32 BattlePresentation_BuildActions (struct BattleActionRecord *actions)
 Builds the turn's actions and sorts them into turn order: the party's commands, then the link opponent's or the enemies' actions.
s32 Battle_GetTaggedSlotValue (s32 taggedPlace)
 Returns the unit id at a list place.
s32 Battle_FindTaggedSlotByValue (u32 unitId)
 Returns the list place of unit id, or -1 if it is in neither list: the party's as 0x100 | place, the enemies' as 0x180 | place (PLACE_PARTY, PLACE_ENEMY).
void BattlePres_AdjustCameraByShoulderKeysAlt (void)
 Turns the camera while L or R is held (a second copy).
void Battle_ReservedNoOp9B2C (void)
 Does nothing; Battle_RunEncounter calls it at the start of each round.

Detailed Description

A round's actions: the party's commands, the enemies' or the link opponent's, and their turn order.

Part of battle.c, the battle object, compiled only through it.

Definition in file round.c.

Macro Definition Documentation

◆ BG_PALETTE_14

#define BG_PALETTE_14   ((u16 *)&BG_PLTT_COLOR(14, 0))

Background palette 14, which takes palette 15 brightened.

Definition at line 9 of file round.c.

Referenced by Palette_UpdatePulseBrightness().

◆ BATTLE_START_NO_ESCAPE

#define BATTLE_START_NO_ESCAPE   2

gGameState.battleStart of a battle the party cannot run from.

Definition at line 135 of file round.c.

Referenced by BattleEscape_CheckSuccess().

◆ DJINN_FIRST_PRIORITY

#define DJINN_FIRST_PRIORITY   10000

A Djinni whose effect is a guard or Ground acts before everyone else.

Definition at line 317 of file round.c.

Referenced by BattleQueue_SortByPriority().

◆ LINK_PACKET_BYTES

#define LINK_PACKET_BYTES   20

The link sends in packets of 20 bytes (the header is one), and a transfer may take 300 frames.

Definition at line 379 of file round.c.

Referenced by BattlePresentation_AppendLinkedActions().

◆ LINK_TRANSFER_TIMEOUT

#define LINK_TRANSFER_TIMEOUT   300

Definition at line 380 of file round.c.

Referenced by BattlePresentation_AppendLinkedActions().

◆ LINK_ACTIONS_BYTES

#define LINK_ACTIONS_BYTES ( count)
Value:
((u32)((count) * 16 + LINK_PACKET_BYTES - 1) / LINK_PACKET_BYTES * \
#define LINK_PACKET_BYTES
The link sends in packets of 20 bytes (the header is one), and a transfer may take 300 frames.
Definition round.c:379
unsigned int u32
Definition types.h:15

The bytes of count actions, in whole packets.

Definition at line 382 of file round.c.

Referenced by BattlePresentation_AppendLinkedActions().

Function Documentation

◆ Palette_UpdatePulseBrightness()

void Palette_UpdatePulseBrightness ( void )

Pulses BG palette 14's colours: each takes the matching colour of palette 15 brightened by up to twelve steps, rising and falling with the frame count.

Nothing in the source calls it. Writes BG palette RAM.

Definition at line 14 of file round.c.

Referenced by Palette_UpdatePulseBrightness().

◆ Camera_ConfigureScene()

void Camera_ConfigureScene ( s32 verticalOffset)

Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels, with its projection and the background's perspective to match.

Called by BattlePresentation_BuildActions, and through its far stub by Battle_CollectPartyCommands and UpdateLinkSessionCountdown. Writes the camera, the transition's targetYaw and flag (left 1, so the camera callback leaves the background alone), gProjection and the background's affine page.

Definition at line 65 of file round.c.

Referenced by BattlePresentation_BuildActions(), and Camera_ConfigureScene().

◆ BattleUnit_ResetGuardLevels()

void BattleUnit_ResetGuardLevels ( void )

Ends every unit's guard (Defend and the like) and recalculates its stats.

Called by BattlePresentation_BuildActions as each round begins. Clears every unit's guardLevel.

Definition at line 119 of file round.c.

Referenced by BattlePresentation_BuildActions(), and BattleUnit_ResetGuardLevels().

◆ BattleEscape_CheckSuccess()

s32 BattleEscape_CheckSuccess ( void )

Rolls whether the party gets away.

The chance, in hundredths of a percent, is 5000 plus 2000 for each attempt that failed, plus 500 times the party's average level, less 500 times the enemies' average level. A party that struck first always gets away; no one gets away from a battle that forbids it. Every attempt counts toward the next. Returns 1 when the party gets away. Called by BattlePresentation_BuildActions when the first action is CMD_FLEE. Each roll, even a successful one, raises gBattleWork->escapeFailures.

Definition at line 145 of file round.c.

Referenced by BattleEscape_CheckSuccess(), and BattlePresentation_BuildActions().

◆ BattlePres_BuildUnitEntries()

s32 BattlePres_BuildUnitEntries ( struct BattleActionRecord * entries)

The party's actions for the round, from the command menu: a member who is asleep, confused, charmed or stunned loses each of their turns (CMD_NONE); the others choose theirs (Battle_CollectPartyCommandsFar).

Returns how many actions there are, or -1 if the menu gave up. Called by BattlePresentation_BuildActions. Fills entries.

Definition at line 191 of file round.c.

Referenced by BattlePres_BuildUnitEntries(), and BattlePresentation_BuildActions().

◆ BattlePres_BuildOpponentEntries()

s32 BattlePres_BuildOpponentEntries ( struct BattleActionRecord * entries)

The enemies' actions for the round, in a shuffled order, each chosen by BattleCommand_SelectAutomatic; a sleeping or stunned enemy loses its turns.

An enemy acting more than once a turn acts later at half its Agility. None act when the party struck first; when the party is caught by surprise, only two to five enemies act, once each. Returns how many actions there are. Called by BattlePresentation_BuildActions outside a link battle. Fills entries.

Definition at line 244 of file round.c.

Referenced by BattlePres_BuildOpponentEntries(), and BattlePresentation_BuildActions().

◆ BattleQueue_SortByPriority()

void BattleQueue_SortByPriority ( struct BattleActionRecord * entries,
s32 count )

Sorts the round's actions into turn order, fastest first, after moving the guarding and grounding Djinn to the front.

Called by BattlePresentation_BuildActions. Raises those Djinn actions' priority and reorders entries in place.

Definition at line 323 of file round.c.

Referenced by BattlePresentation_BuildActions(), and BattleQueue_SortByPriority().

◆ BattlePresentation_AppendLinkedActions()

s32 BattlePresentation_AppendLinkedActions ( struct BattleActionRecord * actions,
s32 count )

Link battle: exchanges the round's actions with the other console and appends the opponent's after the count of this console's.

Each console sees its own party as the party: the received actions' units take the ids they have here and their targets swap sides. The parent sends first and gives the round its random seed; the child checks both consoles agree on the next random number. A party member's priority is made even on the parent and odd on the child, so equal speeds sort alike on both. Returns how many actions were received, or -1 when the exchange fails. Called by BattlePresentation_BuildActions in a link battle. Sets gBattleRandomSeed, writes each action's slot and priority, and on a failure resets the link transfer and removes its interrupt handlers.

Definition at line 397 of file round.c.

Referenced by BattlePresentation_AppendLinkedActions(), and BattlePresentation_BuildActions().

◆ Palette_CopyBanksWithBrightnessOffset()

void Palette_CopyBanksWithBrightnessOffset ( s32 offset)

Copies BG palette 15 to 14 and 5 to 4, brightened or darkened.

Called by BattlePresentation_BuildActions with 8, as the round's commands are chosen.

Parameters
offsetadded to each of the red, green and blue values (held in 0 to 31)

Definition at line 562 of file round.c.

Referenced by BattlePresentation_BuildActions(), and Palette_CopyBanksWithBrightnessOffset().

◆ BattlePresentation_BuildActions()

s32 BattlePresentation_BuildActions ( struct BattleActionRecord * actions)

Builds the turn's actions and sorts them into turn order: the party's commands, then the link opponent's or the enemies' actions.

Returns how many actions there are; negative to abort (a link failure). Called by Battle_RunEncounter at the start of each round outside auto battle. Clears gBattleWork->actions, sets every defender's guardLevel, may set encounterMode to BATTLE_ENCOUNTER_ENEMIES_FIRST after a failed escape, and holds FLAG_CHOOSING_COMMANDS while the commands are chosen.

Parameters
actionsthe actions (20 at most)

Definition at line 620 of file round.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_BuildActions().

◆ Battle_GetTaggedSlotValue()

s32 Battle_GetTaggedSlotValue ( s32 taggedPlace)

Returns the unit id at a list place.

Called by BattleCommand_BuildPlan for a command's target.

Parameters
taggedPlacethe place in the low four bits; 0x80 set for the enemies' list

Definition at line 711 of file round.c.

Referenced by Battle_GetTaggedSlotValue(), and BattleCommand_BuildPlan().

◆ Battle_FindTaggedSlotByValue()

s32 Battle_FindTaggedSlotByValue ( u32 unitId)

Returns the list place of unit id, or -1 if it is in neither list: the party's as 0x100 | place, the enemies' as 0x180 | place (PLACE_PARTY, PLACE_ENEMY).

Called by the enemies' command choice (enemy_ai.c) to aim at a unit.

Parameters
unitId0 to 7 the party, any other an enemy

Definition at line 724 of file round.c.

Referenced by Battle_FindTaggedSlotByValue(), and BattleCommand_SelectAutomatic().

◆ BattlePres_AdjustCameraByShoulderKeysAlt()

void BattlePres_AdjustCameraByShoulderKeysAlt ( void )

Turns the camera while L or R is held (a second copy).

Nothing in the source calls it.

Definition at line 749 of file round.c.

Referenced by BattlePres_AdjustCameraByShoulderKeysAlt().

◆ Battle_ReservedNoOp9B2C()

void Battle_ReservedNoOp9B2C ( void )

Does nothing; Battle_RunEncounter calls it at the start of each round.

Definition at line 752 of file round.c.

Referenced by Battle_ReservedNoOp9B2C(), and Battle_RunEncounter().