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
faction_generic.cpp
Go to the documentation of this file.
1 #include "faction_generic.h"
2 #include "cmd/unit_generic.h"
3 
4 using namespace FactionUtil;
5 
6 vector< boost::shared_ptr<Faction> >factions; //the factions
7 
9 {
10  //MSVC has a bug where it won't let you reuse variables intitliezed in the paramater list of the for loop
11  //the work around is A.) make the scope of the variable in the function level or not to re-define it in subsequent loops
12  unsigned int i = 0;
13  for (i = 0; i < factions.size(); i++)
14  factions[i]->ParseAllies( i );
15  for (i = 0; i < factions.size(); i++)
16  factions[i]->faction[i].relationship = 1;
17 }
18 void Faction::ParseAllies( unsigned int thisfaction )
19 {
20  unsigned int i, j;
21  vector< faction_stuff >tempvec;
22  for (i = 0; i < faction.size(); i++)
23  for (j = 0; j < factions.size(); j++)
24  if (strcmp( faction[i].stats.name, factions[j]->factionname ) == 0) {
25  delete[] faction[i].stats.name;
26  faction[i].stats.index = j;
27  break;
28  }
29  for (i = 0; i < factions.size(); i++) {
30  tempvec.push_back( faction_stuff() );
31  tempvec[i].stats.index = i;
32  tempvec[i].relationship = ( (i == thisfaction) ? 1 : 0 );
33  }
34  for (i = 0; i < faction.size(); i++) {
35  faction_stuff::faction_name tmp = tempvec[faction[i].stats.index].stats;
36  tempvec[faction[i].stats.index] = faction[i];
37  tempvec[faction[i].stats.index].stats = tmp;
38  }
39  faction.swap( tempvec );
40 
41 }
42