Skip to Content
The Alchemy Project

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:

FileSymbol and TLA row counts
item_table.cItemDefinitionTable (516 rows, 374 named in item_ids.h, paired with rare_item_stock.c)
ability_table.cAbilityDefinitions (734 rows, 624 named in ability_ids.h)
enemy_table.cEnemyDefinitions (380 enemy rows, with element presets in element_table.c)
class_table.cClassDefinitionTable (244 classes; learned Psynergy stored as 16-bit halfwords because ability IDs exceed 255)
djinn_table.cDjinnDefinitionTable (80 slots, 20 per element; 72 named Djinn, 18 per element, covering every TBS and TLA Djinni)
summon_table.cSummonDefinitionTable (29 summons: 16 single-element and 13 multi-element)
character_table.cCharacterDefinitionTable (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.cgmMainRoutineRun and gmReturnFromEngine across all 5 gameplay engines (plus four hidden DebugMode boot shortcuts)
game.c, game_internal.hParent translation unit #includeing the game_*.c parts below in ROM order
game_units.c, game_snapshot.cgmUnitCalculate from-scratch recalculation over CharacterUnits and active enemies, plus actor snapshot helpers
game_djinn.c, game_classes.cDjinn 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.c99-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.c15 packed inventory slots and global per-item rare artifact stock counters
game_battle_arithmetic.c, element_table.cgmBattleGetElementMultiplier, enemy elemental presets, hit, unleash, status, and heal formulas, and per-action synced gmBattleRandom
stubs.sJump-table stubs exported to other modules and scene overlays

Source files

src/game/

FileDescription
ability_table.cThe 734 abilities, by ability id.
character_table.cThe eight characters' definitions, by character id.
class_table.cThe 244 classes, by class id.
djinn_table.cThe 80 Djinn, 20 of each element in element order.
element_table.cThe 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.cThe 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.cEach 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.cThe game object: the rules of the party and its world.
game_battle_arithmetic.cBattle arithmetic: element multipliers, random rolls and success rates.
game_classes.cA 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.cThe 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.hWhat every part of the game object shares: its includes, the declarations its parts disagreed on and one inventory helper.
game_inventory.cItems and inventories: equipping, adding, removing, breaking and counting.
game_levels.cActions and Psynergy lists, characters, experience and levelling up.
game_party.cEnemy units, the active party, coins and counters, and summons.
game_snapshot.cThe 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.cThe 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.cThe 516 items, by item id.
main_routine.cThe main routine and scene changes: exits, returns from an engine, entering a scene.
rare_item_stock.cEach item's place among the shops' rare item counters, and two short lists a new game reads.
starting_equipment.c
summon_table.cThe summons: the order the Summon command lists them in, and each one's ability and the Djinn it needs.

include/game/

FileDescription
character.hThe 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.hThe eight playable characters' ids, with each one's Japanese name: one for each row of CharacterDefinitionTable in order.
game.hThe 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.hThe game flags' size, and the byte and bit of GameFlagBytes that hold a flag.
game_functions.hThe 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.hA unit's fifteen inventory slots: counting, finding, adding and taking items, and finding who in the party carries one.
item.hItems: their definitions, types, flags and effects.
main_routine.hThe main routine, which runs the game's engines one after another, and the scene changes between them.
main_routine_state.hThe values MainRoutineStateWork's fields hold.
stubs.hThe stub calls into the game module, as the other modules' code calls them.
system_call.hThe 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.