Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
verify_missions.py
Go to the documentation of this file.
1 
2 import VS
3 import faction_ships
4 
5 campaign_name={}
6 
7 def verifyMission(name,args,campaign=None):
8  mission=None
9  if name=='directions_mission':
10  mission=DirectionsVerifier(args)
11  elif name=='ambush':
12  mission=AmbushVerifier(args)
13  elif name=='bounty_leader':
14  mission=BountyLeaderVerifier(args)
15  elif name=='bounty_troop':
16  mission=BountyTroopVerifier(args)
17  elif name=='bounty':
18  mission=BountyVerifier(args)
19  elif name=='cargo_mission':
20  mission=CargoVerifier(args)
21  elif name=='wrong_escort':
22  mission=WrongEscortVerifier(args)
23  elif name=='cleansweep':
24  mission=CleansweepVerifier(args)
25  elif name=='cleansweep_escort':
26  mission=CleansweepEscortVerifier(args)
27  elif name=='defend':
28  mission=DefendVerifier(args)
29  elif name=='escort_local':
30  mission=EscortLocalVerifier(args)
31  elif name=='escort_mission':
32  mission=EscortVerifier(args)
33  elif name=='patrol_ambush':
34  mission=PatrolAmbushVerifier(args)
35  elif name=='patrol_enemies':
36  mission=PatrolEnemiesVerifier(args)
37  elif name=='patrol':
38  mission=PatrolVerifier(args)
39  elif name=='plunder':
40  mission=PlunderVerifier(args)
41  elif name=='rescue':
42  mission=RescueVerifier(args)
43  elif name=='tail':
44  mission=TailVerifier(args)
45  elif name=='tripatrol':
46  mission=TripatrolVerifier(args)
47  elif name=='ambush_scan':
48  mission=AmbushScan(args)
49  if mission is None:
50  print 'Unsupported mission type'
51  return False
52  else:
53  return mission.isValid()
54 
55 class Default:
56  pass
57 
58 class NoDefault:
59  pass
60 class Argument:
61 
62  NAME="Argument"
63 
64  def __init__(self, nextarg=None, value=NoDefault()):
65  self.warnings = []
66  self.value = None
67  self.nextarg = nextarg
68  self.set(value)
69 
70  def set(self, newvalue):
71  self.value = newvalue
72  arg = self.nextarg
73  if arg is not None:
74  arg.set(self.value)
75 
76  def isValid(self):
77 # print "valid %s?"%self.NAME
78  if isinstance(self.value, NoDefault):
79  self.warn("No default exists for unset argument")
80  return False
81  elif isinstance(self.value, Default):
82  return True
83  valid = self.checkValidity()
84  arg = self.nextarg
85  if arg is not None:
86  valid = valid or arg.isValid()
87  if not valid:
88  self.printwarnings()
89  return valid
90 
91  def checkValidity(self):
92  return True
93 
94  def warn(self, text):
95  self.warnings.append(text)
96 
97  def printwarnings(self):
98  for warning in self.warnings:
99  print "\'%s\' Argument Warning: "%self.NAME + warning
100 
102 
103  NAME="PositiveInt"
104 
105  def checkValidity(self):
106  if isinstance(self.value,long) or isinstance(self.value,int):
107  if self.value < 0:
108  self.warn("Value %s is not a positive integer"%str(self.value))
109  return False
110  else:
111  self.warn("Value %s is not an integer, much less positive."%str(self.value))
112  return False
113  return True
114 
116 
117  NAME="PositiveIntList"
118 
119  def checkValidity(self):
120  if isinstance(self.value,list):
121  for val in self.value:
122  if isinstance(val,long) or isinstance(val,int):
123  if self.value < 0:
124  self.warn("Value %s is not a positive integer"%str(val))
125  return False
126  else:
127  self.warn("Value %s is not an integer, much less positive."%str(val))
128  return False
129  else:
130  self.warn("Value %s is not a list, much less a list of integers."%str(self.value))
131  return False
132  return True
133 
135 
136  NAME="PositiveFraction"
137 
138  def checkValidity(self):
139  if not isinstance(self.value,float) or self.value < 0 or self.value > 1:
140  if isinstance(self.value,int) and (self.value == 0 or self.value == 1):
141  return True
142  self.warn("Value %s is not a positive fraction"%str(self.value))
143  return False
144  return True
145 
147 
148  NAME="String"
149 
150  def checkValidity(self):
151  if not isinstance(self.value,str):
152  self.warn("Value "+str(self.value)+"is not a string")
153  return False
154  return True
155 
157 
158  NAME="PositiveNumber"
159 
160  def checkValidity(self):
161  if not (isinstance(self.value,float) or isinstance(self.value,int)) or self.value < 0:
162  self.warn("Value is not a positive number")
163  return False
164  return True
165 
167 
168  NAME="ZeroInt"
169 
170  def checkValidity(self):
171  if isinstance(self.value,long) or isinstance(self.value,int):
172  if self.value != 0:
173  self.warn("Value %s is not 0"%str(self.value))
174  return False
175  else:
176  self.warn("Value %s is not an integer, much less 0"%str(self.value))
177  return True
178 
180 
181  NAME="System"
182 
183  def checkValidity(self):
184  v = ( VS.universe.has_key(self.value) )
185  if not v:
186  self.warn("System %s does not exist in universe"%self.value)
187  return False
188  return True
189 
191 
192  NAME="SystemTuple"
193 
194  def checkValidity(self):
195  for sys in self.value:
196  v = ( VS.universe.has_key(sys) )
197  if not v:
198  self.warn("System %s does not exist in universe"%sys)
199  return False
200  return True
201 
203 
204  NAME="Destination"
205 
206  def checkValidity(self):
207  self.warn("No way to test destination exists")
208  return True
209 
211 
212  NAME="SaveVar"
213 
214  def checkValidity(self):
215  global campaign_name
216  campvar=self.value.find("_mission")
217  if campvar!=-1 and self.value[0:campvar] in campaign_name:
218  return True
219  elif self.value.find("visited_") == 0:
220  temparg=System(None,self.value[8:])#FIXME hellcatv added
221  if temparg.isValid():
222  return True
223  elif self.value=="menesch_dead" or self.value=="jones_dead" or self.value=="awacs_escort":
224  return True
225  self.warn("%s is not valid"%self.value)
226  return False
227 
229 
230  NAME="Faction"
231 
232  def checkValidity(self):
233  if self.value not in VS._factions:
234  self.warn("'%s' is not a valid faction"%self.value)
235  return False
236  return True
238 
239  NAME="Faction"
240 
241  def checkValidity(self):
242  if type(self.value)!=type(()) and type(self.value)!=type([]):
243  self.warn(str(self.value)+" is not a tuple")
244  return False
245  for value in self.value:
246  if value not in VS._factions:
247  self.warn("'%s' is not a valid faction"%value)
248  return False
249  return True
250 
251 class DynFG(String):
252  NAME="DynFG"
254  NAME="DynFG"
255  def checkValidity(self):
256  if type(self.value)!=type(()) and type(self.value)!=type([]):
257  self.warn(str(self.value)+" is not a tuple");
258  return False;
259  return True
260 
261 
263 
264  NAME="ShipFactionPair"
265 
266  def checkValidity(self):
267  if not isinstance(self.value,tuple):
268  self.warn("is not a tuple")
269  return False
270  if len(self.value) != 2:
271  self.warn("%s does not have a length of 2")
272  return False
273  if self.value[0] not in faction_ships.stattable.keys():
274  self.warn("%s is not a valid shiptype")%str(self.value[0])
275  return False
276  if self.value[1] not in VS._factions:
277  self.warn("%s is not a valid faction")%str(self.value[1])
278  return False
279  return True
280 
282 
283  NAME="FactionList"
284 
285  def checkValidity(self):
286  if type(self.value)==type(""):
287  self.value=[self.value]
288  for val in self.value:
289  if val not in VS._factions:
290  self.warn("%s is not a valid faction"%val)
291  return False
292  return True
293 
295 
296  NAME="ShipType"
297 
298  def checkValidity(self):
299  if self.value not in faction_ships.stattable.keys():
300  self.warn(str(self.value)+" ship type unknown")
301  return False
302  return True
303 
305 
306  NAME="ShipTypeList"
307 
308  def checkValidity(self):
309  if type(self.value)==type(""):
310  self.value=[self.value]
311  for val in self.value:
312  if val not in faction_ships.stattable.keys():
313  self.warn("%s is not a valid shiptype"%val)
314  return False
315  return True
317  NAME="TupleTextList"
318  def checkValidity(self):
319  try:
320  for value in self.value:
321  temparg=TextList(None,value)
322  if temparg.isValid():
323  return True
324  except:
325  self.warn (str(self.value)+" is not iterable")
326  return False
328 
329  NAME="TextList"
330 
331  def checkValidity(self):
332  if not isinstance(self.value,list):
333  self.warn(str(self.value)+"is not a list type")
334  return False
335  for item in self.value:
336  if not isinstance(item,str):
337  if isinstance(item,tuple):
338  if len(item) == 2:
339  if not isinstance(item[0],str) and isinstance(item[1],type(bool(True))):
340  self.warn("item is not a (str,bool) pair")
341  return False
342  elif len(item) == 3:
343  if not (isinstance(item[0],str) and isinstance(item[1],type(bool(True))) and isinstance(item[2],str)):
344  self.warn("item %s is not a (str,bool,str) triplet"%str(item))
345  return False
346  elif len(item) == 0:
347  pass
348  else:
349  self.warn("item %s has too many entries"%str(item))
350  return False
351  else:
352  self.warn("is not a list of strings")
353  return False
354  return True
355 
357 
358  NAME="Boolean"
359 
360  def checkValidity(self):
361  try:
362  isbool = self.value == True or self.value == False
363  except:
364  isbool = False
365  if not isbool:
366  self.warn("is not a boolean type")
367  return False
368  return True
369 
371 
372  NAME="Empty"
373 
374  def checkValidity(self):
375  if self.value is list() or self.value is tuple() or self.value is str():
376  return True
377  return False
378 
380 
381  MISSION_ARGS=[]
382 
383  def __init__(self, newargs):
384  self.origargs = newargs
385  self.args = self.MISSION_ARGS
386  givenargs = False
387  try:
388  givenargs = not len(newargs) == 0
389  except:
390  pass
391  if len(newargs) > len(self.args):
392  raise RuntimeError("More arguments given than this object supports")
393  if givenargs:
394  for i in range(len(newargs)):
395  self.args[i].set(newargs[i])
396 
397  def isValid(self):
398  for a in self.args:
399  if not a.isValid():
400  print self.origargs
401  return False
402  return True
403 
404  def warn(self, text):
405  print "Mission Warning: " + text
406 
409 
411  MISSION_ARGS=[PositiveInt(),PositiveInt(),PositiveInt(),Boolean(),PositiveInt(),Faction(),SystemTuple(None,Default()),SaveVar(None,Default()),DynFG(None,Default()),ShipType(Empty(),Default()),Boolean(None,Default()),DynFG(None,Default()),ShipType(ShipFactionPair(Empty()),Default()),TextList(None,Default()),Argument(None,Default())]#FIXME: last argument is leader_upgrades=[]
412 
414  MISSION_ARGS=[PositiveInt(),PositiveInt(),PositiveInt(),Boolean(),PositiveInt(),Faction(),SystemTuple(None,Default()),SaveVar(None,Default()),DynFG(None,Default()),ShipType(Empty(),Default()),Boolean(None,Default()),DynFG(None,Default()),ShipType(ShipFactionPair(Empty()),Default()),TextList(None,Default()),Argument(None,Default()),PositiveInt(None,Default()),PositiveInt(None,Default()),PositiveInt(None,Default())]#FIXME: last argument is leader_upgrades=[]
415 
418 
420  MISSION_ARGS=[Faction(),PositiveInt(),PositiveInt(),PositiveInt(),PositiveInt(),Boolean(),PositiveInt(),Argument(),SystemTuple(None,Default()),SaveVar(None,Default())]#FIXME: Argument is cargo 'category'
421 
424 
427 
432 
434  MISSION_ARGS=[SaveVar(),SystemTuple(None,Default()),Destination(None,Default())]
435 
438 
441 
444 
447 
450 
453 
455  MISSION_ARGS=[PositiveInt(), Faction(), Argument(), PositiveNumber(), Argument(), SaveVar()]#FIXME: first Argument is cargo 'category', second is not used
456 
459 
462