Alchemy
Loading...
Searching...
No Matches

BattleUnit Struct Reference

A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments. More...

#include <battle/battle_unit.h>

Data Fields

u8 name [0x0f]
 The name, one byte a character, ending in 0.
u8 level
 1 to 99 for a character
s16 baseHp
 before equipment, Djinn and class (UnitCalc)
s16 basePp
 before equipment, Djinn and class (UnitCalc)
s16 hpGauge
 hp / maxHp in 0..0x4000; 1 while any HP remains
s16 ppGauge
 pp / maxPp in 0..0x4000; 1 while any PP remains
u16 baseAttack
 before equipment, Djinn, class and stages
u16 baseDefense
 before equipment, Djinn, class and stages
u16 baseAgility
 before equipment, Djinn, class and stages
u8 baseLuck
 before equipment, Djinn and class
u8 baseActionCount
 Actions a round before equipment: the low four bits are read.
u8 baseHpRegen
 HP regained each turn before equipment; 0 for a character.
u8 basePpRegen
 PP regained each turn before equipment and lighthouses.
u8 unk022 [2]
 Not named by any TBS code.
struct BattleElementStats baseElement [4]
 Power and resistance before equipment and stages: an enemy's from its element preset, a character's from its element levels (Unit_CalcBaseElements).
s16 maxHp
 0 to 1999 for a character, 9999 for an enemy (UnitCalc)
s16 maxPp
 0 to 1999 for a character, 9999 for an enemy (UnitCalc)
s16 hp
 current HP, 0 when downed
s16 pp
 current PP
u16 atk
 Attack, 0 to 999 (UnitCalc).
u16 def
 Defense, 0 to 999 (UnitCalc).
u16 agi
 Agility, 0 to 999: the order of the round's actions.
u8 luck
 0 to 99 (UnitCalc)
u8 actionEntryCount
 Actions each round, 0 to 2: baseActionCount, one more while ready, and the equipment's extra turns (UnitCalc).
u8 hpRegen
 HP regained at each turn's end (UnitCalc).
u8 ppRegen
 PP regained at each turn's end, 0 to 200 (UnitCalc): 4 more once the lighthouse of the character's element is lit.
u8 unk046 [2]
 Not named by any TBS code.
struct BattleElementStats element [4]
 Power and resistance in each element, 0 to 200, after equipment, element levels and Resistance stages (UnitCalc).
struct OwnerActionSlot actionSlots [32]
 The action list: Psynergy taught for good, then the class's and the equipment's (Unit_RefreshPsynergy).
u16 inventory [15]
 Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*).
u8 unk0f6 [2]
 Not named by any TBS code.
u32 djinnAvailable [4]
 The Djinn held, one bit per Djinni (by its index) in each element's word.
u32 djinnActive [4]
 The Djinn set, one bit per Djinni; only these add their stat bonuses.
u8 djinnOwnedCounts [4]
 the Djinn held in each element, at most 10
u8 djinnActiveCounts [4]
 the Djinn set in each element; the class's element levels are read from these
u32 rewards
 Copied from the enemy's definition, where it is 0 in every row.
u32 experience
 a character's experience points
u8 classId
 Who the unit is: a character's id (ISAAC to JENNA, below 8) or an enemy's id (BattleUnitSet).
u8 classIndex
 The character's class, worked out from its Djinn (Unit_UpdateClass); 0 marks an enemy, and code throughout tests it to tell the two apart.
u8 side
 BATTLE_UNIT_ABSENT (0), BATTLE_UNIT_ENEMY (1) or BATTLE_UNIT_PARTY (2).
s8 guardLevel
 0, GUARD_DEFEND (1, half the damage) or GUARD_TOTAL_DEFENSE (2, a tenth); set by Defend and Granite, cleared each round.
s8 elementLevels [4]
 A summon's boost to each element: the Djinn of that element the summon spent, adding (n * n + n) * 5 power (UnitCalc).
s8 restraint
 The curse.
s8 poison
 1 poisoned, 2 deadly poison
u8 psySeal
 bits: 7..3 Luff (16 when cast, minus 8 a turn) | 2..0 Bind's turns (7 when cast).
u8 refrain
 Regenerate's turns left, 7 when cast.
s8 reflect
 Reflect's turns left, 7 when cast.
u8 haunt
 set while an evil spirit grips the unit
u8 grimReaper
 The Grim Reaper's countdown: 7 when cursed, down one at each turn's end; at 0 the unit falls.
u8 equipBonus [2]
 The totals of equipment effects 23 (unleash chance) and 24 that UnitCalc sums; TBS never reads them back.
u8 ready
 Kite's extra action: 2 when cast, down one at each turn's end; while nonzero UnitCalc gives the unit one more action a round.
u8 immobile
 set by Ground: the next action is lost
u8 agilityTurns
 the Agility change's turns left, 5 when cast
s8 agilityStage
 The Agility stage: -4 (Vine) to 8 (Zephyr, twice the Agility).
s8 challenge
 Set by the challenge effect: an enemy with it never chooses to flee.
u8 unk149
 Not named by any TBS code.
u16 enemyId
 Not named by any TBS code; TLA reads it as the unit's id.
u8 attackTurns
 Each stat change: the turns it has left, and its stage (UnitCalc: an eighth of Attack, Defense or Agility, or 20 Resistance, a stage).
s8 attackStage
u8 defenseTurns
s8 defenseStage
u8 resistanceTurns
s8 resistanceStage
u8 delusion
 Delusion to sleep: the turns each status has left, 7 when it lands; each may end sooner at the end of a turn.
s8 confusion
u8 charm
u8 stun
u8 sleep

Detailed Description

A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.

Definition at line 178 of file battle_unit.h.

Field Documentation

◆ name

◆ level

◆ baseHp

s16 BattleUnit::baseHp

before equipment, Djinn and class (UnitCalc)

Definition at line 184 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleEnemy_AdjustLevel(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ basePp

s16 BattleUnit::basePp

before equipment, Djinn and class (UnitCalc)

Definition at line 185 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleEnemy_AdjustLevel(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ hpGauge

s16 BattleUnit::hpGauge

hp / maxHp in 0..0x4000; 1 while any HP remains

Definition at line 186 of file battle_unit.h.

Referenced by BattleUnitSet(), Colosso_ControlCharacterAlone(), Party_InitCharacters(), and UnitCalc().

◆ ppGauge

s16 BattleUnit::ppGauge

pp / maxPp in 0..0x4000; 1 while any PP remains

Definition at line 187 of file battle_unit.h.

Referenced by BattleUnitSet(), Colosso_ControlCharacterAlone(), Party_InitCharacters(), and UnitCalc().

◆ baseAttack

u16 BattleUnit::baseAttack

before equipment, Djinn, class and stages

Definition at line 188 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleEnemy_AdjustLevel(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ baseDefense

u16 BattleUnit::baseDefense

before equipment, Djinn, class and stages

Definition at line 189 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleEnemy_AdjustLevel(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ baseAgility

u16 BattleUnit::baseAgility

before equipment, Djinn, class and stages

Definition at line 190 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleEnemy_AdjustLevel(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ baseLuck

u8 BattleUnit::baseLuck

before equipment, Djinn and class

Definition at line 191 of file battle_unit.h.

Referenced by BattleEffect_ApplyToTargets(), BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ baseActionCount

u8 BattleUnit::baseActionCount

Actions a round before equipment: the low four bits are read.

An enemy's comes from its definition's turns; a level up sets a character's to 1.

Definition at line 194 of file battle_unit.h.

Referenced by BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ baseHpRegen

u8 BattleUnit::baseHpRegen

HP regained each turn before equipment; 0 for a character.

Definition at line 195 of file battle_unit.h.

Referenced by BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ basePpRegen

u8 BattleUnit::basePpRegen

PP regained each turn before equipment and lighthouses.

Definition at line 196 of file battle_unit.h.

Referenced by BattleUnitSet(), Owner_LevelUp(), and UnitCalc().

◆ unk022

u8 BattleUnit::unk022[2]

Not named by any TBS code.

Definition at line 197 of file battle_unit.h.

◆ baseElement

struct BattleElementStats BattleUnit::baseElement[4]

Power and resistance before equipment and stages: an enemy's from its element preset, a character's from its element levels (Unit_CalcBaseElements).

Definition at line 201 of file battle_unit.h.

Referenced by BattleEnemy_AdjustLevel(), BattleTargetExec(), BattleUnitSet(), Unit_UpdateClass(), and UnitCalc().

◆ maxHp

◆ maxPp

◆ hp

◆ pp

◆ atk

◆ def

◆ agi

◆ luck

◆ actionEntryCount

u8 BattleUnit::actionEntryCount

Actions each round, 0 to 2: baseActionCount, one more while ready, and the equipment's extra turns (UnitCalc).

Each gives the unit a place in the round's queue.

Definition at line 213 of file battle_unit.h.

Referenced by BattlePres_BuildOpponentEntries(), BattlePres_BuildUnitEntries(), and UnitCalc().

◆ hpRegen

u8 BattleUnit::hpRegen

HP regained at each turn's end (UnitCalc).

Definition at line 214 of file battle_unit.h.

Referenced by Battle_ProcessRoundEnd(), and UnitCalc().

◆ ppRegen

u8 BattleUnit::ppRegen

PP regained at each turn's end, 0 to 200 (UnitCalc): 4 more once the lighthouse of the character's element is lit.

Definition at line 217 of file battle_unit.h.

Referenced by Battle_ProcessRoundEnd(), and UnitCalc().

◆ unk046

u8 BattleUnit::unk046[2]

Not named by any TBS code.

Definition at line 218 of file battle_unit.h.

◆ element

◆ actionSlots

struct OwnerActionSlot BattleUnit::actionSlots[32]

◆ inventory

u16 BattleUnit::inventory[15]

Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*).

An empty entry is 0.

Definition at line 227 of file battle_unit.h.

Referenced by Battle_CollectPartyCommands(), BattleCommand_BuildPlan(), BattleCommand_SelectAutomatic(), BattlePres_RunItem(), BattleUnit_LookupWeaponValueByClass(), BattleUnit_ResetStateByMode(), BattleUnitSet(), Equipment_GetUnleashRateBonus(), Field_UseItem(), GameFlag_RefreshLureCap(), GomaCaveEntrance_GiveShamansRod(), Inventory_AddAndEquip(), Inventory_AddItem(), Inventory_Break(), Inventory_CheckDiscard(), Inventory_Count(), Inventory_CountItem(), Inventory_Discard(), Inventory_Equip(), Inventory_Find(), Inventory_FindEquipped(), Inventory_GetEquippedDefinition(), Inventory_GetEquippedItem(), Inventory_GetQuantity(), Inventory_Remove(), Inventory_RemoveFirstUnflagged(), Inventory_Repair(), InventoryMenu_GetItemQuantity(), InventorySnapshot_Restore(), InventorySnapshot_Save(), Item_Use(), ItemMenu_CollectItems(), ItemMenu_CountItems(), ItemMenu_DrawEquipPreview(), ItemMenu_RunCommands(), ItemMenu_RunList(), ItemMenu_RunOwnerSelection(), ItemMenu_SelectItem(), KolimaForestTree_ReplaceInventoryItem(), Menu_DrawOwnerStatusPanel(), MercuryLighthouse_ReplaceInventoryItem(), Party_EndChildhood(), Party_InitCharacters(), Scene_GiveAndEquipItem(), Shop_ConfirmEquip(), Shop_DrawEquipComparison(), Shop_DrawUnitGrid(), Shop_DrawUseItem(), Shop_RepairItem(), Shop_SelectBuyNum(), Shop_SelectRepair(), Shop_SelectSell(), Shop_SelectSellNum(), Shop_SelectUse(), Shop_SellItem(), Shop_SellOld(), SolSanctumElementalStarRoom_UnmaskFelix(), Unit_RefreshPsynergy(), and UnitCalc().

◆ unk0f6

u8 BattleUnit::unk0f6[2]

Not named by any TBS code.

Definition at line 228 of file battle_unit.h.

◆ djinnAvailable

u32 BattleUnit::djinnAvailable[4]

◆ djinnActive

u32 BattleUnit::djinnActive[4]

The Djinn set, one bit per Djinni; only these add their stat bonuses.

Definition at line 232 of file battle_unit.h.

Referenced by Battle_SelectAbility(), DebugParty_LoadPreset(), Djinn_Activate(), Djinn_CountTurns(), Djinn_Deactivate(), Djinn_IsActive(), Djinn_IsReady(), Djinn_ListOwnerEntries(), and UnitCalc().

◆ djinnOwnedCounts

◆ djinnActiveCounts

u8 BattleUnit::djinnActiveCounts[4]

the Djinn set in each element; the class's element levels are read from these

Definition at line 234 of file battle_unit.h.

Referenced by CharacterMenu_DrawStatusAilments(), DebugParty_LoadPreset(), Djinn_Activate(), Djinn_Deactivate(), Djinn_IsReady(), DjinnMenu_DrawStatPreview(), and Ui_RunOwnerStatusScreen().

◆ rewards

u32 BattleUnit::rewards

Copied from the enemy's definition, where it is 0 in every row.

During a battle the enemy's action choice keeps its place in its action list here (BattleCommand_SelectAutomatic).

Definition at line 239 of file battle_unit.h.

Referenced by BattleCommand_SelectAutomatic(), and BattleUnitSet().

◆ experience

◆ classId

◆ classIndex

◆ side

◆ guardLevel

s8 BattleUnit::guardLevel

0, GUARD_DEFEND (1, half the damage) or GUARD_TOTAL_DEFENSE (2, a tenth); set by Defend and Granite, cleared each round.

Definition at line 252 of file battle_unit.h.

Referenced by BattleCommand_BuildPlan(), BattlePresentation_BuildActions(), BattleTargetExec(), and BattleUnit_ResetGuardLevels().

◆ elementLevels

s8 BattleUnit::elementLevels[4]

A summon's boost to each element: the Djinn of that element the summon spent, adding (n * n + n) * 5 power (UnitCalc).

Cleared at the battle's start and by Break.

Definition at line 256 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), BattleUnit_ProcessTurnEnd(), Unit_GetElementLevel(), and UnitCalc().

◆ restraint

s8 BattleUnit::restraint

The curse.

bits: 3 item effect 25 (UnitCalc clears it again with bit 0) | 2 keeps bit 0 | 1 cursed item equipped | 0 bound. UnitCalc rebuilds bits 1 and 0 from the equipment. A bound unit loses one action in four, except Defend (BattleCommand_BuildPlan); any bit set shows the curse in the status screens and lets the sanctum remove it.

Definition at line 262 of file battle_unit.h.

Referenced by BattleCommand_BuildPlan(), CharacterMenu_BuildAvailability(), Shop_CanServe(), Ui_RunOwnerStatusScreen(), and UnitCalc().

◆ poison

◆ attackTurns

u8 BattleUnit::attackTurns

Each stat change: the turns it has left, and its stage (UnitCalc: an eighth of Attack, Defense or Agility, or 20 Resistance, a stage).

Stages run -4 to 4 and last 7 turns.

Definition at line 268 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), BattleUnit_TickAttackModifier(), and Ui_RunOwnerStatusScreen().

◆ attackStage

◆ defenseTurns

◆ defenseStage

◆ resistanceTurns

◆ resistanceStage

◆ delusion

u8 BattleUnit::delusion

Delusion to sleep: the turns each status has left, 7 when it lands; each may end sooner at the end of a turn.

Sleep, confusion, charm and stun cost the unit its actions.

Definition at line 279 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleCommand_BuildPlan(), BattleFx_RollSuccess(), BattleParty_ResetActiveRuntimeFields(), BattleTarget_RunSelection(), BattleTargetExec(), BattleUnit_BuildStatusFlags(), and Ui_RunOwnerStatusScreen().

◆ confusion

◆ charm

◆ stun

◆ sleep

◆ psySeal

◆ refrain

u8 BattleUnit::refrain

Regenerate's turns left, 7 when cast.

Definition at line 288 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), and BattleUnit_TickRefrain().

◆ reflect

s8 BattleUnit::reflect

Reflect's turns left, 7 when cast.

Definition at line 289 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), and BattleUnit_TickReflect().

◆ haunt

◆ grimReaper

u8 BattleUnit::grimReaper

The Grim Reaper's countdown: 7 when cursed, down one at each turn's end; at 0 the unit falls.

Definition at line 293 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleFx_RollSuccess(), BattleParty_ResetActiveRuntimeFields(), BattleTarget_RunSelection(), BattleTargetExec(), BattleUnit_BuildStatusFlags(), BattleUnit_ProcessTurnEnd(), and Ui_RunOwnerStatusScreen().

◆ equipBonus

u8 BattleUnit::equipBonus[2]

The totals of equipment effects 23 (unleash chance) and 24 that UnitCalc sums; TBS never reads them back.

Definition at line 296 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), and UnitCalc().

◆ ready

u8 BattleUnit::ready

Kite's extra action: 2 when cast, down one at each turn's end; while nonzero UnitCalc gives the unit one more action a round.

Definition at line 299 of file battle_unit.h.

Referenced by Battle_ProcessRoundEnd(), BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), and UnitCalc().

◆ immobile

u8 BattleUnit::immobile

◆ agilityTurns

u8 BattleUnit::agilityTurns

the Agility change's turns left, 5 when cast

Definition at line 301 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), and BattleUnit_TickAgilityModifier().

◆ agilityStage

s8 BattleUnit::agilityStage

The Agility stage: -4 (Vine) to 8 (Zephyr, twice the Agility).

Definition at line 303 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleParty_ResetActiveRuntimeFields(), BattleTargetExec(), BattleUnit_TickAgilityModifier(), Ui_RunOwnerStatusScreen(), and UnitCalc().

◆ challenge

s8 BattleUnit::challenge

Set by the challenge effect: an enemy with it never chooses to flee.

Definition at line 305 of file battle_unit.h.

Referenced by BattleActor_ResetRuntimeFields(), BattleCommand_SelectAutomatic(), BattleParty_ResetActiveRuntimeFields(), and BattleTargetExec().

◆ unk149

u8 BattleUnit::unk149

Not named by any TBS code.

Definition at line 306 of file battle_unit.h.

◆ enemyId

u16 BattleUnit::enemyId

Not named by any TBS code; TLA reads it as the unit's id.

Definition at line 307 of file battle_unit.h.