Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
car_lib.py
Go to the documentation of this file.
1 import VS
2 import Director
3 def isCar(c):
4  nam = c.getName()
5  return nam=='car' or nam=='porsche'
6 
7 class Environment(Director.Mission):
8  def CreateUnit (self, name):
9  evenodd= (2*(self.num_un %2) - 1)
10  x_coord = -evenodd * 30
11  un = VS.launch ("traffic",name,"neutral", "unit","modules/traffic.py",1,1,(x_coord,0,self.num_un*100),'')
12  un.SetOrientation ((0,1,0),(0,0,evenodd))
13  self.num_un+=1
14  def __init__ (self,numcar, numspec):
15  Director.Mission.__init__(self)
16  print 'initing'
17  self.iter=0
18  self.num_un=0
19  for i in range(numcar):
20  self.CreateUnit ("porsche")
21  for i in range(numspec):
22  self.CreateUnit ("car")
23  def Execute(self):
24  un = VS.getUnit (self.iter)
25  if (un):
26  if (isCar(un)):
27  self.ApplyEventualEnvironment (un,VS.getPlayer())
28  self.iter+=1
29  else:
30  self.iter=0
31  def AlwaysExecute(self):
32  self.EventualExecute()
33  iter = VS.getUnitList ()
34  un = iter.current()
35  playa = VS.getPlayer()
36  while (un):
37  if (isCar(un)):
38  self.ApplyPerFrameEnvironment (un,playa)
39  iter.advance()
40  un = iter.current()
41  def ApplyEventualEnvironment(self,un,playa):
42  if (playa):
43  if (playa!=un):
44  posdiff = playa.Position()[2]-un.Position()[2]
45  if ((posdiff*(2*(posdiff>0)-1))>1500):
46  R = un.GetOrientation ()[2]
47 
48  if (posdiff*R[2]<0):
49  pos=(un.Position()[0],0,playa.Position()[2]+4000*(2*(R[2]<0)-1),)
50  un.SetCurPosition (pos)
51  print "repositioning"
52 # def ApplyPerFrameEnvironment (self,un,playa):
53  pos = un.Position()
54  vel = un.GetVelocity()
55  if (pos[1]!=0):
56  pos=(pos[0],0,pos[2])
57  un.SetCurPosition(pos)
58  if (vel[1]!=0):
59  vel = (vel[0],0,vel[2])
60  un.SetVelocity(vel)
61  if (vel[0]!=0):
62  vel = (0,vel[1],vel[2])
63  un.SetVelocity(vel)