enemy pointers are now actually enemy clones. (3 rocs = 3 entirely separate rocs)
[asgard.git] / utilities.py
blobf153c52f0d466160f557f89793b3727b890721c6
1 import random
3 def computeBaseError(base, err):
4 n = int(base * err)
5 beg = min(base - n,base + n)
6 end = max(base - n,base + n)
7 return random.randint(beg,end)
9 def computeHM(cdex, cagl):
10 """Hit/Miss? If Hit, how many?"""
11 # Compute Hit %
12 hitPC = (cdex - cagl) + 50
13 # Check that Hit % is in [0,100]
14 if hitPC < 0: hitPC = 0
15 if hitPC > 100: hitPC = 100
16 # Hit/Miss?
17 x = random.randint(1,100)
18 # MISS!
19 if x > hitPC: return 0
20 # HIT!
21 else:
22 if (cdex >= 1) and (cdex <= 100):
23 return 1
24 elif (cdex >= 101) and (cdex <= 200):
25 x = random.randint(1,200)
26 if (x >= 1) and (x <= 100):
27 return 1
28 elif x >= 101: return 2
29 elif (cdex >= 201) and (cdex <= 254):
30 x = random.randint(1,254)
31 if (x >= 1) and (x <= 100):
32 return 1
33 elif (x >= 101) and (x <= 200):
34 return 2
35 elif x >= 201: return 3
36 elif cdex == 255:
37 x = random.randint(1,2)
38 if x == 1: return 4
39 elif x == 2: return 5
41 def eventOccurs(percent):
42 a = random.randint(1,100)
43 b = 100 * percent
44 return (a < b)
46 def jobStatQuery(jTree,sname):
47 plus = 0
48 growthRate = 0.0
49 chance = 0.0
51 jStatQuery = jTree.xpathEval("/stat[@name='" + sname + "']")
53 if jStatQuery != []:
54 jStatElem = jStatQuery[0]
56 if jStatElem.prop("plus") != None:
57 plus = int(jStatElem.prop("plus"))
59 if jStatElem.prop("growthRate") != None:
60 growthRate = float(jStatElem.prop("growthRate"))
62 if jStatElem.prop("chance") != None:
63 growthRate = float(jStatElem.prop("chance"))
65 return (plus,chance,growthRate)