Skip to Content
The Alchemy Project

src/battle/battle_targeting.c

How an enemy, or a confused unit, picks whom to aim at: a random living target, the strongest ally, or one its ability would affect, the enemies with a strategy favouring those with the most HP. More…

Included by battle.c.

Macros

NameDescription
#defineCOUNT_STUN (unit, count)
#defineCOUNT_PARTIAL_CURES (unit, count)Counts the statuses of unit that Restore cures: delusion, stun (COUNT_STUN), sleep, the Psynergy seal and the Grim Reaper.
#defineCOUNT_ALL_CURES (unit, count)Counts the statuses Tonic cures: those, the evil spirit and poison.
#defineCOUNT_POSITIVE_MODIFIERS (unit, count)Counts what Break would undo on unit; a raised Agility is not counted.
#defineCHECK_EFFECT_TARGET (unit, action, applies, formula)How worthwhile an enemy's ability is against unit, 0 for pointless: a stat change that can still move, a cure or heal it needs, a status it lacks, a downed unit to revive.

Functions

NameDescription
Sint32btAIChooseRandomTarget (Sint32 party)Picks a random living target on one side: the party (PLACE_PARTY | slot) when party is set, otherwise the enemies (PLACE_ENEMY | slot); 0 when none lives.
Sint32btUnitFindStrongestAlly (Uint32 unitId)Finds the living unit with the highest Attack on unitId's side (the party for ids up to ALLY_MAX, else the enemies), other than unitId itself; unitId when no other lives.
Sint32btAIChooseTarget (Sint32 userId, ABILITY_DEFINITION *action)Picks the target of an enemy's ability, or a confused unit's, at random among those it would affect.

Description

How an enemy, or a confused unit, picks whom to aim at: a random living target, the strongest ally, or one its ability would affect, the enemies with a strategy favouring those with the most HP. Part of battle.c.

Macros in detail

COUNT_STUN

#define COUNT_STUN(unit, count)

Definition at lines 90 and 94 of file battle_targeting.c.

COUNT_PARTIAL_CURES

#define COUNT_PARTIAL_CURES(unit, count)

Counts the statuses of unit that Restore cures: delusion, stun (COUNT_STUN), sleep, the Psynergy seal and the Grim Reaper.

Definition at line 103 of file battle_targeting.c.

COUNT_ALL_CURES

#define COUNT_ALL_CURES(unit, count)

Counts the statuses Tonic cures: those, the evil spirit and poison.

Definition at line 115 of file battle_targeting.c.

COUNT_POSITIVE_MODIFIERS

#define COUNT_POSITIVE_MODIFIERS(unit, count)

Counts what Break would undo on unit; a raised Agility is not counted.

Definition at line 125 of file battle_targeting.c.

CHECK_EFFECT_TARGET

#define CHECK_EFFECT_TARGET(unit, action, applies, formula)

How worthwhile an enemy's ability is against unit, 0 for pointless: a stat change that can still move, a cure or heal it needs, a status it lacks, a downed unit to revive.

Referenced by btAIChooseTarget().

Definition at line 146 of file battle_targeting.c.

Functions in detail

btAIChooseRandomTarget

Sint32 btAIChooseRandomTarget(Sint32 party)

Picks a random living target on one side: the party (PLACE_PARTY | slot) when party is set, otherwise the enemies (PLACE_ENEMY | slot); 0 when none lives.

References gmBattleRandomStub(), gmUnitGet() and Sint32.

Referenced by btActionRunBuild(), btAIChooseAction() and btStagingPlanDaedalus().

Definition at line 7 of file battle_targeting.c.

btUnitFindStrongestAlly

Sint32 btUnitFindStrongestAlly(Uint32 unitId)

Finds the living unit with the highest Attack on unitId's side (the party for ids up to ALLY_MAX, else the enemies), other than unitId itself; unitId when no other lives.

References gmUnitGet() and Sint32.

Referenced by btActionRunBuild().

Definition at line 43 of file battle_targeting.c.

btAIChooseTarget

Sint32 btAIChooseTarget(Sint32 userId, ABILITY_DEFINITION *action)

Picks the target of an enemy's ability, or a confused unit's, at random among those it would affect. A single-target attack by an enemy with a strategy favours the targets with the most HP (TARGET_STRATEGY_MOST_HP), or with the highest maximum HP.

References gmEnemyGetDefinitionStub(), gmUnitGet() and Sint32.

Referenced by btAIChooseAction().

Definition at line 300 of file battle_targeting.c.