src/battle/battle_turn.c
A turn's actions: the party's commands, the enemies' or the link opponent's, and their action order. More…
Included by battle.c.
Structures
| Name | Description | |
|---|---|---|
struct | BATTLE_LINK_HEADER | The header a link battle sends before its actions: how many, the next random number to check the consoles agree, and the parent's seed for the turn. |
Macros
| Name | Description | |
|---|---|---|
#define | TURN_ORDER_SWAPS 32 | The random swaps that shuffle the enemies' order each turn. |
#define | PRIORITY_LOWEST -32768 | An empty action's priority, below every other. |
#define | COMMAND_VIEW_DEPTH toFIXED(969) | The command view's projection has no focal length, so every unit is drawn at one scale (syConvert3Dto2D's 1.32) whatever its depth, out to twice this depth; its near depth, as btCameraSetView's, is a fraction of a pixel. |
#define | DJINN_FIRST_PRIORITY 10000 | A Djinni whose effect is a guard or Ground acts before everyone else: its priority is raised by this, past any Agility (999 at most). |
#define | LINK_PACKET_BYTES 20 | The link sends in packets of 20 bytes (the header is one), and a transfer may take 300 ticks. |
#define | LINK_TRANSFER_TIMEOUT 300 | |
#define | LINK_ACTIONS_BYTES (count) | The bytes of count actions, in whole packets. |
Enumerations
| Name | Description | |
|---|---|---|
enum | FLEE_CHANCE { FLEE_ROLL_RANGE, FLEE_BASE_CHANCE, FLEE_CHANCE_PER_FAILURE, … } | The odds of fleeing in hundredths of a percent, against a roll below FLEE_ROLL_RANGE: FLEE_BASE_CHANCE, FLEE_CHANCE_PER_FAILURE more for each failed attempt, and FLEE_CHANCE_PER_LEVEL for each level of the party's average above the enemies'. |
Functions
| Name | Description | |
|---|---|---|
void | btPaletteUpdatePulseBrightness (void) | Unused: fills HIGHLIGHT_PALETTE with WINDOW_PALETTE's colours, brightened by a pulse that rises and falls with the tick count. |
void | btCameraSetCommandView (Sint32 verticalOffset) | Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels. |
void | btUnitResetGuardLevels (void) | Ends every unit's guard (Defend and the like) and recalculates its stats. |
Sint32 | btFleeCheckSuccess (void) | Rolls whether the party gets away: 50 percent, 20 more for each failed attempt, and 5 for each level the party's average is above the enemies'. |
Sint32 | btBuildPartyActions (BATTLE_ACTION *entries) | The party's actions for the turn, from the command menu; one who is asleep, confused, charmed or stunned loses theirs. |
Sint32 | btBuildEnemyActions (BATTLE_ACTION *entries) | The enemies' actions for the turn, in a shuffled order. |
void | btActionOrderSort (BATTLE_ACTION *entries, Sint32 count) | Sorts the turn's actions into action order, fastest first, after moving the guarding and grounding Djinn to the front. |
Sint32 | btAppendLinkedActions (BATTLE_ACTION *actions, Sint32 count) | Link battle: exchanges the turn's actions with the other console and appends the opponent's, their units and targets seen from this side. |
void | btPaletteCopyWithBrightnessOffset (Sint32 offset) | Copies WINDOW_PALETTE into HIGHLIGHT_PALETTE and BASIC_COLORS_PALETTE into the palette before it, each channel moved by offset levels. |
Sint32 | btGatherActions (BATTLE_ACTION *actions) | Builds the turn's actions and sorts them: the party's commands, then the link opponent's or the enemies' actions. |
Sint32 | btGetUnitAtPlace (Sint32 taggedPlace) | Returns the unit id at a list place, PLACE_ENEMY_SIDE set for the enemies' list. |
Sint32 | btFindUnitPlace (Uint32 unitId) | Returns the list place of a unit, PLACE_PARTY or PLACE_ENEMY with its place, or -1 when it is in neither list. |
DEFINE_ADJUST_CAMERA(btCameraAdjustByShoulderKeysAlternate) // Does nothing; btRun calls it at the start of each turn. void | btTurnStartNoOperation (void) | Unused: a second copy of the camera turn while L or R is held. |
Description
A turn's actions: the party's commands, the enemies' or the link opponent's,
and their action order. Part of battle.c.
Macros in detail
TURN_ORDER_SWAPS
#define TURN_ORDER_SWAPS 32
The random swaps that shuffle the enemies' order each turn.
Referenced by btBuildEnemyActions().
Definition at line 19 of file battle_turn.c.
PRIORITY_LOWEST
#define PRIORITY_LOWEST -32768
An empty action's priority, below every other.
Referenced by btGatherActions().
Definition at line 22 of file battle_turn.c.
COMMAND_VIEW_DEPTH
#define COMMAND_VIEW_DEPTH toFIXED(969)
The command view's projection has no focal length, so every unit is drawn at
one scale (syConvert3Dto2D's 1.32) whatever its depth, out to twice this
depth; its near depth, as btCameraSetView's, is a fraction of a pixel.
Referenced by btCameraSetCommandView().
Definition at line 58 of file battle_turn.c.
DJINN_FIRST_PRIORITY
#define DJINN_FIRST_PRIORITY 10000
A Djinni whose effect is a guard or Ground acts before everyone else: its priority is raised by this, past any Agility (999 at most).
Referenced by btActionOrderSort().
Definition at line 330 of file battle_turn.c.
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 ticks.
Referenced by btAppendLinkedActions().
Definition at line 399 of file battle_turn.c.
LINK_TRANSFER_TIMEOUT
#define LINK_TRANSFER_TIMEOUT 300
Referenced by btAppendLinkedActions().
Definition at line 400 of file battle_turn.c.
LINK_ACTIONS_BYTES
#define LINK_ACTIONS_BYTES(count)
The bytes of count actions, in whole packets.
Referenced by btAppendLinkedActions().
Definition at line 402 of file battle_turn.c.
Enumerations in detail
FLEE_CHANCE
enum FLEE_CHANCE
The odds of fleeing in hundredths of a percent, against a roll below
FLEE_ROLL_RANGE: FLEE_BASE_CHANCE, FLEE_CHANCE_PER_FAILURE more for each
failed attempt, and FLEE_CHANCE_PER_LEVEL for each level of the party's
average above the enemies'.
| Enumerator | Value | Description |
|---|---|---|
FLEE_ROLL_RANGE | 10000 | |
FLEE_BASE_CHANCE | 5000 | |
FLEE_CHANCE_PER_FAILURE | 2000 | |
FLEE_CHANCE_PER_LEVEL | 500 |
Definition at line 10 of file battle_turn.c.
Functions in detail
btPaletteUpdatePulseBrightness
void btPaletteUpdatePulseBrightness(void)
Unused: fills HIGHLIGHT_PALETTE with WINDOW_PALETTE's colours, brightened by
a pulse that rises and falls with the tick count.
References Sint32, syCos() and TickCount.
Definition at line 26 of file battle_turn.c.
btCameraSetCommandView
void btCameraSetCommandView(Sint32 verticalOffset)
Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels.
References btCameraSetRange(), HeapSlots, ProjectionWork, Sint32, syCalcPoint(), syDivFX(), syInitMatrix(), syMatrixTranslateVector(), syRotX(), syRotY() and sySetScreenDist().
Referenced by btGatherActions().
Definition at line 62 of file battle_turn.c.
btUnitResetGuardLevels
void btUnitResetGuardLevels(void)
Ends every unit's guard (Defend and the like) and recalculates its stats.
References btUnitListIds(), gmUnitCalculateStub(), gmUnitGetStub() and Sint32.
Referenced by btGatherActions().
Definition at line 107 of file battle_turn.c.
btFleeCheckSuccess
Sint32 btFleeCheckSuccess(void)
Rolls whether the party gets away: 50 percent, 20 more for each failed attempt, and 5 for each level the party's average is above the enemies'. A party that struck first always gets away, and no one from a battle that forbids it. Returns 1 when the party gets away.
References btUnitListLiving(), gmUnitGetStub(), MainRoutineStateWork and Sint32.
Referenced by btGatherActions().
Definition at line 128 of file battle_turn.c.
btBuildPartyActions
Sint32 btBuildPartyActions(BATTLE_ACTION *entries)
The party's actions for the turn, from the command menu; one who is asleep, confused, charmed or stunned loses theirs. Returns how many there are, or -1 if the menu gave up.
References btUnitListLiving(), gmUnitGetStub(), mnBattleCollectPartyCommandsStub(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().
Referenced by btGatherActions().
Definition at line 180 of file battle_turn.c.
btBuildEnemyActions
Sint32 btBuildEnemyActions(BATTLE_ACTION *entries)
The enemies' actions for the turn, in a shuffled order. An enemy acting more than once acts later at half its Agility; none act when the party struck first, and when the party is caught by surprise two to five act once each. Returns how many there are.
References btAIChooseAction(), btUnitListLiving(), gmUnitGetStub() and Sint32.
Referenced by btGatherActions().
Definition at line 243 of file battle_turn.c.
btActionOrderSort
void btActionOrderSort(BATTLE_ACTION *entries, Sint32 count)
Sorts the turn's actions into action order, fastest first, after moving the guarding and grounding Djinn to the front.
References gmAbilityGetDefinitionStub(), gmDjinnGetAbilityIdStub(), gmUnitGetStub(), Sint32 and syWordsCopy().
Referenced by btGatherActions().
Definition at line 334 of file battle_turn.c.
btAppendLinkedActions
Sint32 btAppendLinkedActions(BATTLE_ACTION *actions, Sint32 count)
Link battle: exchanges the turn's actions with the other console and appends the opponent's, their units and targets seen from this side. Returns how many were received, or -1 when the exchange fails.
References gmBattleRandomStub(), LinkStatusWork, RandWork, SerialReceivedSize, Sint32, syHeapAllocateEWRAM(), syHeapRelease(), syLinkBattleResetTransferState(), sySerialGetActiveTransfers(), sySerialRemoveIRQHandlers(), sySerialStartReceive(), sySerialStartSend() and sySynch().
Referenced by btGatherActions().
Definition at line 409 of file battle_turn.c.
btPaletteCopyWithBrightnessOffset
void btPaletteCopyWithBrightnessOffset(Sint32 offset)
Copies WINDOW_PALETTE into HIGHLIGHT_PALETTE and BASIC_COLORS_PALETTE into
the palette before it, each channel moved by offset levels.
References Sint32.
Referenced by btGatherActions().
Definition at line 607 of file battle_turn.c.
btGatherActions
Sint32 btGatherActions(BATTLE_ACTION *actions)
Builds the turn's actions and sorts them: the party's commands, then the link opponent's or the enemies' actions. Returns how many there are, negative when the link fails.
References btActionOrderSort(), btAppendLinkedActions(), btBuildEnemyActions(), btBuildPartyActions(), btCameraSetCommandView(), btCameraSetDefaultView(), btFleeCheckSuccess(), btLinkBattleWaitSync(), btPaletteCopyWithBrightnessOffset(), btUnitResetGuardLevels(), gmFlagClearStub(), gmFlagSetStub(), gmUnitGetStub(), mnBattleMessageCloseStub() and Sint32.
Referenced by btRun().
Definition at line 649 of file battle_turn.c.
btGetUnitAtPlace
Sint32 btGetUnitAtPlace(Sint32 taggedPlace)
Returns the unit id at a list place, PLACE_ENEMY_SIDE set for the enemies'
list.
References Sint32.
Referenced by btActionRunBuild().
Definition at line 745 of file battle_turn.c.
btFindUnitPlace
Sint32 btFindUnitPlace(Uint32 unitId)
Returns the list place of a unit, PLACE_PARTY or PLACE_ENEMY with its place,
or -1 when it is in neither list.
References Sint32.
Referenced by btAIChooseAction().
Definition at line 756 of file battle_turn.c.
btTurnStartNoOperation
DEFINE_ADJUST_CAMERA(btCameraAdjustByShoulderKeysAlternate) // Does nothing; btRun calls it at the start of each turn. void btTurnStartNoOperation(void)
Unused: a second copy of the camera turn while L or R is held.
References btCameraAdjustByShoulderKeysAlternate() and void().
Referenced by btRun().
Definition at line 784 of file battle_turn.c.