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
unit_functions.cpp
Go to the documentation of this file.
1 #include "unit.h"
2 #include "gfx/vec.h"
3 #include "gfx/animation.h"
4 #include "gfx/cockpit_generic.h"
5 #include "faction_generic.h"
6 #include "savegame.h"
7 #include "xml_support.h"
8 #include "unit_factory.h"
9 #include "gfx/halo.h"
10 #include "gfx/mesh.h"
11 #include "gfx/sphere.h"
12 #include "gfx/sprite.h"
13 #include "audiolib.h"
15 #include "unit_collide.h"
16 #include <string>
17 #include <set>
18 
19 //Various functions that were used in .cpp files that are now included because of
20 //the temple GameUnit class
21 //If not separated from those files functions would be defined in multiple places
22 //Those functions are client specific
23 
24 //Wrappers used in unit_xml.cpp
25 VSSprite * createVSSprite( const char *file )
26 {
27  return new VSSprite( file );
28 }
29 bool isVSSpriteLoaded( const VSSprite *sprite )
30 {
31  return sprite->LoadSuccess();
32 }
33 void deleteVSSprite( VSSprite *sprite )
34 {
35  delete sprite;
36 }
37 //From communication_xml.cpp
38 int createSound( string file, bool val )
39 {
40  return AUDCreateSoundWAV( file, val );
41 }
42 
43 //From unit_xml.cpp
44 using vsUMap;
45 static vsUMap< std::string, Animation* >cached_ani;
46 std::set< std::string >tempcache;
47 void cache_ani( string s )
48 {
49  tempcache.insert( s );
50 }
52 {
53  for (std::set< std::string >::iterator it = tempcache.begin(); it != tempcache.end(); it++)
54  if ( cached_ani.find( *it ) == cached_ani.end() )
55  cached_ani.insert( std::pair< std::string, Animation* > ( *it,
56  new Animation( (*it).c_str(), false, .1, BILINEAR, false ) ) );
57  tempcache.clear();
58 }
60 {
61  if ( cached_ani.size() ) {
62  unsigned int rn = rand()%cached_ani.size();
63  vsUMap< std::string, Animation* >::iterator j = cached_ani.begin();
64  for (unsigned int i = 0; i < rn; i++)
65  j++;
66  return (*j).first;
67  } else {
68  return "";
69  }
70 }
72 {
73  if ( cached_ani.size() ) {
74  unsigned int rn = rand()%cached_ani.size();
75  vsUMap< std::string, Animation* >::iterator j = cached_ani.begin();
76  for (unsigned int i = 0; i < rn; i++)
77  j++;
78  return (*j).second;
79  } else {
80  return NULL;
81  }
82 }
83