Alchemy
Loading...
Searching...
No Matches

target_exec.c File Reference

An ability applied to one target, BattleTargetExec: damage, healing and its added effect. More...

Go to the source code of this file.

Macros

#define STAT_STAGE_MIN   -4
 A stat stage changes the stat by an eighth of it (UnitCalc), from half at the lowest to one and a half at the highest.
#define STAT_STAGE_MAX   4
#define AGILITY_STAGE_DOUBLED   8
 Zephyr's Agility stage, beyond the usual highest: twice the Agility.
#define RESISTANCE_PER_STAGE   20
 A Resistance stage adds 20 to the resistance to every element (UnitCalc).
#define STAT_CHANGE_TURNS   7
#define AGILITY_CHANGE_TURNS   5
#define STATUS_TURNS   7
#define CURSE_TURNS   7
 The Grim Reaper's countdown.
#define PSY_SEAL_BIND   7
 BattleUnit.psySeal: Bind's seal counts its seven turns in the low three bits, and may end sooner; Luff's counts down 8 a turn, two turns that never end early (Battle_AdvanceCounterAndCheckChance).
#define PSY_SEAL_LUFF   16
#define FULL_RATE   256
 The rate BattlePowerCalc and BattleRecoveryCalc scale by: 256 is 1.
#define MESSAGE_NONE   -1
 A message operand that shows nothing: the event only waits for the player.
#define IS_PARTY_UNIT(unitId)
 Unit ids 0 to 7 are the party's; enemy units start at FIRST_ENEMY_UNIT.
#define CLAMP_STAT_STAGE(stage)
 Holds a stat stage within STAT_STAGE_MIN to STAT_STAGE_MAX.
#define PUSH_SIDE_MESSAGE(unitId, partyMessage, enemyMessage)
 Pushes one message for a unit of the party and another for an enemy.
#define REDUCE_BY_GUARD(damage, unit)
 A guarding unit takes half the damage, or a tenth behind Total Defense.
#define ABILITY_PSY_DRAIN   126
 The ability Psy Drain, Psynergy that costs no PP.

Functions

s32 BattleEffectDeadCheck (s32 effect)
 Returns 1 for an effect that still applies when the ability's damage has just knocked its target out: the drains, which give the damage they dealt back to the actor.
s32 BattleTargetExec (struct BattlePlan *plan, s32 slot)
 Applies the planned ability to one of its targets: first its damage or healing, then its added effect (a status, a stat change, a revival...).
u32 Ability_IsPsynergy (s32 abilityId)
 Returns 1 for an ability that costs PP, and for Psy Drain, which costs none.

Detailed Description

An ability applied to one target, BattleTargetExec: damage, healing and its added effect.

Part of battle.c, the battle object, compiled only through it.

Definition in file target_exec.c.

Macro Definition Documentation

◆ STAT_STAGE_MIN

#define STAT_STAGE_MIN   -4

A stat stage changes the stat by an eighth of it (UnitCalc), from half at the lowest to one and a half at the highest.

Definition at line 28 of file target_exec.c.

Referenced by BattleTargetExec().

◆ STAT_STAGE_MAX

#define STAT_STAGE_MAX   4

Definition at line 29 of file target_exec.c.

◆ AGILITY_STAGE_DOUBLED

#define AGILITY_STAGE_DOUBLED   8

Zephyr's Agility stage, beyond the usual highest: twice the Agility.

Definition at line 31 of file target_exec.c.

Referenced by BattleTargetExec().

◆ RESISTANCE_PER_STAGE

#define RESISTANCE_PER_STAGE   20

A Resistance stage adds 20 to the resistance to every element (UnitCalc).

Definition at line 33 of file target_exec.c.

Referenced by BattleTargetExec().

◆ STAT_CHANGE_TURNS

#define STAT_CHANGE_TURNS   7

Definition at line 37 of file target_exec.c.

Referenced by BattleTargetExec().

◆ AGILITY_CHANGE_TURNS

#define AGILITY_CHANGE_TURNS   5

Definition at line 38 of file target_exec.c.

Referenced by BattleTargetExec().

◆ STATUS_TURNS

#define STATUS_TURNS   7

Definition at line 39 of file target_exec.c.

Referenced by BattleTargetExec().

◆ CURSE_TURNS

#define CURSE_TURNS   7

The Grim Reaper's countdown.

Definition at line 41 of file target_exec.c.

Referenced by BattleTargetExec().

◆ PSY_SEAL_BIND

#define PSY_SEAL_BIND   7

BattleUnit.psySeal: Bind's seal counts its seven turns in the low three bits, and may end sooner; Luff's counts down 8 a turn, two turns that never end early (Battle_AdvanceCounterAndCheckChance).

Definition at line 46 of file target_exec.c.

Referenced by BattleTargetExec().

◆ PSY_SEAL_LUFF

#define PSY_SEAL_LUFF   16

Definition at line 47 of file target_exec.c.

Referenced by BattleTargetExec().

◆ FULL_RATE

#define FULL_RATE   256

The rate BattlePowerCalc and BattleRecoveryCalc scale by: 256 is 1.

Definition at line 50 of file target_exec.c.

Referenced by BattleTargetExec().

◆ MESSAGE_NONE

#define MESSAGE_NONE   -1

A message operand that shows nothing: the event only waits for the player.

Definition at line 53 of file target_exec.c.

Referenced by BattleTargetExec().

◆ IS_PARTY_UNIT

#define IS_PARTY_UNIT ( unitId)
Value:
((unitId) >= 0 && (unitId) < 8)

Unit ids 0 to 7 are the party's; enemy units start at FIRST_ENEMY_UNIT.

Definition at line 56 of file target_exec.c.

Referenced by BattleTargetExec().

◆ CLAMP_STAT_STAGE

#define CLAMP_STAT_STAGE ( stage)
Value:
{ \
if ((stage) < STAT_STAGE_MIN) \
(stage) = STAT_STAGE_MIN; \
if ((stage) > STAT_STAGE_MAX) \
(stage) = STAT_STAGE_MAX; \
}
#define STAT_STAGE_MAX
Definition target_exec.c:29
#define STAT_STAGE_MIN
A stat stage changes the stat by an eighth of it (UnitCalc), from half at the lowest to one and a hal...
Definition target_exec.c:28

Holds a stat stage within STAT_STAGE_MIN to STAT_STAGE_MAX.

Definition at line 62 of file target_exec.c.

Referenced by BattleTargetExec().

◆ PUSH_SIDE_MESSAGE

#define PUSH_SIDE_MESSAGE ( unitId,
partyMessage,
enemyMessage )
Value:
{ \
if (IS_PARTY_UNIT(unitId)) \
PUSH_MESSAGE(partyMessage); \
else \
PUSH_MESSAGE(enemyMessage); \
}
#define IS_PARTY_UNIT(unitId)
Unit ids 0 to 7 are the party's; enemy units start at FIRST_ENEMY_UNIT.
Definition target_exec.c:56

Pushes one message for a unit of the party and another for an enemy.

Definition at line 71 of file target_exec.c.

Referenced by BattleTargetExec().

◆ REDUCE_BY_GUARD

#define REDUCE_BY_GUARD ( damage,
unit )
Value:
{ \
s32 guard = (unit)->guardLevel; \
\
if (guard != 0) { \
if (guard == GUARD_DEFEND) \
(damage) /= 2; \
else \
(damage) /= 10; \
} \
}
#define GUARD_DEFEND
BattleUnit.guardLevel: Defend and Granite halve the damage, Total Defense and Flash cut it to a tenth...
signed int s32
Definition types.h:14

A guarding unit takes half the damage, or a tenth behind Total Defense.

Definition at line 80 of file target_exec.c.

Referenced by BattleTargetExec().

◆ ABILITY_PSY_DRAIN

#define ABILITY_PSY_DRAIN   126

The ability Psy Drain, Psynergy that costs no PP.

Definition at line 1312 of file target_exec.c.

Referenced by Ability_IsPsynergy().

Function Documentation

◆ BattleEffectDeadCheck()

s32 BattleEffectDeadCheck ( s32 effect)

Returns 1 for an effect that still applies when the ability's damage has just knocked its target out: the drains, which give the damage they dealt back to the actor.

Called by BattleTargetExec before the added effect. effect : the ability's effect (enum AbilityEffect)

Definition at line 13 of file target_exec.c.

Referenced by BattleEffectDeadCheck(), and BattleTargetExec().

◆ BattleTargetExec()

s32 BattleTargetExec ( struct BattlePlan * plan,
s32 slot )

Applies the planned ability to one of its targets: first its damage or healing, then its added effect (a status, a stat change, a revival...).

Nothing is shown here: each step queues battle events (the names and numbers a message needs, the message, the target's reactions) that BattleEvent_Playback then plays in order. The units themselves change at once: UnitCalcFar recalculates a unit's stats from its stages, and UnitRatioFar its HP and PP gauges after either changes.

Called for each target in turn by BattleEvent_Playback (an action with an effect) and BattlePres_RunActorEntries (one without). Changes the target's HP, PP, statuses, stat stages and turns, and its guard; the actor's HP or PP for a drain, and plan->hauntDamage; adds an enemy to gBattleWork->enemyIds when one is called; sets gBattleWork->challengeFlag bit 1 when the party is challenged; queues the events that show it all. It takes BattleRandomFar rolls, and borrows a heap block for the target's copy.

It runs in phases, each marked in the body:

  1. Setup: a copy of the target as it was; the target's distance from the aimed place; the element's affinity (resisted, neutral or weak); the actor's power in the element.
  2. The Djinn bonus roll, and whether the effect lands (hit).
  3. Calling an ally (Ally Search, Search for Help, Speed Surge).
  4. The effects that change the damage step: Ground, Torch, Severe Blow, instant death, a self-destruct, Psy Drain.
  5. Damage and healing, by the ability's kind (attack, PP damage, HP and PP healing, Psynergy damage, an effect's damage).
  6. The added effect, by the ability's effect: cures, heals, stat changes, revivals, statuses, drains, Break, the curse, guards.
  7. Waking from damage, the recalculated stats, the redraw, and the evil spirit's share for a haunted actor.

plan : the action under way: the actor, the ability, its element and its targets, each with its distance from the aimed position, damage multiplier, critical hit and any hit roll made in advance. slot : which of the plan's targets (0 to plan->targetCount - 1).

Definition at line 132 of file target_exec.c.

Referenced by BattleEvent_Playback(), BattlePres_RunActorEntries(), and BattleTargetExec().

◆ Ability_IsPsynergy()

u32 Ability_IsPsynergy ( s32 abilityId)

Returns 1 for an ability that costs PP, and for Psy Drain, which costs none.

Called by BattleCommand_BuildPlan (a cast's staging) and BattleCommand_SelectAutomatic (an enemy's PP and seal checks).

Definition at line 1318 of file target_exec.c.

Referenced by Ability_IsPsynergy(), BattleCommand_BuildPlan(), and BattleCommand_SelectAutomatic().