Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
All Data Structures Namespaces Files Functions Variables
ai_escortpatrol Class Reference
Inheritance diagram for ai_escortpatrol:

Public Member Functions

def init
 
def Execute
 

Data Fields

 timer
 
 target
 
 thrustfactor
 

Detailed Description

Definition at line 22 of file ai_escortpatrol.py.

Member Function Documentation

def Execute (   self)

Definition at line 35 of file ai_escortpatrol.py.

References Vector.Cross(), unit.facingAngleToUnit(), unit.getSignedVelocity(), sre_parse.max, Vector.SafeNorm(), Vector.Sub(), ai_escortpatrol.target, ai_escortpatrol.thrustfactor, ai_escortpatrol.timer, and vsrandom.uniform().

35 
36  def Execute(self):
37  import unit
38  import Vector
39  import vsrandom
40  VS.PythonAI.Execute(self);
41  distance = abs(self.GetParent().getDistance(self.target))
42 
43  # evade the target and almost parallel flyby
44  if (distance<=2000 and VS.GetGameTime()>self.timer):
45  angle = unit.facingAngleToUnit(self.GetParent(),self.target)
46  velocity = unit.getSignedVelocity(self.GetParent())
47  if (angle<0.30):
48  angular = 0.80-angle
49  change = (vsrandom.uniform(-angular,angular),
50  vsrandom.uniform(angular,angular),
51  vsrandom.uniform(-angular,angular))
52  self.GetParent().SetAngularVelocity(change)
53  if (velocity<100):
54  self.GetParent().LongitudinalThrust(100)
55  self.timer = VS.GetGameTime()+1
56 
57  # patrol in random direction
58  if (distance>2000 and distance<7000 and VS.GetGameTime()>self.timer):
59  angular = vsrandom.uniform(0.01,0.10)
60  change = (vsrandom.uniform(-angular,angular),
61  vsrandom.uniform(angular,angular),
62  vsrandom.uniform(-angular,angular))
63  self.GetParent().SetAngularVelocity(change)
64  velocity = unit.getSignedVelocity(self.GetParent())
65  if (velocity<100):
66  self.GetParent().LongitudinalThrust(200)
67  self.timer = VS.GetGameTime()+2
68 
69  # return to target proximity
70  if (distance>=7000 and VS.GetGameTime()>self.timer):
71  # calculates the angular velocity required to turn back on target
72  vec = Vector.Sub(self.GetParent().Position(),self.target.Position())
73  change = Vector.Cross(Vector.SafeNorm(self.GetParent().GetOrientation()[2]),Vector.SafeNorm(vec))
74  self.GetParent().SetAngularVelocity(change)
75  # calculate the required thrust depending on mass and
76  # signed velocity magnitude as result of momentum
77  velocity = unit.getSignedVelocity(self.GetParent())
78  if (velocity<100):
79  if (velocity<0):
80  # thrust more while not flying forward
81  thrust = self.thrustfactor * max(abs(velocity),300)
82  else:
83  thrust = self.thrustfactor * 300
84  self.GetParent().LongitudinalThrust(thrust)
85  self.timer = VS.GetGameTime()+1
86  return 1
def init (   self,
  un 
)

Definition at line 24 of file ai_escortpatrol.py.

24 
25  def init(self,un):
26  self.timer = VS.GetGameTime()
27  self.target = self.GetParent().GetTarget()
28  self.GetParent().setSpeed(100)
29  # calculate required thrust factor as an approximate relation of mass to reference mass
30  # found empirically, since thrust values are not read from the model
31  self.thrustfactor = self.GetParent().GetMass()/50

Field Documentation

target

Definition at line 26 of file ai_escortpatrol.py.

thrustfactor

Definition at line 30 of file ai_escortpatrol.py.

timer

Definition at line 25 of file ai_escortpatrol.py.


The documentation for this class was generated from the following file: