Alchemy
Loading...
Searching...
No Matches

battle_internal.h

Go to the documentation of this file.
1#ifndef ALCHEMY_BATTLE_INTERNAL_H
2#define ALCHEMY_BATTLE_INTERNAL_H
3
4/// @file
5/// What every part of the battle object shares: its includes, in their
6/// original order, and the names two or more parts use. battle.c includes it
7/// before the parts, and each part includes it too, so that a part read on
8/// its own still resolves. It places no bytes.
9
10#include "vram_tab.h"
11#include "item_ids.h"
12#include "window.h"
13#include "unit/battle/battle.h"
14#include "unit/object/object.h"
16#include "battle.h"
17#include "keystate.h"
18#include "debug.h"
19#include "field.h"
20#include "game.h"
21#include "graphics.h"
22#include "menu.h"
23#include "minigame.h"
24#include "sound.h"
25#include "system.h"
26#include "types.h"
27#include "owner_state.h"
28#include "edition.h"
29#include "io_reg.h"
30#include "battle_unit.h"
31#include "game_state.h"
32#include "battle_system.h"
33#include "text/msg_ids.h"
34#include "mem.h"
35#include "resource_ids.h"
36#include "callback_scheduler.h"
38#include "iwram_call.h"
39#include "global_cells.h"
40#include "battle_display.h"
41#include "battle_message.h"
42#include "battle_party.h"
43#include "battle_intro.h"
44#include "inventory.h"
45#include "dma.h"
46#include "scene.h"
47#include "battle_work.h"
48#include "battle_type.h"
49#include "battle_summon.h"
50#include "tbs_edition.h"
51#include "serial_runtime.h"
52#include "ram_buffer.h"
53#include "party_state.h"
54#include "battle_command.h"
55#include "resource.h"
56#include "heap_state.h"
57#include "flags.h"
58#include "ability_ids.h"
59#include "menu_list.h"
61#include "ui.h"
62#include "battle_calc.h"
63#include "objdisp.h"
64#include "motobj.h"
65#include "battle_status_icon.h"
66#include "animspr.h"
67#include "field_event.h"
68#include "metadata_lookup.h"
69#include "fixed_math.h"
70#include "battle_motion.h"
71#include "effect_step.h"
72#include "battle_escape.h"
73#include "battle_target.h"
74#include "battle_obj.h"
75#include "battle_event.h"
76#include "project.h"
77#include "battle_random.h"
78#include "irqlock.h"
79#include "transform.h"
80#include "battle_effect.h"
81#include "battle_effect_work.h"
82#include "character.h"
83#include "io_write_queue.h"
84#include "item.h"
85#include "irq.h"
86#include "vram_block.h"
87#include "owner_value.h"
88#include "songs.h"
89#include "ramcode.h"
90#include "map_scroll.h"
91#include "iowrite.h"
92#include "battle_formation.h"
93#include "b5_context.h"
94#include "frame.h"
96#include "macros.h"
97
98/// The battle's windows: window 0 shows BG0 to BG2, sprites and blending,
99/// window 1 BG0, BG2, sprites and blending, and outside them only BG0 and
100/// blending.
101#define BATTLE_WININ \
102 (WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | \
103 WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | \
104 WININ_WIN1_CLR)
105#define BATTLE_WINOUT (WINOUT_WIN01_BG0 | WINOUT_WIN01_CLR | WINOUT_WINOBJ_ALL)
106
107/// The battle background's colours: BG palettes 6 to 13, filled from
108/// BattleWork.palette, darkened or not.
109#define BATTLE_BG_PALETTE ((u16 *)&BG_PLTT_COLOR(6, 0))
110
111/// The opening curtain's tiles: 4-bit tiles 128 to 136 of character block 1,
112/// which BG1 shows from its map in screen block 12.
113#define CURTAIN_TILE(n) (BG_CHAR_BLOCK(1) + (128 + (n)) * TILE_SIZE_4BPP)
114
115/// BG1 during a battle: 256 colours, priority 3, its map in screen block 31.
116#define BATTLE_BG1CNT \
117 (BGCNT_PRIORITY(3) | BGCNT_256_COLORS | BGCNT_SCREEN_BASE(31))
118
119// The kinds of argument a message's placeholders take, for
120// UiWork_PushValueSlotFar: a unit's name, an item's, a class's, an
121// ability's, and a number.
122#define VALUE_UNIT_NAME 1
123#define VALUE_ITEM_NAME 2
124#define VALUE_CLASS_NAME 3
125#define VALUE_ABILITY_NAME 4
126#define VALUE_NUMBER 5
127
128/// Unit ids from 128 are the enemies'; in a link battle the opponent's party
129/// takes the first three.
130#define FIRST_ENEMY_UNIT 128
131#define LINK_PARTY_SIZE 3
132
133/// The party fights four at a time, three in a link battle; six enemies at
134/// most, three in a link battle.
135#define PARTY_BATTLE_SIZE 4
136#define ENEMY_BATTLE_SIZE 6
137
138#define ABILITY_ATTACK 1 ///< the ability "Attack"
139#define ALLY_MAX 7 ///< the last party member's unit id
140
141/// An enemy's class id is its row of enemies.tsv plus 8 (Enemy_GetDefinition);
142/// class ids 0 to 7 are the party's. A formation lists its members by row.
143#define ENEMY_CLASS_FIRST 8
144
145/// The game flag of an enemy class the party has defeated, set by
146/// BattleEnemy_RecordDefeat outside the monster battles; the monster battles
147/// choose only formations of defeated enemies (BattleFormation_AverageLevel).
148#define ENEMY_DEFEATED_FLAG(classId) ((classId) + 0x600)
149
150/// The length of a unit's name, its terminator excluded.
151#define UNIT_NAME_LENGTH 14
152
153/// This console's number in a link session (SIOCNT bits 4 and 5, which the
154/// hardware sets in multi-player mode): 0 for the parent, 1 for the child.
155#define SIO_MULTI_PLAYER_ID() ((REG_SIOCNT << 26) >> 30)
156
157/// gLinkStatus: both consoles are connected.
158#define LINK_BOTH_CONNECTED 3
159
160/// The frames a link battle tolerates without a connection before it gives
161/// up.
162#define LINK_MAX_MISSED_FRAMES 24
163
164/// The Djinn recovery list's two tables (Djinn_GetRecoveryTableFar): the
165/// party's and the link opponent's.
166#define DJINN_RECOVERY_PARTY 0
167#define DJINN_RECOVERY_OPPONENT 1
168
169/// DjinnRecoveryEntry.turns of a Djinni waiting for the battle to end.
170#define DJINN_RECOVERY_AFTER_BATTLE -1
171
172#define DJINN_PER_ELEMENT 20
173
174/// BattleWork.battleType, from the enemy formation
175/// (BattleFormation_BuildEnemyList): the random formations stand left to right
176/// in the order they were drawn, any other is laid out from the centre.
177#define FORMATION_SHUFFLED 0
178#define FORMATION_INTERLEAVED 1
179
180/// The two battle sprites whose next sprite is loaded with them (into a
181/// second free place), the pass after them loading animation + 1.
182#define SPRITE_WITH_SECOND_PART_A 476
183#define SPRITE_WITH_SECOND_PART_B 483
184
185/// The inventory's weapon slot, for Inventory_FindEquippedFar.
186#define EQUIP_WEAPON 1
187
188// MotionObject.recordStorageKind's low four bits: no sprite, one sprite in
189// records, or records pointing to a table of up to four.
190#define RECORDS_NONE 0
191#define RECORDS_SINGLE 1
192#define RECORDS_TABLE 2
193#define RECORDS_KIND_MASK 15
194#define RECORDS_TABLE_SIZE 4
195
196/// BattleUnit.poison: the poison takes a tenth of the maximum HP at the end of
197/// each turn, deadly poison a fifth.
198#define POISON_NORMAL 1
199#define POISON_DEADLY 2
200
201/// BattleUnit.guardLevel: Defend and Granite halve the damage, Total Defense
202/// and Flash cut it to a tenth.
203#define GUARD_DEFEND 1
204#define GUARD_TOTAL_DEFENSE 2
205
206/// BattlePlan.outcome: how BattlePresentation_DispatchAction shows the
207/// action, set by BattleCommand_BuildPlan from the ability
208/// (gBattle_ActionStatus where it gives one).
210 PLAN_SHOW_MESSAGES = 1, ///< no animation: each target's events only
211 PLAN_SHOW_ATTACK = 2, ///< the actor runs up and strikes
212 PLAN_SHOW_CAST = 3, ///< Psynergy, and Venus, Mercury, Mars, Jupiter
213 PLAN_SHOW_ITEM = 4, ///< an item
214 PLAN_SHOW_SUMMON = 5, ///< the larger summons, the actor hidden
215 PLAN_SHOW_DJINNI = 6, ///< a Djinni with no attack (Granite, Quartz...)
216 PLAN_SHOW_FLEE = 7, ///< a unit runs
217 PLAN_SHOW_ENEMY_CAST = 8, ///< an enemy's Psynergy
218 PLAN_SHOW_FULL_SCREEN = 9 ///< Gaia, Rockfall, Procne and their kin
219};
220
221// BattlePlan.presentationFlags: the effect's kind in the low twelve bits and
222// its strength (a double or triple blow) above them; then how the effect is
223// staged.
224#define STAGING_KIND_MASK 0xfff
225#define STAGING_VARIANT_MASK 0x3000
226#define STAGING_VARIANT_SHIFT 12
227#define STAGING_BY_ID_RANGE 0x4000 ///< BattleFx_DispatchByIdRangeFar
228#define STAGING_SCENE 0x8000 ///< BattleFx_RunSceneEffectFar, actor's view
229#define STAGING_ON_DOWNED 0x10000 ///< shown on downed targets too (revivals)
230#define STAGING_OTHER_SIDE 0x20000 ///< played from the other side
231
232/// More of BattlePlan.presentationFlags: the camera takes the other side's
233/// view (an enemy's cast a view of its own), or turns right round.
234#define STAGING_VIEW_ACROSS 0x40000
235#define STAGING_VIEW_REVERSED 0x80000
236
237// ItemDefinition.useType: what using an item in battle does to it.
238#define ITEM_USE_CONSUMED 1 ///< one is used up
239#define ITEM_USE_MAY_BREAK 2 ///< breaks one time in eight
240#define ITEM_USE_EMPTIES 4 ///< Hermes' Water leaves an Empty Bottle
241
242// BattleAct.targetMode: whom an ability may target, from its user's view.
243#define TARGET_MODE_NONE 0
244#define TARGET_MODE_FOES 1
245#define TARGET_MODE_ALLIES 2
246#define TARGET_MODE_SELF 4
247
248/// BattleActionRecord.target of an action that needs none: a held unit's
249/// lost turn (the enemies' and the party's), and an enemy's attack in auto
250/// battle, which picks a party place.
251#define TARGET_NONE_ENEMY 0x100
252#define TARGET_NONE_PARTY 0x180
253
254/// The camera's yaw while a party member acts, and while an enemy does.
255#define YAW_PARTY_TURN 0x2000
256#define YAW_ENEMY_TURN -0x2000
257
258/// REG_BLDCNT: blend the semi-transparent sprites (OBJ mode 1) over every
259/// layer, to fade them.
260#define BLEND_SPRITES_OVER_ALL (BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL)
261
262/// The keys that take the player on past a message: A, B, L and R.
263#define KEY_ADVANCE (KEY_A | KEY_B | KEYS_SHOULDERS)
264
265#endif
Ability numbers, named from the English release.
Animated sprites: their layers, frames and colour modes, and the resource slots they draw from.
The sound driver's command masks, cue controls and the routines and globals it shares with the engine...
B5Context, the object context a battle routine reads; most of its fields are still unnamed.
The battle calculation tables: hit chances, HP and PP damage and recovery.
The battle command names: auto battle and the battle options (aliases of debug and key globals),...
The battle camera and the presentation's transition, background and affine work.
The battle effect argument and the rectangle-drawing routines effects call.
BattleEffectWork, the running battle effect's work, and its animation objects.
Declares nothing of its own: it only includes edition.h, battle_session.h and types....
The battle event queue: the events BattleEvPush queues and the playback phases that play them.
The enemy formation records.
BattlePlanStaging
BattlePlan.outcome: how BattlePresentation_DispatchAction shows the action, set by BattleCommand_Buil...
@ 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_ITEM
an item
@ 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
Who strikes first as a battle opens.
Declares nothing of its own: it only includes types.h and text/msg_ids.h.
Declares nothing of its own: it only includes edition.h and types.h.
Actor_Place, which places a battle object for a unit.
Which units are in a battle, and the Djinn recovery list.
gBattleRandomSeed, the battle's random seed.
Declares nothing of its own: it only includes edition.h and battle_session.h.
Summons and the battle sprite definitions of the enemy classes.
BattleUnit_Recalculate, which recalculates a unit's stats.
Declares nothing of its own: it only includes edition.h, battle_session.h and types....
BattlePlan, an action planned for its targets: the hits, criticals and multipliers rolled.
BattleUnit, a party member's or enemy's battle state, with the elements, abilities and actions it use...
BattleWork, the battle's own work, and the battle display work.
The task scheduler: tasks, their order and the scheduler's state.
The definitions of characters, classes, Djinn and enemies, and a level up's result.
The engine calls the debug menus import, and their palette swatch tiles.
DMA channel registers, and the DMA and CPU fills.
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
EffectStep and EffectPosition, the positions effects move through.
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
16.16 fixed-point constants, sine and cosine, and the library division.
FixedPointPosition, a position in 16.16 fixed point.
Game flags, named where their meaning is shown.
The frame loop's globals: lag counts, the CPU load display and the VBlank flags.
GameState, the game's state: play time, coins, the scene and the leader's position,...
The work slots of gWorkSlot, read through their own names.
The screen blend's globals and the graphics routines.
The heap's work slots and HeapState.
gOverflowItem, an item slot the spoils code uses when items are handed out.
The hardware's I/O registers and their bits, as pret names them.
The register write queue that VBlank carries out after each finished frame.
Io_Write16, a 16-bit write to a register or memory.
The hardware's interrupt sources and the interrupt handler table.
Saving, disabling and restoring the interrupt master enable.
Items: their definitions, types, flags and effects.
Item numbers, named from the English release.
The IWRAM call layer: the routines the game keeps resident in IWRAM, each at its fixed address,...
The keypad state the VBlank interrupt keeps.
Small statement macros both games use for positions, velocities and bounds.
The map layers' scroll work and the background scroll values.
The heaps: allocating and freeing blocks.
Menu lists: sprites, cursors, the party status window and paged selections.
Animation metadata and its lookup by resource.
The reel game's title lettering.
MotionObject, an effect object that moves and draws one sprite.
The object dispatcher's forward declaration.
Declares nothing of its own: it only includes battle_system.h.
Declares nothing of its own: it only includes types.h, edition.h and farcall.h.
Declares nothing of its own: it only includes static_assert.h and game_state.h.
The 3D projection.
The work pointers in the gWorkSlot table, by name.
Copying ARM routines to RAM to run them there.
Resource numbers, named where their contents are known.
FIELD_AT_OFFSET and the entity and camera views older scene code reads.
The link cable's runtime: serial packets, registers and transfer state.
Song and sound effect ids, indices into gSound_SongTable.
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
Values that differ by patch level or language, chosen once for their code.
The 3D transform and its stack.
The integer types, TRUE, UNUSED and the fixed-address macros.
UiWork, the window system's work, and the status screen's cursors.
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
The sprite VRAM block cache and its owners.
The window renderer's work.