Skip to Content
The Alchemy Project

src/battle/battle_staging.c

Playing one action of a turn: the staging its ability calls for (an attack, a cast, a summon over a faded field, an item, a flight), the extra strikes that Daedalus, Megaera and Iris add, and a unit's motion graphics. More…

Included by battle.c.

Macros

NameDescription
#defineBEAST_SPRITE_SLOT 7The sprite slot a called beast borrows, after the six enemy slots.
#defineBEAST_ARRIVAL_TICKS 30The ticks a called beast takes to drop in, and to rise away.
#defineBEAST_DEPARTURE_TICKS 16
#defineCRITICAL_ZOOM_START 100A critical hit's zoom on the attacker and its target, in percent: from CRITICAL_ZOOM_START, CRITICAL_ZOOM_GAIN more by the end of the run up.
#defineCRITICAL_ZOOM_GAIN 30
#defineITEM_DARKEN_TICKS 20The ticks the battle background darkens through before an item's effect, a BACKGROUND_LEVEL_STEP each: to two thirds of its brightness.

Functions

NameDescription
UNREAD_RESULTbtStagingPlanDaedalus (Uint16 *src, BATTLE_PLAN *plan)The plan of the extra action Daedalus queues for the turn's end (COMMAND_DAEDALUS): ABILITY_DAEDALUS_STRIKE from a random unit of the queuing side against every unit of the other, staged as the summon SUMMON_EFFECT_DAEDALUS_STRIKE. src is the queued BATTLE_ACTION_RECORD, read as halfwords: [0] its unit, [3] its command.
voidbtStagingPlanHighImpact (BATTLE_PLAN *plan)The plan of Megaera's second part (STAGING_MEGAERA): High Impact (ABILITY_HIGH_IMPACT) from the acting unit on every living unit of its own side.
voidbtStagingPlanAuroraField (BATTLE_PLAN *plan)The plan of Iris's second part (STAGING_IRIS): Aurora Field (ABILITY_AURORA_FIELD) over the acting unit's whole side, reserves included for the party.
voidbtPartyReturnAllToSpots (void)Sends every battler back to its spot.
Sint32btStagingDispatchAction (BATTLE_ACTION_RECORD *request, Sint32 delay)Plays one action of the turn after delay ticks: an enemy picks its ability now, the action is built and staged, and every unit returns to its spot.
voidbtStagingBuildTargetList (BATTLE_PLAN *plan, BATTLE_PRESENTATION_STATE *effect)Fills a battle effect command from an action run: its kind and strength, the user and the targets still standing, or all of them for an effect that revives.
Sint32btStagingRunFlee (BATTLE_PLAN *plan)Plays a unit's attempt to run: the party runs off one by one unless the roll failed ("But there's no escape!"); an enemy gets away 7 times in 10.
Sint32btStagingRunFullScreen (BATTLE_PLAN *plan, Sint32 mode)Plays a summon or a full-screen Psynergy: the unit glows in its element and the other side fades out while the effect plays, then everyone fades back in.
UNREAD_RESULTbtStagingRunMessages (BATTLE_PLAN *plan, Sint32 unused)Plays an action with no battle effect (STAGING_MESSAGES): each target's outcome is applied and its messages shown in turn.
voidbtObjectReset (BATTLE_OBJECT *battleObject, Sint32 keep)Resets a battle object, making its actor when it has none: nine tenths size, the anchors at the centre unless keep is set, no sprite, animation, shadow or status, turned half a turn, borrowed, then the empty script.
SAVED_BATTLE_OBJECT *btMotionCallBeast (BATTLE_PLAN *plan, BATTLE_PRESENTATION_STATE *state)The beasts called up in battle (ABILITY_WILD_WOLF to ABILITY_CALL_DULLAHAN): for a call that lands, saves the battle object it borrows and brings in the beast's enemy (ENEMY_WILD_WOLF for Wild Wolf and so on) to play the attack; returns the save, or NULL for any other ability.
voidbtMotionReleaseBuffer (SAVED_BATTLE_OBJECT *saved)Frees the borrowed buffer and releases the motion graphics slot.
voidbtMotionDismissBeast (SAVED_BATTLE_OBJECT *saved)Sends the called beast away and puts back the battle object btMotionCallBeast saved, then frees the save.
Sint32btStagingRunAttack (BATTLE_PLAN *plan, Sint32 mode)Plays an attack: the attacker runs up to its first target and the blow lands.
Sint32gmInventoryBreakStub (Sint32 owner, Sint32 slot)Marks the item in slot broken; returns -1 for an empty slot.
Sint32btStagingRunItem (BATTLE_PLAN *plan, Sint32 unused, BATTLE_ACTION_RECORD *selection)Plays an item's use: the camera turns to the user's side, the user raises the item and, for an item with a battle effect, the battle background dims to two thirds while the effect plays with its messages.
voidbtObjectSetColorMode (MOTION_OBJECT *object, Sint32 value)Draws a unit's body in colour mode value on each of its sprites (SPRITE_COLOR_WHITE for a hit's flash, its own palette to end it), and its other layers in their plain colours.
Sint32btStagingRunPsynergyCast (BATTLE_PLAN *plan, Sint32 mode)Plays Psynergy, a Djinni or an enemy's cast.
voidbtMotionFlashHit (Sint32 id, Sint32 unusedA, Sint32 unusedB)Flashes a unit as it is hit, white and back twice in its damage pose.
Sint32btObjectRemoveFromLists (Sint32 id)Takes unit id out of the battle: off the party's or the enemies' list, its name suffix freed and its actions this turn struck off.
voidbtMotionShowDowned (Sint32 id)Shows unit id downed: a party member takes POSE_PARTY_HELD; an enemy takes POSE_ENEMY_DOWN, turns grey, and four ticks later leaves the battle and dissolves pixel by pixel.

Description

Playing one action of a turn: the staging its ability calls for (an attack, a cast, a summon over a faded field, an item, a flight), the extra strikes that Daedalus, Megaera and Iris add, and a unit's motion graphics. Part of battle.c.

Macros in detail

BEAST_SPRITE_SLOT

#define BEAST_SPRITE_SLOT 7

The sprite slot a called beast borrows, after the six enemy slots.

Referenced by btMotionCallBeast() and btMotionDismissBeast().

Definition at line 650 of file battle_staging.c.

BEAST_ARRIVAL_TICKS

#define BEAST_ARRIVAL_TICKS 30

The ticks a called beast takes to drop in, and to rise away.

Referenced by btMotionCallBeast().

Definition at line 653 of file battle_staging.c.

BEAST_DEPARTURE_TICKS

#define BEAST_DEPARTURE_TICKS 16

Referenced by btMotionDismissBeast().

Definition at line 654 of file battle_staging.c.

CRITICAL_ZOOM_START

#define CRITICAL_ZOOM_START 100

A critical hit's zoom on the attacker and its target, in percent: from CRITICAL_ZOOM_START, CRITICAL_ZOOM_GAIN more by the end of the run up.

Referenced by btStagingRunAttack().

Definition at line 658 of file battle_staging.c.

CRITICAL_ZOOM_GAIN

#define CRITICAL_ZOOM_GAIN 30

Referenced by btStagingRunAttack().

Definition at line 659 of file battle_staging.c.

ITEM_DARKEN_TICKS

#define ITEM_DARKEN_TICKS 20

The ticks the battle background darkens through before an item's effect, a BACKGROUND_LEVEL_STEP each: to two thirds of its brightness.

Referenced by btStagingRunItem().

Definition at line 663 of file battle_staging.c.

Functions in detail

btStagingPlanDaedalus

UNREAD_RESULT btStagingPlanDaedalus(Uint16 *src, BATTLE_PLAN *plan)

The plan of the extra action Daedalus queues for the turn's end (COMMAND_DAEDALUS): ABILITY_DAEDALUS_STRIKE from a random unit of the queuing side against every unit of the other, staged as the summon SUMMON_EFFECT_DAEDALUS_STRIKE. src is the queued BATTLE_ACTION_RECORD, read as halfwords: [0] its unit, [3] its command.

References btAIChooseRandomTarget(), btGetUnitAtPlace(), btUnitListLivingIds() and Sint32.

Referenced by btStagingDispatchAction().

Definition at line 11 of file battle_staging.c.

btStagingPlanHighImpact

void btStagingPlanHighImpact(BATTLE_PLAN *plan)

The plan of Megaera's second part (STAGING_MEGAERA): High Impact (ABILITY_HIGH_IMPACT) from the acting unit on every living unit of its own side.

References btUnitListLivingIds() and Sint32.

Referenced by btStagingDispatchAction().

Definition at line 52 of file battle_staging.c.

btStagingPlanAuroraField

void btStagingPlanAuroraField(BATTLE_PLAN *plan)

The plan of Iris's second part (STAGING_IRIS): Aurora Field (ABILITY_AURORA_FIELD) over the acting unit's whole side, reserves included for the party.

References btPartyPrepareMembers(), btPartyPrepareReserveOwners(), btUnitListIds() and Sint32.

Referenced by btStagingDispatchAction().

Definition at line 79 of file battle_staging.c.

btPartyReturnAllToSpots

void btPartyReturnAllToSpots(void)

Sends every battler back to its spot.

References btMotionReturnToSpot(), btUnitListIds() and Sint32.

Referenced by btStagingDispatchAction().

Definition at line 110 of file battle_staging.c.

btStagingDispatchAction

Sint32 btStagingDispatchAction(BATTLE_ACTION_RECORD *request, Sint32 delay)

Plays one action of the turn after delay ticks: an enemy picks its ability now, the action is built and staged, and every unit returns to its spot. Returns 1 when the party got away, 0 otherwise, and -1 when the unit is already down.

References btActionRunBuild(), btAIChooseAction(), btBackgroundSetMode(), btDjinnRecoveryCountDownSide(), btHighlightSetModes(), btMessageWaitForAdvance(), btMotionDestroyAllSlotObjects(), btObjectPut(), btPartyReturnAllToSpots(), btPlacementRelayoutEnemies(), btStagingPlanAuroraField(), btStagingPlanDaedalus(), btStagingPlanHighImpact(), btStagingRunAttack(), btStagingRunFlee(), btStagingRunFullScreen(), btStagingRunItem(), btStagingRunMessages(), btStagingRunPsynergyCast(), btUnitGetPartyAttackEffect(), btUnitListLiving(), btUnitProcessActionEnd(), gmUnitGet(), mnBattleMessageShowAndWaitStub(), mnMessageArgumentPushStub(), result, Sint32, syDivFX(), syInitMatrix(), syLookAtLoad(), sySetScreenDist(), sySoundPlayStub() and sySynch().

Referenced by btRun().

Definition at line 124 of file battle_staging.c.

btStagingBuildTargetList

void btStagingBuildTargetList(BATTLE_PLAN *plan, BATTLE_PRESENTATION_STATE *effect)

Fills a battle effect command from an action run: its kind and strength, the user and the targets still standing, or all of them for an effect that revives.

References btUnitIsListed(), gmUnitGet() and Sint32.

Referenced by btStagingRunAttack(), btStagingRunFullScreen(), btStagingRunItem() and btStagingRunPsynergyCast().

Definition at line 324 of file battle_staging.c.

btStagingRunFlee

Sint32 btStagingRunFlee(BATTLE_PLAN *plan)

Plays a unit's attempt to run: the party runs off one by one unless the roll failed ("But there's no escape!"); an enemy gets away 7 times in 10. Returns 1 when the party got away.

References btHighlightSetModes(), btMessageWaitForAdvance(), btMotionSetupEscapeObject(), btObjectMarkForRelease(), btObjectRemoveFromLists(), btUnitListLiving(), gmUnitGet(), mnBattleMessageShowAndWaitStub(), Sint32 and sySynch().

Referenced by btStagingDispatchAction().

Definition at line 370 of file battle_staging.c.

btStagingRunFullScreen

Sint32 btStagingRunFullScreen(BATTLE_PLAN *plan, Sint32 mode)

Plays a summon or a full-screen Psynergy: the unit glows in its element and the other side fades out while the effect plays, then everyone fades back in. STAGING_HIDE_ACTOR hides the unit too, as the summons do.

References btActorGetSprite(), btActorSpawnObjectsForList(), btBackgroundRestorePalette(), btCameraSetView(), btEffectRunSummonStub(), btElementGlowPlay(), btHighlightSetModes(), btHighlightSetSpriteMode(), btObjectGet(), btObjectPut(), btPlaybackPush(), btPlaybackRun(), btPlaybackRunAll(), btPlaybackWaitForReady(), btStagingBuildTargetList(), btUnitListIds(), fdActorSelectAnimationStub(), mnPartyStatusDrawStub(), Sint32, sySetEvent(), sySoundPlayStub() and sySynch().

Referenced by btStagingDispatchAction().

Definition at line 440 of file battle_staging.c.

btStagingRunMessages

UNREAD_RESULT btStagingRunMessages(BATTLE_PLAN *plan, Sint32 unused)

Plays an action with no battle effect (STAGING_MESSAGES): each target's outcome is applied and its messages shown in turn. With no targets, it only waits for the message to advance.

References btAbilityApplyToTarget(), btHighlightSetModes(), btMessageWaitForAdvance(), btPlaybackRunAll(), Sint32 and sySynch().

Referenced by btStagingDispatchAction().

Definition at line 627 of file battle_staging.c.

btMotionCallBeast

SAVED_BATTLE_OBJECT *btMotionCallBeast(BATTLE_PLAN *plan, BATTLE_PRESENTATION_STATE *state)

The beasts called up in battle (ABILITY_WILD_WOLF to ABILITY_CALL_DULLAHAN): for a call that lands, saves the battle object it borrows and brings in the beast's enemy (ENEMY_WILD_WOLF for Wild Wolf and so on) to play the attack; returns the save, or NULL for any other ability. btMotionDismissBeast undoes it.

References ActorSpriteSlots, btHighlightSetSpriteMode(), btObjectDestroySprites(), btObjectGet(), btObjectReleaseSpriteSlots(), btObjectReset(), btObjectSpawnObjectsForList(), btSpriteGetPalette(), btSpriteGetSprite(), btUnitListIds(), fdActorSelectAnimationStub(), fdActorSetAnimationSpeedStub(), fdSpritePictureCacheLoadStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease(), syIOWriteQueueStore16(), sySoundPlayStub() and sySynch().

Referenced by btStagingRunAttack() and btStagingRunPsynergyCast().

Definition at line 670 of file battle_staging.c.

btMotionReleaseBuffer

void btMotionReleaseBuffer(SAVED_BATTLE_OBJECT *saved)

Frees the borrowed buffer and releases the motion graphics slot.

References btActorGetSprite(), btObjectGet(), fdSpriteRemoveAnimationAtStub(), fdSpriteSkipToStopStub(), syHeapRelease() and sySynch().

Referenced by btStagingRunAttack() and btStagingRunPsynergyCast().

Definition at line 838 of file battle_staging.c.

btMotionDismissBeast

void btMotionDismissBeast(SAVED_BATTLE_OBJECT *saved)

Sends the called beast away and puts back the battle object btMotionCallBeast saved, then frees the save.

References btEnemySpriteLoadIntoSlots(), btHighlightSetSpriteMode(), btMotionDestroyAllSlotObjects(), btMotionReturnToSpot(), btObjectDestroySprites(), btObjectGet(), btObjectMarkForRelease(), btObjectSpawnObjectsForList(), btUnitListIds(), fdSpritePictureCacheLoadStub(), Sint32, syIOWriteQueueStore16() and sySynch().

Referenced by btStagingRunAttack() and btStagingRunPsynergyCast().

Definition at line 859 of file battle_staging.c.

btStagingRunAttack

Sint32 btStagingRunAttack(BATTLE_PLAN *plan, Sint32 mode)

Plays an attack: the attacker runs up to its first target and the blow lands. A miss makes the target hop back ("nimbly dodges the blow"); a critical hit zooms in on the pair with only the two of them shown.

References btActorGetSprite(), btActorSpawnObjectsForList(), btCameraSetView(), btCameraSetViewAtPairMidpoint(), btHighlightSetModes(), btMotionApproachTarget(), btMotionCallBeast(), btMotionDismissBeast(), btMotionHopBack(), btMotionReleaseBuffer(), btMotionReturnToSpot(), btObjectGet(), btObjectPutKeepingPoses(), btPlaybackPush(), btPlaybackRun(), btPlaybackRunAll(), btPlaybackWaitForReady(), btSpriteGetAttackHop(), btStagingBuildTargetList(), fdActorSelectAnimationStub(), fdActorSetAnimationSpeedStub(), fdSpriteAnimationSumCommandLengthsStub(), gmUnitGet(), mnPartyStatusDrawStub(), Sint32, syAtan(), syHeapRelease(), sySetEvent() and sySynch().

Referenced by btStagingDispatchAction().

Definition at line 939 of file battle_staging.c.

gmInventoryBreakStub

Sint32 gmInventoryBreakStub(Sint32 owner, Sint32 slot)

Marks the item in slot broken; returns -1 for an empty slot.

Referenced by btStagingRunItem() and mnItemMenuTryBreak().

Definition at line 1132 of file battle_staging.c.

btStagingRunItem

Sint32 btStagingRunItem(BATTLE_PLAN *plan, Sint32 unused, BATTLE_ACTION_RECORD *selection)

Plays an item's use: the camera turns to the user's side, the user raises the item and, for an item with a battle effect, the battle background dims to two thirds while the effect plays with its messages. Then the item is spent as its use type says: used up, broken one time in eight, or the Hermes' Water left an Empty Bottle. When a used-up item empties its slot, the user's later item commands this turn (selection is this one) follow their items to their new slots, or lose theirs (-1).

References btActorGetSprite(), btColorBufferScale(), btHighlightSetModes(), btMotionReturnToSpot(), btObjectGet(), btPlaybackPush(), btPlaybackRun(), btPlaybackRunAll(), btPlaybackWaitForReady(), btStagingBuildTargetList(), fdActorSelectAnimationStub(), fdActorSetAnimationSpeedStub(), gmBattleRandomStub(), gmInventoryBreakStub(), gmInventoryRemoveStub(), gmItemGetDefinitionStub(), gmUnitGet(), result, Sint32, sySetEvent() and sySynch().

Referenced by btStagingDispatchAction().

Definition at line 1141 of file battle_staging.c.

btObjectSetColorMode

void btObjectSetColorMode(MOTION_OBJECT *object, Sint32 value)

Draws a unit's body in colour mode value on each of its sprites (SPRITE_COLOR_WHITE for a hit's flash, its own palette to end it), and its other layers in their plain colours.

References btActorGetSprite() and Sint32.

Referenced by btMotionFlashHit() and btPlaybackRun().

Definition at line 1277 of file battle_staging.c.

btStagingRunPsynergyCast

Sint32 btStagingRunPsynergyCast(BATTLE_PLAN *plan, Sint32 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 battle effect plays with its playback, and the targets return to their spots. The party status window is drawn without its PP row meanwhile. mode is a BATTLE_CAST_KIND: STAGING_CAST plays CAST_PSYNERGY, STAGING_DJINNI CAST_DJINNI and STAGING_ENEMY_CAST CAST_ENEMY.

References btActorGetSprite(), btBackgroundRestorePalette(), btElementGlowPlay(), btHighlightSetModes(), btMotionCallBeast(), btMotionDismissBeast(), btMotionReleaseBuffer(), btMotionReturnToSpot(), btObjectGet(), btPlaybackPush(), btPlaybackRun(), btPlaybackRunAll(), btPlaybackWaitForReady(), btStagingBuildTargetList(), fdActorSelectAnimationStub(), fdActorSetAnimationSpeedStub(), mnPartyStatusDrawStub(), Sint32, syAtan(), syHeapRelease(), sySetEvent() and sySoundPlayStub().

Referenced by btStagingDispatchAction().

Definition at line 1315 of file battle_staging.c.

btMotionFlashHit

void btMotionFlashHit(Sint32 id, Sint32 unusedA, Sint32 unusedB)

Flashes a unit as it is hit, white and back twice in its damage pose.

References btMotionGetSlotPalette(), btObjectGet(), btObjectSetColorMode(), fdActorSelectAnimationStub(), gmUnitGet(), mnPartyStatusDrawStub(), mnPartyStatusHighlightMembersStub(), Sint32 and sySynch().

Referenced by btPlaybackRunAll().

Definition at line 1441 of file battle_staging.c.

btObjectRemoveFromLists

Sint32 btObjectRemoveFromLists(Sint32 id)

Takes unit id out of the battle: off the party's or the enemies' list, its name suffix freed and its actions this turn struck off. Returns -1 when it is on neither list.

References btEnemyReleaseNameLetter(), gmUnitGet() and Sint32.

Referenced by btMotionShowDowned(), btPlaybackRun(), btPlaybackRunAll(), btStagingRunFlee() and btUnitRemoveEnemy().

Definition at line 1472 of file battle_staging.c.

btMotionShowDowned

void btMotionShowDowned(Sint32 id)

Shows unit id downed: a party member takes POSE_PARTY_HELD; an enemy takes POSE_ENEMY_DOWN, turns grey, and four ticks later leaves the battle and dissolves pixel by pixel.

References btActorGetSprite(), btObjectGet(), btObjectMarkForRelease(), btObjectRemoveFromLists(), fdSpriteDissolveRunManyStub(), fdSpriteStartAnimationStub(), gmUnitGet(), Sint32 and sySynch().

Referenced by btPlaybackRunAll().

Definition at line 1519 of file battle_staging.c.