Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
ambush.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import VS
3 import Director
4 import directions_mission
5 import launch
6 import faction_ships
7 import universe
8 
10  def privateSetupPlayer(self):
11  self.timer=0
12  self.inescapable=0
13  self.havelaunched=0
14  self.terminated=0
15 
16  def __init__(self,savevar,systems,delay,faction,numenemies,dyntype='',dynfg='',greetingText=["Hello there, smuggler. Prepare to die!", "The price on your head is big enough that I missed my lunch"], directions=[], destination='',AdjustFaction=True):
17  directions_mission.directions_mission.__init__ (self,savevar,directions,destination)
18  print 'Ambush: Starting'
19  self.faction=faction
20  self.systems=systems
21  if type(systems)!=tuple and type(systems)!=list :
22  self.systems=(systems,)
23  self.numenemies=numenemies
24  self.dyntype=dyntype
25  self.dynfg=dynfg
26  self.greetingText=greetingText
27  self.cp=VS.getCurrentPlayer()
28  self.delay=delay
29  self.privateSetupPlayer()
30  self.AdjustFaction=AdjustFaction
31  def setupPlayer(self,cp):
32  print "ambush setting player up"
34  self.privateSetupPlayer()
35 
36  def Launch(self,you):
37  if (self.havelaunched==0):
38  if (type(self.numenemies)==type(1)):
39  self.numenemies=(self.numenemies,)
40  self.faction=(self.faction,)
41  self.dyntype=(self.dyntype,)
42  self.dynfg=(self.dynfg,)
43  if (type(self.AdjustFaction)!=type( () ) and type (self.AdjustFaction)!=type([])):
44  self.AdjustFaction=(self.AdjustFaction,)
45  for i in xrange(len(self.faction)):
46  numenemies=self.numenemies[i]
47  faction=self.faction[i]
48  for z in xrange(numenemies):
49  AdjustFaction=self.AdjustFaction[-1]
50  if (i<len(self.AdjustFaction)):
51  AdjustFaction=self.AdjustFaction[i]
52  dynfg=""
53  if (len(self.dynfg)>i):
54  dynfg=self.dynfg[i]
55  dyntype=""
56  if (len(self.dyntype)>i):
57  dyntype=self.dyntype[i]
58  print 'Ambush: Launch ships!'
59  self.havelaunched=1
60  L=launch.Launch()
61  L.fg="Shadow"
62  if (dyntype==""):
63  dyntype=faction_ships.getRandomFighter(faction)
64  L.dynfg=dynfg
65  L.type=dyntype
66  L.num=1
67  L.fgappend="X"
68  L.minradius=6000
69  L.maxradius=8000
70  try:
71  L.minradius*=faction_ships.launch_distance_factor
72  L.maxradius*=faction_ships.launch_distance_factor
73  except:
74  pass
75  L.faction=faction
76  enemy=L.launch(you)
77  lead=enemy.getFlightgroupLeader()
78  enemy.SetTarget(you)
79  if (lead):
80  lead.SetTarget(you)
81  else:
82  enemy.setFlightgroupLeader(enemy)
83  enemy.setFgDirective("A.")
84  self.enemy=lead
85  rel=VS.GetRelation(faction,"privateer")
86  if (AdjustFaction and rel>=0):
87  VS.AdjustRelation(faction,"privateer",-.02-rel,1.0)
88  rel=VS.GetRelation("privateer",faction)
89  VS.AdjustRelation("privateer",faction,-.02-rel,1.0)
90  if (i==len(self.faction)-1 and z==0):
91  universe.greet(self.greetingText,enemy,you)
92  #print "launchin"
93  print 'Ambush: Ships have been launched. Exiting...'
94  def terminate(self):
95  self.terminated=1#VS.terminateMission(0)
96  def Execute(self):
98  if (self.terminated==1):
99  return
100  you=VS.getPlayerX(self.cp)
101  if you.isNull():
102  return
103  sys=you.getUnitSystemFile()
104  if(not self.inescapable):
105  for i in self.systems:
106  where=sys.find(i)
107  if (where>0):
108  if (sys[where-1]=='/'):
109  where=0
110  if (where==0):
111  #print 'Ambush: wait before launching ship...'
112  self.inescapable=1
113  self.timer=VS.GetGameTime()
114  if (self.inescapable and ((self.delay==0) or (VS.GetGameTime()-self.timer>=self.delay))):
115  self.Launch(you)
116  self.terminate()
117 # print "it's unavoidable, my young apprentice... in "+str(self.delay)+" seconds from "+str(self.timer)
118