44 for (index = 3; index >= 0; index--)
60 for (rollIndex = 0; rollIndex < (
u8)(unit->
level / 10U) + 1; rollIndex++)
61 bonus += ((
Random16() * 6) >> 16) + 1;
63 minimumBonus = base * 3 / 10;
64 if (bonus < minimumBonus)
79 for (rollIndex = 0; rollIndex < (
u8)(unit->
level / 10U) + 1; rollIndex++)
80 bonus += ((
Random16() * 4) >> 16) + 1;
82 minimumBonus = base * 3 / 10;
83 if (bonus < minimumBonus)
104 s32 itemOrClassIndex;
107 s32 lowestItemPriority;
114 if (unitId >= 0 && unitId < 8)
119 itemOrClassIndex = 0;
122 if (++itemOrClassIndex > 5)
126 if (itemOrClassIndex != 6)
127 classSlot = itemOrClassIndex;
133 if (classSlot < battle->firstDefeated)
143 if (djinnBonus != 0) {
144 if (enemy->
coins != 0)
155 itemOrClassIndex = 0;
158 if (++itemOrClassIndex > 3)
160 }
while (spoils->
items[itemOrClassIndex] != enemy->
item);
162 if (itemOrClassIndex != 4)
172 lowestItemPriority = 0x40000000;
173 for (itemOrClassIndex = 0; itemOrClassIndex <= 3; itemOrClassIndex++) {
175 if (itemPriority < lowestItemPriority) {
176 lowestItemPriority = itemPriority;
177 lowestSlot = itemOrClassIndex;
205 s32 highestItemPriority;
224 for (unitIndex = 0; unitIndex < count; unitIndex++) {
225 unitId = unitIds[unitIndex];
238 for (abilityIndex = 0; abilityIndex < 32; abilityIndex++) {
241 for (oldAbilityIndex = 0; oldAbilityIndex < 32; oldAbilityIndex++) {
242 if (encodedAbility ==
246 if (oldAbilityIndex == 32) {
258 if ((
s16)gains.
hp != 0) {
263 if ((
s16)gains.
pp != 0) {
268 if ((
s16)gains.
atk != 0) {
273 if ((
s16)gains.
def != 0) {
278 if ((
s16)gains.
agi != 0) {
291 if (spoils->
coins != 0) {
301 highestItemSlot = -1;
302 highestItemPriority = -1;
303 for (slot = 0; slot <= 3; slot++) {
304 if (spoils->
items[slot] != 0) {
306 if (itemPriority >= highestItemPriority) {
307 highestItemPriority = itemPriority;
308 highestItemSlot = slot;
312 if (highestItemSlot == -1)
318 *overflowItem = spoils->
items[highestItemSlot];
321 spoils->
items[highestItemSlot] = 0;
s32 BattleParty_ListLivingUnits(s32 sideMask, u16 *unitIds)
Lists the units still standing (HP above 0) on the sides in sideMask (BATTLE_SIDE_PARTY,...
s32 BattlePresentation_WaitForAdvance(void)
Shows the bobbing arrow at the message window and waits for the player to go on (B,...
What every part of the battle object shares: its includes, in their original order,...
#define VALUE_ABILITY_NAME
#define ENEMY_DEFEATED_FLAG(classId)
The game flag of an enemy class the party has defeated, set by BattleEnemy_RecordDefeat outside the m...
struct BattleWork * gBattleWork
struct BattleUnit * UnitGetFar(u32 owner)
struct ItemDefinition * Item_GetDirectFar(s32 item)
s32 GameFlag_TestFar(s32 flag)
struct LevelUpResult * Unit_TryLevelUpFar(s32 owner_id, struct LevelUpResult *value)
s32 GameFlag_SetBitFar(s32 flag)
s32 PartyInventory_AddFar(s32 item_id)
const u8 * Enemy_GetDefinitionFar(s32 selector)
s32 BattleRandomFar(void)
s32 Party_AdjustCoinsFar(s32 amount)
void AudioCommand_PlayFar(s32 id)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
void UiText_ShowMessageAndWaitCoreFar(s32 argument)
void UiWork_ClearValueNameTablesFar(void)
#define FLAG_MONSTER_BATTLE
The link lobby's battle against a monster when no opponent is linked: formations matched to the party...
struct GameState gGameState
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
@ ITEM_RARE
selects the shop's rare item offers
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
void MemFree(void *buffer)
u32 BattleSpoils_RankItem(u32 inventoryEntry)
Ranks an item among the spoils, 0 for none: an indispensable item first, then a rare item,...
void BattleSpoils_Clear(void)
Empties the battle's spoils (BattleWork.spoils) and gGameState.pendingItem.
void Battle_AwardSpoils(void)
Hands out the spoils after a victory: the experience to each party member still standing,...
s32 BattleEnemy_RecordDefeat(s32 unitId, s32 djinnBonus)
Counts a fallen enemy and adds its coins, experience and perhaps its item to the spoils.
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 leve...
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...
void Battle_ReservedNoOp2A08(void)
Does nothing; the debug battle menu (DebugBattle_RunMenu) calls it.
A battle's spoils so far: coins, experience, enemies defeated and up to four items.
s32 defeated
enemies defeated
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
struct OwnerActionSlot actionSlots[32]
The action list: Psynergy taught for good, then the class's and the equipment's (Unit_RefreshPsynergy...
u8 classId
Who the unit is: a character's id (ISAAC to JENNA, below 8) or an enemy's id (BattleUnitSet).
u32 experience
a character's experience points
u8 classIndex
The character's class, worked out from its Djinn (Unit_UpdateClass); 0 marks an enemy,...
u8 level
1 to 99 for a character
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
u16 firstDefeated
The enemyClasses index of the first class to fall; 6 for none.
u16 enemyClasses[6]
The enemy classes met so far, for their name letters, and the first class to fall (firstDefeated).
u16 defeatState
DEFEAT_ONE, DEFEAT_SEVERAL or DEFEAT_BY_PARTY_MEMBER.
struct BattleSpoils spoils
An enemy's definition: its level and stats, items, element preset, the actions it chooses from and it...
s16 item
the item it may leave, 0 for none
s16 itemChance
The chance of the item: 1 in 2 to the power itemChance - 1, two powers better with BattleEnemy_Record...
u16 experience
experience won
u16 pendingItem
given on returning to the field if the party has room
A level up's result: the level reached, an ability learned and the gain in each stat.
u16 encodedAction
bits: 15 from the class | 14 from an equipped item | 13..0 action id.