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_util.cpp
Go to the documentation of this file.
1 #include "cmd/unit_generic.h"
2 #include "faction_generic.h"
3 #include "gfx/aux_texture.h"
4 #include "cmd/unit_util.h"
5 #include <assert.h>
6 
7 using namespace FactionUtil;
8 
10 {
11  delete[] factionname;
12  if (contraband.get())
13  contraband->Kill();
14  delete logo;
15 }
16 
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 }
33 //fixme--add squads in here
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 }
51 
53 {
54  return factions[faction]->comm_faces.size();
55 }
56 
57 //COMES FROM FACTION_XML.CPP
58 
59 std::vector< Animation* >* FactionUtil::GetAnimation( int faction, int n, unsigned char &sex )
60 {
61  sex = factions[faction]->comm_face_sex[n];
62  return &factions[faction]->comm_faces[n].animations;
63 }
64 
65 std::vector< Animation* >* FactionUtil::GetRandCommAnimation( int faction, Unit *un, unsigned char &sex )
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 }
96 
97 Animation* FactionUtil::GetRandExplosionAnimation( int whichfaction, std::string &which )
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 }
108 
109 #include "vs_globals.h"
110 #include "cmd/unit_generic.h"
111 #include "gfx/aux_texture.h"
112 #include "gfx/animation.h"
113 #include "cmd/music.h"
114 
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 }
123 
125 {
126  return new Animation( anim );
127 }
128 
129 Texture* FactionUtil::createTexture( const char *tex, bool force )
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 }
136 
137 Texture* FactionUtil::createTexture( const char *tex, const char *tmp, bool force )
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 }
144