19 s32 threshold = ((unit->
luck * 3 - turns * 5) + bias) * 0x28f;
55#define DEFINE_TICK_MODIFIER(name, counter, level) \
56 s32 name(s32 unitId) { \
57 struct BattleUnit *state = UnitGetFar(unitId); \
59 if (state->counter != 0) { \
61 if (state->counter == 0) { \
65 if (state->level < 0 && \
66 BattleUnit_RollCounterEarlyEnd(unitId, state->counter, 20) != 0) { \
85#define DEFINE_TICK_STATUS(name, counter, bias) \
86 s32 name(s32 unitId) { \
87 struct BattleUnit *state = UnitGetFar(unitId); \
88 if (state->counter != 0) { \
90 if (state->counter == 0) \
92 if (BattleUnit_RollCounterEarlyEnd(unitId, state->counter, bias) != 0) { \
148 turns = sealCounter & 0xFF;
155 if (sealCounter & 7) {
156 decremented = sealCounter + 0xFF;
158 sealCounter = decremented;
160 remaining = sealCounter;
163 if (remaining <= 7U &&
233 if (index < initialCount) {
241 }
while (index < list->count);
246 if (index < list->count) {
249 if (expiredEntry->
turns == 0) {
260 }
while (index < list->count);
276 }
while (turns >= 0);
312 sideCount = (battle->
twoSided != 0) + 1;
313 for (side = 0; side < sideCount; side++) {
317 if (recoveryIndex < list->count) {
326 }
while (recoveryIndex < list->count);
334 if (recoveryIndex < list->count) {
337 if (expiredEntry->
turns == 0) {
348 expiredEntry->
index +
358 element = expiredEntry->
element;
361 expiredEntry->
index);
370 }
while (recoveryIndex < list->count);
390 groupList = order.
group;
393 for (unitIndex = 0; unitIndex < count; unitIndex++) {
396 s32 unitId = unitIds[unitIndex];
399 if (unit->
ready != 0) {
406 if (unit->
hp + hpAmount > unit->
maxHp) {
407 hpAmount = unit->
maxHp - unit->
hp;
422 if (unit->
pp + ppAmount > unit->
maxPp) {
423 ppAmount = unit->
maxPp - unit->
pp;
535 s32 strongestElement;
545 (unitId < 0 || unitId > 7)))
547 for (strongestElement = 0; strongestElement <
list->
count;
548 strongestElement++) {
564 (unitId < 0 || unitId > 7)))
570 for (i = 0; i < 4; i++) {
575 for (i = 0; i < pending->
count; i++) {
585 for (i = 0; i < pending->
count; i++) {
592 if (recoveryTurn <= 1) {
595 for (i = 0; i < pending->
count; i++) {
605 if (battleContinues != 0) {
607 s32 mostOfOneElement;
612 mostOfOneElement = 0;
615 strongestElement = -1;
616 for (i = 0; i <= 3; i++) {
617 if (counts[i] > mostOfOneElement) {
618 mostOfOneElement = counts[i];
619 strongestElement = i;
622 if (strongestElement >= 0 &&
627 for (i = 0; i <= 3; i++) {
652 if (battleContinues != 0) {
664 if (unitId >= 0 && unitId <= 7) {
667 text = MsgStrengthExhausted;
696 if (unitId >= 0 && unitId <= 7) {
699 text = MsgStrengthExhausted;
718 if (unitId >= 0 && unitId <= 7) {
void BattlePresentation_ConfigurePaletteFade(s32 mode, s32 unusedResource, s32 fade)
Switches the background's display mode, optionally sets its palette, and rebuilds both its maps.
s32 BattleParty_ListLivingUnits(s32 sideMask, u16 *unitIds)
Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY,...
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...
u32 BattleEvPush(u32 opcode, u32 operand)
Queues one battle event (enum BattleEventOpcode) with its operand, and returns the opcode.
u32 BattleEv_DispatchQueued(void)
Plays the queued battle events at once, in order (BattleEvent_Playback plays them over frames instead...
s32 BattlePresentation_WaitForAdvance(void)
Shows the bobbing arrow at the message window and waits for the player to go on (B,...
s32 BattlePres_SetActorModeAndAction(s32 unitId)
Sets unit id's pose to match its state: held (asleep, stunned or unable to move) or down,...
struct BattleObj * BattleObjGet(s32 unitId)
Returns unitId's battle object, through its place, or null for a unit with no place.
s32 BattleUnit_BuildStatusFlags(s32 unitId, struct BattleObj *battleObject)
Builds the status icon bits of unit id's ailments into its battle object's activeConditions,...
const struct BattleGroupOrder gBattleParty_RoundEndGroupOrder
@ BATTLE_EVENT_DEFEAT
the unit falls; an enemy fades out
@ BATTLE_EVENT_UNIT_NAME
a unit's name for the next message
@ BATTLE_EVENT_DRAW_STATUS
redraws the party's status
@ BATTLE_EVENT_HIT
the unit flinches and flashes
@ BATTLE_EVENT_ABILITY_NAME
an ability's name for the next message
@ BATTLE_EVENT_REFRESH_UNIT
the unit's status icons, colour, pose
@ BATTLE_EVENT_NUMBER
a number for the next message
@ BATTLE_EVENT_SOUND
plays a sound
What every part of the battle object shares: its includes, in their original order,...
struct BattleWork * gBattleWork
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_SetAnimationSpeedFar(struct DispatchObject *obj, s32 val)
struct BattleUnit * UnitGetFar(u32 owner)
s16 Unit_AddPpFar(s32 owner, s32 delta)
void * Djinn_GetRecoveryTableFar(s32 arg0)
s32 DjinnRecovery_RemoveFar(s32 owner, s32 index, s32 bit)
u32 Djinn_DeactivateFar(s32 owner, s32 index, s32 bit)
s32 Unit_AddHpFar(s32 owner, s32 delta)
s32 BattleRandomFar(void)
s32 Djinn_ActivateFar(s32 owner, s32 index, s32 bit)
void UnitCalcFar(s32 owner)
void AudioCommand_PlayFar(s32 id)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
void UiText_ShowMessageAndWaitCoreFar(s32 argument)
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
void MemFree(void *buffer)
s32 BattleEventRuntime_SchedulePhase(s32 frames)
Empties the event queue and schedules playback of the events queued next, with no targets to resolve.
s32 BattleEventRuntime_WaitForReady(void)
Waits, a frame at a time, until BattleEvent_Playback has played every target, then removes the callba...
void BattleEventRuntime_Reset(void)
Stops playback and empties the event queue.
void BattleFx_PlayUnitElementEffect(s32 unitId, s32 element, s32 mode, s32 variant)
Plays a glow of the element about a unit, and returns when it is over.
s16 power
Elemental power in the element.
s32 pendingCue
hit sound (an SE_ id), played on the next hit
The order the two sides' units take their round-end effects in, as gBattleParty_RoundEndGroupOrder gi...
s32 group[2]
enum BattleSideMask: the party (1), then the enemies (2)
One action, as BattleCommand_BuildPlan lays it out for BattleTargetExec to apply target by target.
u32 hauntDamage
The damage the evil spirit deals a haunted actor at the end of its turn.
u8 actorId
the acting unit
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 agilityTurns
the Agility change's turns left, 5 when cast
u8 luck
0 to 99 (UnitCalc)
u8 hpRegen
HP regained at each turn's end (UnitCalc).
s8 elementLevels[4]
A summon's boost to each element: the Djinn of that element the summon spent, adding (n * n + n) * 5 ...
u8 grimReaper
The Grim Reaper's countdown: 7 when cursed, down one at each turn's end; at 0 the unit falls.
u8 psySeal
bits: 7..3 Luff (16 when cast, minus 8 a turn) | 2..0 Bind's turns (7 when cast).
u8 ppRegen
PP regained at each turn's end, 0 to 200 (UnitCalc): 4 more once the lighthouse of the character's el...
s16 maxPp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
s8 poison
1 poisoned, 2 deadly poison
s16 hp
current HP, 0 when downed
struct BattleElementStats element[4]
Power and resistance in each element, 0 to 200, after equipment, element levels and Resistance stages...
s16 maxHp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
s8 agilityStage
The Agility stage: -4 (Vine) to 8 (Zephyr, twice the Agility).
u8 refrain
Regenerate's turns left, 7 when cast.
s8 reflect
Reflect's turns left, 7 when cast.
u8 attackTurns
Each stat change: the turns it has left, and its stage (UnitCalc: an eighth of Attack,...
u8 delusion
Delusion to sleep: the turns each status has left, 7 when it lands; each may end sooner at the end of...
u8 ready
Kite's extra action: 2 when cast, down one at each turn's end; while nonzero UnitCalc gives the unit ...
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
u16 background
the battle background's id
u8 twoSided
1 in a link battle
struct BattleEventState events
u8 linkSide
this console's multiplayer id
A field object as the object dispatcher's far calls take it.
A Djinni on standby or recovering: its element and index, its owner, and the turns until it is set ag...
s8 turns
Turns until it is set again; -1 on standby (DJINN_RECOVERY_AFTER_BATTLE), -2 while a summon uses it.
u8 index
the Djinni within its element, 0 to 19
One side's Djinn recovery list: up to 64 entries and their count.
struct DjinnRecoveryEntry entries[64]
One side's Djinn recovery table, as Djinn_GetRecoveryTable returns it.
struct DjinnRecoveryList list
s32 BattleUnit_TickStun(s32 unitId)
Counts down stun, which may end early at bias 40; Battle_ProcessRoundEnd shows MsgCureStun when it re...
s32 Battle_ProcessRoundEnd(void)
Ends a round: sets recovered Djinn, then gives each unit its regeneration and counts down its stat ch...
s32 BattleUnit_ProcessTurnEnd(struct BattlePlan *plan)
Ends one unit's turn: its Djinn on standby are taken off its set, the Djinn a summon used begin to re...
s32 BattleUnit_RollCounterEarlyEnd(s32 unitId, s32 turns, s32 bias)
Rolls whether a stat change or status with five turns or fewer left ends early.
s32 BattleUnit_TickReflect(s32 unitId)
Counts down Reflect and returns 1 when it runs out; it never ends early.
s32 BattleUnit_TickResistanceModifier(s32 unitId)
Counts down a Resistance change; Battle_ProcessRoundEnd shows MsgResNormal when it returns 1.
#define DEFINE_TICK_MODIFIER(name, counter, level)
Defines a stat change's turn-end tick, as BattleUnit_TickAttackModifier is with bias 20: clears level...
s32 BattleUnit_TickSleep(s32 unitId)
Counts down sleep, which may end early at bias 50; Battle_ProcessRoundEnd shows MsgWakes when it retu...
s32 BattleUnit_TickDelusion(s32 unitId)
Counts down delusion, which may end early at bias 30; Battle_ProcessRoundEnd shows MsgCureDelusion wh...
s32 BattleUnit_TickRefrain(s32 unitId)
Counts down BattleUnit.refrain and returns 1 when it runs out; it never ends early.
s32 BattleUnit_TickDefenseModifier(s32 unitId)
Counts down a Defense change; Battle_ProcessRoundEnd shows MsgDefNormal when it returns 1.
s32 DjinnRecovery_Tick(void)
Brings the party's recovering Djinn one turn nearer, setting each whose turns reach 0,...
s32 Battle_AdvanceCounterAndCheckChance(s32 unitId)
Counts down both seals packed in BattleUnit.psySeal and returns 1 when the last ends.
#define DEFINE_TICK_STATUS(name, counter, bias)
Defines a status's turn-end tick: returns 1 when counter runs out, or clears it and returns 1 when th...
s32 DjinnRecovery_TickTwenty(void)
Runs DjinnRecovery_Tick twenty times, which sets every recovering Djinni of a party member with HP.
s32 BattleUnit_TickAgilityModifier(s32 unitId)
Counts down an Agility change, clearing agilityStage and returning 1 when it runs out; unlike the oth...
s32 BattleUnit_TickCharm(s32 unitId)
Counts down charm, which may end early at bias 70; Battle_ProcessRoundEnd shows MsgConscious2 when it...
s32 BattleUnit_TickAttackModifier(s32 unitId)
Counts down an Attack change and returns 1 when it ends.
s32 BattleUnit_TickConfusion(s32 unitId)
Counts down confusion, which may end early at bias 60; Battle_ProcessRoundEnd shows MsgConscious when...
void Battle_ReservedNoOpF674(void)
Does nothing; Battle_RunEncounter calls it at the end of each round and of the battle.
#define PUSH_MESSAGE(message)
Pushes a message to show, waiting for the player to read it.