Added Python versions of stat formulae.
[zzz-pokedex.git] / pokedex / formulae.py
1 # encoding: utf8
2 """Faithful translations of calculations the games make."""
3
4 def calculated_stat(base_stat, level, iv, effort):
5 """Returns the calculated stat -- i.e. the value actually shown in the game
6 on a Pokémon's status tab.
7 """
8
9 # Remember: this is from C; use floor division!
10 return (base_stat * 2 + iv + effort // 4) * level // 100 + 5
11
12 def calculated_hp(base_hp, level, iv, effort):
13 """Similar to `calculated_stat`, except with a slightly different formula
14 used specifically for HP.
15 """
16
17 # Shedinja's base stat of 1 is special; its HP is always 1
18 if base_hp == 1:
19 return 1
20
21 return (base_hp * 2 + iv + effort // 4) * level // 100 + 10 + level