Skip to Content
The Alchemy Project

src/battle/battle_spoils.c

The spoils: coins, experience, items and level ups. More…

Included by battle.c.

Macros

NameDescription
#defineSPOILS_RANK_CEILING (1 << 30)Above every item's rank: the search for the lowest of the spoils' four starts here.
#defineFIRST_DIGIT_BASE JAPANESE_OR('A', '1')The name suffixes the scan reads back (NAME_SUFFIX_COUNT of them): the digits 1 to 9 outside Japan, and the letters A to Z in the Japanese release.
#defineFIRST_DIGIT_COUNT JAPANESE_OR(26, 9)

Enumerations

NameDescription
enumLEVEL_UP_GAIN { GAIN_HP, GAIN_PP, GAIN_ATTACK, GAIN_DEFENSE, GAIN_AGILITY, G … }What a level up raised, as places in the halfwords gmUnitTryLevelUp fills (LEVEL_UP_RESULT's fields, read here as an array): each is shown when it is not 0.

Functions

NameDescription
Uint32btSpoilsRankItem (Uint32 inventoryEntry)Returns an item's rank among the spoils, by which the four kept are chosen and handed out best first: its item id (INVENTORY_ITEM_ID_MASK's nine bits), with ITEM_RARE's bit above it and ITEM_INDISPENSABLE's above that; 0 for none.
voidbtSpoilsClear (void)Empties the battle's spoils and the party's pending item.
Sint32btStringFindFirstDigit (Uint8 *name)Returns an enemy name's suffix: its first digit less one (its first letter's place in the alphabet in Japanese), or FIRST_DIGIT_COUNT when it has none.
static __inline__ Sint32btEnemyCalculateCoinReward (UNIT *unit, Uint16 *reward)Returns an enemy's coins with the Djinn bonus: its own, plus a six-sided die for every ten levels and one more, at least 30 percent of its own.
static __inline__ Sint32btEnemyCalculateExperienceReward (UNIT *unit, Uint16 *reward)Returns an enemy's experience with the Djinn bonus: its own plus a four-sided die for every ten levels and one more, at least 30 percent more.
Sint32btEnemyRecordDefeat (Sint32 unitId, Sint32 djinnBonus)Counts a fallen enemy and adds its spoils, The Broken Seal's btEnemyRecordDefeat with the battle state from its heap slot.
voidbtAwardSpoils (void)Hands out the spoils after a victory: experience to each party member still standing, with every level gained, then the coins, then the items best first.

Description

The spoils: coins, experience, items and level ups. Part of battle.c.

Macros in detail

SPOILS_RANK_CEILING

#define SPOILS_RANK_CEILING (1 << 30)

Above every item's rank: the search for the lowest of the spoils' four starts here.

Referenced by btEnemyRecordDefeat().

Definition at line 43 of file battle_spoils.c.

FIRST_DIGIT_BASE

#define FIRST_DIGIT_BASE JAPANESE_OR('A', '1')

The name suffixes the scan reads back (NAME_SUFFIX_COUNT of them): the digits 1 to 9 outside Japan, and the letters A to Z in the Japanese release.

Referenced by btStringFindFirstDigit().

Definition at line 64 of file battle_spoils.c.

FIRST_DIGIT_COUNT

#define FIRST_DIGIT_COUNT JAPANESE_OR(26, 9)

Referenced by btStringFindFirstDigit().

Definition at line 65 of file battle_spoils.c.

Enumerations in detail

LEVEL_UP_GAIN

enum LEVEL_UP_GAIN

What a level up raised, as places in the halfwords gmUnitTryLevelUp fills (LEVEL_UP_RESULT's fields, read here as an array): each is shown when it is not 0.

EnumeratorValueDescription
GAIN_HP2
GAIN_PP
GAIN_ATTACK
GAIN_DEFENSE
GAIN_AGILITY
GAIN_LUCK
GAIN_COUNT

Definition at line 6 of file battle_spoils.c.

Functions in detail

btSpoilsRankItem

Uint32 btSpoilsRankItem(Uint32 inventoryEntry)

Returns an item's rank among the spoils, by which the four kept are chosen and handed out best first: its item id (INVENTORY_ITEM_ID_MASK's nine bits), with ITEM_RARE's bit above it and ITEM_INDISPENSABLE's above that; 0 for none.

References gmItemGetDefinitionStub().

Referenced by btAwardSpoils() and btEnemyRecordDefeat().

Definition at line 21 of file battle_spoils.c.

btSpoilsClear

void btSpoilsClear(void)

Empties the battle's spoils and the party's pending item. Called by btRun.

References MainRoutineStateWork and Sint32.

Referenced by btRun().

Definition at line 46 of file battle_spoils.c.

btStringFindFirstDigit

Sint32 btStringFindFirstDigit(Uint8 *name)

Returns an enemy name's suffix: its first digit less one (its first letter's place in the alphabet in Japanese), or FIRST_DIGIT_COUNT when it has none.

References Sint32.

Referenced by btEnemyRecordDefeat().

Definition at line 69 of file battle_spoils.c.

btEnemyCalculateCoinReward

static __inline__ Sint32 btEnemyCalculateCoinReward(UNIT *unit, Uint16 *reward)

Returns an enemy's coins with the Djinn bonus: its own, plus a six-sided die for every ten levels and one more, at least 30 percent of its own.

References Sint32.

Referenced by btEnemyRecordDefeat().

Definition at line 83 of file battle_spoils.c.

btEnemyCalculateExperienceReward

static __inline__ Sint32 btEnemyCalculateExperienceReward(UNIT *unit, Uint16 *reward)

Returns an enemy's experience with the Djinn bonus: its own plus a four-sided die for every ten levels and one more, at least 30 percent more.

References Sint32.

Referenced by btEnemyRecordDefeat().

Definition at line 101 of file battle_spoils.c.

btEnemyRecordDefeat

Sint32 btEnemyRecordDefeat(Sint32 unitId, Sint32 djinnBonus)

Counts a fallen enemy and adds its spoils, The Broken Seal's btEnemyRecordDefeat with the battle state from its heap slot. This game also keeps the last two defeated enemies (their ids and btStringFindFirstDigit's first digit of their names, alternating slots, with a count up to 2) and sets the defeated flag only for the enemies that have one, below ENEMY_DEFEATED_FLAG_COUNT.

References btEnemyCalculateCoinReward(), btEnemyCalculateExperienceReward(), btSpoilsRankItem(), btStringFindFirstDigit(), gmBattleRandomStub(), gmEnemyGetDefinitionStub(), gmUnitGet(), Sint32, syGameFlagGet() and syGameFlagSet().

Referenced by btPlaybackRun() and btPlaybackRunAll().

Definition at line 124 of file battle_spoils.c.

btAwardSpoils

void btAwardSpoils(void)

Hands out the spoils after a victory: experience to each party member still standing, with every level gained, then the coins, then the items best first.

References btMessageWaitForAdvance(), btSpoilsRankItem(), btUnitListLiving(), btUnitListLivingWithReserve(), gmPartyAdjustCoinsStub(), gmPartyInventoryAddStub(), gmUnitGet(), gmUnitTryLevelUpStub(), MainRoutineStateWork, mnBattleMessageShowAndWaitStub(), mnMessageArgumentClearAllStub(), mnMessageArgumentPushStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease() and sySoundPlayStub().

Referenced by btRun().

Definition at line 237 of file battle_spoils.c.