Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Orders::MoveToParent Class Reference

#include <navigation.h>

Public Member Functions

void SetAfterburn (bool tf)
 
 MoveToParent (bool aft, unsigned char switchbacks, bool terminating=true)
 
bool Execute (Unit *parent, const QVector &targetlocation)
 

Detailed Description

The moveto order attempts to calculate the best way to apply thrust (within the computer bound limits) to get a starship to place B and stopped. It uses an integral of acceleration and velocity over time to solve for time when to decelerate. Is inaccurate within 1 physics frame, and must use switchbacks and then once they have been met sets terminating X,Y, and Z to figure out how many switchbacks it has made , missing the target and coming back over it.

Definition at line 22 of file navigation.h.

Constructor & Destructor Documentation

Orders::MoveToParent::MoveToParent ( bool  aft,
unsigned char  switchbacks,
bool  terminating = true 
)
inline

Definition at line 38 of file navigation.h.

39  : afterburn(aft)
40  , switchbacks(switchbacks)
41  , terminatingX( 0 )
42  , terminatingY( 0 )
43  , terminatingZ( 0 )
44  , last_velocity( 0, 0, 0 )
45  , selfterminating( terminating ) {}

Member Function Documentation

bool MoveToParent::Execute ( Unit parent,
const QVector targetlocation 
)

Definition at line 128 of file navigation.cpp.

References Unit::Limits::afterburn, Unit::ApplyLocalForce(), CalculateBalancedDecelTime(), CalculateDecelTime(), done, float, Unit::Limits::forward, Unit::GetComputerData(), Unit::GetMass(), Unit::GetVelocity(), Unit::Limits::lateral, Unit::Limits(), Unit::Computer::max_ab_speed(), Unit::Computer::max_speed(), Unit::Position(), Unit::Limits::retro, SIMULATION_ATOM, Orders::THRESHOLD, Unit::ToLocalCoordinates(), Unit::UpCoordinateLevel(), Vector, and Unit::Limits::vertical.

Referenced by Orders::MoveTo::Execute().

129 {
130  bool done = false;
131  Vector local_vel( parent->UpCoordinateLevel( parent->GetVelocity() ) );
132  //local location is ued for storing the last velocity;
133  terminatingX += ( (local_vel.i > 0) != (last_velocity.i > 0) || (!local_vel.i) );
134  terminatingY += ( (local_vel.j > 0) != (last_velocity.j > 0) || (!local_vel.j) );
135  terminatingZ += ( (local_vel.k > 0) != (last_velocity.k > 0) || (!local_vel.k) );
136 
137  last_velocity = local_vel;
138  Vector heading = parent->ToLocalCoordinates( ( targetlocation-parent->Position() ).Cast() );
139  Vector thrust( parent->Limits().lateral, parent->Limits().vertical,
140  afterburn ? parent->Limits().afterburn : parent->Limits().forward );
141  float max_speed =
142  ( afterburn ? parent->GetComputerData().max_ab_speed() : parent->GetComputerData().max_speed() );
143  Vector normheading = heading;
144  normheading.Normalize();
145  Vector max_velocity = max_speed*normheading;
146  max_velocity.Set( fabs( max_velocity.i ),
147  fabs( max_velocity.j ),
148  fabs( max_velocity.k ) );
149  if (done) return done; //unreachable
150 
151  if (terminatingX > switchbacks
152  && terminatingY > switchbacks
153  && terminatingZ > switchbacks) {
154  if ( Done( last_velocity ) ) {
155  if (selfterminating) {
156  done = true;
157  } else {
158  terminatingX = 0;
159  terminatingY = 0;
160  terminatingZ = 0;
161  }
162  return done;
163  }
164  thrust = (-parent->GetMass()/SIMULATION_ATOM)*last_velocity;
165  } else {
166  float div = 1.0f;
167  float vdiv = 1.0f;
168  if (selfterminating && terminatingX > 8 && terminatingY > 8 && terminatingZ > 8) {
169  int tmp = (terminatingX-4);
170  if (terminatingY < terminatingX) tmp = terminatingY-4;
171  if (terminatingZ < terminatingX && terminatingZ < terminatingY) tmp = terminatingZ-4;
172  tmp /= 4;
173  if (tmp > 30) tmp = 30;
174  vdiv = (float) (1<<tmp);
175  div = vdiv;
176  thrust.i /= div;
177  thrust.j /= div;
178  thrust.k /= div;
179  }
180  //start with Forward/Reverse:
181  float t = CalculateDecelTime( heading.k, last_velocity.k, thrust.k, parent->Limits().retro/div, parent->GetMass() );
182  if (t < THRESHOLD) {
183  thrust.k =
184  ( thrust.k > 0 ? -parent->Limits().retro
185  /div : ( afterburn ? parent->Limits().afterburn/div : parent->Limits().forward/div ) );
186  } else if (t < SIMULATION_ATOM) {
187  thrust.k *= t/SIMULATION_ATOM;
188  thrust.k +=
190  -t)
191  *( thrust.k > 0 ? -parent->Limits().retro
192  /div : ( afterburn ? parent->Limits().afterburn/div : parent->Limits().forward/div ) )/SIMULATION_ATOM;
193  }
194  OptimizeSpeed( parent, last_velocity.k, thrust.k, max_velocity.k/vdiv );
195  t = CalculateBalancedDecelTime( heading.i, last_velocity.i, thrust.i, parent->GetMass() );
196  if (t < THRESHOLD)
197  thrust.i = -thrust.i;
198  else if (t < SIMULATION_ATOM)
199  thrust.i *= ( t-(SIMULATION_ATOM-t) )/SIMULATION_ATOM;
200  OptimizeSpeed( parent, last_velocity.i, thrust.i, max_velocity.i/vdiv );
201  t = CalculateBalancedDecelTime( heading.j, last_velocity.j, thrust.j, parent->GetMass() );
202  if (t < THRESHOLD)
203  thrust.j = -thrust.j;
204  else if (t < SIMULATION_ATOM)
205  thrust.j *= ( t-(SIMULATION_ATOM-t) )/SIMULATION_ATOM;
206  OptimizeSpeed( parent, last_velocity.j, thrust.j, max_velocity.j/vdiv );
207  }
208  parent->ApplyLocalForce( thrust );
209 
210  return done;
211 }
void Orders::MoveToParent::SetAfterburn ( bool  tf)
inline

Definition at line 34 of file navigation.h.

Referenced by Orders::MoveTo::SetAfterburn().

35  {
36  afterburn = tf;
37  }

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