Skip to Content
The Alchemy Project

include/game/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. More…

Included by game.h and system_call.h.

Functions

NameDescription
struct DJINN_RECOVERY_TABLE *gmDjinnGetRecoveryTable (Sint32 enemySide)The game module's functions in the order of its stub table (src/game/stubs.s).
voidgmUnitCalculate (Sint32 unitId)Works out a unit's stats from its base stats, equipment, set Djinn, class and battle stat levels; its HP and PP keep their share of a new maximum.
struct ITEM_DEFINITION *gmItemGetDefinition (Sint32 item)Returns an item's definition; an inventory entry's other bits are ignored.
Sint32gmInventoryGetQuantity (Sint32 unitId, Sint32 slot)Returns how many of the item in slot the unit carries (0 for an empty slot).
Sint32gmInventoryAddItem (Sint32 unitId, Sint32 itemId)Gives a unit one item, joining its first matching stack (up to INVENTORY_STACK_MAX) or taking the first free slot.
Sint32gmPartyInventoryAdd (Sint32 itemId)Gives the item to the first party member with room.
Sint32gmInventoryFind (Sint32 unitId, Sint32 itemId)Returns the first slot holding itemId (any quantity, equipped or not), or -1.
Sint32gmPartyInventoryFindMember (Sint32 itemId)Returns who carries itemId, asking the leader first, or -1.
Sint32gmPartyInventoryRemove (Sint32 itemId)Removes one itemId from whoever carries it first; always returns 0.
Sint32gmInventoryEquip (Sint32 unitId, Sint32 slot)Equips the item in slot, clearing the equipped bit of the item of the same type it replaces.
Sint32gmInventoryRemove (Sint32 unitId, Sint32 slot)Takes one item out of slot, closing up the inventory when it was the last.
Sint32gmInventoryBreak (Sint32 unitId, Sint32 slot)Marks the item in slot broken; returns -1 for an empty slot.
Sint32gmInventoryRepair (Sint32 unitId, Sint32 slot)Clears the broken mark of the item in slot; returns -1 for an empty slot.
Uint8gmItemGetTargetMode (Sint32 itemId)Returns how the action an item performs when used picks its targets.
Sint32gmInventoryGetEquippedItem (struct UNIT *unit, Sint32 type)Returns the id of the unit's equipped item of type, or 0.
struct ABILITY_DEFINITION *gmAbilityGetDefinition (Sint32 abilityId)Returns the definition of ability abilityId (its low 14 bits); an id past the table gives the first.
Sint32gmUnitLearnPsynergy (Sint32 owner, Sint32 ability)Teaches character owner ability ability for good (or makes a class action permanent by clearing its marks), then rebuilds its list.
BoolgmUnitKnowsPsynergy (Sint32 unitId, Sint32 abilityId)Returns 1 when abilityId is in the unit's Psynergy list.
voidgmMainRoutineStateInitDefaults (void)Starts a new game's state: clears MainRoutineStateWork, the scene state and the snapshots, the flags and the characters by DMA, builds the characters, sets the defaults (the button layout, Felix and Jenna in the party, their first Psynergy, NEW_GAME_COINS, the message settings and the play time clock) and fills the two tables after the rare item stock.
struct LEVEL_UP_RESULT *gmUnitCheckLevelUp (Sint32 unitId, struct LEVEL_UP_RESULT *gains)Levels the character up once if it has the experience, and returns gains, or NULL.
voidgmPartyInitCharacters (void)Sets up all eight characters for a new game: names from the message table, starting equipment equipped, class and elements worked out, and levels raised to their starting level.
voidgmUnitLevelNoOperation (void)Unused: reserved entry; keeps its place in the stub table.
struct LEVEL_UP_RESULT *gmUnitTryLevelUp (Sint32 unitId, struct LEVEL_UP_RESULT *gains)Levels the character up once if its experience reaches the next level, and returns gains, or NULL.
voidgmRestartQuest (void)Starts a new game: clears the main routine's state and restarts at the opening.
Sint32gmUnitAddHp (Sint32 unitId, Sint32 delta)Adds delta to a unit's HP, kept between 0 and its maximum, updates its gauges and returns the new HP.
Sint16gmUnitAddPp (Sint32 unitId, Sint32 delta)Adds delta to unit unitId's PP, clamped to 0 and its maximum, recomputes its gauges and returns the new PP.
voidgmUnitRecalculateGauges (Sint32 unitId)Recomputes the HP and PP gauges of unitId from its current HP and PP, so that gmUnitCalculate keeps the same fractions.
voidgmUnitSetHp (struct UNIT *unit, Sint32 value)Sets the unit's HP, clamped to 0 and its maximum, and recomputes its HP and PP gauges.
voidgmUnitSetPp (struct UNIT *unit, Sint32 value)Sets the unit's PP, clamped to 0 and its maximum, and recomputes its HP and PP gauges.
BoolgmBattleUnitSet (Sint32 unitId, Sint32 enemyId, Sint32 suffix)Fills a battle unit with an enemy: its stats, its name with its suffix, its items, rewards and elements.
Sint32gmPartyCountMembers (void)Returns the number of party members, counted from its FLAG_IN_PARTY flags.
Sint32gmPartyAddMember (Sint32 unitId)Adds a character to the end of the party unless it is there already, and returns the party size.
Sint32gmPartyListMembers (Sint16 *unitIds)Writes the party members to unitIds, ended by BATTLE_UNIT_LIST_END, and returns how many there are.
Sint32gmEquipmentRollUnleash (struct UNIT *owner)Rolls whether a character's weapon unleashes, 5 percent a point of its chance.
Sint32gmPartyRemoveMember (Sint32 unitId)Takes character unitId out of the party: clears its game flag and closes the gap it leaves in MainRoutineStateWork.party.
Sint32gmUnitGetAttackElement (Sint32 unitId)Returns the element the unit attacks with (ELEMENT_NONE for none): an enemy's comes from its kind, a character's from its equipped weapon.
Sint32gmBattleRollEffectSuccess (Sint32 caster, Sint32 target, Sint32 element, Sint32 effectId, Sint32 successScale)Rolls whether effect effectId takes hold on target: it fails at once when there is nothing for it to do.
Sint32gmBattleCalculateAttackDamage (Sint32 attack, Sint32 defense, Sint32 addedPower, Sint32 elementDifference)Scales max(attack - defense, 0) plus twice the added power by half the element multiplier, then halves it.
Sint32gmBattleCalculatePsynergyPower (Sint32 power, Sint32 elementDifference, Sint32 powerMultiplier)Returns Psynergy's power times the element multiplier and powerMultiplier.
Sint32gmBattleCalculateRecovery (Sint32 power, Sint32 elementPower, Sint32 powerMultiplier)Returns the amount healed: power times powerMultiplier and the multiplier for the healer's element power above HEALING_BASE_POWER.
const struct ENEMY_DEFINITION *gmEnemyGetDefinition (Sint32 enemyId)Returns the row of enemy_table.c for enemyId (see ENEMY_ROW).
Uint32gmBattleRandom (void)The battle's random number generator, the same as syRandom with its own seed: returns bits 8 to 23 of the new seed.
Sint32gmDjinnGive (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Gives a Djinni to a unit.
Sint32gmDjinnSet (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Sets a ready Djinni on the unit, counts it and works out the unit's class again.
Uint32gmDjinnPutOnStandby (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Takes a set Djinni off the unit and works out its class again.
Sint32gmDjinnRecoveryRemove (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Takes the Djinni off its side's standby and recovery list, closing the gap.
Uint32 *gmDjinnRecoveryAddStandby (Uint32 unitId, Uint32 element, Uint32 djinnIndex)Puts a unit's Djinni at the end of its side's list on standby.
Sint32gmDjinnTransfer (Sint32 src, Sint32 element, Sint32 djinnIndex, Sint32 target)Moves a Djinni from one unit to another, set or on standby as it was.
Sint32gmSummonListLearned (Uint8 *output)Writes the summons the party can call to output, in menu order, ending with SUMMON_END, and returns how many.
const struct SUMMON_DEFINITION *gmSummonDefinitionGetNear (Uint32 summonId)Returns summon summonId's definition, or NULL past the last.
Uint16gmDjinnGetAbilityId (Uint32 element, Uint32 djinn)Returns the ability the Djinni performs when it is unleashed.
voidgmUnitLevelUpTo (Sint32 unitId, Sint32 targetLevel)Levels character unitId up one level at a time until targetLevel, then recomputes its stats.
Sint32gmUnitGetElementLevel (Sint32 unitId, Sint32 element)Returns how strongly a unit is attuned to element, its whole element level (a tenth of what gmUnitGetElementLevels counts), and 0 for ELEMENT_NONE.
Sint32gmDjinnRecoveryCountStandby (Uint8 *counts)Counts the party's Djinn on standby, and by element into counts when it is given.
Uint32gmDjinnIsSet (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Returns 1 when the Djinni is set on the unit.
BoolgmDjinnCanSet (Sint32 unitId, Sint32 element, Sint32 djinnIndex)Returns 1 when the unit holds the Djinni and it can be set: not set, not recovering and not held by a summon.
Sint32gmItemCanUnitEquip (Sint32 unitId, Sint32 itemId)Returns whether the character can equip the item: the bit of its equipMask for who the unit is, and 0 for anyone past PIERS.
Sint32gmItemIsCompatibleWithUnit (Sint32 unit, Sint32 item)Returns 1 for an item that is not a weapon or armor, and for those whether the character can equip it.
Sint32gmInventoryFindEquipped (Sint32 unitId, Sint32 type)Returns the slot of the equipped item of type, or -1.
Sint32gmPartyAdjustCoins (Sint32 amount)Adds amount to the party's coins, kept between 0 and COIN_MAX, and returns the new total.
Sint32gmItemGetEquipmentGroup (Sint32 itemId)Returns an item's equipment group from its type: weapons, tridents and the class-changing items count as weapons, armor, shields, helms, boots and shirts as armor, and anything else as neither.
Sint32gmItemAdjustRareItemStock (Sint32 itemId, Sint32 delta)Adds delta to how many of a rare item the shops may sell, and returns the new count; ordinary items have none.
Sint32gmInventoryCount (Sint32 unitId)Counts filled inventory slots up to the first empty slot; the inventory is kept closed up, so this is how many items the unit carries.
BoolgmPartyInventoryHasSpace (void)Returns 1 when the leader or any party member has a free inventory slot.
Uint32gmUnitGetExperienceForLevel (Sint32 unitId, Sint32 level)Returns the experience a character needs for level: 0 below level 1, and -1 for an enemy or a level past UNIT_LEVEL_MAX.
voidgmPartyRestoreHpPp (Sint32 cureConditions)Restores every party member's HP and PP; with cureConditions 1 it also cures poison and haunting.
voidgmPartyRestorePpInLighthouse (void)Restores the PP of each party member whose element group's lighthouse the party is inside: Venus or Mars for Isaac, Garet, Felix and Jenna, Mercury or Jupiter for the others.
voidgmPartySetLeaderJenna (void)Makes Jenna the leader.
voidgmPartySetLeaderFelix (void)Makes Felix the leader, with Jenna and Sheba out of the party.
voidgmPartyGivePiersDjinn (void)Gives Piers his two Mercury Djinn, Spring and Shade (Mercury 9 and 10), set, then evens out the party's Djinn and recalculates its members.
voidgmUnitReservedNoOperation (void)Does nothing; nothing calls it or its stub.
voidgmDataTransferApply (Uint8 *save, Sint32 byPassword)The data transfer from Golden Sun ("Transfer data from Golden Sun", MsgTransferDataFromGoldenSun): copies a The Broken Seal save's Djinn, six of its flags, its coins, its options (when it came by link rather than by password) and its four units into this game's state.
voidgmPartyAddIsaacsParty (void)Isaac's party joins: the transferred Djinn flags move to their places, Isaac, Garet, Ivan and Mia join with their Djinn evened out and restored, a missing Djinni of each element is picked, and the transferred items and coins are given.
Sint32gmDjinnGiveToParty (Sint32 element, Sint32 djinn)Gives a newly found Djinni to the party member holding the fewest Djinn who has room, on standby.
Sint32gmPartySumDjinnCounts (Sint32 element)Returns how many Djinn of element the party holds, or of all elements for -1.
Sint32gmPartyAdjustShopCredit (Sint32 amount)Adds amount to the shop credit, kept between 0 and COIN_MAX, and returns the new credit.
Sint32gmPartyAdjustShopGifts (Sint32 amount)Adds amount to the Game Tickets given, kept between 0 and SHOP_GIFTS_MAX, and returns the new count.
Sint32gmInventoryCheckDiscard (Sint32 unitId, Sint32 slot)Returns 0 when the item in slot may be dropped, or else why not, as INVENTORY_REFUSAL bits: the item is indispensable, it is equipped and cannot be taken off, or the slot is empty.
Sint32gmInventoryCheckUnequip (Sint32 unitId, Sint32 slot)Returns 0 when the item in slot may be taken off, or else why not: it is equipped and cannot be (INVENTORY_REFUSE_CANNOT_UNEQUIP), or the slot is empty.
Sint32gmInventoryDiscard (Sint32 unitId, Sint32 slot)Removes one item as gmInventoryRemove does, and puts a rare item back into circulation (its counter goes up by one) for the shops to sell.
BoolgmBattleIsReviveEffect (Sint32 effectId)Returns 1 for the revive effects, which only work on a downed unit.
voidgmUnitRefreshPsynergy (Sint32 unitId)Works out a character's class, Psynergy and base elements again.
Uint32gmPartyGetAverageLevel (void)Returns the average level of the party members, rounded down (0 with no party members).
voidgmUnitUpdateClass (Sint32 unitId)Works out a character's class again after its Djinn or its class-changing item change, then its Psynergy list and its base elements.
Sint32gmInventoryCountItem (Sint32 unitId, Sint32 itemId)Counts matching nonstackable items, or the quantity in the first matching stack.
Sint32gmPartyInventoryCountItem (Sint32 itemId)Counts itemId across the party.
Sint32gmPartyInventoryDiscard (Sint32 itemId)Discards one itemId from whoever carries it first, as gmInventoryDiscard does; always returns 0.
voidgmFlagRefreshLureCap (void)Sets FLAG_LURE_CAP when any party member has the Lure Cap (the one item with EQUIP_EFFECT_LURE) equipped, and clears it otherwise.
Sint32gmEquipmentGetUnleashRateBonus (struct UNIT *unit)Returns the unleash chance, in percent, that a unit's equipment adds (EQUIP_EFFECT_ADD_UNLEASH_CHANCE).
Uint32gmBuildStampGetTime (void)Encodes the build stamp's time, which a new game takes as its start stamp and the file list compares saves with.
Sint32gmPartyInventoryCountFreeSlots (void)Returns the free inventory slots of the whole party.
voidgmInventorySnapshotSave (void)Saves the inventories of Felix's party (FELIX to PIERS), the shortcuts and the party order as the leader and Moapa set off on the Trial Road (scShamanVillageTakeLeftPath and its twin), then drops every weapon, armor, shield and helm not equipped (and, in every edition but the Japanese, every item that raises a stat), sets FLAG_TRIAL_ROAD_HOLDS_EQUIPMENT and restores everyone's HP and PP.
voidgmInventorySnapshotRestore (void)Gives back the inventories, shortcuts and party order gmInventorySnapshotSave put aside, empties the snapshot and clears FLAG_TRIAL_ROAD_HOLDS_EQUIPMENT: at the end of the Trial Road, and from the clear scene.
Sint32gmPartyFindOwnerWithAction (Sint32 action)Returns the first party member who knows Psynergy action, or -1.
Sint32gmPartyInventoryFindRoom (Sint32 itemId)Returns the first party member with room for itemId, found by giving it and taking it back, or -1.
voidgmSummonLearn (Sint32 summonId)Lets the party call summon summonId from now on, setting its bit in the party's summon mask.
voidgmDjinnSetAllForParty (void)Counts the Djinn recovery down, then sets every Djinni each party member holds and can set, taking it off the recovery list.
Sint32gmInventoryClearSlot (Sint32 unitId, Sint32 slot)gmInventoryClearSlot through its stub call: empties an inventory slot and returns 2.
voidgmPartyDrainPp (Sint32 count)Takes count PP from the party, one at a time from the fullest member.
FIXEDgmPartyGetPpRatio (void)Returns the party's PP over its maximum PP, in 16.16; 0 with no members.
voidgmDataTransferGiveDefaultDjinn (void)Stands in for transferred data when the player transfers none: unless the transferred Djinn are already set, sets the party aside, makes Isaac's party the party, gives it Flint and Fizz, then hands out DEFAULT_TRANSFER_DJINN random Djinn of The Broken Seal's still unowned, keeping the elements' counts within one, each with its chance in DataTransferDjinnChances; then moves the Djinn flags to the transferred ones and puts the party back.
Sint32gmOwnerSumDjinnCounts (Sint32 unitId, Sint32 element)Returns how many Djinn of element the unit holds, or of every element for -1.
voidgmClearDataApply (Uint8 *save)Carries Clear Data over to a new quest: the options, coins and each unit's base stats, level and experience.
struct CLASS_DEFINITION *gmClassGetDefinition (Sint32 classId)Returns class classId's definition: its series, element requirements, stat multipliers and the Psynergy it teaches by level.
const struct DJINN_DEFINITION *gmDjinnGetDefinition (Uint32 element, Uint32 djinn)Returns the definition of Djinni djinn of element; anything out of range gives DJINNI_FLINT's.

Description

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. It is for the units that must not see that inline: the scenes Apojii Islands, Naribwe and Jupiter Lighthouse's side halls, which have it through system_call.h. game.h includes it for everyone else.

Functions in detail

gmUnitAddHp

Sint32 gmUnitAddHp(Sint32 unitId, Sint32 delta)

Adds delta to a unit's HP, kept between 0 and its maximum, updates its gauges and returns the new HP.

Referenced by scFieldUnitAddHp().

Definition at line 105 of file game_functions.h.

gmUnitAddPp

Sint16 gmUnitAddPp(Sint32 unitId, Sint32 delta)

Adds delta to unit unitId's PP, clamped to 0 and its maximum, recomputes its gauges and returns the new PP.

Referenced by dbPsynergyTestDamageAndAfflictParty(), dbShopTestDamageAndAfflictParty(), gmPartyDrainPpFromFullest(), scFieldUnitAddPp(), scJupiterLighthouseIsaacAndIvanAreHurt() and scWorldMapSetUpShip().

Definition at line 108 of file game_functions.h.

gmUnitSetHp

void gmUnitSetHp(struct UNIT *unit, Sint32 value)

Sets the unit's HP, clamped to 0 and its maximum, and recomputes its HP and PP gauges.

Definition at line 114 of file game_functions.h.

gmUnitSetPp

void gmUnitSetPp(struct UNIT *unit, Sint32 value)

Sets the unit's PP, clamped to 0 and its maximum, and recomputes its HP and PP gauges.

Definition at line 117 of file game_functions.h.

gmPartyAdjustShopCredit

Sint32 gmPartyAdjustShopCredit(Sint32 amount)

Adds amount to the shop credit, kept between 0 and COIN_MAX, and returns the new credit.

Definition at line 278 of file game_functions.h.

gmPartyAdjustShopGifts

Sint32 gmPartyAdjustShopGifts(Sint32 amount)

Adds amount to the Game Tickets given, kept between 0 and SHOP_GIFTS_MAX, and returns the new count.

Definition at line 281 of file game_functions.h.