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
PlanetaryOrbit Class Reference

#include <planet_generic.h>

Inheritance diagram for PlanetaryOrbit:
Order

Public Member Functions

 PlanetaryOrbit (Unit *p, double velocity, double initpos, const QVector &x_axis, const QVector &y_axis, const QVector &Centre, Unit *target=NULL)
 
 ~PlanetaryOrbit ()
 
void Execute ()
 The function that gets called and executes all queued suborders. More...
 
- Public Member Functions inherited from Order
virtual void ChooseTarget ()
 this function calls the destructor (needs to be overridden for python; More...
 
virtual bool PursueTarget (Unit *, bool isleader)
 
void ClearMessages ()
 clears the messasges of this order More...
 
 Order ()
 The default constructor setting everything to NULL and no dependency on order. More...
 
 Order (int type, int subtype)
 The constructor that specifies what order dependencies this order has. More...
 
virtual void Destroy ()
 The virutal function that unrefs all memory then calls Destruct () which takes care of unreffing this or calling delete on this. More...
 
OrderqueryType (unsigned int type)
 returns a pointer to the first order that may be bitwised ored with that type More...
 
OrderqueryAny (unsigned int type)
 returns a pointer to the first order that may be bitwise ored with any type More...
 
void eraseType (unsigned int type)
 Erases all orders that bitwise OR with that type. More...
 
bool AttachOrder (Unit *targets)
 Attaches a group of targets to this order (used for strategery-type games) More...
 
bool AttachOrder (QVector target)
 Attaches a navigation point to this order. More...
 
bool AttachSelfOrder (Unit *targets)
 Attaches a group (form up) to this order. More...
 
OrderEnqueueOrder (Order *ord)
 Enqueues another order that will be executed (in parallel perhaps) when next void Execute() is called. More...
 
OrderReplaceOrder (Order *ord)
 Replaces the first order of that type in the order queue. More...
 
bool Done ()
 
int getType ()
 
int getSubType ()
 
virtual void SetParent (Unit *parent1)
 Sets the parent of this Unit. Any virtual functions must call this one. More...
 
UnitGetParent () const
 
virtual void Communicate (const class CommunicationMessage &c)
 Sends a communication message from the Unit (encapulated in c) to this unit. More...
 
virtual void ProcessCommMessage (class CommunicationMessage &c)
 processes a single message...generally called by the Messages() func More...
 
virtual void ProcessCommunicationMessages (float CommRepsonseTime, bool RemoveMessageProcessed)
 responds (or does not) to certain messages in the message queue More...
 
OrderfindOrder (Order *ord)
 return pointer to order or NULL if not found More...
 
void eraseOrder (Order *ord)
 erase that order from the list More...
 
OrderEnqueueOrderFirst (Order *ord)
 enqueue order as first order More...
 
virtual olist_tgetOrderList ()
 returns the orderlist (NULL for orders that haven't got any) More...
 
virtual void AdjustRelationTo (Unit *un, float factor)
 
virtual std::string getOrderDescription ()
 
OrderfindOrderList ()
 searches the suborders recursively for the first order that has an orderlist More...
 
std::string createFullOrderDescription (int level=0)
 
void setActionString (std::string astring)
 
std::string getActionString ()
 
virtual float getMood ()
 

Protected Attributes

std::vector< intlights
 A vector containing all lihgts currently activated on current planet. More...
 
- Protected Attributes inherited from Order
Unitparent
 The unit this order is attached to. More...
 
unsigned int type
 The bit code (from ORDERTYPES) that this order is (for parallel execution) More...
 
unsigned int subtype
 
bool done
 Whether or not this order is done. More...
 
UnitContainer group
 If this order applies to a group of units (as in form up with this group) More...
 
QVector targetlocation
 If this order applies to a physical location in world space. More...
 
std::vector< Order * > suborders
 The queue of suborders that will be executed in parallel according to bit code. More...
 
std::list< class
CommunicationMessage * > 
messagequeue
 a bunch of communications that have not been answered CommunicationMessages are actually containing reference to a nice Finite State Machine that can allow a player to have a reasonable conversation with an AI More...
 
std::string actionstring
 

Additional Inherited Members

- Public Types inherited from Order
enum  ORDERTYPES {
  MOVEMENT =1, FACING =2, WEAPON =4, CLOAKING =8,
  ALLTYPES =(1|2|4|8)
}
 The varieties of order types MOVEMENT,FACING, and WEAPON orders may not be mutually executed (lest one engine goes left, the other right) More...
 
enum  SUBORDERTYPES { SLOCATION =1, STARGET =2, SSELF =4 }
 
- Protected Member Functions inherited from Order
virtual ~Order ()
 
virtual void Destructor ()
 changes the local relation of this unit to another...may inform superiors about "good" or bad! behavior depending on the AI More...
 

Detailed Description

Definition at line 14 of file planet_generic.h.

Constructor & Destructor Documentation

PlanetaryOrbit::PlanetaryOrbit ( Unit p,
double  velocity,
double  initpos,
const QVector x_axis,
const QVector y_axis,
const QVector Centre,
Unit target = NULL 
)

Definition at line 32 of file planet_generic.cpp.

References Order::AttachOrder(), Order::AttachSelfOrder(), getNewTime(), Order::MOVEMENT, Network, NUM_ORBIT_AVERAGE, PI, QVector, SERVER, Order::SetParent(), Unit::SetResolveForces(), SIMULATION_ATOM, Order::SLOCATION, Order::SSELF, Order::subtype, and Order::type.

38  : Order( MOVEMENT, 0 )
39  , velocity( velocity )
40  , theta( initpos )
41  , inittheta( initpos )
42  , x_size( x_axis )
43  , y_size( y_axis )
44  , current_orbit_frame( 0 )
45 {
46  for (unsigned int t = 0; t < NUM_ORBIT_AVERAGE; ++t)
47  orbiting_average[t] = QVector( 0, 0, 0 );
48  orbiting_last_simatom = SIMULATION_ATOM;
49  orbit_list_filled = false;
50  p->SetResolveForces( false );
51  double delta = x_size.Magnitude()-y_size.Magnitude();
52  if (delta == 0)
53  focus = QVector( 0, 0, 0 );
54  else if (delta > 0)
55  focus = x_size*( delta/x_size.Magnitude() );
56  else
57  focus = y_size*( -delta/y_size.Magnitude() );
58  if (targetunit) {
59  type = (MOVEMENT);
60  subtype = (SSELF);
61  AttachSelfOrder( targetunit );
62  } else {
63  type = (MOVEMENT);
64  subtype = (SLOCATION);
65  AttachOrder( centre );
66  }
67  const double div2pi = ( 1.0/(2.0*PI) );
68  if (Network != NULL || SERVER)
69  theta = inittheta+velocity * getNewTime()*div2pi;
70  this->SetParent( p );
71 }
PlanetaryOrbit::~PlanetaryOrbit ( )

Definition at line 73 of file planet_generic.cpp.

References Order::parent, and Unit::SetResolveForces().

74 {
75  parent->SetResolveForces( true );
76 }

Member Function Documentation

void PlanetaryOrbit::Execute ( )
virtual

The function that gets called and executes all queued suborders.

Reimplemented from Order.

Definition at line 78 of file planet_generic.cpp.

References UniverseUtil::cos(), Unit::cumulative_velocity, Order::done, Order::Execute(), f, float, getNewTime(), UnitContainer::GetUnit(), VegaConfig::getVariable(), Order::group, i, int, j, k, Unit::LocalPosition(), Magnitude(), Network, NUM_ORBIT_AVERAGE, Order::parent, XMLSupport::parse_float(), PI, Transformation::position, Unit::predicted_priority, Unit::prev_physical_state, QVector, Unit::rSize(), SERVER, Unit::SetCurPosition(), Unit::SetResolveForces(), SIMULATION_ATOM, UniverseUtil::sin(), Order::SSELF, Order::subtype, Order::targetlocation, Unit::Velocity, and vs_config.

79 {
80  bool mining = parent->rSize() > 1444 && parent->rSize() < 1445;
81  bool done = this->done;
82  this->Order::Execute();
83  this->done = done; //we ain't done till the cows come home
84  if (done)
85  return;
86  QVector origin( targetlocation );
87  static float orbit_centroid_averaging = XMLSupport::parse_float( vs_config->getVariable( "physics", "orbit_averaging", "16" ) );
88  float averaging = (float) orbit_centroid_averaging/(float) (parent->predicted_priority+1.0f);
89  if (averaging < 1.0f) averaging = 1.0f;
90  if (subtype&SSELF) {
91  Unit *unit = group.GetUnit();
92  if (unit) {
93  unsigned int o = current_orbit_frame++;
94  current_orbit_frame %= NUM_ORBIT_AVERAGE;
95  if (current_orbit_frame == 0)
96  orbit_list_filled = true;
97  QVector desired = unit->prev_physical_state.position;
98  if (orbiting_average[o].i == 0 && orbiting_average[o].j == 0 && orbiting_average[o].k == 0) {
99  //clear all of them.
100  for (o = 0; o < NUM_ORBIT_AVERAGE; o++)
101  orbiting_average[o] = desired;
102  orbiting_last_simatom = SIMULATION_ATOM;
103  current_orbit_frame = 2;
104  orbit_list_filled = false;
105  } else {
106  if (SIMULATION_ATOM != orbiting_last_simatom) {
107  QVector sum_diff( 0, 0, 0 );
108  QVector sum_position;
109  int limit;
110  if (orbit_list_filled) {
111  sum_position = orbiting_average[o];
112  limit = NUM_ORBIT_AVERAGE-1;
113  o = (o+1)%NUM_ORBIT_AVERAGE;
114  } else {
115  sum_position = orbiting_average[0];
116  limit = o;
117  o = 1;
118  }
119  for (int i = 0; i < limit; i++) {
120  sum_diff += (orbiting_average[o]-orbiting_average[(o+NUM_ORBIT_AVERAGE-1)%NUM_ORBIT_AVERAGE]);
121  sum_position += orbiting_average[o];
122  o = (o+1)%NUM_ORBIT_AVERAGE;
123  }
124  if (limit != 0)
125  sum_diff *= ( 1./(limit) );
126  sum_position *= ( 1./(limit+1) );
127 
128  float ratio_simatom = (SIMULATION_ATOM/orbiting_last_simatom);
129  sum_diff *= ratio_simatom;
130  unsigned int number_to_fill;
131  number_to_fill = (int) ( (NUM_ORBIT_AVERAGE/ratio_simatom)+.99 );
132  if (number_to_fill > NUM_ORBIT_AVERAGE) number_to_fill = NUM_ORBIT_AVERAGE;
133  if (ratio_simatom <= 1)
134  number_to_fill = NUM_ORBIT_AVERAGE;
135  //subtract it so the average remains the same.
136  sum_position += ( sum_diff*(number_to_fill/ -2.) );
137  for (o = 0; o < number_to_fill; o++) {
138  orbiting_average[o] = sum_position;
139  sum_position += sum_diff;
140  }
141  orbit_list_filled = (o >= NUM_ORBIT_AVERAGE-1);
142  o %= NUM_ORBIT_AVERAGE;
143  current_orbit_frame = (o+1)%NUM_ORBIT_AVERAGE;
144  orbiting_last_simatom = SIMULATION_ATOM;
145  }
146  orbiting_average[o] = desired;
147  }
148  } else {
149  done = true;
150  parent->SetResolveForces( true );
151  return; //flung off into space.
152  }
153  }
154  QVector sum_orbiting_average( 0, 0, 0 );
155  {
156  int limit;
157  if (orbit_list_filled)
158  limit = NUM_ORBIT_AVERAGE;
159  else
160  limit = current_orbit_frame;
161  for (int o = 0; o < limit; o++)
162  sum_orbiting_average += orbiting_average[o];
163  sum_orbiting_average *= 1./(limit == 0 ? 1 : limit);
164  }
165  const double div2pi = ( 1.0/(2.0*PI) );
166  theta += velocity*SIMULATION_ATOM*div2pi;
167  if (Network != NULL || SERVER) {
168  float truetheta = inittheta+velocity * getNewTime()*div2pi;
169  theta = theta*( (averaging-1.0f)/averaging )+truetheta*(1.0f/averaging);
170  }
171  QVector x_offset = cos( theta )*x_size;
172  QVector y_offset = sin( theta )*y_size;
173 
174  QVector destination = origin-focus+sum_orbiting_average+x_offset+y_offset;
175  double mag = ( destination-parent->LocalPosition() ).Magnitude();
176  if (mining && 0) {
177  printf( "(%.2f %.2f %.2f)\n(%.2f %.2f %.2f) del %.2f spd %.2f\n",
178  parent->LocalPosition().i,
179  parent->LocalPosition().j,
180  parent->LocalPosition().k,
181  destination.i,
182  destination.j,
183  destination.k,
184  mag,
185  mag*(1./SIMULATION_ATOM)
186  );
187  }
188  parent->Velocity = parent->cumulative_velocity = ( ( ( destination-parent->LocalPosition() )*(1./SIMULATION_ATOM) ).Cast() );
189  static float Unreasonable_value =
190  XMLSupport::parse_float( vs_config->getVariable( "physics", "planet_ejection_stophack", "2000" ) );
191  float v2 = parent->Velocity.Dot( parent->Velocity );
192  if (v2 > Unreasonable_value*Unreasonable_value ) {
193  parent->Velocity.Set( 0, 0, 0 );
194  parent->cumulative_velocity.Set( 0, 0, 0 );
195  parent->SetCurPosition( origin-focus+sum_orbiting_average+x_offset+y_offset );
196  }
197 }

Member Data Documentation

std::vector< int > PlanetaryOrbit::lights
protected

A vector containing all lihgts currently activated on current planet.

Definition at line 32 of file planet_generic.h.


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