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
basecomputer.cpp File Reference
#include "vegastrike.h"
#include "basecomputer.h"
#include "savegame.h"
#include "universe_util.h"
#include "save_util.h"
#include <algorithm>
#include <set>
#include "load_mission.h"
#include "cmd/planet_generic.h"
#include "cmd/unit_util.h"
#include "cmd/music.h"
#include "cmd/unit_const_cache.h"
#include "cmd/unit_factory.h"
#include "gui/modaldialog.h"
#include "main_loop.h"
#include "lin_time.h"
#include "gui/newbutton.h"
#include "gui/staticdisplay.h"
#include "gui/textinputdisplay.h"
#include "gui/simplepicker.h"
#include "gui/groupcontrol.h"
#include "gui/scroller.h"
#include "networking/netclient.h"
#include "unit_xml.h"
#include "gfx/sprite.h"
#include "gfx/aux_texture.h"
#include "gamemenu.h"
#include "audiolib.h"
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>

Go to the source code of this file.

Classes

struct  ModeInfo
 
class  CargoColorSort
 
class  BaseComputer::UpgradeOperation
 
class  BaseComputer::BuyUpgradeOperation
 
class  BaseComputer::SellUpgradeOperation
 
class  UpgradeOperationMountDialog
 
class  PriceSort
 

Namespaces

 CockpitKeys
 

Constant Groups

 CockpitKeys
 

Macros

#define PRETTY_ADD(str, val, digits)
 
#define PRETTY_ADDN(str, val, digits)
 
#define PRETTY_ADDU(str, val, digits, unit)
 

Typedefs

typedef int(* scancompare )(const void *v1, const void *v2)
 

Functions

static GFXColor UnsaturatedColor (float r, float g, float b, float a=1.0f)
 
std::vector< std::string > getWeapFilterVec ()
 
bool upgradeNotAddedToCargo (std::string category)
 
std::string getDisplayCategory (const Cargo &cargo)
 
static GFXColor NO_MONEY_COLOR ()
 
static GFXColor PROHIBITED_COLOR ()
 
static GFXColor DOWNGRADE_OR_NONCOMPAT_COLOR ()
 
static GFXColor NO_ROOM_COLOR ()
 
static GFXColor ITEM_DESTROYED_COLOR ()
 
static GFXColor CATEGORY_TEXT_COLOR ()
 
static GFXColor MISSION_COLOR ()
 
static GFXColor DEFAULT_UPGRADE_COLOR ()
 
static GFXColor MOUNT_POINT_NO_SELECT ()
 
static GFXColor MOUNT_POINT_EMPTY ()
 
static GFXColor MOUNT_POINT_FULL ()
 
const UnitmakeFinalBlankUpgrade (string name, int faction)
 
int GetModeFromName (const char *)
 
CargoGetMasterPartList (const char *input_buffer)
 
UnitGetUnitMasterPartList ()
 
void SwitchUnits (Unit *ol, Unit *nw)
 
void TerminateCurrentBase (void)
 
void CurrentBaseUnitSet (Unit *un)
 
string MakeUnitXMLPretty (std::string, Unit *)
 
float totalShieldEnergyCapacitance (const Shield &shield)
 
void RespawnNow (Cockpit *cockpit)
 
void showUnitStats (Unit *playerUnit, string &text, int subunitlevel, int mode, Cargo &item)
 
string buildShipDescription (Cargo &item, string &descriptiontexture)
 
string buildCargoDescription (const Cargo &item, BaseComputer &computer, float price)
 
void prettyPrintFloat (char *buffer, float f, int digitsBefore, int digitsAfter, int bufferLen=128)
 
string buildUpgradeDescription (Cargo &item)
 
int basecargoassets (Unit *base, string cargoname)
 
const GFXColor BASIC_REPAIR_TEXT_COLOR ()
 
template<typename T >
mymin (T a, T b)
 
template<typename T >
mymax (T a, T b)
 
static std::string beautify (const string &input)
 
static double usedValue (double originalValue)
 
float RepairPrice (float operational, float price)
 
static float basicRepairPrice (void)
 
static float SellPrice (float operational, float price)
 
const UnitmakeTemplateUpgrade (string name, int faction)
 
const UnitgetUnitFromUpgradeName (const string &upgradeName, int myUnitFaction=0)
 
bool isWeapon (std::string name)
 
bool UpgradeAllowed (const Cargo &item, Unit *playerUnit)
 
int SelectDockPort (Unit *utdw, Unit *parent)
 
static void eliminateZeroCargo (Unit *un)
 
static std::string GarnerInfoFromSaveGame (const string &filename)
 
static int nodirs (const struct dirent *entry)
 
static int datesort (const void *v1, const void *v2)
 
static void BasicRepair (Unit *parent)
 
static bool matchCargoToWeapon (const std::string &cargoName, const std::string &weaponName)
 
Cargo CreateCargoForOwnerStarship (const Cockpit *cockpit, const Unit *base, int i)
 
Cargo CreateCargoForOwnerStarshipName (const Cockpit *cockpit, const Unit *base, std::string name, int &index)
 
void SwapInNewShipName (Cockpit *cockpit, Unit *base, const std::string &newFileName, int swappingShipsIndex)
 
string buildShipDescription (Cargo &item, std::string &texturedescription)
 
void trackPrice (int whichplayer, const Cargo &item, float price, const string &systemName, const string &baseName, vector< string > &highest, vector< string > &lowest)
 
bool sellShip (Unit *baseUnit, Unit *playerUnit, std::string shipname, BaseComputer *bcomputer)
 
bool buyShip (Unit *baseUnit, Unit *playerUnit, std::string content, bool myfleet, bool force_base_inventory, BaseComputer *bcomputer)
 
static std::string factionColorTextString (int faction)
 
void CockpitKeys::QuitNow ()
 

Variables

const char * DamagedCategory
 
std::string emergency_downgrade_mode
 
std::string CurrentSaveGameName
 
std::vector< std::string > weapfiltervec = getWeapFilterVec()
 
vector< unsigned intbase_keyboard_queue
 
static const char CATEGORY_SEP = '/'
 
static const char CATEGORY_TAG = (-1)
 
static bool color_prohibited_upgrade_flag = false
 
static bool color_downgrade_or_noncompatible_flag = false
 
static bool color_insufficient_space_flag = false
 
static bool color_insufficient_money_flag = false
 
static const float MODE_BUTTON_SPACE = 0.03
 
static const char *const MISSION_SCRIPTS_LABEL = "mission_scripts"
 
static const char *const MISSION_NAMES_LABEL = "mission_names"
 
static const char *const MISSION_DESC_LABEL = "mission_descriptions"
 
static const char *const NEWS_NAME_LABEL = "news"
 
static const string LOAD_FAILED = "LOAD_FAILED"
 
const string BASIC_REPAIR_NAME = "Basic Repair & Refuel"
 
const string BASIC_REPAIR_DESC
 
static const ModeInfo modeInfo []
 
static const string GOT_MOUNT_ID = "GotMount"
 
static const string GOT_TURRET_ID = "GotTurret"
 
static const string CONFIRM_ID = "Confirm"
 
static const char * WeaponTypeStrings []
 

Macro Definition Documentation

#define PRETTY_ADD (   str,
  val,
  digits 
)
Value:
do { \
text += "#n#"; \
text += prefix; \
text += str; \
prettyPrintFloat( conversionBuffer, val, 0, digits ); \
text += conversionBuffer; \
} \
while (0)

Definition at line 411 of file basecomputer.cpp.

Referenced by showUnitStats(), and trackPrice().

#define PRETTY_ADDN (   str,
  val,
  digits 
)
Value:
do { \
text += str; \
prettyPrintFloat( conversionBuffer, val, 0, digits ); \
text += conversionBuffer; \
} \
while (0)

Definition at line 421 of file basecomputer.cpp.

Referenced by showUnitStats(), and BaseComputer::updateTransactionControlsForSelection().

#define PRETTY_ADDU (   str,
  val,
  digits,
  unit 
)
Value:
do { \
text += "#n#"; \
text += prefix; \
text += str; \
prettyPrintFloat( conversionBuffer, val, 0, digits ); \
text += conversionBuffer; \
text += " "; \
text += unit; \
} \
while (0)

Definition at line 429 of file basecomputer.cpp.

Referenced by showUnitStats().

Typedef Documentation

typedef int(* scancompare)(const void *v1, const void *v2)

Definition at line 3053 of file basecomputer.cpp.

Function Documentation

int basecargoassets ( Unit base,
string  cargoname 
)

Definition at line 3759 of file basecomputer.cpp.

References Unit::GetCargo(), and Cargo::quantity.

Referenced by BaseComputer::BuyUpgradeOperation::concludeTransaction().

3760 {
3761  unsigned int dummy;
3762  Cargo *somecargo = baseUnit->GetCargo( cargoname, dummy );
3763  if (somecargo)
3764  return somecargo->quantity;
3765  else
3766  return 0;
3767 }
const GFXColor BASIC_REPAIR_TEXT_COLOR ( )

Definition at line 254 of file basecomputer.cpp.

Referenced by BaseComputer::loadBuyUpgradeControls().

255 {
256  return GFXColor( 0, 1, 1 );
257 }
static void BasicRepair ( Unit parent)
static

Definition at line 3376 of file basecomputer.cpp.

References UnitUtil::addCredits(), basicRepairPrice(), UnitUtil::getCredits(), Unit::RepairCost(), Unit::RepairUpgrade(), and showAlert().

Referenced by BaseComputer::buyUpgrade().

3377 {
3378  if (parent) {
3379  int repairmultiplier = parent->RepairCost();
3380  if (UnitUtil::getCredits( parent ) < basicRepairPrice()*repairmultiplier)
3381  showAlert( "You don't have enough credits to repair your ship." );
3382  else if ( ( repairmultiplier = parent->RepairUpgrade() ) )
3383  UnitUtil::addCredits( parent, -basicRepairPrice()*repairmultiplier );
3384  else
3385  showAlert( "Your ship has no damage. No charge." );
3386  }
3387 }
static float basicRepairPrice ( void  )
static

Definition at line 391 of file basecomputer.cpp.

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

Referenced by BasicRepair(), BaseComputer::loadBuyUpgradeControls(), and BaseComputer::updateTransactionControlsForSelection().

392 {
393  static const float price = XMLSupport::parse_float( vs_config->getVariable( "physics", "repair_price", "5000" ) );
394  return price*g_game.difficulty;
395 }
static std::string beautify ( const string &  input)
static

Definition at line 361 of file basecomputer.cpp.

References i.

Referenced by BaseComputer::createCategoryCell(), BaseComputer::loadListPicker(), BaseComputer::loadMissionsMasterList(), and showUnitStats().

362 {
363  std::string result;
364 
365  bool wordStart = true;
366  for (std::string::const_iterator i = input.begin(); i != input.end(); i++) {
367  if (*i == '_') {
368  //Turn this into a space, and make sure next letter is capitalized.
369  result += ' ';
370  wordStart = true;
371  } else if (wordStart) {
372  //Start or a word. Capitalize the character, and turn off start of word.
373  result += toupper( *i );
374  wordStart = false;
375  } else {
376  //Normal character in middle of word.
377  result += *i;
378  }
379  }
380  return result;
381 }
string buildCargoDescription ( const Cargo item,
BaseComputer computer,
float  price 
)

Definition at line 4379 of file basecomputer.cpp.

References _Universe, Unit::getFullname(), UniverseUtil::getSystemName(), UnitContainer::GetUnit(), VegaConfig::getVariable(), i, Unit::isUnit(), BaseComputer::m_base, BaseComputer::m_player, Unit::name, XMLSupport::parse_bool(), PLANETPTR, trackPrice(), vs_config, and Universe::whichPlayerStarship().

Referenced by BaseComputer::updateTransactionControlsForSelection().

4380 {
4381  static bool trackBestPrices =
4382  XMLSupport::parse_bool( vs_config->getVariable( "general", "trade_interface_tracks_prices", "true" ) );
4383 
4384  string desc;
4385 
4386  if (trackBestPrices && computer.m_base.GetUnit() != NULL) {
4387  int cp = _Universe->whichPlayerStarship( computer.m_player.GetUnit() );
4388  vector<string> highest, lowest;
4389 
4390  const string &baseName = (computer.m_base.GetUnit()->isUnit() == PLANETPTR) ?
4391  computer.m_base.GetUnit()->name.get()
4392  : computer.m_base.GetUnit()->getFullname();
4393 
4394  trackPrice(cp, item, price, UniverseUtil::getSystemName(), baseName, highest, lowest );
4395 
4396  if (highest.size()) {
4397  desc += "#n##n##b#Highest prices seen#-b#:";
4398  for (vector<string>::const_iterator i=highest.begin(); i!=highest.end(); ++i)
4399  desc += *i;
4400  }
4401 
4402  if (lowest.size()) {
4403  desc += "#n##n##b#Lowest prices seen#-b#:";
4404  for (vector<string>::const_iterator i=lowest.begin(); i!=lowest.end(); ++i)
4405  desc += *i;
4406  }
4407  }
4408 
4409  return desc;
4410 }
string buildShipDescription ( Cargo item,
string &  descriptiontexture 
)
string buildShipDescription ( Cargo item,
std::string &  texturedescription 
)

Definition at line 4124 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), UnitFactory::createUnit(), current_unit_load_mode, DEFAULT, Cargo::GetCategory(), Cargo::GetContent(), Unit::getHudImage(), VSSprite::getTexture(), Cockpit::GetUnitModifications(), NO_MESH, showUnitStats(), and Texture::texfilename.

4125 {
4126  //load the Unit
4127  string newModifications;
4128  if (item.GetCategory().find( "My_Fleet" ) != string::npos)
4129  //Player owns this starship.
4130  newModifications = _Universe->AccessCockpit()->GetUnitModifications();
4131  Flightgroup *flightGroup = new Flightgroup();
4132  int fgsNumber = 0;
4134  Unit *newPart = UnitFactory::createUnit( item.GetContent().c_str(), false, 0, newModifications,
4135  flightGroup, fgsNumber );
4137  string sHudImage;
4138  string sImage;
4139  if ( newPart->getHudImage() ) {
4140  if ( newPart->getHudImage()->getTexture() ) {
4141  sHudImage = newPart->getHudImage()->getTexture()->texfilename;
4142  string::size_type delim = sHudImage.find( '|' ); //cut off alpha texture
4143  if (delim != string::npos) {
4144  sImage = sHudImage.substr( delim+1 );
4145  sHudImage = sHudImage.substr( 0, delim-sImage.length() ); //assumes RGBname == Alphaname for ships
4146  }
4147  delim = sHudImage.rfind( '.' ); //cut off mangled base directory
4148  if (delim != string::npos)
4149  sHudImage = sHudImage.substr( delim+2 );
4150  texturedescription = "../units/"+sHudImage+"/"+sImage;
4151  }
4152  }
4153  std::string str;
4154  showUnitStats( newPart, str, 0, 0, item );
4155  delete newPart;
4156  if ( texturedescription != "" && ( string::npos == str.find( '@' ) ) )
4157  str = "@"+texturedescription+"@"+str;
4158  return str;
4159 }
string buildUpgradeDescription ( Cargo item)

Definition at line 4162 of file basecomputer.cpp.

References UnitFactory::createUnit(), current_unit_load_mode, DEFAULT, Cargo::description, Cargo::GetContent(), FactionUtil::GetUpgradeFaction(), NO_MESH, and showUnitStats().

Referenced by BaseComputer::updateTransactionControlsForSelection().

4163 {
4164  //load the Unit
4165  string blnk; //modifications to an upgrade item???
4166  Flightgroup *flightGroup = new Flightgroup(); //sigh
4167  int fgsNumber = 0;
4169  Unit *newPart = UnitFactory::createUnit( item.GetContent().c_str(), false,
4170  FactionUtil::GetUpgradeFaction(), blnk, flightGroup, fgsNumber );
4172  string str = "";
4173  str += item.description;
4174  showUnitStats( newPart, str, 0, 1, item );
4175  delete newPart;
4176  return str;
4177 }
bool buyShip ( Unit baseUnit,
Unit playerUnit,
std::string  content,
bool  myfleet,
bool  force_base_inventory,
BaseComputer bcomputer 
)

Definition at line 4491 of file basecomputer.cpp.

References _Universe, Universe::AccessCockpit(), Universe::activeStarSystem(), StarSystem::AddUnit(), Subcmd::BuyShip, c, Window::close(), CreateCargoForOwnerStarshipName(), UnitFactory::createUnit(), Cockpit::credits, Unit::curr_physical_state, CurrentBaseUnitSet(), CurrentSaveGameName, Unit::faction, Unit::GetCargo(), Cargo::GetCategory(), Cargo::GetContent(), Unit::getFlightgroup(), UniverseUtil::GetMasterPartList(), Cockpit::GetNumUnits(), Cockpit::GetUnitFileName(), Cockpit::GetUnitModifications(), VegaConfig::getVariable(), i, j, k, Unit::Kill(), LOAD_FAILED, SaveGame::LoadSavedMissions(), BaseComputer::m_player, Cargo::mission, Universe::netLocked(), Network, Flightgroup::nr_ships, Flightgroup::nr_ships_left, Unit::numCargo(), XMLSupport::parse_bool(), UniverseUtil::playSound(), Transformation::position, Unit::Position(), Unit::prev_physical_state, Cargo::price, Cargo::quantity, QVector, Unit::RemoveCargo(), UniverseUtil::SafeEntrancePoint(), Cockpit::savegame, Cockpit::SetParent(), UnitContainer::SetUnit(), NetClient::shipRequest(), UniverseUtil::StopAllSounds(), SwapInNewShipName(), Subcmd::SwitchShip, SwitchUnits(), Unit::UnDock(), Vector, vs_config, WindowController::window(), and WriteSaveGame().

Referenced by BaseUtil::BuyShip().

4497 {
4498  unsigned int tempInt; //Not used.
4499  Cargo *shipCargo = baseUnit->GetCargo( content, tempInt );
4500  if (shipCargo == NULL && force_base_inventory)
4501  shipCargo = UniverseUtil::GetMasterPartList()->GetCargo( content, tempInt );
4502  Cargo myFleetShipCargo;
4503  int swappingShipsIndex = -1;
4504  if (myfleet) {
4505  //Player owns this starship.
4506  shipCargo = &myFleetShipCargo;
4507  myFleetShipCargo = CreateCargoForOwnerStarshipName( _Universe->AccessCockpit(), baseUnit, content, swappingShipsIndex );
4508  if ( shipCargo->GetContent().empty() ) {
4509  //Something happened -- can't find ship by name.
4510  shipCargo = NULL;
4511  swappingShipsIndex = -1;
4512  }
4513  } else {
4514  Cockpit *cockpit = _Universe->AccessCockpit();
4515  for (size_t i = 1, n = cockpit->GetNumUnits(); i < n; ++i)
4516  if (cockpit->GetUnitFileName(i) == content)
4517  return false;
4518  //can't buy a ship you own
4519  }
4520  if (shipCargo) {
4521  if (shipCargo->price < _Universe->AccessCockpit()->credits) {
4522  if ( Network && !_Universe->netLocked() ) {
4523  Network[0].shipRequest( content, myfleet ? Subcmd::SwitchShip : Subcmd::BuyShip );
4524  return false;
4525  }
4526  Flightgroup *flightGroup = playerUnit->getFlightgroup();
4527  int fgsNumber = 0;
4528  if (flightGroup != NULL) {
4529  fgsNumber = flightGroup->nr_ships;
4530  flightGroup->nr_ships++;
4531  flightGroup->nr_ships_left++;
4532  }
4533  string newModifications;
4534  std::string tmpnam = CurrentSaveGameName;
4535  if (swappingShipsIndex != -1) {
4536  //if we're swapping not buying load the olde one
4537  newModifications = _Universe->AccessCockpit()->GetUnitModifications();
4539  }
4540  WriteSaveGame( _Universe->AccessCockpit(), true ); //oops saved game last time at wrong place
4542  UniverseUtil::playSound( "sales/salespitch"+content.substr( 0, content.find( "." ) )+"accept.wav", QVector( 0,
4543  0,
4544  0 ),
4545  Vector( 0, 0, 0 ) );
4546  Unit *newPart =
4547  UnitFactory::createUnit( content.c_str(),
4548  false,
4549  baseUnit->faction,
4550  newModifications,
4551  flightGroup,
4552  fgsNumber );
4553  CurrentSaveGameName = tmpnam;
4554  newPart->SetFaction( playerUnit->faction );
4555  if (newPart->name != LOAD_FAILED) {
4556  if (newPart->nummesh() > 0) {
4557  _Universe->AccessCockpit()->credits -= shipCargo->price;
4558  newPart->curr_physical_state = playerUnit->curr_physical_state;
4559  newPart->SetPosAndCumPos( UniverseUtil::SafeEntrancePoint( playerUnit->Position(), newPart->rSize() ) );
4560  newPart->prev_physical_state = playerUnit->prev_physical_state;
4561  _Universe->activeStarSystem()->AddUnit( newPart );
4562  SwapInNewShipName( _Universe->AccessCockpit(), baseUnit, content, swappingShipsIndex );
4563  for (int j = 0; j < 2; ++j) {
4564  for (int i = playerUnit->numCargo()-1; i >= 0; --i) {
4565  Cargo c = playerUnit->GetCargo( i );
4566  if ( (c.mission != 0 && j == 0)
4567  || (c.mission == 0 && j == 1 && (!myfleet || Network) && c.GetCategory().find( "upgrades" ) != 0) ) {
4568  for (int k = c.quantity; k > 0; --k) {
4569  c.quantity = k;
4570  if ( newPart->CanAddCargo( c ) ) {
4571  newPart->AddCargo( c );
4572  playerUnit->RemoveCargo( i, c.quantity, true );
4573  break;
4574  }
4575  }
4576  }
4577  }
4578  }
4579  WriteSaveGame( _Universe->AccessCockpit(), true ); //oops saved game last time at wrong place
4580 
4581  _Universe->AccessCockpit()->SetParent( newPart, content.c_str(),
4583  playerUnit->curr_physical_state.position ); //absolutely NO NO NO modifications...you got this baby clean off the slate
4584 
4585  //We now put the player in space.
4586  SwitchUnits( NULL, newPart );
4587  playerUnit->UnDock( baseUnit );
4588  if (bcomputer)
4589  bcomputer->m_player.SetUnit( newPart );
4591  if (baseUnit)
4592  newPart->ForceDock( baseUnit, 0 );
4593  CurrentBaseUnitSet( newPart );
4594  if (bcomputer)
4595  bcomputer->m_player.SetUnit( newPart );
4596  static bool persistent_missions_across_ship_switch =
4597  XMLSupport::parse_bool( vs_config->getVariable( "general", "persistent_mission_across_ship_switch",
4598  "true" ) );
4599  if (persistent_missions_across_ship_switch)
4601  newPart = NULL;
4602  playerUnit->Kill();
4603  if (bcomputer)
4604  bcomputer->window()->close();
4605  return true;
4606  }
4607  }
4608  newPart->Kill();
4609  newPart = NULL;
4610  }
4611  }
4612  return false;
4613 }
static GFXColor CATEGORY_TEXT_COLOR ( )
static

Definition at line 170 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::createCategoryCell().

171 {
172  static GFXColor CTC = getConfigColor( "base_category_color", GFXColor( 0, .75, 0, 1 ) );
173  return CTC;
174 }
Cargo CreateCargoForOwnerStarship ( const Cockpit cockpit,
const Unit base,
int  i 
)

Definition at line 4042 of file basecomputer.cpp.

References _Universe, Universe::activeStarSystem(), Cargo::category, Cargo::content, StarSystem::getFileName(), Universe::getJumpPath(), Cockpit::GetUnitBaseName(), Cockpit::GetUnitFileName(), Cockpit::GetUnitSystemName(), VegaConfig::getVariable(), StarSystemGent::jumps, Cockpit::MakeBaseName(), XMLSupport::parse_float(), Cargo::price, Cargo::quantity, Cargo::volume, vs_config, and VSFileSystem::vs_dprintf().

Referenced by CreateCargoForOwnerStarshipName(), and BaseComputer::loadShipDealerControls().

4043 {
4044  Cargo cargo;
4045  cargo.quantity = 1;
4046  cargo.volume = 1;
4047  cargo.price = 0;
4048 
4049  string locationSystemName = cockpit->GetUnitSystemName(i);
4050  string locationBaseName = cockpit->GetUnitBaseName(i);
4051  string destinationSystemName = _Universe->activeStarSystem()->getFileName();
4052  string destinationBaseName = (base != NULL) ? Cockpit::MakeBaseName(base) : "";
4053 
4054  bool needsJumpTransport = (locationSystemName != destinationSystemName);
4055  bool needsInsysTransport = (locationBaseName != destinationBaseName);
4056 
4057  static const float shipping_price_base =
4058  XMLSupport::parse_float( vs_config->getVariable( "physics", "shipping_price_base", "0" ) );
4059  static const float shipping_price_insys =
4060  XMLSupport::parse_float( vs_config->getVariable( "physics", "shipping_price_insys", "1000" ) );
4061  static const float shipping_price_perjump =
4062  XMLSupport::parse_float( vs_config->getVariable( "physics", "shipping_price_perjump", "25000" ) );
4063 
4064  cargo.price = shipping_price_base;
4065  cargo.content = cockpit->GetUnitFileName(i);
4066  cargo.category = "starships/My_Fleet";
4067 
4068  if (needsJumpTransport) {
4069  vector< string > jumps;
4071  locationSystemName,
4072  destinationSystemName,
4073  jumps);
4074  VSFileSystem::vs_dprintf(3, "Player ship needs transport from %s to %s across %d systems",
4075  locationBaseName.c_str(),
4076  destinationSystemName.c_str(),
4077  jumps.size());
4078  cargo.price += shipping_price_perjump * (jumps.size() - 1);
4079  } else if (needsInsysTransport) {
4080  VSFileSystem::vs_dprintf(3, "Player ship needs insys transport from %s to %s",
4081  locationBaseName.c_str(),
4082  destinationBaseName.c_str());
4083  cargo.price += shipping_price_insys;
4084  }
4085 
4086  return cargo;
4087 }
Cargo CreateCargoForOwnerStarshipName ( const Cockpit cockpit,
const Unit base,
std::string  name,
int index 
)

Definition at line 4090 of file basecomputer.cpp.

References CreateCargoForOwnerStarship(), Cockpit::GetNumUnits(), Cockpit::GetUnitFileName(), and i.

Referenced by buyShip().

4091 {
4092  for (size_t i = 1, n = cockpit->GetNumUnits(); i < n; ++i) {
4093  if (cockpit->GetUnitFileName(i) == name) {
4094  index = i;
4095  return CreateCargoForOwnerStarship( cockpit, base, i );
4096  }
4097  }
4098  //Didn't find it.
4099  return Cargo();
4100 }
void CurrentBaseUnitSet ( Unit un)

Definition at line 1159 of file base_interface.cpp.

References BaseInterface::caller, BaseInterface::CurrentBase, and UnitContainer::SetUnit().

Referenced by buyShip().

1160 {
1163 }
static int datesort ( const void *  v1,
const void *  v2 
)
static

Definition at line 3036 of file basecomputer.cpp.

References VSFileSystem::homedir.

Referenced by BaseComputer::loadLoadSaveControls().

3037 {
3038  const struct dirent *d1 = *(const struct dirent**) v1;
3039  const struct dirent *d2 = *(const struct dirent**) v2;
3040  struct stat s1, s2;
3041  std::string tmp = VSFileSystem::homedir+"/save/"+d1->d_name;
3042  if ( stat( tmp.c_str(), &s1 ) )
3043  return 0;
3044  tmp = VSFileSystem::homedir+"/save/"+d2->d_name;
3045  if ( stat( tmp.c_str(), &s2 ) )
3046  return 0;
3047  return s1.st_mtime-s2.st_mtime;
3048 }
static GFXColor DEFAULT_UPGRADE_COLOR ( )
static

Definition at line 184 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadBuyUpgradeControls(), BaseComputer::loadMissionsMasterList(), and BaseComputer::loadSellUpgradeControls().

185 {
186  static GFXColor DuC = getConfigColor( "base_upgrade_color", GFXColor( 1, 1, 1, 1 ) );
187  return DuC;
188 }
static GFXColor DOWNGRADE_OR_NONCOMPAT_COLOR ( )
static

Definition at line 151 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

152 {
153  static GFXColor DNC = getConfigColor( "downgrade_or_noncompatible", GFXColor( .75, .5, .5, 1 ) );
154  return DNC;
155 }
static void eliminateZeroCargo ( Unit un)
static

Definition at line 2795 of file basecomputer.cpp.

References Unit::GetCargo(), i, Unit::numCargo(), Cargo::quantity, and Unit::RemoveCargo().

Referenced by BaseComputer::buySelectedCargo(), BaseComputer::draw(), BaseComputer::refresh(), and BaseComputer::sellSelectedCargo().

2796 {
2797  for (int i = un->numCargo()-1; i >= 0; --i)
2798  if (un->GetCargo( i ).quantity == 0)
2799  un->RemoveCargo( i, 1, true );
2800 }
static std::string factionColorTextString ( int  faction)
static

Definition at line 4660 of file basecomputer.cpp.

References colorsToCommandString(), and FactionUtil::GetSparkColor().

Referenced by BaseComputer::showPlayerInfo().

4661 {
4662  //The following gets the spark (faction) color.
4663  const float *spark = FactionUtil::GetSparkColor( faction );
4664 
4665  //This line puts the faction colors on the std out.
4666  //printf("%2d. r=%g g=%g b=%g\n", faction, spark[0], spark[1], spark[2]);
4667 
4668  //Brighten up the raw colors by multiplying each channel by 2/3, then adding back 1/3.
4669  //The darker colors are too hard to read.
4670  std::string result = colorsToCommandString( spark[0]/1.5+1.0/3, spark[1]/1.5+1.0/3, spark[2]/1.5+1.0/3 );
4671 
4672  return result;
4673 }
static std::string GarnerInfoFromSaveGame ( const string &  filename)
static

Definition at line 2951 of file basecomputer.cpp.

References UniverseUtil::getSaveInfo().

Referenced by BaseComputer::loadSavePickerChangedSelection().

2952 {
2953  return UniverseUtil::getSaveInfo( filename, true );
2954 }
std::string getDisplayCategory ( const Cargo cargo)

Definition at line 115 of file basecomputer.cpp.

References Cargo::category, and Cargo::GetDescription().

Referenced by BaseComputer::loadListPicker(), and BaseComputer::scrollToItem().

116 {
117  std::string::size_type where = cargo.GetDescription().find( "<" );
118  if (where != string::npos) {
119  std::string category = cargo.GetDescription().substr( where+1 );
120  where = category.find( ">" );
121  return category.substr( 0, where );
122  }
123  return cargo.category;
124 }
Cargo* GetMasterPartList ( const char *  input_buffer)

Definition at line 8519 of file unit_generic.cpp.

Referenced by Beam::Collide(), showUnitStats(), and BaseComputer::SellUpgradeOperation::start().

8520 {
8521  unsigned int i;
8523 }
int GetModeFromName ( const char *  )

Definition at line 87 of file unit_xml.cpp.

Referenced by Unit::FilterDowngradeList(), showUnitStats(), BaseComputer::BuyUpgradeOperation::start(), Unit::Upgrade(), and UpgradeUnit().

88 {
89  if (strlen( input_buffer ) > 3) {
90  if (input_buffer[0] == 'a'
91  && input_buffer[1] == 'd'
92  && input_buffer[2] == 'd')
93  return 1;
94  if (input_buffer[0] == 'm'
95  && input_buffer[1] == 'u'
96  && input_buffer[2] == 'l')
97  return 2;
98  }
99  return 0;
100 }
const Unit* getUnitFromUpgradeName ( const string &  upgradeName,
int  myUnitFaction = 0 
)

Definition at line 37 of file unit_functions_generic.cpp.

Referenced by BaseComputer::UpgradeOperation::endInit(), UnitUtil::PercentOperational(), Unit::Repair(), and Unit::RepairUpgradeCargo().

38 {
39  const char *name = upgradeName.c_str();
41  if (!partUnit) {
45  }
46  if (partUnit->name == "LOAD_FAILED") {
47  partUnit = UnitConstCache::getCachedConst( StringIntKey( name, myUnitFaction ) );
48  if (!partUnit)
49  partUnit = UnitConstCache::setCachedConst( StringIntKey( name, myUnitFaction ),
50  UnitFactory::createUnit( name, true, myUnitFaction ) );
51  }
52  return partUnit;
53 }
Unit& GetUnitMasterPartList ( )
std::vector< std::string > getWeapFilterVec ( )

Definition at line 95 of file basecomputer.cpp.

References weapfiltervec.

96 {
97  std::vector< std::string >weapfiltervec;
99  weapfiltervec.push_back( "upgrades/Weapon" );
100  weapfiltervec.push_back( "SubUnits" );
101  weapfiltervec.push_back( "upgrades/Ammunition" );
102  return weapfiltervec;
103 }
bool isWeapon ( std::string  name)

Definition at line 8815 of file unit_generic.cpp.

Referenced by BaseComputer::buyUpgrade(), BaseComputer::configureUpgradeCommitControls(), UnitUtil::PercentOperational(), Unit::RepairUpgradeCargo(), and BaseComputer::sellUpgrade().

8816 {
8817  if (name.find( "Weapon" ) != std::string::npos)
8818  return true;
8819  if (name.find( "SubUnit" ) != std::string::npos)
8820  return true;
8821  if (name.find( "Ammunition" ) != std::string::npos)
8822  return true;
8823  return false;
8824 }
static GFXColor ITEM_DESTROYED_COLOR ( )
static

Definition at line 163 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

164 {
165  static GFXColor IDC = getConfigColor( "upgrade_item_destroyed", GFXColor( 0.2, 0.2, 0.2, 1 ) );
166  return IDC;
167 }
const Unit* makeFinalBlankUpgrade ( string  name,
int  faction 
)

Definition at line 4906 of file unit_generic.cpp.

References ClassCache< Typ, Key >::getCachedConst(), GetUnitDir(), LOAD_FAILED, makeBlankUpgrade(), Unit::name, and ClassCache< Typ, Key >::setCachedConst().

Referenced by Unit::ReduceToTemplate(), Unit::RepairUpgrade(), and BaseComputer::SellUpgradeOperation::start().

4907 {
4908  char *unitdir = GetUnitDir( name.c_str() );
4909  string limiternam = name;
4910  if (unitdir != name)
4911  limiternam = string( unitdir )+string( ".blank" );
4912  free( unitdir );
4913  const Unit *lim = UnitConstCache::getCachedConst( StringIntKey( limiternam, faction ) );
4914  if (!lim)
4915  lim = UnitConstCache::setCachedConst( StringIntKey( limiternam, faction ), makeBlankUpgrade( limiternam, faction ) );
4916  if (lim->name == LOAD_FAILED)
4917  lim = NULL;
4918  return lim;
4919 }
const Unit* makeTemplateUpgrade ( string  name,
int  faction 
)

Definition at line 4921 of file unit_generic.cpp.

Referenced by UnitUtil::PercentOperational(), Unit::Repair(), Unit::RepairUpgrade(), Unit::RepairUpgradeCargo(), and BaseComputer::BuyUpgradeOperation::start().

4922 {
4923  char *unitdir = GetUnitDir( name.c_str() );
4924  string limiternam = string( unitdir )+string( ".template" );
4925  free( unitdir );
4926  const Unit *lim = UnitConstCache::getCachedConst( StringIntKey( limiternam, faction ) );
4927  if (!lim) {
4928  lim =
4930  faction ), UnitFactory::createUnit( limiternam.c_str(), true, faction ) );
4931  }
4932  if (lim->name == LOAD_FAILED)
4933  lim = NULL;
4934  return lim;
4935 }
string MakeUnitXMLPretty ( std::string  ,
Unit  
)
static bool matchCargoToWeapon ( const std::string &  cargoName,
const std::string &  weaponName 
)
static

Definition at line 3798 of file basecomputer.cpp.

References c, i, and strtoupper().

Referenced by BaseComputer::SellUpgradeOperation::selectMount().

3799 {
3800  //Weapon names have capitalized words, and no spaces between the words.
3801  //Cargo names are lower-case, and have underscores between words.
3802  //Also, anything in the Ammo category ends with "_ammo" in cargo, and not in weapon.
3803  //We try to make a cargo name look like a weapon name, then match them.
3804 
3805  std::string convertedCargoName;
3806 
3807  //Take off "_ammo" if it's there.
3808  int end = cargoName.size();
3809  const string::size_type ammoOffset = cargoName.rfind( "_ammo" );
3810  if (ammoOffset != std::string::npos)
3811  end = ammoOffset;
3812  bool wordStart = true; //Start of word.
3813  for (int i = 0; i < end; i++) {
3814  const char c = cargoName[i];
3815  if (c == '_') {
3816  //Skip this, and make sure next letter is capitalized.
3817  wordStart = true;
3818  } else if (wordStart) {
3819  //Start or a word. Capitalize the character, and turn off start of word.
3820  convertedCargoName += toupper( c );
3821  wordStart = false;
3822  } else {
3823  //Normal character in middle of word.
3824  convertedCargoName += c;
3825  }
3826  }
3827  return strtoupper( convertedCargoName ) == strtoupper( weaponName );
3828 }
static GFXColor MISSION_COLOR ( )
static

Definition at line 175 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

176 {
177  static GFXColor MiC = getConfigColor( "base_mission_color", GFXColor( .66, .2, 0, 1 ) );
178  return MiC;
179 }
static GFXColor MOUNT_POINT_EMPTY ( )
static

Definition at line 198 of file basecomputer.cpp.

Referenced by BaseComputer::BuyUpgradeOperation::selectMount().

199 {
200  return GFXColor( .2, 1, .2 );
201 }
static GFXColor MOUNT_POINT_FULL ( )
static

Definition at line 204 of file basecomputer.cpp.

Referenced by BaseComputer::BuyUpgradeOperation::selectMount(), and BaseComputer::SellUpgradeOperation::selectMount().

205 {
206  return GFXColor( 1, 1, 0 );
207 }
static GFXColor MOUNT_POINT_NO_SELECT ( )
static

Definition at line 192 of file basecomputer.cpp.

Referenced by BaseComputer::BuyUpgradeOperation::selectMount(), and BaseComputer::SellUpgradeOperation::selectMount().

193 {
194  return GFXColor( 1, .7, .7 );
195 }
template<typename T >
T mymax ( a,
b 
)
inline

Definition at line 355 of file basecomputer.cpp.

References b.

356 {
357  return (a>b) ? a : b;
358 }
template<typename T >
T mymin ( a,
b 
)
inline

Definition at line 350 of file basecomputer.cpp.

References b.

351 {
352  return (a<b) ? a : b;
353 }
static GFXColor NO_MONEY_COLOR ( )
static

Definition at line 138 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

139 {
140  static GFXColor NMC = getConfigColor( "no_money", GFXColor( 1, 1, .3, 1 ) );
141  return NMC; //Start out with bogus color.
142 }
static GFXColor NO_ROOM_COLOR ( )
static

Definition at line 157 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

158 {
159  static GFXColor NRFU = getConfigColor( "no_room_for_upgrade", GFXColor( 1, 0, 1, 1 ) );
160  return NRFU;
161 }
static int nodirs ( const struct dirent *  entry)
static

Definition at line 3018 of file basecomputer.cpp.

References VSFileSystem::homedir.

Referenced by BaseComputer::loadLoadSaveControls().

3020 {
3021 #if defined (_WIN32) || defined(__HAIKU__)
3022  //Have to check if we have the full path or just relative (which would be a problem)
3023  std::string tmp = VSFileSystem::homedir+"/save/"+entry->d_name;
3024  struct stat s;
3025  if (stat( tmp.c_str(), &s ) < 0)
3026  return string( entry->d_name ) != "." && string( entry->d_name ) != "..";
3027  if ( (s.st_mode&S_IFDIR) == 0 && string( entry->d_name ) != "." && string( entry->d_name ) != ".." )
3028  return 1;
3029 #else
3030  if (entry->d_type != DT_DIR && string( entry->d_name ) != "." && string( entry->d_name ) != "..")
3031  return 1;
3032 #endif
3033  return 0;
3034 }
void prettyPrintFloat ( char *  buffer,
float  f,
int  digitsBefore,
int  digitsAfter,
int  bufferLen = 128 
)

Definition at line 4750 of file basecomputer.cpp.

References FINITE, float, i, int, and ISNAN.

Referenced by showUnitStats().

4751 {
4752  int bufferPos = 0;
4753  if ( !FINITE( f ) || ISNAN( f ) ) {
4754  buffer[0] = 'n';
4755  buffer[1] = '/';
4756  buffer[2] = 'a';
4757  buffer[3] = '\0';
4758  return;
4759  }
4760  if (f < 0) {
4761  buffer[0] = '-';
4762  bufferPos = 1;
4763  f = (-f);
4764  }
4765  float temp = f;
4766  int before = 0;
4767  while (temp >= 1.0f) {
4768  before++;
4769  temp /= 10.0f;
4770  }
4771  while (bufferPos < (bufferLen-4-digitsAfter) && before < digitsBefore) {
4772  buffer[bufferPos++] = '0';
4773  digitsBefore--;
4774  }
4775  if (before) {
4776  for (int p = before; bufferPos < (bufferLen-4-digitsAfter) && p > 0; p--) {
4777  temp = f;
4778  float substractor = 1;
4779  for (int i = 0; i < p-1; i++) {
4780  temp /= 10.0f;
4781  substractor *= 10.0;
4782  } //whe cant't cast to int before in case of overflow
4783  int digit = ( (int) temp )%10;
4784  buffer[bufferPos++] = '0'+digit;
4785  //reason for the folowing line: otherwise the "((int)temp)%10" may overflow when converting
4786  f = f-( (float) digit*substractor );
4787  if ( (p != 1) && (p%3 == 1) ) buffer[bufferPos++] = ' '; // thousand separator
4788  }
4789  } else {
4790  buffer[bufferPos++] = '0';
4791  }
4792  if (digitsAfter == 0) {
4793  buffer[bufferPos] = 0;
4794  return;
4795  }
4796 
4797  if (bufferPos < bufferLen)
4798  buffer[bufferPos++] = '.';
4799 
4800  temp = f;
4801  for (int i = 0; bufferPos < (bufferLen-1) && i < digitsAfter; i++) {
4802  temp *= 10;
4803  buffer[bufferPos++] = '0'+( ( (int) temp )%10 );
4804  }
4805  if (bufferPos < bufferLen)
4806  buffer[bufferPos] = 0;
4807  //printf("******************* %f is, I think %s\n",dbgval,buffer);
4808 }
static GFXColor PROHIBITED_COLOR ( )
static

Definition at line 145 of file basecomputer.cpp.

References getConfigColor().

Referenced by BaseComputer::loadListPicker().

146 {
147  static GFXColor PU = getConfigColor( "prohibited_upgrade", GFXColor( 1, .1, 0, 1 ) );
148  return PU;
149 }
float RepairPrice ( float  operational,
float  price 
)

Definition at line 7684 of file unit_generic.cpp.

References game_data_t::difficulty, and g_game.

Referenced by BaseComputer::configureUpgradeCommitControls(), Unit::RepairUpgradeCargo(), SellPrice(), and BaseComputer::updateTransactionControlsForSelection().

7685 {
7686  return .5*price*(1-operational)*g_game.difficulty;
7687 }
void RespawnNow ( Cockpit cockpit)

Definition at line 1799 of file cockpit.cpp.

Referenced by BaseComputer::actionConfirmedLoadGame(), and UniverseUtil::loadGame().

1800 {
1801  while ( respawnunit.size() <= _Universe->numPlayers() )
1802  respawnunit.push_back( 0 );
1803  for (unsigned int i = 0; i < _Universe->numPlayers(); i++)
1804  if (_Universe->AccessCockpit( i ) == cp)
1805  respawnunit[i] = 2;
1806 }
int SelectDockPort ( Unit utdw,
Unit parent 
)

Definition at line 110 of file docking.cpp.

111 {
112  const vector< DockingPorts >& dp = utdw->DockingPortLocations();
113  float dist = FLT_MAX;
114  int num = -1;
115  for (unsigned int i = 0; i < dp.size(); ++i)
116  if (!dp[i].IsOccupied()) {
117  Vector rez = Transform( utdw->GetTransformation(), dp[i].GetPosition() );
118  float wdist = ( rez - parent->Position() ).MagnitudeSquared();
119  if (wdist < dist) {
120  num = i;
121  dist = wdist;
122  }
123  }
124  return num;
125 }
static float SellPrice ( float  operational,
float  price 
)
static

Definition at line 397 of file basecomputer.cpp.

References RepairPrice(), and usedValue().

Referenced by BaseComputer::updateTransactionControlsForSelection().

398 {
399  return usedValue( price )-RepairPrice( operational, price );
400 }
bool sellShip ( Unit baseUnit,
Unit playerUnit,
std::string  shipname,
BaseComputer bcomputer 
)

Definition at line 4443 of file basecomputer.cpp.

References _Universe, Universe::activeStarSystem(), Cockpit::credits, Unit::GetCargo(), StarSystem::getFileName(), UniverseUtil::GetMasterPartList(), Cockpit::GetNumUnits(), Cockpit::GetUnitFileName(), Cockpit::GetUnitSystemName(), VegaConfig::getVariable(), i, Universe::isPlayerStarship(), BaseComputer::loadShipDealerControls(), Universe::netLocked(), Network, XMLSupport::parse_float(), Cargo::price, Cockpit::RemoveUnit(), Subcmd::SellShip, NetClient::shipRequest(), BaseComputer::updateTransactionControlsForSelection(), and vs_config.

Referenced by BaseComputer::sellShip(), and BaseUtil::SellShip().

4444 {
4445  Cockpit *cockpit = _Universe->isPlayerStarship( playerUnit );
4446  unsigned int tempInt = 1;
4447  Cargo *shipCargo = baseUnit->GetCargo( shipname, tempInt );
4448  if (shipCargo == NULL)
4449  shipCargo = UniverseUtil::GetMasterPartList()->GetCargo( shipname, tempInt );
4450  if (shipCargo) {
4451  //now we can actually do the selling
4452  for (size_t i = 1, n = cockpit->GetNumUnits(); i < n; ++i)
4453  if (cockpit->GetUnitFileName(i) == shipname) {
4454  if ( Network && !_Universe->netLocked() ) {
4455  Network[0].shipRequest( shipname, Subcmd::SellShip );
4456  return false;
4457  }
4458  float xtra = 0;
4459  if ( cockpit->GetUnitSystemName(i) == _Universe->activeStarSystem()->getFileName() ) {
4460  static const float shipping_price =
4461  XMLSupport::parse_float( vs_config->getVariable( "physics", "sellback_shipping_price", "6000" ) );
4462  xtra += shipping_price;
4463  }
4464  cockpit->RemoveUnit(i);
4465  static float shipSellback =
4466  XMLSupport::parse_float( vs_config->getVariable( "economics", "ship_sellback_price", ".5" ) );
4467  cockpit->credits += shipSellback*shipCargo->price; //sellback cost
4468  cockpit->credits -= xtra; //transportation cost
4469  break;
4470  }
4471  if (bcomputer) {
4472  bcomputer->loadShipDealerControls();
4473  bcomputer->updateTransactionControlsForSelection( NULL );
4474  }
4475  return true;
4476  }
4477  return false;
4478 }
void showUnitStats ( Unit playerUnit,
string &  text,
int  subunitlevel,
int  mode,
Cargo item 
)

Definition at line 4818 of file basecomputer.cpp.

References UniverseUtil::acos(), Unit::Limits::afterburn, Unit::armor, Armor::backleftbottom, Armor::backlefttop, Armor::backrightbottom, Armor::backrighttop, weapon_info::BALL, BASIC_REPAIR_NAME, weapon_info::BEAM, beautify(), weapon_info::BOLT, UnitImages< BOGUS >::cloakenergy, Unit::cloaking, Cargo::content, UnitFactory::createUnit(), weapon_info::Damage, Unit::UnitJump::damage, Unit::UnitJump::delay, Unit::UnitJump::drive, Unit::UnitJump::energy, weapon_info::EnergyRate, Unit::EnergyRechargeData(), Unit::Limits::forward, Armor::frontleftbottom, Armor::frontlefttop, Armor::frontrightbottom, Armor::frontrighttop, Unit::FuelData(), Cargo::GetContent(), Cargo::GetDescription(), Unit::getEmptyCargoVolume(), Unit::getEmptyUpgradeVolume(), FactionUtil::GetFactionIndex(), Unit::getFullname(), Unit::GetHull(), Unit::GetHullPercent(), Unit::GetJumpStatus(), Unit::GetMass(), GetMasterPartList(), GetModeFromName(), Unit::GetMoment(), Unit::GetNumMounts(), Unit::getSubUnits(), VegaConfig::getVariable(), Unit::GetWarpEnergy(), i, index, Unit::UnitJump::insysenergy, Unit::Computer::itts, Unit::Limits::lateral, Unit::limits, Unit::Computer::RADARLIM::lockcone, weapon_info::LockTime, weapon_info::Longrange, lookupMountSize(), Cargo::mass, Unit::Computer::max_ab_speed(), Unit::Computer::max_pitch_up, Unit::Computer::max_roll_right, Unit::Computer::max_speed(), Unit::Computer::max_yaw_right, Unit::Computer::RADARLIM::maxcone, Unit::MaxEnergyData(), Unit::Computer::RADARLIM::maxrange, GFXMatrices::model, Unit::mounts, Unit::name, Shield::number, XMLSupport::parse_bool(), XMLSupport::parse_float(), weapon_info::PhaseDamage, PI, Unit::pImage, Unit::Limits::pitch, PRETTY_ADD, PRETTY_ADDN, PRETTY_ADDU, prettyPrintFloat(), weapon_info::PROJECTILE, Unit::Computer::radar, weapon_info::Range, Shield::recharge, weapon_info::Refire(), Unit::Limits::retro, Unit::Limits::roll, Unit::shield, Shield::shield2fb, Shield::shield4fbrl, Shield::shield8, weapon_info::size, weapon_info::Speed, weapon_info::Stability, totalShieldEnergyCapacitance(), Unit::Computer::RADARLIM::trackingcone, weapon_info::type, Unit::Computer::RADARLIM::UseFriendFoe(), Unit::Computer::RADARLIM::UseThreatAssessment(), Unit::Limits::vertical, Unit::ViewComputerData(), Cargo::volume, vs_config, Unit::WarpCapData(), weapon_info::weapon_name, and Unit::Limits::yaw.

Referenced by buildShipDescription(), buildUpgradeDescription(), and BaseComputer::showShipStats().

4819 {
4820  static Unit *blankUnit = UnitFactory::createUnit( "upgrading_dummy_unit", 1, FactionUtil::GetFactionIndex( "upgrades" ) );
4821  static float warpenratio = XMLSupport::parse_float( vs_config->getVariable( "physics", "warp_energy_multiplier", "0.12" ) );
4822  static float warpbleed = XMLSupport::parse_float( vs_config->getVariable( "physics", "warpbleed", "20" ) );
4823  static float shield_maintenance_cost =
4824  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_maintenance_charge", ".25" ) );
4825  static bool shields_require_power =
4826  XMLSupport::parse_bool( vs_config->getVariable( "physics", "shields_require_passive_recharge_maintenance", "true" ) );
4827  static float shieldenergycap =
4828  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_capacitance", ".2" ) );
4829 
4830  float Wconv = warpenratio == 0.0 ? 0.0 : (1.0/warpenratio); //converts from reactor to warp energy scales
4831  char conversionBuffer[128];
4832  string prefix = "";
4833  for (int i = 0; i < subunitlevel; i++)
4834  prefix += " ";
4835  //get conversion factor for damage -> MJ; note that shield and reactor stats use a different constant.
4836  static float kj_per_unit_damage =
4837  XMLSupport::parse_float( vs_config->getVariable( "physics", "kilojoules_per_unit_damage", "5400" ) );
4838  float VSDM = kj_per_unit_damage/1000.0;
4839  float RSconverter = 100; //100MJ per reactor or shield recharge energy unit
4840  float totalWeaponEnergyUsage = 0;
4841  float totalWeaponDamage = 0;
4842  string MPLdesc = "";
4843  string statcolor = "#c.75:.9:1#";
4844  string substatcolor = "#c.675:.925:.825#";
4845  string expstatcolor = "#c.6:.7:.8#";
4846  string nametemp = "";
4847  string model = "";
4848  size_t nameindex = 0;
4849  int replacement_mode = -1;
4850  if (mode) {
4851  replacement_mode = GetModeFromName( item.GetContent().c_str() );
4852  MPLdesc += text;
4853  text = "";
4854  string nametemp = "";
4855  string model = "";
4856  if (item.content == BASIC_REPAIR_NAME) {
4857  text += MPLdesc;
4858  return;
4859  }
4860  nametemp = playerUnit->getFullname();
4861  if (nametemp == "") {
4862  const std::string &name = playerUnit->name.get();
4863  for (nameindex = 0; ( nameindex < name.size() ) && name[nameindex] != '.'; ++nameindex)
4864  nametemp += name[nameindex];
4865  }
4866  if ( nametemp.length() )
4867  nametemp[0] = toupper( nametemp[0] );
4868  nametemp = beautify( nametemp );
4869  text += statcolor+"Selected Part: #-c"+nametemp;
4870  if (item.mass == 1)
4871  PRETTY_ADDU( statcolor+"Mass: #-c", item.mass, 0, "metric ton." );
4872  else
4873  PRETTY_ADDU( statcolor+"Mass: #-c", item.mass, 1, "metric tons." );
4874  if (item.volume == 1) {
4875  PRETTY_ADDN( statcolor+" Space required: #-c", item.volume, 0 );
4876  text += " cubic meter.#n##n##c0:1:.5#"+prefix+"[DESCRIPTION]#n##-c";
4877  } else {
4878  PRETTY_ADDN( statcolor+" Space required: #-c", item.volume, 1 );
4879  text += " cubic meters.#n##n##c0:1:.5#"+prefix+"[DESCRIPTION]#n##-c";
4880  }
4881  text += MPLdesc;
4882  text += "#n#";
4883  text += "#n##c0:1:.5#[STATS]#n##-c";
4884  }
4885  if (!mode) {
4886  const std::string &name = playerUnit->name;
4887  for (nameindex = 0; ( nameindex < name.size() ) && name[nameindex] != '.'; nameindex++) {
4888  }
4889  nametemp = playerUnit->getFullname();
4890  if ( nametemp.length() )
4891  nametemp[0] = toupper( nametemp[0] );
4892  for (nameindex = nameindex+1; nameindex < name.size(); nameindex++)
4893  model += name[nameindex];
4894  if (model == "blank")
4895  model = "TEMPLATE--WARNING--BUG";
4896  else if (model == "")
4897  model = "Military Issue (equipped)";
4898  else if (model == "rg")
4899  model = "Regional Guard Issue (equipped)";
4900  else if (model == "milspec")
4901  model = "Military Spec.";
4902  else if (model == "rgspec")
4903  model = "Regional Guard Spec.";
4904  else if (model == "stock")
4905  model = "Stock";
4906  else if (model == "begin")
4907  model = "Stock(Refurbished)";
4908  else
4909  model = "Military Spec. Variant ("+model+")";
4910  Cargo *fullname = GetMasterPartList( playerUnit->name.get().c_str() );
4911  Cargo *milname = GetMasterPartList( nametemp.c_str() );
4912  Cargo *blankname = GetMasterPartList( (nametemp+".blank").c_str() );
4913  if ( !subunitlevel && (fullname || milname || blankname) ) {
4914  text += "#c0:1:.5#"+prefix+"[NOTES]#n##n##-c";
4915  if (fullname)
4916  text += fullname->GetDescription();
4917  else if (blankname)
4918  text += blankname->GetDescription();
4919  else if (milname)
4920  text += milname->GetDescription();
4921  text += "#n#";
4922  }
4923  text += "#n##c0:1:.5#"+prefix+"[GENERAL INFORMATION]#n##-c";
4924 
4925  text += "#n#"+prefix+statcolor+"Class: #-c"+nametemp+statcolor+" Model: #-c"+model;
4926  PRETTY_ADDU( statcolor+"Mass: #-c", playerUnit->GetMass(), 0, "metric tons" );
4927  //Irrelevant to player as is proportional to mass in our physics system.
4928  //PRETTY_ADDU("Moment of inertia: ",playerUnit->GetMoment(),2,"tons.m�");
4929  }
4930  if ( mode && replacement_mode == 2 && playerUnit->GetMass() != blankUnit->GetMass() )
4931  PRETTY_ADDU( statcolor+"Effective Mass reduced by: #-c", 100.0*( 1.0-playerUnit->GetMass() ), 0, "%" );
4932  if (!subunitlevel) {
4933  float vol[2];
4934  float bvol[2];
4935  const char *dvol[2] = {"Hold", "Upgrade"};
4936  vol[0] = playerUnit->getEmptyCargoVolume();
4937  vol[1] = playerUnit->getEmptyUpgradeVolume();
4938  bvol[0] = blankUnit->getEmptyCargoVolume();
4939  bvol[1] = blankUnit->getEmptyUpgradeVolume();
4940  for (int index = 0; index < 2; ++index) {
4941  if (!mode) {
4942  PRETTY_ADDU( statcolor+dvol[index]+" volume: #-c", vol[index], 0, "cubic meters" );
4943  } else if (bvol[index] != vol[index]) {
4944  switch (replacement_mode)
4945  {
4946  case 0: //Replacement or new Module
4947  PRETTY_ADDU( statcolor+"Changes "+dvol[index]+" Volume to: #-c", vol[index], 0, "cubic meters" );
4948  break;
4949  case 1: //Additive
4950  PRETTY_ADDU( statcolor+"Adds #-c", vol[index], 0, "cubic meters "+statcolor+"to "+dvol[index]+" Volume #-c" );
4951  break;
4952  case 2: //multiplicative
4953  PRETTY_ADDU( statcolor+"Increases "+dvol[index]+" Volume by #-c", 100.0*(vol[index]-1), 0, "%" );
4954  break;
4955  default: //Failure
4956  text += "Oh dear, this wasn't an upgrade. Please debug code.";
4957  break;
4958  }
4959  }
4960  }
4961  }
4962  //following lines somewhat borken in terms of semantics for quantity of fuel
4963  //and policy of upgrades to fuel
4964  if (!mode) {
4965  PRETTY_ADDU( statcolor+"Fuel capacity: #-c", playerUnit->FuelData(), 2, "metric tons of Lithium-6" );
4966  } else if ( blankUnit->FuelData() != playerUnit->FuelData() ) {
4967  switch (replacement_mode)
4968  {
4969  case 0: //Replacement or new Module
4970  break;
4971  case 1: //Additive
4972  PRETTY_ADDU( statcolor+"Adds #-c", playerUnit->FuelData(), 2, "metric tons of Lithium-6 " /*+statcolor+"to Fuel Capacity #-c"*/ );
4973  break;
4974  case 2: //multiplicative
4975  break;
4976  default: //Failure
4977  text += "Oh dear, this wasn't an upgrade. Please debug code.";
4978  break;
4979  }
4980  }
4981  const Unit::Computer uc = playerUnit->ViewComputerData();
4982  const Unit::Computer buc = blankUnit->ViewComputerData();
4983  if (!mode) {
4984  text += "#n##n#"+prefix+"#c0:1:.5#[FLIGHT CHARACTERISTICS]#n##-c";
4985  text += "#n#"+prefix+statcolor+"Turning response: #-c";
4986  }
4987  if (playerUnit->limits.yaw == playerUnit->limits.pitch && playerUnit->limits.yaw == playerUnit->limits.roll) {
4988  prettyPrintFloat( conversionBuffer, playerUnit->limits.yaw
4989  /( (playerUnit->GetMoment() != 0) ? playerUnit->GetMoment() : 1 ), 0, 4 );
4990  if (!mode) {
4991  text += conversionBuffer;
4992  text += " radians/second^2#n#"+expstatcolor+" (yaw, pitch, roll)#-c";
4993  } else if (playerUnit->limits.yaw != blankUnit->limits.yaw) {
4994  switch (replacement_mode)
4995  {
4996  case 0: //Replacement or new Module
4997  PRETTY_ADDU( statcolor+"#n#Installs maneuvering jets with turning response #-c",
4998  playerUnit->limits.yaw,
4999  0,
5000  " radians/second^2#n#"+statcolor+" (yaw, pitch, roll)#-c" );
5001  break;
5002  case 1: //Additive
5003  break;
5004  case 2: //multiplicative
5005  PRETTY_ADDU( statcolor+"#n#Increases turning response by #-c",
5006  100.0*( (playerUnit->limits.yaw*180/PI)-1 ),
5007  0,
5008  "%#n#"+statcolor+" (yaw, pitch, roll)#-c" );
5009  break;
5010  default: //Failure
5011  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5012  break;
5013  }
5014  }
5015  } else {
5016  if (!mode) {
5017  float moment = (playerUnit->GetMoment() != 0) ? playerUnit->GetMoment() : 1;
5018  PRETTY_ADDN( substatcolor+" yaw #-c", playerUnit->limits.yaw/(moment), 4 );
5019  PRETTY_ADDN( substatcolor+" pitch #-c", playerUnit->limits.pitch/(moment), 4 );
5020  PRETTY_ADDN( substatcolor+" roll #-c", playerUnit->limits.roll/(moment), 4 );
5021  text += " radians/second^2";
5022  } else if (playerUnit->limits.yaw != blankUnit->limits.yaw || playerUnit->limits.pitch != blankUnit->limits.pitch
5023  || playerUnit->limits.roll != blankUnit->limits.roll) {
5024  switch (replacement_mode)
5025  {
5026  case 0: //Replacement or new Module
5027  text += "#n#Replaces existing maneuvering system with one rated at: #-c#n#";
5028  PRETTY_ADDN( substatcolor+"Yaw #-c", playerUnit->limits.yaw, 2 );
5029  PRETTY_ADDN( substatcolor+" Pitch #-c", playerUnit->limits.pitch, 2 );
5030  PRETTY_ADDN( substatcolor+" Roll #-c", playerUnit->limits.roll, 2 );
5031  text += " metric-ton*radians/second^2";
5032  break;
5033  case 1: //Additive
5034  text += "#n#Upgrades existing maneuvering system by the following amounts: #-c#n#";
5035  PRETTY_ADDN( substatcolor+"Yaw #-c", playerUnit->limits.yaw, 2 );
5036  PRETTY_ADDN( substatcolor+" Pitch #-c", playerUnit->limits.pitch, 2 );
5037  PRETTY_ADDN( substatcolor+" Roll #-c", playerUnit->limits.roll, 2 );
5038  text += " metric-ton*radians/second^2";
5039  break;
5040  case 2: //multiplicative
5041  text += "#n#Increases performance of existing maneuvering system by the following percentages: #-c#n#";
5042  PRETTY_ADDN( substatcolor+"Yaw #-c", 100.0*( (playerUnit->limits.yaw*180/PI)-1 ), 0 );
5043  PRETTY_ADDN( substatcolor+" Pitch #-c", 100.0*( (playerUnit->limits.pitch*180/PI)-1 ), 0 );
5044  PRETTY_ADDN( substatcolor+" Roll #-c", 100.0*( (playerUnit->limits.roll*180/PI)-1 ), 0 );
5045  break;
5046  default: //Failure
5047  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5048  break;
5049  }
5050  }
5051  }
5052  if (!subunitlevel) {
5053  if ( !mode && (playerUnit->GetMass() != 0) ) {
5054  PRETTY_ADDU( statcolor+"Fore acceleration: #-c",
5055  playerUnit->limits.forward/( 9.8*playerUnit->GetMass() ), 2, "gravities" );
5056  PRETTY_ADDU( statcolor+"Aft acceleration: #-c",
5057  playerUnit->limits.retro/( 9.8*playerUnit->GetMass() ), 2, "gravities" );
5058  if (playerUnit->limits.lateral == playerUnit->limits.vertical) {
5059  PRETTY_ADDU( statcolor+"Orthogonal acceleration: #-c",
5060  playerUnit->limits.vertical/( 9.8*playerUnit->GetMass() ), 2, "gravities" );
5061  text += expstatcolor+"#n# (vertical and lateral axes)#-c";
5062  } else {
5063  PRETTY_ADDN( statcolor+" Lateral acceleration #-c", playerUnit->limits.lateral/( 9.8*playerUnit->GetMass() ), 2 );
5064  PRETTY_ADDN( statcolor+" Vertical acceleration #-c",
5065  playerUnit->limits.vertical/( 9.8*playerUnit->GetMass() ), 2 );
5066  text += " gravities";
5067  }
5068  PRETTY_ADDU( statcolor+"Forward acceleration with overthrust: #-c", playerUnit->limits.afterburn
5069  /( 9.8*playerUnit->GetMass() ), 2, "gravities" );
5070  text.append( "#n##n##c0:1:.5#"+prefix+"[GOVERNOR SETTINGS]#n##-c" );
5071  } else {
5072  switch (replacement_mode)
5073  {
5074  case 0: //Replacement or new Module
5075  if (playerUnit->limits.forward != blankUnit->limits.forward) {
5076  PRETTY_ADDU( statcolor+"Provides forward thrust rated at: #-c",
5077  playerUnit->limits.forward/1000.0,
5078  2,
5079  "MegaNewtons" );
5080  }
5081  if (playerUnit->limits.retro != blankUnit->limits.retro) {
5082  PRETTY_ADDU( statcolor+"Provides aftward thrust rated at: #-c",
5083  playerUnit->limits.retro/1000.0,
5084  2,
5085  "MegaNewtons" );
5086  }
5087  if (playerUnit->limits.vertical != blankUnit->limits.vertical) {
5088  PRETTY_ADDU( statcolor+"Provides vertical thrust rated at: #-c",
5089  playerUnit->limits.vertical/1000.0,
5090  2,
5091  "MegaNewtons" );
5092  }
5093  if (playerUnit->limits.lateral != blankUnit->limits.lateral) {
5094  PRETTY_ADDU( statcolor+"Provides lateral thrust rated at: #-c",
5095  playerUnit->limits.lateral/1000.0,
5096  2,
5097  "MegaNewtons" );
5098  }
5099  if (playerUnit->limits.afterburn != blankUnit->limits.afterburn) {
5100  PRETTY_ADDU( statcolor+"Overdrive thrust rated at: #-c",
5101  playerUnit->limits.afterburn/1000.0,
5102  2,
5103  "MegaNewtons" );
5104  }
5105  break;
5106  case 1: //Additive
5107  if (playerUnit->limits.forward != blankUnit->limits.forward) {
5108  PRETTY_ADDU( statcolor+"Increases forward thrust rating by: #-c",
5109  playerUnit->limits.forward/1000.0,
5110  2,
5111  "MegaNewtons" );
5112  }
5113  if (playerUnit->limits.retro != blankUnit->limits.retro) {
5114  PRETTY_ADDU( statcolor+"Increases aftward thrust rating by: #-c",
5115  playerUnit->limits.retro/1000.0,
5116  2,
5117  "MegaNewtons" );
5118  }
5119  if (playerUnit->limits.vertical != blankUnit->limits.vertical) {
5120  PRETTY_ADDU( statcolor+"Increases vertical thrust rating by: #-c",
5121  playerUnit->limits.vertical/1000.0,
5122  2,
5123  "MegaNewtons" );
5124  }
5125  if (playerUnit->limits.lateral != blankUnit->limits.lateral) {
5126  PRETTY_ADDU( statcolor+"Increases lateral thrust rating by: #-c",
5127  playerUnit->limits.lateral/1000.0,
5128  2,
5129  "MegaNewtons" );
5130  }
5131  if (playerUnit->limits.afterburn != blankUnit->limits.afterburn) {
5132  PRETTY_ADDU( statcolor+"Increases overdrive thrust rating by: #-c",
5133  playerUnit->limits.afterburn/1000.0,
5134  2,
5135  "MegaNewtons" );
5136  }
5137  break;
5138  case 2: //multiplicative
5139  if (playerUnit->limits.forward != blankUnit->limits.forward) {
5140  PRETTY_ADDU( statcolor+"Increases forward thrust rating by: #-c",
5141  (playerUnit->limits.forward-1)*100,
5142  0,
5143  "%" );
5144  }
5145  if (playerUnit->limits.retro != blankUnit->limits.retro) {
5146  PRETTY_ADDU( statcolor+"Increases aftward thrust rating by: #-c",
5147  (playerUnit->limits.retro-1)*100,
5148  0,
5149  "%" );
5150  }
5151  if (playerUnit->limits.vertical != blankUnit->limits.vertical) {
5152  PRETTY_ADDU( statcolor+"Increases vertical thrust rating by: #-c",
5153  (playerUnit->limits.vertical-1)*100,
5154  0,
5155  "%" );
5156  }
5157  if (playerUnit->limits.lateral != blankUnit->limits.lateral) {
5158  PRETTY_ADDU( statcolor+"Increases lateral thrust rating by: #-c",
5159  (playerUnit->limits.lateral-1)*100,
5160  0,
5161  "%" );
5162  }
5163  if (playerUnit->limits.afterburn != blankUnit->limits.afterburn)
5164  PRETTY_ADDU( statcolor+"Overdrive thrust rating by: #-c", (playerUnit->limits.afterburn-1)*100, 0, "%" );
5165  break;
5166  default: //Failure
5167  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5168  break;
5169  }
5170  }
5171  static float non_combat_mode_mult =
5172  XMLSupport::parse_float( vs_config->getVariable( "physics", "combat_speed_boost", "100" ) );
5173  if (!mode) {
5174  PRETTY_ADDU( statcolor+"Max combat speed: #-c", uc.max_speed(), 0, "m/s" );
5175  PRETTY_ADDU( statcolor+"Max overdrive combat speed: #-c", uc.max_ab_speed(), 0, "m/s" );
5176  PRETTY_ADDU( statcolor+"Max non-combat speed: #-c", uc.max_speed()*non_combat_mode_mult, 0, "m/s" );
5177  } else {
5178  switch (replacement_mode)
5179  {
5180  case 0: //Replacement or new Module
5181  if ( uc.max_speed() != buc.max_speed() ) {
5182  PRETTY_ADDU( statcolor+"Sets max combat speed governor to: #-c", uc.max_speed(), 0, "m/s" );
5183  PRETTY_ADDU( statcolor+"Sets max non-combat speed governor to: #-c",
5184  uc.max_speed()*non_combat_mode_mult, 0, "m/s" );
5185  }
5186  if ( uc.max_ab_speed() != buc.max_ab_speed() )
5187  PRETTY_ADDU( statcolor+"Sets max overdrive combat speed governor to: #-c", uc.max_ab_speed(), 0, "m/s" );
5188  break;
5189  case 1: //Additive
5190  if ( uc.max_speed() != buc.max_speed() ) {
5191  PRETTY_ADDU( statcolor+"Increases max combat speed governor setting by: #-c", uc.max_speed(), 0, "m/s" );
5192  PRETTY_ADDU( statcolor+"Increases max non-combat speed governor setting by: #-c",
5193  uc.max_speed()*non_combat_mode_mult, 0, "m/s" );
5194  }
5195  if ( uc.max_ab_speed() != buc.max_ab_speed() )
5196  PRETTY_ADDU( statcolor+"Increases max overdrive combat speed governor setting by: #-c",
5197  uc.max_ab_speed(), 0, "m/s" );
5198  break;
5199  case 2: //multiplicative
5200  if ( uc.max_speed() != buc.max_speed() ) {
5201  PRETTY_ADDU( statcolor+"Increases max combat speed governor settings by: #-c",
5202  100.0*(uc.max_speed()-1), 0, "%" );
5203  PRETTY_ADDU( statcolor+"Increases max non-combat speed governor settings by: #-c",
5204  100.0*(uc.max_speed()-1), 0, "%" );
5205  }
5206  if ( uc.max_ab_speed() != buc.max_ab_speed() )
5207  PRETTY_ADDU( statcolor+"Increases max overdrive combat speed governor settings by: #-c",
5208  (uc.max_ab_speed()-1)*100, 0, "%" );
5209  break;
5210  default: //Failure
5211  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5212  break;
5213  }
5214  }
5215  }
5216  if (!mode) {
5217  if (uc.max_yaw_right == uc.max_pitch_up && uc.max_yaw_right == uc.max_roll_right) {
5218  PRETTY_ADD( statcolor+"Max turn rate: #-c", uc.max_yaw_right, 2 );
5219  text += " radians/second "+expstatcolor+"(yaw, pitch, roll)#-c";
5220  } else {
5221  text += ("#n#"+prefix+statcolor+"Max turn rates:#-c");
5222  PRETTY_ADDU( substatcolor+" - yaw: #-c", uc.max_yaw_right, 2, "radians/second" );
5223  PRETTY_ADDU( substatcolor+" - pitch: #-c", uc.max_pitch_up, 2, "radians/second" );
5224  PRETTY_ADDU( substatcolor+" - roll: #-c", uc.max_roll_right, 2, "radians/second" );
5225  }
5226  text += "#n##n##c0:1:.5#"+prefix+"[TARGETTING SUBSYSTEM]#n##-c";
5227  } else if (uc.max_yaw_right != buc.max_yaw_right || uc.max_pitch_up != buc.max_pitch_up || uc.max_roll_right
5228  != buc.max_roll_right) {
5229  switch (replacement_mode)
5230  {
5231  case 0: //Replacement or new Module
5232  text += ("#n#"+prefix+"Governor settings for maximum turn rates set to: ");
5233  PRETTY_ADDN( substatcolor+" yaw #-c", uc.max_yaw_right, 2 );
5234  PRETTY_ADDN( substatcolor+" pitch #-c", uc.max_pitch_up, 2 );
5235  PRETTY_ADDN( substatcolor+" roll #-c", uc.max_roll_right, 2 );
5236  text += " radians/second";
5237  break;
5238  case 1: //Additive
5239  text += ("#n#"+prefix+"Governor settings for maximum turn rates increased by: ");
5240  PRETTY_ADDN( substatcolor+" yaw #-c", uc.max_yaw_right, 2 );
5241  PRETTY_ADDN( substatcolor+" pitch #-c", uc.max_pitch_up, 2 );
5242  PRETTY_ADDN( substatcolor+" roll #-c", uc.max_roll_right, 2 );
5243  text += " radians/second";
5244  break;
5245  case 2: //multiplicative
5246  text += ("#n#"+substatcolor+"Increases governor settings for maximum turn rates by: #-c");
5247  PRETTY_ADDN( substatcolor+" yaw #-c", 100.0*( (uc.max_yaw_right*180/PI)-1 ), 0 );
5248  PRETTY_ADDN( substatcolor+" pitch #-c", 100.0*( (uc.max_pitch_up*180/PI)-1 ), 0 );
5249  PRETTY_ADDN( substatcolor+" roll #-c", 100.0*( (uc.max_roll_right*180/PI)-1 ), 0 );
5250  text += " %";
5251  break;
5252  default: //Failure
5253  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5254  break;
5255  }
5256  }
5257  if (!mode) {
5258  PRETTY_ADDU( statcolor+"Tracking range: #-c", uc.radar.maxrange/1000, 0, "km" );
5259  if ( (acos( uc.radar.maxcone )*360/PI) < 359 ) {
5260  PRETTY_ADDU( statcolor+"Tracking cone: #-c", acos( uc.radar.maxcone )*2, 2, "radians" );
5261  text += expstatcolor+"#n# (planar angle: 2 pi means full space)#-c";
5262  } else {
5263  text += "#n#"+prefix+statcolor+"Tracking cone: #-cOMNIDIRECTIONAL";
5264  }
5265  PRETTY_ADDU( statcolor+"Assisted targeting cone: #-c", acos( uc.radar.trackingcone )*2, 2, "radians" );
5266  PRETTY_ADDU( statcolor+"Missile locking cone: #-c", acos( uc.radar.lockcone )*2, 2, "radians" );
5267  if (!subunitlevel) {
5268  //Always zero PRETTY_ADDU("Minimum target size: ",uc.radar.mintargetsize,2,"m");
5269  text += "#n#"+prefix+statcolor+"ITTS (Intelligent Target Tracking System) support: #-c";
5270  if (uc.itts) text += "yes";
5271 
5272  else text += "no";
5273  text += "#n#"+prefix+statcolor+"AFHH (Advanced Flag & Hostility Heuristics) support: #-c";
5274  std::string afhh;
5275  if (uc.radar.UseFriendFoe())
5276  afhh += "friendly/hostile ";
5277  if (uc.radar.UseThreatAssessment())
5278  afhh += "threat ";
5279  if (afhh.empty())
5280  afhh = "no";
5281  text += afhh;
5282  }
5283  text.append( "#n##n##c0:1:.5#"+prefix+"[ENERGY SUBSYSTEM]#n##-c" );
5284  } else {
5285  switch (replacement_mode)
5286  {
5287  case 0: //Replacement or new Module
5288  if (uc.radar.maxrange != buc.radar.maxrange || uc.radar.maxcone != buc.radar.maxcone) {
5289  PRETTY_ADDU( statcolor+"Tracking range: #-c", uc.radar.maxrange/1000, 0, "km" );
5290  if ( (acos( uc.radar.maxcone )*360/PI) < 359 ) {
5291  PRETTY_ADDU( statcolor+"Tracking cone: #-c", acos( uc.radar.maxcone )*2, 2, "radians" );
5292  text += statcolor+" (planar angle: 2 pi means full space)#-c";
5293  } else {
5294  text += "#n#"+prefix+statcolor+"Tracking cone: #-cOMNIDIRECTIONAL";
5295  }
5296  PRETTY_ADDU( statcolor+"Assisted targeting cone: #-c", acos( uc.radar.trackingcone )*2, 2, "radians" );
5297  PRETTY_ADDU( statcolor+"Missile locking cone: #-c", acos( uc.radar.lockcone )*2, 2, "radians" );
5298  text += "#n#"+prefix+statcolor+"ITTS (Intelligent Target Tracking System) support: #-c";
5299  if (uc.itts) text += "yes";
5300 
5301  else text += "no";
5302  text += "#n#"+prefix+statcolor+"AFHH (Advanced Flag & Hostility Heuristics) support: #-c";
5303  std::string afhh;
5304  if (uc.radar.UseFriendFoe())
5305  afhh += "friendly/hostile ";
5306  if (uc.radar.UseThreatAssessment())
5307  afhh += "threat ";
5308  if (afhh.empty())
5309  afhh = "no";
5310  text += afhh;
5311  }
5312  break;
5313  case 1: //Additive
5314  break;
5315  case 2: //multiplicative
5316  break;
5317  default: //Failure
5318  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5319  break;
5320  }
5321  }
5322  const Unit::UnitJump &uj = playerUnit->GetJumpStatus();
5323  const Unit::UnitJump &buj = blankUnit->GetJumpStatus();
5324  if (!mode) {
5325  float maxshield = totalShieldEnergyCapacitance( playerUnit->shield );
5326  if (shields_require_power)
5327  maxshield = 0;
5328  PRETTY_ADDU( statcolor+"Recharge: #-c", playerUnit->EnergyRechargeData()*RSconverter, 0, "MJ/s" );
5329  PRETTY_ADDU( statcolor+"Weapon capacitor bank storage: #-c",
5330  ( (playerUnit->MaxEnergyData()-maxshield)*RSconverter ), 0, "MJ" );
5331  //note: I found no function to get max warp energy, but since we're docked they are the same
5332  if (!subunitlevel) {
5333  PRETTY_ADDU( statcolor+"Warp capacitor bank storage: #-c", playerUnit->WarpCapData()*RSconverter*Wconv, 0, "MJ" );
5334 
5335  text += "#n##n##c0:1:.5#"+prefix+"[SPEC SUBSYSTEM]#n##-c";
5336 
5337  PRETTY_ADDU( statcolor+"Active SPEC Energy Requirements: #-c",
5338  uj.insysenergy*RSconverter*Wconv/warpbleed,
5339  0,
5340  "MJ/s" );
5341 
5342  text += "#n##n##c0:1:.5#"+prefix+"[JUMP SUBSYSTEM]#n##-c";
5343  if (uj.drive == -2) {
5344  text += "#n##c1:.3:.3#No outsystem jump drive present#-c"; //fixed??
5345  } else {
5346  PRETTY_ADDU( statcolor+"Energy cost for jumpnode travel: #-c", uj.energy*RSconverter*Wconv, 0, "MJ" );
5347  if (uj.delay)
5348  PRETTY_ADDU( statcolor+"Delay: #-c", uj.delay, 0, "seconds" );
5349  if (uj.damage > 0)
5350  PRETTY_ADDU( statcolor+"Damage to outsystem jump drive: #-c", uj.damage*VSDM, 0, "MJ" );
5351  if (playerUnit->WarpCapData() < uj.energy) {
5352  text += "#n##c1:.3:.3#"+prefix
5353  +
5354  "WARNING: Warp capacitor banks under capacity for jump: upgrade warp capacitance#-c";
5355  }
5356  }
5357  }
5358  } else {
5359  switch (replacement_mode)
5360  {
5361  case 0: //Replacement or new Module
5362  if ( playerUnit->EnergyRechargeData() != blankUnit->EnergyRechargeData() )
5363  PRETTY_ADDU( statcolor+"Installs reactor with recharge rate: #-c",
5364  playerUnit->EnergyRechargeData()*RSconverter, 0, "MJ/s" );
5365  if ( playerUnit->MaxEnergyData() != blankUnit->MaxEnergyData() )
5366  PRETTY_ADDU( statcolor+"Installs main capacitor bank with storage capacity: #-c",
5367  (playerUnit->MaxEnergyData()*RSconverter), 0, "MJ" );
5368  if ( playerUnit->GetWarpEnergy() != blankUnit->GetWarpEnergy() )
5369  PRETTY_ADDU( statcolor+"Installs warp capacitor bank with storage capacity: #-c",
5370  playerUnit->GetWarpEnergy()*RSconverter*Wconv, 0, "MJ" );
5371  if (buj.drive != uj.drive) {
5372  text += statcolor
5373  +
5374  "#n#Allows travel via Jump Points.#n#Consult your personal info screen for ship specific energy requirements. #-c";
5375  }
5376  break;
5377  case 1: //Additive
5378  if ( playerUnit->EnergyRechargeData() != blankUnit->EnergyRechargeData() )
5379  PRETTY_ADDU( statcolor+"Increases recharge rate by #-c",
5380  playerUnit->EnergyRechargeData()*RSconverter, 0, "MJ/s" );
5381  if ( playerUnit->MaxEnergyData() != blankUnit->MaxEnergyData() )
5382  PRETTY_ADDU( statcolor+"Adds #-c",
5383  (playerUnit->MaxEnergyData()*RSconverter), 0, "MJ of storage to main capacitor banks" );
5384  if ( playerUnit->GetWarpEnergy() != blankUnit->GetWarpEnergy() )
5385  PRETTY_ADDU( statcolor+"Adds #-c",
5386  playerUnit->GetWarpEnergy()*RSconverter*Wconv, 0, "MJ of storage to warp capacitor bank" );
5387  break;
5388  case 2: //multiplicative
5389  if ( playerUnit->EnergyRechargeData() != blankUnit->EnergyRechargeData() )
5390  PRETTY_ADDU( statcolor+"Increases reactor recharge rate by #-c",
5391  100.0*(playerUnit->EnergyRechargeData()-1), 0, "%" );
5392  if ( playerUnit->MaxEnergyData() != blankUnit->MaxEnergyData() )
5393  PRETTY_ADDU( statcolor+"Increases main capacitor bank storage by #-c",
5394  100.0*(playerUnit->MaxEnergyData()-1), 0, "%" );
5395  if ( playerUnit->GetWarpEnergy() != blankUnit->GetWarpEnergy() )
5396  PRETTY_ADDU( statcolor+"Increases warp capacitor bank storage by #-c",
5397  (playerUnit->GetWarpEnergy()-1)*100, 0, "%" );
5398  break;
5399  default: //Failure
5400  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5401  break;
5402  }
5403  }
5404  if (!mode) {
5405  text += "#n##n##c0:1:.5#"+prefix+"[DURABILITY STATISTICS]#n##-c";
5406  text += "#n#"+prefix+statcolor+"Armor damage resistance:#-c";
5407  }
5408  if (mode && playerUnit->armor.frontlefttop != blankUnit->armor.frontlefttop) {
5409  switch (replacement_mode)
5410  {
5411  case 0: //Replacement or new Module
5412  text += "#n#"+prefix+statcolor+"Replaces existing armor, if any.#n#Armor damage resistance:#-c";
5413  break;
5414  case 1: //Additive
5415  text += "#n#"+prefix+statcolor+"Adds the following to armor damage resistance ratings:#-c";
5416  break;
5417  case 2: //multiplicative
5418  text += "#n#"+prefix+statcolor+"Armor damage resistance increased by following percentages:#-c";
5419  break;
5420  default: //Failure
5421  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5422  break;
5423  }
5424  }
5425  if (!mode || playerUnit->armor.frontrighttop != blankUnit->armor.frontrighttop) {
5426  PRETTY_ADDU(
5427  substatcolor+" - Fore-starboard-high: #-c",
5428  (mode && replacement_mode
5429  == 2) ? 100.0*(playerUnit->armor.frontrighttop-1) : playerUnit->armor.frontrighttop*VSDM,
5430  0,
5431  (2 == replacement_mode) ? "%" : "MJ" );
5432  PRETTY_ADDU(
5433  substatcolor+" - Aft-starboard-high: #-c",
5434  (mode && replacement_mode
5435  == 2) ? 100.0*(playerUnit->armor.backrighttop-1) : playerUnit->armor.backrighttop*VSDM,
5436  0,
5437  (2 == replacement_mode) ? "%" : "MJ" );
5438  PRETTY_ADDU(
5439  substatcolor+" - Fore-port-high: #-c",
5440  (mode && replacement_mode
5441  == 2) ? 100.0*(playerUnit->armor.frontlefttop-1) : playerUnit->armor.frontlefttop*VSDM,
5442  0,
5443  (2 == replacement_mode) ? "%" : "MJ" );
5444  PRETTY_ADDU(
5445  substatcolor+" - Aft-port-high: #-c",
5446  (mode && replacement_mode
5447  == 2) ? 100.0*(playerUnit->armor.backlefttop-1) : playerUnit->armor.backlefttop*VSDM,
5448  0,
5449  (2 == replacement_mode) ? "%" : "MJ" );
5450  PRETTY_ADDU(
5451  substatcolor+" - Fore-starboard-low: #-c",
5452  (mode && replacement_mode
5453  == 2) ? 100.0*(playerUnit->armor.frontrightbottom-1) : playerUnit->armor.frontrightbottom*VSDM,
5454  0,
5455  (2 == replacement_mode) ? "%" : "MJ" );
5456  PRETTY_ADDU(
5457  substatcolor+" - Aft-starboard-low: #-c",
5458  (mode && replacement_mode
5459  == 2) ? 100.0*(playerUnit->armor.backrightbottom-1) : playerUnit->armor.backrightbottom*VSDM,
5460  0,
5461  (2 == replacement_mode) ? "%" : "MJ" );
5462  PRETTY_ADDU(
5463  substatcolor+" - Fore-port-low: #-c",
5464  (mode && replacement_mode
5465  == 2) ? 100.0*(playerUnit->armor.frontleftbottom-1) : playerUnit->armor.frontleftbottom*VSDM,
5466  0,
5467  (2 == replacement_mode) ? "%" : "MJ" );
5468  PRETTY_ADDU(
5469  substatcolor+" - Aft-port-low: #-c",
5470  (mode && replacement_mode
5471  == 2) ? 100.0*(playerUnit->armor.backleftbottom-1) : playerUnit->armor.backleftbottom*VSDM,
5472  0,
5473  (2 == replacement_mode) ? "%" : "MJ" );
5474  }
5475  if (!mode) {
5476  PRETTY_ADDU( statcolor+"Sustainable Hull Damage: #-c",
5477  playerUnit->GetHull()/( playerUnit->GetHullPercent() )*VSDM, 0, "MJ" );
5478  if ( 1 != playerUnit->GetHullPercent() ) {
5479  PRETTY_ADD( " Current condition: ", playerUnit->GetHullPercent()*100, 2 );
5480  text += "% of normal";
5481  }
5482  } else if ( playerUnit->GetHull() != blankUnit->GetHull() ) {
5483  switch (replacement_mode)
5484  {
5485  case 0: //Replacement or new Module
5486  PRETTY_ADDU( statcolor+"New Sustained Hull Damage Rating: #-c",
5487  playerUnit->GetHull()/( playerUnit->GetHullPercent() )*VSDM, 0, "MJ" );
5488  break;
5489  case 1: //Additive
5490  PRETTY_ADDU( statcolor+"Increases sustainable hull damage by #-c", playerUnit->GetHull()
5491  /( playerUnit->GetHullPercent() )*VSDM, 0, "MJ" );
5492  break;
5493  case 2: //multiplicative
5494  PRETTY_ADDU( statcolor+"Hull Strength increased by #-c", 100.0*(playerUnit->GetHull()-1), 0, "%" );
5495  break;
5496  default: //Failure
5497  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5498  break;
5499  }
5500  }
5501  if (!mode) {
5502  if (playerUnit->shield.number) {
5503  PRETTY_ADD( statcolor+"Number of shield emitter facings: #-c", playerUnit->shield.number, 0 );
5504  text += "#n#"+prefix+statcolor+"Shield protection rating:#-c";
5505  } else {
5506  text += "#n#"+prefix+statcolor+"No shielding. #-c";
5507  }
5508  } else if ( playerUnit->shield.number
5509  && ( (playerUnit->shield.shield2fb.frontmax != blankUnit->shield.shield2fb.frontmax)
5510  || (playerUnit->shield.shield4fbrl.frontmax != blankUnit->shield.shield4fbrl.frontmax)
5511  || (playerUnit->shield.shield8.frontrightbottommax != blankUnit->shield.shield8.frontrightbottommax) ) ) {
5512  switch (replacement_mode)
5513  {
5514  case 0: //Replacement or new Module
5515  text += "#n#"+prefix+statcolor+"Installs shield with following protection ratings:#-c";
5516  break;
5517  case 1: //Additive
5518  text += "#n#"+prefix+statcolor+"Adds following amounts to shield protection ratings:#-c";
5519  break;
5520  case 2: //multiplicative
5521  text += "#n#"+prefix+statcolor+"Shield protection rating for each emitter increased by listed percentage:#-c";
5522  break;
5523  default: //Failure
5524  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5525  break;
5526  }
5527  }
5528  switch (playerUnit->shield.number)
5529  {
5530  case 0:
5531  break;
5532  case 2:
5533  if (!mode || playerUnit->shield.shield2fb.frontmax != blankUnit->shield.shield2fb.frontmax) {
5534  PRETTY_ADDU(
5535  substatcolor+" - fore: #-c",
5536  (mode && replacement_mode == 2) ? ( 100.0
5537  *(playerUnit->shield.shield2fb.backmax
5538  -1) ) : playerUnit->shield.shield2fb.frontmax*VSDM,
5539  0,
5540  (2 == replacement_mode) ? "%" : "MJ" );
5541  PRETTY_ADDU(
5542  substatcolor+" - aft: #-c",
5543  (mode && replacement_mode == 2) ? ( 100.0
5544  *(playerUnit->shield.shield2fb.backmax
5545  -1) ) : playerUnit->shield.shield2fb.backmax*VSDM,
5546  0,
5547  (2 == replacement_mode) ? "%" : "MJ" );
5548  }
5549  break;
5550  case 4:
5551  if (!mode || playerUnit->shield.shield4fbrl.frontmax != blankUnit->shield.shield4fbrl.frontmax) {
5552  PRETTY_ADDU(
5553  substatcolor+" - fore: #-c",
5554  (mode && replacement_mode == 2) ? ( 100.0
5555  *(playerUnit->shield.shield4fbrl.frontmax
5556  -1) ) : playerUnit->shield.shield4fbrl.frontmax*VSDM,
5557  0,
5558  (2 == replacement_mode) ? "%" : "MJ" );
5559  PRETTY_ADDU(
5560  substatcolor+" - aft: #-c",
5561  (mode && replacement_mode == 2) ? ( 100.0
5562  *(playerUnit->shield.shield4fbrl.backmax
5563  -1) ) : playerUnit->shield.shield4fbrl.backmax*VSDM,
5564  0,
5565  (2 == replacement_mode) ? "%" : "MJ" );
5566  PRETTY_ADDU(
5567  substatcolor+" - port: #-c",
5568  (mode && replacement_mode == 2) ? ( 100.0
5569  *(playerUnit->shield.shield4fbrl.leftmax
5570  -1) ) : playerUnit->shield.shield4fbrl.leftmax*VSDM,
5571  0,
5572  (2 == replacement_mode) ? "%" : "MJ" );
5573  PRETTY_ADDU(
5574  substatcolor+" - starboard: #-c",
5575  (mode && replacement_mode == 2) ? ( 100.0
5576  *(playerUnit->shield.shield4fbrl.rightmax
5577  -1) ) : playerUnit->shield.shield4fbrl.rightmax*VSDM,
5578  0,
5579  (2 == replacement_mode) ? "%" : "MJ" );
5580  }
5581  break;
5582  case 8:
5583  if (!mode || playerUnit->shield.shield8.frontrightbottommax != blankUnit->shield.shield8.frontrightbottommax) {
5584  PRETTY_ADDU(
5585  statcolor+" - Fore-starboard-high: #-c",
5586  (mode && replacement_mode
5587  == 2) ? 100.0
5588  *(playerUnit->shield.shield8.frontrighttopmax-1) : playerUnit->shield.shield8.frontrighttopmax*VSDM,
5589  0,
5590  (2 == replacement_mode) ? "%" : "MJ" );
5591  PRETTY_ADDU(
5592  substatcolor+" - Aft-starboard-high: #-c",
5593  (mode && replacement_mode
5594  == 2) ? 100.0
5595  *(playerUnit->shield.shield8.backrighttopmax-1) : playerUnit->shield.shield8.backrighttopmax*VSDM,
5596  0,
5597  (2 == replacement_mode) ? "%" : "MJ" );
5598  PRETTY_ADDU(
5599  substatcolor+" - Fore-port-high: #-c",
5600  (mode && replacement_mode
5601  == 2) ? 100.0
5602  *(playerUnit->shield.shield8.frontlefttopmax-1) : playerUnit->shield.shield8.frontlefttopmax*VSDM,
5603  0,
5604  (2 == replacement_mode) ? "%" : "MJ" );
5605  PRETTY_ADDU(
5606  substatcolor+" - Aft-port-high: #-c",
5607  (mode && replacement_mode
5608  == 2) ? 100.0
5609  *(playerUnit->shield.shield8.backlefttopmax-1) : playerUnit->shield.shield8.backlefttopmax*VSDM,
5610  0,
5611  (2 == replacement_mode) ? "%" : "MJ" );
5612  PRETTY_ADDU(
5613  substatcolor+" - Fore-starboard-low: #-c",
5614  (mode && replacement_mode
5615  == 2) ? 100.0
5616  *(playerUnit->shield.shield8.frontrighttopmax-1) : playerUnit->shield.shield8.frontrightbottommax*VSDM,
5617  0,
5618  (2 == replacement_mode) ? "%" : "MJ" );
5619  PRETTY_ADDU(
5620  substatcolor+" - Aft-starboard-low: #-c",
5621  (mode && replacement_mode
5622  == 2) ? 100.0
5623  *(playerUnit->shield.shield8.backrighttopmax-1) : playerUnit->shield.shield8.backrightbottommax*VSDM,
5624  0,
5625  (2 == replacement_mode) ? "%" : "MJ" );
5626  PRETTY_ADDU(
5627  substatcolor+" - Fore-port-low: #-c",
5628  (mode && replacement_mode
5629  == 2) ? 100.0
5630  *(playerUnit->shield.shield8.frontlefttopmax-1) : playerUnit->shield.shield8.frontleftbottommax*VSDM,
5631  0,
5632  (2 == replacement_mode) ? "%" : "MJ" );
5633  PRETTY_ADDU(
5634  substatcolor+" - Aft-port-low: #-c",
5635  (mode && replacement_mode
5636  == 2) ? 100.0
5637  *(playerUnit->shield.shield8.backlefttopmax-1) : playerUnit->shield.shield8.backleftbottommax*VSDM,
5638  0,
5639  (2 == replacement_mode) ? "%" : "MJ" );
5640  }
5641  break;
5642  default:
5643  text += "#c1:.3:.3#Shield model unrecognized#-c";
5644  break;
5645  }
5646  if (!mode) {
5647  PRETTY_ADDU( statcolor+"Shield protection recharge speed: #-c", playerUnit->shield.recharge*VSDM, 0, "MJ/s" );
5648  } else if (playerUnit->shield.recharge != blankUnit->shield.recharge) {
5649  switch (replacement_mode)
5650  {
5651  case 0: //Replacement or new Module
5652  PRETTY_ADDU( statcolor+"Shield protection recharge speed set to: #-c", playerUnit->shield.recharge*VSDM, 0, "MJ/s" );
5653  break;
5654  case 1: //Additive
5655  PRETTY_ADDU( statcolor+"Increases shield protection recharge speed by #-c",
5656  playerUnit->shield.recharge*VSDM,
5657  0,
5658  "MJ/s" );
5659  break;
5660  case 2: //multiplicative
5661  PRETTY_ADDU( statcolor+"Shield protection recharge speed increased by #-c",
5662  100.0*(playerUnit->shield.recharge-1),
5663  0,
5664  "%" );
5665  break;
5666  default: //Failure
5667  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5668  break;
5669  }
5670  }
5671  //cloaking device? If we don't have one, no need to mention it ever exists, right?
5672  if (playerUnit->cloaking != -1) {
5673  if (!mode) {
5674  PRETTY_ADDU( statcolor+"Cloaking device available, energy usage: #-c",
5675  playerUnit->pImage->cloakenergy*RSconverter*Wconv,
5676  0,
5677  "MJ/s" );
5678  } else {
5679  switch (replacement_mode)
5680  {
5681  case 0: //Replacement or new Module
5682  PRETTY_ADDU( statcolor+"Installs a cloaking device.#n# Activated energy usage: #-c",
5683  playerUnit->pImage->cloakenergy*RSconverter*Wconv,
5684  0,
5685  "MJ/s" );
5686  break;
5687  case 1: //Additive
5688  text += "#n#Additive Cloaking...Seems like a bug to me.#n#";
5689  break;
5690  case 2: //multiplicative
5691  text += "#n#Multiplicative Cloaking...Seems like a bug to me.#n#";
5692  break;
5693  default: //Failure
5694  text += "Oh dear, this wasn't an upgrade. Please debug code.";
5695  break;
5696  }
5697  }
5698  }
5699  bool anyweapons = false;
5700  if (!mode) {
5701  text += "#n##n##c0:1:.5#"+prefix+"[ARMAMENT]#n##-c";
5702  text += prefix+"MOUNTPOINT RATINGS:";
5703  }
5704  //let's go through all mountpoints
5705  {
5706  for (int i = 0; i < playerUnit->GetNumMounts(); i++) {
5707  if (!mode) {
5708  PRETTY_ADD( " #c0:1:.3#[#-c", i+1, 0 );
5709  text += "#c0:1:.3#]#-c #c0:1:1#"+lookupMountSize( playerUnit->mounts[i].size )+"#-c";
5710  }
5711  const weapon_info *wi = playerUnit->mounts[i].type;
5712  if (wi && wi->weapon_name != "")
5713  anyweapons = true;
5714  }
5715  }
5716  if (!mode)
5717  text += "#n#"+prefix+"MOUNTED:"; //need brace for namespace issues on VC++
5718  {
5719  if (anyweapons) {
5720  for (int i = 0; i < playerUnit->GetNumMounts(); i++) {
5721  const weapon_info *wi = playerUnit->mounts[i].type;
5722  if ( (!wi) || (wi->weapon_name == "") ) {
5723  continue;
5724  } else {
5725  if (!mode) {
5726  PRETTY_ADD( " #c0:1:.3#[#-c", i+1, 0 );
5727  text += "#c0:1:.3#]#-c ";
5728  }
5729  text += wi->weapon_name+": #c0:1:1#"+lookupMountSize( wi->size )+"#-c#c.9:.9:.5#"
5730  +WeaponTypeStrings[wi->type]+" #-c";
5731  if (wi->Damage < 0) {text += "#n#"+prefix+statcolor+" Damage:#-c special"; } else {
5732  PRETTY_ADDU( statcolor+" Damage: #-c",
5733  wi->Damage*VSDM,
5734  0,
5735  wi->type == weapon_info::BEAM ? "MJ/s" : "MJ" );
5736  }
5737  PRETTY_ADDU( statcolor+" Range: #-c", wi->Range, 0, "meters" );
5738  PRETTY_ADDU( statcolor+" Energy usage: #-c",
5739  wi->EnergyRate*RSconverter,
5740  0,
5741  wi->type == weapon_info::BEAM ? "MJ/s" : "MJ/shot" );
5742 
5743  PRETTY_ADDU( statcolor+" Refire delay: #-c", wi->Refire(), 2, "seconds" );
5744  if (wi->PhaseDamage > 0)
5745  PRETTY_ADDU( statcolor+" Phase damage: #-c", wi->PhaseDamage*VSDM, 2, "MJ" );
5746  //display info specific to some weapons type
5747  switch (wi->type)
5748  {
5749  case weapon_info::BALL: //may need ammo
5750  case weapon_info::BOLT:
5751  if (wi->Damage > 0)
5752  totalWeaponDamage += ( wi->Damage/wi->Refire() ); //damage per second
5753  PRETTY_ADDU( statcolor+" Exit velocity: #-c", wi->Speed, 0, "meters/second" );
5754  if ( ( 100000*(1.0-wi->Longrange)/(wi->Range) ) > 0.00001 ) {
5755  PRETTY_ADD( statcolor+" Range attenuation factor: #-c",
5756  100000*(1.0-wi->Longrange)/(wi->Range),
5757  2 );
5758  text += "% per km";
5759  }
5760  if ( playerUnit->mounts[i].ammo != -1 && (lookupMountSize( wi->size ) != "SPECIAL-MISSILE") )
5761  PRETTY_ADD( statcolor+" Rounds remaining: #-c", playerUnit->mounts[i].ammo, 0 );
5762  else if (lookupMountSize( wi->size ) == "SPECIAL-MISSILE")
5763  PRETTY_ADD( statcolor+" Rockets remaining: #-c", playerUnit->mounts[i].ammo, 0 );
5764  totalWeaponEnergyUsage += ( wi->EnergyRate/wi->Refire() );
5765  break;
5766  case weapon_info::PROJECTILE: //need ammo
5767  if (wi->LockTime > 0) {
5768  PRETTY_ADDU( statcolor+" 'Fire and Forget' lock time: #-c", wi->LockTime, 0, "seconds" );
5769  } else {
5770  text += "#n#";
5771  text += prefix;
5772  text += statcolor+" Missile Lock Type: #-c#c1:.3:.3#None.#-c Inertial Guidance Only";
5773  }
5774  PRETTY_ADD( statcolor+" Missiles remaining: #-c", playerUnit->mounts[i].ammo, 0 );
5775  totalWeaponEnergyUsage += ( wi->EnergyRate/wi->Refire() );
5776  break;
5777  case weapon_info::BEAM:
5778  if (wi->Damage > 0)
5779  totalWeaponDamage += wi->Damage;
5780  PRETTY_ADDU( statcolor+" Beam stability: #-c", wi->Stability, 2, "seconds" );
5781  if ( ( 100000*(1.0-wi->Longrange)/(wi->Range) ) > 0.00001 ) {
5782  PRETTY_ADD( statcolor+" Range attenuation factor: #-c",
5783  100000*(1.0-wi->Longrange)/(wi->Range),
5784  2 );
5785  text += "% per km";
5786  }
5787  totalWeaponEnergyUsage += wi->EnergyRate;
5788  break;
5789  default:
5790  break;
5791  }
5792  }
5793  }
5794  } else //end mountpoint list
5795  if (!mode) {
5796  text += "#n##c1:.3:.3#"+prefix+" NO MOUNTED WEAPONS#n##-c";
5797  }
5798  }
5799  if (mode)
5800  return;
5801  if (subunitlevel == 0 && mode == 0) {
5802  text += "#n##n##c0:1:.5#"+prefix+"[KEY FIGURES]#n##-c";
5803  float maxshield = totalShieldEnergyCapacitance( playerUnit->shield );
5804  if (shields_require_power)
5805  maxshield = 0;
5806  PRETTY_ADDU( statcolor+"Minimum time to reach full overthrust speed: #-c",
5807  playerUnit->GetMass()*uc.max_ab_speed()/playerUnit->limits.afterburn, 2, "seconds" );
5808  //reactor
5809  float avail = (playerUnit->MaxEnergyData()*RSconverter-maxshield*VSDM);
5810  float overhead =
5811  (shields_require_power) ? (playerUnit->shield.recharge/shieldenergycap*shield_maintenance_cost
5812  *playerUnit->shield.number*VSDM) : 0;
5813  float nrt = avail/(playerUnit->EnergyRechargeData()*RSconverter-overhead);
5814  PRETTY_ADDU( statcolor+"Reactor nominal replenish time: #-c", nrt, 2, "seconds" );
5815  //shield related stuff
5816  //code taken from RegenShields in unit_generic.cpp, so we're sure what we say here is correct.
5817  static float low_power_mode = XMLSupport::parse_float( vs_config->getVariable( "physics", "low_power_mode_energy", "10" ) );
5818  if (playerUnit->MaxEnergyData()-maxshield < low_power_mode) {
5819  text += "#n##c1:.3:.3#"+prefix
5820  +
5821  "WARNING: Capacitor banks are overdrawn: downgrade shield, upgrade reactor or purchase reactor capacitance!#-c";
5822  }
5823  if (uj.drive != -2 && playerUnit->WarpCapData() < uj.energy) {
5824  text += "#n##c1:.3:.3#"+prefix
5825  +
5826  "WARNING: Warp capacitor banks under capacity for jump: upgrade warp capacitance#-c";
5827  }
5828  if (playerUnit->shield.number) {
5829  if (playerUnit->shield.recharge*playerUnit->shield.number*VSDM/shieldenergycap > playerUnit->EnergyRechargeData()
5830  *RSconverter) {
5831  text += "#n##c1:1:.1#"+prefix+"WARNING: reactor recharge rate is less than combined shield recharge rate.#n#";
5832  text += "Your shields won't be able to regenerate at their optimal speed!#-c";
5833  }
5834  if (shields_require_power) {
5835  text += "#n#"+prefix+statcolor+"Reactor recharge slowdown caused by shield maintenance: #-c";
5836  float maint_draw_percent = playerUnit->shield.recharge*VSDM*100.0/shieldenergycap*shield_maintenance_cost
5837  *playerUnit->shield.number/(playerUnit->EnergyRechargeData()*RSconverter);
5838  sprintf( conversionBuffer, "%.2f", maint_draw_percent );
5839  text += conversionBuffer;
5840  text += " %.";
5841  if (maint_draw_percent > 60) {
5842  text += "#n##c1:1:.1#"+prefix
5843  +
5844  "WARNING: Reactor power is heavily consumed by passive shield maintenance: consider downgrading shield or upgrading reactor.#-c";
5845  } else if (maint_draw_percent > 95) {
5846  text += "#n##c1:.3:.3#"+prefix
5847  +
5848  "SEVERE WARNING: Reactor power is overdrawn! Unsustainable power is being consumed by passive shield maintenance: downgrade shield or upgrade reactor immediately!#-c";
5849  }
5850  }
5851  }
5852  totalWeaponEnergyUsage = totalWeaponEnergyUsage*RSconverter;
5853  PRETTY_ADDU( statcolor+"Combined weapon energy usage: #-c", totalWeaponEnergyUsage, 0, "MJ/s" );
5854  float maint_draw =
5855  (shields_require_power && playerUnit->shield.number) ? (playerUnit->shield.recharge*VSDM/shieldenergycap
5856  *shield_maintenance_cost*playerUnit->shield.number) : 0;
5857  if ( totalWeaponEnergyUsage < (playerUnit->EnergyRechargeData()*RSconverter-maint_draw) ) {
5858  //waouh, impressive...
5859  text += "#n##c0:1:.2#"+prefix+"Your reactor produces more energy than your weapons can use!#-c";
5860  } else {
5861  PRETTY_ADDU( statcolor+"Reactor energy depletion time if weapons in continuous use: #-c",
5862  (playerUnit->MaxEnergyData()
5863  *RSconverter)/( totalWeaponEnergyUsage-( (playerUnit->EnergyRechargeData()*RSconverter-maint_draw) ) ),
5864  2,
5865  "seconds" );
5866  }
5867  PRETTY_ADDU( statcolor+"Combined (non-missile) weapon damage: #-c", totalWeaponDamage*VSDM, 0, "MJ/s" );
5868  }
5869  if (!mode) {
5870  //handle SubUnits
5871  Unit *sub;
5872  int i = 1;
5873  for (un_iter ki = playerUnit->getSubUnits(); (sub=*ki)!=NULL; ++ki, ++i) {
5874  if (i == 1) text += "#n##n##c0:1:.5#"+prefix+"[SUB UNITS]#-c";
5875  PRETTY_ADD( "#n#"+prefix+"#c0:1:.2#[#-csub unit ", i, 0 );
5876  text += "#c0:1:.2#]#-c#n#";
5877  showUnitStats( sub, text, subunitlevel+1, 0, item );
5878  }
5879  }
5880 }
void SwapInNewShipName ( Cockpit cockpit,
Unit base,
const std::string &  newFileName,
int  swappingShipsIndex 
)

Definition at line 4102 of file basecomputer.cpp.

References _Universe, Universe::activeStarSystem(), StarSystem::getFileName(), Cockpit::GetNumUnits(), Cockpit::GetParent(), Cockpit::GetUnitBaseName(), Cockpit::GetUnitFileName(), Cockpit::GetUnitSystemName(), i, Cockpit::MakeBaseName(), Unit::name, and Cockpit::RemoveUnit().

Referenced by buyShip().

4103 {
4104  Unit *parent = cockpit->GetParent();
4105  if (parent) {
4106  size_t putpos = (swappingShipsIndex >= 0) ? swappingShipsIndex : cockpit->GetNumUnits();
4107  cockpit->GetUnitFileName(putpos) = parent->name;
4108  cockpit->GetUnitSystemName(putpos) = _Universe->activeStarSystem()->getFileName();
4109  cockpit->GetUnitBaseName(putpos) = (base != NULL) ? Cockpit::MakeBaseName(base) : string("");
4110  if (swappingShipsIndex != -1) {
4111  for (size_t i = 1, n = cockpit->GetNumUnits(); i < n ; ++i)
4112  if (cockpit->GetUnitFileName(i) == newFileName) {
4113  cockpit->RemoveUnit(i);
4114  --i; //then ++;
4115  }
4116  }
4117  } else if (swappingShipsIndex != -1) {
4118  //if parent is dead
4119  cockpit->RemoveUnit(swappingShipsIndex);
4120  }
4121  cockpit->GetUnitFileName() = newFileName;
4122 }
void SwitchUnits ( Unit ol,
Unit nw 
)

Definition at line 328 of file cockpit_generic.cpp.

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 TerminateCurrentBase ( void  )

Definition at line 1151 of file base_interface.cpp.

1152 {
1156  }
1157 }
float totalShieldEnergyCapacitance ( const Shield shield)

Definition at line 3613 of file unit_generic.cpp.

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

Referenced by Unit::EnergyData(), Unit::RegenShields(), and showUnitStats().

3614 {
3615  static float shieldenergycap =
3616  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_capacitance", ".2" ) );
3617  static bool use_max_shield_value =
3618  XMLSupport::parse_bool( vs_config->getVariable( "physics", "use_max_shield_energy_usage", "false" ) );
3619  return shieldenergycap*use_max_shield_value ? totalShieldVal( shield ) : currentTotalShieldVal( shield );
3620 }
void trackPrice ( int  whichplayer,
const Cargo item,
float  price,
const string &  systemName,
const string &  baseName,
vector< string > &  highest,
vector< string > &  lowest 
)

Definition at line 4199 of file basecomputer.cpp.

References Cargo::category, Cargo::content, getSaveData(), getStringList(), VegaConfig::getVariable(), i, index, mymin, XMLSupport::parse_int(), PRETTY_ADD, pushSaveData(), pushSaveString(), putSaveData(), saveDataList(), saveStringList(), vs_config, and VSFileSystem::vs_dprintf().

Referenced by buildCargoDescription().

4201 {
4202  static size_t toprank = (size_t)
4203  XMLSupport::parse_int( vs_config->getVariable( "general", "trade_interface_tracks_prices_toprank", "10" ) );
4204 
4205  VSFileSystem::vs_dprintf(1, "Ranking item %s/%s at %s/%s\n",
4206  item.category.get().c_str(), item.content.get().c_str(),
4207  systemName.c_str(), baseName.c_str());
4208  fflush(stderr);
4209 
4210  // Recorded prices are always sorted, so we first do a quick check to avoid
4211  // triggering savegame serialization without reason
4212  string itemkey = string(item.category) + "/" + item.content;
4213  string hilock = itemkey + "?hi?loc";
4214  string lolock = itemkey + "?lo?loc";
4215  string hipricek = itemkey + "?hi?pcs";
4216  string lopricek = itemkey + "?lo?pcs";
4217 
4218  // First record the given item's price and update the ranking lists
4219  {
4220  string locname = "#b#" + baseName + "#-b# in the #b#" + systemName + "#-b# system";
4221 
4222  {
4223  bool resort = false;
4224  {
4225  // Limited lifetime iterator (points to invalid data after save data manipulation)
4226  const vector<string> &recordedHighestLocs = getStringList(whichplayer, hilock);
4227  const vector<float> &recordedHighestPrices = getSaveData(whichplayer, hipricek);
4228  vector<string>::const_iterator prev = std::find(
4229  recordedHighestLocs.begin(), recordedHighestLocs.end(),
4230  locname);
4231 
4232  if (prev != recordedHighestLocs.end()) {
4233  size_t index = prev - recordedHighestLocs.begin();
4234  putSaveData(whichplayer, hipricek, index, price);
4235  resort = true;
4236  } else if (recordedHighestPrices.size() < toprank || recordedHighestPrices.back() < price) {
4237  // Track new top price
4238  pushSaveString(whichplayer, hilock, locname);
4239  pushSaveData(whichplayer, hipricek, price);
4240  resort = true;
4241  }
4242  }
4243 
4244  if (resort) {
4245  // Re-get lists, the ones we got earlier could be empty stubs
4246  const vector<string> &locs = getStringList(whichplayer, hilock);
4247  const vector<float> &prices = getSaveData(whichplayer, hipricek);
4248  vector<size_t> indices;
4249 
4250  indices.resize(mymin(prices.size(),locs.size()));
4251  { for (size_t i=0; i<indices.size(); ++i)
4252  indices[i] = i; }
4253 
4254  std::sort(indices.begin(), indices.end(), PriceSort(prices, true));
4255 
4256  vector<string> newlocs;
4257  vector<float> newprices;
4258 
4259  newlocs.reserve(indices.size());
4260  newprices.reserve(indices.size());
4261  { for (size_t i=0; i<indices.size() && i<toprank; ++i) {
4262  newlocs.push_back(locs[indices[i]]);
4263  newprices.push_back(prices[indices[i]]);
4264  } }
4265 
4266  // Save new rank list
4267  saveDataList(whichplayer, hipricek, newprices);
4268  saveStringList(whichplayer, hilock, newlocs);
4269  }
4270  }
4271 
4272  {
4273  bool resort = false;
4274  {
4275  // Limited lifetime iterator (points to invalid data after save data manipulation)
4276  const vector<string> &recordedLowestLocs = getStringList(whichplayer, lolock);
4277  const vector<float> &recordedLowestPrices = getSaveData(whichplayer, lopricek);
4278  vector<string>::const_iterator prev = std::find(
4279  recordedLowestLocs.begin(), recordedLowestLocs.end(),
4280  locname);
4281 
4282  if (prev != recordedLowestLocs.end()) {
4283  size_t index = prev - recordedLowestLocs.begin();
4284  putSaveData(whichplayer, lopricek, index, price);
4285  resort = true;
4286  } else if (recordedLowestPrices.size() < toprank || recordedLowestPrices.back() > price) {
4287  // Track new top price
4288  pushSaveString(whichplayer, lolock, locname);
4289  pushSaveData(whichplayer, lopricek, price);
4290  resort = true;
4291  }
4292  }
4293 
4294  if (resort) {
4295  // Re-get lists, the ones we got earlier could be empty stubs
4296  const vector<string> &locs = getStringList(whichplayer, lolock);
4297  const vector<float> &prices = getSaveData(whichplayer, lopricek);
4298  vector<size_t> indices;
4299 
4300  indices.resize(mymin(prices.size(),locs.size()));
4301  { for (size_t i=0; i<indices.size(); ++i)
4302  indices[i] = i; }
4303 
4304  std::sort(indices.begin(), indices.end(), PriceSort(prices, false));
4305 
4306  vector<string> newlocs;
4307  vector<float> newprices;
4308 
4309  newlocs.reserve(indices.size());
4310  newprices.reserve(indices.size());
4311  { for (size_t i=0; i<indices.size() && i<toprank; ++i) {
4312  newlocs.push_back(locs[indices[i]]);
4313  newprices.push_back(prices[indices[i]]);
4314  } }
4315 
4316  // Save new rank list
4317  saveDataList(whichplayer, lopricek, newprices);
4318  saveStringList(whichplayer, lolock, newlocs);
4319  }
4320  }
4321  }
4322 
4323  // Now build the top-ranking descriptions
4324  {
4325  const vector<string> &recordedHighestLocs = getStringList(whichplayer, hilock);
4326  const vector<string> &recordedLowestLocs = getStringList(whichplayer, lolock);
4327  const vector<float> &recordedHighestPrices = getSaveData(whichplayer, hipricek);
4328  const vector<float> &recordedLowestPrices = getSaveData(whichplayer, lopricek);
4329 
4330  string prefix = " ";
4331  char conversionBuffer[128];
4332 
4333  VSFileSystem::vs_dprintf(1,"Tracking data:\n");
4334  VSFileSystem::vs_dprintf(1," highest locs: (%d)\n", recordedHighestLocs.size());
4335  { for (size_t i=0; i < recordedHighestLocs.size(); ++i) {
4336  VSFileSystem::vs_dprintf(1, " %d : %s\n", i, recordedHighestLocs[i].c_str());
4337  } }
4338 
4339  VSFileSystem::vs_dprintf(1," highest prices: (%d)\n", recordedHighestPrices.size());
4340  { for (size_t i=0; i < recordedHighestPrices.size(); ++i) {
4341  VSFileSystem::vs_dprintf(1, " %d : %.2f\n", i, recordedHighestPrices[i]);
4342  } }
4343 
4344  VSFileSystem::vs_dprintf(1," loest locs: (%d)\n", recordedLowestLocs.size());
4345  { for (size_t i=0; i < recordedLowestLocs.size(); ++i) {
4346  VSFileSystem::vs_dprintf(1, " %d : %s\n", i, recordedLowestLocs[i].c_str());
4347  } }
4348 
4349  VSFileSystem::vs_dprintf(1," lowest prices: (%d)\n", recordedLowestPrices.size());
4350  { for (size_t i=0; i < recordedLowestPrices.size(); ++i) {
4351  VSFileSystem::vs_dprintf(1, " %d : %.2f\n", i, recordedLowestPrices[i]);
4352  } }
4353 
4354  fflush(stderr);
4355 
4356 
4357  highest.clear();
4358  highest.resize(recordedHighestPrices.size());
4359  { for (size_t i=0; i < recordedHighestPrices.size(); ++i) {
4360  string &text = highest[i];
4361  PRETTY_ADD( "", recordedHighestPrices[i], 2 );
4362  text += " (at " + recordedHighestLocs[i] + ")";
4363 
4364  VSFileSystem::vs_dprintf(1, "Highest item %s\n", text.c_str());
4365  } }
4366 
4367  lowest.clear();
4368  lowest.resize(recordedLowestPrices.size());
4369  { for (size_t i=0; i < recordedLowestPrices.size(); ++i) {
4370  string &text = lowest[i];
4371  PRETTY_ADD( "", recordedLowestPrices[i], 2 );
4372  text += " (at " + recordedLowestLocs[i] + ")";
4373 
4374  VSFileSystem::vs_dprintf(1, "Lowest item %s\n", text.c_str());
4375  } }
4376  }
4377 }
static GFXColor UnsaturatedColor ( float  r,
float  g,
float  b,
float  a = 1.0f 
)
static

Definition at line 86 of file basecomputer.cpp.

References a.

Referenced by BaseComputer::constructControls().

87 {
88  GFXColor ret( r, g, b, a );
89  return ret;
90 }
bool UpgradeAllowed ( const Cargo item,
Unit playerUnit 
)

Definition at line 2380 of file basecomputer.cpp.

References Cargo::category, color_prohibited_upgrade_flag, Cargo::content, Unit::faction, Unit::GetCargo(), FactionUtil::GetFactionName(), i, UniverseUtil::LookupUnitStat(), Unit::name, Unit::numCargo(), and Cargo::quantity.

Referenced by BaseComputer::isTransactionOK().

2381 {
2382  std::string prohibited_upgrades =
2384  playerUnit->faction ), "Prohibited_Upgrades" );
2385  while ( prohibited_upgrades.length() ) {
2386  std::string::size_type where = prohibited_upgrades.find( " " );
2387  if (where == string::npos) where = prohibited_upgrades.find( ";" );
2388  std::string prohibited_upgrade = prohibited_upgrades;
2389  if (where != string::npos) {
2390  prohibited_upgrade = prohibited_upgrades.substr( 0, where );
2391  prohibited_upgrades = prohibited_upgrades.substr( where+1 );
2392  } else {prohibited_upgrades = ""; } where = prohibited_upgrade.find( ":" );
2393  std::string content = prohibited_upgrade.substr( 0, where );
2394  int quantity = 0;
2395  if (where != string::npos) {
2396  std::string tmp = prohibited_upgrade.substr( where+1 );
2397  quantity = atoi( tmp.c_str() );
2398  }
2399  if ( item.content == content || ( 0 == string( item.category ).find( content ) ) ) {
2400  if (quantity == 0) {
2402  return false;
2403  }
2404  unsigned int i = 0;
2405  Cargo *numUpgrades = playerUnit->GetCargo( item.content, i );
2406  if (numUpgrades) {
2407  if (numUpgrades->quantity >= quantity) {
2409  return false;
2410  }
2411  }
2412  unsigned int limit = playerUnit->numCargo();
2413  int totalquant = 0;
2414  for (i = 0; i < limit; ++i) {
2415  numUpgrades = &( playerUnit->GetCargo( i ) );
2416  if ( numUpgrades && ( 0 == string( numUpgrades->category ).find( content ) ) )
2417  totalquant += numUpgrades->quantity;
2418  }
2419  if (totalquant >= quantity) {
2421  return false;
2422  }
2423  }
2424  }
2425  return true;
2426 }
bool upgradeNotAddedToCargo ( std::string  category)

Definition at line 106 of file basecomputer.cpp.

References i, and weapfiltervec.

Referenced by BaseComputer::isTransactionOK().

107 {
108  for (unsigned int i = 0; i < weapfiltervec.size(); ++i)
109  if (weapfiltervec[i].find( category ) == 0)
110  return true;
111  return false;
112 }
static double usedValue ( double  originalValue)
static

Definition at line 384 of file basecomputer.cpp.

Referenced by BaseComputer::SellUpgradeOperation::concludeTransaction(), SellPrice(), and BaseComputer::updateTransactionControlsForSelection().

385 {
386  return .5*originalValue;
387 }

Variable Documentation

vector< unsigned int > base_keyboard_queue
const string BASIC_REPAIR_DESC
Initial value:
=
"Hire starship mechanics to examine and assess any wear and tear on your craft. They will replace any damaged components on your vessel with the standard components of the vessel you initially purchased. Further upgrades above and beyond the original will not be replaced free of charge. The total assessment and repair cost applies if any components are damaged or need servicing (fuel, wear and tear on jump drive, etc...). If such components are damaged you may save money by repairing them on your own. Your vessel will also be refuelled."

Definition at line 259 of file basecomputer.cpp.

Referenced by BaseComputer::loadBuyUpgradeControls().

const string BASIC_REPAIR_NAME = "Basic Repair & Refuel"
const char CATEGORY_TAG = (-1)
static
bool color_downgrade_or_noncompatible_flag = false
static
bool color_insufficient_money_flag = false
static
bool color_insufficient_space_flag = false
static
bool color_prohibited_upgrade_flag = false
static

Definition at line 133 of file basecomputer.cpp.

Referenced by BaseComputer::loadListPicker(), and UpgradeAllowed().

const string CONFIRM_ID = "Confirm"
static

Definition at line 3473 of file basecomputer.cpp.

std::string CurrentSaveGameName
std::string emergency_downgrade_mode
const string GOT_MOUNT_ID = "GotMount"
static

Definition at line 3471 of file basecomputer.cpp.

const string GOT_TURRET_ID = "GotTurret"
static

Definition at line 3472 of file basecomputer.cpp.

const string LOAD_FAILED = "LOAD_FAILED"
static

Definition at line 226 of file basecomputer.cpp.

Referenced by buyShip(), and BaseComputer::UpgradeOperation::endInit().

const char* const MISSION_DESC_LABEL = "mission_descriptions"
static
const char* const MISSION_NAMES_LABEL = "mission_names"
static
const char* const MISSION_SCRIPTS_LABEL = "mission_scripts"
static
const float MODE_BUTTON_SPACE = 0.03
static

Definition at line 182 of file basecomputer.cpp.

Referenced by BaseComputer::createModeButtons().

const ModeInfo modeInfo[]
static
Initial value:
= {
ModeInfo( "Cargo Dealer ", "Cargo", "CargoMode", "CargoGroup" ),
ModeInfo( "Ship Upgrades ", "Upgrades", "UpgradeMode", "UpgradeGroup" ),
ModeInfo( "New Ships ", "Ships", "ShipDealerMode", "ShipDealerGroup" ),
ModeInfo( "Missions BBS ", "Missions", "MissionsMode", "MissionsGroup" ),
ModeInfo( "GNN News ", "News", "NewsMode", "NewsGroup" ),
ModeInfo( "Info/Stats ", "Info", "InfoMode", "InfoGroup" ),
ModeInfo( "Load / Save ", "LoadSave", "LoadSaveMode", "LoadSaveGroup" ),
ModeInfo( "Network ", "Network", "NetworkMode", "NetworkGroup" )
}

Definition at line 277 of file basecomputer.cpp.

const char* const NEWS_NAME_LABEL = "news"
static

Definition at line 217 of file basecomputer.cpp.

Referenced by BaseComputer::loadNewsControls().

std::vector< std::string > weapfiltervec = getWeapFilterVec()
const char* WeaponTypeStrings[]
static
Initial value:
= {
"UNKNOWN",
"BEAM",
"BALL",
"BOLT",
"PROJECTILE"
}

Definition at line 4810 of file basecomputer.cpp.