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
cockpit_generic.cpp File Reference
#include "in.h"
#include "vsfilesystem.h"
#include "vs_globals.h"
#include "vegastrike.h"
#include "cockpit_generic.h"
#include "universe_generic.h"
#include "star_system_generic.h"
#include "cmd/unit_generic.h"
#include "cmd/unit_factory.h"
#include "cmd/unit_util.h"
#include "cmd/collection.h"
#include "lin_time.h"
#include "configxml.h"
#include "cmd/images.h"
#include "cmd/script/mission.h"
#include "cmd/script/msgcenter.h"
#include "cmd/ai/aggressive.h"
#include <assert.h>
#include "savegame.h"
#include "universe_util.h"
#include "cmd/ai/fire.h"
#include "background.h"
#include "networking/netclient.h"
#include "save_util.h"
#include <algorithm>

Go to the source code of this file.

Macros

#define SWITCH_CONST   (0.9)
 

Functions

static float getInitialZoomFactor ()
 
static void FaceTarget (Unit *un)
 
void SwitchUnits2 (Unit *nw)
 
void SwitchUnits (Unit *ol, Unit *nw)
 
static void SwitchUnitsTurret (Unit *ol, Unit *nw)
 
UnitGetFinalTurret (Unit *baseTurret)
 
void DoCockpitKeys ()
 
static float dockingdistance (Unit *port, Unit *un)
 
void PowerDownShield (Shield *shield, float howmuch)
 
void visitSystemHelp (Cockpit *cp, string systemname, float num)
 

Variables

vector< intrespawnunit
 
vector< intswitchunit
 
vector< intturretcontrol
 
static bool too_many_attackers = false
 
static const std::string emptystring
 

Macro Definition Documentation

#define SWITCH_CONST   (0.9)

Definition at line 35 of file cockpit_generic.cpp.

Function Documentation

static float dockingdistance ( Unit port,
Unit un 
)
static

Definition at line 391 of file cockpit_generic.cpp.

References Unit::cumulative_transformation_matrix, UnitImages< BOGUS >::dockingports, UnitUtil::getDistance(), Unit::GetImageInformation(), i, InvTransform(), Magnitude(), Unit::Position(), QVector, and Unit::rSize().

Referenced by Cockpit::Update().

392 {
393  vector< DockingPorts >::const_iterator i = port->GetImageInformation().dockingports.begin();
394  vector< DockingPorts >::const_iterator end = port->GetImageInformation().dockingports.end();
396  float mag = FLT_MAX;
397  for (; i != end; ++i) {
398  float tmag = (pos.Cast()-(*i).GetPosition()).Magnitude()-un->rSize()-(*i).GetRadius();
399  if (tmag < mag)
400  mag = tmag;
401  }
402  if (mag == FLT_MAX)
403  return UnitUtil::getDistance( port, un );
404  return mag;
405 }
void DoCockpitKeys ( )

Definition at line 1730 of file cockpit.cpp.

References CockpitKeys::Inside(), CockpitKeys::Pan(), and PRESS.

Referenced by Cockpit::Update().

1731 {
1734 }
static void FaceTarget ( Unit un)
static

Definition at line 276 of file cockpit_generic.cpp.

References Unit::GetOrientation(), Unit::Position(), q, QVector, Unit::SetOrientation(), Unit::Target(), and Vector.

Referenced by AfterburnTurnTowards(), Cockpit::Autopilot(), FlyByKeyboard::Execute(), Orders::FireAt::FaceTarget(), Orders::AggressiveAI::ProcessCurrentFgDirective(), TurnTowards(), and VeerAway().

277 {
278  Unit *targ = un->Target();
279  if (targ) {
280  QVector dir( targ->Position()-un->Position() );
281  dir.Normalize();
282  Vector p, q, r;
283  un->GetOrientation( p, q, r );
284  QVector qq( q.Cast() );
285  qq = qq+QVector( .001, .001, .001 );
286  un->SetOrientation( qq, dir );
287  }
288 }
Unit* GetFinalTurret ( Unit baseTurret)

Definition at line 362 of file cockpit_generic.cpp.

References Unit::getSubUnits(), and SwitchUnits().

Referenced by Cockpit::Update().

363 {
364  Unit *un = baseTurret;
365  Unit *tur;
366  for (un_iter uj = un->getSubUnits(); (tur = *uj); ++uj) {
367  SwitchUnits( NULL, tur );
368  un = GetFinalTurret( tur );
369  }
370  return un;
371 }
static float getInitialZoomFactor ( )
static

Definition at line 175 of file cockpit_generic.cpp.

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

176 {
177  static float inizoom = XMLSupport::parse_float( vs_config->getVariable( "graphics", "inital_zoom_factor", "2.25" ) );
178  return inizoom;
179 }
void PowerDownShield ( Shield shield,
float  howmuch 
)

Definition at line 454 of file cockpit_generic.cpp.

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

Referenced by FireKeyboard::Execute(), and Cockpit::Update().

455 {
456  switch (shield->number)
457  {
458  case 2:
459  if (shield->shield2fb.front/howmuch > shield->shield2fb.frontmax)
460  shield->shield2fb.front = shield->shield2fb.frontmax*howmuch;
461  if (shield->shield2fb.back/howmuch > shield->shield2fb.backmax)
462  shield->shield2fb.back = shield->shield2fb.backmax*howmuch;
463  break;
464  case 4:
465  if (shield->shield4fbrl.front/howmuch > shield->shield4fbrl.frontmax)
466  shield->shield4fbrl.front = shield->shield4fbrl.frontmax*howmuch;
467  if (shield->shield4fbrl.right/howmuch > shield->shield4fbrl.rightmax)
468  shield->shield4fbrl.right = shield->shield4fbrl.rightmax*howmuch;
469  if (shield->shield4fbrl.left/howmuch > shield->shield4fbrl.leftmax)
470  shield->shield4fbrl.left = shield->shield4fbrl.leftmax*howmuch;
471  if (shield->shield4fbrl.back/howmuch > shield->shield4fbrl.backmax)
472  shield->shield4fbrl.back = shield->shield4fbrl.backmax*howmuch;
473  break;
474  case 8:
475  if (shield->shield8.frontlefttop/howmuch > shield->shield8.frontlefttopmax)
476  shield->shield8.frontlefttop = shield->shield8.frontlefttopmax*howmuch;
477  if (shield->shield8.frontleftbottom/howmuch > shield->shield8.frontleftbottommax)
478  shield->shield8.frontleftbottom = shield->shield8.frontleftbottommax*howmuch;
479  if (shield->shield8.frontrighttop/howmuch > shield->shield8.frontrighttopmax)
480  shield->shield8.frontrighttop = shield->shield8.frontrighttopmax*howmuch;
481  if (shield->shield8.frontrightbottom/howmuch > shield->shield8.frontrightbottommax)
482  shield->shield8.frontrightbottom = shield->shield8.frontrightbottommax*howmuch;
483  if (shield->shield8.backlefttop/howmuch > shield->shield8.backlefttopmax)
484  shield->shield8.backlefttop = shield->shield8.backlefttopmax*howmuch;
485  if (shield->shield8.backleftbottom/howmuch > shield->shield8.backleftbottommax)
486  shield->shield8.backleftbottom = shield->shield8.backleftbottommax*howmuch;
487  if (shield->shield8.backrighttop/howmuch > shield->shield8.backrighttopmax)
488  shield->shield8.backrighttop = shield->shield8.backrighttopmax*howmuch;
489  if (shield->shield8.backrightbottom/howmuch > shield->shield8.backrightbottommax)
490  shield->shield8.backrightbottom = shield->shield8.backrightbottommax*howmuch;
491  break;
492  default:
493  break;
494  }
495 }
void SwitchUnits ( Unit ol,
Unit nw 
)

Definition at line 328 of file cockpit_generic.cpp.

References _Universe, Universe::AccessCockpit(), Universe::CurrentCockpit(), Cockpit::GetParent(), Unit::getRelation(), i, Universe::numPlayers(), Unit::PrimeOrders(), Unit::SetAI(), Unit::SetVisible(), SwitchUnits2(), and Unit::Target().

Referenced by buyShip(), Unit::EjectCargo(), GetFinalTurret(), SwitchUnitsTurret(), and Cockpit::Update().

329 {
330  bool pointingtool = false;
331  bool pointingtonw = false;
332  for (unsigned int i = 0; i < _Universe->numPlayers(); ++i)
333  if ( i != _Universe->CurrentCockpit() ) {
334  if (_Universe->AccessCockpit( i )->GetParent() == ol)
335  pointingtool = true;
336  if (_Universe->AccessCockpit( i )->GetParent() == nw)
337  pointingtonw = true;
338  }
339  if ( ol && (!pointingtool) ) {
340  Unit *oltarg = ol->Target();
341  if (oltarg)
342  if (ol->getRelation( oltarg ) >= 0)
343  ol->Target( NULL );
344  ol->PrimeOrders();
345  ol->SetAI( new Orders::AggressiveAI( "default.agg.xml" ) );
346  ol->SetVisible( true );
347  }
348  SwitchUnits2( nw );
349 }
void SwitchUnits2 ( Unit nw)

Definition at line 2808 of file cockpit.cpp.

2809 {
2810  if (nw) {
2811  nw->PrimeOrders();
2814 
2815  nw->SetTurretAI();
2816  nw->DisableTurretAI();
2817 
2818  static bool LoadNewCockpit =
2819  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "UnitSwitchCockpitChange", "false" ) );
2820  static bool DisCockpit =
2821  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "SwitchCockpitToDefaultOnUnitSwitch", "false" ) );
2822  if (nw->getCockpit().length() > 0 || DisCockpit)
2823  _Universe->AccessCockpit()->Init( nw->getCockpit().c_str(), LoadNewCockpit == false );
2824  /* Here is the old code:
2825  *
2826  * if (nw->getCockpit().length()>0&&LoadNewCockpit) {
2827  * _Universe->AccessCockpit()->Init (nw->getCockpit().c_str());
2828  * }else {
2829  * if (DisCockpit) {
2830  * _Universe->AccessCockpit()->Init ("disabled-cockpit.cpt");
2831  * }
2832  * }
2833  *
2834  */
2835  }
2836 }
static void SwitchUnitsTurret ( Unit ol,
Unit nw 
)
static

Definition at line 350 of file cockpit_generic.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_bool(), Unit::PrimeOrders(), SwitchUnits(), and vs_config.

Referenced by Cockpit::Update().

351 {
352  static bool FlyStraightInTurret =
353  XMLSupport::parse_bool( vs_config->getVariable( "physics", "ai_pilot_when_in_turret", "true" ) );
354  if (FlyStraightInTurret) {
355  SwitchUnits( ol, nw );
356  } else {
357  ol->PrimeOrders();
358  SwitchUnits( NULL, nw );
359  }
360 }
void visitSystemHelp ( Cockpit cp,
string  systemname,
float  num 
)

Definition at line 831 of file cockpit_generic.cpp.

References SaveGame::getMissionData(), Cockpit::savegame, and v.

Referenced by Cockpit::visitSystem().

832 {
833  string key( string( "visited_" )+systemname );
834  vector< float > *v = &cp->savegame->getMissionData( key );
835  if ( v->empty() )
836  v->push_back( num );
837  else if ( (*v)[0] != 1.0 && num == 1 )
838  (*v)[0] = num;
839 }

Variable Documentation

const std::string emptystring
static
vector< int > respawnunit

Definition at line 37 of file cockpit_generic.cpp.

Referenced by Cockpit::Update().

vector< int > switchunit

Definition at line 38 of file cockpit_generic.cpp.

Referenced by Cockpit::Update().

bool too_many_attackers = false
static

Definition at line 406 of file cockpit_generic.cpp.

Referenced by Cockpit::tooManyAttackers(), and Cockpit::updateAttackers().

vector< int > turretcontrol

Definition at line 39 of file cockpit_generic.cpp.

Referenced by Unit::UnDock(), and Cockpit::Update().