src/battle/battle_formation.c
Enemy formations: the enemies chosen, levelled and lettered. 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. |
struct | BATTLE_BASE_STATS | A unit's base stats as they were before its level changed. |
Macros
| Name | Description | |
|---|---|---|
#define | ENEMY_NAME_SUFFIX_COUNT JAPANESE_OR(26, 9) | How many name letters tell the enemies of one kind apart: 26 in Japanese, 9 in the localizations. |
#define | NAME_LETTER_MASK_BITS 32 | The letters a kind's mask holds, one bit each. |
#define | FORMATION_FALLBACK 1 | The formation a battle falls back on when its own is out of range or has no sure member: a lone Vermin. |
#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 above MONSTER_BATTLE_OPEN_LEVEL is one the party has not defeated, or no member has a definition. |
#define | FORMATION_UNMET_ENEMY -2 | |
#define | FORMATION_NO_ENEMY -3 | |
#define | MONSTER_BATTLE_OPEN_LEVEL 3 | The monster battles offer an enemy up to this level whether or not the party has defeated it. |
#define | FORMATION_MEMBER_SLOTS (formation, member) | The sprite slots one of member's enemies takes: two for a large enemy. |
#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 | ELEMENT_POWER_GAIN 15 | The element power an enemy gains a level (btEnemyAdjustLevel). |
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 3 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. |
Sint32 | btEnemyClaimNameLetter (Sint32 enemyId, Sint32 unused) | Gives an enemy its name letter, 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 letter for the next of its kind. |
UNREAD_RESULT | btEnemyLetterFirstOfKind (Sint32 enemyId) | Gives the first enemy of the kind on the field the first letter (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: the enemies chosen, levelled and lettered. Part of
battle.c.
Macros in detail
ENEMY_NAME_SUFFIX_COUNT
#define ENEMY_NAME_SUFFIX_COUNT JAPANESE_OR(26, 9)
How many name letters tell the enemies of one kind apart: 26 in Japanese, 9 in the localizations.
Referenced by btEnemyClaimNameLetter().
Definition at line 8 of file battle_formation.c.
NAME_LETTER_MASK_BITS
#define NAME_LETTER_MASK_BITS 32
The letters a kind's mask holds, one bit each.
Referenced by btEnemyClaimNameLetter() and btEnemyReleaseNameLetter().
Definition at line 10 of file battle_formation.c.
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: a lone Vermin.
Referenced by btFormationBuildEnemyList(), btFormationGetRandomMember() and btFormationSelectLevelMatchedCandidate().
Definition at line 13 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 15 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 above MONSTER_BATTLE_OPEN_LEVEL is one the party has
not defeated, or no member has a definition.
Referenced by btFormationAverageLevel().
Definition at line 20 of file battle_formation.c.
FORMATION_UNMET_ENEMY
#define FORMATION_UNMET_ENEMY -2
Referenced by btFormationAverageLevel().
Definition at line 21 of file battle_formation.c.
FORMATION_NO_ENEMY
#define FORMATION_NO_ENEMY -3
Referenced by btFormationAverageLevel().
Definition at line 22 of file battle_formation.c.
MONSTER_BATTLE_OPEN_LEVEL
#define MONSTER_BATTLE_OPEN_LEVEL 3
The monster battles offer an enemy up to this level whether or not the party has defeated it.
Referenced by btFormationAverageLevel().
Definition at line 25 of file battle_formation.c.
FORMATION_MEMBER_SLOTS
#define FORMATION_MEMBER_SLOTS(formation, member)
The sprite slots one of member's enemies takes: two for a large enemy.
Referenced by btFormationBuildEnemyList().
Definition at line 82 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 88 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 90 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 93 of file battle_formation.c.
ELEMENT_POWER_GAIN
#define ELEMENT_POWER_GAIN 15
The element power an enemy gains a level (btEnemyAdjustLevel). Its other
stats gain tenths of a point: 9.7 HP, 1.5 PP, 12.3 Attack, 3.3 Defense and
5.1 Agility a level.
Referenced by btEnemyAdjustLevel().
Definition at line 213 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.
References Formations, gmEnemyGetDefinitionStub(), gmFlagGetStub() and Sint32.
Referenced by btFormationSelectLevelMatchedCandidate().
Definition at line 29 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 3 above it, and returns it with the levels its enemies must gain in outMargin.
References BattleFormationExcludedEnemies, btFormationAverageLevel(), btPartyPrepareMembers(), Formations, gmEnemyGetDefinitionStub(), gmFlagClearStub(), gmFlagGetByteStub(), gmUnitGetStub(), Sint32, syHeapAllocateEWRAM() and syHeapRelease().
Referenced by btFormationBuildEnemyList().
Definition at line 119 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(), gmUnitGetStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease() and syWordsCopy().
Referenced by btFormationBuildEnemyList().
Definition at line 217 of file battle_formation.c.
btEnemyClaimNameLetter
Sint32 btEnemyClaimNameLetter(Sint32 enemyId, Sint32 unused)
Gives an enemy its name letter, which tells it from others of its kind: digits abroad and the alphabet in Japanese. Returns -1 when five kinds are already listed.
References Sint32.
Referenced by btAbilityApplyToTarget() and btFormationBuildEnemyList().
Definition at line 261 of file battle_formation.c.
btEnemyReleaseNameLetter
UNREAD_RESULT btEnemyReleaseNameLetter(Sint32 unitId)
Frees a departing enemy's name letter for the next of its kind.
References gmUnitGetStub() and Sint32.
Referenced by btObjectRemoveFromLists().
Definition at line 313 of file battle_formation.c.
btEnemyLetterFirstOfKind
UNREAD_RESULT btEnemyLetterFirstOfKind(Sint32 enemyId)
Gives the first enemy of the kind on the field the first letter (0), appended to its name, once a second of its kind arrives.
References gmUnitGetStub() and Sint32.
Referenced by btAbilityApplyToTarget() and btFormationBuildEnemyList().
Definition at line 357 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 and Sint32.
Referenced by btAbilityApplyToTarget().
Definition at line 385 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(), btSpriteIsSmall(), Formations, gmBattleUnitSetStub(), gmFlagGetStub(), gmUnitGetStub(), Sint32, syRandom() and syWordsClear().
Referenced by btRun().
Definition at line 408 of file battle_formation.c.