Skip to Content
The Alchemy Project

struct UNIT

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

Declared in battle_unit.h.

Fields

NameDescription
Uint8name [UNIT_NAME_SIZE]The name, one byte a character, ending in 0.
Uint8level1 to 99 for a character.
Sint16baseHpBefore equipment, Djinn and class (gmUnitCalculate).
Sint16basePpBefore equipment, Djinn and class (gmUnitCalculate).
Sint16hpGaugehp / hpMax in 0..UNIT_GAUGE_FULL; 1 while any HP remains.
Sint16ppGaugepp / ppMax in 0..UNIT_GAUGE_FULL; 1 while any PP remains.
Uint16baseAttackBefore equipment, Djinn, class and stages.
Uint16baseDefenseBefore equipment, Djinn, class and stages.
Uint16baseAgilityBefore equipment, Djinn, class and stages.
Uint8baseLuckBefore equipment, Djinn and class.
Uint8baseActionCountActions a turn before equipment: the low four bits are read.
Uint8baseHpRegenHP regained each turn before equipment; a level up sets a character's to 0.
Uint8basePpRegenPP regained each turn before equipment and lighthouses.
Uint8baseUnused [2]No code names it.
BATTLE_ELEMENT_STATSbaseElement [ELEMENT_COUNT]Power and resistance before equipment and stages: an enemy's from its element preset, a character's from its element levels (gmUnitCalculateBaseElements).
Sint16hpMax0 to 1999 for a character, 9999 for an enemy (gmUnitCalculate).
Sint16ppMax0 to 1999 for a character, 9999 for an enemy (gmUnitCalculate).
Sint16hpCurrent HP, 0 when downed.
Sint16ppCurrent PP.
Uint16attackAttack, 0 to 999 (gmUnitCalculate).
Uint16defenseDefense, 0 to 999 (gmUnitCalculate).
Uint16agilityAgility, 0 to 999: the order of the turn's actions.
Uint8luck0 to 99 (gmUnitCalculate).
Uint8actionsPerTurnActions each turn, 0 to 2: baseActionCount, one more while ready, and the equipment's extra actions (gmUnitCalculate).
Uint8hpRegenHP regained at each turn's end (gmUnitCalculate).
Uint8ppRegenPP regained at each turn's end, 0 to 200 (gmUnitCalculate): 4 more once the lighthouse of the character's element is lit.
Uint8unused [2]No code names it, as baseUnused.
BATTLE_ELEMENT_STATSelement [ELEMENT_COUNT]Power and resistance in each element, 0 to 200, after equipment, a summon's boost and Resistance stages (gmUnitCalculate).
PSYNERGY_ENTRYpsynergy [PSYNERGY_SLOTS]The action list: Psynergy taught for good, then the class's and the equipment's (gmUnitRefreshPsynergy).
Uint16inventory [INVENTORY_SLOTS]Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*).
Uint8paddingBeforeDjinn [2]Up to the word djinnHeld starts on.
Uint32djinnHeld [ELEMENT_COUNT]The Djinn held, one bit per Djinni (by its index) in each element's word.
Uint32djinnSet [ELEMENT_COUNT]The Djinn set, one bit per Djinni; only these add their stat bonuses.
Uint8djinnHeldCounts [ELEMENT_COUNT]The Djinn held in each element, at most 10.
Uint8djinnSetCounts [ELEMENT_COUNT]The Djinn set in each element; the class's element levels are read from these.
BATTLE_AI_STATEaiStateCopied from the enemy's definition, where it is 0 in every row.
Uint32experienceA character's experience points.
Uint8idWho the unit is: a character's id (ISAAC to PIERS, below 8) or an enemy's id (gmBattleUnitSet); BattleSprites and the enemy tables are read by it.
Uint8classIdThe character's class, worked out from its Djinn (gmUnitUpdateClass); CLASS_NONE marks an enemy, and code throughout tests it to tell the two apart.
Uint8sideBATTLE_SIDE.
Sint8defendLevelDEFEND_NORMAL or DEFEND_TOTAL while the unit guards, else 0.
Sint8summonBoost [ELEMENT_COUNT]A summon's boost to its summoner's power in each element: at the end of the summoner's action, the element the summon spent the most Djinn of rises to that many (btUnitProcessActionEnd), and n adds (n * n + n) * 5 power (gmUnitCalculate).
Sint8curseThe curse: CURSE_FLAG bits.
Sint8poisonPOISON_NORMAL or POISON_VENOM, 0 for none.
Uint8attackTurnsEach stat change: the turns it has left, and its stage (gmUnitCalculate: an eighth of Attack, Defense or Agility, or 20 Resistance, a stage).
Sint8attackStage
Uint8defenseTurns
Sint8defenseStage
Uint8resistanceTurns
Sint8resistanceStage
Uint8delusionDelusion to sleep: the turns each status has left, 7 when it lands; each may end sooner at the end of a turn.
Uint8confusion
Uint8charm
Uint8stun
Uint8sleep
Uint8psySealbits: 7..3 Luff (16 when cast, minus 8 a turn) | 2..0 Bind's turns (7 when cast).
Uint8regenerateRegenerate's turns left, 7 when cast.
Uint8reflectReflect's turns left, 7 when cast.
Uint8hauntSet while an evil spirit grips the unit.
Uint8grimReaperThe Grim Reaper's countdown: 7 when cursed, down one at the end of each of the unit's own actions (btUnitProcessActionEnd); at 0 it falls.
Uint8equipBonus [2]The totals of EQUIP_EFFECT_ADD_UNLEASH_CHANCE and EQUIP_EFFECT_ADD_COUNTERSTRIKE_RATE that gmUnitCalculate sums; nothing reads them back.
Uint8readyKite's extra action: 2 when cast, down one at each turn's end; while nonzero gmUnitCalculate gives the unit one more action a turn.
Uint8immobileSet by ABILITY_EFFECT_GROUND: the next action is lost.
Uint8agilityTurnsThe Agility change's turns left, 5 when cast.
Sint8agilityStageThe Agility stage: -4 (Vine) to 8 (Zephyr, twice the Agility).
Sint8challengeSet by the challenge effect: an enemy with it never chooses to flee.
Uint8paddingBeforeEnemyIdUp to the halfword enemyId starts on.
Uint16enemyIdNot named by any TBS code; TLA reads it as the unit's id.

Description

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

struct UNIT

Referenced by btAbilityApplyToTarget(), btActionRunBuild(), btAIChooseAction(), btAIChooseTarget(), btAutoBattleApplyDamage(), btAutoBattleBuildActions(), btAutoBattleRunAction(), btAutoBattleShowDefend(), btAwardSpoils(), btBuildEnemyActions(), btBuildPartyActions(), btDebugBattleViewMessages(), btDebugParamSetLoad(), btEffectRunAttackSlash(), btEnemyAdjustLevel(), btEnemyCalculateCoinReward(), btEnemyCalculateExperienceReward(), btEnemyLetterFirstOfKind(), btEnemyRecordDefeat(), btEnemyReleaseNameLetter(), btEnemySpriteLoadIntoSlots(), btGatherActions(), btLinkBattleReceiveParty(), btLinkBattleSendParty(), btMotionShowDowned(), btObjectMake(), btObjectUpdatePose(), btPartyClearBattleStatuses(), btPlacementLayoutEnemies(), btPlaybackRun(), btProcessTurnEnd(), btStagingDispatchAction(), btStagingRunAttack(), btStagingRunFlee(), btStagingRunItem(), btSummonUpdateAvailability(), btUnitBuildStatusFlags(), btUnitClearStatuses(), btUnitCountDownAgilityStage(), btUnitCountDownAttackStage(), btUnitCountDownPsynergySeal(), btUnitGetWeaponSprite(), btUnitListLiving(), btUnitProcessActionEnd(), btUnitRemoveEnemy(), btUnitResetGuardLevels(), btUnitRollCounterEarlyEnd(), CharacterUnits, dbIncreaseItemAndLevelRaiseMemberLevel(), dbIncreaseItemAndLevelRunLevelEditor() and 123 more.

Definition at line 363 of file battle_unit.h.

Fields in detail

name

Uint8 name[UNIT_NAME_SIZE]

The name, one byte a character, ending in 0. An enemy's is its message name cut to 14 characters, with the suffix letter gmBattleUnitSet is given (a digit in Japanese); its last byte is always 0.

level

Uint8 level

1 to 99 for a character.

baseHp

Sint16 baseHp

Before equipment, Djinn and class (gmUnitCalculate).

basePp

Sint16 basePp

Before equipment, Djinn and class (gmUnitCalculate).

hpGauge

Sint16 hpGauge

hp / hpMax in 0..UNIT_GAUGE_FULL; 1 while any HP remains.

ppGauge

Sint16 ppGauge

pp / ppMax in 0..UNIT_GAUGE_FULL; 1 while any PP remains.

baseAttack

Uint16 baseAttack

Before equipment, Djinn, class and stages.

baseDefense

Uint16 baseDefense

Before equipment, Djinn, class and stages.

baseAgility

Uint16 baseAgility

Before equipment, Djinn, class and stages.

baseLuck

Uint8 baseLuck

Before equipment, Djinn and class.

baseActionCount

Uint8 baseActionCount

Actions a turn before equipment: the low four bits are read. An enemy's comes from its definition's actionCount; a level up sets a character's to 1.

baseHpRegen

Uint8 baseHpRegen

HP regained each turn before equipment; a level up sets a character's to 0.

basePpRegen

Uint8 basePpRegen

PP regained each turn before equipment and lighthouses.

baseUnused

Uint8 baseUnused[2]

No code names it.

baseElement

BATTLE_ELEMENT_STATS baseElement[ELEMENT_COUNT]

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

hpMax

Sint16 hpMax

0 to 1999 for a character, 9999 for an enemy (gmUnitCalculate).

ppMax

Sint16 ppMax

0 to 1999 for a character, 9999 for an enemy (gmUnitCalculate).

hp

Sint16 hp

Current HP, 0 when downed.

pp

Sint16 pp

Current PP.

attack

Uint16 attack

Attack, 0 to 999 (gmUnitCalculate).

defense

Uint16 defense

Defense, 0 to 999 (gmUnitCalculate).

agility

Uint16 agility

Agility, 0 to 999: the order of the turn's actions.

luck

Uint8 luck

0 to 99 (gmUnitCalculate).

actionsPerTurn

Uint8 actionsPerTurn

Actions each turn, 0 to 2: baseActionCount, one more while ready, and the equipment's extra actions (gmUnitCalculate). Each gives the unit a place in the turn's queue.

hpRegen

Uint8 hpRegen

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

ppRegen

Uint8 ppRegen

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

unused

Uint8 unused[2]

No code names it, as baseUnused.

element

BATTLE_ELEMENT_STATS element[ELEMENT_COUNT]

Power and resistance in each element, 0 to 200, after equipment, a summon's boost and Resistance stages (gmUnitCalculate).

psynergy

PSYNERGY_ENTRY psynergy[PSYNERGY_SLOTS]

The action list: Psynergy taught for good, then the class's and the equipment's (gmUnitRefreshPsynergy). An empty entry is 0.

inventory

Uint16 inventory[INVENTORY_SLOTS]

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

paddingBeforeDjinn

Uint8 paddingBeforeDjinn[2]

Up to the word djinnHeld starts on.

djinnHeld

Uint32 djinnHeld[ELEMENT_COUNT]

The Djinn held, one bit per Djinni (by its index) in each element's word.

djinnSet

Uint32 djinnSet[ELEMENT_COUNT]

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

djinnHeldCounts

Uint8 djinnHeldCounts[ELEMENT_COUNT]

The Djinn held in each element, at most 10.

djinnSetCounts

Uint8 djinnSetCounts[ELEMENT_COUNT]

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

aiState

BATTLE_AI_STATE aiState

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 (btAIChooseAction).

experience

Uint32 experience

A character's experience points.

id

Uint8 id

Who the unit is: a character's id (ISAAC to PIERS, below 8) or an enemy's id (gmBattleUnitSet); BattleSprites and the enemy tables are read by it.

classId

Uint8 classId

The character's class, worked out from its Djinn (gmUnitUpdateClass); CLASS_NONE marks an enemy, and code throughout tests it to tell the two apart.

side

Uint8 side

BATTLE_SIDE. The Djinn the party fights are enemies put on BATTLE_SIDE_PARTY (gmBattleUnitSet).

defendLevel

Sint8 defendLevel

DEFEND_NORMAL or DEFEND_TOTAL while the unit guards, else 0.

summonBoost

Sint8 summonBoost[ELEMENT_COUNT]

A summon's boost to its summoner's power in each element: at the end of the summoner's action, the element the summon spent the most Djinn of rises to that many (btUnitProcessActionEnd), and n adds (n * n + n) * 5 power (gmUnitCalculate). Cleared at the battle's start, on going down and by Break.

curse

Sint8 curse

The curse: CURSE_FLAG bits. gmUnitCalculate rebuilds CURSE_BOUND and CURSE_ITEM from the equipment. A bound unit loses one action in four, except Defend (btActionRunBuild); any bit set shows the curse in the Status screens and lets the sanctum remove it.

poison

Sint8 poison

POISON_NORMAL or POISON_VENOM, 0 for none.

attackTurns

Uint8 attackTurns

Each stat change: the turns it has left, and its stage (gmUnitCalculate: an eighth of Attack, Defense or Agility, or 20 Resistance, a stage). Stages run -4 to 4 and last 7 turns; a lowered one may recover sooner at the end of a turn.

attackStage

Sint8 attackStage

defenseTurns

Uint8 defenseTurns

defenseStage

Sint8 defenseStage

resistanceTurns

Uint8 resistanceTurns

resistanceStage

Sint8 resistanceStage

delusion

Uint8 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.

confusion

Uint8 confusion

charm

Uint8 charm

stun

Uint8 stun

sleep

Uint8 sleep

psySeal

Uint8 psySeal

bits: 7..3 Luff (16 when cast, minus 8 a turn) | 2..0 Bind's turns (7 when cast). Psynergy is sealed while any bit is set.

regenerate

Uint8 regenerate

Regenerate's turns left, 7 when cast.

reflect

Uint8 reflect

Reflect's turns left, 7 when cast.

haunt

Uint8 haunt

Set while an evil spirit grips the unit.

grimReaper

Uint8 grimReaper

The Grim Reaper's countdown: 7 when cursed, down one at the end of each of the unit's own actions (btUnitProcessActionEnd); at 0 it falls.

equipBonus

Uint8 equipBonus[2]

The totals of EQUIP_EFFECT_ADD_UNLEASH_CHANCE and EQUIP_EFFECT_ADD_COUNTERSTRIKE_RATE that gmUnitCalculate sums; nothing reads them back.

ready

Uint8 ready

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

immobile

Uint8 immobile

Set by ABILITY_EFFECT_GROUND: the next action is lost.

agilityTurns

Uint8 agilityTurns

The Agility change's turns left, 5 when cast.

agilityStage

Sint8 agilityStage

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

challenge

Sint8 challenge

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

paddingBeforeEnemyId

Uint8 paddingBeforeEnemyId

Up to the halfword enemyId starts on.

enemyId

Uint16 enemyId

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