src/battle/battle_formation.c
Enemy formations: choosing, levelling and building a formation's enemies and assigning their name suffixes. More…
Included by battle.c.
Structures
| Name | Description | |
|---|---|---|
struct | FORMATION_CANDIDATE | A formation that may be chosen for the party's level, with its enemies' average level. |
Macros
| Name | Description | |
|---|---|---|
#define | FORMATION_FALLBACK 1 | The formation a battle falls back on when its own is out of range or has no sure member: the unused Echo alone, the first of the Djinni battles. |
#define | FORMATION_SHUFFLE_SWAPS 10 | The random swaps that shuffle a FORMATION_LAYOUT_SHUFFLED formation. |
#define | FORMATION_NO_SURE_MEMBER -1 | btFormationAverageLevel's reasons a formation may not be chosen: no member always appears, an enemy in it is one the party has not defeated, or no member has a definition. |
#define | FORMATION_UNMET_ENEMY -2 | |
#define | FORMATION_NO_ENEMY -3 | |
#define | FORMATION_POOL_SIZE 32 | The most formations a monster battle chooses among. |
#define | FORMATION_LEVEL_MARGIN 3 | How far above the party's level a monster battle's formation may be. |
#define | FORMATION_SCORE_ABOVE_ALL 999 | Above any formation's average level: where the search for the pool's lowest entry starts. |
#define | HP_GAIN_TENTHS 97 | What an enemy gains a level (btEnemyAdjustLevel), each stat in tenths of a point: 9.7 HP, 1.5 PP, 12.3 Attack, 3.3 Defense and 5.1 Agility; and its element power in whole points. |
#define | PP_GAIN_TENTHS 15 | |
#define | ATTACK_GAIN_TENTHS 123 | |
#define | DEFENSE_GAIN_TENTHS 33 | |
#define | AGILITY_GAIN_TENTHS 51 | |
#define | ELEMENT_POWER_GAIN 15 | |
#define | NAME_SUFFIX_MASK_BITS 32 | The suffixes a kind's mask holds, one bit each. |
#define | ENEMY_SLOTS_TAKEN (enemyId) (2 - (btSpriteIsSmall(enemyId) != 0)) | The enemy sprite slots an enemy takes: one for a small enemy, two for any other. |
Functions
| Name | Description | |
|---|---|---|
Sint32 | btFormationAverageLevel (Sint32 formationId) | Returns a formation's average enemy level for the monster battles, or a negative reason it may not be chosen. |
Sint32 | btFormationSelectLevelMatchedCandidate (Sint32 *outMargin) | Chooses a monster battle's formation for the party's level plus its winning streak, at random among those at most FORMATION_LEVEL_MARGIN above it, and returns it with the levels its enemies must gain in outMargin. |
UNREAD_RESULT | btEnemyAdjustLevel (Sint32 unitId, Sint32 levels) | Raises an enemy by levels, or lowers it for a negative count, each stat by a fixed amount a level and no lower than 70 percent of what it was. |
void | btUnitStrengthen (Sint32 unitId) | Raises a unit's base HP by half and base Attack and Defense by a quarter, at least 70 percent of the old values and at most UNIT_ENEMY_HP_MAX and UNIT_STAT_MAX: an enemy on the HARD level (FLAG_HARD_LEVEL). |
Sint32 | btEnemyClaimNameLetter (Sint32 enemyId, Sint32 unused) | Gives an enemy its name suffix, which tells it from others of its kind: digits abroad and the alphabet in Japanese. |
UNREAD_RESULT | btEnemyReleaseNameLetter (Sint32 unitId) | Frees a departing enemy's name suffix for the next of its kind. |
Sint32 | btEnemyLetterFirstOfKind (Sint32 enemyId) | Gives the first enemy of the kind on the field the first suffix (0), appended to its name, once a second of its kind arrives. |
Sint32 | btFormationGetRandomMember (Sint32 formationId) | Returns the enemy id of a random member of the formation that may appear. |
Sint32 | btFormationBuildEnemyList (Sint32 formationId) | Builds the battle's enemies from a formation and returns how many there are: each member its fewest times and at random up to its most while the sprite slots hold them, laid out as the formation says. |
Description
Enemy formations: choosing, levelling and building a formation's enemies and
assigning their name suffixes. Part of battle.c.
Macros in detail
FORMATION_FALLBACK
#define FORMATION_FALLBACK 1
The formation a battle falls back on when its own is out of range or has no sure member: the unused Echo alone, the first of the Djinni battles.
Referenced by btFormationBuildEnemyList(), btFormationGetRandomMember() and btFormationSelectLevelMatchedCandidate().
Definition at line 6 of file battle_formation.c.
FORMATION_SHUFFLE_SWAPS
#define FORMATION_SHUFFLE_SWAPS 10
The random swaps that shuffle a FORMATION_LAYOUT_SHUFFLED formation.
Referenced by btFormationBuildEnemyList().
Definition at line 8 of file battle_formation.c.
FORMATION_NO_SURE_MEMBER
#define FORMATION_NO_SURE_MEMBER -1
btFormationAverageLevel's reasons a formation may not be chosen: no member
always appears, an enemy in it is one the party has not defeated, or no
member has a definition.
Referenced by btFormationAverageLevel() and btFormationSelectLevelMatchedCandidate().
Definition at line 13 of file battle_formation.c.
FORMATION_UNMET_ENEMY
#define FORMATION_UNMET_ENEMY -2
Referenced by btFormationAverageLevel().
Definition at line 14 of file battle_formation.c.
FORMATION_NO_ENEMY
#define FORMATION_NO_ENEMY -3
Referenced by btFormationAverageLevel().
Definition at line 15 of file battle_formation.c.
FORMATION_POOL_SIZE
#define FORMATION_POOL_SIZE 32
The most formations a monster battle chooses among.
Referenced by btFormationSelectLevelMatchedCandidate().
Definition at line 70 of file battle_formation.c.
FORMATION_LEVEL_MARGIN
#define FORMATION_LEVEL_MARGIN 3
How far above the party's level a monster battle's formation may be.
Referenced by btFormationSelectLevelMatchedCandidate().
Definition at line 72 of file battle_formation.c.
FORMATION_SCORE_ABOVE_ALL
#define FORMATION_SCORE_ABOVE_ALL 999
Above any formation's average level: where the search for the pool's lowest entry starts.
Referenced by btFormationSelectLevelMatchedCandidate().
Definition at line 75 of file battle_formation.c.
HP_GAIN_TENTHS
#define HP_GAIN_TENTHS 97
What an enemy gains a level (btEnemyAdjustLevel), each stat in tenths of a
point: 9.7 HP, 1.5 PP, 12.3 Attack, 3.3 Defense and 5.1 Agility; and its
element power in whole points.
Referenced by btEnemyAdjustLevel().
Definition at line 211 of file battle_formation.c.
PP_GAIN_TENTHS
#define PP_GAIN_TENTHS 15
Referenced by btEnemyAdjustLevel().
Definition at line 212 of file battle_formation.c.
ATTACK_GAIN_TENTHS
#define ATTACK_GAIN_TENTHS 123
Referenced by btEnemyAdjustLevel().
Definition at line 213 of file battle_formation.c.
DEFENSE_GAIN_TENTHS
#define DEFENSE_GAIN_TENTHS 33
Referenced by btEnemyAdjustLevel().
Definition at line 214 of file battle_formation.c.
AGILITY_GAIN_TENTHS
#define AGILITY_GAIN_TENTHS 51
Referenced by btEnemyAdjustLevel().
Definition at line 215 of file battle_formation.c.
ELEMENT_POWER_GAIN
#define ELEMENT_POWER_GAIN 15
Referenced by btEnemyAdjustLevel().
Definition at line 216 of file battle_formation.c.
NAME_SUFFIX_MASK_BITS
#define NAME_SUFFIX_MASK_BITS 32
The suffixes a kind's mask holds, one bit each.
Referenced by btEnemyClaimNameLetter() and btEnemyReleaseNameLetter().
Definition at line 285 of file battle_formation.c.
ENEMY_SLOTS_TAKEN
#define ENEMY_SLOTS_TAKEN(enemyId) (2 - (btSpriteIsSmall(enemyId) != 0))
The enemy sprite slots an enemy takes: one for a small enemy, two for any other.
Referenced by btFormationBuildEnemyList().
Definition at line 464 of file battle_formation.c.
Functions in detail
btFormationAverageLevel
Sint32 btFormationAverageLevel(Sint32 formationId)
Returns a formation's average enemy level for the monster battles, or a
negative reason it may not be chosen. Every enemy in it must have been
defeated (ENEMY_DEFEATED_FLAG), unless FLAG_MONSTER_BATTLE_ANY_ENEMY opens
them all.
References Formations, gmEnemyGetDefinitionStub(), Sint32 and syGameFlagGet().
Referenced by btFormationSelectLevelMatchedCandidate().
Definition at line 21 of file battle_formation.c.
btFormationSelectLevelMatchedCandidate
Sint32 btFormationSelectLevelMatchedCandidate(Sint32 *outMargin)
Chooses a monster battle's formation for the party's level plus its winning
streak, at random among those at most FORMATION_LEVEL_MARGIN above it, and
returns it with the levels its enemies must gain in outMargin.
References BattleFormationExcludedEnemies, btFormationAverageLevel(), btPartyPrepareMembers(), gmUnitGet(), result, Sint32, syGameFlagClear(), syGameFlagGet(), syGameFlagGetByte(), syGameFlagSet(), syHeapAllocateEWRAM(), syHeapRelease() and syRandom().
Referenced by btFormationBuildEnemyList().
Definition at line 80 of file battle_formation.c.
btEnemyAdjustLevel
UNREAD_RESULT btEnemyAdjustLevel(Sint32 unitId, Sint32 levels)
Raises an enemy by levels, or lowers it for a negative count, each stat by a fixed amount a level and no lower than 70 percent of what it was.
References gmUnitCalculateStub(), gmUnitGet(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().
Referenced by btFormationBuildEnemyList().
Definition at line 220 of file battle_formation.c.
btUnitStrengthen
void btUnitStrengthen(Sint32 unitId)
Raises a unit's base HP by half and base Attack and Defense by a quarter, at
least 70 percent of the old values and at most UNIT_ENEMY_HP_MAX and
UNIT_STAT_MAX: an enemy on the HARD level (FLAG_HARD_LEVEL).
References gmUnitCalculateStub(), gmUnitGet(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().
Referenced by btFormationBuildEnemyList().
Definition at line 264 of file battle_formation.c.
btEnemyClaimNameLetter
Sint32 btEnemyClaimNameLetter(Sint32 enemyId, Sint32 unused)
Gives an enemy its name suffix, which tells it from others of its kind:
digits abroad and the alphabet in Japanese. The first of a kind goes without
one (NAME_SUFFIX_COUNT) until a second arrives. Returns -1 when five kinds
are already listed.
References Sint32.
Referenced by btAbilityApplyToTarget(), btChangeEnemyForm() and btFormationBuildEnemyList().
Definition at line 291 of file battle_formation.c.
btEnemyReleaseNameLetter
UNREAD_RESULT btEnemyReleaseNameLetter(Sint32 unitId)
Frees a departing enemy's name suffix for the next of its kind.
References gmUnitGet() and Sint32.
Referenced by btObjectRemoveFromLists().
Definition at line 342 of file battle_formation.c.
btEnemyLetterFirstOfKind
Sint32 btEnemyLetterFirstOfKind(Sint32 enemyId)
Gives the first enemy of the kind on the field the first suffix (0), appended to its name, once a second of its kind arrives.
References gmUnitGet() and Sint32.
Referenced by btAbilityApplyToTarget() and btFormationBuildEnemyList().
Definition at line 386 of file battle_formation.c.
btFormationGetRandomMember
Sint32 btFormationGetRandomMember(Sint32 formationId)
Returns the enemy id of a random member of the formation that may appear.
References Formations, Sint32 and syRandom().
Referenced by btAbilityApplyToTarget().
Definition at line 427 of file battle_formation.c.
btFormationBuildEnemyList
Sint32 btFormationBuildEnemyList(Sint32 formationId)
Builds the battle's enemies from a formation and returns how many there are: each member its fewest times and at random up to its most while the sprite slots hold them, laid out as the formation says. A monster battle chooses the formation for the party's level instead.
References btEnemyAdjustLevel(), btEnemyClaimNameLetter(), btEnemyLetterFirstOfKind(), btFormationSelectLevelMatchedCandidate(), btUnitStrengthen(), Formations, gmBattleUnitSetStub(), gmUnitGet(), Sint32, syGameFlagGet() and syRandom().
Referenced by btRun().
Definition at line 470 of file battle_formation.c.