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:
| File | Symbol & TBS row counts |
|---|---|
item_table.c | ItemDefinitionTable (items plus spare slots 269–323) |
ability_table.c | AbilityDefinitions (519 rows; 339 named in ability_ids.h: Psynergy, unleashes, Djinn, and enemy skills) |
enemy_table.c | EnemyDefinitions (165 enemies: base stats, elemental Power and Resist, 8-move AI list, and XP, coins, and drops) |
class_table.c | ClassDefinitionTable (203 classes: series, stat multipliers, and Psynergy learning lists) |
djinn_table.c | DjinnDefinitionTable (28 named TBS Djinn, 7 per element) |
summon_table.c | SummonDefinitionTable (16 single-element summons) |
character_table.c | CharacterDefinitionTable (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.c | gmMainRoutineRun and gmReturnFromEngine top-level engine dispatcher |
game_units.c | gmUnitGet (contains an unused return-address read removed in TLA) and gmUnitCalculate from-scratch stat recalculation |
game_djinn.c, game_classes.c | Djinn state transitions and gmClassDetermine (the highest two element levels select class series and tier) |
game_levels.c, game_party.c, game_inventory.c | 99-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.c | syGameFlag* 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.c | Shared hit, unleash, status, damage, elemental multiplier, and healing formulas, plus the deterministic gmBattleRandom PRNG |
stubs.s | Jump-table stubs exported to other modules and scene overlays |
Source files
| File | Description |
|---|---|
ability_table.c | The 519 abilities, by ability id: Psynergy, the party's and enemies' moves, item uses, Djinn and summons. |
character_table.c | The eight party members' growth curves, element bonuses, starting levels and starting equipment. |
class_table.c | The 203 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 and the power and resistance curve. |
enemy_table.c | The 165 enemies, by enemy id less ENEMY_ID_FIRST. |
experience_table.c | Each character's lighthouse group and the experience each 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 | Element levels and classes. |
game_djinn.c | Djinn: definitions, setting and standby, and their counts. |
game_flags.c | The game flags: bits, bytes and nibbles. |
game_internal.h | What every part of the game object shares: its includes and the inventory helper two parts use. |
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 | Equipping a given item, and the equipment put aside for the Colosso. |
game_units.c | The party's units and their stats, a new game, the prologue, HP and PP. |
item_table.c | Every 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.c | The main routine and scene changes: exits, returns from battle, entering. |
rare_item_stock.c | Which items the shops keep a stock of in their Artifacts, and where. |
starting_equipment.c | The characters a new game sets up with their starting equipment, class and level. |
summon_table.c | The 16 summons: the standby Djinn each one needs, and the order the summon menus list them in. |
| File | Description |
|---|---|
character.h | The definitions of characters, classes, Djinn and enemies, and a level up's result. |
character_ids.h | Character numbers, with each character's Japanese name, and the portraits. |
game.h | The 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.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 (src/game/stubs.s). |
inventory.h | OverflowItem, an item slot the spoils code uses when items are handed out. |
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 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.h | Party members, items, Djinn and game-state operations. |
system_call.h | The 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. |