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

#include <planet.h>

Inheritance diagram for GamePlanet:
GameUnit< class Planet >

Public Member Functions

virtual ~GamePlanet ()
 
virtual void AddFog (const std::vector< AtmosphericFogMesh > &, bool optical_illusion)
 
Vector AddSpaceElevator (const std::string &name, const std::string &faction, char direction)
 
void AddAtmosphere (const std::string &texture, float radius, BLENDFUNC blendSrc, BLENDFUNC blendDst, bool inside_out)
 
void AddRing (const std::string &texture, float iradius, float oradius, const QVector &r, const QVector &s, int slices, int numwrapx, int numwrapy, BLENDFUNC blendSrc, BLENDFUNC blendDst)
 
void AddCity (const std::string &texture, float radius, int numwrapx, int numwrapy, BLENDFUNC blendSrc, BLENDFUNC blendDst, bool inside_out=false, bool reverse_normals=true)
 
void DisableLights ()
 
void EnableLights ()
 
virtual void Draw (const Transformation &quat=identity_transformation, const Matrix &m=identity_matrix)
 Draws this unit with the transformation and matrix (should be equiv) separately. More...
 
void DrawTerrain ()
 
virtual void Kill (bool erasefromsave=false)
 
PlanetaryTransform * setTerrain (ContinuousTerrain *, float ratiox, int numwraps, float scaleatmos)
 
ContinuousTerraingetTerrain (PlanetaryTransform *&t)
 
void setAtmosphere (Atmosphere *)
 
AtmospheregetAtmosphere ()
 
void reactToCollision (Unit *smaller, const QVector &biglocation, const Vector &bignormal, const QVector &smalllocation, const Vector &smallnormal, float dist)
 
- Public Member Functions inherited from GameUnit< class Planet >
 GameUnit (int dummy)
 
 GameUnit (std::vector< Mesh * > &meshes, bool Subunit, int faction)
 
 GameUnit (const char *filename, bool SubUnit, int faction, std::string customizedUnit=std::string(""), Flightgroup *flightgroup=NULL, int fg_subnumber=0, std::string *netxml=NULL)
 
virtual ~GameUnit ()
 
int nummesh () const
 
UnitImages< void > & GetImageInformation ()
 
bool RequestClearance (Unit *dockingunit)
 
void UpgradeInterface (Unit *base)
 Loads a user interface for the user to upgrade his ship. More...
 
virtual void Cloak (bool cloak)
 The name (type) of this unit shouldn't be public. More...
 
void Split (int level)
 
void FixGauges ()
 
void UpdateHudMatrix (int whichcam)
 Sets the camera to be within this unit. More...
 
VSSpritegetHudImage () const
 What's the HudImage of this unit. More...
 
virtual void Draw (const Transformation &quat)
 
virtual void Draw ()
 
virtual void DrawNow (const Matrix &m, float lod=1000000000)
 
virtual void DrawNow ()
 
void addHalo (const char *filename, const QVector &loc, const Vector &size, const GFXColor &col, std::string halo_type, float halo_speed)
 Deprecated. More...
 
virtual void applyTechniqueOverrides (const std::map< std::string, std::string > &overrides)
 
bool TransferUnitToSystem (unsigned int whichJumpQueue, StarSystem *&previouslyActiveStarSystem, bool DoSightAndSound)
 
bool Explode (bool draw, float timeit)
 Begin and continue explosion. More...
 
bool queryFrustum (double frustum[6][4]) const
 
*bool querySphereClickList (int, int, float err, Camera *activeCam)
 
virtual void UpdatePhysics2 (const Transformation &trans, const Transformation &old_physical_state, const Vector &accel, float difficulty, const Matrix &transmat, const Vector &CumulativeVelocity, bool ResolveLast, UnitCollection *uc=NULL)
 returns true if jump possible even if not taken More...
 
void Thrust (const Vector &amt, bool afterburn=false)
 Thrusts by ammt and clamps accordingly (afterburn or not) More...
 
Vector ResolveForces (const Transformation &, const Matrix &)
 Resolves forces of given unit on a physics frame. More...
 
virtual void ArmorDamageSound (const Vector &pnt)
 
virtual void HullDamageSound (const Vector &pnt)
 
float DealDamageToShield (const Vector &pnt, float &Damage)
 applies damage from the given pnt to the shield, and returns % damage applied and applies lighitn More...
 
bool UpgradeSubUnits (const Unit *up, int subunitoffset, bool touchme, bool downgrade, int &numave, double &percentage)
 
double Upgrade (const std::string &file, int mountoffset, int subunitoffset, bool force, bool loop_through_mounts)
 
Matrix WarpMatrix (const Matrix &ctm) const
 Holds temporary values for inter-function XML communication Saves deprecated restr info. More...
 

Static Public Member Functions

static void ProcessTerrains ()
 

Public Attributes

UnitCollection satellites
 
- Public Attributes inherited from GameUnit< class Planet >
double sparkle_accum
 
std::auto_ptr< HaloSystemphalos
 

Protected Member Functions

 GamePlanet ()
 default constructor - only to be called by UnitFactory More...
 
 GamePlanet (QVector x, QVector y, float vely, const Vector &rotvel, float pos, float gravity, float radius, const std::string &filename, const std::string &technique, const std::string &unitname, BLENDFUNC blendsrc, BLENDFUNC blenddst, const std::vector< std::string > &dest, const QVector &orbitcent, Unit *parent, const GFXMaterial &ourmat, const std::vector< GFXLightLocal > &, int faction, string fullname, bool inside_out=false)
 constructor - only to be called by UnitFactory More...
 

Friends

class UnitFactory
 
class Planet::PlanetIterator
 
class PlanetaryOrbit
 

Detailed Description

Definition at line 25 of file planet.h.

Constructor & Destructor Documentation

GamePlanet::GamePlanet ( )
protected

default constructor - only to be called by UnitFactory

Definition at line 30 of file planet.cpp.

30  :
31  GameUnit< Planet > ( 0 )
32 {
33  atmosphere = NULL;
34  terrain = NULL;
35  radius = 0.0;
36  shine = NULL;
37  inside = false;
38  Init();
39  terraintrans = NULL;
40  SetAI( new Order() ); //no behavior
41 }
GamePlanet::GamePlanet ( QVector  x,
QVector  y,
float  vely,
const Vector rotvel,
float  pos,
float  gravity,
float  radius,
const std::string &  filename,
const std::string &  technique,
const std::string &  unitname,
BLENDFUNC  blendsrc,
BLENDFUNC  blenddst,
const std::vector< std::string > &  dest,
const QVector orbitcent,
Unit parent,
const GFXMaterial ourmat,
const std::vector< GFXLightLocal > &  ,
int  faction,
string  fullname,
bool  inside_out = false 
)
protected

constructor - only to be called by UnitFactory

GamePlanet::~GamePlanet ( )
virtual

Definition at line 511 of file planet.cpp.

512 {
513  if (shine)
514  delete shine;
515  if (terrain)
516  delete terrain;
517  if (atmosphere)
518  delete atmosphere;
519 #ifdef FIX_TERRAIN
520  if (terraintrans) {
521  Matrix *tmp = new Matrix();
522  *tmp = cumulative_transformation_matrix;
523  terraintrans->SetTransformation( tmp );
524  //FIXME
525  //We're losing memory here...but alas alas... planets don't die that often
526  }
527 #endif
528 }

Member Function Documentation

void GamePlanet::AddAtmosphere ( const std::string &  texture,
float  radius,
BLENDFUNC  blendSrc,
BLENDFUNC  blendDst,
bool  inside_out 
)

Definition at line 177 of file planet.cpp.

References a, VegaConfig::getVariable(), XMLSupport::parse_int(), and vs_config.

182 {
183  if ( meshdata.empty() )
184  meshdata.push_back( NULL );
185  Mesh *shield = meshdata.back();
186  meshdata.pop_back();
187  static int stacks = XMLSupport::parse_int( vs_config->getVariable( "graphics", "planet_detail", "24" ) );
188  meshdata.push_back( new SphereMesh( radius, stacks, stacks, texture.c_str(), string(), NULL, inside_out, blendSrc, blendDst ) );
189  if ( meshdata.back() ) {
190  //By klauss - this needs to be done for most atmospheres
191  GFXMaterial a = {
192  0, 0, 0, 0,
193  1, 1, 1, 1,
194  0, 0, 0, 0,
195  0, 0, 0, 0,
196  0
197  };
198  meshdata.back()->SetMaterial( a );
199  }
200  meshdata.push_back( shield );
201 }
void GamePlanet::AddCity ( const std::string &  texture,
float  radius,
int  numwrapx,
int  numwrapy,
BLENDFUNC  blendSrc,
BLENDFUNC  blendDst,
bool  inside_out = false,
bool  reverse_normals = true 
)

Definition at line 141 of file planet.cpp.

References GFXMaterial::aa, GFXMaterial::ab, GFXMaterial::ag, GFXMaterial::ar, GFXMaterial::da, GFXMaterial::db, GFXMaterial::dg, GFXMaterial::dr, GFXMaterial::ea, GFXMaterial::eb, GFXMaterial::eg, GFXMaterial::er, VegaConfig::getVariable(), GFXFALSE, M_PI, ONE, XMLSupport::parse_float(), XMLSupport::parse_int(), GFXMaterial::power, GFXMaterial::sa, GFXMaterial::sb, GFXMaterial::sg, GFXMaterial::sr, and vs_config.

149 {
150  if ( meshdata.empty() )
151  meshdata.push_back( NULL );
152  Mesh *shield = meshdata.back();
153  meshdata.pop_back();
154  GFXMaterial m;
155  m.ar = m.ag = m.ab = m.aa = 0.0;
156  static float materialweight = XMLSupport::parse_float( vs_config->getVariable( "graphics", "city_light_strength", "10" ) );
157  static float daymaterialweight =
158  XMLSupport::parse_float( vs_config->getVariable( "graphics", "day_city_light_strength", "0" ) );
159  m.dr = m.dg = m.db = m.da = materialweight;
160  m.sr = m.sg = m.sb = m.sa = 0.0;
161  m.er = m.eg = m.eb = m.ea = daymaterialweight;
162  m.power = 0.0;
163  static int stacks = XMLSupport::parse_int( vs_config->getVariable( "graphics", "planet_detail", "24" ) );
164  meshdata.push_back( new CityLights( radius, stacks, stacks, texture.c_str(), numwrapx, numwrapy, inside_out, ONE, ONE,
165  false, 0, M_PI, 0.0, 2*M_PI, reverse_normals ) );
166  meshdata.back()->setEnvMap( GFXFALSE );
167  meshdata.back()->SetMaterial( m );
168 
169  meshdata.push_back( shield );
170 }
void GamePlanet::AddFog ( const std::vector< AtmosphericFogMesh > &  v,
bool  optical_illusion 
)
virtual

Definition at line 117 of file planet.cpp.

References UnitFactory::createUnit(), Unit::GetHullPercent(), Unit::hull, i, MakeFogMesh(), and Unit::setFaceCamera().

118 {
119  if ( meshdata.empty() ) meshdata.push_back( NULL );
120 #ifdef MESHONLY
121  Mesh *shield = meshdata.back();
122  meshdata.pop_back();
123 #endif
124  std::vector< Mesh* >fogs;
125  for (unsigned int i = 0; i < v.size(); ++i) {
126  Mesh *fog = MakeFogMesh( v[i], rSize() );
127  fogs.push_back( fog );
128  }
129  Unit *fawg;
130  if (opticalillusion)
131  fawg = new AtmosphereHalo( this->rSize(), fogs, 0 );
132  else
133  fawg = UnitFactory::createUnit( fogs, true, 0 );
134  fawg->setFaceCamera();
135  getSubUnits().preinsert( fawg );
136  fawg->hull /= fawg->GetHullPercent();
137 #ifdef MESHONLY
138  meshdata.push_back( shield );
139 #endif
140 }
void GamePlanet::AddRing ( const std::string &  texture,
float  iradius,
float  oradius,
const QVector r,
const QVector s,
int  slices,
int  numwrapx,
int  numwrapy,
BLENDFUNC  blendSrc,
BLENDFUNC  blendDst 
)

Definition at line 202 of file planet.cpp.

References VegaConfig::getVariable(), i, M_PI, XMLSupport::parse_int(), R, S, and vs_config.

212 {
213  if ( meshdata.empty() )
214  meshdata.push_back( NULL );
215  Mesh *shield = meshdata.back();
216  meshdata.pop_back();
217  static int stacks = XMLSupport::parse_int( vs_config->getVariable( "graphics", "planet_detail", "24" ) );
218  if (slices > 0) {
219  stacks = stacks;
220  if (stacks < 3)
221  stacks = 3;
222  for (int i = 0; i < slices; i++)
223  meshdata.push_back( new RingMesh( iradius, oradius, stacks, texture.c_str(), R, S, wrapx, wrapy, blendSrc, blendDst,
224  false, i*(2*M_PI)/( (float) slices ), (i+1)*(2*M_PI)/( (float) slices ) ) );
225  }
226  meshdata.push_back( shield );
227 }
Vector GamePlanet::AddSpaceElevator ( const std::string &  name,
const std::string &  faction,
char  direction 
)

Definition at line 172 of file planet.cpp.

References Planet::AddSpaceElevator().

173 {
174  //direction is udrlfb//up down right left front ack
175  return Planet::AddSpaceElevator( name, faction, direction );
176 }
void GamePlanet::DisableLights ( )

Definition at line 506 of file planet.cpp.

References GFXDisableLight(), i, and StarSystemGent::lights.

507 {
508  for (unsigned int i = 0; i < lights.size(); i++)
509  GFXDisableLight( lights[i] );
510 }
void GamePlanet::Draw ( const Transformation quat = identity_transformation,
const Matrix m = identity_matrix 
)
virtual

Draws this unit with the transformation and matrix (should be equiv) separately.

somehow warp unit to reasonable place outisde of planet

Reimplemented from GameUnit< class Planet >.

Definition at line 362 of file planet.cpp.

References _Universe, Universe::AccessCamera(), c, Animation::Draw(), GameUnit< UnitType >::Draw(), Camera::GetPosition(), VegaConfig::getVariable(), GFXLoadIdentity(), GFXSetLight(), i, StarSystemGent::lights, MatrixToVectors(), MODEL, XMLSupport::parse_int(), POSITION, q, QVector, Animation::SetOrientation(), Animation::SetPosition(), Vector, and vs_config.

363 {
364  //Do lighting fx
365  //if cam inside don't draw?
366  //if(!inside) {
367  GameUnit< Planet >::Draw( quat, m );
368  //}
369  QVector t( _Universe->AccessCamera()->GetPosition()-Position() );
370  static int counter = 0;
371  if (counter++ > 100) {
372  if (t.Magnitude() < corner_max.i) {
373  inside = true;
374  } else {
375  inside = false;
377  if (terrain) {
378 #ifdef PLANETARYTRANSFORM
379  terrain->DisableUpdate();
380 #endif
381  }
382  }
383  }
385  for (unsigned int i = 0; i < lights.size(); i++)
386  GFXSetLight( lights[i], POSITION, GFXColor( cumulative_transformation.position.Cast() ) );
387  if (inside && terrain)
388  PlanetTerrainDrawQueue.push_back( new UnitContainer( this ) );
389  if (shine) {
390  Vector p, q, r;
391  QVector c;
392  MatrixToVectors( cumulative_transformation_matrix, p, r, q, c );
393  shine->SetOrientation( p, q, r );
394  shine->SetPosition( c );
395  static int num_shine_drawing =
396  XMLSupport::parse_int( vs_config->getVariable( "graphics", "num_times_to_draw_shine", "2" ) );
397  for (int i = 0; i < num_shine_drawing; ++i)
398  shine->Draw();
399  }
400 }
void GamePlanet::DrawTerrain ( )

Definition at line 412 of file planet.cpp.

References _Universe, Universe::AccessCamera(), Universe::activeStarSystem(), blah, Camera::GetPlanetGFX(), Camera::GetPosition(), GFXLoadIdentity(), MODEL, Camera::UpdatePlanetGFX(), and Vector.

413 {
414  inside = true;
415  if (terrain)
416  terrain->EnableUpdate();
417 #ifdef PLANETARYTRANSFORM
418  TerrainUp = t;
419  Normalize( TerrainUp );
420  TerrainH = TerrainUp.Cross( Vector( -TerrainUp.i+.25, TerrainUp.j-.24, -TerrainUp.k+.24 ) );
421  Normalize( TerrainH );
422 #endif
423 
425  if (inside && terrain) {
427  terrain->SetTransformation( *_Universe->AccessCamera()->GetPlanetGFX() );
428  terrain->AdjustTerrain( _Universe->activeStarSystem() );
429  terrain->Draw();
430 #ifdef PLANETARYTRANSFORM
431  terraintrans->GrabPerpendicularOrigin( _Universe->AccessCamera()->GetPosition(), tmp );
432  terrain->SetTransformation( tmp );
433  terrain->AdjustTerrain( _Universe->activeStarSystem() );
434  terrain->Draw();
435  if (atmosphere) {
436  Vector tup( tmp[4], tmp[5], tmp[6] );
438  Vector blah = p-Vector( tmp[12], tmp[13], tmp[14] );
439  blah = p-( blah.Dot( tup ) )*tup;
440  tmp[12] = blah.i;
441  tmp[13] = blah.j;
442  tmp[14] = blah.k;
443  atmosphere->SetMatricesAndDraw( _Universe->AccessCamera()->GetPosition(), tmp );
444  }
445 #endif
446  }
447 }
void GamePlanet::EnableLights ( )

Definition at line 501 of file planet.cpp.

References GFXEnableLight(), i, and StarSystemGent::lights.

502 {
503  for (unsigned int i = 0; i < lights.size(); i++)
504  GFXEnableLight( lights[i] );
505 }
Atmosphere* GamePlanet::getAtmosphere ( )
inline

Definition at line 95 of file planet.h.

96  {
97  return atmosphere;
98  }
ContinuousTerrain* GamePlanet::getTerrain ( PlanetaryTransform *&  t)
inline

Definition at line 89 of file planet.h.

90  {
91  t = terraintrans;
92  return terrain;
93  }
void GamePlanet::Kill ( bool  erasefromsave = false)
virtual

Definition at line 550 of file planet.cpp.

References UnitCollection::clear(), UnitCollection::createIterator(), GFXDeleteLight(), i, StarSystemGent::lights, satellites, and Unit::SetAI().

551 {
552  Unit *tmp;
553  for (un_iter iter = satellites.createIterator(); (tmp=*iter)!=NULL; ++iter)
554  tmp->SetAI( new Order );
555  /* probably not FIXME...right now doesn't work on paged out systems... not a big deal */
556  for (unsigned int i = 0; i < this->lights.size(); i++)
557  GFXDeleteLight( lights[i] );
558  /* */
559  satellites.clear();
560  insiders.clear();
561  GameUnit< Planet >::Kill( erasefromsave );
562 }
void GamePlanet::ProcessTerrains ( )
static

Definition at line 401 of file planet.cpp.

References Planet::DrawTerrain().

Referenced by GameStarSystem::Draw().

402 {
403  while ( !PlanetTerrainDrawQueue.empty() ) {
404  Planet *pl = (Planet*) PlanetTerrainDrawQueue.back()->GetUnit();
405  pl->DrawTerrain();
406  PlanetTerrainDrawQueue.back()->SetUnit( NULL );
407  delete PlanetTerrainDrawQueue.back();
408  PlanetTerrainDrawQueue.pop_back();
409  }
410 }
void GamePlanet::reactToCollision ( Unit smaller,
const QVector biglocation,
const Vector bignormal,
const QVector smalllocation,
const Vector smallnormal,
float  dist 
)

Definition at line 451 of file planet.cpp.

References _Universe, CrashForceDock(), Unit::UnitJump::drive, Unit::GetJumpStatus(), Unit::GetOrientation(), VegaConfig::getVariable(), Identity(), InvertMatrix(), Universe::isPlayerStarship(), Unit::isUnit(), MultMatrix(), Unit::name, XMLSupport::parse_bool(), PLANETPTR, Unit::Position(), R, Vector, VectorAndPositionToMatrix(), vs_config, and VSFileSystem::vs_fprintf().

457 {
458 #ifdef JUMP_DEBUG
459  VSFileSystem::vs_fprintf( stderr, "%s reacting to collision with %s drive %d", name.c_str(),
460  un->name.c_str(), un->GetJumpStatus().drive );
461 #endif
462 #ifdef FIX_TERRAIN
463  if (terrain && un->isUnit() != PLANETPTR) {
464  un->SetPlanetOrbitData( terraintrans );
465  Matrix top;
466  Identity( top );
467  /*
468  * Vector posRelToTerrain = terraintrans->InvTransform(un->LocalPosition());
469  * top[12]=un->Position().i- posRelToTerrain.i;
470  * top[13]=un->Position().j- posRelToTerrain.j;
471  * top[14]=un->Position().k- posRelToTerrain.k;
472  */
473  Vector P, Q, R;
474  un->GetOrientation( P, Q, R );
475  terraintrans->InvTransformBasis( top, P, Q, R, un->Position() );
476  Matrix inv, t;
477 
478  InvertMatrix( inv, top );
479  VectorAndPositionToMatrix( t, P, Q, R, un->Position() );
480  MultMatrix( top, t, inv );
481 #ifdef PLANETARYTRANSFORM
482  terraintrans->GrabPerpendicularOrigin( un->Position(), top );
483  static int tmp = 0;
484 #endif
485  terrain->Collide( un, top );
486  }
487 #endif
488  jumpReactToCollision( un );
489  //screws with earth having an atmosphere... blahrgh
490  if (!terrain && GetDestinations().empty() && !atmospheric) {
491  //no place to go and acts like a ship
492  GameUnit< Planet >::reactToCollision( un, biglocation, bignormal, smalllocation, smallnormal, dist );
493  static bool planet_crash_docks =
494  XMLSupport::parse_bool( vs_config->getVariable( "physics", "planet_collision_docks", "true" ) );
495  if (_Universe->isPlayerStarship( un ) && planet_crash_docks)
496  CrashForceDock( this, un, true );
497  }
498  //nothing happens...you fail to do anythign :-)
499  //maybe air reisstance here? or swithc dynamics to atmos mode
500 }
void GamePlanet::setAtmosphere ( Atmosphere t)

Definition at line 545 of file planet.cpp.

546 {
547  atmosphere = t;
548 }
PlanetaryTransform * GamePlanet::setTerrain ( ContinuousTerrain t,
float  ratiox,
int  numwraps,
float  scaleatmos 
)

Definition at line 530 of file planet.cpp.

References ContinuousTerrain::DisableDraw(), ContinuousTerrain::GetTotalSize(), x, and z.

531 {
532  terrain = t;
533  terrain->DisableDraw();
534  float x, z;
535  t->GetTotalSize( x, z );
536 #ifdef FIX_TERRAIN
537  terraintrans = new PlanetaryTransform( .8*corner_max.i, x*ratiox, z, numwraps, scaleatmos );
538  terraintrans->SetTransformation( &cumulative_transformation_matrix );
539 
540  return terraintrans;
541 #endif
542  return NULL;
543 }

Friends And Related Function Documentation

friend class Planet::PlanetIterator
friend

Definition at line 106 of file planet.h.

friend class PlanetaryOrbit
friend

Definition at line 107 of file planet.h.

friend class UnitFactory
friend

Definition at line 55 of file planet.h.

Member Data Documentation

UnitCollection GamePlanet::satellites

Definition at line 58 of file planet.h.

Referenced by Kill().


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