Alchemy
Loading...
Searching...
No Matches

turn_end.c File Reference

The end of a turn and of a round: counters, Djinn recovery, poison and the Grim Reaper. More...

Go to the source code of this file.

Data Structures

struct  BattleGroupOrder
 The order the two sides' units take their round-end effects in, as gBattleParty_RoundEndGroupOrder gives it. More...

Macros

#define DEFINE_TICK_MODIFIER(name, counter, level)
 Defines a stat change's turn-end tick, as BattleUnit_TickAttackModifier is with bias 20: clears level and returns 1 when counter runs out, or clears both when a lowered stat recovers early.
#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 the status ends early at bias.

Functions

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_TickAttackModifier (s32 unitId)
 Counts down an Attack change and returns 1 when it ends.
s32 BattleUnit_TickDefenseModifier (s32 unitId)
 Counts down a Defense change; Battle_ProcessRoundEnd shows MsgDefNormal when it returns 1.
s32 BattleUnit_TickResistanceModifier (s32 unitId)
 Counts down a Resistance change; Battle_ProcessRoundEnd shows MsgResNormal when it returns 1.
s32 BattleUnit_TickDelusion (s32 unitId)
 Counts down delusion, which may end early at bias 30; Battle_ProcessRoundEnd shows MsgCureDelusion when it returns 1.
s32 BattleUnit_TickConfusion (s32 unitId)
 Counts down confusion, which may end early at bias 60; Battle_ProcessRoundEnd shows MsgConscious when it returns 1.
s32 BattleUnit_TickCharm (s32 unitId)
 Counts down charm, which may end early at bias 70; Battle_ProcessRoundEnd shows MsgConscious2 when it returns 1.
s32 BattleUnit_TickStun (s32 unitId)
 Counts down stun, which may end early at bias 40; Battle_ProcessRoundEnd shows MsgCureStun when it returns 1.
s32 BattleUnit_TickSleep (s32 unitId)
 Counts down sleep, which may end early at bias 50; Battle_ProcessRoundEnd shows MsgWakes when it returns 1.
s32 Battle_AdvanceCounterAndCheckChance (s32 unitId)
 Counts down both seals packed in BattleUnit.psySeal and returns 1 when the last ends.
s32 BattleUnit_TickRefrain (s32 unitId)
 Counts down BattleUnit.refrain and returns 1 when it runs out; it never ends early.
s32 BattleUnit_TickReflect (s32 unitId)
 Counts down Reflect and returns 1 when it runs out; it never ends early.
s32 BattleUnit_TickAgilityModifier (s32 unitId)
 Counts down an Agility change, clearing agilityStage and returning 1 when it runs out; unlike the other stats it never ends early.
s32 DjinnRecovery_Tick (void)
 Brings the party's recovering Djinn one turn nearer, setting each whose turns reach 0, and returns 1 when any was set.
s32 DjinnRecovery_TickTwenty (void)
 Runs DjinnRecovery_Tick twenty times, which sets every recovering Djinni of a party member with HP.
void Battle_ReservedNoOpF674 (void)
 Does nothing; Battle_RunEncounter calls it at the end of each round and of the battle.
s32 Battle_ProcessRoundEnd (void)
 Ends a round: sets recovered Djinn, then gives each unit its regeneration and counts down its stat changes and statuses, showing each that ends.
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 recover, and the actor takes its summon's power boost, the haunt's damage, poison and the Grim Reaper.

Detailed Description

The end of a turn and of a round: counters, Djinn recovery, poison and the Grim Reaper.

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

Definition in file turn_end.c.

Macro Definition Documentation

◆ DEFINE_TICK_MODIFIER

#define DEFINE_TICK_MODIFIER ( name,
counter,
level )
Value:
s32 name(s32 unitId) { \
struct BattleUnit *state = UnitGetFar(unitId); \
\
if (state->counter != 0) { \
state->counter--; \
if (state->counter == 0) { \
state->level = 0; \
return 1; \
} \
if (state->level < 0 && \
BattleUnit_RollCounterEarlyEnd(unitId, state->counter, 20) != 0) { \
state->level = 0; \
state->counter = 0; \
return 1; \
} \
} \
return 0; \
}
struct BattleUnit * UnitGetFar(u32 owner)
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 level
1 to 99 for a character
s32 BattleUnit_RollCounterEarlyEnd(s32 unitId, s32 turns, s32 bias)
Rolls whether a stat change or status with five turns or fewer left ends early.
Definition turn_end.c:13
signed int s32
Definition types.h:14

Defines a stat change's turn-end tick, as BattleUnit_TickAttackModifier is with bias 20: clears level and returns 1 when counter runs out, or clears both when a lowered stat recovers early.

Definition at line 55 of file turn_end.c.

Referenced by BattleUnit_TickDefenseModifier().

◆ DEFINE_TICK_STATUS

#define DEFINE_TICK_STATUS ( name,
counter,
bias )
Value:
s32 name(s32 unitId) { \
struct BattleUnit *state = UnitGetFar(unitId); \
if (state->counter != 0) { \
state->counter--; \
if (state->counter == 0) \
return 1; \
if (BattleUnit_RollCounterEarlyEnd(unitId, state->counter, bias) != 0) { \
state->counter = 0; \
return 1; \
} \
} \
return 0; \
}

Defines a status's turn-end tick: returns 1 when counter runs out, or clears it and returns 1 when the status ends early at bias.

Definition at line 85 of file turn_end.c.

Referenced by BattleUnit_TickCharm(), BattleUnit_TickDelusion(), BattleUnit_TickSleep(), and BattleUnit_TickStun().

Function Documentation

◆ BattleUnit_RollCounterEarlyEnd()

s32 BattleUnit_RollCounterEarlyEnd ( s32 unitId,
s32 turns,
s32 bias )

Rolls whether a stat change or status with five turns or fewer left ends early.

The chance is luck * 3 - turns * 5 + bias percent, so a lucky unit and a counter near its end recover sooner. Called by the turn-end Tick functions below, each with its own bias.

Definition at line 13 of file turn_end.c.

Referenced by Battle_AdvanceCounterAndCheckChance(), BattleUnit_RollCounterEarlyEnd(), BattleUnit_TickAttackModifier(), and BattleUnit_TickConfusion().

◆ BattleUnit_TickAttackModifier()

s32 BattleUnit_TickAttackModifier ( s32 unitId)

Counts down an Attack change and returns 1 when it ends.

Clears attackStage when the turns run out, and clears attackStage and attackTurns when a lowered Attack recovers early (bias 30). Called by Battle_ProcessRoundEnd, which then shows MsgAtkNormal.

Definition at line 30 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickAttackModifier().

◆ BattleUnit_TickDefenseModifier()

s32 BattleUnit_TickDefenseModifier ( s32 unitId)

Counts down a Defense change; Battle_ProcessRoundEnd shows MsgDefNormal when it returns 1.

Definition at line 77 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickDefenseModifier().

◆ BattleUnit_TickResistanceModifier()

s32 BattleUnit_TickResistanceModifier ( s32 unitId)

Counts down a Resistance change; Battle_ProcessRoundEnd shows MsgResNormal when it returns 1.

Definition at line 81 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickDefenseModifier().

◆ BattleUnit_TickDelusion()

s32 BattleUnit_TickDelusion ( s32 unitId)

Counts down delusion, which may end early at bias 30; Battle_ProcessRoundEnd shows MsgCureDelusion when it returns 1.

Definition at line 102 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickDelusion().

◆ BattleUnit_TickConfusion()

s32 BattleUnit_TickConfusion ( s32 unitId)

Counts down confusion, which may end early at bias 60; Battle_ProcessRoundEnd shows MsgConscious when it returns 1.

Definition at line 106 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickConfusion().

◆ BattleUnit_TickCharm()

s32 BattleUnit_TickCharm ( s32 unitId)

Counts down charm, which may end early at bias 70; Battle_ProcessRoundEnd shows MsgConscious2 when it returns 1.

Definition at line 125 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickCharm().

◆ BattleUnit_TickStun()

s32 BattleUnit_TickStun ( s32 unitId)

Counts down stun, which may end early at bias 40; Battle_ProcessRoundEnd shows MsgCureStun when it returns 1.

Definition at line 128 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickStun().

◆ BattleUnit_TickSleep()

s32 BattleUnit_TickSleep ( s32 unitId)

Counts down sleep, which may end early at bias 50; Battle_ProcessRoundEnd shows MsgWakes when it returns 1.

Definition at line 131 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickSleep().

◆ Battle_AdvanceCounterAndCheckChance()

s32 Battle_AdvanceCounterAndCheckChance ( s32 unitId)

Counts down both seals packed in BattleUnit.psySeal and returns 1 when the last ends.

Luff's seal counts down by 8 above the low three bits and Bind's by 1 in them (PSY_SEAL_LUFF, PSY_SEAL_BIND); only Bind's, once Luff's is gone, may end early (bias 30), which clears psySeal. Called by Battle_ProcessRoundEnd, which then shows MsgCureSeal.

Definition at line 139 of file turn_end.c.

Referenced by Battle_AdvanceCounterAndCheckChance(), and Battle_ProcessRoundEnd().

◆ BattleUnit_TickRefrain()

s32 BattleUnit_TickRefrain ( s32 unitId)

Counts down BattleUnit.refrain and returns 1 when it runs out; it never ends early.

Battle_ProcessRoundEnd then shows MsgRefrainEnd.

Definition at line 174 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickRefrain().

◆ BattleUnit_TickReflect()

s32 BattleUnit_TickReflect ( s32 unitId)

Counts down Reflect and returns 1 when it runs out; it never ends early.

Battle_ProcessRoundEnd then shows MsgReflectEnd.

Definition at line 187 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickReflect().

◆ BattleUnit_TickAgilityModifier()

s32 BattleUnit_TickAgilityModifier ( s32 unitId)

Counts down an Agility change, clearing agilityStage and returning 1 when it runs out; unlike the other stats it never ends early.

Battle_ProcessRoundEnd then shows MsgAgiNormal.

Definition at line 201 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and BattleUnit_TickAgilityModifier().

◆ DjinnRecovery_Tick()

s32 DjinnRecovery_Tick ( void )

Brings the party's recovering Djinn one turn nearer, setting each whose turns reach 0, and returns 1 when any was set.

A Djinni counts down only while its owner has HP; one that is set is taken off the party's recovery list and its owner's stats worked out again (UnitCalc). Called once at the end of every battle by Battle_RunEncounter, and outside battle by Field_ProcessStep as the party walks, by the Djinn menu's tutorial and by DjinnRecovery_TickTwenty.

Definition at line 221 of file turn_end.c.

Referenced by Battle_RunEncounter(), DjinnRecovery_Tick(), and DjinnRecovery_TickTwenty().

◆ DjinnRecovery_TickTwenty()

s32 DjinnRecovery_TickTwenty ( void )

Runs DjinnRecovery_Tick twenty times, which sets every recovering Djinni of a party member with HP.

Called by the link lobby when it restores the party, and by Vault's scene before Ivan hands back Isaac's Djinni.

Definition at line 269 of file turn_end.c.

Referenced by DjinnRecovery_TickTwenty(), LinkLobby_RunRoundResult(), and Vault_ReturnIsaacsDjinni().

◆ Battle_ReservedNoOpF674()

void Battle_ReservedNoOpF674 ( void )

Does nothing; Battle_RunEncounter calls it at the end of each round and of the battle.

Definition at line 282 of file turn_end.c.

Referenced by Battle_ReservedNoOpF674(), and Battle_RunEncounter().

◆ Battle_ProcessRoundEnd()

s32 Battle_ProcessRoundEnd ( void )

Ends a round: sets recovered Djinn, then gives each unit its regeneration and counts down its stat changes and statuses, showing each that ends.

Called by Battle_RunEncounter once every unit has acted. Changes HP, PP, BattleUnit.ready, the Djinn recovery lists and the counters the Tick functions clear, and puts the background back in its perspective mode (2).

Definition at line 298 of file turn_end.c.

Referenced by Battle_ProcessRoundEnd(), and Battle_RunEncounter().

◆ BattleUnit_ProcessTurnEnd()

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 recover, and the actor takes its summon's power boost, the haunt's damage, poison and the Grim Reaper.

Called by BattlePresentation_DispatchAction after every action, with the action's plan. Changes the side's Djinn recovery list, the actor's elementLevels, HP and grimReaper, and works out its stats again (UnitCalc); the messages are queued and played at once (BattleEv_DispatchQueued).

Definition at line 528 of file turn_end.c.

Referenced by BattlePresentation_DispatchAction(), and BattleUnit_ProcessTurnEnd().