MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / getPsiAttackChance

Function getPsiAttackChance

game/state/battle/battleunit.cpp:52–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52static int getPsiAttackChance(int psiAttack, int psiDefense, PsiStatus status, bool isAttack)
53{
54 // Psi chance as per Wong's Guide, confirmed by Mell
55 /*
56 100*attack*(100-defense)
57 success rate = --------------------------------------
58 attack*(100-defense) + 100*defense
59
60 psiattack rating * 40
61 attack = ---------------------------
62 initiation cost of action
63
64 Note: As tested by Mell, Probe is min 20%
65 */
66 int cost = getPsiCost(status, isAttack);
67 int attack = psiAttack * 40 / cost;
68 int defense = psiDefense;
69 int chance = 0;
70 if (attack != 0 || defense != 0)
71 {
72 chance = (100 * attack * (100 - defense)) / (attack * (100 - defense) + 100 * defense);
73 }
74 if (status == PsiStatus::Probe && attack != 0)
75 {
76 chance = std::max(20, chance);
77 }
78 return chance;
79}
80
81namespace
82{

Callers 2

applyMoraleDamageMethod · 0.85

Calls 1

getPsiCostFunction · 0.85

Tested by

no test coverage detected