Skip to Content
The Alchemy Project

src/battle/battle_internal.h

What every part of the battle object shares: its includes, in their original order, and the names two or more parts use. More…

Included by battle.c.

Structures

NameDescription
structSNAPSHOT_VITALSA unit's HP and PP as btScriptedBattleSaveUnits keeps them.
structSNAPSHOT_COPYA unit's 25 status bytes, from its curse to its challenge, kept between the scripted battles.
structSNAPSHOTWhat btScriptedBattleSaveUnits keeps of the five units of the scripted battles between them: whether each was listed, the first three's summon boosts, each one's statuses and the last two's HP and PP.
structBATTLE_LINK_HEADERThe packet the two consoles exchange each turn of a link battle: how many actions follow, a random check, and the random seed both sides then use.
structSAVED_BATTLE_OBJECTWhat btMotionCallBeast saves of the battle object a called beast borrows, for btMotionDismissBeast to put back.
structAI_ENEMY_RESTAn ENEMY_DEFINITION as btAIChooseAction reads its abilities: through a pointer two bytes past its start.

Macros

NameDescription
#defineENEMY_LETTER_FIRST_TOO 0x8000btEnemyClaimNameLetter returns the letter in ENEMY_LETTER_MASK, with ENEMY_LETTER_FIRST_TOO set for the second enemy of a class: its callers then give the first one its letter too (btEnemyLetterFirstOfKind) before passing the letter to gmBattleUnitSetStub.
#defineENEMY_LETTER_MASK 0x7fff
#definePLACE_ENEMY_SIDE 0x80A list place code's side bit, set for the enemies' list, and its place in the list (btGetUnitAtPlace): PLACE_ENEMY is PLACE_PARTY with the side bit set.
#definePLACE_INDEX_MASK 0xf
#definePRIORITY_FIRST_IN_TURN 10000What an action that comes first adds to its priority (a Djinni that shields, guards or defends, an enemy's Counter or Guard Aura stance): more than any agility, so it is taken before every other action of the turn.
#defineUNIT_NAME_LENGTH 14The length of a unit's name, its terminator excluded.
#defineLINK_PARTY_SIZE 3In a link battle each console sends LINK_PARTY_SIZE places, at most three party members (btLinkBattleSendParty), and the opponent's take the first three enemy ids from FIRST_ENEMY_UNIT.
#defineLINK_BOTH_CONNECTED 3LinkStatusWork: both consoles are connected.
#defineTARGET_PICK_SIDE_EMPTY -2btAIChooseTarget's results when it picks no one: the side it may target lists no one, or no one there is worth the ability.
#defineTARGET_PICK_NONE -1
#defineBATTLE_OBJECT_NONE 255BATTLE_STATE.placement of a unit with no place on the battlefield: btUnitRefreshPlacement fills the list with it.
#defineDEFEAT_ONE 0BATTLE_STATE.defeatState: whether the last enemy fell alone, or with others before it, or a party member's action ended the battle with a single defeat.
#defineDEFEAT_SEVERAL 1
#defineDEFEAT_BY_PARTY_MEMBER 3
#defineENEMY_DEFEATED_FLAG (classId) ((classId) + FLAG_ENEMY_DEFEATED_FIRST)The game flag of an enemy the party has defeated, set by btEnemyRecordDefeat outside the monster battles; the monster battles choose only formations of defeated enemies (btFormationAverageLevel).
#defineENEMY_DEFEATED_FLAG_COUNT 512The enemies that have a defeated flag, the flags 0x600 to 0x7ff.
#defineYAW_PARTY_ACTION (DEGtoANG(45))The camera's yaw while a party member acts, and while an enemy does, in 1/65536 turns: an eighth of a turn either side of 0.
#defineYAW_ENEMY_ACTION (-(DEGtoANG(45)))
#defineYAW_BEHIND_ENEMIES (TRIG_TURN * 5 / 16)The camera's yaw from behind the enemies, which an enemy's staged effect and cast take in place of YAW_ENEMY_ACTION.
#defineBLEND_SPRITES_OVER_ALL (BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL)REG_BLDCNT: blend the semi-transparent sprites over every layer, to fade them.
#defineBATTLE_EFFECT_RUN (args, battleEffect)Runs a battle effect by its ability's effect word (Ability.battleEffect): with EFFECT_BY_ID_RANGE from the second range of kinds (btEffectRunByIdRangeStub), otherwise from the handler table.
#defineKEY_ADVANCE (KEY_A | KEY_B | KEYS_SHOULDERS)The keys that take the player on past a message: A, B, L and R.
#defineEQUIP_WEAPON 1gmInventoryGetEquippedItemStub's slot for the weapon.
#defineACTOR_SPRITE_GROUP_SIZE 4A group's sprite word (ACTOR_SPRITE_GROUP) points to a table of four sprites.
#defineRESOURCE_SLOT_SHIFT 12Where a battle object's resource keeps its sprite slot, above its sprite: (slot << RESOURCE_SLOT_SHIFT) | sprite.
#defineDEFEAT_HP_CHANGE 0xc0000000An HP change that defeats any unit: the Grim Reaper's call deals it, and the debug defeat.
#defineACTION_REPORTED -1What btActionRunBuild returns besides 0, which stages the action.
#defineACTION_NOTHING_TO_SHOW -2nothing to stage or show
#defineSTAGING_HIDE_ACTOR 1btStagingRunFullScreen's mode bit that hides the acting unit too, as the summons do.
#defineSTAGING_NO_CAST 2btStagingRunFullScreen's mode bit for Daedalus's strike at the turn's end: the acting unit plays no cast, with no pose, sound or star field.
#defineATTACK_WITH_PARTNER 32btStagingRunAttack's mode bit for Meld: BATTLE_PLAN.partnerId runs in beside the attacker.
#defineRamScriptedBattleSnapshot
#defineBATTLE_BG_PALETTE ((Uint16 *)&BG_PLTT_COLOR(6, 0))The battle background's colours: BG palettes 6 to 13, filled from BATTLE_STATE.palette, darkened or not.
#defineBATTLE_BG1CNTBG1 during a battle: 256 colours, priority 3, its map in screen block BATTLE_BG1_SCREEN_BLOCK.
#defineTARGET_NONE_ENEMY PLACE_PARTYBATTLE_ACTION_RECORD.target of a held unit's lost action (COMMAND_NONE, from btBuildEnemyActions): as a place code, place 0 of the other side, the party's for an enemy and the enemies' for a party member.
#defineSTAT_STAGE_MIN -4A stat stage changes the stat by an eighth of it (gmUnitCalculate), from half at the lowest to one and a half at the highest.
#defineSTAT_STAGE_MAX 4

Typedefs

NameDescription
typedef const Uint8 *(*MODEL_DECODER )(const Uint8 *source, void *destination);The bit decoder btBackgroundLoad copies to RAM and runs.

Enumerations

NameDescription
enumBATTLE_CAST_KIND { CAST_PSYNERGY, CAST_DJINNI, CAST_ENEMY }How btStagingRunPsynergyCast shows the caster.

Functions

NameDescription
Sint32fdSpriteAddAnimationStub (void *state, Sint32 id)Stub calls the parts make, each passing its own view of the record: fdSpriteAddAnimation and fdSpriteAnimationStart (field.c, resource_slot/) take the metadata slot state and the animation entry.
voidfdSpriteRemoveAnimationStub (void *state, Sint32 handle)Removes a sprite animation from a sprite and clears it.

Variables

NameDescription
extern Uint8ScriptedBattleSnapshot []
extern Uint8ScriptedBattleUnits []The five units Karst and Agatio's battle carries over between its parts: Felix, Piers and Jenna, and the first two enemies.
extern const Sint32BattleKnockbackAcceleration []A knocked-back unit's motion by variant, which btMotionApplyKnockback reads, as The Broken Seal's.
extern const Sint32BattleKnockbackSpeedLimit []speed limit
extern const Sint32BattleKnockbackVelocityY []upward velocity
extern const Sint32BattleKnockbackDistancePercent []distance, in percent of the anchor's x
extern const FIXEDBattleCameraCommandMatrix []The tilt the battle camera adds while commands are chosen (btCameraApplyTransform).
extern const Sint32BattleObjectEmptyScript []The script a battle object starts with: none.
extern const Sint8BattleFormationCenteredOffsets []The order enemies of a fixed formation take from the centre out: 0, -1, 1, -2, 2 and on.
extern const Uint16BattleUnitWeaponAnimationsIsaac []Each character's battle sprite for each weapon kind (btUnitGetWeaponSprite).
extern const Uint16BattleUnitWeaponAnimationsGaret []Garet's battle sprite for each kind of weapon he holds.
extern const Uint16BattleUnitWeaponAnimationsIvan []Ivan's battle sprite for each kind of weapon he holds.
extern const Uint16BattleUnitWeaponAnimationsMia []Mia's battle sprite for each kind of weapon she holds.
extern const Uint16BattleUnitWeaponAnimationsJenna []Jenna's battle sprite for each kind of weapon she holds.
extern const Uint16BattleUnitWeaponAnimationsFelix []Felix's battle sprite for each kind of weapon he holds.
extern const Uint16BattleUnitWeaponAnimationsSheba []Sheba's battle sprite for each kind of weapon she holds.
extern const Uint16BattleUnitWeaponAnimationsPiers []Piers's battle sprite for each kind of weapon he holds.

Description

What every part of the battle object shares: its includes, in their original order, and the names two or more parts use. battle.c includes it before the parts, and each part includes it too, so that a part read on its own still resolves. It places no bytes.

Macros in detail

ENEMY_LETTER_FIRST_TOO

#define ENEMY_LETTER_FIRST_TOO 0x8000

btEnemyClaimNameLetter returns the letter in ENEMY_LETTER_MASK, with ENEMY_LETTER_FIRST_TOO set for the second enemy of a class: its callers then give the first one its letter too (btEnemyLetterFirstOfKind) before passing the letter to gmBattleUnitSetStub.

Referenced by btAbilityApplyToTarget(), btEnemyClaimNameLetter() and btFormationBuildEnemyList().

Definition at line 70 of file battle_internal.h.

ENEMY_LETTER_MASK

#define ENEMY_LETTER_MASK 0x7fff

Referenced by btAbilityApplyToTarget() and btFormationBuildEnemyList().

Definition at line 71 of file battle_internal.h.

PLACE_ENEMY_SIDE

#define PLACE_ENEMY_SIDE 0x80

A list place code's side bit, set for the enemies' list, and its place in the list (btGetUnitAtPlace): PLACE_ENEMY is PLACE_PARTY with the side bit set.

Referenced by btActionRunBuild(), btAppendLinkedActions() and btGetUnitAtPlace().

Definition at line 75 of file battle_internal.h.

PLACE_INDEX_MASK

#define PLACE_INDEX_MASK 0xf

Referenced by btActionRunBuild() and btGetUnitAtPlace().

Definition at line 76 of file battle_internal.h.

PRIORITY_FIRST_IN_TURN

#define PRIORITY_FIRST_IN_TURN 10000

What an action that comes first adds to its priority (a Djinni that shields, guards or defends, an enemy's Counter or Guard Aura stance): more than any agility, so it is taken before every other action of the turn.

Referenced by btActionOrderSort() and btAIChooseAction().

Definition at line 81 of file battle_internal.h.

UNIT_NAME_LENGTH

#define UNIT_NAME_LENGTH 14

The length of a unit's name, its terminator excluded.

Referenced by btLinkBattleReceiveParty().

Definition at line 84 of file battle_internal.h.

#define LINK_PARTY_SIZE 3

In a link battle each console sends LINK_PARTY_SIZE places, at most three party members (btLinkBattleSendParty), and the opponent's take the first three enemy ids from FIRST_ENEMY_UNIT.

Referenced by btEnemyList(), btLinkBattleReceiveParty(), btLinkBattleSendParty(), btPartyPrepareMembers(), btUnitListLiving() and btUnitListLivingWithReserve().

Definition at line 89 of file battle_internal.h.

#define LINK_BOTH_CONNECTED 3

LinkStatusWork: both consoles are connected.

Referenced by btAppendLinkedActions(), btCameraUpdate(), btLinkBattleSyncTurn(), btLinkBattleWaitSync() and btRun().

Definition at line 92 of file battle_internal.h.

TARGET_PICK_SIDE_EMPTY

#define TARGET_PICK_SIDE_EMPTY -2

btAIChooseTarget's results when it picks no one: the side it may target lists no one, or no one there is worth the ability.

Referenced by btAIChooseAction() and btAIChooseTarget().

Definition at line 96 of file battle_internal.h.

TARGET_PICK_NONE

#define TARGET_PICK_NONE -1

Referenced by btAIChooseAction() and btAIChooseTarget().

Definition at line 97 of file battle_internal.h.

BATTLE_OBJECT_NONE

#define BATTLE_OBJECT_NONE 255

BATTLE_STATE.placement of a unit with no place on the battlefield: btUnitRefreshPlacement fills the list with it.

Referenced by btObjectFindSlot(), btObjectGet() and btUnitRefreshPlacement().

Definition at line 101 of file battle_internal.h.

DEFEAT_ONE

#define DEFEAT_ONE 0

BATTLE_STATE.defeatState: whether the last enemy fell alone, or with others before it, or a party member's action ended the battle with a single defeat. The messages are "has been downed!" and "'s party goes down!", MsgDowned plus the state; DEFEAT_BY_PARTY_MEMBER shows neither.

Referenced by btFormationBuildEnemyList().

Definition at line 107 of file battle_internal.h.

DEFEAT_SEVERAL

#define DEFEAT_SEVERAL 1

Referenced by btEnemyRecordDefeat() and btRun().

Definition at line 108 of file battle_internal.h.

DEFEAT_BY_PARTY_MEMBER

#define DEFEAT_BY_PARTY_MEMBER 3

Referenced by btRun().

Definition at line 109 of file battle_internal.h.

ENEMY_DEFEATED_FLAG

#define ENEMY_DEFEATED_FLAG(classId) ((classId) + FLAG_ENEMY_DEFEATED_FIRST)

The game flag of an enemy the party has defeated, set by btEnemyRecordDefeat outside the monster battles; the monster battles choose only formations of defeated enemies (btFormationAverageLevel).

Referenced by btEnemyRecordDefeat(), btFormationAverageLevel() and btFormationSelectLevelMatchedCandidate().

Definition at line 114 of file battle_internal.h.

ENEMY_DEFEATED_FLAG_COUNT

#define ENEMY_DEFEATED_FLAG_COUNT 512

The enemies that have a defeated flag, the flags 0x600 to 0x7ff.

Referenced by btEnemyRecordDefeat().

Definition at line 116 of file battle_internal.h.

YAW_PARTY_ACTION

#define YAW_PARTY_ACTION (DEGtoANG(45))

The camera's yaw while a party member acts, and while an enemy does, in 1/65536 turns: an eighth of a turn either side of 0.

Referenced by btAutoBattleRunAction(), btAutoBattleRunApproachAttack(), btAutoBattleRunAttackOrItem(), btAutoBattleRunPsynergy(), btCameraSetRange(), btGatherActions(), btRun(), btStagingDispatchAction(), btStagingRunAttack(), btStagingRunFlee(), btStagingRunFullScreen(), btStagingRunItem() and btStagingRunPsynergyCast().

Definition at line 192 of file battle_internal.h.

YAW_ENEMY_ACTION

#define YAW_ENEMY_ACTION (-(DEGtoANG(45)))

Referenced by btAutoBattleRunAction(), btAutoBattleRunAttackOrItem(), btStagingRunFullScreen(), btStagingRunItem() and btStagingRunPsynergyCast().

Definition at line 193 of file battle_internal.h.

YAW_BEHIND_ENEMIES

#define YAW_BEHIND_ENEMIES (TRIG_TURN * 5 / 16)

The camera's yaw from behind the enemies, which an enemy's staged effect and cast take in place of YAW_ENEMY_ACTION.

Referenced by btAutoBattleRunPsynergy(), btStagingRunFullScreen() and btStagingRunPsynergyCast().

Definition at line 197 of file battle_internal.h.

BLEND_SPRITES_OVER_ALL

#define BLEND_SPRITES_OVER_ALL (BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL)

REG_BLDCNT: blend the semi-transparent sprites over every layer, to fade them.

Referenced by btAutoBattleRunPsynergy(), btBackgroundStepHighlightBlend(), btStagingRunFullScreen() and btTransitionRun().

Definition at line 201 of file battle_internal.h.

BATTLE_EFFECT_RUN

#define BATTLE_EFFECT_RUN(args, battleEffect)

Runs a battle effect by its ability's effect word (Ability.battleEffect): with EFFECT_BY_ID_RANGE from the second range of kinds (btEffectRunByIdRangeStub), otherwise from the handler table.

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

Definition at line 206 of file battle_internal.h.

KEY_ADVANCE

#define KEY_ADVANCE (KEY_A | KEY_B | KEYS_SHOULDERS)

The keys that take the player on past a message: A, B, L and R.

Referenced by btMessageWaitForAdvance(), btMessageWaitForAdvanceAt() and btPlaybackRun().

Definition at line 211 of file battle_internal.h.

EQUIP_WEAPON

#define EQUIP_WEAPON 1

gmInventoryGetEquippedItemStub's slot for the weapon.

Referenced by btActionRunBuild(), btObjectMake() and btUnitGetWeaponSprite().

Definition at line 214 of file battle_internal.h.

ACTOR_SPRITE_GROUP_SIZE

#define ACTOR_SPRITE_GROUP_SIZE 4

A group's sprite word (ACTOR_SPRITE_GROUP) points to a table of four sprites.

Referenced by btActorDetachSpriteScripts(), btHighlightSetSpriteMode(), btObjectSpawnObjectsForList() and btObjectUpdateSpritePriorities().

Definition at line 217 of file battle_internal.h.

RESOURCE_SLOT_SHIFT

#define RESOURCE_SLOT_SHIFT 12

Where a battle object's resource keeps its sprite slot, above its sprite: (slot << RESOURCE_SLOT_SHIFT) | sprite.

Referenced by btEnemySpriteLoadIntoSlots() and btMotionCallBeast().

Definition at line 221 of file battle_internal.h.

DEFEAT_HP_CHANGE

#define DEFEAT_HP_CHANGE 0xc0000000

An HP change that defeats any unit: the Grim Reaper's call deals it, and the debug defeat.

Referenced by btActionRunBuild() and btUnitProcessActionEnd().

Definition at line 225 of file battle_internal.h.

ACTION_REPORTED

#define ACTION_REPORTED -1

What btActionRunBuild returns besides 0, which stages the action.

the action failed and its message is shown

Referenced by btActionRunBuild() and btStagingDispatchAction().

Definition at line 228 of file battle_internal.h.

ACTION_NOTHING_TO_SHOW

#define ACTION_NOTHING_TO_SHOW -2

nothing to stage or show

Referenced by btActionRunBuild().

Definition at line 229 of file battle_internal.h.

STAGING_HIDE_ACTOR

#define STAGING_HIDE_ACTOR 1

btStagingRunFullScreen's mode bit that hides the acting unit too, as the summons do.

Referenced by btStagingDispatchAction() and btStagingRunFullScreen().

Definition at line 263 of file battle_internal.h.

STAGING_NO_CAST

#define STAGING_NO_CAST 2

btStagingRunFullScreen's mode bit for Daedalus's strike at the turn's end: the acting unit plays no cast, with no pose, sound or star field.

Referenced by btStagingDispatchAction() and btStagingRunFullScreen().

Definition at line 266 of file battle_internal.h.

ATTACK_WITH_PARTNER

#define ATTACK_WITH_PARTNER 32

btStagingRunAttack's mode bit for Meld: BATTLE_PLAN.partnerId runs in beside the attacker.

Referenced by btStagingDispatchAction() and btStagingRunAttack().

Definition at line 270 of file battle_internal.h.

RamScriptedBattleSnapshot

#define RamScriptedBattleSnapshot

Referenced by btScriptedBattleRestoreUnits() and btScriptedBattleSaveUnits().

Definition at line 285 of file battle_internal.h.

BATTLE_BG_PALETTE

#define BATTLE_BG_PALETTE ((Uint16 *)&BG_PLTT_COLOR(6, 0))

The battle background's colours: BG palettes 6 to 13, filled from BATTLE_STATE.palette, darkened or not.

Referenced by btBackgroundLoad(), btBackgroundSetMode(), btBackgroundSetPaletteLevel(), btElementGlowPlay() and btStagingRunItem().

Definition at line 333 of file battle_internal.h.

BATTLE_BG1CNT

#define BATTLE_BG1CNT

BG1 during a battle: 256 colours, priority 3, its map in screen block BATTLE_BG1_SCREEN_BLOCK.

Referenced by btBackgroundLoad(), btBackgroundSetMode() and btTransitionRun().

Definition at line 337 of file battle_internal.h.

TARGET_NONE_ENEMY

#define TARGET_NONE_ENEMY PLACE_PARTY

BATTLE_ACTION_RECORD.target of a held unit's lost action (COMMAND_NONE, from btBuildEnemyActions): as a place code, place 0 of the other side, the party's for an enemy and the enemies' for a party member.

Referenced by btBuildEnemyActions().

Definition at line 344 of file battle_internal.h.

STAT_STAGE_MIN

#define STAT_STAGE_MIN -4

A stat stage changes the stat by an eighth of it (gmUnitCalculate), from half at the lowest to one and a half at the highest.

Referenced by btAbilityApplyToTarget().

Definition at line 348 of file battle_internal.h.

STAT_STAGE_MAX

#define STAT_STAGE_MAX 4

Referenced by btAbilityApplyToTarget().

Definition at line 349 of file battle_internal.h.

Typedefs in detail

MODEL_DECODER

typedef const Uint8 *(*MODEL_DECODER)(const Uint8 *source, void *destination);

The bit decoder btBackgroundLoad copies to RAM and runs. It returns the source after the last halfword it read.

Referenced by btBackgroundLoad().

Definition at line 233 of file battle_internal.h.

Enumerations in detail

BATTLE_CAST_KIND

enum BATTLE_CAST_KIND

How btStagingRunPsynergyCast shows the caster.

EnumeratorValueDescription
CAST_PSYNERGY0the star field gathers on the caster
CAST_DJINNI1no glow; the effect plays its prelude
CAST_ENEMY2the element's streaks

Definition at line 273 of file battle_internal.h.

Functions in detail

fdSpriteAddAnimationStub

Sint32 fdSpriteAddAnimationStub(void *state, Sint32 id)

Stub calls the parts make, each passing its own view of the record: fdSpriteAddAnimation and fdSpriteAnimationStart (field.c, resource_slot/) take the metadata slot state and the animation entry. Adds a sprite animation to a sprite in its first free slot; returns it, 0 when none could be taken, or -1 when all four are in use.

Referenced by btMotionPlayHitFlash(), btObjectSpawnObjectsForList(), btStatusIconCycle(), fdActorResetForLeader(), fdEntranceEndArrivalAnimation(), fdExitAddHiddenLeaderLayer(), fdExitPrepareActorAnimation() and fdExitPrepareAnimation().

Definition at line 123 of file battle_internal.h.

fdSpriteRemoveAnimationStub

void fdSpriteRemoveAnimationStub(void *state, Sint32 handle)

Removes a sprite animation from a sprite and clears it.

Referenced by btEffectRunAzul() and btStatusIconCycle().

Definition at line 125 of file battle_internal.h.

Variables in detail

ScriptedBattleSnapshot

extern Uint8 ScriptedBattleSnapshot[]

Definition at line 283 of file battle_internal.h.