Alchemy
Loading...
Searching...
No Matches

battle.h File Reference

Go to the source code of this file.

Macros

#define PUSH_MESSAGE(message)
 Pushes a message to show, waiting for the player to read it.
#define DEFINE_ADJUST_CAMERA(name)
 Moves camera yaw by 512 while L/R is held; two identical functions exist.

Functions

s32 DebugParty_LoadPreset (s32 preset)
 Debug: replaces the party with the members of preset number preset.
void DebugBattle_ViewMessages (void)
 Debug: a message viewer that never returns.
void DebugBattle_RunMenu (void)
 Debug: the battle test menu, which never returns.
void BattlePresentation_UpdateCamera (void)
 Runs each frame of a battle.
void BattleIntro_AnnounceEncounter (s32 enemyCount)
 Announces the enemies at the start of a battle, then whether the party strikes first or is caught by surprise.
void BattleParty_CollectUnitList (void)
 Fills the battle's two unit lists, each ended by BATTLE_UNIT_LIST_END: the party members in their order, and the enemies, left to right for a random formation or, for a fixed one, alternating out from the centre (gBattleParty_CenterOrderOffsets).
s32 BattlePresentation_InitializeTilePattern (void)
 Moves the 16 bytes at VRAM 0x06000290 down to 0x06000280 and clears the 20 bytes from 0x0600028c.
void BattlePresentation_ClearBg0VerticalOffset (void)
 Nothing in the source calls it.
void Party_ReservedNoOp5B14 (s32 unused)
 Does nothing; Battle_RunEncounter calls it with 1 as the battle is set up.
s32 BattleParty_ResetActiveRuntimeFields (void)
 Clears every battle-only state of the party members (stat stages and their turns, statuses, Djinn element boosts, the countdowns) and recalculates their stats, as a battle ends.
s32 BattleParty_ReconcileDjinnRecovery (void)
 Brings the Djinn recovery list up to date as a battle starts: every Djinni a party member has on standby that the list lacks joins it.
struct BattleSummonState * BattleSummon_UpdateAvailability (void)
 Works out which summons the party can call: one whose Djinn requirement of every element is met by the party's Djinn of that element, all members together.
void BattleSummon_ReservedNoOp (void)
 Does nothing; nothing in the source calls it.
s32 LinkBattle_ReceiveParty (void)
 Link battle: receives the opponent's party into the enemy units, one member at a time, and puts the "Enemy" label (MsgEnemyLabel) before each name; then receives the opponent's Djinn recovery list.
s32 LinkBattle_SendParty (void)
 Link battle: sends the party, one member at a time and three places in all (an empty place has side 0), then the Djinn recovery list with each owner given the unit id the opponent knows them by.
u8 * Text_CopyFiveCharsPaddingUnderscore (u32 unused0, u32 unused1, u16 *source)
 Copies four characters of a name and a terminator, an underscore for each missing character, and returns a pointer to the terminator.
s32 BattlePres_WaitSync (void)
 In a link battle, shows the "EXEC" signature to the other console and waits up to 30 frames for it to show the same.
s32 BattlePres_SyncTurn (void)
 In a link battle, after each action and after the end of each round, steps both consoles through the same handshake: "ex" "TU", then "rn", "EXEC", "tu" and finally "RN".
s32 BattleParty_AssignMemberSlots (void)
 Records, for each party member, the unit id the link opponent knows them by (FIRST_ENEMY_UNIT plus their place in the party), in gBattleWork->ownerSlots.
s32 Battle_ClearSerialTransferPayload (void)
 Clears the link transfer's payload, the signatures included.
s32 Battle_RunEncounter (s32 enemyGroup)
 Fights the battle against the enemy formation enemyGroup, from the opening transition to the end, and returns how it ended: the number of enemies defeated when the party won (or the link broke), ENCOUNTER_FLED when the party ran, or ENCOUNTER_PARTY_LOST.
void BattlePres_AdjustCameraByShoulderKeys (void)
 Turns the camera while L or R is held. Nothing in the source calls it.
void BattlePres_AdjustCameraByShoulderKeysAlt (void)
 Turns the camera while L or R is held (a second copy).
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_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 BattleParty_PrepareActiveOwners (u16 *owners)
 Lists the party members who fight (the first four of the party, three in a link battle) and marks each unit as a party member.
s32 BattleEnemyList (s16 *unitIds)
 Lists the enemy units present, ended by BATTLE_UNIT_LIST_END, and returns how many there are (0 when unitIds is null).
s32 BattleParty_ListLivingUnits (s32 sideMask, u16 *unitIds)
 Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY, BATTLE_SIDE_ENEMIES or both), party first.
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 removed from the battle.
void BattleObjPut (void)
 Readies the sprite of every unit in the battle (releasing those of units that left) and sets each one's display mode and motion afresh.
void BattleParty_ListAllUnitsAndSubmit (void)
 Readies the sprite of every unit in the battle (releasing those of units that left), keeping their modes and motions.
s32 BattleMotion_GetSlotPalette (s32 unitId)
 Returns the palette of unit id's battle object.
s32 EnemyCheck (s32 classId)
 Returns 1 if an enemy of class classId would find room among the enemy sprite slots: one free slot for a small enemy, two free side by side for a large one.
s32 SummonSlot_RegisterActorSprites (s32 unitId)
 Loads an enemy unit's battle sprite into the first free enemy sprite slots (one for a small enemy, two side by side for a large one) and records the unit as their owner.
s32 BattleMotion_ReleaseObjectSlotByValue (s32 unitId)
 Frees every enemy sprite slot unit unitId holds, unloading its sprite.
s32 BattleUnit_GetWeaponKind (s32 itemId)
 Returns the kind of the weapon whose item id is itemId (0 to 5), which picks a party member's attack animation, or WEAPON_KIND_NONE for an item the list lacks.
s32 BattleUnit_LookupWeaponValueByClass (s32 unitId)
 Returns the weapon sprite a party member's attack shows for the kind of weapon they have equipped (gBattleUnit_WeaponAnimsClass*), or 0 for no weapon, for Felix, or for a unit that is no party member.
void BattleObjMake (struct BattleObj *actor, s32 unitId, s32 x, s32 y)
 Creates the battle object of unit at (x, y) on the battlefield, in pixels: its sprite (an enemy's from its class, sharing the slot it already holds; a party member's battle sprite), palette, size and weapon sprite, turned to face the centre, and starts its motion script (gBattlePres_ActorObjectScript).
void BattlePlacement_GetStepPair (s32 partyPlace, s32 *x, s32 *y)
 Reads the battlefield position of party place index from gBattlePlacement_StepPairs, in pixels.
void Summon_LayoutPositions (u16 *actorIds, s32 count, s32 *xPositions, s32 *zPositions)
 Lays out count enemies in a column 80 pixels left of the centre, spaced by their size (38 pixels around a large enemy, 27 around a small one, 25 around an empty place, closer when there are more than four) and centred on the line.
s32 EnemySlotGet (void)
 Returns the id of the first free enemy unit, or -1 when all six are taken.
s32 EnemyUpdate (void)
 Lays the enemies out again and moves each one's object anchor to its new place.
void BattleUnit_RefreshPlacement (void)
 Places every unit at the start of a battle: numbers the places (party members 0 up in their order, enemies 8 to 13) and creates each unit's object at its spot.
s32 BattlePlacement_ContainsId (s16 *list, s32 place)
 Returns 1 if the unit at place is in list.
void BattleActor_UpdateSpritePriorities (void)
 Runs each frame of a battle: advances every unit's status icon, lifts an airborne unit's effect sprite above the others, and draws whichever side is nearer the camera in front.
s32 BattleUnit_BuildStatusFlags (s32 unitId, struct BattleObj *battleObject)
 Builds the status icon bits of unit id's ailments into its battle object's activeConditions, which BattleStatusIcon_Cycle shows.
s32 BattleStatusIcon_Cycle (struct BattleObj *battleObject)
 Shows a unit's status icons one after another, each for ICON_CYCLE_FRAMES frames, switching at once when the shown status ends, and removes the icon when no status is left.
s32 BattlePres_SetActorModeAndAction (s32 unitId)
 Sets unit id's pose to match its state: held (asleep, stunned or unable to move) or down, else standing; then gives its sprites their palette row, 14 to 17 by unit.
void ReleaseBattleObjectRecords (s32 unitId)
 Releases every sprite unitId's object holds and leaves it with none, clearing the battle object's animationEntry and effectEntry.
void BattleActor_SpawnObjectsForList (s16 *unitIds, s32 refreshPoses)
 Readies the sprites of the units in list: releases those of every place list lacks, then creates each listed unit's sprites (body, weapon, status icon and effect; or the two parts of a two-part enemy) unless it has them, building its status icons and setting its pose.
struct BattleObj * BattleObjGet (s32 unitId)
 Returns unitId's battle object, through its place, or null for a unit with no place.
void ResetMotionRecordGroup (void *recordGroup)
 Detaches the scripts from the four sprite entries of one sprite.
void ResetBattleObjectRecordGroups (struct MotionObject *object)
 Detaches the scripts from every sprite of a battle object.
s32 BattleObj_MarkForRelease (s32 unitId)
 Frees the enemy sprite slots unitId holds and marks its object for release at the end of the round (BattleMotion_DestroyAllSlotObjects), setting its active field.
void * BattleMotion_DestroyAllSlotObjects (void)
 Releases the object of every unit marked by BattleObj_MarkForRelease, leaving its battle object with no object.
s32 Battle_GetWorkEntryPair (s32 place, struct FixedPointPosition *position)
 Writes the battlefield spot of place (its anchor, on the ground) to position.
s32 Camera_ApplyTransformByFlag (void)
 Sets up the camera's view for projecting points; under FLAG_CHOOSING_COMMANDS, through the extra transform gCamera_FlagTransformWork first.
s32 BattleMotion_ProjectPosition (s32 unitId, s32 *projected)
 Projects unit id's position onto the screen, into projected.
void * GetMotionRecord (struct MotionObject *object, s32 recordIndex)
 Returns sprite recordIndex of an object (0 only, for a single sprite), or null when it has no such sprite.
void Camera_InitDefaultTransform (void)
 Puts the battle camera at its default view of the battlefield's centre.
void ObjMotRst (s32 unitId)
 Sends unitId back to its spot, landing there, and turns it to face the centre.
void BattleMotion_SetupEscapeObject (s32 unitId)
 Sends unitId running off its side of the battlefield, three times as far out as its spot, with a hop, in pose 1.
void BattleMotion_InterpolatePosition (struct BattleObj *startSlot, struct BattleObj *endSlot, s32 progress)
 Sends the unit of startSlot leaping progress percent of the way toward the unit of endSlot, in pose 2.
void BattleMotion_SetObjectPosition (struct BattleObj *battleObject)
 Sends a unit's object back to its spot. Nothing in the source calls it.
void BattleMotion_ResetObjectAtScaledAnchor (s32 unitId)
 Sends unitId hopping out to one and a half times its spot's distance from the centre.
void BattleMotion_InitializeObject (s32 unitId)
 Sends unit id leaping back to 1.3 times its spot's distance from the centre, in pose 5.
void BattleMotion_ApplyVariantMotion (s32 unitId, s32 variant)
 Knocks unit id back, by the speed, hop and distance of motion variant (gBattleMotion_Variant*), and puts it in pose 5.
void BattleMotion_ApproachTarget (s32 actorId, s32 targetId, s32 travelDivisor, s32 initialVelocityY)
 Sends unit actorId three quarters of the way to unit targetId, arriving in travelDivisor steps, leaping up at initialVelocityY, in pose 2.
void BattleMotion_ResetSlotObjectMode2 (s32 unitId)
 Restarts unit id's motion in pose 2. Nothing in the source calls it.
void BattleMotion_ReservedNoOp83B0 ()
 Does nothing; BattleMotion_ApplyPairMidpoint, its only caller, passes it a position and a distance.
void BattleMotion_ApplyPairMidpoint (s32 firstId, s32 secondId)
 Works out the point halfway between two units, at their move targets where they have one, and hands it to BattleMotion_ReservedNoOp83B0, which does nothing.
void BattleMotion_SpawnSlotEffectAndWait (s32 unitId)
 Plays the hit flash on unit id's sprite and waits ten frames.
s32 BattleMotion_ProjectScaledPosition (s32 unitId, s32 *projected)
 Projects the point above unit id where its effects play (its class's height, BattleUnit_GetEffectHeight) onto the screen, into projected; the height is scaled by the sprite's projected scale.
s32 BattleMotion_ProjectConditionalPosition (s32 unitId, s32 *projected)
 Projects the point above unit id onto the screen, into projected: 24 pixels up for a small enemy, 48 for others, as drawn.
s32 BattleUnit_GetEffectHeight (s32 unitId)
 Returns the height above unit id where its effects play, 16.16: its class's own (BattleClass_GetEffectHeight), else 24 for a small enemy and 48 for others.
s32 BattlePresentation_BuildSortedUnitEntries (struct BattleActionRecord *entries)
 Auto battle: gives every living unit a plain attack and sorts them into turn order.
s32 BattlePres_RunAction (struct BattleActionRecord *action)
 Auto battle: plays one action.
s32 BattleObject_IsValidId (u32 unitId)
 Returns 0 for a party member's or an enemy's unit id, -1 for any other.
s32 BattleEscape_PlayRun (struct BattleActionRecord *action)
 Auto battle: the party tries to run, and gets away 15 times in 16, each living member running off in turn.
s32 BattlePres_ShowDefendMessage (const struct BattleActionRecord *action)
 Auto battle: shows that a standing unit is defending.
s32 BattlePresentation_RunPairedUnitTransition (struct BattleActionRecord *action)
 Auto battle: casts Psynergy.
s32 BattlePres_RunApproachAction (struct BattleActionRecord *input)
 Auto battle: an attack.
s32 BattlePres_RunUnitAction (struct BattleActionRecord *action)
 Auto battle: an attack or an item.
void BattlePresentation_ApplyUnitDamage (u32 unitId, s32 damage, s32 showMessage, u8 *context)
 Auto battle: deals damage HP to unit unitId and shows it.
void BattleMotion_SetMode5AndActivateSlot (s32 unitId)
 For a unit whose HP has run out: plays its falling animation to the last frame and marks its object for release (BattleObj_MarkForRelease).
s32 BattleTarget_ReplaceDefeated (const struct BattleActionRecord *action)
 Returns the action's target, or a random living unit of its side when the target is down; TARGET_SIDE_DEFEATED when none is left.
void Palette_UpdatePulseBrightness (void)
 Pulses BG palette 14's colours: each takes the matching colour of palette 15 brightened by up to twelve steps, rising and falling with the frame count.
void Camera_ConfigureScene (s32 verticalOffset)
 Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels, with its projection and the background's perspective to match.
void BattleUnit_ResetGuardLevels (void)
 Ends every unit's guard (Defend and the like) and recalculates its stats.
s32 BattleEscape_CheckSuccess (void)
 Rolls whether the party gets away.
s32 BattlePres_BuildUnitEntries (struct BattleActionRecord *entries)
 The party's actions for the round, from the command menu: a member who is asleep, confused, charmed or stunned loses each of their turns (CMD_NONE); the others choose theirs (Battle_CollectPartyCommandsFar).
s32 BattlePres_BuildOpponentEntries (struct BattleActionRecord *entries)
 The enemies' actions for the round, in a shuffled order, each chosen by BattleCommand_SelectAutomatic; a sleeping or stunned enemy loses its turns.
void BattleQueue_SortByPriority (struct BattleActionRecord *entries, s32 count)
 Sorts the round's actions into turn order, fastest first, after moving the guarding and grounding Djinn to the front.
s32 BattlePresentation_AppendLinkedActions (struct BattleActionRecord *actions, s32 count)
 Link battle: exchanges the round's actions with the other console and appends the opponent's after the count of this console's.
void Palette_CopyBanksWithBrightnessOffset (s32 offset)
 Copies BG palette 15 to 14 and 5 to 4, brightened or darkened.
s32 BattlePresentation_BuildActions (struct BattleActionRecord *actions)
 Builds the turn's actions and sorts them into turn order: the party's commands, then the link opponent's or the enemies' actions.
s32 Battle_GetTaggedSlotValue (s32 taggedPlace)
 Returns the unit id at a list place.
s32 Battle_FindTaggedSlotByValue (u32 unitId)
 Returns the list place of unit id, or -1 if it is in neither list: the party's as 0x100 | place, the enemies' as 0x180 | place (PLACE_PARTY, PLACE_ENEMY).
void Battle_ReservedNoOp9B2C (void)
 Does nothing; Battle_RunEncounter calls it at the start of each round.
s32 BattlePresentation_DispatchAction (struct BattleActionRecord *request, s32 delay)
 Plays one action of the round, after delay frames facing the party: an enemy picks its ability now; the action is planned (its targets, hits and damage) and shown the way its staging asks, then the turn's end effects run and every unit returns to its spot.
s32 BattlePres_BuildTargetList (struct BattlePlan *plan, struct BattleEffectArgument *effect)
 Fills an effect command from a plan: its kind and strength, the actor and the targets still standing (or every target, for an effect that revives), at least the first.
s32 BattlePres_RunEscape (struct BattlePlan *plan)
 Plays a unit's attempt to run.
s32 BattlePresentation_RunUnitTransition (struct BattlePlan *plan, s32 mode)
 Plays a summon or a full-screen Psynergy.
s32 BattlePres_RunActorEntries (struct BattlePlan *plan, s32 unused)
 Clears the highlights, then applies the action to each target in turn and plays its events; with no target, only waits for the player.
s32 BattlePres_RunAttack (struct BattlePlan *plan, s32 mode)
 Plays an attack: the camera turns halfway to the attacker's view, the attacker runs up to its first target over its swing's frames, and the blow lands: a miss makes the target hop back; a hit plays its effect and the events, and a critical hit zooms in on the pair with only those two shown.
s32 BattlePres_RunPlainAttack (struct BattlePlan *input, s32 flags)
 Unused.
s32 BattlePres_RunItem (struct BattlePlan *plan, s32 unused, struct BattleActionRecord *selection)
 Plays an item's use: the camera turns to the user's side, the user raises the item and, for an item with an effect, the screen dims while it plays with the events.
s32 BattleMotion_SetRecordChildValues (struct MotionObject *object, s32 palette)
 Draws every sprite of an object in a colour mode (enum SpriteColorMode): colorMode on each sprite's first layer, SPRITE_COLOR_NORMAL on the others, and every layer's frame set to 255 (none) so that it is drawn again.
s32 BattlePres_RunPsynergyCast (struct BattlePlan *plan, s32 mode)
 Plays Psynergy, a Djinni or an enemy's cast.
void BattleMotion_FlashHit (s32 unitId, s32 unused0, s32 unused1)
 Flashes unit id as it is hit: puts it in its damage pose and switches its sprites between white and their own colours twice, two frames each, its status panel highlighted.
void BattleActor_RemoveFromLists (s32 unitId)
 Takes unit id out of the party's or the enemies' list and out of this round's actions, and frees its name letter.
void BattleMotion_ShowDowned (s32 unitId)
 Shows a downed unit: a party member lies down, an enemy keeps its damage pose, turns grey, leaves the lists after four frames and dissolves a dot at a time.
s32 BattleTarget_SelectRandomPosition (s32 requireLivingUnit)
 Picks a random place: with requireLivingUnit, a party member still standing; otherwise any enemy place in use.
s32 BattleTarget_SelectForAction (s32 actorId, struct BattleAct *action)
 Picks the target of an enemy's ability (or a confused unit's), as a place code: among the units of the side it may target, those it would affect (CHECK_EFFECT_TARGET), at random; a single-target attack by an enemy with a strategy favours the strongest, the first of the sorted targets 6 times in 11, 15 or 18, the next 5 times, and so on.
s32 BattleActor_ResetRuntimeFields (s32 unitId)
 Clears every ailment and stat change of a unit that goes down, recalculates its stats and rebuilds its status icons.
s32 BattlePresentation_WaitForAdvance (void)
 Shows the bobbing arrow at the message window and waits for the player to go on (B, or one of KEY_ADVANCE), then plays the cursor sound.
s32 BattlePresentation_WaitForPromptAt (s32 x, s32 y)
 Shows the cursor bobbing at (x, y) and waits for one of KEY_ADVANCE.
void BattleEv_MarkDisplay (void)
 Sets gBattleDisplayWork->marked, which the next message reads, as BATTLE_EVENT_MARK does.
s32 BattleActor_DestroyTemporaryObject (s32 unitId)
 Takes an enemy out of the battle at once (one that leaves rather than falls): its HP to 0, out of the lists, and its object released.
void BattleEv_GrantDjinnBonus (struct BattleEventState *runtime, u32 operand)
 The BATTLE_EVENT_DJINN_BONUS event: grants the Djinn bonus for the rest of the action.
u32 BattleEv_DispatchQueued (void)
 Plays the queued battle events at once, in order (BattleEvent_Playback plays them over frames instead): the messages with their arguments, the hit flashes, the downed units, the redraws.
u32 BattleEvPush (u32 opcode, u32 operand)
 Queues one battle event (enum BattleEventOpcode) with its operand, and returns the opcode.
s32 BattleEffectDeadCheck (s32 effect)
 Returns 1 for an effect that still applies when the ability's damage has just knocked its target out: the drains, which give the damage they dealt back to the actor.
s32 BattleTargetExec (struct BattlePlan *plan, s32 slot)
 Applies the planned ability to one of its targets: first its damage or healing, then its added effect (a status, a stat change, a revival...).
u32 Ability_IsPsynergy (s32 abilityId)
 Returns 1 for an ability that costs PP, and for Psy Drain, which costs none.
s32 BattleCommand_SelectAutomatic (struct BattleActionRecord *request, s32 retry)
 Chooses an enemy's action (a party member's is chosen in the menu): one of the eight in its definition, picked by its action strategy, with an item instead where its item mask says so, and a target worth the ability.
void Dma_StopAllThenRunHook (void)
 Sets DMA3 three times over, stopping it, then calls the IRQ return instruction's word as a routine.
void BattleEventRuntime_BeginPhase (s32 cue)
 Starts playback of the plan's targets when the effect's blow lands.
s32 BattleEventRuntime_SchedulePhase (s32 frames)
 Empties the event queue and schedules playback of the events queued next, with no targets to resolve.
void BattleEvent_Playback (void)
 Plays the plan's targets one at a time: resolves the next target with BattleTargetExec, then plays the events it queued over the frames that follow, until every target is done.
void BattleEventRuntime_Reset (void)
 Stops playback and empties the event queue.
s32 BattleEventRuntime_WaitForReady (void)
 Waits, a frame at a time, until BattleEvent_Playback has played every target, then removes the callback and resets the events.
u32 BattleParty_IsUnitListed (u32 unitId)
 Returns one when the unit is in its side's formation.
s32 BattleParty_CountStandbyDjinn (u32 unitId, u8 *counts)
 Counts the standby Djinn whose owners fight on unitId's side, from that side's Djinn recovery list.
s32 BattleCommand_BuildPlan (struct BattleActionRecord *request, struct BattlePlan *plan)
 Announces the action and plans its targets and effects.
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_TickConfusion (s32 unitId)
 Counts down confusion, which may end early at bias 60; Battle_ProcessRoundEnd shows MsgConscious 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.
s32 BattlePres_RunMosaicFadeOut (void)
 Fades the screen to black over sixteen frames as every background's mosaic grows, then shows no layer.
void Graphics_BuildSequentialTileTable (void *tilemap)
 Builds the perspective plane's 32 by 32 affine map: tiles 0 to 255 in its first eight rows, 0 to 223 in the next seven, and 0xff in the rest.
void BattlePresentation_BuildTilemap (void *tilemap)
 Builds BG1's flat map of the same picture: rows 0 to 3 0xffff, rows 4 and 5 tile 0x3ff, rows 6 to 20 tiles 0x200 to 0x3df in order, then tile 0x3ff.
void BattlePres_UpdateHBlankScroll (void)
 Shows the perspective plane's finished page each frame while the background is in mode 2: its first line's BG2CNT now, the rest by HBlank DMA 0, and its affine parameters into BG2PA to BG2Y.
void BattlePresentation_UploadTileVariant (void)
 Copies one of eight curtain tiles from gBattlePres_TileVariants into CURTAIN_TILE(0), a new one every four frames while the transition timer (gDisp) runs from 1 to 32.
void BattlePres_AdvanceTransitionTimer (void)
 Advances the curtain opening by a frame: scrolls BG0 from 32 pixels to 0 over frames 20 to 52, and over frames 0 to 80 turns the camera round to YAW_PARTY_TURN and zooms it from 180 to 100 percent.
void BattlePres_DrawTransitionRows (void)
 Draws a frame of the curtain opening on BG1: over 80 frames a row moves up from row 13 to row 4 and its vertically flipped twin down to row 20, the row's tile stepping through CURTAIN_TILE(1) to (8), the last one clear.
void Graphics_ClearBg0Vofs (void)
 Clears REG_BG0VOFS, so that BG0's scroll applies only above the line the interrupt fires on.
void BattlePres_RunEntryTransition (s32 enemyCount, s32 encounterId)
 Opens a battle: the curtain opening, or for the Fusion Dragon the storm on the Venus Lighthouse aerie; then announces the enemies and leaves the battle's display set.
void BattlePresentation_SetPaletteLevel (s32 unused, s32 level)
 Copies the background's saved palette to BG palettes 6 to 13, darkened by level (0 for none).
void BattlePresentation_ConfigurePaletteFade (s32 mode, s32 unusedResource, s32 fade)
 Switches the background's display mode, optionally sets its palette, and rebuilds both its maps.
void BattlePresentation_InitializeWorkAndResetState (void)
 Allocates the perspective plane's scanline work (heap slot 10) cleared, and sets the background's mode to 0, so the next load adds its scanline callback.
void Runtime_ReleaseHeapBlock10 (void)
 Frees the perspective plane's scanline work (heap slot 10); called by Battle_RunEncounter as the battle ends.
void BattleBackground_Load (s32 mode, s32 resourceId, s32 level)
 Loads a battle background: its picture into character blocks 2 and 3, its palette into BattleWork.palette and, darkened by level, BG palettes 6 to 13, and both its maps.
void BattleCamera_SetRange (s32 centerX, s32 centerY, s32 offsetX, s32 offsetY, s32 scale)
 Builds the perspective plane's next page for a zoom of scale about centerX and centerY (all 16.16), shifted by offsetX and offsetY (8.8 pixels), and shows it.
void BattlePres_SetupTransitionSceneAtDepth (s32 x, s32 depth, s32 y)
 Sets the camera's eye at its stored distance without taking a zoom; nothing in the source calls it.
void BattlePres_SetupTransitionScene (s32 x, s32 depth, s32 y, s32 zoom)
 Points the battle camera at (x, depth, y) with a zoom in percent, and lines the perspective plane up with it.
void BattlePres_SetupTransitionAtPairMidpoint (s32 firstUnitId, s32 secondUnitId, s32 zoom)
 Points the battle camera, through BattlePres_SetupTransitionScene, at the ground between two units' battle objects, with a zoom in percent.
void Graphics_FadeAlphaOut (void)
 Fades BG2 out over the backdrop in eight frames, its blend weight falling by 2 a frame from 15, while the backdrop's stays 16.
void Graphics_FadeAlphaIn (void)
 Fades BG2 in over the backdrop in eight frames, its blend weight rising by 2 a frame from 1, while the backdrop's stays 16.
void Graphics_SetBlendControl (void)
 Sets REG_BLDCNT to lighten every layer by REG_BLDY; nothing calls it.
void BattlePresentation_InitializeTransitionEntries (struct BattleTransitionEntry *entries)
 Sets entries to the identity transform, then stores the first word's old value plus its new one in the second; nothing calls it.
s32 BattlePres_DivideBy16 (s32 value)
 Nothing calls it.
s32 Runtime_AdjustDebugValueWithButtons (s32 selectedValue)
 A debug aid: while Start is held, edits BattleWork.debugValue with the d-pad (1 left and right, 100 up and down) until A takes it as the result; with Select held, returns DEBUG_SELECT_VALUE instead.
void BattlePres_SetActorRecordMode (s32 actorId, s32 mode)
 Sets the OBJ mode (1 semi-transparent, 0 normal) of every sprite of a unit's battle object, the picture and its shadow.
void BattlePres_SetOtherActorRecordModes (s32 selectedUnitId)
 Makes every unit's sprites semi-transparent but selectedUnitId's, which are left as they are; nothing calls it.
void BattlePres_ClearAllActorRecordModes (void)
 Returns every unit's sprites to OBJ mode 0; called by BattlePres_SetActorModes when the highlight stops.
void Graphics_AdvancePaletteCycle (void)
 Lightens the opaque sprites, the highlighted units, by the next step of gBattleFx_HighlightBlendRamp.
void BattlePres_SetActorModes (u16 *selectedUnits, s32 mode)
 Highlights the units in selectedUnits, a list ended by BATTLE_UNIT_LIST_END, or with mode 0 stops the highlight.
s32 BattleFx_UpdateStarField (void)
u32 BattleFx_UploadStarField (void)
s32 BattleFx_InitializeStarField (s32 mode)
 Starts a star field of the element mode (0 to 3, enum Element order): sixteen sparks on random rings and three rings 120 degrees apart.
s32 Graphics_ResetVramBlockAndReleaseHeapBlocks (s32 unused)
 Ends a star field: clears BG2's tiles in character block 1, frees its blitters, canvas and work, turns BG2 off and removes both callbacks.
s32 Graphics_ScaleRgb555Clamped (u16 *source, u16 *destination, s32 scale, s32 count)
 Copies count colours from source to destination, each channel scaled by scale (16.16, at most 1), and returns 0.
void BattlePres_RestorePalette (void)
 Copies the background's saved palette back undarkened, as the star field of BattleFx_PlayUnitElementEffect leaves it dark.
void Runtime_RemoveIrqHandlerSlot2 (void)
 Removes the VCount interrupt's handler, as BattlePres_RunEntryTransition installs one; nothing calls it.
s32 BattleFormation_AverageLevel (s32 recordId)
 Returns a formation's average enemy level, for the monster battles to choose by.
s32 BattleFormation_SelectLevelMatchedCandidate (s32 *outMargin)
 Chooses a monster battle's formation for the party's level, and returns it with the levels its enemies must gain in outMargin.
s32 BattleEnemy_AdjustLevel (s32 owner, s32 levels)
 Raises an enemy by levels, or lowers it for a negative count: each base stat changes by a fixed amount a level, kept between 70 percent of what it was and its cap.
s32 BattleEnemy_ClaimNameLetter (s32 classId, s32 unused)
 Gives an enemy of the class its name letter, which tells it from others of its kind, and returns the letter's number for BattleUnitSetFar.
s32 BattleEnemy_ReleaseNameLetter (s32 actorId)
 Frees a departing enemy's name letter for the next of its class, reading the letter back from the end of its name.
s32 BattleEnemy_LetterFirstOfClass (s32 classId)
 Gives the first enemy of the class on the field the first letter (0), appended to its name, once a second of its class arrives.
s32 BattleGroupRandom (s32 recordId)
 Returns the class id of a random member of the formation, among those that may appear (maximum count above 0); formation 1 stands in for an id out of range.
s32 BattleFormation_BuildEnemyList (s32 recordId)
 Builds the battle's enemies from formation recordId and returns how many there are.
u32 BattleClass_GetDefeatSoundKind (s32 index)
 Returns the class's defeat-sound kind, 0 to 4, or -1 for none; a fallen enemy's sound is SE_146 plus it.
s32 BattleClass_GetSprite (s32 index)
 Returns the class's battle sprite, row 0's for a class out of range.
s32 BattleClass_GetPalette (s32 index)
 Returns the class's sprite palette.
s32 BattleClass_IsSmall (s32 index)
 Returns 1 for a small class, which takes one enemy sprite slot instead of two and stands closer to its neighbours; 0 out of range.
u32 BattleClass_GetAttackEffect (u32 index)
 Returns the effect a class's plain attack shows, 1 for none or out of range.
u32 BattleClass_GetAttackHop (u32 index)
 Returns how high a class hops as it runs up to attack, in pixels; 0 out of range.
s32 Summon_IsEntrySecondaryFlagged (s32 index)
 Returns 1 for a class whose blow lands with SE_HEAVY_IMPACT instead of SE_133; 0 out of range.
s32 BattleClass_GetEffectHeight (s32 index)
 Returns the height an effect is drawn at over a class, in pixels, or 0 for its size's default; 0 out of range.
u32 BattleSpoils_RankItem (u32 inventoryEntry)
 Ranks an item among the spoils, 0 for none: an indispensable item first, then a rare item, then the higher item id.
void BattleSpoils_Clear (void)
 Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem.
s32 BattleEnemy_RecordDefeat (s32 unitId, s32 djinnBonus)
 Counts a fallen enemy and adds its coins, experience and perhaps its item to the spoils.
void Battle_AwardSpoils (void)
 Hands out the spoils after a victory: the experience to each party member still standing, with every level gained and what it brings, then the coins, then the items best first.
void Battle_ReservedNoOp2A08 (void)
 Does nothing; the debug battle menu (DebugBattle_RunMenu) calls it.

Macro Definition Documentation

◆ PUSH_MESSAGE

#define PUSH_MESSAGE ( message)
Value:
u32 BattleEvPush(u32 opcode, u32 operand)
Queues one battle event (enum BattleEventOpcode) with its operand, and returns the opcode.
Definition events.c:321
@ BATTLE_EVENT_MESSAGE
a message, waiting for the player

Pushes a message to show, waiting for the player to read it.

Definition at line 64 of file battle.h.

Referenced by Battle_ProcessRoundEnd(), BattleTargetExec(), and BattleUnit_ProcessTurnEnd().

◆ DEFINE_ADJUST_CAMERA

#define DEFINE_ADJUST_CAMERA ( name)
Value:
void name(void) { \
struct BattlePresentationTransition *trans = \
\
if ((gKeysHeld & KEY_L) != 0) { \
cam->yaw += 512; \
} \
if ((gKeysHeld & KEY_R) != 0) { \
cam->yaw -= 512; \
} \
if (trans->flag == 0) { \
BattleCamera_SetRange(0x780000, 0x780000, 0, 0, 0x10000); \
} \
}
@ HEAP_SLOT_BATTLE_BACKGROUND
Definition heap_state.h:45
@ HEAP_SLOT_CAMERA
Definition heap_state.h:38
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
Definition heap_state.h:14
@ KEY_R
Definition io_reg.h:251
@ KEY_L
Definition io_reg.h:252
volatile u32 gKeysHeld
Keys down now.
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
u16 yaw
1/65536 turns
The battle background's work slot as the camera reads it: the yaw the camera eases toward and the fra...
s32 flag
0 lets the camera update set the background's range each frame; 1 for a critical hit's zoom and once ...

Moves camera yaw by 512 while L/R is held; two identical functions exist.

Definition at line 67 of file battle.h.

Referenced by BattlePres_AdjustCameraByShoulderKeys(), and BattlePres_AdjustCameraByShoulderKeysAlt().

Function Documentation

◆ DebugParty_LoadPreset()

s32 DebugParty_LoadPreset ( s32 preset)

Debug: replaces the party with the members of preset number preset.

Each member is raised to the row's level, given the row's Djinn (Set, in order of their numbers across the party), the row's abilities, and an emptied inventory holding the row's items, each equipped. Called by DebugBattle_RunMenu and, through its far stub, by the link lobby's LinkLobby_ChooseDebugPartyPreset. Changes the active party and each member's level, Djinn, abilities and inventory. Returns 1 when the table ends before that preset, 0 otherwise.

Definition at line 53 of file debug.c.

Referenced by DebugBattle_RunMenu(), DebugParty_LoadPreset(), and LinkLobby_ChooseDebugPartyPreset().

◆ DebugBattle_ViewMessages()

void DebugBattle_ViewMessages ( void )

Debug: a message viewer that never returns.

Names the first party member "Ha hi fu he ho" (MsgDebugSampleName), fills the message arguments with sample values and shows one message at a time, counted from the Babi Lighthouse dialogue (MsgBabiLighthouseTheyWereTerribleWeWereAbsolutely) or, in the second range, from DEBUG_SECOND_FORM. Right and Left step the index, R and L step it by ten, Up and Down pick the range, and B alternates between the ranges, moving on one message each time it leaves the first. A closes the window and shows the message again. Called by DebugBattle_RunMenu when Start is pressed. Renames party member 0, sets REG_DISPCNT and gGameState.messageSpeed, and clears the window work's message busy byte after each window.

Definition at line 153 of file debug.c.

Referenced by DebugBattle_RunMenu(), and DebugBattle_ViewMessages().

◆ DebugBattle_RunMenu()

void DebugBattle_RunMenu ( void )

Debug: the battle test menu, which never returns.

Without Down held it fights encounter 257 again and again with auto battle on. Holding Down at the start opens the chooser: Right and Left step the encounter, Up and Down by ten, R and L pick the party preset, Start opens the message viewer and A fights; B marks every later battle with start mode 5. Holding Down when A is pressed makes it a link battle. Exported as DebugBattle_RunMenuFar; nothing in the source calls it. Sets FLAG_DEBUG_BATTLE and, as chosen, FLAG_AUTO_BATTLE, FLAG_LINK_BATTLE and FLAG_DJINN_TUTORIAL, and resets the task table, heap and VRAM cache before each battle.

Definition at line 253 of file debug.c.

Referenced by DebugBattle_RunMenu().

◆ BattlePresentation_UpdateCamera()

void BattlePresentation_UpdateCamera ( void )

Runs each frame of a battle.

In a link battle it first checks the link: a connection lost for more than LINK_MAX_MISSED_FRAMES frames, or a console whose link number changed, pauses the battle. Then it turns the camera a sixteenth of the way toward a transition's yaw, places the camera at its position (or at the one it follows) with its yaw, pitch and distance, and, unless a transition owns the background, refreshes the background's perspective. Runs as a scheduler callback (priority 0xc7f) that Battle_RunEncounter adds. Changes work->linkMisses and linkPaused, the camera's yaw and the transition's frame count, the transform state, and through BattleCamera_SetRange the background's affine page.

Definition at line 18 of file setup.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_UpdateCamera().

◆ BattleIntro_AnnounceEncounter()

void BattleIntro_AnnounceEncounter ( s32 enemyCount)

Announces the enemies at the start of a battle, then whether the party strikes first or is caught by surprise.

Each of the first enemyCount enemies gets <enemy> appeared!, the last one's message a different line. Called by BattlePres_RunEntryTransition. Rewrites the message argument tables.

Definition at line 90 of file setup.c.

Referenced by BattleIntro_AnnounceEncounter(), and BattlePres_RunEntryTransition().

◆ BattleParty_CollectUnitList()

void BattleParty_CollectUnitList ( void )

Fills the battle's two unit lists, each ended by BATTLE_UNIT_LIST_END: the party members in their order, and the enemies, left to right for a random formation or, for a fixed one, alternating out from the centre (gBattleParty_CenterOrderOffsets).

Called by Battle_RunEncounter as the battle is set up. Writes gBattleWork->partyUnits and enemyIds, and marks each party member's side.

Definition at line 135 of file setup.c.

Referenced by Battle_RunEncounter(), and BattleParty_CollectUnitList().

◆ BattlePresentation_InitializeTilePattern()

s32 BattlePresentation_InitializeTilePattern ( void )

Moves the 16 bytes at VRAM 0x06000290 down to 0x06000280 and clears the 20 bytes from 0x0600028c.

Nothing in the source calls it. XXX: what the tiles at 0x06000280 are; a caller in another image, or the picture loaded there, would settle it.

Definition at line 173 of file setup.c.

Referenced by BattlePresentation_InitializeTilePattern().

◆ BattlePresentation_ClearBg0VerticalOffset()

void BattlePresentation_ClearBg0VerticalOffset ( void )

Nothing in the source calls it.

Definition at line 180 of file setup.c.

Referenced by BattlePresentation_ClearBg0VerticalOffset().

◆ Party_ReservedNoOp5B14()

void Party_ReservedNoOp5B14 ( s32 unused)

Does nothing; Battle_RunEncounter calls it with 1 as the battle is set up.

Definition at line 188 of file setup.c.

Referenced by Battle_RunEncounter(), and Party_ReservedNoOp5B14().

◆ BattleParty_ResetActiveRuntimeFields()

s32 BattleParty_ResetActiveRuntimeFields ( void )

Clears every battle-only state of the party members (stat stages and their turns, statuses, Djinn element boosts, the countdowns) and recalculates their stats, as a battle ends.

Called by Battle_RunEncounter on every way out of the battle.

Definition at line 197 of file setup.c.

Referenced by Battle_RunEncounter(), and BattleParty_ResetActiveRuntimeFields().

◆ BattleParty_ReconcileDjinnRecovery()

s32 BattleParty_ReconcileDjinnRecovery ( void )

Brings the Djinn recovery list up to date as a battle starts: every Djinni a party member has on standby that the list lacks joins it.

Then, outside a link battle, each Djinni waiting for a battle to end whose owner has no battle object is Set again and leaves the list. Called by Battle_RunEncounter once the unit lists and battle objects are in place. Changes the party's and the opponent's recovery lists and Djinn states.

Definition at line 260 of file setup.c.

Referenced by Battle_RunEncounter(), and BattleParty_ReconcileDjinnRecovery().

◆ BattleSummon_UpdateAvailability()

struct BattleSummonState * BattleSummon_UpdateAvailability ( void )

Works out which summons the party can call: one whose Djinn requirement of every element is met by the party's Djinn of that element, all members together.

Stores the mask of them (bit n for summon n) and returns the state that holds it. Called by Battle_RunEncounter as the battle is set up and at the start of each round. Writes the party recovery table's availableMask.

Definition at line 337 of file setup.c.

Referenced by Battle_RunEncounter(), and BattleSummon_UpdateAvailability().

◆ BattleSummon_ReservedNoOp()

void BattleSummon_ReservedNoOp ( void )

Does nothing; nothing in the source calls it.

Definition at line 401 of file setup.c.

Referenced by BattleSummon_ReservedNoOp().

◆ LinkBattle_ReceiveParty()

s32 LinkBattle_ReceiveParty ( void )

Link battle: receives the opponent's party into the enemy units, one member at a time, and puts the "Enemy" label (MsgEnemyLabel) before each name; then receives the opponent's Djinn recovery list.

Stops early if a transfer cannot start. Returns how many of the received units are members (a unit sent with side 0 is an empty place). Nothing in the source calls it. Overwrites enemy units 128 to 130 and the opponent's recovery table.

Definition at line 32 of file link.c.

Referenced by LinkBattle_ReceiveParty().

◆ LinkBattle_SendParty()

s32 LinkBattle_SendParty ( void )

Link battle: sends the party, one member at a time and three places in all (an empty place has side 0), then the Djinn recovery list with each owner given the unit id the opponent knows them by.

Records that id of each member in gBattleWork->ownerSlots (0xff for none). Nothing in the source calls it.

Definition at line 102 of file link.c.

Referenced by LinkBattle_SendParty().

◆ Text_CopyFiveCharsPaddingUnderscore()

u8 * Text_CopyFiveCharsPaddingUnderscore ( u32 unused0,
u32 unused1,
u16 * source )

Copies four characters of a name and a terminator, an underscore for each missing character, and returns a pointer to the terminator.

UBFIX keeps the private scratch buffer valid until the next call; the original returns a pointer to expired stack storage. The first two arguments are ignored. Nothing calls it.

Definition at line 170 of file link.c.

Referenced by Text_CopyFiveCharsPaddingUnderscore().

◆ BattlePres_WaitSync()

s32 BattlePres_WaitSync ( void )

In a link battle, shows the "EXEC" signature to the other console and waits up to 30 frames for it to show the same.

Returns 0 once both do (or outside a link battle), and -1 if the battle is paused, the link is lost for more than LINK_MAX_MISSED_FRAMES frames or the signatures never meet. Called by BattlePresentation_BuildActions. Writes the first eight bytes of gSerialTransfer.payload.

Definition at line 207 of file link.c.

Referenced by BattlePres_WaitSync(), and BattlePresentation_BuildActions().

◆ BattlePres_SyncTurn()

s32 BattlePres_SyncTurn ( void )

In a link battle, after each action and after the end of each round, steps both consoles through the same handshake: "ex" "TU", then "rn", "EXEC", "tu" and finally "RN".

Each step shows its signature and waits for the other console to show it too, failing if the other console shows a different earlier step. Returns -1 if the battle is paused, the link is lost for more than LINK_MAX_MISSED_FRAMES frames, or the steps disagree; 0 once in step, or outside a link battle. Called by Battle_RunEncounter. Writes the first sixteen bytes of gSerialTransfer.payload.

Definition at line 255 of file link.c.

Referenced by Battle_RunEncounter(), and BattlePres_SyncTurn().

◆ BattleParty_AssignMemberSlots()

s32 BattleParty_AssignMemberSlots ( void )

Records, for each party member, the unit id the link opponent knows them by (FIRST_ENEMY_UNIT plus their place in the party), in gBattleWork->ownerSlots.

Called by Battle_RunEncounter as a link battle is set up.

Definition at line 371 of file link.c.

Referenced by Battle_RunEncounter(), and BattleParty_AssignMemberSlots().

◆ Battle_ClearSerialTransferPayload()

s32 Battle_ClearSerialTransferPayload ( void )

Clears the link transfer's payload, the signatures included.

Called by Battle_RunEncounter on each way out of the battle but fleeing.

Definition at line 388 of file link.c.

Referenced by Battle_ClearSerialTransferPayload(), and Battle_RunEncounter().

◆ Battle_RunEncounter()

s32 Battle_RunEncounter ( s32 enemyGroup)

Fights the battle against the enemy formation enemyGroup, from the opening transition to the end, and returns how it ended: the number of enemies defeated when the party won (or the link broke), ENCOUNTER_FLED when the party ran, or ENCOUNTER_PARTY_LOST.

Each round, the party's commands are chosen (or chosen automatically under FLAG_AUTO_BATTLE), every unit acts in turn order, and the round ends with the turn-end effects; the Djinn tutorial adds its two messages after each round.

Reached through its far stub from Game_ResetForNewGame's scene switch (SCENE_BATTLE, with the entrance as enemyGroup), and from DebugBattle_RunMenu. Allocates the battle's work slots (the camera, gBattleWork, the link copy, the background transition, the display and others), sets FLAG_IN_BATTLE, and on its way out resets the party's battle state, sets gGameState.battleStart back to 0 and releases heap block 10. A broken link also sets flag 0x3e8, which the link lobby reads (LinkLobby_RunRoundResult).

Definition at line 44 of file encounter.c.

Referenced by Battle_RunEncounter(), and DebugBattle_RunMenu().

◆ BattlePres_AdjustCameraByShoulderKeys()

void BattlePres_AdjustCameraByShoulderKeys ( void )

Turns the camera while L or R is held. Nothing in the source calls it.

Definition at line 83 of file auto_battle.c.

Referenced by BattlePres_AdjustCameraByShoulderKeys().

◆ BattlePres_AdjustCameraByShoulderKeysAlt()

void BattlePres_AdjustCameraByShoulderKeysAlt ( void )

Turns the camera while L or R is held (a second copy).

Nothing in the source calls it.

Definition at line 749 of file round.c.

Referenced by BattlePres_AdjustCameraByShoulderKeysAlt().

◆ 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_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().

◆ BattleParty_PrepareActiveOwners()

s32 BattleParty_PrepareActiveOwners ( u16 * owners)

Lists the party members who fight (the first four of the party, three in a link battle) and marks each unit as a party member.

owners, if not null, receives their ids ended by BATTLE_UNIT_LIST_END. Returns how many fight. Called across the battle parts whenever they need the party, and through its far stub by the party status window (party_status.c). Sets each fighting member's side to BATTLE_UNIT_PARTY.

Definition at line 371 of file encounter.c.

Referenced by Battle_RunEncounter(), BattleFormation_SelectLevelMatchedCandidate(), BattleParty_AssignMemberSlots(), BattleParty_CollectUnitList(), BattleParty_ListLivingUnits(), BattleParty_PrepareActiveOwners(), BattleParty_ReconcileDjinnRecovery(), BattleParty_ResetActiveRuntimeFields(), BattleSummon_UpdateAvailability(), BattleUnit_RefreshPlacement(), and LinkBattle_SendParty().

◆ BattleEnemyList()

s32 BattleEnemyList ( s16 * unitIds)

Lists the enemy units present, ended by BATTLE_UNIT_LIST_END, and returns how many there are (0 when unitIds is null).

A link battle looks only at the opponent's three places. Called by BattleIntro_AnnounceEncounter, BattleParty_CollectUnitList and BattleTargetExec.

Definition at line 401 of file encounter.c.

Referenced by BattleEnemyList(), BattleIntro_AnnounceEncounter(), BattleParty_CollectUnitList(), and BattleTargetExec().

◆ BattleParty_ListLivingUnits()

s32 BattleParty_ListLivingUnits ( s32 sideMask,
u16 * unitIds )

Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY, BATTLE_SIDE_ENEMIES or both), party first.

unitIds, if not null, receives them ended by BATTLE_UNIT_LIST_END. Returns how many there are. Called across the battle parts (the round, staging, auto battle, turn end and spoils) to test whether a side still stands and to pick targets.

Definition at line 437 of file encounter.c.

Referenced by Battle_AwardSpoils(), Battle_RunEncounter(), BattleEscape_CheckSuccess(), BattleEscape_PlayRun(), BattleParty_ListLivingUnits(), BattlePres_BuildOpponentEntries(), BattlePres_BuildUnitEntries(), BattlePres_RunEscape(), BattlePres_RunUnitAction(), BattlePresentation_BuildSortedUnitEntries(), BattlePresentation_RunPairedUnitTransition(), BattleTarget_ReplaceDefeated(), and BattleUnit_ProcessTurnEnd().

◆ BattleParty_ListActorIds()

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 removed from the battle.

unitIds, if not null, receives them ended by BATTLE_UNIT_LIST_END. Returns how many there are. Unlike BattleParty_ListLivingUnits, it does not test HP. Called across the battle parts that draw or target units, and through its far stub by the command windows (command_row.c, party_commands.c).

Definition at line 510 of file encounter.c.

Referenced by Battle_ProcessRoundEnd(), BattleActor_UpdateSpritePriorities(), BattleObjPut(), BattleParty_CountStandbyDjinn(), BattleParty_IsUnitListed(), BattleParty_ListActorIds(), BattleParty_ListAllUnitsAndSubmit(), BattlePres_ClearAllActorRecordModes(), BattlePres_RunEntryTransition(), BattlePres_SetActorModes(), BattlePres_SetOtherActorRecordModes(), BattlePresentation_DispatchAction(), BattlePresentation_RunUnitTransition(), and BattleUnit_ResetGuardLevels().

◆ BattleObjPut()

void BattleObjPut ( void )

Readies the sprite of every unit in the battle (releasing those of units that left) and sets each one's display mode and motion afresh.

Called by Battle_RunEncounter as the battle is set up, by BattlePresentation_DispatchAction, BattlePresentation_RunUnitTransition, the auto battle and BattleTargetExec after a call for help, and through the far stub BattleActor_CommitPlacementFar by BattleFx_RunParticleStreams.

Definition at line 13 of file sprites.c.

Referenced by Battle_RunEncounter(), BattleObjPut(), BattlePresentation_DispatchAction(), BattlePresentation_RunPairedUnitTransition(), BattlePresentation_RunUnitTransition(), and BattleTargetExec().

◆ BattleParty_ListAllUnitsAndSubmit()

void BattleParty_ListAllUnitsAndSubmit ( void )

Readies the sprite of every unit in the battle (releasing those of units that left), keeping their modes and motions.

Called by BattlePres_RunAttack.

Definition at line 22 of file sprites.c.

Referenced by BattleParty_ListAllUnitsAndSubmit(), and BattlePres_RunAttack().

◆ BattleMotion_GetSlotPalette()

s32 BattleMotion_GetSlotPalette ( s32 id)

Returns the palette of unit id's battle object.

Called by BattleEvent_Playback and BattleMotion_FlashHit, and through its far stub by the effect dispatcher (effect/parts/dispatch.c).

Definition at line 32 of file sprites.c.

Referenced by BattleEvent_Playback(), BattleMotion_FlashHit(), and BattleMotion_GetSlotPalette().

◆ EnemyCheck()

s32 EnemyCheck ( s32 classId)

Returns 1 if an enemy of class classId would find room among the enemy sprite slots: one free slot for a small enemy, two free side by side for a large one.

Called by BattleTargetExec before an enemy calls for help.

Definition at line 41 of file sprites.c.

Referenced by BattleTargetExec(), and EnemyCheck().

◆ SummonSlot_RegisterActorSprites()

s32 SummonSlot_RegisterActorSprites ( s32 unitId)

Loads an enemy unit's battle sprite into the first free enemy sprite slots (one for a small enemy, two side by side for a large one) and records the unit as their owner.

Two sprites take a second part, loaded the same way into further slots. Returns the first slot and the sprite as (slot << 12) | sprite, or 0 for a party member's unit or when a load fails. Called by BattleObjMake. Writes gBattleWork->spriteSlots and the slots' 16 KB sprite buffers at Ram_ActorSpriteSlots.

Definition at line 67 of file sprites.c.

Referenced by BattleObjMake(), and SummonSlot_RegisterActorSprites().

◆ BattleMotion_ReleaseObjectSlotByValue()

s32 BattleMotion_ReleaseObjectSlotByValue ( s32 unitId)

Frees every enemy sprite slot unit unitId holds, unloading its sprite.

Called by BattleObj_MarkForRelease. Clears those gBattleWork->spriteSlots.

Definition at line 141 of file sprites.c.

Referenced by BattleMotion_ReleaseObjectSlotByValue(), and BattleObj_MarkForRelease().

◆ BattleUnit_GetWeaponKind()

s32 BattleUnit_GetWeaponKind ( s32 itemId)

Returns the kind of the weapon whose item id is itemId (0 to 5), which picks a party member's attack animation, or WEAPON_KIND_NONE for an item the list lacks.

Called by BattleUnit_LookupWeaponValueByClass.

gResource_SlotAssignments seen as volatile, for the FAKEMATCH below.

< bits: 15..9 weapon kind | 8..0 item id

Definition at line 163 of file sprites.c.

Referenced by BattleUnit_GetWeaponKind(), and BattleUnit_LookupWeaponValueByClass().

◆ BattleUnit_LookupWeaponValueByClass()

s32 BattleUnit_LookupWeaponValueByClass ( s32 unitId)

Returns the weapon sprite a party member's attack shows for the kind of weapon they have equipped (gBattleUnit_WeaponAnimsClass*), or 0 for no weapon, for Felix, or for a unit that is no party member.

Called by BattleObjMake.

Definition at line 197 of file sprites.c.

Referenced by BattleObjMake(), and BattleUnit_LookupWeaponValueByClass().

◆ BattleObjMake()

void BattleObjMake ( struct BattleObj * actor,
s32 unitId,
s32 x,
s32 y )

Creates the battle object of unit at (x, y) on the battlefield, in pixels: its sprite (an enemy's from its class, sharing the slot it already holds; a party member's battle sprite), palette, size and weapon sprite, turned to face the centre, and starts its motion script (gBattlePres_ActorObjectScript).

Called by BattleUnit_RefreshPlacement and by BattleTargetExec for an enemy that joins. Fills in actor, creates a field object for it and, for an enemy, claims its sprite slots.

Definition at line 24 of file placement.c.

Referenced by BattleObjMake(), BattleTargetExec(), and BattleUnit_RefreshPlacement().

◆ BattlePlacement_GetStepPair()

void BattlePlacement_GetStepPair ( s32 partyPlace,
s32 * x,
s32 * y )

Reads the battlefield position of party place index from gBattlePlacement_StepPairs, in pixels.

Nothing in the source calls it; BattleUnit_RefreshPlacement reads the table directly.

Definition at line 274 of file placement.c.

Referenced by BattlePlacement_GetStepPair().

◆ Summon_LayoutPositions()

void Summon_LayoutPositions ( u16 * actorIds,
s32 count,
s32 * xPositions,
s32 * zPositions )

Lays out count enemies in a column 80 pixels left of the centre, spaced by their size (38 pixels around a large enemy, 27 around a small one, 25 around an empty place, closer when there are more than four) and centred on the line.

Two large classes stand nearer, 50 pixels left. Called by BattleUnit_RefreshPlacement and EnemyUpdate; writes only xPositions and zPositions.

Definition at line 290 of file placement.c.

Referenced by BattleUnit_RefreshPlacement(), EnemyUpdate(), and Summon_LayoutPositions().

◆ EnemySlotGet()

s32 EnemySlotGet ( void )

Returns the id of the first free enemy unit, or -1 when all six are taken.

Called by BattleTargetExec when an enemy calls for help.

Definition at line 328 of file placement.c.

Referenced by BattleTargetExec(), and EnemySlotGet().

◆ EnemyUpdate()

s32 EnemyUpdate ( void )

Lays the enemies out again and moves each one's object anchor to its new place.

Called by BattleTargetExec after an enemy joins. Writes the anchorX and anchorZ of every enemy's battle object.

Definition at line 348 of file placement.c.

Referenced by BattleTargetExec(), and EnemyUpdate().

◆ BattleUnit_RefreshPlacement()

void BattleUnit_RefreshPlacement ( void )

Places every unit at the start of a battle: numbers the places (party members 0 up in their order, enemies 8 to 13) and creates each unit's object at its spot.

Called by Battle_RunEncounter once the unit lists are filled. Writes gBattleWork->placement and every unit's battle object.

Definition at line 379 of file placement.c.

Referenced by Battle_RunEncounter(), and BattleUnit_RefreshPlacement().

◆ BattlePlacement_ContainsId()

s32 BattlePlacement_ContainsId ( s16 * list,
s32 place )

Returns 1 if the unit at place is in list.

Called by BattleActor_SpawnObjectsForList to find the objects to release.

Parameters
listunit ids, ended by BATTLE_UNIT_LIST_END, 14 at most
place0 to 7 a party unit id, 8 to 13 the enemies

Definition at line 436 of file placement.c.

Referenced by BattleActor_SpawnObjectsForList(), and BattlePlacement_ContainsId().

◆ BattleActor_UpdateSpritePriorities()

void BattleActor_UpdateSpritePriorities ( void )

Runs each frame of a battle: advances every unit's status icon, lifts an airborne unit's effect sprite above the others, and draws whichever side is nearer the camera in front.

Runs as a scheduler callback (priority 0xc80) that Battle_RunEncounter adds after the entry transition and removes as the battle ends. Writes each battle object's icon state and its sprites' priorities.

Definition at line 16 of file objects.c.

Referenced by Battle_RunEncounter(), and BattleActor_UpdateSpritePriorities().

◆ BattleUnit_BuildStatusFlags()

s32 BattleUnit_BuildStatusFlags ( s32 unitId,
struct BattleObj * battleObject )

Builds the status icon bits of unit id's ailments into its battle object's activeConditions, which BattleStatusIcon_Cycle shows.

Called wherever a unit's statuses may have changed: BattleEv_DispatchQueued, BattleEvent_Playback, Battle_ProcessRoundEnd, BattleActor_ResetRuntimeFields and BattleActor_SpawnObjectsForList.

Definition at line 155 of file objects.c.

Referenced by Battle_ProcessRoundEnd(), BattleActor_ResetRuntimeFields(), BattleActor_SpawnObjectsForList(), BattleEv_DispatchQueued(), BattleEvent_Playback(), and BattleUnit_BuildStatusFlags().

◆ BattleStatusIcon_Cycle()

s32 BattleStatusIcon_Cycle ( struct BattleObj * battleObject)

Shows a unit's status icons one after another, each for ICON_CYCLE_FRAMES frames, switching at once when the shown status ends, and removes the icon when no status is left.

Called each frame for every unit by BattleActor_UpdateSpritePriorities. Changes the battle object's cycleTimer, selectedCondition, animation and animationEntry, and registers or unregisters the icon on its first sprite.

Definition at line 204 of file objects.c.

Referenced by BattleActor_UpdateSpritePriorities(), and BattleStatusIcon_Cycle().

◆ BattlePres_SetActorModeAndAction()

s32 BattlePres_SetActorModeAndAction ( s32 unitId)

Sets unit id's pose to match its state: held (asleep, stunned or unable to move) or down, else standing; then gives its sprites their palette row, 14 to 17 by unit.

Called by BattleActor_SpawnObjectsForList, BattleEv_DispatchQueued, BattleEvent_Playback and Battle_ProcessRoundEnd.

Definition at line 294 of file objects.c.

Referenced by Battle_ProcessRoundEnd(), BattleActor_SpawnObjectsForList(), BattleEv_DispatchQueued(), BattleEvent_Playback(), and BattlePres_SetActorModeAndAction().

◆ ReleaseBattleObjectRecords()

void ReleaseBattleObjectRecords ( s32 unitId)

Releases every sprite unitId's object holds and leaves it with none, clearing the battle object's animationEntry and effectEntry.

Called by BattleActor_SpawnObjectsForList; BATTLE.S also gives it an unnamed overlay veneer, which nothing in the source calls.

Definition at line 321 of file objects.c.

Referenced by BattleActor_SpawnObjectsForList(), and ReleaseBattleObjectRecords().

◆ BattleActor_SpawnObjectsForList()

void BattleActor_SpawnObjectsForList ( s16 * unitIds,
s32 refreshPoses )

Readies the sprites of the units in list: releases those of every place list lacks, then creates each listed unit's sprites (body, weapon, status icon and effect; or the two parts of a two-part enemy) unless it has them, building its status icons and setting its pose.

With refreshPoses, sets every listed unit's pose again afterwards. Called by BattleObjPut (refreshing) and BattleParty_ListAllUnitsAndSubmit, by the staging and entry transition code, and through its far stub by BattleFx_SelectLivingTargets. Writes the objects' records, their storage kind and height, and the battle objects' icon and effect entries.

Definition at line 356 of file objects.c.

Referenced by BattleActor_SpawnObjectsForList(), BattleObjPut(), BattleParty_ListAllUnitsAndSubmit(), BattlePres_RunAttack(), BattlePres_RunEntryTransition(), BattlePresentation_RunPairedUnitTransition(), and BattlePresentation_RunUnitTransition().

◆ BattleObjGet()

struct BattleObj * BattleObjGet ( s32 unitId)

Returns unitId's battle object, through its place, or null for a unit with no place.

Called throughout the battle parts.

Definition at line 480 of file objects.c.

Referenced by Battle_ProcessRoundEnd(), BattleActor_DestroyTemporaryObject(), BattleActor_ResetRuntimeFields(), BattleActor_SpawnObjectsForList(), BattleActor_UpdateSpritePriorities(), BattleCommand_BuildPlan(), BattleEv_DispatchQueued(), BattleEvent_Playback(), BattleMotion_ApplyPairMidpoint(), BattleMotion_ApplyVariantMotion(), BattleMotion_ApproachTarget(), BattleMotion_DestroyAllSlotObjects(), BattleMotion_FlashHit(), BattleMotion_GetSlotPalette(), BattleMotion_InitializeObject(), BattleMotion_ProjectConditionalPosition(), BattleMotion_ProjectPosition(), BattleMotion_ProjectScaledPosition(), BattleMotion_ResetObjectAtScaledAnchor(), BattleMotion_ResetSlotObjectMode2(), BattleMotion_SetMode5AndActivateSlot(), BattleMotion_SetupEscapeObject(), BattleMotion_ShowDowned(), BattleMotion_SpawnSlotEffectAndWait(), BattleObj_MarkForRelease(), BattleObjGet(), BattleParty_ReconcileDjinnRecovery(), BattlePres_RunApproachAction(), BattlePres_RunAttack(), BattlePres_RunEntryTransition(), BattlePres_RunItem(), BattlePres_RunPlainAttack(), BattlePres_RunPsynergyCast(), BattlePres_RunUnitAction(), BattlePres_SetActorModeAndAction(), BattlePres_SetActorRecordMode(), BattlePres_SetupTransitionAtPairMidpoint(), BattlePresentation_ApplyUnitDamage(), BattlePresentation_RunPairedUnitTransition(), BattlePresentation_RunUnitTransition(), BattleTargetExec(), BattleUnit_ProcessTurnEnd(), BattleUnit_RefreshPlacement(), EnemyUpdate(), ObjMotRst(), and ReleaseBattleObjectRecords().

◆ ResetMotionRecordGroup()

void ResetMotionRecordGroup ( void * recordGroup)

Detaches the scripts from the four sprite entries of one sprite.

Called only by ResetBattleObjectRecordGroups.

Definition at line 497 of file objects.c.

Referenced by ResetBattleObjectRecordGroups(), and ResetMotionRecordGroup().

◆ ResetBattleObjectRecordGroups()

void ResetBattleObjectRecordGroups ( struct MotionObject * object)

Detaches the scripts from every sprite of a battle object.

Nothing in the source calls it.

Definition at line 511 of file objects.c.

Referenced by ResetBattleObjectRecordGroups().

◆ BattleObj_MarkForRelease()

s32 BattleObj_MarkForRelease ( s32 unitId)

Frees the enemy sprite slots unitId holds and marks its object for release at the end of the round (BattleMotion_DestroyAllSlotObjects), setting its active field.

Called when a unit leaves the battle: by BattleEvent_Playback, BattlePres_RunEscape, BattleMotion_ShowDowned, BattleActor_DestroyTemporaryObject and the auto battle.

Definition at line 543 of file objects.c.

Referenced by BattleActor_DestroyTemporaryObject(), BattleEvent_Playback(), BattleMotion_SetMode5AndActivateSlot(), BattleMotion_ShowDowned(), BattleObj_MarkForRelease(), and BattlePres_RunEscape().

◆ BattleMotion_DestroyAllSlotObjects()

void * BattleMotion_DestroyAllSlotObjects ( void )

Releases the object of every unit marked by BattleObj_MarkForRelease, leaving its battle object with no object.

Called by Battle_RunEncounter at the end of each round and by BattlePresentation_DispatchAction.

Definition at line 557 of file objects.c.

Referenced by Battle_RunEncounter(), BattleMotion_DestroyAllSlotObjects(), and BattlePresentation_DispatchAction().

◆ Battle_GetWorkEntryPair()

s32 Battle_GetWorkEntryPair ( s32 place,
struct FixedPointPosition * position )

Writes the battlefield spot of place (its anchor, on the ground) to position.

Nothing in the source calls it.

Definition at line 581 of file objects.c.

Referenced by Battle_GetWorkEntryPair().

◆ Camera_ApplyTransformByFlag()

s32 Camera_ApplyTransformByFlag ( void )

Sets up the camera's view for projecting points; under FLAG_CHOOSING_COMMANDS, through the extra transform gCamera_FlagTransformWork first.

Called by the three projections, BattleMotion_ProjectPosition, BattleMotion_ProjectScaledPosition and BattleMotion_ProjectConditionalPosition. Replaces the transform state.

Definition at line 597 of file objects.c.

Referenced by BattleMotion_ProjectConditionalPosition(), BattleMotion_ProjectPosition(), BattleMotion_ProjectScaledPosition(), and Camera_ApplyTransformByFlag().

◆ BattleMotion_ProjectPosition()

s32 BattleMotion_ProjectPosition ( s32 unitId,
s32 * projected )

Projects unit id's position onto the screen, into projected.

Reached through its far stub from EffectPosition_ProjectBattler.

Definition at line 611 of file objects.c.

Referenced by BattleMotion_ProjectPosition().

◆ GetMotionRecord()

◆ Camera_InitDefaultTransform()

void Camera_InitDefaultTransform ( void )

Puts the battle camera at its default view of the battlefield's centre.

Called by Battle_RunEncounter as the battle is set up and by BattlePresentation_BuildActions. Writes the camera's yaw, pitch, distance, position and eye, and the transform state.

Definition at line 644 of file objects.c.

Referenced by Battle_RunEncounter(), BattlePresentation_BuildActions(), and Camera_InitDefaultTransform().

◆ ObjMotRst()

void ObjMotRst ( s32 unitId)

Sends unitId back to its spot, landing there, and turns it to face the centre.

Called after an action by the staging code, the auto battle, BattleTargetExec and the Quake effect.

Definition at line 17 of file motion.c.

Referenced by BattlePres_RunApproachAction(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPlainAttack(), BattlePres_RunPsynergyCast(), BattlePres_RunUnitAction(), BattlePresentation_DispatchAction(), BattleTargetExec(), and ObjMotRst().

◆ BattleMotion_SetupEscapeObject()

void BattleMotion_SetupEscapeObject ( s32 unitId)

Sends unitId running off its side of the battlefield, three times as far out as its spot, with a hop, in pose 1.

Called by BattleEscape_PlayRun and BattlePres_RunEscape.

Definition at line 46 of file motion.c.

Referenced by BattleEscape_PlayRun(), BattleMotion_SetupEscapeObject(), and BattlePres_RunEscape().

◆ BattleMotion_InterpolatePosition()

void BattleMotion_InterpolatePosition ( struct BattleObj * startSlot,
struct BattleObj * endSlot,
s32 progress )

Sends the unit of startSlot leaping progress percent of the way toward the unit of endSlot, in pose 2.

Also clears REG_BLDCNT. Nothing in the source calls it.

Definition at line 67 of file motion.c.

Referenced by BattleMotion_InterpolatePosition().

◆ BattleMotion_SetObjectPosition()

void BattleMotion_SetObjectPosition ( struct BattleObj * battleObject)

Sends a unit's object back to its spot. Nothing in the source calls it.

Definition at line 96 of file motion.c.

Referenced by BattleMotion_SetObjectPosition().

◆ BattleMotion_ResetObjectAtScaledAnchor()

void BattleMotion_ResetObjectAtScaledAnchor ( s32 unitId)

Sends unitId hopping out to one and a half times its spot's distance from the centre.

Called by BattlePres_RunAttack and BattlePres_RunPlainAttack.

Definition at line 111 of file motion.c.

Referenced by BattleMotion_ResetObjectAtScaledAnchor(), BattlePres_RunAttack(), and BattlePres_RunPlainAttack().

◆ BattleMotion_InitializeObject()

void BattleMotion_InitializeObject ( s32 unitId)

Sends unit id leaping back to 1.3 times its spot's distance from the centre, in pose 5.

Only an unnamed overlay veneer in BATTLE.S reaches it, and nothing in the source calls that.

Definition at line 135 of file motion.c.

Referenced by BattleMotion_InitializeObject().

◆ BattleMotion_ApplyVariantMotion()

void BattleMotion_ApplyVariantMotion ( s32 unitId,
s32 variant )

Knocks unit id back, by the speed, hop and distance of motion variant (gBattleMotion_Variant*), and puts it in pose 5.

One class only takes the pose. Reached through its far stub from the effects, by the EFFECT_STRIKE_TARGET macro of effect_internal.h and directly.

Definition at line 160 of file motion.c.

Referenced by BattleMotion_ApplyVariantMotion().

◆ BattleMotion_ApproachTarget()

void BattleMotion_ApproachTarget ( s32 actorId,
s32 targetId,
s32 travelDivisor,
s32 initialVelocityY )

Sends unit actorId three quarters of the way to unit targetId, arriving in travelDivisor steps, leaping up at initialVelocityY, in pose 2.

Called by BattlePres_RunAttack, BattlePres_RunPlainAttack and BattlePres_RunApproachAction, and through its far stub by the Bind, burst scene, Annihilation, target motes and Thrash effects.

Definition at line 191 of file motion.c.

Referenced by BattleMotion_ApproachTarget(), BattlePres_RunApproachAction(), BattlePres_RunAttack(), and BattlePres_RunPlainAttack().

◆ BattleMotion_ResetSlotObjectMode2()

void BattleMotion_ResetSlotObjectMode2 ( s32 unitId)

Restarts unit id's motion in pose 2. Nothing in the source calls it.

Definition at line 229 of file motion.c.

Referenced by BattleMotion_ResetSlotObjectMode2().

◆ BattleMotion_ReservedNoOp83B0()

void BattleMotion_ReservedNoOp83B0 ( )

Does nothing; BattleMotion_ApplyPairMidpoint, its only caller, passes it a position and a distance.

Definition at line 239 of file motion.c.

Referenced by BattleMotion_ApplyPairMidpoint(), and BattleMotion_ReservedNoOp83B0().

◆ BattleMotion_ApplyPairMidpoint()

void BattleMotion_ApplyPairMidpoint ( s32 firstId,
s32 secondId )

Works out the point halfway between two units, at their move targets where they have one, and hands it to BattleMotion_ReservedNoOp83B0, which does nothing.

Nothing in the source calls it.

Definition at line 244 of file motion.c.

Referenced by BattleMotion_ApplyPairMidpoint().

◆ BattleMotion_SpawnSlotEffectAndWait()

void BattleMotion_SpawnSlotEffectAndWait ( s32 unitId)

Plays the hit flash on unit id's sprite and waits ten frames.

Only a single-sprite object takes it. Nothing in the source calls it.

Definition at line 286 of file motion.c.

Referenced by BattleMotion_SpawnSlotEffectAndWait().

◆ BattleMotion_ProjectScaledPosition()

s32 BattleMotion_ProjectScaledPosition ( s32 unitId,
s32 * projected )

Projects the point above unit id where its effects play (its class's height, BattleUnit_GetEffectHeight) onto the screen, into projected; the height is scaled by the sprite's projected scale.

Called by BattleFx_PlayUnitElementEffect, and through its far stub by EffectPosition_ProjectScaledBattler and SelectionScreen_Draw.

Definition at line 310 of file motion.c.

Referenced by BattleFx_PlayUnitElementEffect(), and BattleMotion_ProjectScaledPosition().

◆ BattleMotion_ProjectConditionalPosition()

s32 BattleMotion_ProjectConditionalPosition ( s32 unitId,
s32 * projected )

Projects the point above unit id onto the screen, into projected: 24 pixels up for a small enemy, 48 for others, as drawn.

Reached through its far stub from BattleTarget_RunSelection, to place the target cursor.

Definition at line 331 of file motion.c.

Referenced by BattleMotion_ProjectConditionalPosition().

◆ BattleUnit_GetEffectHeight()

s32 BattleUnit_GetEffectHeight ( s32 unitId)

Returns the height above unit id where its effects play, 16.16: its class's own (BattleClass_GetEffectHeight), else 24 for a small enemy and 48 for others.

Called by BattleMotion_ProjectScaledPosition, and through its far stub by the effects that play at a unit's body.

Definition at line 352 of file motion.c.

Referenced by BattleMotion_ProjectScaledPosition(), and BattleUnit_GetEffectHeight().

◆ BattlePresentation_BuildSortedUnitEntries()

s32 BattlePresentation_BuildSortedUnitEntries ( struct BattleActionRecord * entries)

Auto battle: gives every living unit a plain attack and sorts them into turn order.

The party act at their Agility and target the first enemy; enemies act at half their Agility plus a random part of it and target a random party member. Returns how many actions there are. Called by Battle_RunEncounter each round under FLAG_AUTO_BATTLE; fills entries.

Definition at line 12 of file auto_battle.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_BuildSortedUnitEntries().

◆ BattlePres_RunAction()

s32 BattlePres_RunAction ( struct BattleActionRecord * action)

Auto battle: plays one action.

A unit already down does nothing (-1); a defeated target is replaced by a living unit of its side first. Returns 1 when the party got away, 0 otherwise. Called by Battle_RunEncounter for each action under FLAG_AUTO_BATTLE. Turns the camera to the actor's side (gTransitionWork) and rewrites action->target.

Definition at line 90 of file auto_battle.c.

Referenced by Battle_RunEncounter(), and BattlePres_RunAction().

◆ BattleObject_IsValidId()

s32 BattleObject_IsValidId ( u32 unitId)

Returns 0 for a party member's or an enemy's unit id, -1 for any other.

Called by the auto battle's action players.

Definition at line 145 of file auto_battle.c.

Referenced by BattleObject_IsValidId(), BattlePres_RunApproachAction(), BattlePres_RunUnitAction(), BattlePres_ShowDefendMessage(), and BattlePresentation_RunPairedUnitTransition().

◆ BattleEscape_PlayRun()

s32 BattleEscape_PlayRun ( struct BattleActionRecord * action)

Auto battle: the party tries to run, and gets away 15 times in 16, each living member running off in turn.

Returns 1 when they got away; else shows MsgCannotEscape and returns 0. Called by BattlePres_RunAction.

Definition at line 158 of file auto_battle.c.

Referenced by BattleEscape_PlayRun(), and BattlePres_RunAction().

◆ BattlePres_ShowDefendMessage()

s32 BattlePres_ShowDefendMessage ( const struct BattleActionRecord * action)

Auto battle: shows that a standing unit is defending.

The message is <unit> is defending. Returns -1 for an invalid unit id, 0 otherwise. Called by BattlePres_RunAction.

Definition at line 188 of file auto_battle.c.

Referenced by BattlePres_RunAction(), and BattlePres_ShowDefendMessage().

◆ BattlePresentation_RunPairedUnitTransition()

s32 BattlePresentation_RunPairedUnitTransition ( struct BattleActionRecord * action)

Auto battle: casts Psynergy.

The camera turns to the caster's side and the caster raises its hand; the target side fades out, its living units are readied alone, the Psynergy's effect (kind action->parameter) plays on them, and everyone fades back in. Returns -1 for an invalid actor or target. Called by BattlePres_RunAction for CMD_PSYNERGY. Writes REG_BLDCNT and REG_BLDALPHA and the actors' record modes, and leaves the battle objects readied again.

Definition at line 215 of file auto_battle.c.

Referenced by BattlePres_RunAction(), and BattlePresentation_RunPairedUnitTransition().

◆ BattlePres_RunApproachAction()

s32 BattlePres_RunApproachAction ( struct BattleActionRecord * input)

Auto battle: an attack.

Shows <unit> attacks!, sends the attacker up to its target, plays the blow and sends both back. Returns -1 for an invalid attacker or target. Nothing in the source calls it.

Definition at line 332 of file auto_battle.c.

Referenced by BattlePres_RunApproachAction().

◆ BattlePres_RunUnitAction()

s32 BattlePres_RunUnitAction ( struct BattleActionRecord * action)

Auto battle: an attack or an item.

Turns the camera to the actor's side, poses the actor and plays the effect (kind action->parameter) on the first living unit of the target's side, then sends both back. Returns -1 for an invalid actor. Called by BattlePres_RunAction for CMD_ATTACK, CMD_ITEM and any other command but fleeing, defending and Psynergy.

Definition at line 383 of file auto_battle.c.

Referenced by BattlePres_RunAction(), and BattlePres_RunUnitAction().

◆ BattlePresentation_ApplyUnitDamage()

void BattlePresentation_ApplyUnitDamage ( u32 unitId,
s32 damage,
s32 showMessage,
u8 * context )

Auto battle: deals damage HP to unit unitId and shows it.

When showMessage is set, "A bitter blow!" (to the party) or "A critical hit!" (to an enemy) comes first; then <unit> takes <damage> damage!, and <unit> goes down... or <unit> has been downed! when the HP runs out. context, if null, is replaced by four cleared bytes nothing reads. Nothing in the source calls it. Lowers unit->hp, no lower than 0.

Definition at line 469 of file auto_battle.c.

Referenced by BattlePresentation_ApplyUnitDamage().

◆ BattleMotion_SetMode5AndActivateSlot()

void BattleMotion_SetMode5AndActivateSlot ( s32 unitId)

For a unit whose HP has run out: plays its falling animation to the last frame and marks its object for release (BattleObj_MarkForRelease).

Called by BattlePresentation_ApplyUnitDamage.

Definition at line 526 of file auto_battle.c.

Referenced by BattleMotion_SetMode5AndActivateSlot(), and BattlePresentation_ApplyUnitDamage().

◆ BattleTarget_ReplaceDefeated()

s32 BattleTarget_ReplaceDefeated ( const struct BattleActionRecord * action)

Returns the action's target, or a random living unit of its side when the target is down; TARGET_SIDE_DEFEATED when none is left.

Called by BattlePres_RunAction.

Definition at line 548 of file auto_battle.c.

Referenced by BattlePres_RunAction(), and BattleTarget_ReplaceDefeated().

◆ Palette_UpdatePulseBrightness()

void Palette_UpdatePulseBrightness ( void )

Pulses BG palette 14's colours: each takes the matching colour of palette 15 brightened by up to twelve steps, rising and falling with the frame count.

Nothing in the source calls it. Writes BG palette RAM.

Definition at line 14 of file round.c.

Referenced by Palette_UpdatePulseBrightness().

◆ Camera_ConfigureScene()

void Camera_ConfigureScene ( s32 verticalOffset)

Sets the camera up for the fixed view the battle shows while commands are chosen, raised by verticalOffset pixels, with its projection and the background's perspective to match.

Called by BattlePresentation_BuildActions, and through its far stub by Battle_CollectPartyCommands and UpdateLinkSessionCountdown. Writes the camera, the transition's targetYaw and flag (left 1, so the camera callback leaves the background alone), gProjection and the background's affine page.

Definition at line 65 of file round.c.

Referenced by BattlePresentation_BuildActions(), and Camera_ConfigureScene().

◆ BattleUnit_ResetGuardLevels()

void BattleUnit_ResetGuardLevels ( void )

Ends every unit's guard (Defend and the like) and recalculates its stats.

Called by BattlePresentation_BuildActions as each round begins. Clears every unit's guardLevel.

Definition at line 119 of file round.c.

Referenced by BattlePresentation_BuildActions(), and BattleUnit_ResetGuardLevels().

◆ BattleEscape_CheckSuccess()

s32 BattleEscape_CheckSuccess ( void )

Rolls whether the party gets away.

The chance, in hundredths of a percent, is 5000 plus 2000 for each attempt that failed, plus 500 times the party's average level, less 500 times the enemies' average level. A party that struck first always gets away; no one gets away from a battle that forbids it. Every attempt counts toward the next. Returns 1 when the party gets away. Called by BattlePresentation_BuildActions when the first action is CMD_FLEE. Each roll, even a successful one, raises gBattleWork->escapeFailures.

Definition at line 145 of file round.c.

Referenced by BattleEscape_CheckSuccess(), and BattlePresentation_BuildActions().

◆ BattlePres_BuildUnitEntries()

s32 BattlePres_BuildUnitEntries ( struct BattleActionRecord * entries)

The party's actions for the round, from the command menu: a member who is asleep, confused, charmed or stunned loses each of their turns (CMD_NONE); the others choose theirs (Battle_CollectPartyCommandsFar).

Returns how many actions there are, or -1 if the menu gave up. Called by BattlePresentation_BuildActions. Fills entries.

Definition at line 191 of file round.c.

Referenced by BattlePres_BuildUnitEntries(), and BattlePresentation_BuildActions().

◆ BattlePres_BuildOpponentEntries()

s32 BattlePres_BuildOpponentEntries ( struct BattleActionRecord * entries)

The enemies' actions for the round, in a shuffled order, each chosen by BattleCommand_SelectAutomatic; a sleeping or stunned enemy loses its turns.

An enemy acting more than once a turn acts later at half its Agility. None act when the party struck first; when the party is caught by surprise, only two to five enemies act, once each. Returns how many actions there are. Called by BattlePresentation_BuildActions outside a link battle. Fills entries.

Definition at line 244 of file round.c.

Referenced by BattlePres_BuildOpponentEntries(), and BattlePresentation_BuildActions().

◆ BattleQueue_SortByPriority()

void BattleQueue_SortByPriority ( struct BattleActionRecord * entries,
s32 count )

Sorts the round's actions into turn order, fastest first, after moving the guarding and grounding Djinn to the front.

Called by BattlePresentation_BuildActions. Raises those Djinn actions' priority and reorders entries in place.

Definition at line 323 of file round.c.

Referenced by BattlePresentation_BuildActions(), and BattleQueue_SortByPriority().

◆ BattlePresentation_AppendLinkedActions()

s32 BattlePresentation_AppendLinkedActions ( struct BattleActionRecord * actions,
s32 count )

Link battle: exchanges the round's actions with the other console and appends the opponent's after the count of this console's.

Each console sees its own party as the party: the received actions' units take the ids they have here and their targets swap sides. The parent sends first and gives the round its random seed; the child checks both consoles agree on the next random number. A party member's priority is made even on the parent and odd on the child, so equal speeds sort alike on both. Returns how many actions were received, or -1 when the exchange fails. Called by BattlePresentation_BuildActions in a link battle. Sets gBattleRandomSeed, writes each action's slot and priority, and on a failure resets the link transfer and removes its interrupt handlers.

Definition at line 397 of file round.c.

Referenced by BattlePresentation_AppendLinkedActions(), and BattlePresentation_BuildActions().

◆ Palette_CopyBanksWithBrightnessOffset()

void Palette_CopyBanksWithBrightnessOffset ( s32 offset)

Copies BG palette 15 to 14 and 5 to 4, brightened or darkened.

Called by BattlePresentation_BuildActions with 8, as the round's commands are chosen.

Parameters
offsetadded to each of the red, green and blue values (held in 0 to 31)

Definition at line 562 of file round.c.

Referenced by BattlePresentation_BuildActions(), and Palette_CopyBanksWithBrightnessOffset().

◆ BattlePresentation_BuildActions()

s32 BattlePresentation_BuildActions ( struct BattleActionRecord * actions)

Builds the turn's actions and sorts them into turn order: the party's commands, then the link opponent's or the enemies' actions.

Returns how many actions there are; negative to abort (a link failure). Called by Battle_RunEncounter at the start of each round outside auto battle. Clears gBattleWork->actions, sets every defender's guardLevel, may set encounterMode to BATTLE_ENCOUNTER_ENEMIES_FIRST after a failed escape, and holds FLAG_CHOOSING_COMMANDS while the commands are chosen.

Parameters
actionsthe actions (20 at most)

Definition at line 620 of file round.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_BuildActions().

◆ Battle_GetTaggedSlotValue()

s32 Battle_GetTaggedSlotValue ( s32 taggedPlace)

Returns the unit id at a list place.

Called by BattleCommand_BuildPlan for a command's target.

Parameters
taggedPlacethe place in the low four bits; 0x80 set for the enemies' list

Definition at line 711 of file round.c.

Referenced by Battle_GetTaggedSlotValue(), and BattleCommand_BuildPlan().

◆ Battle_FindTaggedSlotByValue()

s32 Battle_FindTaggedSlotByValue ( u32 unitId)

Returns the list place of unit id, or -1 if it is in neither list: the party's as 0x100 | place, the enemies' as 0x180 | place (PLACE_PARTY, PLACE_ENEMY).

Called by the enemies' command choice (enemy_ai.c) to aim at a unit.

Parameters
unitId0 to 7 the party, any other an enemy

Definition at line 724 of file round.c.

Referenced by Battle_FindTaggedSlotByValue(), and BattleCommand_SelectAutomatic().

◆ Battle_ReservedNoOp9B2C()

void Battle_ReservedNoOp9B2C ( void )

Does nothing; Battle_RunEncounter calls it at the start of each round.

Definition at line 752 of file round.c.

Referenced by Battle_ReservedNoOp9B2C(), and Battle_RunEncounter().

◆ BattlePresentation_DispatchAction()

s32 BattlePresentation_DispatchAction ( struct BattleActionRecord * request,
s32 delay )

Plays one action of the round, after delay frames facing the party: an enemy picks its ability now; the action is planned (its targets, hits and damage) and shown the way its staging asks, then the turn's end effects run and every unit returns to its spot.

Returns 1 when the party got away, 0 otherwise, and -1 when the actor is already down. Called by Battle_RunEncounter for each action of the round, with a delay of 10 for the first. Resets the camera's view (gTransitionWork's frames, flag and yaw, gBattleWork->brightness, the transform and projection), builds gBattleWork->plan, and marks the action done (request->unitId to BATTLE_UNIT_LIST_END) unless the party fled.

Definition at line 18 of file staging.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_DispatchAction().

◆ BattlePres_BuildTargetList()

s32 BattlePres_BuildTargetList ( struct BattlePlan * plan,
struct BattleEffectArgument * effect )

Fills an effect command from a plan: its kind and strength, the actor and the targets still standing (or every target, for an effect that revives), at least the first.

Called by each staging runner before its effect plays: RunUnitTransition, RunAttack, RunPlainAttack, RunItem and RunPsynergyCast. Writes effect's prelude (0), kind, variant, actor, actors, firstTarget, count and range (1); the caller sets its side.

Definition at line 129 of file staging.c.

Referenced by BattlePres_BuildTargetList(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPlainAttack(), BattlePres_RunPsynergyCast(), and BattlePresentation_RunUnitTransition().

◆ BattlePres_RunEscape()

s32 BattlePres_RunEscape ( struct BattlePlan * plan)

Plays a unit's attempt to run.

The party gets away unless the enemies struck first ("But there's no escape!"), each member able to move running off in turn; an enemy gets away 7 times in 10 and leaves the battle. Returns 1 when the party got away. Called by BattlePresentation_DispatchAction for PLAN_SHOW_FLEE. Turns the camera to the party's view and holds gTransitionWork->active while it runs; an enemy that gets away is taken out of the lists and its object released.

Definition at line 175 of file staging.c.

Referenced by BattlePres_RunEscape(), and BattlePresentation_DispatchAction().

◆ BattlePresentation_RunUnitTransition()

s32 BattlePresentation_RunUnitTransition ( struct BattlePlan * plan,
s32 mode )

Plays a summon or a full-screen Psynergy.

The camera turns to the target side (or to the actor's, for a staged scene), the actor glows in its element and the other side fades out; then, unless the cast failed ("blocked" or too little PP), the target side's units are readied alone and the effect plays while the events run. Everyone fades back in. Called by BattlePresentation_DispatchAction for PLAN_SHOW_SUMMON (mode 1) and PLAN_SHOW_FULL_SCREEN (mode 0). Sets gTransitionWork's yaw (and its frames, for a scene), REG_BLDCNT and REG_BLDALPHA for the fades, and the units' record modes; schedules BattleEvent_Playback around the effect. mode : bit 0 hides the actor too (the summons)

Definition at line 252 of file staging.c.

Referenced by BattlePresentation_DispatchAction(), and BattlePresentation_RunUnitTransition().

◆ BattlePres_RunActorEntries()

s32 BattlePres_RunActorEntries ( struct BattlePlan * plan,
s32 unused )

Clears the highlights, then applies the action to each target in turn and plays its events; with no target, only waits for the player.

Called by BattlePresentation_DispatchAction for PLAN_SHOW_MESSAGES, an action with no animation: each target's BattleTargetExec is played at once by BattleEv_DispatchQueued. plan : the action and its targets

Definition at line 428 of file staging.c.

Referenced by BattlePres_RunActorEntries(), and BattlePresentation_DispatchAction().

◆ BattlePres_RunAttack()

s32 BattlePres_RunAttack ( struct BattlePlan * plan,
s32 mode )

Plays an attack: the camera turns halfway to the attacker's view, the attacker runs up to its first target over its swing's frames, and the blow lands: a miss makes the target hop back; a hit plays its effect and the events, and a critical hit zooms in on the pair with only those two shown.

Both then return. A miss "nimbly dodges the blow". Called by BattlePresentation_DispatchAction for PLAN_SHOW_ATTACK; mode is unused. Sets gTransitionWork's yaw (and its flag for a critical hit's zoom), the window registers (WIN0 and WIN1 to the battlefield, rows 16 to 136, both turned on), and schedules BattleEvent_Playback around the effect.

Definition at line 454 of file staging.c.

Referenced by BattlePres_RunAttack(), and BattlePresentation_DispatchAction().

◆ BattlePres_RunPlainAttack()

s32 BattlePres_RunPlainAttack ( struct BattlePlan * input,
s32 flags )

Unused.

Plays a plain attack run: the attacker runs up to its first target and the blow's effect and events play, or, with bit 1 of flags (a miss), the target hops back; both then return. Nothing calls it. BattlePres_RunAttack without the hop height, the windows, the critical zoom, the dodge message or playback; its events are played at once after the effect, and the camera's slower turn waits 20 frames.

Definition at line 617 of file staging.c.

Referenced by BattlePres_RunPlainAttack().

◆ BattlePres_RunItem()

s32 BattlePres_RunItem ( struct BattlePlan * plan,
s32 unused,
struct BattleActionRecord * selection )

Plays an item's use: the camera turns to the user's side, the user raises the item and, for an item with an effect, the screen dims while it plays with the events.

Then the item is spent as its use type says; when its slot empties, later item commands of the same member this round follow their items to their new slots (or lose theirs, -1). Called by BattlePresentation_DispatchAction for PLAN_SHOW_ITEM, with the action's record as selection. Sets gTransitionWork's yaw and, while an effect plays, dims gBattleWork->brightness and BG palettes 6 to 13; changes the user's inventory (Inventory_RemoveFar, Inventory_BreakFar, or the Empty Bottle) and the parameters of gBattleWork->actions.

Definition at line 700 of file staging.c.

Referenced by BattlePres_RunItem(), and BattlePresentation_DispatchAction().

◆ BattleMotion_SetRecordChildValues()

s32 BattleMotion_SetRecordChildValues ( struct MotionObject * object,
s32 colorMode )

Draws every sprite of an object in a colour mode (enum SpriteColorMode): colorMode on each sprite's first layer, SPRITE_COLOR_NORMAL on the others, and every layer's frame set to 255 (none) so that it is drawn again.

Called by BattleMotion_FlashHit and BattleEvent_Playback (a hit's flashes and a unit's redraw), with the flash's colour or the unit's own (BattleMotion_GetSlotPalette).

Definition at line 830 of file staging.c.

Referenced by BattleEvent_Playback(), BattleMotion_FlashHit(), and BattleMotion_SetRecordChildValues().

◆ BattlePres_RunPsynergyCast()

s32 BattlePres_RunPsynergyCast ( struct BattlePlan * plan,
s32 mode )

Plays Psynergy, a Djinni or an enemy's cast.

The camera turns toward the targets from the caster's side, the caster raises its hand and glows in its element (no glow for a Djinni); then the cast fails ("blocked" or too little PP) or its effect plays with the events, and the targets return to their spots. Called by BattlePresentation_DispatchAction for PLAN_SHOW_CAST (mode 0), PLAN_SHOW_DJINNI (1) and PLAN_SHOW_ENEMY_CAST (2). Sets gTransitionWork's yaw (and its frames for a fixed view), redraws the party's status without bit 0, and schedules BattleEvent_Playback around the effect. mode : 1 a Djinni, 2 an enemy's cast, 0 any other

Definition at line 871 of file staging.c.

Referenced by BattlePres_RunPsynergyCast(), and BattlePresentation_DispatchAction().

◆ BattleMotion_FlashHit()

void BattleMotion_FlashHit ( s32 unitId,
s32 unused0,
s32 unused1 )

Flashes unit id as it is hit: puts it in its damage pose and switches its sprites between white and their own colours twice, two frames each, its status panel highlighted.

Called for BATTLE_EVENT_HIT by BattleEv_DispatchQueued (BattleEvent_Playback flashes over frames itself). Waits 8 frames and redraws the party's status at the end.

Definition at line 978 of file staging.c.

Referenced by BattleEv_DispatchQueued(), and BattleMotion_FlashHit().

◆ BattleActor_RemoveFromLists()

void BattleActor_RemoveFromLists ( s32 unitId)

Takes unit id out of the party's or the enemies' list and out of this round's actions, and frees its name letter.

Called when a unit leaves the battle: by BattlePres_RunEscape (an enemy that gets away), BattleMotion_ShowDowned and PLAY_FELLED in BattleEvent_Playback (a fallen enemy), and BattleActor_DestroyTemporaryObject. Sets the unit's side to BATTLE_UNIT_ABSENT and its list entry to BATTLE_UNIT_REMOVED, releases its name letter (BattleEnemy_ReleaseNameLetter), and ends its actions this round (unitId BATTLE_UNIT_LIST_END). A unit in neither list only has its side changed.

Definition at line 1019 of file staging.c.

Referenced by BattleActor_DestroyTemporaryObject(), BattleActor_RemoveFromLists(), BattleEvent_Playback(), BattleMotion_ShowDowned(), and BattlePres_RunEscape().

◆ BattleMotion_ShowDowned()

void BattleMotion_ShowDowned ( s32 unitId)

Shows a downed unit: a party member lies down, an enemy keeps its damage pose, turns grey, leaves the lists after four frames and dissolves a dot at a time.

Called for BATTLE_EVENT_DEFEAT by BattleEv_DispatchQueued; PLAY_FELLED in BattleEvent_Playback is its counterpart over frames. An enemy's object is marked for release.

Definition at line 1072 of file staging.c.

Referenced by BattleEv_DispatchQueued(), and BattleMotion_ShowDowned().

◆ BattleTarget_SelectRandomPosition()

s32 BattleTarget_SelectRandomPosition ( s32 requireLivingUnit)

Picks a random place: with requireLivingUnit, a party member still standing; otherwise any enemy place in use.

Returns its place code, or 0 when there is none. Called by BattleCommand_SelectAutomatic when BattleTarget_SelectForAction finds no one listed on the side (-2). Takes one Random16 roll when any position qualifies.

Definition at line 26 of file targeting.c.

Referenced by BattleCommand_SelectAutomatic(), and BattleTarget_SelectRandomPosition().

◆ BattleTarget_SelectForAction()

s32 BattleTarget_SelectForAction ( s32 actorId,
struct BattleAct * action )

Picks the target of an enemy's ability (or a confused unit's), as a place code: among the units of the side it may target, those it would affect (CHECK_EFFECT_TARGET), at random; a single-target attack by an enemy with a strategy favours the strongest, the first of the sorted targets 6 times in 11, 15 or 18, the next 5 times, and so on.

Returns -2 when the side has no one, -1 when the ability would affect no one. Called by BattleCommand_SelectAutomatic for an ability aimed at allies, the user or foes. Takes Random16 rolls to choose among eligible targets.

Definition at line 317 of file targeting.c.

Referenced by BattleCommand_SelectAutomatic(), and BattleTarget_SelectForAction().

◆ BattleActor_ResetRuntimeFields()

s32 BattleActor_ResetRuntimeFields ( s32 unitId)

Clears every ailment and stat change of a unit that goes down, recalculates its stats and rebuilds its status icons.

Reached through the BATTLE_EVENT_DEFEAT event, from BattleEv_DispatchQueued and BattleEvent_Playback. Clears the unit's element levels, poison, stat stages and their turns, every status, its equipment bonuses, ready, immobile and challenge; UnitCalcFar then recomputes its stats, and BattleUnit_BuildStatusFlags its battle object's status flags.

Definition at line 19 of file events.c.

Referenced by BattleActor_ResetRuntimeFields(), BattleEv_DispatchQueued(), and BattleEvent_Playback().

◆ BattlePresentation_WaitForAdvance()

s32 BattlePresentation_WaitForAdvance ( void )

Shows the bobbing arrow at the message window and waits for the player to go on (B, or one of KEY_ADVANCE), then plays the cursor sound.

Called after a message by BattlePresentation_DispatchAction and the staging runners, BattleCommand_BuildPlan (a flight), BattleIntro_AnnounceEncounter, the round's end (turn_end.c), and BattleEv_DispatchQueued for each BATTLE_EVENT_MESSAGE. Waits for the message window first. Takes a 128-byte VRAM cache entry for the arrow's tiles and frees it; each frame queues the WINOUT writes, sets REG_BLDALPHA and pushes the arrow sprite.

Definition at line 90 of file events.c.

Referenced by Battle_AwardSpoils(), Battle_ProcessRoundEnd(), Battle_RunEncounter(), BattleCommand_BuildPlan(), BattleEv_DispatchQueued(), BattleIntro_AnnounceEncounter(), BattlePres_RunActorEntries(), BattlePres_RunEscape(), BattlePresentation_DispatchAction(), and BattlePresentation_WaitForAdvance().

◆ BattlePresentation_WaitForPromptAt()

s32 BattlePresentation_WaitForPromptAt ( s32 x,
s32 y )

Shows the cursor bobbing at (x, y) and waits for one of KEY_ADVANCE.

Called by Battle_RunEncounter under the Djinn tutorial's standby message, and by Menu_RunCommandRow through BattlePresentation_WaitForPromptAtFar. Waits for the message window first; takes a 128-byte VRAM cache entry for the cursor's tiles and frees it, and each frame queues the WINOUT writes, sets REG_BLDALPHA and pushes the cursor sprite. x, y : in pixels

Definition at line 152 of file events.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_WaitForPromptAt().

◆ BattleEv_MarkDisplay()

void BattleEv_MarkDisplay ( void )

Sets gBattleDisplayWork->marked, which the next message reads, as BATTLE_EVENT_MARK does.

Called by BattleCommand_BuildPlan between a weapon's two unleash messages.

Definition at line 189 of file events.c.

Referenced by BattleCommand_BuildPlan(), and BattleEv_MarkDisplay().

◆ BattleActor_DestroyTemporaryObject()

s32 BattleActor_DestroyTemporaryObject ( s32 unitId)

Takes an enemy out of the battle at once (one that leaves rather than falls): its HP to 0, out of the lists, and its object released.

Reached through the BATTLE_EVENT_REMOVE_UNIT event, which BattleTargetExec queues for a self-destructing actor, from BattleEv_DispatchQueued and BattleEvent_Playback. A party unit is left as it is. Clears the battle object's object and active and releases its dispatch object.

Definition at line 200 of file events.c.

Referenced by BattleActor_DestroyTemporaryObject(), BattleEv_DispatchQueued(), and BattleEvent_Playback().

◆ BattleEv_GrantDjinnBonus()

void BattleEv_GrantDjinnBonus ( struct BattleEventState * runtime,
u32 operand )

The BATTLE_EVENT_DJINN_BONUS event: grants the Djinn bonus for the rest of the action.

Its operand is ignored. Called for the event by BattleEv_DispatchQueued and BattleEvent_Playback; BattleTargetExec queues it. Sets EVENT_FLAG_DJINN_BONUS in runtime->flags, which BattleEventRuntime_Reset clears.

Definition at line 226 of file events.c.

Referenced by BattleEv_DispatchQueued(), BattleEv_GrantDjinnBonus(), and BattleEvent_Playback().

◆ BattleEv_DispatchQueued()

u32 BattleEv_DispatchQueued ( void )

Plays the queued battle events at once, in order (BattleEvent_Playback plays them over frames instead): the messages with their arguments, the hit flashes, the downed units, the redraws.

Then empties the queue. Called where an outcome is shown outside an effect: by the staging runners (a blocked cast, a dodge, a broken item, a plan's targets one by one), BattleCommand_BuildPlan's debug defeat, and the turn's end (turn_end.c). Each message, flash and fall waits its frames here. Ends with BattleEventRuntime_Reset.

Definition at line 241 of file events.c.

Referenced by BattleCommand_BuildPlan(), BattleEv_DispatchQueued(), BattlePres_RunActorEntries(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPlainAttack(), BattlePres_RunPsynergyCast(), BattlePresentation_RunUnitTransition(), and BattleUnit_ProcessTurnEnd().

◆ BattleEvPush()

u32 BattleEvPush ( u32 opcode,
u32 operand )

Queues one battle event (enum BattleEventOpcode) with its operand, and returns the opcode.

Called, directly or through PUSH_MESSAGE, by BattleTargetExec for each step of an outcome, and by staging.c, plan.c and turn_end.c. Appends to gBattleWork->events.queue with no test against BATTLE_EVENT_CAPACITY.

Definition at line 321 of file events.c.

Referenced by Battle_ProcessRoundEnd(), BattleCommand_BuildPlan(), BattleEvPush(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPsynergyCast(), BattlePresentation_RunUnitTransition(), BattleTargetExec(), and BattleUnit_ProcessTurnEnd().

◆ BattleEffectDeadCheck()

s32 BattleEffectDeadCheck ( s32 effect)

Returns 1 for an effect that still applies when the ability's damage has just knocked its target out: the drains, which give the damage they dealt back to the actor.

Called by BattleTargetExec before the added effect. effect : the ability's effect (enum AbilityEffect)

Definition at line 13 of file target_exec.c.

Referenced by BattleEffectDeadCheck(), and BattleTargetExec().

◆ BattleTargetExec()

s32 BattleTargetExec ( struct BattlePlan * plan,
s32 slot )

Applies the planned ability to one of its targets: first its damage or healing, then its added effect (a status, a stat change, a revival...).

Nothing is shown here: each step queues battle events (the names and numbers a message needs, the message, the target's reactions) that BattleEvent_Playback then plays in order. The units themselves change at once: UnitCalcFar recalculates a unit's stats from its stages, and UnitRatioFar its HP and PP gauges after either changes.

Called for each target in turn by BattleEvent_Playback (an action with an effect) and BattlePres_RunActorEntries (one without). Changes the target's HP, PP, statuses, stat stages and turns, and its guard; the actor's HP or PP for a drain, and plan->hauntDamage; adds an enemy to gBattleWork->enemyIds when one is called; sets gBattleWork->challengeFlag bit 1 when the party is challenged; queues the events that show it all. It takes BattleRandomFar rolls, and borrows a heap block for the target's copy.

It runs in phases, each marked in the body:

  1. Setup: a copy of the target as it was; the target's distance from the aimed place; the element's affinity (resisted, neutral or weak); the actor's power in the element.
  2. The Djinn bonus roll, and whether the effect lands (hit).
  3. Calling an ally (Ally Search, Search for Help, Speed Surge).
  4. The effects that change the damage step: Ground, Torch, Severe Blow, instant death, a self-destruct, Psy Drain.
  5. Damage and healing, by the ability's kind (attack, PP damage, HP and PP healing, Psynergy damage, an effect's damage).
  6. The added effect, by the ability's effect: cures, heals, stat changes, revivals, statuses, drains, Break, the curse, guards.
  7. Waking from damage, the recalculated stats, the redraw, and the evil spirit's share for a haunted actor.

plan : the action under way: the actor, the ability, its element and its targets, each with its distance from the aimed position, damage multiplier, critical hit and any hit roll made in advance. slot : which of the plan's targets (0 to plan->targetCount - 1).

Definition at line 132 of file target_exec.c.

Referenced by BattleEvent_Playback(), BattlePres_RunActorEntries(), and BattleTargetExec().

◆ Ability_IsPsynergy()

u32 Ability_IsPsynergy ( s32 abilityId)

Returns 1 for an ability that costs PP, and for Psy Drain, which costs none.

Called by BattleCommand_BuildPlan (a cast's staging) and BattleCommand_SelectAutomatic (an enemy's PP and seal checks).

Definition at line 1318 of file target_exec.c.

Referenced by Ability_IsPsynergy(), BattleCommand_BuildPlan(), and BattleCommand_SelectAutomatic().

◆ BattleCommand_SelectAutomatic()

s32 BattleCommand_SelectAutomatic ( struct BattleActionRecord * request,
s32 retry )

Chooses an enemy's action (a party member's is chosen in the menu): one of the eight in its definition, picked by its action strategy, with an item instead where its item mask says so, and a target worth the ability.

A choice that cannot be made (too little PP, sealed, a forbidden escape, no worthwhile target) picks again; after 18 tries the enemy defends. Called with retry 0 for each enemy as the round is built (BattlePres_BuildOpponentEntries), and with retry 1 at its turn (BattlePresentation_DispatchAction). Writes request's command, parameter, target and range; strategies 3 and 4 advance the place remembered in BattleUnit.rewards. Returns nothing. retry : 0 when the round is built: only a guard is settled now (it must raise before anyone acts); 1 at the enemy's turn: the rest.

Picks a place in the action list from a 0-255 roll and eight weights: the first place whose running total passes the roll, else place 0.

Definition at line 33 of file enemy_ai.c.

Referenced by BattleCommand_SelectAutomatic(), BattlePres_BuildOpponentEntries(), and BattlePresentation_DispatchAction().

◆ Dma_StopAllThenRunHook()

void Dma_StopAllThenRunHook ( void )

Sets DMA3 three times over, stopping it, then calls the IRQ return instruction's word as a routine.

Nothing in this game calls it. XXX: _call_via_r0 is given the value of IwramIrqModeWord, the instruction orr r3, r3, #0x92 in runtime.s, not its address, so it would branch to 0xe3833092; a caller in another edition, or the same function in The Lost Age, would show what it was meant to run.

Definition at line 14 of file playback.c.

Referenced by Dma_StopAllThenRunHook().

◆ BattleEventRuntime_BeginPhase()

void BattleEventRuntime_BeginPhase ( s32 cue)

Starts playback of the plan's targets when the effect's blow lands.

Reached as EFFECT_SHOW_DAMAGE(hitSound), through BattleEventRuntime_BeginPhaseFar, from the effects (see the folder README). Only while playback is idle: sets the phase to BATTLE_PLAYBACK_RESOLVE_TARGET, and a nonzero cue to pendingCue. cue : the hit's sound (an SE_ id); zero keeps the one set

Definition at line 27 of file playback.c.

Referenced by BattleEventRuntime_BeginPhase().

◆ BattleEventRuntime_SchedulePhase()

s32 BattleEventRuntime_SchedulePhase ( s32 frames)

Empties the event queue and schedules playback of the events queued next, with no targets to resolve.

Called before a Djinni is set (BattleCommand_BuildPlan) and for the Djinn the round's and a turn's end show (Battle_ProcessRoundEnd, BattleUnit_ProcessTurnEnd), each followed by BattleEventRuntime_WaitForReady. Sets the phase to BATTLE_PLAYBACK_DISPATCH and gBattleWork->plan's targetCount to 0, so playback goes to BATTLE_PLAYBACK_READY once the queue is played; adds BattleEvent_Playback as a scheduler callback and returns the scheduler's result. frames : the delay before the first event

Definition at line 49 of file playback.c.

Referenced by Battle_ProcessRoundEnd(), BattleCommand_BuildPlan(), BattleEventRuntime_SchedulePhase(), and BattleUnit_ProcessTurnEnd().

◆ BattleEvent_Playback()

void BattleEvent_Playback ( void )

Plays the plan's targets one at a time: resolves the next target with BattleTargetExec, then plays the events it queued over the frames that follow, until every target is done.

Runs each frame as a scheduler callback (priority 0xc80), added by the staging runners in staging.c and by BattleEventRuntime_SchedulePhase, and removed by BattleEventRuntime_WaitForReady. Idle until BattleEventRuntime_BeginPhase or the wait starts it. Advances gBattleWork->events (phase, eventIndex, timer, queue.targetIndex, actorId, displaySource, displayEntry, flags); plays the sounds, message arguments, messages, flashes, falls and redraws as BattleEv_DispatchQueued does, without waiting. Each pass of its loop handles one phase; a phase that has to wait for a later frame returns.

Clears a sprite's tiles in OBJ VRAM, at its VRAM cache entry's offset; the last step of a fallen enemy's dissolve.

Definition at line 87 of file playback.c.

Referenced by BattleEvent_Playback(), BattleEventRuntime_SchedulePhase(), BattleEventRuntime_WaitForReady(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPsynergyCast(), and BattlePresentation_RunUnitTransition().

◆ BattleEventRuntime_Reset()

void BattleEventRuntime_Reset ( void )

Stops playback and empties the event queue.

Called when an action is planned (BattleCommand_BuildPlan), after a queue is played (BattleEv_DispatchQueued, BattleEventRuntime_WaitForReady), and before playback is scheduled (BattleCommand_BuildPlan, turn_end.c). Sets gBattleWork->events' phase to BATTLE_PLAYBACK_IDLE, clears the queue, the event index, the timer, the target index and the flags (the Djinn bonus), and sets the hit sound back to SE_HEAVY_IMPACT.

Definition at line 437 of file playback.c.

Referenced by Battle_ProcessRoundEnd(), BattleCommand_BuildPlan(), BattleEv_DispatchQueued(), BattleEventRuntime_Reset(), BattleEventRuntime_WaitForReady(), and BattleUnit_ProcessTurnEnd().

◆ BattleEventRuntime_WaitForReady()

s32 BattleEventRuntime_WaitForReady ( void )

Waits, a frame at a time, until BattleEvent_Playback has played every target, then removes the callback and resets the events.

Called after the effect by the staging runners in staging.c, and after a Djinn's effect by BattleCommand_BuildPlan and turn_end.c. Playback still idle (the effect never called EFFECT_SHOW_DAMAGE) is started here.

Definition at line 458 of file playback.c.

Referenced by Battle_ProcessRoundEnd(), BattleCommand_BuildPlan(), BattleEventRuntime_WaitForReady(), BattlePres_RunAttack(), BattlePres_RunItem(), BattlePres_RunPsynergyCast(), BattlePresentation_RunUnitTransition(), and BattleUnit_ProcessTurnEnd().

◆ BattleParty_IsUnitListed()

u32 BattleParty_IsUnitListed ( u32 unitId)

Returns one when the unit is in its side's formation.

Called by BattleCommand_BuildPlan, for the owners of the standby Djinn a summon uses. unitId : 0 to 7 a party member, any other an enemy

Definition at line 11 of file plan.c.

Referenced by BattleCommand_BuildPlan(), and BattleParty_IsUnitListed().

◆ BattleParty_CountStandbyDjinn()

s32 BattleParty_CountStandbyDjinn ( u32 unitId,
u8 * counts )

Counts the standby Djinn whose owners fight on unitId's side, from that side's Djinn recovery list.

Called by BattleCommand_BuildPlan for a summon, and through BattleParty_CountStandbyDjinnFar by the command menu (Menu_RunCommandRow, Battle_CollectPartyCommands, PartyStatusDraw). unitId : 0 to 7 the party's side, any other the enemies' counts : if not null, receives the count for each of the four elements

Definition at line 37 of file plan.c.

Referenced by BattleCommand_BuildPlan(), and BattleParty_CountStandbyDjinn().

◆ BattleCommand_BuildPlan()

s32 BattleCommand_BuildPlan ( struct BattleActionRecord * request,
struct BattlePlan * plan )

Announces the action and plans its targets and effects.

Returns zero to execute, -1 on failure (already reported), or -2 for no action. Called by BattlePresentation_DispatchAction for each action of the round. Fills plan (its actor, targets, hit and critical rolls, ability, element, outcome, presentation flags and failure), resets the battle events and shows the announcing message. The command's costs are paid here: a caster's PP, a Djinni set or put on standby (with its own effect), the standby Djinn a summon uses (turns -2). A unit that cannot act, or finds no target, may be set to guard (guardLevel).

The phases: the debug defeat; what stops the actor; the announcement and the ability id, by command; the rolls of a plain attack, or an ability's extra blows, critical hit or advance hit roll; then how it is staged.

Fills the plan's targets: the aimed unit, or for a range the places within range - 1 of the aimed place on its side, standing units only unless the ability revives. With none, the actor defends ("defends") and it returns -1. Called by BattleCommand_BuildPlan once the command gives its ability id.

Definition at line 108 of file plan.c.

Referenced by BattleCommand_BuildPlan(), and BattlePresentation_DispatchAction().

◆ 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_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().

◆ 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().

◆ BattlePres_RunMosaicFadeOut()

s32 BattlePres_RunMosaicFadeOut ( void )

Fades the screen to black over sixteen frames as every background's mosaic grows, then shows no layer.

Reached only through its entry in the battle bank's far-call table (FarCall_BattleTable), which no code in TBS names. Sets REG_BLDCNT to darken the backgrounds, leaves REG_MOSAIC at its largest and REG_DISPCNT in mode 1 with every layer off; the four BGxCNT are put back as they were. It draws four random numbers a frame, which only advances the sequence.

Definition at line 22 of file transition.c.

Referenced by BattlePres_RunMosaicFadeOut().

◆ Graphics_BuildSequentialTileTable()

void Graphics_BuildSequentialTileTable ( void * tilemap)

Builds the perspective plane's 32 by 32 affine map: tiles 0 to 255 in its first eight rows, 0 to 223 in the next seven, and 0xff in the rest.

The two runs show the background picture's two halves, which the scanline BG2CNT values (BattleCamera_SetRange) read from character blocks 2 and 3. Called with screen block 7 by BattleBackground_Load and BattlePresentation_ConfigurePaletteFade.

Definition at line 75 of file transition.c.

Referenced by BattleBackground_Load(), BattlePresentation_ConfigurePaletteFade(), and Graphics_BuildSequentialTileTable().

◆ BattlePresentation_BuildTilemap()

void BattlePresentation_BuildTilemap ( void * tilemap)

Builds BG1's flat map of the same picture: rows 0 to 3 0xffff, rows 4 and 5 tile 0x3ff, rows 6 to 20 tiles 0x200 to 0x3df in order, then tile 0x3ff.

In 256 colours from character block 0, tile 0x200 is the start of block 2, where BattleBackground_Load decodes the picture. Called with screen block 31 (BATTLE_BG1CNT) by BattleBackground_Load and BattlePresentation_ConfigurePaletteFade.

Definition at line 106 of file transition.c.

Referenced by BattleBackground_Load(), BattlePresentation_BuildTilemap(), and BattlePresentation_ConfigurePaletteFade().

◆ BattlePres_UpdateHBlankScroll()

void BattlePres_UpdateHBlankScroll ( void )

Shows the perspective plane's finished page each frame while the background is in mode 2: its first line's BG2CNT now, the rest by HBlank DMA 0, and its affine parameters into BG2PA to BG2Y.

Runs each frame as a scheduler callback, added by BattleBackground_Load and BattlePresentation_ConfigurePaletteFade; BattleCamera_SetRange builds the pages.

Definition at line 132 of file transition.c.

Referenced by BattleBackground_Load(), BattlePres_UpdateHBlankScroll(), and BattlePresentation_ConfigurePaletteFade().

◆ BattlePresentation_UploadTileVariant()

void BattlePresentation_UploadTileVariant ( void )

Copies one of eight curtain tiles from gBattlePres_TileVariants into CURTAIN_TILE(0), a new one every four frames while the transition timer (gDisp) runs from 1 to 32.

XXX: no code in TBS names it; a scheduler or table entry that reaches it would show which transition used it.

Definition at line 153 of file transition.c.

Referenced by BattlePresentation_UploadTileVariant().

◆ BattlePres_AdvanceTransitionTimer()

void BattlePres_AdvanceTransitionTimer ( void )

Advances the curtain opening by a frame: scrolls BG0 from 32 pixels to 0 over frames 20 to 52, and over frames 0 to 80 turns the camera round to YAW_PARTY_TURN and zooms it from 180 to 100 percent.

Runs each frame as a scheduler callback added by BattlePres_RunEntryTransition, which removes it once the encounter is announced. Advances the timer in gDisp's slot (heap slot 42), and writes gBgScroll[0].y and the camera's yaw.

Definition at line 167 of file transition.c.

Referenced by BattlePres_AdvanceTransitionTimer(), and BattlePres_RunEntryTransition().

◆ BattlePres_DrawTransitionRows()

void BattlePres_DrawTransitionRows ( void )

Draws a frame of the curtain opening on BG1: over 80 frames a row moves up from row 13 to row 4 and its vertically flipped twin down to row 20, the row's tile stepping through CURTAIN_TILE(1) to (8), the last one clear.

Runs each frame as a scheduler callback added by BattlePres_RunEntryTransition, reading the frame from gDisp's timer; writes BG1's map in screen block 12.

Definition at line 202 of file transition.c.

Referenced by BattlePres_DrawTransitionRows(), and BattlePres_RunEntryTransition().

◆ Graphics_ClearBg0Vofs()

void Graphics_ClearBg0Vofs ( void )

Clears REG_BG0VOFS, so that BG0's scroll applies only above the line the interrupt fires on.

Installed by BattlePres_RunEntryTransition as the VCount interrupt's handler at line 32, while gBgScroll[0].y holds BG0 scrolled.

Definition at line 252 of file transition.c.

Referenced by BattlePres_RunEntryTransition(), and Graphics_ClearBg0Vofs().

◆ BattlePres_RunEntryTransition()

void BattlePres_RunEntryTransition ( s32 enemyCount,
s32 encounterId )

Opens a battle: the curtain opening, or for the Fusion Dragon the storm on the Venus Lighthouse aerie; then announces the enemies and leaves the battle's display set.

Called once by Battle_RunEncounter with the enemy count and formation. Uses heap slot 42 for the opening's frame timer and frees it; leaves BG1 on BATTLE_BG1CNT, BG0's priority lowered by 2 again, REG_DISPCNT showing BG0, BG2 and the sprites, and no VCount handler. The storm also sets BattleWork.background to the aerie's storm backdrop.

Definition at line 272 of file transition.c.

Referenced by Battle_RunEncounter(), and BattlePres_RunEntryTransition().

◆ BattlePresentation_SetPaletteLevel()

void BattlePresentation_SetPaletteLevel ( s32 unused,
s32 level )

Copies the background's saved palette to BG palettes 6 to 13, darkened by level (0 for none).

Called by BattlePres_RestorePalette with 0, and by effects that dim the background (beams.c, canvas.c). Sets BattleWork.brightness when it darkens; interrupts are off while it writes, as IME_DISABLE turns them off by storing REG_IME's own address, whose bit 0 is clear.

Definition at line 42 of file background.c.

Referenced by BattlePres_RestorePalette(), and BattlePresentation_SetPaletteLevel().

◆ BattlePresentation_ConfigurePaletteFade()

void BattlePresentation_ConfigurePaletteFade ( s32 mode,
s32 unusedResource,
s32 fade )

Switches the background's display mode, optionally sets its palette, and rebuilds both its maps.

fade 0x80 restores the saved palette, another nonzero fade takes that much from each colour channel, and 0 leaves the palette alone; mode 1 queues BATTLE_BG1CNT for BG1. Called with mode 1 by BattleFx_PlayUnitElementEffect and the effects' canvas layers (canvas.c), and with mode 2 by BattlePresentation_DispatchAction and Battle_ProcessRoundEnd. Sets BattleBackgroundView.mode, adds BattlePres_UpdateHBlankScroll when the mode was 0, and copies the first sprite palette to BG palette 5. unusedResource is not read.

Definition at line 85 of file background.c.

Referenced by Battle_ProcessRoundEnd(), BattleFx_PlayUnitElementEffect(), BattlePresentation_ConfigurePaletteFade(), and BattlePresentation_DispatchAction().

◆ BattlePresentation_InitializeWorkAndResetState()

void BattlePresentation_InitializeWorkAndResetState ( void )

Allocates the perspective plane's scanline work (heap slot 10) cleared, and sets the background's mode to 0, so the next load adds its scanline callback.

Called once by Battle_RunEncounter before BattleBackground_Load.

Definition at line 145 of file background.c.

Referenced by Battle_RunEncounter(), and BattlePresentation_InitializeWorkAndResetState().

◆ Runtime_ReleaseHeapBlock10()

void Runtime_ReleaseHeapBlock10 ( void )

Frees the perspective plane's scanline work (heap slot 10); called by Battle_RunEncounter as the battle ends.

Definition at line 156 of file background.c.

Referenced by Battle_RunEncounter(), and Runtime_ReleaseHeapBlock10().

◆ BattleBackground_Load()

void BattleBackground_Load ( s32 mode,
s32 resourceId,
s32 level )

Loads a battle background: its picture into character blocks 2 and 3, its palette into BattleWork.palette and, darkened by level, BG palettes 6 to 13, and both its maps.

A negative level leaves the BG palettes alone. The resource is 256 bytes of palette and then the packed picture, which the RAM copy of BitDecoder_DecodeImage (heap slot 49) unpacks. Called with mode 1 by Battle_RunEncounter as the battle opens, and by the Atalanta and Boreas effects for their violet sky. Sets BattleBackgroundView.mode, and adds BattlePres_UpdateHBlankScroll when the mode was 0.

Definition at line 170 of file background.c.

Referenced by Battle_RunEncounter(), and BattleBackground_Load().

◆ BattleCamera_SetRange()

void BattleCamera_SetRange ( s32 centerX,
s32 centerY,
s32 offsetX,
s32 offsetY,
s32 scale )

Builds the perspective plane's next page for a zoom of scale about centerX and centerY (all 16.16), shifted by offsetX and offsetY (8.8 pixels), and shows it.

The page holds the affine parameters and each line's BG2CNT: which half of the picture a line shows, or none. At a zoom of 1 or more the plane wraps and turns sideways with the camera's yaw. While the background is in mode 1 (or secondMode is) and not busy, it also sets BG1's horizontal scroll. Called by BattlePres_SetupTransitionScene, by BattlePresentation_UpdateCamera and the shoulder-key camera (DEFINE_ADJUST_CAMERA) while BattlePresentationTransition.flag is 0, by Battle_RunEncounter and by Camera_ConfigureScene. Does nothing before heap slot 10 is allocated, and builds no page unless the mode is 2.

Definition at line 224 of file background.c.

Referenced by Battle_RunEncounter(), BattleCamera_SetRange(), BattlePres_SetupTransitionScene(), BattlePres_SetupTransitionSceneAtDepth(), BattlePresentation_UpdateCamera(), and Camera_ConfigureScene().

◆ BattlePres_SetupTransitionSceneAtDepth()

void BattlePres_SetupTransitionSceneAtDepth ( s32 x,
s32 depth,
s32 y )

Sets the camera's eye at its stored distance without taking a zoom; nothing in the source calls it.

The original zoom is an uninitialized local; UBFIX makes it an explicit percentage argument, as in BattlePres_SetupTransitionScene.

Definition at line 301 of file background.c.

Referenced by BattlePres_SetupTransitionSceneAtDepth().

◆ BattlePres_SetupTransitionScene()

void BattlePres_SetupTransitionScene ( s32 x,
s32 depth,
s32 y,
s32 zoom )

Points the battle camera at (x, depth, y) with a zoom in percent, and lines the perspective plane up with it.

The camera's eye is set 510 pixels from the focus along its yaw and pitch; where the battlefield's origin then projects decides the plane's offset (BattleCamera_SetRange), and the projection's focal length and depth range are then scaled by the zoom. Called by the battle's staging (BattlePres_RunEntryTransition, Battle_RunEncounter, staging.c, auto_battle.c), BattlePres_SetupTransitionAtPairMidpoint and several effects. Writes the camera's pos and eye, gProjection, and the plane's next page.

Definition at line 359 of file background.c.

Referenced by Battle_RunEncounter(), BattlePres_AdvanceTransitionTimer(), BattlePres_RunAttack(), BattlePres_RunEntryTransition(), BattlePres_SetupTransitionAtPairMidpoint(), BattlePres_SetupTransitionScene(), BattlePresentation_RunPairedUnitTransition(), and BattlePresentation_RunUnitTransition().

◆ BattlePres_SetupTransitionAtPairMidpoint()

void BattlePres_SetupTransitionAtPairMidpoint ( s32 firstUnitId,
s32 secondUnitId,
s32 zoom )

Points the battle camera, through BattlePres_SetupTransitionScene, at the ground between two units' battle objects, with a zoom in percent.

Called by the staging of a paired action (staging.c) and by the beam effects (beams.c).

Definition at line 406 of file background.c.

Referenced by BattlePres_RunAttack(), and BattlePres_SetupTransitionAtPairMidpoint().

◆ Graphics_FadeAlphaOut()

void Graphics_FadeAlphaOut ( void )

Fades BG2 out over the backdrop in eight frames, its blend weight falling by 2 a frame from 15, while the backdrop's stays 16.

Reached only through its entry in FarCall_BattleTable, which no code in TBS names. Leaves REG_BLDCNT blending BG2 over the backdrop.

Definition at line 424 of file background.c.

Referenced by Graphics_FadeAlphaOut().

◆ Graphics_FadeAlphaIn()

void Graphics_FadeAlphaIn ( void )

Fades BG2 in over the backdrop in eight frames, its blend weight rising by 2 a frame from 1, while the backdrop's stays 16.

Reached only through its entry in FarCall_BattleTable, which no code in TBS names. Leaves REG_BLDCNT blending BG2 over the backdrop.

Definition at line 438 of file background.c.

Referenced by Graphics_FadeAlphaIn().

◆ Graphics_SetBlendControl()

void Graphics_SetBlendControl ( void )

Sets REG_BLDCNT to lighten every layer by REG_BLDY; nothing calls it.

Definition at line 458 of file background.c.

Referenced by Graphics_SetBlendControl().

◆ BattlePresentation_InitializeTransitionEntries()

void BattlePresentation_InitializeTransitionEntries ( struct BattleTransitionEntry * entries)

Sets entries to the identity transform, then stores the first word's old value plus its new one in the second; nothing calls it.

XXX: what the sum is for; a caller, which TBS lacks, would show it.

Definition at line 465 of file background.c.

Referenced by BattlePresentation_InitializeTransitionEntries().

◆ BattlePres_DivideBy16()

s32 BattlePres_DivideBy16 ( s32 value)

Nothing calls it.

Definition at line 475 of file background.c.

Referenced by BattlePres_DivideBy16().

◆ Runtime_AdjustDebugValueWithButtons()

s32 Runtime_AdjustDebugValueWithButtons ( s32 selectedValue)

A debug aid: while Start is held, edits BattleWork.debugValue with the d-pad (1 left and right, 100 up and down) until A takes it as the result; with Select held, returns DEBUG_SELECT_VALUE instead.

Nothing in TBS calls it; it returns selectedValue unchanged otherwise.

Definition at line 481 of file background.c.

Referenced by Runtime_AdjustDebugValueWithButtons().

◆ BattlePres_SetActorRecordMode()

void BattlePres_SetActorRecordMode ( s32 actorId,
s32 mode )

Sets the OBJ mode (1 semi-transparent, 0 normal) of every sprite of a unit's battle object, the picture and its shadow.

Does nothing for a unit with no battle object or motion object. Called by BattlePres_SetActorModes and its helpers here, by the opening's storm (BattlePres_RunEntryTransition), by the staging (staging.c) and by auto battle (auto_battle.c).

Definition at line 515 of file background.c.

Referenced by BattlePres_ClearAllActorRecordModes(), BattlePres_RunEntryTransition(), BattlePres_SetActorModes(), BattlePres_SetActorRecordMode(), BattlePres_SetOtherActorRecordModes(), BattlePresentation_RunPairedUnitTransition(), and BattlePresentation_RunUnitTransition().

◆ BattlePres_SetOtherActorRecordModes()

void BattlePres_SetOtherActorRecordModes ( s32 selectedUnitId)

Makes every unit's sprites semi-transparent but selectedUnitId's, which are left as they are; nothing calls it.

Definition at line 552 of file background.c.

Referenced by BattlePres_SetOtherActorRecordModes().

◆ BattlePres_ClearAllActorRecordModes()

void BattlePres_ClearAllActorRecordModes ( void )

Returns every unit's sprites to OBJ mode 0; called by BattlePres_SetActorModes when the highlight stops.

Definition at line 565 of file background.c.

Referenced by BattlePres_ClearAllActorRecordModes(), and BattlePres_SetActorModes().

◆ Graphics_AdvancePaletteCycle()

void Graphics_AdvancePaletteCycle ( void )

Lightens the opaque sprites, the highlighted units, by the next step of gBattleFx_HighlightBlendRamp.

The ramp's first sixteen steps play once, then its second sixteen over and over. Runs each frame as a scheduler callback added by BattlePres_SetActorModes while BattleWork.highlightMode is set; writes REG_BLDCNT, REG_BLDALPHA, REG_BLDY and BattleWork.highlightStep.

Definition at line 580 of file background.c.

Referenced by BattlePres_SetActorModes(), and Graphics_AdvancePaletteCycle().

◆ BattlePres_SetActorModes()

void BattlePres_SetActorModes ( u16 * selectedUnits,
s32 mode )

Highlights the units in selectedUnits, a list ended by BATTLE_UNIT_LIST_END, or with mode 0 stops the highlight.

With an odd mode every other unit's sprites turn semi-transparent and the selected units' stay opaque, so only they take the pulsing lightening of Graphics_AdvancePaletteCycle. Called with the acting unit by BattlePresentation_DispatchAction, with the targets being chosen by the command menu (party_commands.c, targets.c, selection.c), and with 0 when either is done. Sets BattleWork.highlightMode and highlightStep, and adds or removes the callback.

Definition at line 609 of file background.c.

Referenced by BattleCommand_BuildPlan(), BattlePres_RunActorEntries(), BattlePres_RunAttack(), BattlePres_RunEscape(), BattlePres_RunItem(), BattlePres_RunPlainAttack(), BattlePres_RunPsynergyCast(), BattlePres_SetActorModes(), BattlePresentation_DispatchAction(), and BattlePresentation_RunUnitTransition().

◆ BattleFx_UpdateStarField()

s32 BattleFx_UpdateStarField ( void )

Definition at line 48 of file star_field.c.

Referenced by BattleFx_UpdateStarField().

◆ BattleFx_UploadStarField()

u32 BattleFx_UploadStarField ( void )

Definition at line 168 of file star_field.c.

Referenced by BattleFx_UploadStarField().

◆ BattleFx_InitializeStarField()

s32 BattleFx_InitializeStarField ( s32 mode)

Starts a star field of the element mode (0 to 3, enum Element order): sixteen sparks on random rings and three rings 120 degrees apart.

Allocates the field's work (HEAP_SLOT_BATTLE_EFFECT) and a cleared 128 by 128 canvas (HEAP_SLOT_BATTLE_CANVAS), decodes the blue ring sheet into the work, loads the element's 64 colours over the first of BG palette RAM, sets BG2's affine parameters to no zoom, loads both blitters and adds BattleFx_UpdateStarField and BattleFx_UploadStarField. Also sets BattleBackgroundView.mode to 1. Called by BattleFx_PlayUnitElementEffect; Graphics_ResetVramBlockAndReleaseHeapBlocks undoes it.

Definition at line 198 of file star_field.c.

Referenced by BattleFx_InitializeStarField(), and BattleFx_PlayUnitElementEffect().

◆ Graphics_ResetVramBlockAndReleaseHeapBlocks()

s32 Graphics_ResetVramBlockAndReleaseHeapBlocks ( s32 unused)

Ends a star field: clears BG2's tiles in character block 1, frees its blitters, canvas and work, turns BG2 off and removes both callbacks.

Called by BattleFx_PlayUnitElementEffect once the field has played.

Definition at line 297 of file star_field.c.

Referenced by BattleFx_PlayUnitElementEffect(), and Graphics_ResetVramBlockAndReleaseHeapBlocks().

◆ Graphics_ScaleRgb555Clamped()

s32 Graphics_ScaleRgb555Clamped ( u16 * source,
u16 * destination,
s32 scale,
s32 count )

Copies count colours from source to destination, each channel scaled by scale (16.16, at most 1), and returns 0.

Called to darken the background's palette by BattlePresentation_SetPaletteLevel, BattleBackground_Load, BattleFx_PlayUnitElementEffect, the item staging (staging.c) and the effects' canvas (canvas.c).

Definition at line 315 of file star_field.c.

Referenced by BattleBackground_Load(), BattleFx_PlayUnitElementEffect(), BattlePres_RunItem(), BattlePresentation_SetPaletteLevel(), and Graphics_ScaleRgb555Clamped().

◆ BattlePres_RestorePalette()

void BattlePres_RestorePalette ( void )

Copies the background's saved palette back undarkened, as the star field of BattleFx_PlayUnitElementEffect leaves it dark.

Called by BattlePresentation_RunUnitTransition and BattlePres_RunPsynergyCast once the effect has played.

Definition at line 469 of file star_field.c.

Referenced by BattlePres_RestorePalette(), BattlePres_RunPsynergyCast(), and BattlePresentation_RunUnitTransition().

◆ Runtime_RemoveIrqHandlerSlot2()

void Runtime_RemoveIrqHandlerSlot2 ( void )

Removes the VCount interrupt's handler, as BattlePres_RunEntryTransition installs one; nothing calls it.

Definition at line 475 of file star_field.c.

Referenced by Runtime_RemoveIrqHandlerSlot2().

◆ BattleFormation_AverageLevel()

s32 BattleFormation_AverageLevel ( s32 recordId)

Returns a formation's average enemy level, for the monster battles to choose by.

Returns -1 for a formation with no required member, -2 when it holds an enemy above level 3 the party has not defeated (ENEMY_DEFEATED_FLAG, unless flag 0x174 is set), and -3 when it has no member. Called by BattleFormation_SelectLevelMatchedCandidate for every formation.

Definition at line 24 of file formation.c.

Referenced by BattleFormation_AverageLevel(), and BattleFormation_SelectLevelMatchedCandidate().

◆ BattleFormation_SelectLevelMatchedCandidate()

s32 BattleFormation_SelectLevelMatchedCandidate ( s32 * outMargin)

Chooses a monster battle's formation for the party's level, and returns it with the levels its enemies must gain in outMargin.

The target is the active members' average level plus the monster battles won in a row (FLAG_MONSTER_BATTLE_WINS), between 1 and 99; a formation qualifies when its average level is at most 3 above it, and one of up to 32 qualifying is chosen at random. With none, it returns formation 1 and a margin of 0. Called by BattleFormation_BuildEnemyList under FLAG_MONSTER_BATTLE; clears the defeated flags of the classes in gBattleFormation_LevelMatchedEnemies, excluding them unless flag 0x174 bypasses the defeated-enemy check.

Definition at line 102 of file formation.c.

Referenced by BattleFormation_BuildEnemyList(), and BattleFormation_SelectLevelMatchedCandidate().

◆ BattleEnemy_AdjustLevel()

s32 BattleEnemy_AdjustLevel ( s32 owner,
s32 levels )

Raises an enemy by levels, or lowers it for a negative count: each base stat changes by a fixed amount a level, kept between 70 percent of what it was and its cap.

A level is worth 9.7 HP, 1.5 PP, 12.3 Attack, 3.3 Defense, 5.1 Agility and 15 power in each element; HP and PP are capped at 9999, the other stats at 999 and power at 200. Changes the unit's base stats and level and works out its stats again (UnitCalc). Called by BattleFormation_BuildEnemyList for each enemy of a monster battle.

Definition at line 202 of file formation.c.

Referenced by BattleEnemy_AdjustLevel(), and BattleFormation_BuildEnemyList().

◆ BattleEnemy_ClaimNameLetter()

s32 BattleEnemy_ClaimNameLetter ( s32 classId,
s32 unused )

Gives an enemy of the class its name letter, which tells it from others of its kind, and returns the letter's number for BattleUnitSetFar.

The letters are digits from 1 abroad and the alphabet in Japanese. The class's first enemy gets ENEMY_NAME_SUFFIX_COUNT, which BattleUnitSetFar takes as no letter. Its second gets letter 1 with bit 15 (0x8001), telling the caller to give the first letter 0 (BattleEnemy_LetterFirstOfClass); later ones take the next free letter, wrapping. Returns -1 when five classes are already listed. Called by BattleFormation_BuildEnemyList for each enemy and by BattleTargetExec for an enemy called into the battle. Changes BattleWork's enemyClasses, summonChannels, summonMasks and summonCount.

Definition at line 269 of file formation.c.

Referenced by BattleEnemy_ClaimNameLetter(), BattleFormation_BuildEnemyList(), and BattleTargetExec().

◆ BattleEnemy_ReleaseNameLetter()

s32 BattleEnemy_ReleaseNameLetter ( s32 actorId)

Frees a departing enemy's name letter for the next of its class, reading the letter back from the end of its name.

Does nothing for a unit that is not an enemy, a class not listed or one with no letters given. Clears the letter's bit in BattleWork.summonMasks. Called by BattleActor_RemoveFromLists.

Definition at line 320 of file formation.c.

Referenced by BattleActor_RemoveFromLists(), and BattleEnemy_ReleaseNameLetter().

◆ BattleEnemy_LetterFirstOfClass()

s32 BattleEnemy_LetterFirstOfClass ( s32 classId)

Gives the first enemy of the class on the field the first letter (0), appended to its name, once a second of its class arrives.

Called by BattleFormation_BuildEnemyList and BattleTargetExec when BattleEnemy_ClaimNameLetter returns bit 15. Writes BattleUnit.name.

Definition at line 362 of file formation.c.

Referenced by BattleEnemy_LetterFirstOfClass(), BattleFormation_BuildEnemyList(), and BattleTargetExec().

◆ BattleGroupRandom()

s32 BattleGroupRandom ( s32 recordId)

Returns the class id of a random member of the formation, among those that may appear (maximum count above 0); formation 1 stands in for an id out of range.

Called by BattleTargetExec when an enemy calls for help.

Definition at line 407 of file formation.c.

Referenced by BattleGroupRandom(), and BattleTargetExec().

◆ BattleFormation_BuildEnemyList()

s32 BattleFormation_BuildEnemyList ( s32 recordId)

Builds the battle's enemies from formation recordId and returns how many there are.

Each member comes its minimum number of times, plus a random number more up to its maximum while the six sprite slots hold them (a large enemy takes two). The formation's battle type orders them: shuffled kinds, each kind together (FORMATION_SHUFFLED), interleaved at random (FORMATION_INTERLEAVED), or in the record's order. Under FLAG_MONSTER_BATTLE the formation is chosen for the party's level instead, and each enemy raised to it. An empty or out-of-range formation becomes formation 1. Called once by Battle_RunEncounter. Fills the enemy units from FIRST_ENEMY_UNIT, with their name letters, and sets BattleWork's battleType, firstDefeated, defeatState and the name-letter lists.

Definition at line 451 of file formation.c.

Referenced by Battle_RunEncounter(), and BattleFormation_BuildEnemyList().

◆ BattleClass_GetDefeatSoundKind()

u32 BattleClass_GetDefeatSoundKind ( s32 index)

Returns the class's defeat-sound kind, 0 to 4, or -1 for none; a fallen enemy's sound is SE_146 plus it.

Called by BattleEvent_Playback as an enemy falls. Reads any index unchecked.

Definition at line 11 of file classes.c.

Referenced by BattleClass_GetDefeatSoundKind(), and BattleEvent_Playback().

◆ BattleClass_GetSprite()

s32 BattleClass_GetSprite ( s32 index)

Returns the class's battle sprite, row 0's for a class out of range.

Called by BattleObjMake and SummonSlot_RegisterActorSprites.

Definition at line 24 of file classes.c.

Referenced by BattleClass_GetSprite(), BattleObjMake(), and SummonSlot_RegisterActorSprites().

◆ BattleClass_GetPalette()

s32 BattleClass_GetPalette ( s32 index)

Returns the class's sprite palette.

For a class out of range it returns row 0's sprite, not a palette. XXX: likely a slip copied from BattleClass_GetSprite, because no other getter here returns another column for a bad index. Called by BattleObjMake and SummonSlot_RegisterActorSprites.

Definition at line 35 of file classes.c.

Referenced by BattleClass_GetPalette(), BattleObjMake(), and SummonSlot_RegisterActorSprites().

◆ BattleClass_IsSmall()

s32 BattleClass_IsSmall ( s32 index)

Returns 1 for a small class, which takes one enemy sprite slot instead of two and stands closer to its neighbours; 0 out of range.

Called by the formation and placement code (BattleFormation_BuildEnemyList, Summon_LayoutPositions) and by motion.c.

Definition at line 45 of file classes.c.

Referenced by BattleClass_IsSmall(), BattleFormation_BuildEnemyList(), BattleMotion_ProjectConditionalPosition(), BattleUnit_GetEffectHeight(), EnemyCheck(), Summon_LayoutPositions(), and SummonSlot_RegisterActorSprites().

◆ BattleClass_GetAttackEffect()

u32 BattleClass_GetAttackEffect ( u32 index)

Returns the effect a class's plain attack shows, 1 for none or out of range.

Called by BattleCommand_BuildPlan, which stages it by id range (STAGING_BY_ID_RANGE).

Definition at line 60 of file classes.c.

Referenced by BattleClass_GetAttackEffect(), and BattleCommand_BuildPlan().

◆ BattleClass_GetAttackHop()

u32 BattleClass_GetAttackHop ( u32 index)

Returns how high a class hops as it runs up to attack, in pixels; 0 out of range.

Called by BattlePres_RunAttack, which passes it to BattleMotion_ApproachTarget, and reached through FarCall_BattleTable.

Definition at line 73 of file classes.c.

Referenced by BattleClass_GetAttackHop(), and BattlePres_RunAttack().

◆ Summon_IsEntrySecondaryFlagged()

s32 Summon_IsEntrySecondaryFlagged ( s32 index)

Returns 1 for a class whose blow lands with SE_HEAVY_IMPACT instead of SE_133; 0 out of range.

Called by the beam effects (beams.c) through its far stub.

Definition at line 85 of file classes.c.

Referenced by Summon_IsEntrySecondaryFlagged().

◆ BattleClass_GetEffectHeight()

s32 BattleClass_GetEffectHeight ( s32 index)

Returns the height an effect is drawn at over a class, in pixels, or 0 for its size's default; 0 out of range.

Called by BattleUnit_GetEffectHeight, and reached through FarCall_BattleTable.

Definition at line 95 of file classes.c.

Referenced by BattleClass_GetEffectHeight(), and BattleUnit_GetEffectHeight().

◆ BattleSpoils_RankItem()

u32 BattleSpoils_RankItem ( u32 inventoryEntry)

Ranks an item among the spoils, 0 for none: an indispensable item first, then a rare item, then the higher item id.

The rank's bits: 10 ITEM_INDISPENSABLE | 9 ITEM_RARE | 8..0 the item id. Called by BattleEnemy_RecordDefeat, to keep the best four drops, and by Battle_AwardSpoils, to hand them out best first.

Definition at line 12 of file spoils.c.

Referenced by Battle_AwardSpoils(), BattleEnemy_RecordDefeat(), and BattleSpoils_RankItem().

◆ BattleSpoils_Clear()

void BattleSpoils_Clear ( void )

Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem.

Called once by Battle_RunEncounter as the battle opens.

Definition at line 33 of file spoils.c.

Referenced by Battle_RunEncounter(), and BattleSpoils_Clear().

◆ BattleEnemy_RecordDefeat()

s32 BattleEnemy_RecordDefeat ( s32 unitId,
s32 djinnBonus )

Counts a fallen enemy and adds its coins, experience and perhaps its item to the spoils.

Returns -1 for a party unit and -2 for a party member fought as an enemy, else 0. It notes the class for the victory message (firstDefeated, defeatState). In a monster battle it adds nothing more; otherwise it sets the class's ENEMY_DEFEATED_FLAG, adds the rewards (with the Djinn bonus, djinnBonus nonzero, the rolls above) and rolls the item: 1 in 2^(itemChance - 1), two powers likelier with the bonus. An item not yet among the four kept replaces the lowest ranked, if it ranks higher. Called as each enemy falls by BattleEv_DispatchQueued and BattleEvent_Playback.

Definition at line 99 of file spoils.c.

Referenced by BattleEnemy_RecordDefeat(), BattleEv_DispatchQueued(), and BattleEvent_Playback().

◆ Battle_AwardSpoils()

void Battle_AwardSpoils ( void )

Hands out the spoils after a victory: the experience to each party member still standing, with every level gained and what it brings, then the coins, then the items best first.

Each level up shows its message, every Psynergy newly learned and each stat that rose. An item the inventory cannot take goes to gOverflowItem and ends the handing out. Called by Battle_RunEncounter once the battle is won. Changes the members' experience, levels and stats, the party's coins and inventory.

Definition at line 194 of file spoils.c.

Referenced by Battle_AwardSpoils(), and Battle_RunEncounter().

◆ Battle_ReservedNoOp2A08()

void Battle_ReservedNoOp2A08 ( void )

Does nothing; the debug battle menu (DebugBattle_RunMenu) calls it.

Definition at line 326 of file spoils.c.

Referenced by Battle_ReservedNoOp2A08(), and DebugBattle_RunMenu().