Skip to Content
The Alchemy Project

src/game/game_units.c

The party's units and their stats, a new game, the prologue, HP and PP. More…

Included by game.c.

Structures

NameDescription
structSCENE_STATE_VIEWEWRAM from SceneLocalState on, as a new game clears it: the scene's state, the equipment put aside for the Colosso and the actors kept across a battle.
structSTAT_STATEThe running totals gmUnitCalculate builds a unit's stats in.

Macros

NameDescription
#defineNEW_GAME_SPEECH 1A new game's settings: voice sounds "On" (MsgSpeechSetting + 1) and "Window brightness" one step brighter than the hue's own colour.
#defineNEW_GAME_WINDOW_BRIGHTNESS (WINDOW_BRIGHTNESS_NEUTRAL + 1)
#defineUNIT_STAT_DIFF (a, b) ((a) - (b) < 0 ? (b) - (a) : (a) - (b))The distance between a and b, |a - b|.
#defineSCALE_EFFECT (kind) ((kind) - EQUIP_EFFECT_SCALE_HP)A scaling effect's number among the eight, from EQUIP_EFFECT_SCALE_HP.
#defineLIGHTHOUSE_PP_REGEN 4The PP an Adept regains at the end of each battle turn, on top of its own, inside the lighthouse of its element.
#defineSTAT_STAGE_EIGHTHS 8Each battle stage of Attack, Defense or Agility moves it by an eighth.
#defineBUILD_STAMP_MARK 0x1000Set in every build stamp's time.
#defineBUILD_STAMP_DEBUG 0xffff8000Set on top of the time in a debug build's stamp (DebugMode): bit 15, sign-extended, so that its stamp is above every release build's, and a debug build takes a release's saves for older ones.
#definePROLOGUE_COINS 300The coins the party sets out with after the prologue.
#defineUNIT_DEFINE_SET (name, field, maximum)Each sets the unit's HP or PP, clamped to 0 and its maximum, and recomputes its HP and PP gauges.
#defineUNIT_DEFINE_ADD (type, name, field, maximum)Each adds delta to the HP or PP of unit unitId, clamped to 0 and its maximum, recomputes its gauges and returns the new value, as type.

Functions

NameDescription
voidgmRestartQuest (void)Starts a new game: clears the main routine's state and restarts at the opening.
DJINN_RECOVERY_TABLE *gmDjinnGetRecoveryTable (Sint32 enemySide)Returns a side's Djinn recovery table, its standby Djinn and their turns to recover: the party's (DJINN_RECOVERY_PARTY), kept in MainRoutineStateWork, or the opponent's (DJINN_RECOVERY_OPPONENT), in OPPONENT_RECOVERY_UNIT's record.
Uint32gmPartyGetAverageLevel (void)Returns the average level of the party members, rounded down (0 with no party members).
UNIT *gmUnitGet (Uint32 unitId)Returns the unit of unitId: ISAAC to PIERS the characters, the six from FIRST_ENEMY_UNIT the enemies of the current battle; NULL for anything else.
const ENEMY_DEFINITION *gmEnemyGetDefinition (Sint32 enemyId)Returns the definition of enemy enemyId; enemy ids start past the eight characters', so that one id names any unit.
voidgmMemoryCopyBytesDirectional (Uint8 *first, Uint8 *second, Sint32 count, Sint32 direction)Unused: copies count bytes from first to second when direction is set, and from second to first otherwise.
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.
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.
Uint32gmBuildStampGetTime (void)Encodes the build stamp's time, which a new game takes as its start stamp and the file list compares saves with.
voidgmMainRoutineStateInitDefaults (void)Clears the game's state and sets a new game's defaults: Isaac alone in the party, the standard buttons, the message speed and the odds of the Lucky Medals fountain.
voidgmPartyStartChildhood (void)Sets FLAG_CHILDHOOD and recomputes Isaac, Garet and Jenna, whose classes then take their childhood forms.
voidgmPartyEndChildhood (void)The party after the prologue: Isaac and Garet healed and given the Short Sword, Move and Retreat for Isaac, Move for Garet, Mind Read for Ivan, and PROLOGUE_COINS.
voidgmPartyRestoreHpPp (Sint32 cureConditions)Restores every party member's HP and PP; with cureConditions 1 it also cures poison and haunting.
voidgmPartyRestorePpInLighthouse (void)Refills the PP of each party member whose lighthouse group (CharacterLighthouseGroupTable) holds the lighthouse the party is inside.
voidgmUnitGaugeNoOperation (void)Unused: reserved entry; keeps its place in the stub table.
voidgmUnitRecalculateGauges (Sint32 unitId)Recomputes the HP and PP gauges of unitId from its current HP and PP, so that gmUnitCalculate keeps the same fractions.
static inline Sint32gmUnitClampGaugeValue (Sint32 value, Sint32 maximum)Clamps a new HP or PP value to 0 and the maximum.

Description

The party's units and their stats, a new game, the prologue, HP and PP. Part of game.c.

Macros in detail

NEW_GAME_SPEECH

#define NEW_GAME_SPEECH 1

A new game's settings: voice sounds "On" (MsgSpeechSetting + 1) and "Window brightness" one step brighter than the hue's own colour.

Referenced by gmMainRoutineStateInitDefaults().

Definition at line 46 of file game_units.c.

NEW_GAME_WINDOW_BRIGHTNESS

#define NEW_GAME_WINDOW_BRIGHTNESS (WINDOW_BRIGHTNESS_NEUTRAL + 1)

Referenced by gmMainRoutineStateInitDefaults().

Definition at line 47 of file game_units.c.

UNIT_STAT_DIFF

#define UNIT_STAT_DIFF(a, b) ((a) - (b) < 0 ? (b) - (a) : (a) - (b))

The distance between a and b, |a - b|.

Referenced by gmUnitCalculate().

Definition at line 50 of file game_units.c.

SCALE_EFFECT

#define SCALE_EFFECT(kind) ((kind) - EQUIP_EFFECT_SCALE_HP)

A scaling effect's number among the eight, from EQUIP_EFFECT_SCALE_HP.

Referenced by gmUnitCalculate().

Definition at line 163 of file game_units.c.

LIGHTHOUSE_PP_REGEN

#define LIGHTHOUSE_PP_REGEN 4

The PP an Adept regains at the end of each battle turn, on top of its own, inside the lighthouse of its element.

Referenced by gmUnitCalculate().

Definition at line 166 of file game_units.c.

STAT_STAGE_EIGHTHS

#define STAT_STAGE_EIGHTHS 8

Each battle stage of Attack, Defense or Agility moves it by an eighth.

Referenced by gmUnitCalculate().

Definition at line 168 of file game_units.c.

BUILD_STAMP_MARK

#define BUILD_STAMP_MARK 0x1000

Set in every build stamp's time.

Referenced by gmBuildStampGetTime().

Definition at line 533 of file game_units.c.

BUILD_STAMP_DEBUG

#define BUILD_STAMP_DEBUG 0xffff8000

Set on top of the time in a debug build's stamp (DebugMode): bit 15, sign-extended, so that its stamp is above every release build's, and a debug build takes a release's saves for older ones.

Referenced by gmBuildStampGetTime().

Definition at line 537 of file game_units.c.

PROLOGUE_COINS

#define PROLOGUE_COINS 300

The coins the party sets out with after the prologue.

Referenced by gmPartyEndChildhood().

Definition at line 643 of file game_units.c.

UNIT_DEFINE_SET

#define UNIT_DEFINE_SET(name, field, maximum)

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

Definition at line 796 of file game_units.c.

UNIT_DEFINE_ADD

#define UNIT_DEFINE_ADD(type, name, field, maximum)

Each adds delta to the HP or PP of unit unitId, clamped to 0 and its maximum, recomputes its gauges and returns the new value, as type.

Definition at line 812 of file game_units.c.

Functions in detail

gmRestartQuest

void gmRestartQuest(void)

Starts a new game: clears the main routine's state and restarts at the opening.

References gmMainRoutineRunStub() and gmMainRoutineStateInitDefaults().

Definition at line 54 of file game_units.c.

gmDjinnGetRecoveryTable

DJINN_RECOVERY_TABLE *gmDjinnGetRecoveryTable(Sint32 enemySide)

Returns a side's Djinn recovery table, its standby Djinn and their turns to recover: the party's (DJINN_RECOVERY_PARTY), kept in MainRoutineStateWork, or the opponent's (DJINN_RECOVERY_OPPONENT), in OPPONENT_RECOVERY_UNIT's record.

References gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by gmDjinnCanSet(), gmDjinnRecoveryAddStandby(), gmDjinnRecoveryCountStandby(), gmDjinnRecoveryRemove(), gmSummonListLearned(), scBattleArenaReceivePartyRecords() and scBattleArenaSendPartyRecords().

Definition at line 63 of file game_units.c.

gmPartyGetAverageLevel

Uint32 gmPartyGetAverageLevel(void)

Returns the average level of the party members, rounded down (0 with no party members).

References gmPartyCountMembers(), gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by scStuccoRoomsCOfferLuckyDice().

Definition at line 72 of file game_units.c.

gmUnitGet

UNIT *gmUnitGet(Uint32 unitId)

Returns the unit of unitId: ISAAC to PIERS the characters, the six from FIRST_ENEMY_UNIT the enemies of the current battle; NULL for anything else.

References CharacterUnits.

Referenced by dbIncreaseItemAndLevelRaiseMemberLevel(), dbIncreaseItemAndLevelRunLevelEditor(), dbMenuTestDamageAndAfflictParty(), gmBattleRollEffectSuccess(), gmBattleUnitSet(), gmDjinnCanSet(), gmDjinnGetRecoveryTable(), gmDjinnGive(), gmDjinnGiveToParty(), gmDjinnIsSet(), gmDjinnPutOnStandby(), gmDjinnSet(), gmDjinnTransfer(), gmFlagRefreshLureCap(), gmInventoryAddAndEquip(), gmInventoryAddItem(), gmInventoryBreak(), gmInventoryCheckDiscard(), gmInventoryCount(), gmInventoryCountItem(), gmInventoryDiscard(), gmInventoryEquip(), gmInventoryFind(), gmInventoryFindEquipped(), gmInventoryGetQuantity(), gmInventoryRemove(), gmInventoryRepair(), gmInventorySnapshotRestore(), gmInventorySnapshotSave(), gmItemCanUnitEquip(), gmPartyEndChildhood(), gmPartyGetAverageLevel(), gmPartyInitCharacters(), gmPartyRestoreHpPp(), gmPartyRestorePpInLighthouse(), gmPartySumDjinnCounts(), gmUnitCalculate(), gmUnitCalculateBaseElements(), gmUnitGetAttackElement(), gmUnitGetElementLevel(), gmUnitGetExperienceForLevel(), gmUnitKnowsPsynergy(), gmUnitLearnPsynergy(), gmUnitLevelUp(), gmUnitLevelUpTo(), gmUnitRecalculateGauges(), gmUnitRefreshPsynergy(), gmUnitTryLevelUp(), gmUnitUpdateClass(), scBabiPalaceRestorePartyAndInventory() and 11 more.

Definition at line 88 of file game_units.c.

gmEnemyGetDefinition

const ENEMY_DEFINITION *gmEnemyGetDefinition(Sint32 enemyId)

Returns the definition of enemy enemyId; enemy ids start past the eight characters', so that one id names any unit.

References EnemyDefinitions and Sint32.

Referenced by gmBattleAbilityIsWeakToEffect(), gmEnemyGetAttackElement(), gmUnitCalculateBaseElements() and gmUnitGetElementLevels().

Definition at line 122 of file game_units.c.

gmMemoryCopyBytesDirectional

void gmMemoryCopyBytesDirectional(Uint8 *first, Uint8 *second, Sint32 count, Sint32 direction)

Unused: copies count bytes from first to second when direction is set, and from second to first otherwise.

References Sint32.

Definition at line 143 of file game_units.c.

gmUnitCalculate

void gmUnitCalculate(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.

References gmClassGetDefinition(), gmDjinnGetDefinition(), gmFlagGet(), gmItemGetDefinition(), gmUnitGet(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().

Referenced by dbIncreaseItemAndLevelRaiseMemberLevel(), dbIncreaseItemAndLevelRunLevelEditor(), dbMenuTestRecalculateParty(), gmBattleUnitSet(), gmInventoryEquip(), gmInventoryRemove(), gmInventorySnapshotRestore(), gmInventorySnapshotSave(), gmPartyEndChildhood(), gmPartyInitCharacters(), gmPartyStartChildhood(), gmUnitLevelUp(), gmUnitLevelUpTo(), scMercuryLighthouseMiaJoinsAfterRescue() and scVaultReturnIsaacsDjinni().

Definition at line 172 of file game_units.c.

gmFlagRefreshLureCap

void gmFlagRefreshLureCap(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.

References gmFlagClear(), gmFlagSet(), gmItemGetDefinition(), gmPartyCountMembers(), gmUnitGet(), MainRoutineStateWork and Sint32.

Definition at line 503 of file game_units.c.

gmBuildStampGetTime

Uint32 gmBuildStampGetTime(void)

Encodes the build stamp's time, which a new game takes as its start stamp and the file list compares saves with.

References DebugMode, Sint32 and syResourceGetTableEntry().

Referenced by gmMainRoutineStateInitDefaults() and scInit().

Definition at line 541 of file game_units.c.

gmMainRoutineStateInitDefaults

void gmMainRoutineStateInitDefaults(void)

Clears the game's state and sets a new game's defaults: Isaac alone in the party, the standard buttons, the message speed and the odds of the Lucky Medals fountain.

References BupSlot, CharacterUnits, GameFlagBytes, gmBuildStampGetTime(), gmPartyAddMember(), gmPartyInitCharacters(), IdleSleepEnabled, IdleTicks, MainRoutineStateWork, PlayTimeTicks, SceneLocalState, Sint32 and syDMAWait().

Referenced by gmRestartQuest() and scInit().

Definition at line 570 of file game_units.c.

gmPartyStartChildhood

void gmPartyStartChildhood(void)

Sets FLAG_CHILDHOOD and recomputes Isaac, Garet and Jenna, whose classes then take their childhood forms.

References gmFlagSet(), gmUnitCalculate() and gmUnitUpdateClass().

Referenced by scInit().

Definition at line 631 of file game_units.c.

gmPartyEndChildhood

void gmPartyEndChildhood(void)

The party after the prologue: Isaac and Garet healed and given the Short Sword, Move and Retreat for Isaac, Move for Garet, Mind Read for Ivan, and PROLOGUE_COINS.

References gmFlagClear(), gmFlagSet(), gmInventoryEquip(), gmUnitCalculate(), gmUnitGet(), gmUnitLearnPsynergy(), gmUnitUpdateClass(), MainRoutineStateWork and Sint32.

Referenced by scInit().

Definition at line 648 of file game_units.c.

gmPartyRestoreHpPp

void gmPartyRestoreHpPp(Sint32 cureConditions)

Restores every party member's HP and PP; with cureConditions 1 it also cures poison and haunting.

References gmPartyCountMembers(), gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by gmInventorySnapshotSave(), scColosseumNavampaMatchPlayPostBattleReunion(), scColossoRestoreMatchResult(), scInit(), scTimberRoomsBCReportToFaran(), scValePlazaDepartForQuest() and scWorldMapMeetFlint().

Definition at line 694 of file game_units.c.

gmPartyRestorePpInLighthouse

void gmPartyRestorePpInLighthouse(void)

Refills the PP of each party member whose lighthouse group (CharacterLighthouseGroupTable) holds the lighthouse the party is inside. The aeries of Venus and Mercury Lighthouse call it.

References CharacterLighthouseGroupTable, gmFlagGet(), gmPartyCountMembers(), gmUnitGet(), MainRoutineStateWork and Sint32.

Referenced by scMercuryLighthouseAeriePartyArrives() and scVenusLighthouseAerieCombineSaturosAndMenardi().

Definition at line 720 of file game_units.c.

gmUnitGaugeNoOperation

void gmUnitGaugeNoOperation(void)

Unused: reserved entry; keeps its place in the stub table.

Definition at line 764 of file game_units.c.

gmUnitRecalculateGauges

void gmUnitRecalculateGauges(Sint32 unitId)

Recomputes the HP and PP gauges of unitId from its current HP and PP, so that gmUnitCalculate keeps the same fractions.

References gmUnitGet() and Sint32.

Referenced by scBabiPalaceRestorePartyAndInventory().

Definition at line 770 of file game_units.c.

gmUnitClampGaugeValue

static inline Sint32 gmUnitClampGaugeValue(Sint32 value, Sint32 maximum)

Clamps a new HP or PP value to 0 and the maximum.

References Sint32.

Definition at line 779 of file game_units.c.