Alchemy
Loading...
Searching...
No Matches

formation.c File Reference

Enemy formations: the enemies chosen, levelled and lettered. More...

Go to the source code of this file.

Data Structures

struct  FormationCandidate
 A formation that may be chosen for the party's level: its record and its enemies' average level. More...
struct  BattleBaseStats
 A copy of a unit's base stats, from baseHp to its element stats, kept while its level is adjusted: BattleEnemy_AdjustLevel reads only the stats it changes, for their 70 percent floors. More...

Macros

#define FORMATION_COUNT   380
 The rows of gBattleFormation_Records.
#define ENEMY_NAME_SUFFIX_COUNT   9

Functions

s32 BattleFormation_AverageLevel (s32 recordId)
 Returns a formation's average enemy level, for the monster battles to choose by.
s32 BattleFormation_SelectLevelMatchedCandidate (s32 *outMargin)
 Chooses a monster battle's formation for the party's level, and returns it with the levels its enemies must gain in outMargin.
s32 BattleEnemy_AdjustLevel (s32 owner, s32 levels)
 Raises an enemy by levels, or lowers it for a negative count: each base stat changes by a fixed amount a level, kept between 70 percent of what it was and its cap.
s32 BattleEnemy_ClaimNameLetter (s32 classId, s32 unused)
 Gives an enemy of the class its name letter, which tells it from others of its kind, and returns the letter's number for BattleUnitSetFar.
s32 BattleEnemy_ReleaseNameLetter (s32 actorId)
 Frees a departing enemy's name letter for the next of its class, reading the letter back from the end of its name.
s32 BattleEnemy_LetterFirstOfClass (s32 classId)
 Gives the first enemy of the class on the field the first letter (0), appended to its name, once a second of its class arrives.
s32 BattleGroupRandom (s32 recordId)
 Returns the class id of a random member of the formation, among those that may appear (maximum count above 0); formation 1 stands in for an id out of range.
s32 BattleFormation_BuildEnemyList (s32 recordId)
 Builds the battle's enemies from formation recordId and returns how many there are.

Detailed Description

Enemy formations: the enemies chosen, levelled and lettered.

Part of battle.c, the battle object, compiled only through it.

Definition in file formation.c.

Macro Definition Documentation

◆ FORMATION_COUNT

#define FORMATION_COUNT   380

The rows of gBattleFormation_Records.

Definition at line 8 of file formation.c.

Referenced by BattleFormation_BuildEnemyList(), BattleFormation_SelectLevelMatchedCandidate(), and BattleGroupRandom().

◆ ENEMY_NAME_SUFFIX_COUNT

#define ENEMY_NAME_SUFFIX_COUNT   9

Definition at line 13 of file formation.c.

Referenced by BattleEnemy_ClaimNameLetter().

Function Documentation

◆ BattleFormation_AverageLevel()

s32 BattleFormation_AverageLevel ( s32 recordId)

Returns a formation's average enemy level, for the monster battles to choose by.

Returns -1 for a formation with no required member, -2 when it holds an enemy above level 3 the party has not defeated (ENEMY_DEFEATED_FLAG, unless flag 0x174 is set), and -3 when it has no member. Called by BattleFormation_SelectLevelMatchedCandidate for every formation.

Definition at line 24 of file formation.c.

Referenced by BattleFormation_AverageLevel(), and BattleFormation_SelectLevelMatchedCandidate().

◆ BattleFormation_SelectLevelMatchedCandidate()

s32 BattleFormation_SelectLevelMatchedCandidate ( s32 * outMargin)

Chooses a monster battle's formation for the party's level, and returns it with the levels its enemies must gain in outMargin.

The target is the active members' average level plus the monster battles won in a row (FLAG_MONSTER_BATTLE_WINS), between 1 and 99; a formation qualifies when its average level is at most 3 above it, and one of up to 32 qualifying is chosen at random. With none, it returns formation 1 and a margin of 0. Called by BattleFormation_BuildEnemyList under FLAG_MONSTER_BATTLE; clears the defeated flags of the classes in gBattleFormation_LevelMatchedEnemies, excluding them unless flag 0x174 bypasses the defeated-enemy check.

Definition at line 102 of file formation.c.

Referenced by BattleFormation_BuildEnemyList(), and BattleFormation_SelectLevelMatchedCandidate().

◆ BattleEnemy_AdjustLevel()

s32 BattleEnemy_AdjustLevel ( s32 owner,
s32 levels )

Raises an enemy by levels, or lowers it for a negative count: each base stat changes by a fixed amount a level, kept between 70 percent of what it was and its cap.

A level is worth 9.7 HP, 1.5 PP, 12.3 Attack, 3.3 Defense, 5.1 Agility and 15 power in each element; HP and PP are capped at 9999, the other stats at 999 and power at 200. Changes the unit's base stats and level and works out its stats again (UnitCalc). Called by BattleFormation_BuildEnemyList for each enemy of a monster battle.

Definition at line 202 of file formation.c.

Referenced by BattleEnemy_AdjustLevel(), and BattleFormation_BuildEnemyList().

◆ BattleEnemy_ClaimNameLetter()

s32 BattleEnemy_ClaimNameLetter ( s32 classId,
s32 unused )

Gives an enemy of the class its name letter, which tells it from others of its kind, and returns the letter's number for BattleUnitSetFar.

The letters are digits from 1 abroad and the alphabet in Japanese. The class's first enemy gets ENEMY_NAME_SUFFIX_COUNT, which BattleUnitSetFar takes as no letter. Its second gets letter 1 with bit 15 (0x8001), telling the caller to give the first letter 0 (BattleEnemy_LetterFirstOfClass); later ones take the next free letter, wrapping. Returns -1 when five classes are already listed. Called by BattleFormation_BuildEnemyList for each enemy and by BattleTargetExec for an enemy called into the battle. Changes BattleWork's enemyClasses, summonChannels, summonMasks and summonCount.

Definition at line 269 of file formation.c.

Referenced by BattleEnemy_ClaimNameLetter(), BattleFormation_BuildEnemyList(), and BattleTargetExec().

◆ BattleEnemy_ReleaseNameLetter()

s32 BattleEnemy_ReleaseNameLetter ( s32 actorId)

Frees a departing enemy's name letter for the next of its class, reading the letter back from the end of its name.

Does nothing for a unit that is not an enemy, a class not listed or one with no letters given. Clears the letter's bit in BattleWork.summonMasks. Called by BattleActor_RemoveFromLists.

Definition at line 320 of file formation.c.

Referenced by BattleActor_RemoveFromLists(), and BattleEnemy_ReleaseNameLetter().

◆ BattleEnemy_LetterFirstOfClass()

s32 BattleEnemy_LetterFirstOfClass ( s32 classId)

Gives the first enemy of the class on the field the first letter (0), appended to its name, once a second of its class arrives.

Called by BattleFormation_BuildEnemyList and BattleTargetExec when BattleEnemy_ClaimNameLetter returns bit 15. Writes BattleUnit.name.

Definition at line 362 of file formation.c.

Referenced by BattleEnemy_LetterFirstOfClass(), BattleFormation_BuildEnemyList(), and BattleTargetExec().

◆ BattleGroupRandom()

s32 BattleGroupRandom ( s32 recordId)

Returns the class id of a random member of the formation, among those that may appear (maximum count above 0); formation 1 stands in for an id out of range.

Called by BattleTargetExec when an enemy calls for help.

Definition at line 407 of file formation.c.

Referenced by BattleGroupRandom(), and BattleTargetExec().

◆ BattleFormation_BuildEnemyList()

s32 BattleFormation_BuildEnemyList ( s32 recordId)

Builds the battle's enemies from formation recordId and returns how many there are.

Each member comes its minimum number of times, plus a random number more up to its maximum while the six sprite slots hold them (a large enemy takes two). The formation's battle type orders them: shuffled kinds, each kind together (FORMATION_SHUFFLED), interleaved at random (FORMATION_INTERLEAVED), or in the record's order. Under FLAG_MONSTER_BATTLE the formation is chosen for the party's level instead, and each enemy raised to it. An empty or out-of-range formation becomes formation 1. Called once by Battle_RunEncounter. Fills the enemy units from FIRST_ENEMY_UNIT, with their name letters, and sets BattleWork's battleType, firstDefeated, defeatState and the name-letter lists.

Definition at line 451 of file formation.c.

Referenced by Battle_RunEncounter(), and BattleFormation_BuildEnemyList().