Alchemy

battle

games/tbs/src/battle on GitHub

The Battles guide explains this folder.

Folders

battle.c

games/tbs/src/battle/battle.c

The battle object: a battle from its opening transition to its spoils. battle_internal.h holds what the parts share (the includes and the names two or more of them use); the code is in the files under battle/, included here in the order it has in the ROM. Camelot's own files are not recoverable: the ROM shows one object, and these parts are ours, cut where one family ends and the next begins.

A battle runs from Battle_RunEncounter (encounter.c). Each round the actions are gathered and put in turn order (round.c, or auto_battle.c under auto battle), and each action is announced and planned (BattleCommand_BuildPlan, plan.c), staged (BattlePresentation_DispatchAction, staging.c) and applied to each target (BattleTargetExec, target_exec.c), which queues the battle events BattleEvent_Playback plays (playback.c). README.md in this folder gives the words, prefixes and spellings the parts use.

battle_internal.h

games/tbs/src/battle/battle_internal.h

Enumerations

BattlePlanStaging

enum BattlePlanStaging

BattlePlan.outcome: how BattlePresentation_DispatchAction shows the action, set by BattleCommand_BuildPlan from the ability (gBattle_ActionStatus where it gives one).

Value=
PLAN_SHOW_MESSAGES1no animation: each target's events only
PLAN_SHOW_ATTACK2the actor runs up and strikes
PLAN_SHOW_CAST3Psynergy, and Venus, Mercury, Mars, Jupiter
PLAN_SHOW_ITEM4an item
PLAN_SHOW_SUMMON5the larger summons, the actor hidden
PLAN_SHOW_DJINNI6a Djinni with no attack (Granite, Quartz...)
PLAN_SHOW_FLEE7a unit runs
PLAN_SHOW_ENEMY_CAST8an enemy's Psynergy
PLAN_SHOW_FULL_SCREEN9Gaia, Rockfall, Procne and their kin

Line 209

Macros

BATTLE_WININ

#define BATTLE_WININ

The battle's windows: window 0 shows BG0 to BG2, sprites and blending, window 1 BG0, BG2, sprites and blending, and outside them only BG0 and blending.

Used by BattlePres_RunAttack, BattlePres_RunEntryTransition.

Line 101

BATTLE_BG_PALETTE

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

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

Used by BattleBackground_Load, BattlePresentation_ConfigurePaletteFade, BattlePresentation_SetPaletteLevel.

Line 109

CURTAIN_TILE

#define CURTAIN_TILE(n) (BG_CHAR_BLOCK(1) + (128 + (n)) * TILE_SIZE_4BPP)

The opening curtain's tiles: 4-bit tiles 128 to 136 of character block 1, which BG1 shows from its map in screen block 12.

Used by BattlePres_RunEntryTransition, BattlePresentation_UploadTileVariant.

Line 113

BATTLE_BG1CNT

#define BATTLE_BG1CNT

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

Used by BattleBackground_Load, BattlePres_RunEntryTransition, BattlePresentation_ConfigurePaletteFade.

Line 116

FIRST_ENEMY_UNIT

#define FIRST_ENEMY_UNIT 128

Unit ids from 128 are the enemies'; in a link battle the opponent's party takes the first three.

Used by BattleActor_SpawnObjectsForList, BattleEnemyList, BattleEnemy_LetterFirstOfClass, BattleFormation_BuildEnemyList, BattleMotion_DestroyAllSlotObjects, BattleObjGet, BattleObject_IsValidId, BattleParty_ListLivingUnits, BattlePres_RunUnitAction, BattlePresentation_AppendLinkedActions, BattlePresentation_BuildSortedUnitEntries, BattlePresentation_RunPairedUnitTransition, BattleTarget_ReplaceDefeated, Battle_RunEncounter, EnemySlotGet, LinkBattle_ReceiveParty.

Line 130

PARTY_BATTLE_SIZE

#define PARTY_BATTLE_SIZE 4

The party fights four at a time, three in a link battle; six enemies at most, three in a link battle.

Used by BattleParty_PrepareActiveOwners.

Line 135

ENEMY_CLASS_FIRST

#define ENEMY_CLASS_FIRST 8

An enemy's class id is its row of enemies.tsv plus 8 (Enemy_GetDefinition); class ids 0 to 7 are the party's. A formation lists its members by row.

Used by BattleFormation_AverageLevel, BattleFormation_BuildEnemyList, BattleGroupRandom.

Line 143

ENEMY_DEFEATED_FLAG

#define ENEMY_DEFEATED_FLAG(classId) ((classId) + 0x600)

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

Used by BattleEnemy_RecordDefeat, BattleFormation_AverageLevel, BattleFormation_SelectLevelMatchedCandidate.

Line 148

UNIT_NAME_LENGTH

#define UNIT_NAME_LENGTH 14

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

Used by DebugBattle_ViewMessages, LinkBattle_ReceiveParty.

Line 151

SIO_MULTI_PLAYER_ID

#define SIO_MULTI_PLAYER_ID() ((REG_SIOCNT << 26) >> 30)

This console's number in a link session (SIOCNT bits 4 and 5, which the hardware sets in multi-player mode): 0 for the parent, 1 for the child.

Used by BattlePresentation_UpdateCamera, Battle_RunEncounter.

Line 155

#define LINK_BOTH_CONNECTED 3

gLinkStatus: both consoles are connected.

Used by BattlePresentation_AppendLinkedActions, BattlePresentation_UpdateCamera, Battle_RunEncounter.

Line 158

#define LINK_MAX_MISSED_FRAMES 24

The frames a link battle tolerates without a connection before it gives up.

Used by BattlePresentation_AppendLinkedActions, BattlePresentation_UpdateCamera, Battle_RunEncounter.

Line 162

DJINN_RECOVERY_PARTY

#define DJINN_RECOVERY_PARTY 0

The Djinn recovery list's two tables (Djinn_GetRecoveryTableFar): the party's and the link opponent's.

Used by Battle_RunEncounter.

Line 166

DJINN_RECOVERY_AFTER_BATTLE

#define DJINN_RECOVERY_AFTER_BATTLE -1

DjinnRecoveryEntry.turns of a Djinni waiting for the battle to end.

Used by BattleCommand_BuildPlan, BattleParty_CountStandbyDjinn.

Line 170

FORMATION_SHUFFLED

#define FORMATION_SHUFFLED 0

BattleWork.battleType, from the enemy formation (BattleFormation_BuildEnemyList): the random formations stand left to right in the order they were drawn, any other is laid out from the centre.

Used by BattleFormation_BuildEnemyList, BattleParty_CollectUnitList, Battle_RunEncounter.

Line 177

SPRITE_WITH_SECOND_PART_A

#define SPRITE_WITH_SECOND_PART_A 476

The two battle sprites whose next sprite is loaded with them (into a second free place), the pass after them loading animation + 1.

Used by BattleActor_SpawnObjectsForList, SummonSlot_RegisterActorSprites.

Line 182

EQUIP_WEAPON

#define EQUIP_WEAPON 1

The inventory's weapon slot, for Inventory_FindEquippedFar.

Used by BattleCommand_BuildPlan, BattleObjMake.

Line 186

POISON_NORMAL

#define POISON_NORMAL 1

BattleUnit.poison: the poison takes a tenth of the maximum HP at the end of each turn, deadly poison a fifth.

Used by BattleUnit_BuildStatusFlags.

Line 198

GUARD_DEFEND

#define GUARD_DEFEND 1

BattleUnit.guardLevel: Defend and Granite halve the damage, Total Defense and Flash cut it to a tenth.

Used by BattleCommand_BuildPlan, BattlePresentation_BuildActions.

Line 203

STAGING_VIEW_ACROSS

#define STAGING_VIEW_ACROSS 0x40000

More of BattlePlan.presentationFlags: the camera takes the other side's view (an enemy's cast a view of its own), or turns right round.

Used by BattlePres_RunPsynergyCast.

Line 234

TARGET_NONE_ENEMY

#define TARGET_NONE_ENEMY 0x100

BattleActionRecord.target of an action that needs none: a held unit's lost turn (the enemies' and the party's), and an enemy's attack in auto battle, which picks a party place.

Used by BattlePres_BuildOpponentEntries.

Line 251

YAW_PARTY_TURN

#define YAW_PARTY_TURN 0x2000

The camera's yaw while a party member acts, and while an enemy does.

Used by BattlePres_RunAction, BattlePres_RunApproachAction, BattlePres_RunEscape, BattlePres_RunItem, BattlePres_RunPsynergyCast, BattlePres_RunUnitAction, BattlePresentation_BuildActions, BattlePresentation_DispatchAction, BattlePresentation_RunPairedUnitTransition, BattlePresentation_RunUnitTransition.

Line 255

BLEND_SPRITES_OVER_ALL

#define BLEND_SPRITES_OVER_ALL (BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL)

REG_BLDCNT: blend the semi-transparent sprites (OBJ mode 1) over every layer, to fade them.

Used by BattlePres_RunEntryTransition, BattlePresentation_RunPairedUnitTransition, BattlePresentation_RunUnitTransition.

Line 260

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.

Used by BattleEvent_Playback, BattlePresentation_WaitForAdvance, BattlePresentation_WaitForPromptAt.

Line 263

Also, macros without a comment: BATTLE_WINOUT, VALUE_UNIT_NAME, VALUE_ITEM_NAME, VALUE_CLASS_NAME, VALUE_ABILITY_NAME, VALUE_NUMBER, LINK_PARTY_SIZE, ENEMY_BATTLE_SIZE, ABILITY_ATTACK, ALLY_MAX, DJINN_RECOVERY_OPPONENT, DJINN_PER_ELEMENT, FORMATION_INTERLEAVED, SPRITE_WITH_SECOND_PART_B, RECORDS_NONE, RECORDS_SINGLE, RECORDS_TABLE, RECORDS_KIND_MASK, RECORDS_TABLE_SIZE, POISON_DEADLY, GUARD_TOTAL_DEFENSE, STAGING_KIND_MASK, STAGING_VARIANT_MASK, STAGING_VARIANT_SHIFT, STAGING_BY_ID_RANGE, STAGING_SCENE, STAGING_ON_DOWNED, STAGING_OTHER_SIDE, STAGING_VIEW_REVERSED, ITEM_USE_CONSUMED, ITEM_USE_MAY_BREAK, ITEM_USE_EMPTIES, TARGET_MODE_NONE, TARGET_MODE_FOES, TARGET_MODE_ALLIES, TARGET_MODE_SELF, TARGET_NONE_PARTY, YAW_ENEMY_TURN.

On this page