Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
escort_local.py
Go to the documentation of this file.
1 from go_to_adjacent_systems import *
2 from go_somewhere_significant import *
3 import vsrandom
4 import launch
5 import faction_ships
6 import VS
7 import Briefing
8 import universe
9 import unit
10 import Director
11 import quest
12 class escort_local (Director.Mission):
13  def __init__ (self,factionname,numsystemsaway, enemyquantity, waves, distance_from_base, creds, incoming, protectivefactionname='',jumps=(),var_to_set='',dynamic_flightgroup='',dynamic_type='', dynamic_defend_fg='',dynamic_defend_type='',greetingText=['Escort: give up while you still can...','If you let us ravage our target then we grant you passage today.']):
14  Director.Mission.__init__(self)
15  self.greetingText=greetingText
17  if (VS.GetRelation(factionname,protectivefactionname)>=0.0):
18  self.dedicatedattack=1
19  self.arrived=0
20  self.todock=VS.Unit()
22  self.protectivefaction = protectivefactionname
23  self.var_to_set=var_to_set
24  self.quantity=0
25  self.mplay="all"
26  self.gametime=VS.GetGameTime()
27  self.waves=waves
28  self.incoming=incoming
29  self.dynatkfg = dynamic_flightgroup
30  self.dynatktype = dynamic_type
31  self.dyndeffg = dynamic_defend_fg
32  self.dyndeftype = dynamic_defend_type
33  self.attackers = []
34  self.objective= 0
35  self.targetiter = 0
37  self.faction = factionname
38  self.jp=VS.Unit()
39  self.cred=creds
40  self.quantity=enemyquantity
41  self.savedquantity=enemyquantity
42  self.distance_from_base=distance_from_base
43  self.defendee=VS.Unit()
44  self.difficulty=1
45  self.you=VS.getPlayer()
46  self.respawn=0
47  name = self.you.getName ()
48  self.successdelay=0
51  self.adjsys = go_to_adjacent_systems(self.you,numsystemsaway,jumps)
52  VS.IOmessage (0,"escort mission",self.mplay,"Your mission is as follows:")
53  self.adjsys.Print("You are in the %s system,","Proceed swiftly to %s.","Your arrival point is %s.","escort mission",1)
54 
55  def SetVarValue (self,value):
56  if (self.var_to_set!=''):
57  quest.removeQuest (self.you.isPlayerStarship(),self.var_to_set,value)
58  def SuccessMission (self):
59  self.defendee.setFgDirective('b')
60  self.defendee.setFlightgroupLeader(self.defendee)
61  if (self.incoming):
62  import unit
64  if (un.getName()==self.defendee.getName()):
66  if (un.getName()==self.defendee.getName()):
68  if (un.getName()==self.defendee.getName()):
70  if (un.getName()==self.defendee.getName()):
72  if (un.getName()!=self.defendee.getName()):
73  self.defendee.performDockingOperations(un,0)
74  #print "docking with "+un.getName()
75  self.todock=un
76  VS.setObjective (self.objectivezero,"Escort To %s" % unit.getUnitFullName(un))
77  else:
78  self.defendee.ActivateJumpDrive(0)
79  self.defendee.SetTarget(self.adjsys.SignificantUnit())
80  self.successdelay=VS.GetGameTime()+1
81 
82  def PayMission(self):
83  VS.AdjustRelation(self.you.getFactionName(),self.faction,.03,1)
84  self.SetVarValue(1)
85  if (self.cred>0):
86  self.you.addCredits (self.cred)
87  VS.IOmessage(0,"escort mission",self.mplay,"Excellent work pilot! Your effort has thwarted the foe!")
88  VS.IOmessage(0,"escort mission",self.mplay,"You have been rewarded for your effort as agreed.")
89  VS.terminateMission(1)
90  def FailMission (self):
91  self.you.addCredits (-self.cred)
92  VS.AdjustRelation(self.you.getFactionName(),self.faction,-.02,1)
93  self.SetVarValue(-1)
94  VS.IOmessage (0,"escort mission",self.mplay,"You Allowed the base you were to protect to be destroyed.")
95  VS.IOmessage (0,"escort mission",self.mplay,"You are a failure to your race!")
96  VS.IOmessage (1,"escort mission",self.mplay,"We have contacted your bank and informed them of your failure to deliver on credit. They have removed a number of your credits for this inconvenience. Let this serve as a lesson.")
97  VS.terminateMission(0)
98  def NoEnemiesInArea (self,jp):
99  if (self.adjsys.DestinationSystem()!=VS.getSystemFile()):
100  return 0
101  if (self.ship_check_count>=len(self.attackers)):
102  VS.setCompleteness(self.objective,1.0)
103  return 1
104  un= self.attackers[self.ship_check_count]
105  self.ship_check_count+=1
106  if (un.isNull() or (un.GetHullPercent()<.7 and self.defendee.getDistance(un)>7000)):
107  return 0
108  else:
109  VS.setObjective(self.objective,"Destroy the %s"%unit.getUnitFullName(un))
110  self.ship_check_count=0
111  return 0
112 
113  def GenerateEnemies (self,jp,you):
114  count=0
115  self.objectivezero=VS.addObjective ("Protect %s from %s" % (unit.getUnitFullName(jp),self.faction))
116  self.objective = VS.addObjective ("Destroy All %s Hostiles" % self.faction)
117  VS.setCompleteness(self.objective,0.0)
118  print "quantity "+str(self.quantity)
119  while (count<self.quantity):
120  L = launch.Launch()
121  L.fg="Shadow";L.dynfg=self.dynatkfg;
122  if (self.dynatktype==''):
124  else:
125  L.type=self.dynatktype
126  L.ai="default";L.num=1;L.minradius=20000.0;L.maxradius=25000.0
127  try:
128  L.minradius*=faction_ships.launch_distance_factor
129  L.maxradius*=faction_ships.launch_distance_factor
130  except:
131  pass
132  L.faction=self.faction
133  launched=L.launch(you)
134  if (count==0):
135  self.you.SetTarget(launched)
136 
137  if (1):
138  launched.SetTarget (jp)
139  else:
140  launched.SetTarget (you)
141  if (self.dedicatedattack):
142  launched.setFgDirective('B')
143  self.attackers += [ launched ]
144  count+=1
145  if (self.respawn==0 and len(self.attackers)>0):
146  self.respawn=1
147  import universe
148  universe.greet(self.greetingText,self.attackers[0],you);
149  else:
150  VS.IOmessage (0,"escort mission",self.mplay,"Eliminate all %s ships here" % self.faction)
151  VS.IOmessage (0,"escort mission",self.mplay,"You must protect %s." % unit.getUnitFullName(jp))
152 
153  self.quantity=0
154  def GenerateDefendee(self):
155  L=launch.Launch()
156  L.fg ="Escort"
157  L.faction=self.protectivefaction
158  if (self.dyndeffg=='' and self.dyndeftype==''):
160  else:
161  L.type = self.dyndeftype
162  L.dynfg = self.dyndeffg
163  import escort_mission
164  escort_mission.escort_num+=1
165  L.fgappend = str(escort_mission.escort_num)
166  L.ai = "default"
167  L.num=1
168  L.minradius = 2.0*self.you.rSize()
169  L.maxradius = 3.0*self.you.rSize()
170  L.forcetype=True
171  escortee=L.launch(self.you)
172  escortee.upgrade("jump_drive",0,0,0,1)
173  escortee.setFlightgroupLeader(self.you)
174  escortee.setFgDirective('F')
175  escortee.setMissionRelevant()
176  return escortee
177 
178  def Execute (self):
179  if (self.successdelay):
180  if (self.defendee.getUnitSystemFile()!=self.you.getUnitSystemFile() or VS.GetGameTime()-self.successdelay>120 or (self.incoming and self.todock.isNull()==False and self.you.isNull()==False and self.you.getDistance(self.todock)<330)):
181  if (self.defendee):
182  self.PayMission()
183  else:
184  self.FailMission()
185  return #nothing more happens inside this control
186  if (self.you.isNull() or (self.launchedfriend and self.defendee.isNull())):
187  VS.IOmessage (0,"escort mission",self.mplay,"#ff0000You were unable to arrive in time to help. Mission failed.")
188  self.SetVarValue(-1)
189  VS.terminateMission(0)
190  return
191  if (not self.adjsys.Execute()):
192  return
193  if (not self.arrived):
194  self.arrived=1
195  if (self.launchedfriend==0 and not self.incoming):
196  self.defendee=self.GenerateDefendee()
197  self.launchedfriend=1
198  self.adjsys=go_somewhere_significant (self.you,0,self.distance_from_base,0)
199  self.adjsys.Print ("You must visit the %s","escort mission","docked around the %s", 0)
200  self.jp=self.adjsys.SignificantUnit()
201  else:
202  if (self.launchedfriend==0):
203  self.defendee=self.GenerateDefendee()
204  self.launchedfriend=1
205  if (self.defendee.isNull ()):
206  self.FailMission(you)
207  return
208  else:
209  self.defendee.setFlightgroupLeader(self.you)
210  if (VS.GetGameTime()-self.gametime>10):
211  self.defendee.setFgDirective('F')
212  if (self.quantity>0):
213  self.GenerateEnemies (self.defendee,self.you)
214  if (self.ship_check_count==0 and self.dedicatedattack):
215  if (self.targetiter>=len(self.attackers)):
216  self.targetiter=0
217  else:
218  un = self.attackers[self.targetiter]
219  if (not un.isNull()):
220  un.SetTarget (self.defendee)
221  self.targetiter=self.targetiter+1
222  if (self.NoEnemiesInArea (self.defendee)):
223  if (self.waves>0):
224  self.quantity=self.savedquantity
225  self.waves-=1
226  else:
227  self.SuccessMission()
228  def initbriefing(self):
229  print "ending briefing"
230  def loopbriefing(self):
231  print "loop briefing"
232  Briefing.terminate();
233  def endbriefing(self):
234  print "ending briefing"
235