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_util.cpp
Go to the documentation of this file.
1 #include <string>
2 #include "unit_generic.h"
3 #include "gfx/cockpit.h"
4 #include "planet_generic.h"
5 #include "gfx/animation.h"
6 #include "config_xml.h"
7 #include "unit_util.h"
8 #include "config_xml.h"
9 #include "vs_globals.h"
10 #include "pilot.h"
11 using std::string;
12 namespace UnitUtil
13 {
14 void switchFg( Unit *my_unit, string arg )
15 {
16  if (!my_unit) return;
17  string type = my_unit->name;
18  int nr_waves_left = 0;
19  int nr_ships = 1;
20  string order( "default" );
21  Flightgroup *fg = my_unit->getFlightgroup();
22  if (fg) {
23  type = fg->type;
24  nr_waves_left = fg->nr_waves_left;
25  nr_ships = 1;
26  fg->Decrement( my_unit );
27  order = fg->ainame;
28  }
30  my_unit->faction ), order, nr_ships, nr_waves_left, "", "", mission );
31  my_unit->SetFg( fg, fg->nr_ships_left-1 );
32 }
33 int communicateTo( Unit *my_unit, Unit *other_unit, float mood )
34 {
35  if (!my_unit) return 0;
36  unsigned char sex = 0;
37  Cockpit *tmp;
38  if ( ( tmp = _Universe->isPlayerStarship( my_unit ) ) ) {
39  if (other_unit) {
40  Animation *ani = other_unit->pilot->getCommFace( other_unit, mood, sex );
41  if (NULL != ani)
42  tmp->SetCommAnimation( ani, other_unit );
43  }
44  }
45  return sex;
46 }
47 bool commAnimation( Unit *my_unit, string anim )
48 {
49  if (!my_unit) return false;
50  Cockpit *tmp;
51  if ( ( tmp = _Universe->isPlayerStarship( my_unit ) ) ) {
52  static Hashtable< std::string, Animation, 63 >AniHashTable;
53  Animation *vid = AniHashTable.Get( anim );
54  if (NULL == vid) {
55  vid = new Animation( anim.c_str() );
56  AniHashTable.Put( anim, vid );
57  }
58  tmp->SetCommAnimation( vid, NULL );
59  return true;
60  } else {
61  return false;
62  }
63 }
64 }
65