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
star_system_generic.cpp File Reference
#include <assert.h>
#include "star_system_generic.h"
#include "gfx/vec.h"
#include "cmd/planet_generic.h"
#include "cmd/unit_generic.h"
#include "cmd/unit_collide.h"
#include "cmd/collection.h"
#include "gfx/cockpit_generic.h"
#include "audiolib.h"
#include "lin_time.h"
#include "cmd/beam.h"
#include "cmd/bolt.h"
#include <expat.h>
#include "cmd/music.h"
#include "configxml.h"
#include "vs_globals.h"
#include "vegastrike.h"
#include "universe_generic.h"
#include "cmd/nebula_generic.h"
#include "galaxy_gen.h"
#include "cmd/script/mission.h"
#include "in_kb.h"
#include "cmd/script/flightgroup.h"
#include "load_mission.h"
#include "cmd/unit_util.h"
#include "cmd/unit_factory.h"
#include "vs_random.h"
#include "savegame.h"
#include "networking/netclient.h"
#include "in_kb_data.h"
#include "universe_util.h"
#include <boost/version.hpp>
#include "cs_boostpython.h"

Go to the source code of this file.

Functions

void TentativeJumpTo (StarSystem *ss, Unit *un, Unit *jumppoint, const std::string &system)
 
float ScaleJumpRadius (float radius)
 
void ClientServerSetLightContext (int lightcontext)
 
void setStaticFlightgroup (vector< Flightgroup * > &fg, const std::string &nam, int faction)
 
FlightgroupgetStaticBaseFlightgroup (int faction)
 
FlightgroupgetStaticStarFlightgroup (int faction)
 
FlightgroupgetStaticNebulaFlightgroup (int faction)
 
FlightgroupgetStaticAsteroidFlightgroup (int faction)
 
FlightgroupgetStaticUnknownFlightgroup (int faction)
 
string RemoveDotSystem (const char *input)
 
UnitgetTopLevelOwner ()
 
void CarSimUpdate (Unit *un, float height)
 
void TerrainCollide ()
 
void UpdateAnimatedTexture ()
 
void UpdateCameraSnds ()
 
float getTimeCompression ()
 
void ExecuteDirector ()
 
StarSystemGetLoadedStarSystem (const char *system)
 
bool PendingJumpsEmpty ()
 
void SetShieldZero (Unit *)
 
double calc_blend_factor (double frac, int priority, unsigned int when_it_will_be_simulated, int cur_simulation_frame)
 
void ActivateAnimation (Unit *jumppoint)
 
static bool isJumping (const vector< unorigdest * > &pending, Unit *un)
 
QVector SystemLocation (std::string system)
 
double howFarToJump ()
 
QVector ComputeJumpPointArrival (QVector pos, std::string origin, std::string destination)
 

Variables

vector< Vectorperplines
 
std::vector< unorigdest * > pendingjump
 
unsigned int physicsframecounter = 1
 
unsigned int theunitcounter = 0
 
unsigned int totalprocessed = 0
 
unsigned int movingavgarray [128] = {0}
 
unsigned int movingtotal = 0
 
double aggfire = 0
 
int numprocessed = 0
 
double targetpick = 0
 
Hashtable< std::string,
StarSystem, 127 > 
star_system_table
 

Function Documentation

void ActivateAnimation ( Unit jumppoint)

Definition at line 893 of file star_system_generic.cpp.

References ActivateAnimation(), Unit::graphic_options::Animating, Unit::getSubUnits(), Unit::graphicOptions, and i.

Referenced by ActivateAnimation(), StarSystem::JumpTo(), and GameUnit< UnitType >::TransferUnitToSystem().

894 {
895  jumppoint->graphicOptions.Animating = 1;
896  Unit *un;
897  for (un_iter i = jumppoint->getSubUnits(); NULL != (un = *i); ++i)
898  ActivateAnimation( un );
899 }
double calc_blend_factor ( double  frac,
int  priority,
unsigned int  when_it_will_be_simulated,
int  cur_simulation_frame 
)

Definition at line 880 of file star_system_generic.cpp.

References SIM_QUEUE_SIZE.

881 {
882  if (when_it_will_be_simulated == SIM_QUEUE_SIZE) {
883  return 1;
884  } else {
885  int relwas = when_it_will_be_simulated-priority;
886  if (relwas < 0) relwas += SIM_QUEUE_SIZE;
887  int relcur = cur_simulation_frame-relwas-1;
888  if (relcur < 0) relcur += SIM_QUEUE_SIZE;
889  return (relcur+frac)/(double) priority;
890  }
891 }
void CarSimUpdate ( Unit un,
float  height 
)
void ClientServerSetLightContext ( int  lightcontext)

Definition at line 41 of file universe_util.cpp.

References GFXSetLightContext().

Referenced by StarSystem::~StarSystem().

42 {
43  GFXSetLightContext( lightcontext );
44 }
QVector ComputeJumpPointArrival ( QVector  pos,
std::string  origin,
std::string  destination 
)

Definition at line 911 of file star_system_generic.cpp.

References howFarToJump(), QVector, start, and SystemLocation().

Referenced by StarSystem::JumpTo().

912 {
913  QVector finish = SystemLocation( destination );
914  QVector start = SystemLocation( origin );
915  QVector dir = finish-start;
916  if ( dir.MagnitudeSquared() ) {
917  dir.Normalize();
918  dir = -dir;
919  pos = -pos;
920  pos.Normalize();
921  if ( pos.MagnitudeSquared() ) pos.Normalize();
922  return (dir*.5+pos*.125)*howFarToJump();
923  }
924  return QVector( 0, 0, 0 );
925 }
void ExecuteDirector ( )

Definition at line 617 of file star_system_generic.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, Cockpit::activeStarSystem, Universe::CurrentCockpit(), i, mission, Universe::popActiveStarSystem(), processDelayedMissions(), Universe::pushActiveStarSystem(), and Universe::SetActiveCockpit().

Referenced by BaseInterface::BaseInterface(), Unit::ForceDock(), NetServer::start(), and StarSystem::Update().

618 {
619  unsigned int curcockpit = _Universe->CurrentCockpit();
620  {
621  for (unsigned int i = 0; i < active_missions.size(); ++i)
622  if (active_missions[i]) {
623  _Universe->SetActiveCockpit( active_missions[i]->player_num );
625  if (ss) _Universe->pushActiveStarSystem( ss );
627  active_missions[i]->DirectorLoop();
628  if (ss) _Universe->popActiveStarSystem();
629  }
630  }
631  _Universe->SetActiveCockpit( curcockpit );
634  {
635  for (unsigned int i = 1; i < active_missions.size();) {
636  if (active_missions[i]) {
637  if (active_missions[i]->runtime.pymissions) {
638  ++i;
639  } else {
640  unsigned int w = active_missions.size();
641  active_missions[i]->terminateMission();
642  if ( w == active_missions.size() ) {
643  printf( "MISSION NOT ERASED\n" );
644  break;
645  }
646  }
647  } else {
648  active_missions.Get()->erase( active_missions.Get()->begin()+i );
649  }
650  }
651  }
652 }
StarSystem* GetLoadedStarSystem ( const char *  system)

Definition at line 786 of file star_system_generic.cpp.

References Hashtable< KEY, VALUE, SIZ >::Get().

Referenced by ZoneMgr::addZone(), GameUniverse::GenerateStarSystem(), and Universe::GenerateStarSystem().

787 {
788  StarSystem *ss = star_system_table.Get( string( system ) );
789  std::string ssys( string( system )+string( ".system" ) );
790  if (!ss)
791  ss = star_system_table.Get( ssys );
792  return ss;
793 }
Flightgroup* getStaticAsteroidFlightgroup ( int  faction)

Definition at line 195 of file star_system_generic.cpp.

References StarSystemGent::faction, and setStaticFlightgroup().

196 {
197  static vector< Flightgroup* >fg;
198  setStaticFlightgroup( fg, "Asteroid", faction );
199  return fg[faction];
200 }
Flightgroup* getStaticBaseFlightgroup ( int  faction)

Definition at line 172 of file star_system_generic.cpp.

References StarSystemGent::faction, and setStaticFlightgroup().

Referenced by Planet::beginElement().

173 {
174  //warning mem leak...not big O(num factions)
175  static vector< Flightgroup* >fg;
176  setStaticFlightgroup( fg, "Base", faction );
177  return fg[faction];
178 }
Flightgroup* getStaticNebulaFlightgroup ( int  faction)

Definition at line 188 of file star_system_generic.cpp.

References StarSystemGent::faction, and setStaticFlightgroup().

189 {
190  static vector< Flightgroup* >fg;
191  setStaticFlightgroup( fg, "Nebula", faction );
192  return fg[faction];
193 }
Flightgroup* getStaticStarFlightgroup ( int  faction)

Definition at line 180 of file star_system_generic.cpp.

References StarSystemGent::faction, and setStaticFlightgroup().

181 {
182  //warning mem leak...not big O(num factions)
183  static vector< Flightgroup* >fg;
184  setStaticFlightgroup( fg, "Base", faction );
185  return fg[faction];
186 }
Flightgroup* getStaticUnknownFlightgroup ( int  faction)

Definition at line 202 of file star_system_generic.cpp.

References StarSystemGent::faction, and setStaticFlightgroup().

203 {
204  static vector< Flightgroup* >fg;
205  setStaticFlightgroup( fg, "Unknown", faction );
206  return fg[faction];
207 }
Unit* getTopLevelOwner ( )

Definition at line 320 of file star_system_generic.cpp.

Referenced by Radar::CollectRadarTracks::acquire(), FireKeyboard::Execute(), UnitUtil::getPhysicsPriority(), UnitUtil::orbit(), and TargUn().

321 {
322  return (Unit*) 0x31337; //FIXME How about telling us a little story behind this function? --chuck_starchaser
323 }
double howFarToJump ( )

Definition at line 2129 of file unit_generic.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), and vs_config.

Referenced by ComputeJumpPointArrival(), GameCockpit::Draw(), and Unit::UpdatePhysics().

2130 {
2131  static float tmp = XMLSupport::parse_float( vs_config->getVariable( "physics", "distance_to_warp", "1000000000000.0" ) );
2132  return tmp;
2133 }
static bool isJumping ( const vector< unorigdest * > &  pending,
Unit un 
)
static

Definition at line 901 of file star_system_generic.cpp.

References i.

Referenced by StarSystem::JumpTo().

902 {
903  for (size_t i = 0; i < pending.size(); ++i)
904  if (pending[i]->un == un)
905  return true;
906  return false;
907 }
bool PendingJumpsEmpty ( )

Definition at line 797 of file star_system_generic.cpp.

References pendingjump.

Referenced by GameUniverse::StartDraw().

798 {
799  return pendingjump.empty();
800 }
string RemoveDotSystem ( const char *  input)

Definition at line 27 of file galaxy.cpp.

28 {
29  int sl = strlen( input );
30  if (sl == 0)
31  return string( "" );
32  char *tmp = strdup( input );
33  char *ptr = tmp+sl-1;
34  while (ptr > tmp) {
35  if (*ptr == '.') {
36  if ( 0 == strcmp( ptr, ".system" ) ) {
37  *ptr = '\0';
38 
39  char *ttmp = tmp;
40  tmp = strdup( RemoveDotSystem( tmp ).c_str() );
41  ptr = ( tmp+(ptr-ttmp) );
42  free( ttmp );
43 
44  break;
45  } else {
46  break;
47  }
48  }
49  ptr--;
50  }
51  string retval( tmp );
52  free( tmp );
53  return retval;
54 }
float ScaleJumpRadius ( float  radius)

Definition at line 64 of file star_system_generic.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), and vs_config.

Referenced by Planet::beginElement().

65 {
66  static float jump_radius_scale = parse_float( vs_config->getVariable( "physics", "jump_radius_scale", "2" ) );
67  static float game_speed = parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
68  //need this because sys scale doesn't affect j-point size
69  radius *= jump_radius_scale*game_speed;
70  return radius;
71 }
void SetShieldZero ( Unit )

Definition at line 78 of file unit_functions_generic.cpp.

References Shield::number, Unit::shield, Shield::shield2fb, Shield::shield4fbrl, and Shield::shield8.

Referenced by StarSystem::ProcessPendingJumps(), and Unit::UpdatePhysics().

79 {
80  switch (un->shield.number)
81  {
82  case 8:
83 
84  un->shield.shield8.frontlefttop =
85  un->shield.shield8.frontrighttop =
86  un->shield.shield8.backlefttop =
87  un->shield.shield8.backrighttop =
88  un->shield.shield8.frontleftbottom =
89  un->shield.shield8.frontrightbottom =
90  un->shield.shield8.backleftbottom =
91  un->shield.shield8.backrightbottom = 0;
92  break;
93  case 4:
94  un->shield.shield4fbrl.front =
95  un->shield.shield4fbrl.back =
96  un->shield.shield4fbrl.left =
97  un->shield.shield4fbrl.right = 0;
98  break;
99  case 2:
100  un->shield.shield2fb.front = un->shield.shield2fb.back = 0;
101  break;
102  }
103 }
void setStaticFlightgroup ( vector< Flightgroup * > &  fg,
const std::string &  nam,
int  faction 
)

Definition at line 151 of file star_system_generic.cpp.

References StarSystemGent::faction, and FactionUtil::GetFaction().

Referenced by getStaticAsteroidFlightgroup(), getStaticBaseFlightgroup(), getStaticNebulaFlightgroup(), getStaticStarFlightgroup(), and getStaticUnknownFlightgroup().

152 {
153  while ( faction >= (int) fg.size() ) {
154  fg.push_back( new Flightgroup() );
155  fg.back()->nr_ships = 0;
156  }
157  if (fg[faction]->nr_ships == 0) {
158  fg[faction]->flightgroup_nr = faction;
159  fg[faction]->pos.i = fg[faction]->pos.j = fg[faction]->pos.k = 0;
160  fg[faction]->nr_ships = 0;
161  fg[faction]->ainame = "default";
162  fg[faction]->faction = FactionUtil::GetFaction( faction );
163  fg[faction]->type = "Base";
164  fg[faction]->nr_waves_left = 0;
165  fg[faction]->nr_ships_left = 0;
166  fg[faction]->name = nam;
167  }
168  ++fg[faction]->nr_ships;
169  ++fg[faction]->nr_ships_left;
170 }
QVector SystemLocation ( std::string  system)

Definition at line 2135 of file unit_generic.cpp.

References _Universe, Universe::getGalaxyProperty(), and QVector.

Referenced by ComputeJumpPointArrival(), GameCockpit::Draw(), NearestSystem(), and WarpPursuit().

2136 {
2137  string xyz = _Universe->getGalaxyProperty( system, "xyz" );
2138  QVector pos;
2139  if ( xyz.size() && (sscanf( xyz.c_str(), "%lf %lf %lf", &pos.i, &pos.j, &pos.k ) >= 3) )
2140  return pos;
2141  else
2142  return QVector( 0, 0, 0 );
2143 }
void TentativeJumpTo ( StarSystem ss,
Unit un,
Unit jumppoint,
const std::string &  system 
)

Definition at line 56 of file star_system_generic.cpp.

References i, StarSystem::JumpTo(), and pendingjump.

57 {
58  for (unsigned int i = 0; i < pendingjump.size(); ++i)
59  if (pendingjump[i]->un.GetUnit() == un)
60  return;
61  ss->JumpTo( un, jumppoint, system );
62 }
void TerrainCollide ( )

Definition at line 15 of file libserver.cpp.

References Terrain::CollideAll().

Referenced by StarSystem::Update().

15 {}
void UpdateAnimatedTexture ( )

Definition at line 14 of file libserver.cpp.

References update_ani_cache(), and AnimatedTexture::UpdateAllPhysics().

Referenced by StarSystem::Update().

14 {}
void UpdateCameraSnds ( )

Variable Documentation

double aggfire = 0
unsigned int movingavgarray[128] = {0}

Definition at line 478 of file star_system_generic.cpp.

unsigned int movingtotal = 0

Definition at line 479 of file star_system_generic.cpp.

int numprocessed = 0
std::vector< unorigdest* > pendingjump

Definition at line 795 of file star_system_generic.cpp.

vector< Vector > perplines
unsigned int physicsframecounter = 1

Definition at line 475 of file star_system_generic.cpp.

Referenced by StarSystem::UpdateUnitPhysics().

Hashtable< std::string, StarSystem, 127 > star_system_table

Definition at line 773 of file star_system_generic.cpp.

double targetpick = 0
unsigned int theunitcounter = 0

Definition at line 476 of file star_system_generic.cpp.

Referenced by StarSystem::UpdateUnitPhysics().

unsigned int totalprocessed = 0

Definition at line 477 of file star_system_generic.cpp.

Referenced by StarSystem::UpdateUnitPhysics().