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
communication.h
Go to the documentation of this file.
1 #ifndef _COMMUNICATION_H_
2 #define _COMMUNICATION_H_
3 #include "cmd/unit_generic.h"
4 
5 class FSM
6 {
7 protected:
8 public:
9  struct Node
10  {
11  vector< std::string > messages;
12  vector< std::string > soundfiles; //messages.size() sound file path for each sex
13  vector< int >sounds; //messages.size() sound for each sex
14  float messagedelta;
15  vector< unsigned int >edges;
16  int GetSound( unsigned char sex, unsigned int multiple );
17  bool StopSound( unsigned char sex );
18  std::string GetMessage( unsigned int &multiple ) const;
19  void AddSound( std::string soundfile, unsigned char sex );
20  Node( const vector< std::string > &message, float messagedel ) : messages( message )
21  , messagedelta( messagedel )
22  {
23  if (messages.size() == 0) messages.push_back( "<static>" );
24  }
25  static Node MakeNode( std::string message, float messagedel )
26  {
27  vector< string >tmp;
28  tmp.push_back( message );
29  return Node( tmp, messagedel );
30  }
31  };
32  vector< Node >nodes;
33  bool StopAllSounds( unsigned char sex );
34  FSM(const std::string& filename);
35  void LoadXML( const char *factionfile );
36  void beginElement( const string &name, const AttributeList attributes );
37  static void beginElement( void *userData, const XML_Char *name, const XML_Char **atts );
38  static void endElement( void *userData, const XML_Char *name );
39  std::string GetEdgesString( unsigned int curstate );
40  float getDeltaRelation( int prevstate, unsigned int curstate ) const;
41  int getCommMessageMood( int curstate, float mood, float randomresponsefactor, float relationship ) const;
42  int getDefaultState( float relationship ) const;
43  int GetUnDockNode() const;
44  int GetFailDockNode() const;
45  int GetDockNode() const;
46  int GetAbleToDockNode() const;
47  int GetUnAbleToDockNode() const;
48  int GetYesNode() const;
49  int GetNoNode() const;
50  int GetHitNode() const;
51  int GetDamagedNode() const;
52  int GetDealtDamageNode() const;
53  int GetScoreKillNode() const;
54  int GetRequestLandNode() const;
55  int GetContrabandInitiateNode() const;
56  int GetContrabandUnDetectedNode() const;
57  int GetContrabandDetectedNode() const;
58  int GetContrabandWobblyNode() const;
59 };
60 
62 {
63  void Init( Unit *send, Unit *recv );
64  void SetAnimation( std::vector< class Animation* > *ani, unsigned char sex );
65 public:
66  FSM *fsm; //the finite state that this communcation stage is in
67  class Animation*ani;
68  unsigned char sex; //which sound should play
69  int prevstate;
70  int curstate;
71  int edgenum; //useful for server validation, -1 = did not move via an edge.
73  CommunicationMessage( Unit *send, Unit *recv, std::vector< class Animation* > *ani, unsigned char sex );
74  CommunicationMessage( Unit *send, Unit *recv, int curstate, std::vector< class Animation* > *ani, unsigned char sex );
76  Unit *recv,
77  int prevvstate,
78  int curstate,
79  std::vector< class Animation* > *ani,
80  unsigned char sex );
81  CommunicationMessage( Unit *send, Unit *recv, const CommunicationMessage &prevsvtate, int curstate,
82  std::vector< class Animation* > *ani, unsigned char sex );
83  void SetCurrentState( int message, std::vector< class Animation* > *ani, unsigned char sex );
85  {
86  if ( curstate < (int) fsm->nodes.size() ) {
87  return &fsm->nodes[curstate];
88  } else {
89  int cs = fsm->getDefaultState( 0 );
90  if ( cs < (int) fsm->nodes.size() )
91  return &fsm->nodes[cs];
92  fprintf( stderr, "Critical error: fsm has less than 3 nodes\n" );
93  return &fsm->nodes[0];
94  }
95  }
96  const vector< FSM::Node >& GetPossibleState() const;
97  float getDeltaRelation() const
98  {
100  }
101 };
102 #endif
103