Alchemy
Loading...
Searching...
No Matches

battle_unit.h File Reference

BattleUnit, a party member's or enemy's battle state, with the elements, abilities and actions it uses. More...

Go to the source code of this file.

Data Structures

struct  OwnerActionSlot
 An entry in a unit's action list: the action's id (OWNER_ACTION_ID_MASK) and marks for an action its class or an equipped item gave. More...
struct  BattleElementStats
 A unit's elemental power and resistance in one element. More...
struct  BattleAct
 An ability's definition, a row of gBattleAction_DefinitionTable: its targeting, kind, element, effect, range, PP cost and power. More...
struct  BattleUnit
 A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments. More...

Macros

#define ABILITY_RANGE_ALL   255
 BattleAct.range of an ability that reaches every unit on the side, each as if aimed at.
#define ABILITY_KIND_MASK   15
 The low four bits of BattleAct.flags: how BattleTargetExec applies the ability's power.
#define Unit_UpdateGauges(unit)
 Recalculates HP and PP gauges, keeping at least one when any points remain.

Enumerations

enum  { BATTLE_ACTION_SIZE = 0x10 , BATTLE_UNIT_SIZE = 0x14c , OWNER_ACTION_ID_MASK = 0x3fff }
enum  Element {
  ELEMENT_VENUS , ELEMENT_MERCURY , ELEMENT_MARS , ELEMENT_JUPITER ,
  ELEMENT_NONE , NUM_ELEMENTS = ELEMENT_NONE
}
 The elements, in the order of every table kept per element: a unit's element stats, the Djinn and the summons. More...
enum  AbilityKind {
  ABILITY_KIND_HEAL_HP = 1 , ABILITY_KIND_EFFECT = 2 , ABILITY_KIND_ATTACK = 3 , ABILITY_KIND_ATTACK_MULTIPLIED = 4 ,
  ABILITY_KIND_DAMAGE = 5 , ABILITY_KIND_UNLEASHED_DAMAGE = 6 , ABILITY_KIND_SUMMON = 8 , ABILITY_KIND_PP_DAMAGE = 10 ,
  ABILITY_KIND_HEAL_PP = 11
}
 The kinds of ability, by the low four bits of BattleAct.flags. More...
enum  AbilityEffect {
  ABILITY_EFFECT_NONE = 0 , ABILITY_EFFECT_CURE_POISON = 3 , ABILITY_EFFECT_RESTORE = 4 , ABILITY_EFFECT_REVIVE = 5 ,
  ABILITY_EFFECT_ATTACK_UP_2 = 6 , ABILITY_EFFECT_ATTACK_UP = 7 , ABILITY_EFFECT_ATTACK_DOWN_2 = 8 , ABILITY_EFFECT_ATTACK_DOWN = 9 ,
  ABILITY_EFFECT_DEFENSE_UP_2 = 10 , ABILITY_EFFECT_DEFENSE_UP = 11 , ABILITY_EFFECT_DEFENSE_DOWN_2 = 12 , ABILITY_EFFECT_DEFENSE_DOWN = 13 ,
  ABILITY_EFFECT_RESISTANCE_UP_2 = 14 , ABILITY_EFFECT_RESISTANCE_UP = 15 , ABILITY_EFFECT_RESISTANCE_DOWN_2 = 16 , ABILITY_EFFECT_RESISTANCE_DOWN = 17 ,
  ABILITY_EFFECT_POISON = 18 , ABILITY_EFFECT_DEADLY_POISON = 19 , ABILITY_EFFECT_DELUSION = 20 , ABILITY_EFFECT_CONFUSION = 21 ,
  ABILITY_EFFECT_CHARM = 22 , ABILITY_EFFECT_STUN = 23 , ABILITY_EFFECT_SLEEP = 24 , ABILITY_EFFECT_SEAL = 25 ,
  ABILITY_EFFECT_HAUNT = 26 , ABILITY_EFFECT_INSTANT_DEATH = 27 , ABILITY_EFFECT_CURSE = 28 , ABILITY_EFFECT_REGENERATE = 29 ,
  ABILITY_EFFECT_REFLECT = 30 , ABILITY_EFFECT_DRAIN_HP = 31 , ABILITY_EFFECT_DRAIN_PP = 32 , ABILITY_EFFECT_BREAK = 33 ,
  ABILITY_EFFECT_LEAVE_ONE_HP = 34 , ABILITY_EFFECT_HALVE_DEFENSE = 35 , ABILITY_EFFECT_CRITICAL_1_IN_64 = 36 , ABILITY_EFFECT_CRITICAL_1_IN_32 = 37 ,
  ABILITY_EFFECT_CRITICAL_1_IN_16 = 38 , ABILITY_EFFECT_CRITICAL_1_IN_8 = 39 , ABILITY_EFFECT_CRITICAL_1_IN_4 = 40 , ABILITY_EFFECT_DOUBLE_BLOW_1_IN_8 = 41 ,
  ABILITY_EFFECT_DOUBLE_BLOW_1_IN_4 = 42 , ABILITY_EFFECT_TRIPLE_BLOW_1_IN_8 = 43 , ABILITY_EFFECT_TRIPLE_BLOW_1_IN_4 = 44 , ABILITY_EFFECT_THREATEN = 45 ,
  ABILITY_EFFECT_DEFEND = 46 , ABILITY_EFFECT_TOTAL_DEFENSE = 47 , ABILITY_EFFECT_FLEE = 49 , ABILITY_EFFECT_CALL_ALLY = 50 ,
  ABILITY_EFFECT_CALL_HELP = 51 , ABILITY_EFFECT_GROUND = 53 , ABILITY_EFFECT_CHALLENGE = 54 , ABILITY_EFFECT_SELF_DESTRUCT = 55 ,
  ABILITY_EFFECT_REVIVE_HALF = 56 , ABILITY_EFFECT_REVIVE_80 = 57 , ABILITY_EFFECT_AGILITY_DOWN = 58 , ABILITY_EFFECT_AGILITY_UP = 59 ,
  ABILITY_EFFECT_DRAIN_HALF_HP = 60 , ABILITY_EFFECT_HEAL_HP_60 = 61 , ABILITY_EFFECT_HEAL_HP_30 = 62 , ABILITY_EFFECT_HEAL_PP_7 = 63 ,
  ABILITY_EFFECT_CURE_ALL = 64 , ABILITY_EFFECT_DOUBLE_BLOW_60 = 65 , ABILITY_EFFECT_ACT_TWICE = 66 , ABILITY_EFFECT_SEAL_2_TURNS = 67 ,
  ABILITY_EFFECT_TRIPLE_BLOW_60 = 68 , ABILITY_EFFECT_PSY_LEECH = 69
}
 BattleAct.effect: what an ability does besides its damage or healing, applied by BattleTargetExec unless noted. More...
enum  BattleActionUse { ACTION_USABLE_IN_FIELD = 0x40 , ACTION_USABLE_IN_BATTLE = 0x80 }
 BattleAct.flags: where an ability can be used. More...

Functions

 STATIC_ASSERT (sizeof(struct BattleAct)==BATTLE_ACTION_SIZE)
 STATIC_ASSERT (offsetof(struct BattleAct, effect)==0x03)
 STATIC_ASSERT (offsetof(struct BattleAct, power)==0x0a)
 STATIC_ASSERT (offsetof(struct BattleAct, type0c)==0x0c)
 STATIC_ASSERT (sizeof(struct OwnerActionSlot)==4)
 STATIC_ASSERT (sizeof(struct BattleElementStats)==4)
 STATIC_ASSERT (sizeof(struct BattleUnit)==BATTLE_UNIT_SIZE)
 STATIC_ASSERT (offsetof(struct BattleUnit, baseHp)==0x10)
 STATIC_ASSERT (offsetof(struct BattleUnit, baseAttack)==0x18)
 STATIC_ASSERT (offsetof(struct BattleUnit, actionSlots)==0x58)
 STATIC_ASSERT (offsetof(struct BattleUnit, djinnAvailable)==0xf8)
 STATIC_ASSERT (offsetof(struct BattleUnit, djinnActive)==0x108)
 STATIC_ASSERT (offsetof(struct BattleUnit, rewards)==0x120)
 STATIC_ASSERT (offsetof(struct BattleUnit, hp)==0x038)
 STATIC_ASSERT (offsetof(struct BattleUnit, baseElement)==0x024)
 STATIC_ASSERT (offsetof(struct BattleUnit, level)==0x00f)
 STATIC_ASSERT (offsetof(struct BattleUnit, element)==0x048)
 STATIC_ASSERT (offsetof(struct BattleUnit, ready)==0x144)
 STATIC_ASSERT (offsetof(struct BattleUnit, inventory)==0x0d8)
 STATIC_ASSERT (offsetof(struct BattleUnit, djinnOwnedCounts)==0x118)
 STATIC_ASSERT (offsetof(struct BattleUnit, djinnActiveCounts)==0x11c)
 STATIC_ASSERT (offsetof(struct BattleUnit, guardLevel)==0x12b)
 STATIC_ASSERT (offsetof(struct BattleUnit, charm)==0x13a)
 STATIC_ASSERT (offsetof(struct BattleUnit, haunt)==0x140)
 STATIC_ASSERT (offsetof(struct BattleUnit, enemyId)==0x14a)
static __inline__ s32 Vitals_Clamp (s32 ratio)
 Clamps a gauge ratio to 0..0x4000, where 0x4000 means full.

Detailed Description

BattleUnit, a party member's or enemy's battle state, with the elements, abilities and actions it uses.

Definition in file battle_unit.h.

Macro Definition Documentation

◆ ABILITY_RANGE_ALL

#define ABILITY_RANGE_ALL   255

BattleAct.range of an ability that reaches every unit on the side, each as if aimed at.

Definition at line 46 of file battle_unit.h.

Referenced by BattleMenu_RunActionSelection(), BattleTarget_RunSelection(), BattleTargetExec(), and DjinnMenu_ShowChangePreview().

◆ ABILITY_KIND_MASK

#define ABILITY_KIND_MASK   15

The low four bits of BattleAct.flags: how BattleTargetExec applies the ability's power.

Kinds 0, 7 and 9 apply none: 0 is no ability, 7 is Granite, Flash and Kite, 9 the field Psynergy, Defend, Flee and enemies' commands.

Definition at line 52 of file battle_unit.h.

Referenced by Battle_ClassifyEntryKind(), BattleCommand_BuildPlan(), BattleTarget_SelectForAction(), and BattleTargetExec().

◆ Unit_UpdateGauges

#define Unit_UpdateGauges ( unit)
Value:
do { \
(unit)->hpGauge = Vitals_Clamp(((unit)->hp << 14) / (unit)->maxHp); \
if ((unit)->hpGauge == 0 && (unit)->hp != 0) \
(unit)->hpGauge = 1; \
(unit)->ppGauge = Vitals_Clamp(((unit)->pp << 14) / (unit)->maxPp); \
if ((unit)->ppGauge == 0 && (unit)->pp != 0) \
(unit)->ppGauge = 1; \
} while (0)
static __inline__ s32 Vitals_Clamp(s32 ratio)
Clamps a gauge ratio to 0..0x4000, where 0x4000 means full.

Recalculates HP and PP gauges, keeping at least one when any points remain.

Definition at line 355 of file battle_unit.h.

Referenced by Field_RunScene(), Party_EndChildhood(), Party_RemoveOwnerRestored(), Party_RestoreHpPp(), Party_RestorePpOfLitElements(), Scene_ReturnFromBattle(), Unit_SetHp(), Unit_SetPp(), and UnitRatio().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BATTLE_ACTION_SIZE 
BATTLE_UNIT_SIZE 
OWNER_ACTION_ID_MASK 

Definition at line 11 of file battle_unit.h.

◆ Element

enum Element

The elements, in the order of every table kept per element: a unit's element stats, the Djinn and the summons.

ELEMENT_NONE marks an ability or a weapon that has no element.

Enumerator
ELEMENT_VENUS 
ELEMENT_MERCURY 
ELEMENT_MARS 
ELEMENT_JUPITER 
ELEMENT_NONE 
NUM_ELEMENTS 

Definition at line 35 of file battle_unit.h.

◆ AbilityKind

The kinds of ability, by the low four bits of BattleAct.flags.

Three kinds have no enumerator, because BattleTargetExec applies no power for them: 0 is no ability; 7 is Granite, Flash and Kite, whose effect is all they do; 9 is the field Psynergy (Move, Catch...), the field-only stat items (Apple, Power Bread...), Defend, Flee and the enemies' commands (Threaten, Ally Search...). The targeting check treats kind 9 as a summon: worth it on a living unit only when the power is nonzero.

Enumerator
ABILITY_KIND_HEAL_HP 

Cure, Fizz, healing items.

ABILITY_KIND_EFFECT 

damage only if the effect lands

ABILITY_KIND_ATTACK 

Attack vs Defense, plus the power.

ABILITY_KIND_ATTACK_MULTIPLIED 

that attack times power / 10

ABILITY_KIND_DAMAGE 

HP damage from the power (Psynergy).

ABILITY_KIND_UNLEASHED_DAMAGE 

an enemy's. Shown as X unleashes Y!

ABILITY_KIND_SUMMON 

the summons: damage scaled by distance

ABILITY_KIND_PP_DAMAGE 

Crazy Voice: the target loses PP.

ABILITY_KIND_HEAL_PP 

Ember, Psy Crystal, Adept Ring.

Definition at line 61 of file battle_unit.h.

◆ AbilityEffect

BattleAct.effect: what an ability does besides its damage or healing, applied by BattleTargetExec unless noted.

Each is named for the abilities that have it (actions.tsv, with their English names and descriptions). Sidestep (48) and Crazy Voice (52) have effects no code here reads.

Enumerator
ABILITY_EFFECT_NONE 
ABILITY_EFFECT_CURE_POISON 

Cure Poison, Antidote.

ABILITY_EFFECT_RESTORE 

Restore, Elixir.

ABILITY_EFFECT_REVIVE 

Revive, Water of Life: full HP.

ABILITY_EFFECT_ATTACK_UP_2 

Impact: two stages.

ABILITY_EFFECT_ATTACK_UP 

High Impact: one stage.

ABILITY_EFFECT_ATTACK_DOWN_2 

Dull.

ABILITY_EFFECT_ATTACK_DOWN 

Blunt.

ABILITY_EFFECT_DEFENSE_UP_2 

Guard.

ABILITY_EFFECT_DEFENSE_UP 

Protect.

ABILITY_EFFECT_DEFENSE_DOWN_2 

Impair.

ABILITY_EFFECT_DEFENSE_DOWN 

Debilitate.

ABILITY_EFFECT_RESISTANCE_UP_2 

Ward.

ABILITY_EFFECT_RESISTANCE_UP 

Resist.

ABILITY_EFFECT_RESISTANCE_DOWN_2 

Weaken.

ABILITY_EFFECT_RESISTANCE_DOWN 

Enfeeble.

ABILITY_EFFECT_POISON 

Taint.

ABILITY_EFFECT_DEADLY_POISON 

Poison.

ABILITY_EFFECT_DELUSION 

Delude.

ABILITY_EFFECT_CONFUSION 

Confuse.

ABILITY_EFFECT_CHARM 

Charm.

ABILITY_EFFECT_STUN 

Paralyze.

ABILITY_EFFECT_SLEEP 

Sleep.

ABILITY_EFFECT_SEAL 

Bind: Psynergy sealed.

ABILITY_EFFECT_HAUNT 

Haunt.

ABILITY_EFFECT_INSTANT_DEATH 

Condemn.

ABILITY_EFFECT_CURSE 

Curse: the Grim Reaper's countdown.

ABILITY_EFFECT_REGENERATE 

Regenerate.

ABILITY_EFFECT_REFLECT 

Reflect.

ABILITY_EFFECT_DRAIN_HP 

Drain.

ABILITY_EFFECT_DRAIN_PP 

Psy Drain.

ABILITY_EFFECT_BREAK 

Break: raised stats undone.

ABILITY_EFFECT_LEAVE_ONE_HP 

Severe Blow, Thrash.

ABILITY_EFFECT_HALVE_DEFENSE 

Torch.

ABILITY_EFFECT_CRITICAL_1_IN_64 

A 1 in 64 to 1 in 4 chance of an ability's critical hit, rolled by BattleCommand_BuildPlan.

ABILITY_EFFECT_CRITICAL_1_IN_32 
ABILITY_EFFECT_CRITICAL_1_IN_16 
ABILITY_EFFECT_CRITICAL_1_IN_8 
ABILITY_EFFECT_CRITICAL_1_IN_4 
ABILITY_EFFECT_DOUBLE_BLOW_1_IN_8 

A chance of a double or triple blow, rolled by BattleCommand_BuildPlan.

ABILITY_EFFECT_DOUBLE_BLOW_1_IN_4 

Double Fang, Twin Beaks.

ABILITY_EFFECT_TRIPLE_BLOW_1_IN_8 
ABILITY_EFFECT_TRIPLE_BLOW_1_IN_4 

Swift Strike.

ABILITY_EFFECT_THREATEN 

Contain, Threaten, Tremble.

ABILITY_EFFECT_DEFEND 

Defend, Granite.

ABILITY_EFFECT_TOTAL_DEFENSE 

Total Defense, Flash.

ABILITY_EFFECT_FLEE 

Flee.

ABILITY_EFFECT_CALL_ALLY 

Ally Search, Speed Surge.

ABILITY_EFFECT_CALL_HELP 

Search for Help.

ABILITY_EFFECT_GROUND 

Ground: the target's turn lost.

ABILITY_EFFECT_CHALLENGE 

no ability has it

ABILITY_EFFECT_SELF_DESTRUCT 

Dynamite, Mortal Blow.

ABILITY_EFFECT_REVIVE_HALF 

Quartz.

ABILITY_EFFECT_REVIVE_80 

Dew: 80% of max HP.

ABILITY_EFFECT_AGILITY_DOWN 

Vine.

ABILITY_EFFECT_AGILITY_UP 

Zephyr.

ABILITY_EFFECT_DRAIN_HALF_HP 

Sap.

ABILITY_EFFECT_HEAL_HP_60 

Fizz: 60% of max HP.

ABILITY_EFFECT_HEAL_HP_30 

Spritz: 30%.

ABILITY_EFFECT_HEAL_PP_7 

Ember: 7% of max PP.

ABILITY_EFFECT_CURE_ALL 

Tonic.

ABILITY_EFFECT_DOUBLE_BLOW_60 

Gust, Rapid Smash: 153 in 256.

ABILITY_EFFECT_ACT_TWICE 

Kite.

ABILITY_EFFECT_SEAL_2_TURNS 

Luff.

ABILITY_EFFECT_TRIPLE_BLOW_60 

Sonic Smash.

ABILITY_EFFECT_PSY_LEECH 

Psy Leech.

Definition at line 77 of file battle_unit.h.

◆ BattleActionUse

BattleAct.flags: where an ability can be used.

Enumerator
ACTION_USABLE_IN_FIELD 

can be used outside battle

ACTION_USABLE_IN_BATTLE 

can be used in battle; else greyed there

Definition at line 171 of file battle_unit.h.

Function Documentation

◆ STATIC_ASSERT() [1/25]

STATIC_ASSERT ( sizeof(struct BattleAct) = =BATTLE_ACTION_SIZE)

◆ STATIC_ASSERT() [2/25]

STATIC_ASSERT ( offsetof(struct BattleAct, effect) = =0x03)

◆ STATIC_ASSERT() [3/25]

STATIC_ASSERT ( offsetof(struct BattleAct, power) = =0x0a)

◆ STATIC_ASSERT() [4/25]

STATIC_ASSERT ( offsetof(struct BattleAct, type0c) = =0x0c)

◆ STATIC_ASSERT() [5/25]

STATIC_ASSERT ( sizeof(struct OwnerActionSlot) = =4)

◆ STATIC_ASSERT() [6/25]

STATIC_ASSERT ( sizeof(struct BattleElementStats) = =4)

◆ STATIC_ASSERT() [7/25]

STATIC_ASSERT ( sizeof(struct BattleUnit) = =BATTLE_UNIT_SIZE)

◆ STATIC_ASSERT() [8/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, baseHp) = =0x10)

◆ STATIC_ASSERT() [9/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, baseAttack) = =0x18)

◆ STATIC_ASSERT() [10/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, actionSlots) = =0x58)

◆ STATIC_ASSERT() [11/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, djinnAvailable) = =0xf8)

◆ STATIC_ASSERT() [12/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, djinnActive) = =0x108)

◆ STATIC_ASSERT() [13/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, rewards) = =0x120)

◆ STATIC_ASSERT() [14/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, hp) = =0x038)

◆ STATIC_ASSERT() [15/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, baseElement) = =0x024)

◆ STATIC_ASSERT() [16/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, level) = =0x00f)

◆ STATIC_ASSERT() [17/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, element) = =0x048)

◆ STATIC_ASSERT() [18/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, ready) = =0x144)

◆ STATIC_ASSERT() [19/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, inventory) = =0x0d8)

◆ STATIC_ASSERT() [20/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, djinnOwnedCounts) = =0x118)

◆ STATIC_ASSERT() [21/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, djinnActiveCounts) = =0x11c)

◆ STATIC_ASSERT() [22/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, guardLevel) = =0x12b)

◆ STATIC_ASSERT() [23/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, charm) = =0x13a)

◆ STATIC_ASSERT() [24/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, haunt) = =0x140)

◆ STATIC_ASSERT() [25/25]

STATIC_ASSERT ( offsetof(struct BattleUnit, enemyId) = =0x14a)

◆ Vitals_Clamp()

__inline__ s32 Vitals_Clamp ( s32 ratio)
static

Clamps a gauge ratio to 0..0x4000, where 0x4000 means full.

Definition at line 339 of file battle_unit.h.

Referenced by Vitals_Clamp().