Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
difficulty.py
Go to the documentation of this file.
1 import sys
2 import VS
3 import Director
4 
6  return (VS.GetDifficulty()!=1.0)
7 
8 def SetDiff(diff):
9  if (diff>VS.GetDifficulty()):
10  VS.SetDifficulty(diff)
11 
12 unbounddiff=[]
13 _key="31337ness"
14 
16  global unbounddiff
17 # print 'unbound diff '+str(unbounddiff)+' player '+str(playa)
18  if (playa>=len(unbounddiff)):
19  print 'error no difficulty set'
20  return 0
21  return unbounddiff[playa]
22 
23 class difficulty:
24  def SetDiff(self,diff):
25  if (diff>VS.GetDifficulty()):
26  VS.SetDifficulty(diff)
27 
28  def __init__(self,credsMax):
29 # print "init diff"
30  global unbounddiff
31  self.diff=[]
32  unbounddiff=[]
33  self.creds=[]
34  self.credsToMax=credsMax
35 # print "unlogical start"
36  un=VS.getPlayerX(0)
37 # print "unlogical end"
38  self.i=0
39  while (not un.isNull()):
40  newunbounddiff=0
41  newdiff=0
42 # print "get save data length"
43 # (open ("/tmp/vswroteship","w")).close()
44  diffsavelen=Director.getSaveDataLength(self.i,_key)
45  if (diffsavelen):
46 # (open ("/tmp/vsgotdata","w")).close()
47 # print "get save dat"
48  newdiff=Director.getSaveData(self.i,_key,0)
49  if (diffsavelen>1):
50  newunbounddiff=Director.getSaveData(self.i,_key,1)
51  else:
52  newunbounddiff=newdiff
53  Director.pushSaveData(self.i,_key,newunbounddiff)
54 # print "get save end"
55  else:
56 # (open ("/tmp/vsmakedata","w")).close()
57 # print "get difficulty start"
58  newdiff=VS.GetDifficulty()
59 # print "get diff done"
60  Director.pushSaveData(self.i,_key,newdiff)
61  newunbounddiff=newdiff
62  Director.pushSaveData(self.i,_key,newunbounddiff)
63 # print "done director"
64 # (open ("/tmp/vsdonedir","w")).close()
65 # (open ("/tmp/vssetdifficulty","w")).close()
66  self.diff.append(newdiff)
67  unbounddiff.append(newunbounddiff)
68 # print "set diff start"
69  SetDiff(newdiff)
70 # print "set diff end"
71  self.creds+=[un.getCredits()]
72  self.i+=1
73 # print "save unit"
74  un=VS.getPlayerX(self.i)
75 # print "done init diff"
76 # (open ("/tmp/vsdoneinitdiff","w")).close()
77 # print "done init diff FINAL"
78  def usingDifficulty (self):
79  return (VS.GetDifficulty()!=1.0)
80 
81  def getPlayerDifficulty (self,playa):
82  return self.diff[playa]
83 
84  def Execute(self):
85  global unbounddiff
86  if (self.i>=len(self.creds)):
87  self.i=0
88  else:
89  un=VS.getPlayerX(self.i)
90  if (un):
91  newcreds=un.getCredits()
92  if (self.creds[self.i]!=newcreds):
93  if (self.creds[self.i]<newcreds):
94  delta=((newcreds-self.creds[self.i])/self.credsToMax)
95  newdiff=self.getPlayerDifficulty(self.i)+delta
96  if (newdiff>.999):
97  newdiff=.999
98  #newdiff=1
99  Director.putSaveData(self.i,_key,0,newdiff)
100  SetDiff(newdiff)
101  unbounddiff[self.i]+=delta
102  Director.putSaveData(self.i,_key,1,unbounddiff[self.i])
103  self.creds[self.i]=newcreds
104  self.i+=1