src/game/game_battle_arithmetic.c
Battle arithmetic: element multipliers, random rolls and success rates. More…
Included by game.c.
Macros
| Name | Description | |
|---|---|---|
#define | LUCK_IMMUNITY 40 | The Luck at which a target shrugs off poison, haunting, instant death, the curse, Leave One HP, Gasp and Gale. |
#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 (the attacker's power less the target's resistance): 256 plus 1.28 a point, the difference held to -200 to 200, its effect half with halve. |
Uint32 | gmBattleRandom (void) | The battle's random number generator, the same as syRandom with its own seed: returns bits 8 to 23 of the new seed. |
Uint32 | gmBattleRandomPercent (void) | Returns a battle random number from 0 to 99. |
Sint32 | gmBattleCalculateAttackDamage (Sint32 attack, Sint32 defense, Sint32 addedPower, Sint32 elementDifference) | A physical attack's damage: half of what the attack exceeds the defense by, plus the added power, scaled by the element difference at half its effect. |
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 *owner) | 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 | gmEnemyIsDragon (Sint32 enemyId) | Returns 1 when enemy enemyId is one of EnemyDragonIds. |
Bool | gmEnemyIsSeaCreature (Sint32 enemyId) | Returns 1 when enemy enemyId is one of EnemySeaCreatureIds. |
Bool | gmBattleAbilityIsWeakToEffect (const UNIT *target, Sint32 effectId) | Returns 1 when the unit is weak to effect effectId: one of three listed for its enemy kind (ENEMY_DEFINITION.weakEffects) or class (CLASS_DEFINITION.weakEffects). |
Bool | gmBattleIsReviveEffect (Sint32 effectId) | Returns 1 for the revive effects, which only work on a downed unit. |
Sint32 | gmBattleRollEffectSuccess (Sint32 caster, Sint32 target, Sint32 element, Sint32 effectId, Sint32 successScale) | Rolls whether effect effectId takes hold on target: it fails at once when there is nothing for it to do. |
Description
Battle arithmetic: element multipliers, random rolls and success rates. Part
of game.c.
Macros in detail
LUCK_IMMUNITY
#define LUCK_IMMUNITY 40
The Luck at which a target shrugs off poison, haunting, instant death, the curse, Leave One HP, Gasp and Gale.
Referenced by gmBattleRollEffectSuccess().
Definition at line 305 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 307 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 (the attacker's
power less the target's 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
Uint32 gmBattleRandom(void)
The battle's random number generator, the same as syRandom with its own seed:
returns bits 8 to 23 of the new seed.
References BattleRandomSeed and Sint32.
Referenced by gmBattleRandomPercent() and gmEquipmentRollUnleash().
Definition at line 53 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 63 of file game_battle_arithmetic.c.
gmBattleCalculateAttackDamage
Sint32 gmBattleCalculateAttackDamage(Sint32 attack, Sint32 defense, Sint32 addedPower, Sint32 elementDifference)
A physical attack's damage: half of what the attack exceeds the defense by, plus the added power, scaled by the element difference at half its effect.
References gmBattleGetElementMultiplier() and Sint32.
Definition at line 70 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 91 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 104 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 121 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 137 of file game_battle_arithmetic.c.
gmEquipmentRollUnleash
Sint32 gmEquipmentRollUnleash(UNIT *owner)
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 166 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 196 of file game_battle_arithmetic.c.
gmEnemyIsDragon
Bool gmEnemyIsDragon(Sint32 enemyId)
Returns 1 when enemy enemyId is one of EnemyDragonIds.
References EnemyDragonIds and Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 236 of file game_battle_arithmetic.c.
gmEnemyIsSeaCreature
Bool gmEnemyIsSeaCreature(Sint32 enemyId)
Returns 1 when enemy enemyId is one of EnemySeaCreatureIds.
References EnemySeaCreatureIds and Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 249 of file game_battle_arithmetic.c.
gmBattleAbilityIsWeakToEffect
Bool gmBattleAbilityIsWeakToEffect(const UNIT *target, Sint32 effectId)
Returns 1 when the unit is weak to effect effectId: one of three listed for
its enemy kind (ENEMY_DEFINITION.weakEffects) or class
(CLASS_DEFINITION.weakEffects). Called by gmBattleRollEffectSuccess.
References gmClassGetDefinition(), gmEnemyGetDefinition() and Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 264 of file game_battle_arithmetic.c.
gmBattleIsReviveEffect
Bool gmBattleIsReviveEffect(Sint32 effectId)
Returns 1 for the revive effects, which only work on a downed unit.
References Sint32.
Referenced by gmBattleRollEffectSuccess().
Definition at line 292 of file game_battle_arithmetic.c.
gmBattleRollEffectSuccess
Sint32 gmBattleRollEffectSuccess(Sint32 caster, Sint32 target, Sint32 element, Sint32 effectId, Sint32 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 element's level less half the target's
luck (so every two points of luck take off three), plus WEAKNESS_BONUS
against a weakness, times successScale percent. A base rate of 0 or less
counts as its magnitude, still scaled but skipping the levels, luck and
weakness; 0 still succeeds when gmBattleRandomPercent gives 0, about 1 time
in 100. Luff, Gasp and Fire Puppet's Paralyze get three tries. Raiden's Wrath
and the Trident take hold only on a dragon or a sea creature; a target with
LUCK_IMMUNITY Luck or more shrugs off poison, haunting, instant death, the
curse, Leave One HP, Gasp and Gale, and a character always shrugs off Gale.
References gmBattleAbilityIsWeakToEffect(), gmBattleGetEffectBaseSuccessRate(), gmBattleIsReviveEffect(), gmBattleRandomPercent(), gmEnemyIsDragon(), gmEnemyIsSeaCreature(), gmUnitGet(), gmUnitGetElementLevel() and Sint32.
Definition at line 320 of file game_battle_arithmetic.c.