Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
launch_recycle.py
Go to the documentation of this file.
1 import vsrandom
2 import unit
3 import launch
4 import VS
5 import faction_ships
6 import dj_lib
7 import debug
8 
9 def NextPos (un, pos, FarApart=1):
10  rad=un.rSize ()
11  whichcoord = vsrandom.randrange(0,3)
12  x = pos[whichcoord]
13  pos = list(pos)
14  x=x+3.0*rad*FarApart
15  debug.debug("next coord is "+str(3.0*rad*FarApart)+" awa")
16  pos[whichcoord]=x
17  return tuple(pos)
18 
19 def move_to (un, where):
20  un.SetPosition(where)
22  un.SetTarget (VS.Unit())
23  return NextPos (un,where)
24 
25 def whereTo (radius, launch_around):
26  if (type(launch_around)==type( (1,2,3))):
27  pos=launch_around
28  rsize = faction_ships.max_radius
29  else:
30  pos = launch_around.Position ()
31  rsize = ((launch_around.rSize())*5.0)
32  if (rsize > faction_ships.max_radius):
33  rsize=faction_ships.max_radius
34  rsize+=radius;
35  import fg_util
36  dir = fg_util.randDirection()
37  return (pos[0]+rsize*dir[0],
38  pos[1]+rsize*dir[1],
39  pos[2]+rsize*dir[2])
40 
41 def unOrTupleDistance(un,unortuple,significantp):
42  if (type(unortuple)==type((1,2,3))):
43  import Vector
44  return Vector.Mag(Vector.Sub(un.Position(),unortuple))-un.rSize()
45  else:
46  if (significantp):
47  return un.getSignificantDistance(unortuple)
48  else:
49  return un.getDistance(unortuple)
50 # THIS FUNCTION NO LONGER WORKS...because it's kinda silly to drag units around the system forcing them in front of a player
51 def look_for (fg, faction, numships,myunit, pos, gcd,newship=[None]):
52  return (numships,pos)
54  for un in unl:
55  if (numships<=0):
56  break
57  if (unOrTupleDistance(un,myunit,1)>gcd ):
58  fac = un.getFactionName ()
59  fgname = un.getFlightgroupName ()
60  name = un.getName ()
61  if ((fg==fgname) and (fac==faction)):
62  if (vsrandom.random()<0.75):
63  pos=move_to (un,pos)
64  numships-=1
65  newship[0]=un
66  debug.debug("TTYmoving %s to current area" % (name))
67  return (numships,pos)
68 
69 def LaunchNext (fg, fac, type, ai, pos, logo,newshp=[None],fgappend='',FarApart=1):
70  debug.debug("Launch nexting "+str(type))
71  combofg=fg+fgappend
72  if (fgappend=='Base'):
73  combofg=fgappend
74  newship = launch.launch (combofg,fac,type,ai,1,1,pos,logo,1,1)
75  import dynamic_universe
76  dynamic_universe.TrackLaunchedShip(fg,fac,type,newship)
77  rad=newship.rSize ()
78 #VS.playAnimation ("warp.ani",pos,(3.0*rad))
79  newshp[0]=newship
80  return NextPos (newship,pos,FarApart)
81 
82 def launch_dockable_around_unit (fg,faction,ai,radius,myunit,garbage_collection_distance,logo='',fgappend='',skipdj=0):
83  import fg_util
84  for i in fg_util.LandedShipsInFG(fg,faction):
85  if (i[0]=='Mule.stock' or i[0]=='Mule' or faction_ships.isCapital(i[0])):
86  un=launch_types_around (fg,faction,[i],ai,radius,myunit,garbage_collection_distance,logo,fgappend,skipdj)
87  if (un.isDockableUnit()):
88  return un
89  if (fgappend=='Base'):
90  fg=fgappend
91  else:
92  fg=fg+fgappend
93  return launch.launch_wave_around_unit(fg,faction,faction_ships.getRandomCapitol(faction),ai,1,radius,radius*1.5,myunit,logo,1,skipdj)
94 
95 def launch_types_around ( fg, faction, typenumbers, ai, radius, myunit, garbage_collection_distance,logo,fgappend='',skipdj=0,FarApart=1):
96  pos = whereTo(radius, myunit)
97  nr_ships=0
98  for t in typenumbers:
99  nr_ships+=t[1]
100  debug.debug("before"+str(nr_ships))
101  retcontainer=[None]
102  if (fgappend=='' and nr_ships>1):
103  (nr_ships,pos) = look_for (fg,faction,nr_ships-1,myunit,pos,garbage_collection_distance,retcontainer)
104  nr_ships+=1
105  debug.debug("after "+str(nr_ships)+ str(retcontainer))
106  count=0
107  ret=retcontainer[0]
108  found=0
109  for tn in typenumbers:
110  num = tn[1]
111  debug.debug("Python launched "+str(faction)+" "+str(tn[0])+" FG "+str(fg)+" with "+str(num)+" ships")
112  if num>nr_ships:
113  num=nr_ships
114  for i in range(num):
115  newship=[None]
116  debug.debug(pos)
117  pos = LaunchNext (fg,faction,tn[0], ai, pos,logo,newship,fgappend,FarApart)
118  if (i==0 and found==0):
119  ret=newship[0]
120  found=1
121  nr_ships-=num
122  if (nr_ships==0):
123  if (not skipdj):
124  dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
125  return ret
126  if (not skipdj):
127  dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
128  return ret
129 
130 
131 def launch_wave_around ( fg, faction, ai, nr_ships, capship, radius, myunit, garbage_collection_distance,logo,skipdj=0):
132  pos = whereTo(radius, myunit)
133  debug.debug("before"+str(nr_ships))
134  (nr_ships,pos) = look_for (fg,faction,nr_ships,myunit,pos,garbage_collection_distance)
135  debug.debug("after "+str(nr_ships))
136  while (nr_ships>0):
137  type=""
138  if (capship):
139  type = faction_ships.getRandomCapitol(faction)
140  else:
141  type = faction_ships.getRandomFighter(faction)
142  pos = LaunchNext (fg,faction,type, ai, pos,logo)
143  nr_ships-=1
144  if (not skipdj):
145  dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
146