Skip to Content
The Alchemy Project

src/battle/battle_ability.c

Applying an ability to each of its targets: damage, healing, statuses, stat changes, Djinn and special effects. More…

Included by battle.c.

Macros

NameDescription
#defineAGILITY_STAGE_DOUBLED 8Zephyr's Agility stage, beyond the usual highest: twice the Agility.
#defineSTAT_CHANGE_TURNS 7The turns a stat change or a status lasts; a status or a lowered stat may end sooner.
#defineAGILITY_CHANGE_TURNS 5
#defineSTATUS_TURNS 7
#defineREGENERATE_TURNS 5
#defineCURSE_TURNS 7The Grim Reaper's countdown.
#defineFULL_RATE 256The rate gmBattleCalculatePsynergyPowerStub and gmBattleCalculateRecoveryStub scale by: 256 is 1.
#defineMESSAGE_NONE -1A message operand that shows nothing: the event only waits for the player.
#defineSUMMON_BONUS_HP_MAX 10000A summon's bonus damage counts the target's max HP up to this much.
#defineIS_PARTY_UNIT (unitId) ((unitId) >= 0 && (unitId) <= ALLY_MAX)Party unit ids run to ALLY_MAX; enemy units start at FIRST_ENEMY_UNIT.
#defineARE_OPPONENTS (unitId, otherId)Whether two units are on opposite sides: party unit ids are below FIRST_ENEMY_UNIT, enemy ids from it.
#defineCLAMP_STAT_STAGE (stage)Holds a stat stage within STAT_STAGE_MIN to STAT_STAGE_MAX.
#definePUSH_SIDE_MESSAGE (unitId, partyMessage, enemyMessage)Pushes one message for a unit of the party and another for an enemy.
#defineREDUCE_BY_GUARD (damage, unit)A guarding unit takes half the damage, two fifths behind Shade, or a tenth behind Total Defense.
#defineDEFENSE_HALVED 1defenseCut: how much of the target's Defense an attack counts.
#defineDEFENSE_IGNORED 2Raiden's Wrath and Trident: none
#defineITEM_ELEMENT_POWER 100The element power an item, or an ability with no element, acts with.
#defineDJINN_BONUS_CHANCE 30An unleashed Djinni gives the Djinn bonus (more coins and experience, and a likelier item, from the enemies that fall) against a target weakest to its element, with a chance in percent of the user's power less the target's resistance, plus this many.

Functions

NameDescription
BoolbtAbilityEffectAppliesToDowned (Sint32 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 user.
BoolbtUnitKeepsOneHp (Sint32 unitId)Returns 1 for a unit no blow may fell, which is left 1 HP: Agatio and Karst in their first battle.
voidbtPartyInsertUnitCentered (Uint16 *list, Sint32 unit)Puts unit into a unit list at the removed place nearest the list's divider, or appends it: where a Star Magician's ball takes its place.
Sint32btAbilityApplyToTarget (BATTLE_PLAN *plan, Sint32 slot)Applies the action's ability to one of its targets, slot, in the seven steps of README.md's "How an ability resolves", queueing what playback will show.
Uint32btAbilityIsPsynergy (Sint32 abilityId)Returns 1 for abilities that cost PP, and for Psy Drain whatever its cost.

Description

Applying an ability to each of its targets: damage, healing, statuses, stat changes, Djinn and special effects. Part of battle.c.

Macros in detail

AGILITY_STAGE_DOUBLED

#define AGILITY_STAGE_DOUBLED 8

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

Referenced by btAbilityApplyToTarget().

Definition at line 5 of file battle_ability.c.

STAT_CHANGE_TURNS

#define STAT_CHANGE_TURNS 7

The turns a stat change or a status lasts; a status or a lowered stat may end sooner.

Referenced by btAbilityApplyToTarget().

Definition at line 9 of file battle_ability.c.

AGILITY_CHANGE_TURNS

#define AGILITY_CHANGE_TURNS 5

Referenced by btAbilityApplyToTarget().

Definition at line 10 of file battle_ability.c.

STATUS_TURNS

#define STATUS_TURNS 7

Referenced by btAbilityApplyToTarget().

Definition at line 11 of file battle_ability.c.

REGENERATE_TURNS

#define REGENERATE_TURNS 5

Referenced by btAbilityApplyToTarget().

Definition at line 12 of file battle_ability.c.

CURSE_TURNS

#define CURSE_TURNS 7

The Grim Reaper's countdown.

Referenced by btAbilityApplyToTarget().

Definition at line 14 of file battle_ability.c.

FULL_RATE

#define FULL_RATE 256

The rate gmBattleCalculatePsynergyPowerStub and gmBattleCalculateRecoveryStub scale by: 256 is 1.

Referenced by btAbilityApplyToTarget().

Definition at line 18 of file battle_ability.c.

MESSAGE_NONE

#define MESSAGE_NONE -1

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

Referenced by btAbilityApplyToTarget().

Definition at line 21 of file battle_ability.c.

SUMMON_BONUS_HP_MAX

#define SUMMON_BONUS_HP_MAX 10000

A summon's bonus damage counts the target's max HP up to this much.

Referenced by btAbilityApplyToTarget().

Definition at line 24 of file battle_ability.c.

IS_PARTY_UNIT

#define IS_PARTY_UNIT(unitId) ((unitId) >= 0 && (unitId) <= ALLY_MAX)

Party unit ids run to ALLY_MAX; enemy units start at FIRST_ENEMY_UNIT.

Referenced by btAbilityApplyToTarget().

Definition at line 109 of file battle_ability.c.

ARE_OPPONENTS

#define ARE_OPPONENTS(unitId, otherId)

Whether two units are on opposite sides: party unit ids are below FIRST_ENEMY_UNIT, enemy ids from it.

Referenced by btAbilityApplyToTarget().

Definition at line 113 of file battle_ability.c.

CLAMP_STAT_STAGE

#define CLAMP_STAT_STAGE(stage)

Holds a stat stage within STAT_STAGE_MIN to STAT_STAGE_MAX.

Referenced by btAbilityApplyToTarget().

Definition at line 117 of file battle_ability.c.

PUSH_SIDE_MESSAGE

#define PUSH_SIDE_MESSAGE(unitId, partyMessage, enemyMessage)

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

Referenced by btAbilityApplyToTarget().

Definition at line 126 of file battle_ability.c.

REDUCE_BY_GUARD

#define REDUCE_BY_GUARD(damage, unit)

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

Referenced by btAbilityApplyToTarget().

Definition at line 136 of file battle_ability.c.

DEFENSE_HALVED

#define DEFENSE_HALVED 1

defenseCut: how much of the target's Defense an attack counts.

Torch: half

Referenced by btAbilityApplyToTarget().

Definition at line 151 of file battle_ability.c.

DEFENSE_IGNORED

#define DEFENSE_IGNORED 2

Raiden's Wrath and Trident: none

Referenced by btAbilityApplyToTarget().

Definition at line 152 of file battle_ability.c.

ITEM_ELEMENT_POWER

#define ITEM_ELEMENT_POWER 100

The element power an item, or an ability with no element, acts with.

Referenced by btAbilityApplyToTarget().

Definition at line 155 of file battle_ability.c.

DJINN_BONUS_CHANCE

#define DJINN_BONUS_CHANCE 30

An unleashed Djinni gives the Djinn bonus (more coins and experience, and a likelier item, from the enemies that fall) against a target weakest to its element, with a chance in percent of the user's power less the target's resistance, plus this many.

Referenced by btAbilityApplyToTarget().

Definition at line 161 of file battle_ability.c.

Functions in detail

btAbilityEffectAppliesToDowned

Bool btAbilityEffectAppliesToDowned(Sint32 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 user.

References Sint32.

Referenced by btAbilityApplyToTarget().

Definition at line 29 of file battle_ability.c.

btUnitKeepsOneHp

Bool btUnitKeepsOneHp(Sint32 unitId)

Returns 1 for a unit no blow may fell, which is left 1 HP: Agatio and Karst in their first battle.

References gmUnitGet() and Sint32.

Referenced by btAbilityApplyToTarget() and btUnitProcessActionEnd().

Definition at line 43 of file battle_ability.c.

btPartyInsertUnitCentered

void btPartyInsertUnitCentered(Uint16 *list, Sint32 unit)

Puts unit into a unit list at the removed place nearest the list's divider, or appends it: where a Star Magician's ball takes its place.

References Sint32.

Referenced by btAbilityApplyToTarget().

Definition at line 54 of file battle_ability.c.

btAbilityApplyToTarget

Sint32 btAbilityApplyToTarget(BATTLE_PLAN *plan, Sint32 slot)

Applies the action's ability to one of its targets, slot, in the seven steps of README.md's "How an ability resolves", queueing what playback will show. The Lost Age adds the shields that turn an ability away, the abilities that call reinforcements, and the Djinn and summon effects of its own.

References btAbilityEffectAppliesToDowned(), btEnemyClaimNameLetter(), btEnemyGetFreeUnitId(), btEnemyHasSpriteRoom(), btEnemyLetterFirstOfKind(), btEnemyList(), btFormationGetRandomMember(), btMotionReturnToSpot(), btObjectGet(), btObjectMake(), btObjectPut(), btPartyInsertUnitCentered(), btPlacementRelayoutEnemies(), btPlaybackPush(), btUnitDrainDjinn(), btUnitKeepsOneHp(), gmAbilityGetDefinitionStub(), gmBattleCalculateAttackDamageStub(), gmBattleCalculatePsynergyPowerStub(), gmBattleCalculateRecoveryStub(), gmBattleIsReviveEffectStub(), gmBattleRandomStub(), gmBattleRollEffectSuccessStub(), gmBattleUnitSetStub(), gmUnitAddPpStub(), gmUnitCalculateStub(), gmUnitGet(), gmUnitRecalculateGaugesStub(), MainRoutineStateWork, mnPartyStatusDrawStub(), RangeFalloffEffectChance, RangeFalloffEffectDamage, RangeFalloffEnemyDamage, RangeFalloffHealHp, RangeFalloffHealPp, RangeFalloffPpDamage, RangeFalloffPpLoss, RangeFalloffPsynergyDamage, RangeFalloffSummonDamage, Sint32, syGameFlagGet(), syHeapAllocate() and syHeapRelease().

Referenced by btPlaybackRun() and btStagingRunMessages().

Definition at line 167 of file battle_ability.c.

btAbilityIsPsynergy

Uint32 btAbilityIsPsynergy(Sint32 abilityId)

Returns 1 for abilities that cost PP, and for Psy Drain whatever its cost.

References gmAbilityGetDefinitionStub() and Sint32.

Referenced by btActionRunBuild() and btAIChooseAction().

Definition at line 1850 of file battle_ability.c.