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.
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 as the sort reads it (Sint16). |
#define | CHOOSER_LIST_BYTES (8 * sizeof(Uint16) + 1) | The list mnBattleCollectPartyCommands fills with the unit id of each action the party is still to choose (mnBattlePartySplitChoosers): eight halfwords, and a byte over. |
#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 (16 each, a BATTLE_ACTION_RECORD), 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 | 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 | btBuildUnitActions (BATTLE_ACTION_RECORD *entries) | Builds the party's commands for the turn into entries and returns how many there are, or -1 when none could be chosen. |
Sint32 | btBuildEnemyActions (BATTLE_ACTION_RECORD *entries) | The enemies' actions for the turn, in a shuffled order; none act when the party struck first. |
static inline void | btActionSwap (BATTLE_ACTION_RECORD *a, BATTLE_ACTION_RECORD *b) | Swaps two actions of the turn's order. |
void | btActionOrderSort (BATTLE_ACTION_RECORD *entries, Sint32 count) | Sorts the actions by descending priority, after putting the Djinn that shield, guard or defend ahead of the rest. |
Sint32 | btAppendLinkedActions (BATTLE_ACTION_RECORD *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) | Fills BG palettes 14 and 4 with palettes 15 and 5 (the windows' and the basic colours) with offset added to each colour channel, held within 0 to RGB_LEVEL_MAX. |
Sint32 | btGatherActions (BATTLE_ACTION_RECORD *actions) | Builds this turn's actions and sorts them by descending priority: the allies' commands and either 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. |
Sint32 | btUnitGetPartyAttackEffect (Sint32 characterId) | A party member's attack effect, staged by id range (EFFECT_BY_ID_RANGE): ATTACK_EFFECT_SLASH for Isaac, Garet, Felix, Jenna and Piers, ATTACK_EFFECT_WAVE for Ivan, Mia and Sheba, as their BattleSprites rows give, any other none. |
void | btTurnStartNoOperation (void) | Called by btRun at the start of every turn; does nothing. |
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 17 of file battle_turn.c.
PRIORITY_LOWEST
#define PRIORITY_LOWEST 32768
An empty action's priority, below every other as the sort reads it (Sint16).
Referenced by btGatherActions().
Definition at line 20 of file battle_turn.c.
CHOOSER_LIST_BYTES
#define CHOOSER_LIST_BYTES (8 * sizeof(Uint16) + 1)
The list mnBattleCollectPartyCommands fills with the unit id of each action
the party is still to choose (mnBattlePartySplitChoosers): eight halfwords,
and a byte over.
Referenced by btBuildUnitActions().
Definition at line 139 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 320 of file battle_turn.c.
LINK_TRANSFER_TIMEOUT
#define LINK_TRANSFER_TIMEOUT 300
Referenced by btAppendLinkedActions().
Definition at line 321 of file battle_turn.c.
LINK_ACTIONS_BYTES
#define LINK_ACTIONS_BYTES(count)
The bytes of count actions (16 each, a BATTLE_ACTION_RECORD), in whole
packets.
Referenced by btAppendLinkedActions().
Definition at line 324 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 8 of file battle_turn.c.
Functions in detail
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(), ProjectionWork, result, Sint32, syCalcPoint(), syDivFX(), syInitMatrix(), syMatrixTranslateVector(), syRotX(), syRotY() and sySetScreenDist().
Referenced by btGatherActions().
Definition at line 24 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(), gmUnitGet() and Sint32.
Referenced by btGatherActions().
Definition at line 66 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 none ever leaves a battle that cannot be fled. Returns 1 when the party gets away.
References btUnitListLiving(), gmUnitGet(), MainRoutineStateWork, Sint32 and syRandom().
Referenced by btGatherActions().
Definition at line 87 of file battle_turn.c.
btBuildUnitActions
Sint32 btBuildUnitActions(BATTLE_ACTION_RECORD *entries)
Builds the party's commands for the turn into entries and returns how many there are, or -1 when none could be chosen.
References mnBattleCollectPartyCommandsStub(), result, Sint32, syHeapAllocateEWRAM() and syHeapRelease().
Referenced by btGatherActions().
Definition at line 143 of file battle_turn.c.
btBuildEnemyActions
Sint32 btBuildEnemyActions(BATTLE_ACTION_RECORD *entries)
The enemies' actions for the turn, in a shuffled order; none act when the party struck first. Returns how many there are.
References btAIChooseAction(), btUnitListLiving(), gmUnitGet(), Sint32 and syRandom().
Referenced by btGatherActions().
Definition at line 157 of file battle_turn.c.
btActionSwap
static inline void btActionSwap(BATTLE_ACTION_RECORD *a, BATTLE_ACTION_RECORD *b)
Swaps two actions of the turn's order.
Referenced by btActionOrderSort().
Definition at line 256 of file battle_turn.c.
btActionOrderSort
void btActionOrderSort(BATTLE_ACTION_RECORD *entries, Sint32 count)
Sorts the actions by descending priority, after putting the Djinn that shield, guard or defend ahead of the rest.
References btActionSwap(), gmAbilityGetDefinitionStub(), gmDjinnGetAbilityIdStub(), gmUnitGet() and Sint32.
Referenced by btGatherActions().
Definition at line 268 of file battle_turn.c.
btAppendLinkedActions
Sint32 btAppendLinkedActions(BATTLE_ACTION_RECORD *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, result, SerialReceivedSize, Sint32, syHeapAllocateEWRAM(), syHeapRelease(), syLinkBattleResetTransferState(), sySerialGetActiveTransfers(), sySerialRemoveIRQHandlers(), sySerialStartReceive(), sySerialStartSend() and sySynch().
Referenced by btGatherActions().
Definition at line 331 of file battle_turn.c.
btPaletteCopyWithBrightnessOffset
void btPaletteCopyWithBrightnessOffset(Sint32 offset)
Fills BG palettes 14 and 4 with palettes 15 and 5 (the windows' and the basic
colours) with offset added to each colour channel, held within 0 to
RGB_LEVEL_MAX.
References Sint32.
Referenced by btGatherActions().
Definition at line 519 of file battle_turn.c.
btGatherActions
Sint32 btGatherActions(BATTLE_ACTION_RECORD *actions)
Builds this turn's actions and sorts them by descending priority: the allies' commands and either the link opponent's or the enemies' actions. Returns the action count, or a negative value on cancellation or link failure.
References btActionOrderSort(), btAppendLinkedActions(), btBuildEnemyActions(), btBuildUnitActions(), btCameraSetCommandView(), btCameraSetDefaultView(), btFleeCheckSuccess(), btLinkBattleWaitSync(), btPaletteCopyWithBrightnessOffset(), btUnitResetGuardLevels(), gmUnitGet(), mnBattleMessageCloseStub(), Sint32, syGameFlagClear() and syGameFlagSet().
Referenced by btRun().
Definition at line 562 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() and btStagingPlanDaedalus().
Definition at line 658 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() and btRun().
Definition at line 669 of file battle_turn.c.
btUnitGetPartyAttackEffect
Sint32 btUnitGetPartyAttackEffect(Sint32 characterId)
A party member's attack effect, staged by id range (EFFECT_BY_ID_RANGE):
ATTACK_EFFECT_SLASH for Isaac, Garet, Felix, Jenna and Piers,
ATTACK_EFFECT_WAVE for Ivan, Mia and Sheba, as their BattleSprites rows give,
any other none.
References Sint32.
Referenced by btActionRunBuild() and btStagingDispatchAction().
Definition at line 700 of file battle_turn.c.
btTurnStartNoOperation
void btTurnStartNoOperation(void)
Called by btRun at the start of every turn; does nothing.
Referenced by btRun().
Definition at line 719 of file battle_turn.c.