spoils.c
The spoils: coins, experience, items and level ups.
games/tbs/src/battle/battle/spoils.c on GitHub
The spoils: coins, experience, items and level ups. Part of battle.c, the battle object, compiled only through it.
Functions
BattleSpoils_RankItem
u32 BattleSpoils_RankItem(u32 inventoryEntry)
Returns an item's rank among the spoils, higher for a better item and 0 for none: an indispensable item first, then a rare item, then the higher item id. The rank's bits: 10 ITEM_INDISPENSABLE | 9 ITEM_RARE | 8..0 the item id. Called by BattleEnemy_RecordDefeat, to keep the best four drops, and by Battle_AwardSpoils, to hand them out best first.
Used by BattleEnemy_RecordDefeat, Battle_AwardSpoils.
BattleSpoils_Clear
void BattleSpoils_Clear(void)
Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem. Called once by Battle_RunEncounter as the battle opens.
Used by Battle_RunEncounter.
BattleEnemy_CalculateCoinReward
static __inline__ s32 BattleEnemy_CalculateCoinReward(struct BattleUnit *unit, u16 *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. Used by BattleEnemy_RecordDefeat.
Used by BattleEnemy_RecordDefeat.
BattleEnemy_CalculateExperienceReward
static __inline__ s32 BattleEnemy_CalculateExperienceReward(struct BattleUnit *unit, u16 *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 of its own. Used by BattleEnemy_RecordDefeat.
Used by BattleEnemy_RecordDefeat.
BattleEnemy_RecordDefeat
s32 BattleEnemy_RecordDefeat(s32 unitId, s32 djinnBonus)
Counts a fallen enemy and adds its coins, experience and perhaps its item to the spoils. Returns -1 for a party unit and -2 for a party member fought as an enemy, else 0. It notes the class for the victory message (firstDefeated, defeatState). In a monster battle it adds nothing more; otherwise it sets the class's ENEMY_DEFEATED_FLAG, adds the rewards (with the Djinn bonus, djinnBonus nonzero, the rolls above) and rolls the item: 1 in 2^(itemChance - 1), two powers likelier with the bonus. An item not yet among the four kept replaces the lowest ranked, if it ranks higher. Called as each enemy falls by BattleEv_DispatchQueued and BattleEvent_Playback.
Used by BattleEv_DispatchQueued, BattleEvent_Playback.
Battle_AwardSpoils
void Battle_AwardSpoils(void)
Hands out the spoils after a victory: the experience to each party member still standing, with every level gained and what it brings, then the coins, then the items best first. Each level up shows its message, every Psynergy newly learned and each stat that rose. An item the inventory cannot take goes to gOverflowItem and ends the handing out. Called by Battle_RunEncounter once the battle is won. Changes the members' experience, levels and stats, the party's coins and inventory.
Used by Battle_RunEncounter.
Battle_ReservedNoOp2A08
void Battle_ReservedNoOp2A08(void)
Does nothing; the debug battle menu (DebugBattle_RunMenu) calls it.
Used by DebugBattle_RunMenu.