Skip to Content
The Alchemy Project

src/game/game_levels.c

Actions and Psynergy lists, characters, experience and levelling up. More…

  • #include "text/msg_ids.h"

Included by game.c.

Macros

NameDescription
#definePSYNERGY_ACTION_AT (slots, index) ((slots)[index].encodedAction)

Functions

NameDescription
ABILITY_DEFINITION *gmAbilityGetDefinition (Sint32 abilityId)Returns the definition of ability abilityId (its low 14 bits); an id past the table gives the first.
Sint32gmPartyFindOwnerWithAction (Sint32 action)Returns the first party member who knows Psynergy action, or -1.
BoolgmUnitKnowsPsynergy (Sint32 unitId, Sint32 abilityId)Returns 1 when abilityId is in the unit's Psynergy list.
Sint32gmUnitRebuildPsynergyList (Sint32 unitId)Rebuilds a character's Psynergy list: what it learned for good stays, in order, then come its class's Psynergy up to its level and its equipped items' Psynergy, while the list has room.
Sint32gmUnitLearnPsynergy (Sint32 unitId, Sint32 ability)Teaches character unitId Psynergy ability for good (or makes one its class or an item gives permanent by clearing its marks), then rebuilds its list.
LEVEL_UP_RESULT *gmUnitCheckLevelUp (Sint32 unitId, LEVEL_UP_RESULT *gains)Levels the character up once if it has the experience, and returns gains, or NULL.
const CHARACTER_DEFINITION *gmCharacterGetDefinition (Sint32 index)Returns character index's definition: growth curves, starting level and equipment.
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.
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.
LEVEL_UP_RESULT *gmUnitLevelUp (Sint32 unitId, LEVEL_UP_RESULT *gains)Raises a character one level (up to UNIT_LEVEL_MAX), adding to each base stat the growth between the two points of its growth curve around the new level (a point every GROWTH_BAND_LEVELS levels), a twentieth of it per level with a random part.
LEVEL_UP_RESULT *gmUnitTryLevelUp (Sint32 unitId, LEVEL_UP_RESULT *gains)Levels the character up once if its experience reaches the next level, and returns gains, or NULL.
voidgmUnitLevelUpTo (Sint32 unitId, Sint32 targetLevel)Levels character unitId up one level at a time until targetLevel, then recomputes its stats.

Description

Actions and Psynergy lists, characters, experience and levelling up. Part of game.c.

Macros in detail

PSYNERGY_ACTION_AT

#define PSYNERGY_ACTION_AT(slots, index) ((slots)[index].encodedAction)

#define PSYNERGY_ACTION_AT(slots, index) (((Uint16 *)(slots))[(index) * 2])

Referenced by gmUnitRebuildPsynergyList().

Definition at lines 9 and 11 of file game_levels.c.

Functions in detail

gmAbilityGetDefinition

ABILITY_DEFINITION *gmAbilityGetDefinition(Sint32 abilityId)

Returns the definition of ability abilityId (its low 14 bits); an id past the table gives the first. Every module reads an ability through its stub call, gmAbilityGetDefinitionStub.

References AbilityDefinitions and Sint32.

Referenced by gmItemGetTargetMode().

Definition at line 17 of file game_levels.c.

gmPartyFindOwnerWithAction

Sint32 gmPartyFindOwnerWithAction(Sint32 action)

Returns the first party member who knows Psynergy action, or -1.

References gmPartyListMembers(), gmUnitKnowsPsynergy() and Sint32.

Referenced by scEasternAlhafraGiveUpOnMastBlock(), scEasternAlhafraStepByCabinDoor(), scLemuriaTryStuckDoor() and scNaribweRoomsNextPowerToGain().

Definition at line 32 of file game_levels.c.

gmUnitKnowsPsynergy

Bool gmUnitKnowsPsynergy(Sint32 unitId, Sint32 abilityId)

Returns 1 when abilityId is in the unit's Psynergy list. Called by the scripts that check whether a party member knows a Psynergy (fdPartyCheckShortcut).

References gmUnitGet() and Sint32.

Referenced by gmPartyFindOwnerWithAction().

Definition at line 51 of file game_levels.c.

gmUnitRebuildPsynergyList

Sint32 gmUnitRebuildPsynergyList(Sint32 unitId)

Rebuilds a character's Psynergy list: what it learned for good stays, in order, then come its class's Psynergy up to its level and its equipped items' Psynergy, while the list has room.

References gmClassGetDefinition(), gmItemGetDefinition(), gmUnitGet() and Sint32.

Referenced by gmUnitUpdateClass().

Definition at line 73 of file game_levels.c.

gmUnitLearnPsynergy

Sint32 gmUnitLearnPsynergy(Sint32 unitId, Sint32 ability)

Teaches character unitId Psynergy ability for good (or makes one its class or an item gives permanent by clearing its marks), then rebuilds its list. Returns the Psynergy's place in the list, or -1 when the list is full.

References gmUnitGet(), gmUnitRefreshPsynergy() and Sint32.

Referenced by gmMainRoutineStateInitDefaults().

Definition at line 190 of file game_levels.c.

gmUnitCheckLevelUp

LEVEL_UP_RESULT *gmUnitCheckLevelUp(Sint32 unitId, LEVEL_UP_RESULT *gains)

Levels the character up once if it has the experience, and returns gains, or NULL.

References gmUnitTryLevelUp() and Sint32.

Definition at line 245 of file game_levels.c.

gmCharacterGetDefinition

const CHARACTER_DEFINITION *gmCharacterGetDefinition(Sint32 index)

Returns character index's definition: growth curves, starting level and equipment.

References CharacterDefinitionTable and Sint32.

Referenced by gmPartyInitCharacters(), gmUnitGetElementLevels() and gmUnitLevelUp().

Definition at line 252 of file game_levels.c.

gmPartyInitCharacters

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

References CharacterNewGameIds, gmCharacterGetDefinition(), gmInventoryAddItem(), gmInventoryEquip(), gmUnitCalculate(), gmUnitGet(), gmUnitLevelUpTo(), gmUnitUpdateClass(), mnMessageDecodeRawUnboundedStub() and Sint32.

Referenced by gmMainRoutineStateInitDefaults().

Definition at line 263 of file game_levels.c.

gmUnitLevelNoOperation

void gmUnitLevelNoOperation(void)

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

Definition at line 331 of file game_levels.c.

gmUnitGetExperienceForLevel

Uint32 gmUnitGetExperienceForLevel(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.

References CharacterLevelExpTable, gmUnitGet() and Sint32.

Referenced by gmUnitLevelUp(), gmUnitTryLevelUp() and scClearApplyImportedData().

Definition at line 337 of file game_levels.c.

gmUnitLevelUp

LEVEL_UP_RESULT *gmUnitLevelUp(Sint32 unitId, LEVEL_UP_RESULT *gains)

Raises a character one level (up to UNIT_LEVEL_MAX), adding to each base stat the growth between the two points of its growth curve around the new level (a point every GROWTH_BAND_LEVELS levels), a twentieth of it per level with a random part. Writes the unit's level, base stats and, if short, its experience, then rebuilds its Psynergy and stats. The gains go to gains, which is returned.

References gmCharacterGetDefinition(), gmUnitCalculate(), gmUnitGet(), gmUnitGetExperienceForLevel(), gmUnitRefreshPsynergy(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().

Referenced by gmUnitLevelUpTo() and gmUnitTryLevelUp().

Definition at line 362 of file game_levels.c.

gmUnitTryLevelUp

LEVEL_UP_RESULT *gmUnitTryLevelUp(Sint32 unitId, LEVEL_UP_RESULT *gains)

Levels the character up once if its experience reaches the next level, and returns gains, or NULL.

References gmUnitGet(), gmUnitGetExperienceForLevel(), gmUnitLevelUp() and Sint32.

Referenced by gmUnitCheckLevelUp().

Definition at line 458 of file game_levels.c.

gmUnitLevelUpTo

void gmUnitLevelUpTo(Sint32 unitId, Sint32 targetLevel)

Levels character unitId up one level at a time until targetLevel, then recomputes its stats.

References gmUnitCalculate(), gmUnitGet(), gmUnitLevelUp() and Sint32.

Referenced by dbIncreaseItemAndLevelRaiseMemberLevel(), dbPsynergyTestRaisePartyLevels(), dbShopTestRaisePartyLevels() and gmPartyInitCharacters().

Definition at line 474 of file game_levels.c.