Game Logic & Tables
This page is a guide to the games/tla/src/game/ folder of the Alchemy project,
where the RPG database, character stat calculations, and top-level engine
switcher for Golden Sun: The Lost Age are kept.
Whenever the game recalculates Felix's class after a Djinni is set, rolls a
weapon unleash, tracks rare artifact stock, or switches between the field,
combat, and Contigo's minigames, it calls code here. Compared with The Broken
Seal, these tables expand to eight party members, 72 named Djinn, 29 summons,
and 16-bit ability IDs, while gmUnitGet and syGameFlag* moved into
system/system_flags.c (System library).
The sections below give the seven RPG definition tables with their exact row counts, followed by a file map of every source file in the module. The conceptual model is described in RPG Data & Rules.
Definition tables
Every table uses dense integer indices matching enums in include/*_ids.h
(item_ids.h, ability_ids.h, enemy_ids.h, djinn_ids.h, plus
include/game/character_ids.h) and message offsets in text/<lang>.po:
| File | Symbol and TLA row counts |
|---|---|
item_table.c | ItemDefinitionTable (516 rows, 374 named in item_ids.h, paired with rare_item_stock.c) |
ability_table.c | AbilityDefinitions (734 rows, 624 named in ability_ids.h) |
enemy_table.c | EnemyDefinitions (380 enemy rows, with element presets in element_table.c) |
class_table.c | ClassDefinitionTable (244 classes; learned Psynergy stored as 16-bit halfwords because ability IDs exceed 255) |
djinn_table.c | DjinnDefinitionTable (80 slots, 20 per element; 72 named Djinn, 18 per element, covering every TBS and TLA Djinni) |
summon_table.c | SummonDefinitionTable (29 summons: 16 single-element and 13 multi-element) |
character_table.c | CharacterDefinitionTable (all 8 characters: Felix, Jenna, and Sheba start at Lv 5; Piers starts at Lv 18 with Spring and Shade; Isaac's party starts at Lv 28 unless imported from Clear Data; 5 native affinity points each) |
File map
| File(s) | Role |
|---|---|
main_routine.c | gmMainRoutineRun and gmReturnFromEngine across all 5 gameplay engines (plus four hidden DebugMode boot shortcuts) |
game.c, game_internal.h | Parent translation unit #includeing the game_*.c parts below in ROM order |
game_units.c, game_snapshot.c | gmUnitCalculate from-scratch recalculation over CharacterUnits and active enemies, plus actor snapshot helpers |
game_djinn.c, game_classes.c | Djinn state transitions and gmClassDetermine (including Jenna and Piers series, plus item-class series for Mysterious Card, Trainer's Whip, and Tomegathericon) |
game_levels.c, experience_table.c, game_party.c | 99-level XP curves, starting-level initialisation, 8-member roster and party flags 0–7, and coins (200 at New Game) |
game_inventory.c, rare_item_stock.c | 15 packed inventory slots and global per-item rare artifact stock counters |
game_battle_arithmetic.c, element_table.c | gmBattleGetElementMultiplier, enemy elemental presets, hit, unleash, status, and heal formulas, and per-action synced gmBattleRandom |
stubs.s | Jump-table stubs exported to other modules and scene overlays |
Source files
| File | Description |
|---|---|
ability_table.c | The 734 abilities, by ability id. |
character_table.c | The eight characters' definitions, by character id. |
class_table.c | The 244 classes, by class id. |
djinn_table.c | The 80 Djinn, 20 of each element in element order. |
element_table.c | The element tables: class series by element, element power and resistance by level, the enemies' element presets, the power and resistance curve, and the dragons and sea creatures two weapons' effects look for. |
enemy_table.c | The 380 enemies' definitions (gmEnemyGetDefinition), each row keyed by its enemy id and headed by its name in the English release; the name field itself is blank, and gmBattleUnitSet takes the name from the messages. |
experience_table.c | Each character's element group, what the data transfer from The Broken Seal copies and hands out, and the experience each character needs for each level. |
game.c | The game object: the rules of the party and its world. |
game_battle_arithmetic.c | Battle arithmetic: element multipliers, random rolls and success rates. |
game_classes.c | A unit's level in each element, the elemental power and resistance those levels give it, and the class a character's Djinn and items make it. |
game_djinn.c | The Djinn the party holds: a Djinni found and given to a member, set or put on standby, moved between members and back from recovery, and the counts the menus show. |
game_internal.h | What every part of the game object shares: its includes, the declarations its parts disagreed on and one inventory helper. |
game_inventory.c | Items and inventories: equipping, adding, removing, breaking and counting. |
game_levels.c | Actions and Psynergy lists, characters, experience and levelling up. |
game_party.c | Enemy units, the active party, coins and counters, and summons. |
game_snapshot.c | The equipment put aside for the Trial Road, as The Broken Seal's for the Colosso: Felix's, Jenna's, Sheba's and Piers's inventories, and giving them back. |
game_units.c | The party's units and their stats, a new game, HP and PP, and the data transfer from The Broken Seal up to Isaac's party joining at Contigo. |
item_table.c | The 516 items, by item id. |
main_routine.c | The main routine and scene changes: exits, returns from an engine, entering a scene. |
rare_item_stock.c | Each item's place among the shops' rare item counters, and two short lists a new game reads. |
starting_equipment.c | |
summon_table.c | The summons: the order the Summon command lists them in, and each one's ability and the Djinn it needs. |
| File | Description |
|---|---|
character.h | The definitions of characters, Djinn and enemies, as The Broken Seal's character.h has them; an enemy's lacks the ten bytes The Broken Seal's keeps before its items. |
character_ids.h | The eight playable characters' ids, with each one's Japanese name: one for each row of CharacterDefinitionTable in order. |
game.h | The game's rules and data as the battles, the field and the menus share them: the tables of items, abilities, summons, Djinn, characters and enemies, the field Psynergy each ability casts, and the game module's functions the other modules call. |
game_flags.h | The game flags' size, and the byte and bit of GameFlagBytes that hold a flag. |
game_functions.h | The game module's functions, declared once each in the order of its stub table, without the inline game.h brings in with battle/battle_unit.h. |
inventory.h | A unit's fifteen inventory slots: counting, finding, adding and taking items, and finding who in the party carries one. |
item.h | Items: their definitions, types, flags and effects. |
main_routine.h | The main routine, which runs the game's engines one after another, and the scene changes between them. |
main_routine_state.h | The values MainRoutineStateWork's fields hold. |
stubs.h | The stub calls into the game module, as the other modules' code calls them. |
system_call.h | The names the scene and debug overlays call these main-image functions by: one typed inline each, which calls the function through the overlay's import stub. |