src/game/game_battle_arithmetic.c
Battle arithmetic: element multipliers, random rolls and success rates. More…
Included by game.c.
Macros
| Name | Description | |
|---|---|---|
#define | WEAK_EFFECTS_READ 3 | The effects a unit is weak to: the first three of its enemy kind's or class's weakEffects, the fourth never read. |
#define | WEAKNESS_BONUS 25 | The points of chance an effect gains against a target weak to it. |
Functions
| Name | Description | |
|---|---|---|
Sint32 | gmBattleGetElementMultiplier (Sint32 difference, Sint32 halve) | Returns the multiplier, 256 for 1x, for an element difference (power less resistance): 256 plus 1.28 a point, the difference held to -200 to 200, its effect half with halve. |
Sint32 | gmBattleRandom (void) | The battle's random number generator, the same as syRandom with its own seed, which link battles exchange. |
Uint32 | gmBattleRandomPercent (void) | Returns a battle random number from 0 to 99. |
Sint32 | gmBattleCalculateAttackDamage (Sint32 attack, Sint32 defense, Sint32 addedPower, Sint32 elementDifference) | Scales max(attack - defense, 0) plus twice the added power by half the element multiplier, then halves it. |
Sint32 | gmBattleCalculatePsynergyPower (Sint32 power, Sint32 elementDifference, Sint32 powerMultiplier) | Returns Psynergy's power times the element multiplier and powerMultiplier. |
Sint32 | gmBattleCalculateRecovery (Sint32 power, Sint32 elementPower, Sint32 powerMultiplier) | Returns the amount healed: power times powerMultiplier and the multiplier for the healer's element power above HEALING_BASE_POWER. |
Sint32 | gmUnitGetAttackElement (Sint32 unitId) | 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. |
Sint32 | gmEquipmentGetUnleashRateBonus (UNIT *unit) | Returns the unleash chance, in percent, that a unit's equipment adds (EQUIP_EFFECT_ADD_UNLEASH_CHANCE). |
Sint32 | gmEquipmentRollUnleash (UNIT *unit) | Rolls whether a character's weapon unleashes, 5 percent a point of its chance. |
Sint32 | gmBattleGetEffectBaseSuccessRate (Sint32 effectId) | Returns the base chance in percent of an effect; a negative one is fixed, and effects not listed always work. |
Bool | gmBattleAbilityIsWeakToEffect (const UNIT *target, Sint32 effectId) | Returns 1 when the unit is weak to the effect: one of those its enemy kind or class lists. |
Bool | gmBattleIsReviveEffect (Sint32 effectId) | Returns 1 for the revive effects (Revive, Quartz, Dew), which only work on a downed unit. |
Sint32 | gmBattleRollEffectSuccess (Sint32 caster, Sint32 target, Sint32 element, Sint32 effectId, Sint32 successScale) | Rolls whether an effect takes hold on target: the base rate, plus three points for each level the caster's element is above the target's and less three for every two points of the target's luck, plus WEAKNESS_BONUS against a weakness, all times successScale percent. |
Description
Battle arithmetic: element multipliers, random rolls and success rates. Part
of game.c.
Macros in detail
WEAK_EFFECTS_READ
#define WEAK_EFFECTS_READ 3
The effects a unit is weak to: the first three of its enemy kind's or class's weakEffects, the fourth never read.
Referenced by gmBattleAbilityIsWeakToEffect().
Definition at line 234 of file game_battle_arithmetic.c.
WEAKNESS_BONUS
#define WEAKNESS_BONUS 25
The points of chance an effect gains against a target weak to it.
Referenced by gmBattleRollEffectSuccess().
Definition at line 281 of file game_battle_arithmetic.c.
Functions in detail
gmBattleGetElementMultiplier
Sint32 gmBattleGetElementMultiplier(Sint32 difference, Sint32 halve)
Returns the multiplier, 256 for 1x, for an element difference (power less
resistance): 256 plus 1.28 a point, the difference held to -200 to 200, its
effect half with halve.
References ElementPowerResistCurve and Sint32.
Referenced by gmBattleCalculateAttackDamage(), gmBattleCalculatePsynergyPower() and gmBattleCalculateRecovery().
Definition at line 7 of file game_battle_arithmetic.c.
gmBattleRandom
Sint32 gmBattleRandom(void)
The battle's random number generator, the same as syRandom with its own seed,
which link battles exchange.
References BattleRandomSeed and Sint32.
Referenced by gmBattleRandomPercent() and gmEquipmentRollUnleash().
Definition at line 55 of file game_battle_arithmetic.c.
gmBattleRandomPercent
Uint32 gmBattleRandomPercent(void)
Returns a battle random number from 0 to 99.
References gmBattleRandom().
Referenced by gmBattleRollEffectSuccess().
Definition at line 65 of file game_battle_arithmetic.c.
gmBattleCalculateAttackDamage
Sint32 gmBattleCalculateAttackDamage(Sint32 attack, Sint32 defense, Sint32 addedPower, Sint32 elementDifference)
Scales max(attack - defense, 0) plus twice the added power by half the element multiplier, then halves it.
References gmBattleGetElementMultiplier() and Sint32.
Definition at line 72 of file game_battle_arithmetic.c.
gmBattleCalculatePsynergyPower
Sint32 gmBattleCalculatePsynergyPower(Sint32 power, Sint32 elementDifference, Sint32 powerMultiplier)
Returns Psynergy's power times the element multiplier and powerMultiplier.
References gmBattleGetElementMultiplier() and Sint32.
Definition at line 93 of file game_battle_arithmetic.c.
gmBattleCalculateRecovery
Sint32 gmBattleCalculateRecovery(Sint32 power, Sint32 elementPower, Sint32 powerMultiplier)
Returns the amount healed: power times powerMultiplier and the multiplier for
the healer's element power above HEALING_BASE_POWER.
References gmBattleGetElementMultiplier() and Sint32.
Definition at line 106 of file game_battle_arithmetic.c.
gmUnitGetAttackElement
Sint32 gmUnitGetAttackElement(Sint32 unitId)
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.
References gmEnemyGetAttackElement(), gmInventoryGetEquippedDefinition(), gmUnitGet() and Sint32.
Definition at line 123 of file game_battle_arithmetic.c.
gmEquipmentGetUnleashRateBonus
Sint32 gmEquipmentGetUnleashRateBonus(UNIT *unit)
Returns the unleash chance, in percent, that a unit's equipment adds
(EQUIP_EFFECT_ADD_UNLEASH_CHANCE).
References gmItemGetDefinition() and Sint32.
Referenced by gmEquipmentRollUnleash().
Definition at line 139 of file game_battle_arithmetic.c.
gmEquipmentRollUnleash
Sint32 gmEquipmentRollUnleash(UNIT *unit)
Rolls whether a character's weapon unleashes, 5 percent a point of its
chance. Returns the unleash's ability, or ABILITY_ATTACK for a plain attack.
References gmBattleRandom(), gmEquipmentGetUnleashRateBonus(), gmInventoryGetEquippedDefinition() and Sint32.
Definition at line 168 of file game_battle_arithmetic.c.
gmBattleGetEffectBaseSuccessRate
Sint32 gmBattleGetEffectBaseSuccessRate(Sint32 effectId)
Returns the base chance in percent of an effect; a negative one is fixed, and effects not listed always work.
References Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 198 of file game_battle_arithmetic.c.
gmBattleAbilityIsWeakToEffect
Bool gmBattleAbilityIsWeakToEffect(const UNIT *target, Sint32 effectId)
Returns 1 when the unit is weak to the effect: one of those its enemy kind or class lists.
References gmClassGetDefinition(), gmEnemyGetDefinition() and Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 238 of file game_battle_arithmetic.c.
gmBattleIsReviveEffect
Bool gmBattleIsReviveEffect(Sint32 effectId)
Returns 1 for the revive effects (Revive, Quartz, Dew), which only work on a downed unit.
References Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 269 of file game_battle_arithmetic.c.
gmBattleRollEffectSuccess
Sint32 gmBattleRollEffectSuccess(Sint32 caster, Sint32 target, Sint32 element, Sint32 effectId, Sint32 successScale)
Rolls whether an effect takes hold on target: the base rate, plus three
points for each level the caster's element is above the target's and less
three for every two points of the target's luck, plus WEAKNESS_BONUS against
a weakness, all times successScale percent. Luff's seal
(ABILITY_EFFECT_SEAL_2_TURNS) gets three tries.
References gmBattleAbilityIsWeakToEffect(), gmBattleGetEffectBaseSuccessRate(), gmBattleIsReviveEffect(), gmBattleRandomPercent(), gmUnitGet(), gmUnitGetElementLevel() and Sint32.
Definition at line 288 of file game_battle_arithmetic.c.