Alchemy
Loading...
Searching...
No Matches

battle_calc.c File Reference

Battle arithmetic: element multipliers, random rolls and success rates. More...

Go to the source code of this file.

Functions

s32 Battle_GetElementMultiplier (s32 input, s32 halve)
 Returns the multiplier (256 = 1x) for an element difference input, read from a five-point line (gElement_PowerResistCurve); with halve the effect of the difference is half.
s32 BattleRandom (void)
 The battle's random number generator, the same linear congruential one as Random16 with its own seed.
u32 BattleRandomPercent (void)
 Returns a battle random number from 0 to 99.
s32 Battle_CalcAttackDamage (s32 attack, s32 defense, s32 addedPower, s32 elementDifference)
 Scales max(attack - defense, 0) + twice the action's added power by the elemental multiplier, then halves it.
s32 Battle_CalcPsynergyPower (s32 power, s32 elementDifference, s32 powerMultiplier)
 Returns the power of Psynergy: power times the multiplier for the element difference (power minus resistance, 0..512 with 256 = 1x) and the supplied powerMultiplier (also 256 = 1x).
s32 Battle_CalcRecovery (s32 power, s32 elementPower, s32 powerMultiplier)
 Returns the amount healed: power and powerMultiplier (256 is 1x) times the multiplier for twice the healer's element power above 100.
s32 Item_GetEquippedElement (s32 owner)
 Returns the element the unit attacks with (ELEMENT_NONE for none): an enemy's comes from its kind, a character's from its equipped weapon.
s32 Equipment_GetUnleashRateBonus (struct BattleUnit *unit)
 Returns the unleash chance, in percent, that a unit's equipment adds (ITEM_EFFECT_ADD_UNLEASH_CHANCE).
s32 RollWeaponUnleash (struct BattleUnit *owner)
 Rolls whether a character's weapon unleashes: its chance is the weapon's unleashChance times 5 percent plus what the equipment adds.
s32 BattleFx_GetBaseSuccessRate (s32 effectId)
 Returns the base chance, in percent, of effect effectId.
s32 BattleTarget_IsWeakToEffect (const struct BattleUnit *target, s32 effectId)
 Returns 1 when the unit is weak to effect effectId: one of three listed for its enemy kind (EnemyDefinition.unk48) or class (ClassDefinition.unk50).
s32 Battle_IsReviveEffect (s32 effectId)
 Returns 1 for the revive effects (Revive, Quartz, Dew), which only work on a downed unit.
s32 BattleFx_RollSuccess (s32 caster, s32 target, s32 resistanceCategory, s32 effectId, s32 successScale)
 Rolls whether effect effectId takes hold on target: it fails at once when there is nothing for it to do.

Detailed Description

Battle arithmetic: element multipliers, random rolls and success rates.

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

Definition in file battle_calc.c.

Function Documentation

◆ Battle_GetElementMultiplier()

s32 Battle_GetElementMultiplier ( s32 input,
s32 halve )

Returns the multiplier (256 = 1x) for an element difference input, read from a five-point line (gElement_PowerResistCurve); with halve the effect of the difference is half.

Called by the damage and recovery formulas below.

Definition at line 11 of file battle_calc.c.

Referenced by Battle_CalcAttackDamage(), Battle_CalcPsynergyPower(), Battle_CalcRecovery(), and Battle_GetElementMultiplier().

◆ BattleRandom()

s32 BattleRandom ( void )

The battle's random number generator, the same linear congruential one as Random16 with its own seed.

Returns bits 8 to 23 of the new seed and writes gBattleRandomSeed. Rolls that use it advance independently of Random16; link battles exchange this seed before resolving the round.

Definition at line 56 of file battle_calc.c.

Referenced by BattleRandom(), BattleRandomPercent(), and RollWeaponUnleash().

◆ BattleRandomPercent()

u32 BattleRandomPercent ( void )

Returns a battle random number from 0 to 99.

Definition at line 65 of file battle_calc.c.

Referenced by BattleFx_RollSuccess(), and BattleRandomPercent().

◆ Battle_CalcAttackDamage()

s32 Battle_CalcAttackDamage ( s32 attack,
s32 defense,
s32 addedPower,
s32 elementDifference )

Scales max(attack - defense, 0) + twice the action's added power by the elemental multiplier, then halves it.

elementDifference is power minus resistance; its effect here is half Psynergy's (128..384 with 256 = 1x). Reached through GAME.S as BattleAtkCalc, which BattleTargetExec calls for attacks and physical abilities.

Definition at line 72 of file battle_calc.c.

Referenced by Battle_CalcAttackDamage().

◆ Battle_CalcPsynergyPower()

s32 Battle_CalcPsynergyPower ( s32 power,
s32 elementDifference,
s32 powerMultiplier )

Returns the power of Psynergy: power times the multiplier for the element difference (power minus resistance, 0..512 with 256 = 1x) and the supplied powerMultiplier (also 256 = 1x).

Reached through GAME.S as BattlePowerCalc, which BattleTargetExec calls for Psynergy damage.

Definition at line 95 of file battle_calc.c.

Referenced by Battle_CalcPsynergyPower().

◆ Battle_CalcRecovery()

s32 Battle_CalcRecovery ( s32 power,
s32 elementPower,
s32 powerMultiplier )

Returns the amount healed: power and powerMultiplier (256 is 1x) times the multiplier for twice the healer's element power above 100.

elementPower : the healer's power in the element (100 is 1x) Reached through GAME.S as BattleRecoveryCalc, which the battle and the menu's healing use.

Definition at line 111 of file battle_calc.c.

Referenced by Battle_CalcRecovery().

◆ Item_GetEquippedElement()

s32 Item_GetEquippedElement ( s32 owner)

Returns the element the unit attacks with (ELEMENT_NONE for none): an enemy's comes from its kind, a character's from its equipped weapon.

Called by the battle plan for an attack's element.

Definition at line 127 of file battle_calc.c.

Referenced by Item_GetEquippedElement().

◆ Equipment_GetUnleashRateBonus()

s32 Equipment_GetUnleashRateBonus ( struct BattleUnit * unit)

Returns the unleash chance, in percent, that a unit's equipment adds (ITEM_EFFECT_ADD_UNLEASH_CHANCE).

Called by RollWeaponUnleash and the battle plan.

Definition at line 143 of file battle_calc.c.

Referenced by Equipment_GetUnleashRateBonus(), and RollWeaponUnleash().

◆ RollWeaponUnleash()

s32 RollWeaponUnleash ( struct BattleUnit * owner)

Rolls whether a character's weapon unleashes: its chance is the weapon's unleashChance times 5 percent plus what the equipment adds.

Returns the unleash action, or 1 for a plain attack. Called by the battle plan for each Attack command.

Definition at line 168 of file battle_calc.c.

Referenced by RollWeaponUnleash().

◆ BattleFx_GetBaseSuccessRate()

s32 BattleFx_GetBaseSuccessRate ( s32 effectId)

Returns the base chance, in percent, of effect effectId.

A negative value is a fixed chance that elements and luck do not change; effects not listed always work (-100). Called by BattleFx_RollSuccess.

Definition at line 194 of file battle_calc.c.

Referenced by BattleFx_GetBaseSuccessRate(), and BattleFx_RollSuccess().

◆ BattleTarget_IsWeakToEffect()

s32 BattleTarget_IsWeakToEffect ( const struct BattleUnit * target,
s32 effectId )

Returns 1 when the unit is weak to effect effectId: one of three listed for its enemy kind (EnemyDefinition.unk48) or class (ClassDefinition.unk50).

Called by BattleFx_RollSuccess.

Definition at line 250 of file battle_calc.c.

Referenced by BattleFx_RollSuccess(), and BattleTarget_IsWeakToEffect().

◆ Battle_IsReviveEffect()

s32 Battle_IsReviveEffect ( s32 effectId)

Returns 1 for the revive effects (Revive, Quartz, Dew), which only work on a downed unit.

Called by the battle's targeting, which lets them aim at downed members, and by BattleFx_RollSuccess.

Definition at line 274 of file battle_calc.c.

Referenced by Battle_IsReviveEffect(), and BattleFx_RollSuccess().

◆ BattleFx_RollSuccess()

s32 BattleFx_RollSuccess ( s32 caster,
s32 target,
s32 resistanceCategory,
s32 effectId,
s32 successScale )

Rolls whether effect effectId takes hold on target: it fails at once when there is nothing for it to do.

The chance is the base rate, plus three times the caster's lead over the target in the element, less half the target's luck, plus 25 against a weakness, times successScale percent. Luff gets three tries. Reached through GAME.S as BattleHitCheck, which BattleTargetExec and the battle plan call for each target of an ability with an effect.

Definition at line 290 of file battle_calc.c.

Referenced by BattleFx_RollSuccess().