Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
patrol.py
Go to the documentation of this file.
1 from go_to_adjacent_systems import *
2 import vsrandom
3 import launch
4 import faction_ships
5 import VS
6 import Briefing
7 import universe
8 import unit
9 import quest
10 import Director
11 class patrol (Director.Mission):
12  def __init__ (self,numsystemsaway, num_significants_to_patrol, distance_from_base, creds, jumps=(), donevar=''):
13  Director.Mission.__init__(self)
14  self.donevar=donevar
15  self.jnum=0
16  self.cred=creds
17  self.patrolpoints = []
18  self.objectives = []
19  self.distance = distance_from_base
20  self.you = VS.getPlayer()
21  self.quantity=num_significants_to_patrol
22  name = self.you.getName ()
24  VS.IOmessage (0,"patrol",self.mplay,"You must patrol a system for us :")
25  self.adjsys = go_to_adjacent_systems(self.you,numsystemsaway,jumps)
26  self.adjsys.Print("From the %s system,","Carefully go to %s.","You should shortly arrive in the %s: patrol it.","patrol",1)
27 
28  def SuccessMission (self):
29  self.you.addCredits (self.cred)
30  if self.donevar!='':
31  quest.removeQuest(self.you.isPlayerStarship(),self.donevar,1)
32  VS.IOmessage (0,"computer",self.mplay,"[Computer] Transmitting Data..")
33  VS.IOmessage (0,"patrol",self.mplay,"Thank you! Patrol Complete.")
34  VS.IOmessage (0,"patrol",self.mplay,"We have credited your account.")
35  VS.terminateMission(1)
36  def FailMission (self):
37  self.you.addCredits (self.cred)
38  if self.donevar!='':
39  quest.removeQuest(self.you.isPlayerStarship(),self.donevar,-1)
40  VS.IOmessage (0,"patrol",self.mplay,"Mission a failure!")
41  VS.terminateMission(0)
42 
43  def GeneratePatrolList (self):
44  VS.IOmessage (0,"patrol",self.mplay,"You must get within %f klicks of" % self.distance)
45  count=self.quantity*6
46  str=""
47  import universe
49  while (len(self.patrolpoints)>self.quantity and len(self.patrolpoints)):
50  del self.patrolpoints[vsrandom.randrange(0,len(self.patrolpoints))]
51  for sig in self.patrolpoints:
52  self.quantity=self.quantity-1
53  fac =sig.getFactionName()
54  nam =unit.getUnitFullName(sig)
55  enam =unit.getUnitFullName(sig,True)
56  sig.setMissionRelevant()
57  if (fac!="neutral"):
58  obj=VS.addObjective ("Scan %s"%nam)
59  VS.IOmessage (0,"patrol",self.mplay,"%s owned %s " % (fac,enam))
60  else:
61  if (sig.isPlanet()):
62  nam =unit.getUnitFullName(sig)
63  if (sig.isJumppoint()):
64  obj=VS.addObjective ("Scan Jumppoint %s" % nam)
65  else:
66  obj=VS.addObjective ("Scan %s" % nam)
67  else:
68  obj=VS.addObjective ("Scan Natural Phenomenon: %s" % nam)
69  VS.IOmessage (0,"patrol",self.mplay,"The object %s " % enam)
70  VS.setOwner(int(obj),self.you)
71  VS.setCompleteness(int(obj),0.0)
72  self.objectives+=[int(obj)]
73  self.quantity=0
74 
75  def DeletePatrolPoint (self,num,nam):
76  VS.IOmessage (0,"patrol",self.mplay,"[Computer] %s scanned, data saved..."%nam)
77  VS.setCompleteness(self.objectives[self.jnum],1.0)
78  self.you.commAnimation("scan_complete.ani")
79  del self.objectives[self.jnum]
80  del self.patrolpoints[self.jnum]
81  def FinishedPatrol (self):
82  if (self.jnum<len(self.patrolpoints)):
83  jpoint =self.patrolpoints[self.jnum]
84  if (jpoint.isNull()):
85  self.DeletePatrolPoint(self.jnum,"Debris")
86  else:
87  if (self.you.getSignificantDistance (jpoint)<self.distance):
89  else:
90  self.jnum+=1
91  else:
92  self.jnum=0
93  return (len(self.patrolpoints)==0)
94  def Execute (self):
95  if (self.you.isNull()):
96  VS.terminateMission(0)
97  return
98  if (self.adjsys.Execute()):
99  if (self.quantity>0):
100  self.GeneratePatrolList ()
101  else:
102  if (self.FinishedPatrol()):
103  self.SuccessMission()
104 
105  def initbriefing(self):
106  print "ending briefing"
107  def loopbriefing(self):
108  print "loop briefing"
109  Briefing.terminate();
110  def endbriefing(self):
111  print "ending briefing"
112 def initrandom (minsysaway,maxsysaway,minsigtopatrol,maxsigtopatrol,mincred,maxcred):
113  nsys = vsrandom.randrange (minsysaway, maxsysaway)
114  nsig = vsrandom.randrange (minsigtopatrol, maxsigtopatrol)
115  return patrol (nsys, nsig,vsrandom.randrange(100.0,300.0),(1+nsys*0.5)*nsig*vsrandom.randrange (mincred,maxcred))