Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
launch.py
Go to the documentation of this file.
1 from difficulty import usingDifficulty
2 import vsrandom
3 import unit
4 import ship_upgrades
5 import VS
6 import sys
7 import dj_lib
8 import debug
9 
10 def launch (fgname, faction, type,ai, nr_ships, nr_waves, vec, logo='',useani=1,skipdj=0):
11 # print 'log'+ str( logo) + ' useani '+ str(useani)
12  diff=usingDifficulty()
13 # if useani:
14 # VS.playAnimation ("warp.ani",vec,300.0)
15  if (not diff or (type.find(".blank")==-1 and -1==type.find(".stock"))):
16  for i in range(nr_ships):
17  ret = VS.launch (fgname,type,faction,"unit",ai,1,nr_waves,VS.SafeEntrancePoint (vec,40),logo)
19  if (not skipdj):
20  dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
21  return ret
22  rsize=0.0
23  diffic = VS.GetDifficulty()
24  ret=VS.Unit()
25  for i in range(nr_ships):
26  mynew=VS.launch(fgname,type,faction,"unit",ai,1,nr_waves,VS.SafeEntrancePoint (vec,40),logo)
28  if (i==0):
29  ret = mynew
30  rsize =mynew.rSize ()*1.75
31  ship_upgrades.upgradeUnit ( mynew,diffic)
32  vec=(vec[0]-rsize,
33  vec[1],#-rsize
34  vec[2]-rsize)
35  if (not skipdj):
36  dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
37  return ret
38 
39 def launch_waves_around_area(fgname,faction,type,ai,nr_ships,nr_waves,r1,r2,pos,logo='',useani=1,skipdj=0):
40  pos=((pos[0]+vsrandom.uniform(r1,r2)*vsrandom.randrange(-1,2,2)),
41  (pos[1]+vsrandom.uniform(r1,r2)*vsrandom.randrange(-1,2,2)),
42  (pos[2]+vsrandom.uniform(r1,r2)*vsrandom.randrange(-1,2,2)))
43  return launch(fgname,faction,type,ai,nr_ships,nr_waves,pos,logo,useani,skipdj)
44 
45 def launch_wave_around_area(fgname,faction,type,ai,nr_ships,r1,r2,pos,logo='',useani=1,skipdj=0):
46 # print 'log' + str(logo)
47  return launch_waves_around_area (fgname,faction,type,ai,nr_ships,1,r1,r2,pos,logo,useani,skipdj)
48 
49 def launch_around_station(station_name,fgname,faction,type,ai,nr_ships,nr_waves,logo='',useani=1,skipdj=0):
50  station_unit = unit.getUnitByFgID(station_name)
51  if(station_unit.isNull()):
52  sys.stderr.write("launch.py:launch_around_station did not find unit %s\n" % (station_name))
53  return VS.Unit()
54  station_pos = station_unit.Position()
55  rsize = station_unit.rSize()
56  launched = launch_waves_around_area(fgname,faction,type,ai,nr_ships,nr_waves,rsize,rsize*2.0,station_pos,logo,useani,skipdj)
57  return launched
58 
59 launch_around_unit=launch_around_station
60 
61 def launch_waves_in_area(fgname,faction,type,ai,nr_ships,nr_waves,radius,pos,logo='',useani=1,skipdj=0):
62  pos=(pos[0]+vsrandom.uniform((-radius)/2,radius/2.0),
63  pos[1]+vsrandom.uniform((-radius)/2,radius/2.0),
64  pos[2]+vsrandom.uniform((-radius)/2,radius/2.0))
65  un = launch(fgname,faction,type,ai,nr_ships,nr_waves,pos,logo,useani,skipdj)
66 
67 def launch_wave_in_area(fgname,faction,type,ai,nr_ships,radius,pos,logo='',useani=1,skipdj=0):
68  launch_waves_in_area(fgname,faction,type,ai,nr_ships,1,radius,pos,logo,useani,skipdj)
69 
70 def launchShipsAtWaypoints(waypoints,faction,type,ainame,nr,logo='',useani=1,skipdj=0):
71  i=0
72  c=length(waypoints)-1
73  for wp in waypoints:
74  outstr="wp%d" % (i)
75  launch(outstr,faction,type,ainame,nr,1,wp,logo,useani,(skipdj or (i==c)))
76  i+=1
77 
78 def launch_wave_around_unit (fgname, faction, type, ai, nr_ships, minradius, maxradius, my_unit,logo='',useani=1,skipdj=0):
79  import faction_ships
80  myvec = (0,0,0)
81  if (my_unit.isNull()):
82  un=launch_wave_around_area (fgname,faction,type,ai,nr_ships,minradius,maxradius,myvec,logo,useani,skipdj)
83  return un
84  myvec=my_unit.LocalPosition()
85  debug.debug('(launching at '+str(myvec)+')')
86  rsiz=my_unit.rSize()
87  if (maxradius > faction_ships.max_radius):
88  maxradius=faction_ships.max_radius
89  if (minradius > faction_ships.max_radius):
90  minradius=faction_ships.max_radius
91  un=launch_wave_around_area (fgname,faction,type,ai,nr_ships,rsiz+minradius,rsiz+maxradius,myvec,logo,useani,skipdj)
92  return un
93 
94 def launch_wave_around_significant (fgname,faction,type,ai,nr_ships,minradius, maxradius,significant_number,logo='',useani=1,skipdj=0):
95  significant_unit=unit.getSignificant(significant_number,0,0)
96  if (significant_unit.isNull()):
97  significant_unit = VS.getPlayer()
98  launched = launch_wave_around_unit(fgname,faction,type,ai,nr_ships,minradius,maxradius,significant_unit,logo,useani,skipdj)
99  return launched
100 
101 class Launch:
102  def __init__ (self):
103  self.fg='Shadow'
104  self.dynfg=''
105  self.type='nova'
106  self.num=1
107  self.minradius=100.0
108  self.maxradius=200.0
109  self.useani=1
110  self.logo=''
111  self.faction='neutral'
112  self.ai='default'
113  self.numwaves=1
114  self._preprocess=0
115  self._nr_ships=0
116  self.pos=(0,0,0)
117  self.fgappend=''
118  self.forcetype=False;
119  self.capitalp=0
120  def Preprocess (self):
121  self._preprocess=1
122  self._dyn_nr_ships=[]
123  self._nr_ships=self.num
124  import faction_ships
125  if self.dynfg!='':
126  import fg_util
127  tn=fg_util.ShipsInFG(self.dynfg,self.faction)
128  debug.debug('dynamic launching from '+str(tn)+' from flightgroup '+self.dynfg + ' faction '+ self.faction)
129  knum=0
130  if (tn!=[] and self.type!=''):
131  for i in range (len(tn)):
132  if (tn[i][0]==self.type):
133  knum=tn[i][1]
134  if (knum>self.num):
135  knum=self.num
136  self._dyn_nr_ships=[(self.type,knum)]
137  del tn[i]
138  break
139 ## if (tn==[]):
140 ## print 'Dyn-Launch: tn==[]'
141 ## self.dynfg=''
142 
143  elif (tn==[]):
144  debug.error("Dyn-Launch: tn==[], dynfg==\'\' Error 47")
146  self.fg = self.dynfg
147  self.dynfg=''
148  if self.forcetype and len(self._dyn_nr_ships)==0 and self.type!='':
149  self._dyn_nr_ships=[(self.type,1)]
150  knum=1
151  for i in tn:
152  if (knum>=self.num):
153  break
154  if (self.capitalp or (not faction_ships.isCapital(i[0])) ):
155  if (i[1]>self.num-knum):
156  i = (i[0],self.num-knum)
157  self._dyn_nr_ships+=[i]
158  knum+=i[1]
159  self._nr_ships=self.num-knum
160  def launch(self,myunit,skipdj=0):
161  self.Preprocess()
162  if (self.dynfg!=''):
163  debug.debug('dynamic launch')
164  if (self._nr_ships>0):
165  if (not myunit):
166  debug.debug('launch area')
167  lame= launch_wave_around_area (self.dynfg+self.fgappend,self.faction,self.type,self.ai,self._nr_ships, self.minradius,self.maxradius,self.pos,self.logo,self.useani,skipdj)
168  else:
169  debug.debug('launch more ships')
170  lame= launch_wave_around_unit (self.dynfg+self.fgappend,self.faction,self.type,self.ai,self._nr_ships,self.minradius,self.maxradius,myunit,self.logo,self.useani,skipdj)
171  import launch_recycle
172  ret= launch_recycle.launch_types_around (self.dynfg,self.faction,self._dyn_nr_ships,self.ai,self.minradius*.5+self.maxradius*.5,myunit,100000+self.maxradius,self.logo,self.fgappend,skipdj)
173  if (len(self._dyn_nr_ships) or self._nr_ships==0):
174  return ret
175  else:
176  return lame
177  else:
178  if ((not myunit) and self._nr_ships>0):
179  debug.debug('launch area')
180  return launch_wave_around_area (self.fg+self.fgappend,self.faction,self.type,self.ai,self._nr_ships, self.minradius,self.maxradius,self.pos,self.logo,self.useani,skipdj)
181  elif (self._nr_ships>0):
182  debug.debug('launch more ships')
183  return launch_wave_around_unit (self.fg+self.fgappend,self.faction,self.type,self.ai,self._nr_ships,self.minradius,self.maxradius,myunit,self.logo,self.useani,skipdj)
184  else:
185  debug.debug(' error viz ze luch')
186  return launch_wave_around_unit (self.fg+self.fgappend,self.faction,self.type,self.ai,1,self.minradius,self.maxradius,myunit,self.logo,self.useani,skipdj)
187  return un