59 actingUnit[0] = request->
unitId;
110 for (unitIndex = 0; unitIndex < unitCount; unitIndex++)
145 if (targetIndex < plan->targetCount) {
147 outputTarget = effect->
actors;
152 *outputTarget++ = *inputTarget;
156 }
while (targetIndex < plan->targetCount);
158 if (livingTargets == 0) {
163 effect->
count = livingTargets;
188 completed.halves[0] = 0;
189 completed.halves[1] = 0;
197 partyMode = completed.value;
211 while (index != -1) {
214 if (unit->
stun == 0 && unit->
sleep == 0) {
223 }
else if (((
Random16() * 10) >> 16) <= 6) {
239 return completed.value;
308 for (i = 0; i != count; i++) {
311 if (units[i] != actor) {
312 if ((target <= 7) != (units[i] <= 7))
323 for (i = 0; i != 16; i++) {
341 for (i = 0; i < count; i++) {
345 units[kept++] = actor;
346 }
else if ((target <= 7) == (unit <= 7)) {
347 units[kept++] = unit;
367 for (child = 0; child != animation->
count - 1; child++)
402 for (i = 0; i !=
count; i++) {
405 if ((target <= 7) != (units[i] <= 7))
408 for (i = 0; i != 16; i++) {
412 for (i = 0; i !=
count; i++)
436 for (targetIndex = 0; targetIndex < plan->
targetCount; targetIndex++) {
492 adjusted = angle - 0x2000;
494 adjusted = angle + 0x6000;
496 facingAngle = (adjusted - 0x2000) / 2 + 0x2000;
498 if (transition->
targetYaw == facingAngle) {
564 transition->
flag = 1;
580 for (index = 0; index != frames; index++) {
581 if (zoomOnCritical != 0) {
585 index * 30 / frames + 100);
601 transition->
flag = 0;
637 adjusted = angle - 0x2000;
639 adjusted = angle + 0x6000;
641 facingAngle = (adjusted - 0x2000) / 2 + 0x2000;
643 if (transition->
targetYaw == facingAngle) {
688#define ITEM_REMOVED_SLOT_GONE 2
704 s32 targetOrFadeIndex;
732 for (targetOrFadeIndex = 0; targetOrFadeIndex != work.
effect.
count;
733 targetOrFadeIndex++) {
738 for (entryIndex = 0; entryIndex != animation->
count - 1; entryIndex++)
750 targetOrFadeIndex = 0;
755 if (targetOrFadeIndex < 20) {
757 s32 value = 0x10000 - fade;
766 }
while (targetOrFadeIndex < 20);
776 for (targetOrFadeIndex = 0; targetOrFadeIndex != work.
effect.
count;
842 u8 lastFrameMask = 0xff;
846 children = &record->
entries[1];
848 previousFrame = child->
frame;
849 child->
frame = previousFrame | lastFrameMask;
850 entryCount = record->
count;
851 child->
param = colorMode;
852 for (childIndex = 1; childIndex < entryCount; childIndex++) {
893 targetYaw =
angle - 0x1800;
895 targetYaw =
angle + 0x1800;
896 targetYaw = (
s16)targetYaw;
901 targetYaw = plan->
actorId <= 7 ? 0x2400 : -0x2400;
933 for (targetIndex = 0; targetIndex != work.
effect.
count; targetIndex++) {
938 for (entryIndex = 0; entryIndex != animation->
count - 1; entryIndex++)
966 for (targetIndex = 0; targetIndex != work.
effect.
count; targetIndex++)
982 s32 flashesRemaining;
987 selected = selection;
988 flashesRemaining = 1;
991 selected[1] = listTerminator;
992 selected[0] = unitId;
998 selected[0] = unitId;
1004 }
while (flashesRemaining >= 0);
1022 u32 enemyOrActionIndex;
1028 for (partyIndex = 0;; partyIndex++) {
1029 if (battle->
partyUnits[partyIndex] == unitId) {
1043 enemyOrActionIndex = 0;
1045 listedUnit = battle->
enemyIds[enemyOrActionIndex];
1046 if (listedUnit == unitId) {
1050 enemyOrActionIndex++;
1060 enemyOrActionIndex++) {
1082 recordCount)) != 0) {
1093 recordCount)) != 0) {
1095 records[recordCount] = record;
1097 entry->
frame = 0xff;
@ SPRITE_COLOR_WHITE
solid colour 15, white
@ SPRITE_COLOR_GREY
greyscale
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,...
void BattlePres_SetupTransitionAtPairMidpoint(s32 firstUnitId, s32 secondUnitId, s32 zoom)
Points the battle camera, through BattlePres_SetupTransitionScene, at the ground between two units' b...
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 ...
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 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...
u32 BattleClass_GetAttackHop(u32 index)
Returns how high a class hops as it runs up to attack, in pixels; 0 out of range.
s32 BattleParty_ListLivingUnits(s32 sideMask, u16 *unitIds)
Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY,...
s32 BattleParty_ListActorIds(s32 sideMask, u16 *unitIds)
Lists the units in the battle's unit lists on the sides in sideMask, party first, skipping those remo...
u32 BattleEvPush(u32 opcode, u32 operand)
Queues one battle event (enum BattleEventOpcode) with its operand, and returns the opcode.
u32 BattleEv_DispatchQueued(void)
Plays the queued battle events at once, in order (BattleEvent_Playback plays them over frames instead...
s32 BattlePresentation_WaitForAdvance(void)
Shows the bobbing arrow at the message window and waits for the player to go on (B,...
void BattleActor_SpawnObjectsForList(s16 *unitIds, s32 refreshPoses)
Readies the sprites of the units in list: releases those of every place list lacks,...
struct BattleObj * BattleObjGet(s32 unitId)
Returns unitId's battle object, through its place, or null for a unit with no place.
s32 BattleObj_MarkForRelease(s32 unitId)
Frees the enemy sprite slots unitId holds and marks its object for release at the end of the round (B...
void * BattleMotion_DestroyAllSlotObjects(void)
Releases the object of every unit marked by BattleObj_MarkForRelease, leaving its battle object with ...
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 sp...
void BattleObjPut(void)
Readies the sprite of every unit in the battle (releasing those of units that left) and sets each one...
void BattleParty_ListAllUnitsAndSubmit(void)
Readies the sprite of every unit in the battle (releasing those of units that left),...
s32 BattleMotion_GetSlotPalette(s32 id)
Returns the palette of unit id's battle object.
@ POSE_PARTY_HELD
asleep, stunned or held; also a downed member
@ POSE_ENEMY_DOWN
a downed enemy stays in its damage pose
@ POSE_DAMAGE
taking damage
struct BattlePresentationTransition * gTransitionWork
@ BATTLE_EVENT_UNIT_NAME
a unit's name for the next message
@ BATTLE_EVENT_MESSAGE
a message, waiting for the player
@ BATTLE_EVENT_ITEM_NAME
an item's name for the next message
What every part of the battle object shares: its includes, in their original order,...
#define STAGING_ON_DOWNED
shown on downed targets too (revivals)
#define ITEM_USE_CONSUMED
one is used up
#define STAGING_VARIANT_SHIFT
#define STAGING_BY_ID_RANGE
BattleFx_DispatchByIdRangeFar.
#define STAGING_KIND_MASK
#define STAGING_VARIANT_MASK
#define ITEM_USE_EMPTIES
Hermes' Water leaves an Empty Bottle.
#define STAGING_VIEW_REVERSED
#define BLEND_SPRITES_OVER_ALL
REG_BLDCNT: blend the semi-transparent sprites (OBJ mode 1) over every layer, to fade them.
#define STAGING_VIEW_ACROSS
More of BattlePlan.presentationFlags: the camera takes the other side's view (an enemy's cast a view ...
#define BATTLE_WININ
The battle's windows: window 0 shows BG0 to BG2, sprites and blending, window 1 BG0,...
@ PLAN_SHOW_ATTACK
the actor runs up and strikes
@ PLAN_SHOW_CAST
Psynergy, and Venus, Mercury, Mars, Jupiter.
@ PLAN_SHOW_ENEMY_CAST
an enemy's Psynergy
@ PLAN_SHOW_FLEE
a unit runs
@ PLAN_SHOW_DJINNI
a Djinni with no attack (Granite, Quartz...)
@ PLAN_SHOW_FULL_SCREEN
Gaia, Rockfall, Procne and their kin.
@ PLAN_SHOW_MESSAGES
no animation: each target's events only
@ PLAN_SHOW_SUMMON
the larger summons, the actor hidden
#define ITEM_USE_MAY_BREAK
breaks one time in eight
#define STAGING_SCENE
BattleFx_RunSceneEffectFar, actor's view.
#define YAW_PARTY_TURN
The camera's yaw while a party member acts, and while an enemy does.
#define STAGING_OTHER_SIDE
played from the other side
@ BATTLE_ENCOUNTER_ENEMIES_FIRST
@ BATTLE_UNIT_LIST_END
ends the list
@ BATTLE_UNIT_REMOVED
a place whose unit has left the battle
struct BattleWork * gBattleWork
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 definitio...
void BattleFx_RunTableEffectFar(struct BattleEffectArgument *effect)
void BattleFx_RunSceneEffectFar(struct BattleEffectArgument *effect)
void BattleFx_DispatchByIdRangeFar(struct BattleEffectArgument *effect)
void Map_RenderAllAnimatedTileFramesFar(u8 **table, s32 cnt)
s32 AnimationObjects_SelectAnimationFar(struct AnimationObject *state, s32 flags)
s32 ResourceMetadata_SumCommandLengthsFar(s32 id, u32 no, s32 cnt)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_SetAnimationSpeedFar(struct DispatchObject *obj, s32 val)
struct BattleUnit * UnitGetFar(u32 owner)
struct ItemDefinition * Item_GetDirectFar(s32 item)
s32 Inventory_RemoveFar(s32 owner, s32 slot)
s32 Inventory_BreakFar(s32 owner, s32 slot)
s32 BattleRandomFar(void)
void AudioCommand_PlayFar(s32 id)
s32 BattleLayout_HighlightPartyPanelsFar(u16 *ids)
void PartyStatusDrawFar(s32 flags)
void UiText_ShowMessageAndWaitCoreFar(s32 argument)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
@ HEAP_SLOT_BATTLE_BACKGROUND
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
#define WIN_RANGE(start, end)
A REG_WINxH or REG_WINxV value: the window covers start up to, but not including, end.
static s32 Iwram_RatioMulQ14(s32 divisor, s32 value)
All calls go through this layer.
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
s32 ArcTan2(s32 x, s32 y)
Returns the angle of the vector (x, y), in 1/65536 turns, measured from the y axis: 0 along +y,...
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,...
void BattleMotion_ResetObjectAtScaledAnchor(s32 unitId)
Sends unitId hopping out to one and a half times its spot's distance from the 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,...
s32 BattleCommand_BuildPlan(struct BattleActionRecord *request, struct BattlePlan *plan)
Announces the action and plans its targets and effects.
s32 BattleEventRuntime_WaitForReady(void)
Waits, a frame at a time, until BattleEvent_Playback has played every target, then removes the callba...
void BattleEvent_Playback(void)
Plays the plan's targets one at a time: resolves the next target with BattleTargetExec,...
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
#define ITEM_REMOVED_SLOT_GONE
Inventory_RemoveFar's result when the last one left its slot, and the slots after it moved up.
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; t...
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 t...
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,...
UNUSED s32 BattlePres_RunPlainAttack(struct BattlePlan *input, s32 flags)
Unused.
s32 BattlePres_RunEscape(struct BattlePlan *plan)
Plays a unit's attempt to run.
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 t...
s32 BattlePres_RunPsynergyCast(struct BattlePlan *plan, s32 mode)
Plays Psynergy, a Djinni or an enemy's cast.
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 ...
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 f...
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 t...
void BattleActor_RemoveFromLists(s32 unitId)
Takes unit id out of the party's or the enemies' list and out of this round's actions,...
s32 BattlePresentation_RunUnitTransition(struct BattlePlan *plan, s32 mode)
Plays a summon or a full-screen Psynergy.
void BattleMotion_ShowDowned(s32 unitId)
Shows a downed unit: a party member lies down, an enemy keeps its damage pose, turns grey,...
void BattlePres_RestorePalette(void)
Copies the background's saved palette back undarkened, as the star field of BattleFx_PlayUnitElementE...
void BattleFx_PlayUnitElementEffect(s32 unitId, s32 element, s32 mode, s32 variant)
Plays a glow of the element about a unit, and returns when it is over.
s32 Graphics_ScaleRgb555Clamped(u16 *source, u16 *destination, s32 scale, s32 count)
Copies count colours from source to destination, each channel scaled by scale (16....
One animation layer of a sprite: its animation id, frames, running script and timer.
u8 param
SpriteColorMode its pixels are drawn with; 0 when taken.
s16 animId
the sprite id whose metadata and frames it uses
u8 mode
frame codec: 1 type-01, 3 LZ, anything else raw
u8 frame
frame shown, frameBase plus the facing offset; 255 none
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
struct AnimationEntry * entries[4]
its layers; empty ones null
u8 count
layers in use, up to the last one present
A unit's chosen action for the turn: its command, the command's parameter, its target and range,...
s16 parameter
an ability id, or CMD_ITEM's inventory index (-1 gone)
s16 command
enum BattleCommand
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
s32 pos[3]
the focus, 16.16 fixed-point pixels
s32 eye[3]
The eye, 16.16 fixed-point pixels: written each frame distance behind the focus along the turned view...
The command shared by an effect's caller, dispatcher and handlers.
s32 range
forwarded action range, otherwise initialized to 1
s32 actor
the user's unit id
s32 side
1 when the targets are the party, 0 for enemies
s32 kind
handler table index; 200 more for a critical hit
s16 actors[8]
the targets' unit ids, count of them
s32 variant
the ability's size, from 0 (Quake, then Earthquake)
s32 count
targets in actors, at least 1
s32 prelude
1 plays a prelude: in some effects a Djinni appears
s32 firstTarget
the action's first target, standing or not
struct MotionObject * object
NULL once released.
One action, as BattleCommand_BuildPlan lays it out for BattleTargetExec to apply target by target.
s32 outcome
enum BattlePlanStaging: how the action is shown
u32 presentationFlags
How the effect is staged (STAGING_ in battle_internal.h).
s8 targetCount
targets in targetIds
u8 actorId
the acting unit
u8 targetIds[BATTLE_TARGET_CAPACITY]
in battlefield order
s8 targetCritical[BATTLE_TARGET_CAPACITY]
enum BattleCritical
s32 failure
0 cast; 1 the Psynergy is sealed, 2 too little PP
s8 targetMultiplier[BATTLE_TARGET_CAPACITY]
The damage multiplier: 0 a miss, 1 a blow, 2 or 3 a double or triple.
The battle background's work slot as the camera reads it: the yaw the camera eases toward and the fra...
s32 frames
frames left to ease the yaw, a sixteenth a frame
s32 flag
0 lets the camera update set the background's range each frame; 1 for a critical hit's zoom and once ...
s32 active
BattleBackgroundView's busy, at the same offset.
s32 targetYaw
1/65536 turns
The effect updates its command while the presentation keeps animation state.
struct BattleEffectArgument effect
u8 savedAnimationParameters[8][4]
Each target's animation entries' param, saved before the effect.
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 side
BATTLE_UNIT_ABSENT (0), BATTLE_UNIT_ENEMY (1) or BATTLE_UNIT_PARTY (2).
s16 hp
current HP, 0 when downed
u8 classId
Who the unit is: a character's id (ISAAC to JENNA, below 8) or an enemy's id (BattleUnitSet).
u8 classIndex
The character's class, worked out from its Djinn (Unit_UpdateClass); 0 marks an enemy,...
u16 inventory[15]
Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*...
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
u8 partyStatus
PARTY_STATUS_SUMMONS or PARTY_STATUS_NO_SUMMONS.
u16 background
the battle background's id
u8 encounterMode
BATTLE_ENCOUNTER_: who strikes first.
s16 partyUnits[7]
ends with BATTLE_UNIT_LIST_END
s32 brightness
the backdrop's brightness, 16.16, 0x10000 full
struct BattleActionRecord actions[BATTLE_ACTION_CAPACITY]
The actions chosen for the turn.
u16 palette[128]
the backdrop's colours, before scaling
s16 enemyIds[BATTLE_ENEMY_CAPACITY+1]
ends with BATTLE_UNIT_LIST_END
A field object as the object dispatcher's far calls take it.
An item's definition: its price, type, who can equip it, its bonuses and unleash, its effects and the...
u8 useType
what using it costs (ITEM_USE_), or 0 for nothing
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
s32 z
16.16 fixed-point pixels
s32 x
16.16 fixed-point pixels
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...
s32 BattleUnit_ProcessTurnEnd(struct BattlePlan *plan)
Ends one unit's turn: its Djinn on standby are taken off its set, the Djinn a summon used begin to re...