Skip to Content
The Alchemy Project

src/battle/battle_run.c

A battle from its setup to its end (btRun), the party's reserves stepping in for the fallen, the Doom Dragon's change of form, and the lists of the units that fight. More…

Included by battle.c.

Macros

NameDescription
#defineENEMY_UNITS_SIZE (ENEMY_BATTLE_SIZE * BATTLE_UNIT_SIZE)The six enemy units, which gmUnitGet reads for unit ids 128 to 133 while the battle lasts (heap slot HEAP_SLOT_ENEMY_UNITS).
#defineBATTLE_ZOOM_BEFORE_OPENING 190The camera's zoom, in percent, from the battle's setup until the opening sets its own: the curtain's a tick later, or the Doom Dragon's shattering opening's, so no tick shows it.
#defineYAW_TURN_START (TRIG_TURN * 5 / 32)The camera's yaw as a battle starts, and as each turn's commands are chosen: about 56 degrees, a little past YAW_PARTY_ACTION.
#defineNAME_LETTER_NONE 255Name letters past every edition's last, which leave an enemy's name bare: 255, and NAME_LETTER_ALPHABET, past Z, the last letter the Japanese edition gives.
#defineNAME_LETTER_PAST_ALL NAME_LETTER_ALPHABET

Functions

NameDescription
voidbtPartySwapInReserves (void)With the front line down and someone living, sends the reserve members in to take the fallen ones' places, as many as there are of both.
voidbtCameraCreate (void)Allocates the battle camera and sets its starting view.
voidbtChangeEnemyForm (Sint32 formationId)Replaces the first enemy with the Doom Dragon's next form: ENEMY_DOOM_DRAGON_E after FORMATION_DOOM_DRAGON_A, else ENEMY_DOOM_DRAGON_H.
voidbtPlayFormChange (Sint32 formationId)Plays the Doom Dragon's form change effect on the first enemy, after the form of formationId (FORMATION_DOOM_DRAGON_A to C) has fallen.
Sint32btTutorialGetDjinnGiveMessage (void)Returns the first of the Djinn tutorial's messages: the second set's (MsgDjinnGiveTutorialB) while FLAG_ALREADY_KNOWS_DJINN is set, as Up held when Echo's tutorial begins sets it.
Sint32btRun (Sint32 formationId)Fights the battle against the enemy formation formationId, from the opening to the end.
Sint32btPartyPrepareMembers (Uint16 *unitIds)Lists the party members who fight, three in a link battle, into unitIds when it is not null, and returns how many.
Sint32btPartyPrepareReserveOwners (Uint16 *unitIds)Lists the party's reserve members, those past the fourth (none in a link battle), into unitIds when it is not null, puts each on the party's side and returns how many there are.
Sint32btEnemyList (Sint16 *unitIds)Lists the enemy units present and returns how many, 0 when unitIds is null.
Sint32btUnitListLiving (Sint32 sideMask, Uint16 *unitIds)Lists the units still standing on the sides in sideMask, party first, into unitIds when it is not null, and returns how many.
Sint32btUnitListLivingWithReserve (Sint32 sideMask, Uint16 *unitIds)As btUnitListLiving, with the reserve members listed after the front line.
Sint32btUnitListIds (Sint32 sideMask, Uint16 *unitIds)Lists the units in the battle on the sides in sideMask, standing or not, and returns how many.
Sint32btUnitListLivingIds (Sint32 sideMask, Uint16 *unitIds)As btUnitListIds, listing only the units whose HP is not 0.

Description

A battle from its setup to its end (btRun), the party's reserves stepping in for the fallen, the Doom Dragon's change of form, and the lists of the units that fight. Part of battle.c.

Macros in detail

ENEMY_UNITS_SIZE

#define ENEMY_UNITS_SIZE (ENEMY_BATTLE_SIZE * BATTLE_UNIT_SIZE)

The six enemy units, which gmUnitGet reads for unit ids 128 to 133 while the battle lasts (heap slot HEAP_SLOT_ENEMY_UNITS).

Referenced by btRun().

Definition at line 7 of file battle_run.c.

BATTLE_ZOOM_BEFORE_OPENING

#define BATTLE_ZOOM_BEFORE_OPENING 190

The camera's zoom, in percent, from the battle's setup until the opening sets its own: the curtain's a tick later, or the Doom Dragon's shattering opening's, so no tick shows it.

Referenced by btRun().

Definition at line 12 of file battle_run.c.

YAW_TURN_START

#define YAW_TURN_START (TRIG_TURN * 5 / 32)

The camera's yaw as a battle starts, and as each turn's commands are chosen: about 56 degrees, a little past YAW_PARTY_ACTION.

Referenced by btCameraCreate() and btRun().

Definition at line 16 of file battle_run.c.

NAME_LETTER_NONE

#define NAME_LETTER_NONE 255

Name letters past every edition's last, which leave an enemy's name bare: 255, and NAME_LETTER_ALPHABET, past Z, the last letter the Japanese edition gives.

Referenced by btChangeEnemyForm().

Definition at line 82 of file battle_run.c.

NAME_LETTER_PAST_ALL

#define NAME_LETTER_PAST_ALL NAME_LETTER_ALPHABET

Referenced by btRun().

Definition at line 83 of file battle_run.c.

Functions in detail

btPartySwapInReserves

void btPartySwapInReserves(void)

With the front line down and someone living, sends the reserve members in to take the fallen ones' places, as many as there are of both.

References btHighlightSetModes(), btObjectGet(), btObjectPut(), btPartyPrepareReserveOwners(), btUnitListIds(), btUnitListLivingWithReserve(), fdActorSetPosAndResetMotionStub(), MainRoutineStateWork, mnPartyStatusDrawStub(), Sint32 and sySynch().

Referenced by btRun().

Definition at line 20 of file battle_run.c.

btCameraCreate

void btCameraCreate(void)

Allocates the battle camera and sets its starting view.

References Sint32 and syHeapSlotAllocateEWRAM().

Referenced by btRun().

Definition at line 66 of file battle_run.c.

btChangeEnemyForm

void btChangeEnemyForm(Sint32 formationId)

Replaces the first enemy with the Doom Dragon's next form: ENEMY_DOOM_DRAGON_E after FORMATION_DOOM_DRAGON_A, else ENEMY_DOOM_DRAGON_H. The form change's battle effect calls it through its stub call.

References btEnemyClaimNameLetter(), btMotionDestroyAllSlotObjects(), btObjectGet(), btObjectMake(), btObjectMarkForRelease(), btObjectPut(), btPlacementRelayoutEnemies(), gmBattleUnitSetStub() and Sint32.

Definition at line 88 of file battle_run.c.

btPlayFormChange

void btPlayFormChange(Sint32 formationId)

Plays the Doom Dragon's form change effect on the first enemy, after the form of formationId (FORMATION_DOOM_DRAGON_A to C) has fallen.

References btEffectRunFormChangeStub() and Sint32.

Referenced by btRun().

Definition at line 115 of file battle_run.c.

btTutorialGetDjinnGiveMessage

Sint32 btTutorialGetDjinnGiveMessage(void)

Returns the first of the Djinn tutorial's messages: the second set's (MsgDjinnGiveTutorialB) while FLAG_ALREADY_KNOWS_DJINN is set, as Up held when Echo's tutorial begins sets it.

References Sint32 and syGameFlagGet().

Referenced by btRun().

Definition at line 134 of file battle_run.c.

btRun

Sint32 btRun(Sint32 formationId)

Fights the battle against the enemy formation formationId, from the opening to the end. Returns the number of enemies defeated when the party won or the link broke, BATTLE_OUTCOME_FLED or BATTLE_OUTCOME_LOST.

References ActorSpriteSlots, btAutoBattleBuildActions(), btAutoBattleRunAction(), btAwardSpoils(), btBackgroundFree(), btBackgroundInit(), btBackgroundLoad(), btCameraCreate(), btCameraSetDefaultView(), btCameraSetRange(), btCameraSetView(), btCameraUpdate(), btClearSerialTransferPayload(), btDjinnRecoveryCountDown(), btDjinnRecoveryReconcile(), btFindUnitPlace(), btFormationBuildEnemyList(), btGatherActions(), btLinkBattleSyncTurn(), btMessageWaitForAdvance(), btMessageWaitForAdvanceAt(), btMotionDestroyAllSlotObjects(), btObjectPut(), btObjectUpdateSpritePriorities(), btPartyAssignOpponentSlots(), btPartyBattleSetupNoOperation(), btPartyClearBattleStatuses(), btPartyClearGuards(), btPartyPrepareMembers(), btPartySwapInReserves(), btPlayFormChange(), btProcessTurnEnd(), btScriptedBattleRestoreUnits(), btScriptedBattleSaveUnits(), btSpoilsClear(), btStagingDispatchAction(), btSummonUpdateAvailability(), btTransitionRun(), btTurnEndNoOperation(), btTurnStartNoOperation(), btTutorialGetDjinnGiveMessage(), btUnitCollect(), btUnitListLiving(), btUnitListLivingIds(), btUnitListLivingWithReserve(), btUnitRefreshPlacement(), CpuLoadDisplayEnabled, fdActorSystemInitStub(), fdBattleBackgroundGetSelectedStub(), gmBattleRandomStub() and 31 more.

Referenced by btDebugBattleRunForever() and btDebugBattleRunMenu().

Definition at line 144 of file battle_run.c.

btPartyPrepareMembers

Sint32 btPartyPrepareMembers(Uint16 *unitIds)

Lists the party members who fight, three in a link battle, into unitIds when it is not null, and returns how many.

References gmPartyCountMembersStub(), gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by btDjinnRecoveryReconcile(), btFormationSelectLevelMatchedCandidate(), btLinkBattleSendParty(), btPartyAssignOpponentSlots(), btPartyClearBattleStatuses(), btPartyClearGuards(), btRun(), btStagingPlanAuroraField(), btSummonUpdateAvailability(), btTransitionRun(), btUnitCollect(), btUnitListLiving(), btUnitListLivingWithReserve() and btUnitRefreshPlacement().

Definition at line 544 of file battle_run.c.

btPartyPrepareReserveOwners

Sint32 btPartyPrepareReserveOwners(Uint16 *unitIds)

Lists the party's reserve members, those past the fourth (none in a link battle), into unitIds when it is not null, puts each on the party's side and returns how many there are.

References gmPartyCountMembersStub(), gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by btPartyClearBattleStatuses(), btPartyClearGuards(), btPartySwapInReserves(), btProcessTurnEnd(), btStagingPlanAuroraField(), btTransitionRun(), btUnitListLivingWithReserve() and btUnitRefreshPlacement().

Definition at line 575 of file battle_run.c.

btEnemyList

Sint32 btEnemyList(Sint16 *unitIds)

Lists the enemy units present and returns how many, 0 when unitIds is null.

References gmUnitGet(), Sint32 and syGameFlagGet().

Referenced by btAbilityApplyToTarget(), btIntroAnnounceEncounter() and btUnitCollect().

Definition at line 603 of file battle_run.c.

btUnitListLiving

Sint32 btUnitListLiving(Sint32 sideMask, Uint16 *unitIds)

Lists the units still standing on the sides in sideMask, party first, into unitIds when it is not null, and returns how many.

References btPartyPrepareMembers(), gmUnitGet(), Sint32 and syGameFlagGet().

Referenced by btAbilityReplaceDefeated(), btAutoBattleBuildActions(), btAutoBattleRunAttackOrItem(), btAutoBattleRunPsynergy(), btAwardSpoils(), btBuildEnemyActions(), btFleeCheckSuccess(), btFleePlayRun(), btRun(), btStagingDispatchAction(), btStagingRunFlee() and btUnitProcessActionEnd().

Definition at line 638 of file battle_run.c.

btUnitListLivingWithReserve

Sint32 btUnitListLivingWithReserve(Sint32 sideMask, Uint16 *unitIds)

As btUnitListLiving, with the reserve members listed after the front line. A copy rather than a flag to btUnitListLiving: its list of members has room for ten where that one's has eight, and one function would not keep both.

References btPartyPrepareMembers(), btPartyPrepareReserveOwners(), gmUnitGet(), Sint32 and syGameFlagGet().

Referenced by btAwardSpoils(), btPartySwapInReserves() and btRun().

Definition at line 716 of file battle_run.c.

btUnitListIds

Sint32 btUnitListIds(Sint32 sideMask, Uint16 *unitIds)

Lists the units in the battle on the sides in sideMask, standing or not, and returns how many.

References Sint32.

Referenced by btDjinnCountStandby(), btHighlightClearAllSpriteModes(), btHighlightSetModes(), btHighlightSetOtherSpriteModes(), btMotionCallBeast(), btMotionDismissBeast(), btObjectPut(), btObjectPutKeepingPoses(), btObjectUpdateSpritePriorities(), btPartyClearGuards(), btPartyReturnAllToSpots(), btPartySwapInReserves(), btProcessTurnEnd(), btStagingPlanAuroraField(), btStagingRunFullScreen(), btTransitionRun(), btUnitIsListed() and btUnitResetGuardLevels().

Definition at line 793 of file battle_run.c.

btUnitListLivingIds

Sint32 btUnitListLivingIds(Sint32 sideMask, Uint16 *unitIds)

As btUnitListIds, listing only the units whose HP is not 0.

References gmUnitGet() and Sint32.

Referenced by btRun(), btStagingPlanDaedalus() and btStagingPlanHighImpact().

Definition at line 831 of file battle_run.c.