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
fg_util Namespace Reference

Functions

void itoa (unsigned int dat, char *output)
 
std::string MakeFactionKey (int faction)
 
bool IsFGKey (const std::string &fgcandidate)
 
std::string MakeFGKey (const std::string &fgname, int faction)
 
std::string MakeStarSystemFGKey (const std::string &starsystem)
 
unsigned int ShipListOffset ()
 
unsigned int PerShipDataSize ()
 
bool CheckFG (std::vector< std::string > &data)
 
bool CheckFG (SaveGame *sg, const std::string &fgname, unsigned int faction)
 
void PurgeZeroShips (SaveGame *sg, unsigned int faction)
 
void PurgeZeroShips (SaveGame *sg)
 

Variables

static std::string gFG = "FG:"
 
static std::string gSS = "SS:"
 

Function Documentation

bool fg_util::CheckFG ( std::vector< std::string > &  data)

Definition at line 69 of file fg_util.cpp.

References i, PerShipDataSize(), and ShipListOffset().

Referenced by CheckFG(), PurgeZeroShips(), and SaveGame::PurgeZeroStarships().

70 {
71  bool retval = false;
72  unsigned int leg = data.size();
73  unsigned int inc = PerShipDataSize();
74  for (unsigned int i = ShipListOffset()+1; i+1 < leg; i += inc) {
75  std::string *numlanded = &data[i+1];
76  std::string *numtotal = &data[i];
77  if (*numlanded != *numtotal) {
78  retval = true;
79  *numlanded = *numtotal;
80  }
81  }
82  return retval;
83 }
bool fg_util::CheckFG ( SaveGame sg,
const std::string &  fgname,
unsigned int  faction 
)

Definition at line 85 of file fg_util.cpp.

References CheckFG(), SaveGame::getMissionStringData(), and MakeFGKey().

86 {
87  std::string key = MakeFGKey( fgname, faction );
88  return CheckFG( sg->getMissionStringData( key ) );
89 }
bool fg_util::IsFGKey ( const std::string &  fgcandidate)

Definition at line 36 of file fg_util.cpp.

Referenced by SaveGame::PurgeZeroStarships().

37 {
38  if (fgcandidate.length() > 3 && fgcandidate[0] == 'F' && fgcandidate[1] == 'G' && fgcandidate[2] == ':') return true;
39  return false;
40 }
void fg_util::itoa ( unsigned int  dat,
char *  output 
)

Definition at line 10 of file fg_util.cpp.

Referenced by MakeFactionKey(), and MakeFGKey().

11 {
12  if (dat == 0) {
13  *output++ = '0';
14  *output = '\0';
15  } else {
16  char *s = output;
17  while (dat) {
18  *s++ = '0'+dat%10;
19  dat /= 10;
20  }
21  *s = '\0';
22  std::reverse( output, s );
23  }
24 }
std::string fg_util::MakeFactionKey ( int  faction)

Definition at line 26 of file fg_util.cpp.

References itoa().

Referenced by PurgeZeroShips().

27 {
28  char output[16];
29  output[0] = 'F';
30  output[1] = 'F';
31  output[2] = ':';
32  itoa( faction, output+3 );
33  return std::string( output );
34 }
std::string fg_util::MakeFGKey ( const std::string &  fgname,
int  faction 
)

Definition at line 44 of file fg_util.cpp.

References gFG, and itoa().

Referenced by CheckFG().

45 {
46  char tmp[16];
47  tmp[0] = '|';
48  itoa( faction, tmp+1 );
49  return gFG+fgname+tmp;
50 }
std::string fg_util::MakeStarSystemFGKey ( const std::string &  starsystem)

Definition at line 54 of file fg_util.cpp.

References gSS.

55 {
56  return gSS+starsystem;
57 }
unsigned int fg_util::PerShipDataSize ( )

Definition at line 64 of file fg_util.cpp.

Referenced by CheckFG().

65 {
66  return 3;
67 }
void fg_util::PurgeZeroShips ( SaveGame sg,
unsigned int  faction 
)

Definition at line 91 of file fg_util.cpp.

References CheckFG(), StarSystemGent::faction, SaveGame::getMissionStringData(), SaveGame::getMissionStringDataLength(), i, and MakeFactionKey().

Referenced by PurgeZeroShips().

92 {
93  std::string key = MakeFactionKey( faction );
94  unsigned int len = sg->getMissionStringDataLength( key );
95  unsigned int i = 0;
96  while (i < len) {
97  CheckFG( sg, sg->getMissionStringData( key )[i] /*flightgroup*/, faction );
98  i += 1;
99  }
100 }
void fg_util::PurgeZeroShips ( SaveGame sg)

Definition at line 102 of file fg_util.cpp.

References factions, i, and PurgeZeroShips().

103 {
104  for (unsigned int i = 0; i < factions.size(); ++i)
105  fg_util::PurgeZeroShips( sg, i );
106 }
unsigned int fg_util::ShipListOffset ( )

Definition at line 59 of file fg_util.cpp.

Referenced by CheckFG().

60 {
61  return 3;
62 }

Variable Documentation

std::string fg_util::gFG = "FG:"
static

Definition at line 42 of file fg_util.cpp.

Referenced by MakeFGKey().

std::string fg_util::gSS = "SS:"
static

Definition at line 52 of file fg_util.cpp.

Referenced by MakeStarSystemFGKey().