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

Functions

std::vector< class Animation * > * GetRandCommAnimation (int faction, Unit *unit, unsigned char &sex)
 
void SerializeFaction (FILE *file)
 
std::string SerializeFaction ()
 
void LoadSerializedFaction (FILE *file)
 
void LoadSerializedFaction (char *&buf)
 
int numnums (const char *str)
 
int GetNumAnimation (int faction)
 returns the index of the faction with that name More...
 
class UnitGetContraband (int faction)
 
const char * GetFaction (int faction)
 
int GetFactionIndex (const std::string &name)
 
int GetUpgradeFaction ()
 
int GetNeutralFaction ()
 
int GetPlanetFaction ()
 
float GetIntRelation (const int myfaction, const int theirfaction)
 
std::string GetFactionName (int index)
 
bool isCitizenInt (int index)
 
bool isCitizen (const std::string &name)
 
void AdjustIntRelation (const int myfaction, const int theirfaction, const float factor, const float rank)
 
int GetPlaylist (const int myfaction)
 
const floatGetSparkColor (const int myfaction)
 
unsigned int GetNumFactions ()
 
FSMGetConversation (const int myfaction, const int theirfaction)
 
TexturegetForceLogo (int faction)
 
TexturegetSquadLogo (int faction)
 
AnimationcreateAnimation (const char *anim)
 
TexturecreateTexture (const char *tex, const char *tmp, bool force=false)
 
TexturecreateTexture (const char *tex, bool force=false)
 
std::vector< class Animation * > * GetAnimation (int faction, int n, unsigned char &sex)
 
AnimationGetRandExplosionAnimation (int whichfaction, std::string &which)
 
void LoadFactionPlaylists ()
 
void LoadContrabandLists ()
 

Variables

int upgradefac = 0
 
int neutralfac = 0
 
int planetfac = 0
 

Function Documentation

void FactionUtil::AdjustIntRelation ( const int  myfaction,
const int  theirfaction,
const float  factor,
const float  rank 
)

Definition at line 90 of file faction_util_generic.cpp.

References vs_options::AllowCivilWar, vs_options::AllowNonplayerFactionChange, vs_options::CappedFactionRating, StarSystemGent::faction, factions, isPlayerFaction(), and vs_options::min_relationship.

91 {
92  assert( factions[Myfaction]->faction[TheirFaction].stats.index == TheirFaction );
93  if (strcmp( factions[Myfaction]->factionname, "neutral" ) != 0) {
94  if (strcmp( factions[Myfaction]->factionname, "upgrades" ) != 0) {
95  if (strcmp( factions[TheirFaction]->factionname, "neutral" ) != 0) {
96  if (strcmp( factions[TheirFaction]->factionname, "upgrades" ) != 0) {
98  if (game_options.AllowCivilWar || Myfaction != TheirFaction) {
99  factions[Myfaction]->faction[TheirFaction].relationship += factor*rank;
100  if (factions[Myfaction]->faction[TheirFaction].relationship > 1 && game_options.CappedFactionRating)
101  factions[Myfaction]->faction[TheirFaction].relationship = 1;
102  if (factions[Myfaction]->faction[TheirFaction].relationship < game_options.min_relationship)
103  factions[Myfaction]->faction[TheirFaction].relationship = game_options.min_relationship;
105  factions[TheirFaction]->faction[Myfaction].relationship =
106  factions[Myfaction]->faction[TheirFaction].relationship; //reflect if player
107  }
108  }
109  }
110  }
111  }
112  }
113 }
Animation * FactionUtil::createAnimation ( const char *  anim)

Definition at line 124 of file faction_util.cpp.

Referenced by Faction::beginElement().

125 {
126  return new Animation( anim );
127 }
Texture * FactionUtil::createTexture ( const char *  tex,
const char *  tmp,
bool  force = false 
)

Definition at line 137 of file faction_util.cpp.

References GFXFALSE, GFXTRUE, MIPMAP, BaseUtil::Texture(), TEXTURE2D, and TEXTURE_2D.

Referenced by getForceLogo(), getSquadLogo(), and SphereMesh::InitSphere().

138 {
139  if (force)
140  return new Texture( tex, tmp, 0, MIPMAP, TEXTURE2D, TEXTURE_2D, 1, 0, GFXTRUE );
141  else
142  return new Texture( tex, tmp, 0, MIPMAP, TEXTURE2D, TEXTURE_2D, 1, 0, GFXFALSE );
143 }
Texture * FactionUtil::createTexture ( const char *  tex,
bool  force = false 
)

Definition at line 129 of file faction_util.cpp.

References GFXFALSE, GFXTRUE, MIPMAP, BaseUtil::Texture(), TEXTURE2D, and TEXTURE_2D.

130 {
131  if (force)
132  return new Texture( tex, 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE );
133  else
134  return new Texture( tex, 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXFALSE );
135 }
std::vector< Animation * > * FactionUtil::GetAnimation ( int  faction,
int  n,
unsigned char &  sex 
)

Definition at line 59 of file faction_util.cpp.

References StarSystemGent::faction, and factions.

Referenced by GetRandCommAnimation().

60 {
61  sex = factions[faction]->comm_face_sex[n];
62  return &factions[faction]->comm_faces[n].animations;
63 }
Unit * FactionUtil::GetContraband ( int  faction)
FSM * FactionUtil::GetConversation ( const int  myfaction,
const int  theirfaction 
)

Definition at line 18 of file faction_util_generic.cpp.

References StarSystemGent::faction, and factions.

Referenced by CommunicatingAI::Destroy(), FireKeyboard::Execute(), CommunicatingAI::ProcessCommMessage(), and CommunicatingAI::RandomInitiateCommunication().

19 {
20  assert( factions[Myfaction]->faction[TheirFaction].stats.index == TheirFaction );
21  return factions[Myfaction]->faction[TheirFaction].conversation.get();
22 }
Texture * FactionUtil::getForceLogo ( int  faction)

Definition at line 17 of file faction_util.cpp.

References createTexture(), StarSystemGent::faction, and factions.

Referenced by getSquadLogo().

18 {
19  boost::shared_ptr<Faction> fac = factions[faction];
20  if (fac->logo == 0) {
21  if ( !fac->logoName.empty() ) {
22  if ( !fac->logoAlphaName.empty() )
23  fac->logo = FactionUtil::createTexture( fac->logoName.c_str(), fac->logoAlphaName.c_str(), true );
24 
25  else
26  fac->logo = FactionUtil::createTexture( fac->logoName.c_str(), true );
27  } else {
28  fac->logo = FactionUtil::createTexture( "white.png", true );
29  }
30  }
31  return factions[faction]->logo;
32 }
float FactionUtil::GetIntRelation ( const int  myfaction,
const int  theirfaction 
)
inline

Definition at line 139 of file faction_generic.h.

References factions.

Referenced by UnitUtil::getFactionRelation(), UniverseUtil::GetRelation(), UnitUtil::getRelationFromFaction(), UnitUtil::getRelationToFaction(), and ScoreKill().

140 {
141  return factions[myfaction]->faction[theirfaction].relationship;
142 }
int FactionUtil::GetNumAnimation ( int  faction)

returns the index of the faction with that name

Definition at line 52 of file faction_util.cpp.

References StarSystemGent::faction, and factions.

53 {
54  return factions[faction]->comm_faces.size();
55 }
unsigned int FactionUtil::GetNumFactions ( )
int FactionUtil::GetPlanetFaction ( )
inline

Definition at line 134 of file faction_generic.h.

References planetfac.

Referenced by Planet::InitPlanet(), ScoreKill(), and BaseComputer::showPlayerInfo().

135 {
136  return planetfac;
137 }
int FactionUtil::GetPlaylist ( const int  myfaction)

Definition at line 114 of file faction_util_generic.cpp.

References factions.

115 {
116  return factions[myfaction]->playlist; //can be -1
117 }
std::vector< Animation * > * FactionUtil::GetRandCommAnimation ( int  faction,
Unit unit,
unsigned char &  sex 
)

Definition at line 65 of file faction_util.cpp.

References Faction::comm_face_t::base, Faction::comm_face_t::CEITHER, Faction::comm_face_t::CNO, Faction::comm_face_t::CYES, Faction::comm_face_t::dockable, StarSystemGent::faction, factions, fprintf, GetAnimation(), UnitUtil::getFlightgroupName(), i, and UnitUtil::isDockableUnit().

Referenced by Pilot::getCommFace(), and Pilot::SetComm().

66 {
67  bool dockable = UnitUtil::isDockableUnit( un );
68  bool base = UnitUtil::getFlightgroupName( un ) == "Base";
69  int siz = factions[faction]->comm_faces.size();
70  if (siz > 0) {
71  for (int i = 0; i < 8+siz; ++i) {
72  int ind = i < 8 ? rand()%siz : i-8;
73  Faction::comm_face_t *tmp = &factions[faction]->comm_faces[ind];
75  || (tmp->dockable == Faction::comm_face_t::CYES && dockable)
76  || (tmp->dockable == Faction::comm_face_t::CNO && !dockable) ) {
78  || (tmp->base == Faction::comm_face_t::CYES && base)
79  || (tmp->base == Faction::comm_face_t::CNO && !base) )
80  return GetAnimation( faction, ind, sex );
81  }
82  if (tmp->base == Faction::comm_face_t::CYES && base)
83  return GetAnimation( faction, ind, sex ); //bases may be dockable but we have set dockable_only to no
84  }
85  fprintf( stderr,
86  "Error picking comm animation for %d faction with bas:%d dock:%d\n",
87  faction,
88  (int) base,
89  (int) dockable );
90  return GetAnimation( faction, rand()%siz, sex );
91  } else {
92  sex = 0;
93  return NULL;
94  }
95 }
Animation * FactionUtil::GetRandExplosionAnimation ( int  whichfaction,
std::string &  which 
)

Definition at line 97 of file faction_util.cpp.

References factions.

Referenced by GameUnit< UnitType >::Explode().

98 {
99  if ( whichfaction < (int) factions.size() ) {
100  if ( factions[whichfaction]->explosion_name.size() ) {
101  int whichexp = rand()%factions[whichfaction]->explosion_name.size();
102  which = factions[whichfaction]->explosion_name[whichexp];
103  return factions[whichfaction]->explosion[whichexp].get();
104  }
105  }
106  return NULL;
107 }
const float * FactionUtil::GetSparkColor ( const int  myfaction)
Texture * FactionUtil::getSquadLogo ( int  faction)

Definition at line 34 of file faction_util.cpp.

References createTexture(), StarSystemGent::faction, factions, and getForceLogo().

35 {
36  boost::shared_ptr<Faction> fac = factions[faction];
37  if (fac->secondaryLogo == 0) {
38  if ( !fac->secondaryLogoName.empty() ) {
39  if ( !fac->secondaryLogoAlphaName.empty() )
40  fac->secondaryLogo = FactionUtil::createTexture(
41  fac->secondaryLogoName.c_str(), fac->secondaryLogoAlphaName.c_str(), true );
42 
43  else
44  fac->secondaryLogo = FactionUtil::createTexture( fac->secondaryLogoName.c_str(), true );
45  } else {
46  return getForceLogo( faction );
47  }
48  }
49  return factions[faction]->secondaryLogo;
50 }
bool FactionUtil::isCitizen ( const std::string &  name)

Definition at line 67 of file faction_util_generic.cpp.

References GetFactionIndex(), and isCitizenInt().

68 {
69  return isCitizenInt( GetFactionIndex( name ) );
70 }
bool FactionUtil::isCitizenInt ( int  index)
void FactionUtil::LoadContrabandLists ( )

Still in faction_xml.cpp because createUnit

Definition at line 382 of file faction_xml.cpp.

References contrabandlists, UnitFactory::createUnit(), factions, and i.

Referenced by bootstrap_main_loop().

383 {
384  for (unsigned int i = 0; i < factions.size() && i < contrabandlists.size(); i++)
385  if (contrabandlists[i].length() > 0)
386  factions[i]->contraband.reset(UnitFactory::createUnit( contrabandlists[i].c_str(), true, i ));
387  contrabandlists.clear();
388 }
void FactionUtil::LoadFactionPlaylists ( )

Definition at line 115 of file faction_util.cpp.

References Music::Addlist(), factions, GetFaction(), i, and muzak.

Referenced by createObjects().

116 {
117  for (unsigned int i = 0; i < factions.size(); i++) {
118  string fac = FactionUtil::GetFaction( i );
119  fac += ".m3u";
120  factions[i]->playlist = muzak->Addlist( fac.c_str() );
121  }
122 }
void FactionUtil::LoadSerializedFaction ( FILE *  file)

Definition at line 155 of file faction_util_generic.cpp.

References StarSystemGent::faction, factions, j, k, and numnums().

Referenced by LoadSerializedFaction(), Faction::LoadXML(), and SaveGame::ReadSavedPackets().

156 {
157  for (unsigned int i = 0; i < factions.size(); i++) {
158  char *tmp = new char[24*factions[i]->faction.size()];
159  static char *bogus_return; //added by chuck_starchaser to squash a warning
160  bogus_return = fgets( tmp, 24*factions[i]->faction.size()-1, fp );
161  char *tmp2 = tmp;
162  if (numnums( tmp ) == 0) {
163  i--;
164  continue;
165  }
166  for (unsigned int j = 0; j < factions[i]->faction.size(); j++) {
167  if ( 1 != sscanf( tmp2, "%f ", &factions[i]->faction[j].relationship ) )
168  printf( "err" );
169  int k = 0;
170  bool founddig = false;
171  while (tmp2[k]) {
172  if ( isdigit( tmp2[k] ) )
173  founddig = true;
174  if ( founddig && (!isdigit( tmp2[k] ) && tmp2[k] != '.') )
175  break;
176  k++;
177  }
178  tmp2 += k;
179  if (*tmp2 == '\r' || *tmp2 == '\n')
180  break;
181  }
182  delete[] tmp;
183  }
184 }
void FactionUtil::LoadSerializedFaction ( char *&  buf)

Definition at line 196 of file faction_util_generic.cpp.

References blah, bleh, StarSystemGent::faction, factions, j, k, LoadSerializedFaction(), numnums(), savedFactions, and whitespaceNewline().

197 {
198  if (buf == NULL) {
199  char *bleh = strdup( savedFactions.c_str() );
200  char *blah = bleh;
201  LoadSerializedFaction( blah );
202  free( bleh );
203  return;
204  }
205  if (factions.size() == 0) {
206  savedFactions = buf;
207  return;
208  }
209  for (unsigned int i = 0; i < factions.size(); i++) {
210  if (numnums( buf ) == 0)
211  return;
212  for (unsigned int j = 0; j < factions[i]->faction.size(); j++) {
213  sscanf( buf, "%f ", &factions[i]->faction[j].relationship );
214  int k = 0;
215  bool founddig = false;
216  while (buf[k]) {
217  if ( isdigit( buf[k] ) )
218  founddig = true;
219  if ( founddig && (!isdigit( buf[k] ) && buf[k] != '.') )
220  break;
221  k++;
222  }
223  buf += k;
224  if ( whitespaceNewline( buf ) )
225  break;
226  }
227  }
228 }
int FactionUtil::numnums ( const char *  str)

Definition at line 148 of file faction_util_generic.cpp.

Referenced by LoadSerializedFaction().

149 {
150  int count = 0;
151  for (int i = 0; str[i]; i++)
152  count += (str[i] >= '0' && str[i] <= '9') ? 1 : 0;
153  return count;
154 }
void FactionUtil::SerializeFaction ( FILE *  file)

Definition at line 126 of file faction_util_generic.cpp.

References StarSystemGent::faction, factions, j, and VSFileSystem::vs_fprintf().

Referenced by SaveGame::WriteDynamicUniverse().

127 {
128  for (unsigned int i = 0; i < factions.size(); i++) {
129  for (unsigned int j = 0; j < factions[i]->faction.size(); j++)
130  VSFileSystem::vs_fprintf( fp, "%g ", factions[i]->faction[j].relationship );
131  VSFileSystem::vs_fprintf( fp, "\n" );
132  }
133 }
string FactionUtil::SerializeFaction ( )

Definition at line 134 of file faction_util_generic.cpp.

References StarSystemGent::faction, factions, and j.

135 {
136  char temp[8192];
137  string ret( "" );
138  for (unsigned int i = 0; i < factions.size(); i++) {
139  for (unsigned int j = 0; j < factions[i]->faction.size(); j++) {
140  sprintf( temp, "%g ", factions[i]->faction[j].relationship );
141  ret += string( temp );
142  }
143  sprintf( temp, "\n" );
144  ret += string( temp );
145  }
146  return ret;
147 }

Variable Documentation

int FactionUtil::neutralfac = 0
int FactionUtil::planetfac = 0

Definition at line 16 of file faction_util_generic.cpp.

Referenced by Faction::beginElement(), and GetPlanetFaction().

int FactionUtil::upgradefac = 0