Skip to Content
The Alchemy Project

Game Logic & Tables

This page is a guide to the games/tbs/src/game/ folder of the Alchemy project. It holds the core RPG rules, data tables, and top-level engine switcher that drive Golden Sun: The Broken Seal.

The seven master definition tables for items, abilities, enemies, classes, Djinn, summons, and characters all live here. Alongside them sit UNIT stat recalculation, all 4,096 game flags, and the shared combat math used across battles and menus. This folder also houses gmMainRoutineRun, which switches between the game's engines.

When Isaac gains a level, a Djinni is swapped to reach a new class, or the strength of a weapon's hit is examined, the numbers come from these files. The sections below give the seven definition tables and a complete file map. 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 & TBS row counts
item_table.cItemDefinitionTable (items plus spare slots 269–323)
ability_table.cAbilityDefinitions (519 rows; 339 named in ability_ids.h: Psynergy, unleashes, Djinn, and enemy skills)
enemy_table.cEnemyDefinitions (165 enemies: base stats, elemental Power and Resist, 8-move AI list, and XP, coins, and drops)
class_table.cClassDefinitionTable (203 classes: series, stat multipliers, and Psynergy learning lists)
djinn_table.cDjinnDefinitionTable (28 named TBS Djinn, 7 per element)
summon_table.cSummonDefinitionTable (16 single-element summons)
character_table.cCharacterDefinitionTable (8 rows: Isaac through Mia populated, an early row for Jenna, and empty slots for Felix, Sheba, and Piers; see How The Lost Age Evolved from The Broken Seal)

File map

File(s)Role
main_routine.cgmMainRoutineRun and gmReturnFromEngine top-level engine dispatcher
game_units.cgmUnitGet (contains an unused return-address read removed in TLA) and gmUnitCalculate from-scratch stat recalculation
game_djinn.c, game_classes.cDjinn state transitions and gmClassDetermine (the highest two element levels select class series and tier)
game_levels.c, game_party.c, game_inventory.c99-level XP curves (reused at New Game so future party members like Mia roll starting stats up front), party flags 0–7, roster and coins, 15 packed inventory slots, and global rare-item counters
game_flags.csyGameFlag* helpers over the 4,096-bit GameFlags array (include/flags.h, including the two 256-bit auto-clearing temp ranges). Moved to system/system_flags.c in TLA.
game_battle_arithmetic.cShared hit, unleash, status, damage, elemental multiplier, and healing formulas, plus the deterministic gmBattleRandom PRNG
stubs.sJump-table stubs exported to other modules and scene overlays

Source files

src/game/

FileDescription
ability_table.cThe 519 abilities, by ability id: Psynergy, the party's and enemies' moves, item uses, Djinn and summons.
character_table.cThe eight party members' growth curves, element bonuses, starting levels and starting equipment.
class_table.cThe 203 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 and the power and resistance curve.
enemy_table.cThe 165 enemies, by enemy id less ENEMY_ID_FIRST.
experience_table.cEach character's lighthouse group and the experience each 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.cElement levels and classes.
game_djinn.cDjinn: definitions, setting and standby, and their counts.
game_flags.cThe game flags: bits, bytes and nibbles.
game_internal.hWhat every part of the game object shares: its includes and the inventory helper two parts use.
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.cEquipping a given item, and the equipment put aside for the Colosso.
game_units.cThe party's units and their stats, a new game, the prologue, HP and PP.
item_table.cEvery item, by item id: its price, what it is and who can equip it, the Attack and Defense it adds, its unleash, what it does while worn, and the ability it is used for.
main_routine.cThe main routine and scene changes: exits, returns from battle, entering.
rare_item_stock.cWhich items the shops keep a stock of in their Artifacts, and where.
starting_equipment.cThe characters a new game sets up with their starting equipment, class and level.
summon_table.cThe 16 summons: the standby Djinn each one needs, and the order the summon menus list them in.

include/game/

FileDescription
character.hThe definitions of characters, classes, Djinn and enemies, and a level up's result.
character_ids.hCharacter numbers, with each character's Japanese name, and the portraits.
game.hThe game's rules and the tables they read: items, summons, abilities, Djinn, classes, elements, enemies, the game flags and the shops' rare item stock.
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 (src/game/stubs.s).
inventory.hOverflowItem, an item slot the spoils code uses when items are handed out.
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 main routine's state: the transition data the main routine reads between engines and the state every engine shares, which a save file keeps.
stubs.hParty members, items, Djinn and game-state operations.
system_call.hThe system call layer: an inline for each of the thirteen main-image functions below that the scene, menu and debug overlays import, which every overlay call of them goes through.