Action Class Reference

#include <action.h>

List of all members.

Public Types

 ACTION_MOVE_LEFT
 ACTION_MOVE_RIGHT
 ACTION_UP
 ACTION_DOWN
 ACTION_JUMP
 ACTION_HIGH_JUMP
 ACTION_BACK_JUMP
 ACTION_SHOOT
 ACTION_CHANGE_WEAPON
 ACTION_WIND
 ACTION_NEXT_CHARACTER
 ACTION_CHANGE_CHARACTER
 ACTION_CHANGE_TEAM
 ACTION_SET_SKIN
 ACTION_SYNC_BEGIN
 ACTION_SYNC_END
 ACTION_EXPLOSION
 ACTION_SUPERTUX_STATE
 ACTION_WEAPON_1
 ACTION_WEAPON_2
 ACTION_WEAPON_3
 ACTION_WEAPON_4
 ACTION_WEAPON_5
 ACTION_WEAPON_6
 ACTION_WEAPON_7
 ACTION_WEAPON_8
 ACTION_WEAPON_9
 ACTION_WEAPON_MORE
 ACTION_WEAPON_LESS
 ACTION_SET_TARGET
 ACTION_SET_TIMEOUT
 ACTION_CONSTRUCTION_UP
 ACTION_CONSTRUCTION_DOWN
 ACTION_SET_CHARACTER_ENERGY
 ACTION_WEAPON_STOP_USE
 ACTION_PING
 ACTION_SET_GAME_MODE
 ACTION_SET_MAP
 ACTION_UPDATE_TEAM
 ACTION_NEW_TEAM
 ACTION_DEL_TEAM
 ACTION_ASK_VERSION
 ACTION_ASK_TEAM
 ACTION_SEND_VERSION
 ACTION_SEND_TEAM
 ACTION_SEND_RANDOM
 ACTION_CHAT_MESSAGE
 ACTION_NICKNAME
 ACTION_SET_CHARACTER_PHYSICS
 ACTION_SET_CHARACTER_DIRECTION
 ACTION_CHANGE_STATE
 ACTION_QUIT
 ACTION_WEAPONS1
 ACTION_WEAPONS2
 ACTION_WEAPONS3
 ACTION_WEAPONS4
 ACTION_WEAPONS5
 ACTION_WEAPONS6
 ACTION_WEAPONS7
 ACTION_WEAPONS8
 ACTION_PAUSE
 ACTION_FULLSCREEN
 ACTION_TOGGLE_INTERFACE
 ACTION_CENTER
 ACTION_TOGGLE_WEAPONS_MENUS
 ACTION_CHAT
enum  Action_t {
  ACTION_MOVE_LEFT, ACTION_MOVE_RIGHT, ACTION_UP, ACTION_DOWN,
  ACTION_JUMP, ACTION_HIGH_JUMP, ACTION_BACK_JUMP, ACTION_SHOOT,
  ACTION_CHANGE_WEAPON, ACTION_WIND, ACTION_NEXT_CHARACTER, ACTION_CHANGE_CHARACTER,
  ACTION_CHANGE_TEAM, ACTION_SET_SKIN, ACTION_SYNC_BEGIN, ACTION_SYNC_END,
  ACTION_EXPLOSION, ACTION_SUPERTUX_STATE, ACTION_WEAPON_1, ACTION_WEAPON_2,
  ACTION_WEAPON_3, ACTION_WEAPON_4, ACTION_WEAPON_5, ACTION_WEAPON_6,
  ACTION_WEAPON_7, ACTION_WEAPON_8, ACTION_WEAPON_9, ACTION_WEAPON_MORE,
  ACTION_WEAPON_LESS, ACTION_SET_TARGET, ACTION_SET_TIMEOUT, ACTION_CONSTRUCTION_UP,
  ACTION_CONSTRUCTION_DOWN, ACTION_SET_CHARACTER_ENERGY, ACTION_WEAPON_STOP_USE, ACTION_PING,
  ACTION_SET_GAME_MODE, ACTION_SET_MAP, ACTION_UPDATE_TEAM, ACTION_NEW_TEAM,
  ACTION_DEL_TEAM, ACTION_ASK_VERSION, ACTION_ASK_TEAM, ACTION_SEND_VERSION,
  ACTION_SEND_TEAM, ACTION_SEND_RANDOM, ACTION_CHAT_MESSAGE, ACTION_NICKNAME,
  ACTION_SET_CHARACTER_PHYSICS, ACTION_SET_CHARACTER_DIRECTION, ACTION_CHANGE_STATE, ACTION_QUIT,
  ACTION_WEAPONS1, ACTION_WEAPONS2, ACTION_WEAPONS3, ACTION_WEAPONS4,
  ACTION_WEAPONS5, ACTION_WEAPONS6, ACTION_WEAPONS7, ACTION_WEAPONS8,
  ACTION_PAUSE, ACTION_FULLSCREEN, ACTION_TOGGLE_INTERFACE, ACTION_CENTER,
  ACTION_TOGGLE_WEAPONS_MENUS, ACTION_CHAT
}

Public Member Functions

 Action (Action_t type)
 Action (Action_t type, int value)
 Action (Action_t type, double value)
 Action (Action_t type, double value1, int value2)
 Action (Action_t type, double value1, double value2)
 Action (Action_t type, const std::string &value)
 Action (const char *is)
 ~Action ()
std::ostream & out (std::ostream &os) const
void Push (int val)
void Push (double val)
void Push (std::string val)
void Push (const Point2i &val)
void Push (const Point2d &val)
int PopInt ()
double PopDouble ()
std::string PopString ()
Point2i PopPoint2i ()
Point2d PopPoint2d ()
bool IsEmpty () const
void StoreCharacter (uint team_no, uint char_no)
void StoreActiveCharacter ()
void RetrieveCharacter ()
void SetTimestamp (uint timestamp)
uint GetTimestamp ()
void WritePacket (char *&packet, int &size)
Action_t GetType () const

Static Public Attributes

static const Action_t ACTION_FIRST = ACTION_MOVE_LEFT
static const Action_t ACTION_LAST = ACTION_CHAT

Protected Attributes

Action_t m_type
uint m_timestamp

Private Member Functions

 Action (const Action &an_action)

Private Attributes

std::list< Uint32 > var


Detailed Description

Definition at line 34 of file action.h.


Member Enumeration Documentation

enum Action::Action_t

Enumerator:
ACTION_MOVE_LEFT 
ACTION_MOVE_RIGHT 
ACTION_UP 
ACTION_DOWN 
ACTION_JUMP 
ACTION_HIGH_JUMP 
ACTION_BACK_JUMP 
ACTION_SHOOT 
ACTION_CHANGE_WEAPON 
ACTION_WIND 
ACTION_NEXT_CHARACTER 
ACTION_CHANGE_CHARACTER 
ACTION_CHANGE_TEAM 
ACTION_SET_SKIN 
ACTION_SYNC_BEGIN 
ACTION_SYNC_END 
ACTION_EXPLOSION 
ACTION_SUPERTUX_STATE 
ACTION_WEAPON_1 
ACTION_WEAPON_2 
ACTION_WEAPON_3 
ACTION_WEAPON_4 
ACTION_WEAPON_5 
ACTION_WEAPON_6 
ACTION_WEAPON_7 
ACTION_WEAPON_8 
ACTION_WEAPON_9 
ACTION_WEAPON_MORE 
ACTION_WEAPON_LESS 
ACTION_SET_TARGET 
ACTION_SET_TIMEOUT 
ACTION_CONSTRUCTION_UP 
ACTION_CONSTRUCTION_DOWN 
ACTION_SET_CHARACTER_ENERGY 
ACTION_WEAPON_STOP_USE 
ACTION_PING 
ACTION_SET_GAME_MODE 
ACTION_SET_MAP 
ACTION_UPDATE_TEAM 
ACTION_NEW_TEAM 
ACTION_DEL_TEAM 
ACTION_ASK_VERSION 
ACTION_ASK_TEAM 
ACTION_SEND_VERSION 
ACTION_SEND_TEAM 
ACTION_SEND_RANDOM 
ACTION_CHAT_MESSAGE 
ACTION_NICKNAME 
ACTION_SET_CHARACTER_PHYSICS 
ACTION_SET_CHARACTER_DIRECTION 
ACTION_CHANGE_STATE 
ACTION_QUIT 
ACTION_WEAPONS1 
ACTION_WEAPONS2 
ACTION_WEAPONS3 
ACTION_WEAPONS4 
ACTION_WEAPONS5 
ACTION_WEAPONS6 
ACTION_WEAPONS7 
ACTION_WEAPONS8 
ACTION_PAUSE 
ACTION_FULLSCREEN 
ACTION_TOGGLE_INTERFACE 
ACTION_CENTER 
ACTION_TOGGLE_WEAPONS_MENUS 
ACTION_CHAT 

Definition at line 40 of file action.h.

00041   {
00042     // Game action.
00043     ACTION_MOVE_LEFT,   ACTION_MOVE_RIGHT, ACTION_UP,   ACTION_DOWN, ACTION_JUMP,
00044     ACTION_HIGH_JUMP,   ACTION_BACK_JUMP, ACTION_SHOOT, ACTION_CHANGE_WEAPON,
00045     ACTION_WIND,        ACTION_NEXT_CHARACTER,          ACTION_CHANGE_CHARACTER,
00046     ACTION_CHANGE_TEAM, ACTION_SET_SKIN,                ACTION_SYNC_BEGIN,
00047     ACTION_SYNC_END,    ACTION_EXPLOSION,               ACTION_SUPERTUX_STATE,
00048     ACTION_WEAPON_1,    ACTION_WEAPON_2,                ACTION_WEAPON_3,
00049     ACTION_WEAPON_4,    ACTION_WEAPON_5,                ACTION_WEAPON_6,
00050     ACTION_WEAPON_7,    ACTION_WEAPON_8,                ACTION_WEAPON_9,
00051     ACTION_WEAPON_MORE, ACTION_WEAPON_LESS,             ACTION_SET_TARGET,
00052     ACTION_SET_TIMEOUT, ACTION_CONSTRUCTION_UP,         ACTION_CONSTRUCTION_DOWN,
00053     ACTION_SET_CHARACTER_ENERGY, ACTION_WEAPON_STOP_USE,
00054 
00055     // Game initialisation
00056     ACTION_PING,        ACTION_SET_GAME_MODE,           ACTION_SET_MAP,
00057     ACTION_UPDATE_TEAM, ACTION_NEW_TEAM,                ACTION_DEL_TEAM,
00058     ACTION_ASK_VERSION, ACTION_ASK_TEAM,                ACTION_SEND_VERSION,
00059     ACTION_SEND_TEAM,   ACTION_SEND_RANDOM,             ACTION_CHAT_MESSAGE,
00060     ACTION_NICKNAME,    ACTION_SET_CHARACTER_PHYSICS,   ACTION_SET_CHARACTER_DIRECTION,
00061     ACTION_CHANGE_STATE,
00062 
00063     // Out of game actions (local only).
00064     ACTION_QUIT,        ACTION_WEAPONS1,                ACTION_WEAPONS2,
00065     ACTION_WEAPONS3,    ACTION_WEAPONS4,                ACTION_WEAPONS5,
00066     ACTION_WEAPONS6,    ACTION_WEAPONS7,                ACTION_WEAPONS8,
00067     ACTION_PAUSE,       ACTION_FULLSCREEN,              ACTION_TOGGLE_INTERFACE,
00068     ACTION_CENTER,      ACTION_TOGGLE_WEAPONS_MENUS,    ACTION_CHAT,
00069   } Action_t;


Constructor & Destructor Documentation

Action::Action ( const Action an_action  )  [private]

Action::Action ( Action_t  type  ) 

Definition at line 33 of file action.cpp.

00034 {
00035   var.clear();
00036   m_type = type;
00037   m_timestamp = Time::GetInstance()->Read();
00038 }

Here is the call graph for this function:

Action::Action ( Action_t  type,
int  value 
)

Definition at line 41 of file action.cpp.

00041                                         : m_type(type)
00042 {
00043   var.clear();
00044   Push(value);
00045   m_timestamp = Time::GetInstance()->Read();
00046 }

Here is the call graph for this function:

Action::Action ( Action_t  type,
double  value 
)

Definition at line 48 of file action.cpp.

00048                                            : m_type(type)
00049 {
00050   var.clear();
00051   Push(value);
00052   m_timestamp = Time::GetInstance()->Read();
00053 }

Here is the call graph for this function:

Action::Action ( Action_t  type,
double  value1,
int  value2 
)

Definition at line 70 of file action.cpp.

00070                                                         : m_type(type)
00071 {
00072   var.clear();
00073   Push(value1);
00074   Push(value2);
00075   m_timestamp = Time::GetInstance()->Read();
00076 }

Here is the call graph for this function:

Action::Action ( Action_t  type,
double  value1,
double  value2 
)

Definition at line 62 of file action.cpp.

00062                                                            : m_type(type)
00063 {
00064   var.clear();
00065   Push(value1);
00066   Push(value2);
00067   m_timestamp = Time::GetInstance()->Read();
00068 }

Here is the call graph for this function:

Action::Action ( Action_t  type,
const std::string &  value 
)

Definition at line 55 of file action.cpp.

00055                                                      : m_type(type)
00056 {
00057   var.clear();
00058   Push(value);
00059   m_timestamp = Time::GetInstance()->Read();
00060 }

Here is the call graph for this function:

Action::Action ( const char *  is  ) 

Definition at line 79 of file action.cpp.

00080 {
00081   var.clear();
00082   m_type = (Action_t)SDLNet_Read32(is);
00083   is += 4;
00084   m_timestamp = (Action_t)SDLNet_Read32(is);
00085   is += 4;
00086   int m_lenght = SDLNet_Read32(is);
00087   is += 4;
00088 
00089   for(int i=0; i < m_lenght; i++)
00090   {
00091     Uint32 val = SDLNet_Read32(is);
00092     var.push_back(val);
00093     is += 4;
00094   }
00095 }

Action::~Action (  ) 

Definition at line 97 of file action.cpp.

00098 {
00099 }


Member Function Documentation

uint Action::GetTimestamp (  ) 

Definition at line 116 of file action.cpp.

00117 {
00118   return m_timestamp;
00119 }

Action::Action_t Action::GetType (  )  const

Definition at line 101 of file action.cpp.

00102 {
00103   return m_type;
00104 }

Here is the caller graph for this function:

bool Action::IsEmpty (  )  const

Definition at line 106 of file action.cpp.

00107 {
00108   return var.empty();
00109 }

std::ostream& Action::out ( std::ostream &  os  )  const

double Action::PopDouble (  ) 

Definition at line 232 of file action.cpp.

00233 {
00234   assert(var.size() > 0);
00235   if(var.size() <= 0)
00236     return 0.0;
00237   double val;
00238   Uint32 tmp[2];
00239 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
00240   tmp[0] = var.front();
00241   var.pop_front();
00242   tmp[1] = var.front();
00243   var.pop_front();
00244   memcpy(&val, &tmp, 8);
00245 #else
00246   tmp[1] = var.front();
00247   var.pop_front();
00248   tmp[0] = var.front();
00249   var.pop_front();
00250   memcpy(&val, &tmp, 8);
00251 #endif
00252 
00253   MSG_DEBUG( "action", " (%s) Poping double : %f",
00254         ActionHandler::GetInstance()->GetActionName(m_type).c_str(), val);
00255   return val;
00256 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Action::PopInt (  ) 

Definition at line 218 of file action.cpp.

00219 {
00220   assert(var.size() > 0);
00221   if(var.size() <= 0)
00222         return 0;
00223   int val;
00224   Uint32 tmp = var.front();
00225   memcpy(&val, &tmp, 4);
00226   var.pop_front();
00227   MSG_DEBUG( "action", " (%s) Poping int : %i",
00228         ActionHandler::GetInstance()->GetActionName(m_type).c_str(), val);
00229   return val;
00230 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2d Action::PopPoint2d (  ) 

Definition at line 303 of file action.cpp.

00304 {
00305   double x, y;
00306   x = PopDouble();
00307   y = PopDouble();
00308   return Point2d(x, y);
00309 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i Action::PopPoint2i (  ) 

Definition at line 295 of file action.cpp.

00296 {
00297   int x, y;
00298   x = PopInt();
00299   y = PopInt();
00300   return Point2i(x, y);
00301 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Action::PopString (  ) 

Definition at line 258 of file action.cpp.

00259 {
00260   assert(var.size() > 1);
00261   if(var.size() <= 1)
00262     return "";
00263   int lenght = PopInt();
00264 
00265   std::string str="";
00266 
00267   assert((int)var.size() >= lenght/4);
00268   if((int)var.size() < lenght/4)
00269     return "";
00270 
00271   while(lenght > 0)
00272   {
00273     Uint32 tmp = var.front();
00274     var.pop_front();
00275     char tmp_str[5] = {0, 0, 0, 0, 0};
00276 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
00277     memcpy(tmp_str, &tmp, 4);
00278     str += tmp_str;
00279     lenght -= 4;
00280 #else
00281     char* c_tmp_str = (char*)(&tmp_str) + 3;
00282     char* c_tmp = (char*)&tmp;
00283     for(int i=0; i < 4; i++)
00284       *(c_tmp_str--) = *(c_tmp++);
00285 
00286     str += tmp_str;
00287     lenght -= 4;
00288 #endif
00289     }
00290   MSG_DEBUG( "action", " (%s) Poping string : %s",
00291         ActionHandler::GetInstance()->GetActionName(m_type).c_str(), str.c_str());
00292   return str;
00293 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action::Push ( const Point2d val  ) 

Definition at line 180 of file action.cpp.

00181 {
00182   Push(val.x);
00183   Push(val.y);
00184 }

Here is the call graph for this function:

void Action::Push ( const Point2i val  ) 

Definition at line 174 of file action.cpp.

00175 {
00176   Push(val.x);
00177   Push(val.y);
00178 }

Here is the call graph for this function:

void Action::Push ( std::string  val  ) 

Definition at line 186 of file action.cpp.

00187 {
00188   //Cut the string into 32bit values
00189   //But first, we write the size of the string:
00190   Push((int)val.size());
00191   char* ch = (char*)val.c_str();
00192 
00193   int count = val.size();
00194   while(count > 0)
00195   {
00196     Uint32 tmp = 0;
00197     // Fix-me : We are reading out of the c_str() buffer there :
00198 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
00199     strncpy((char*)&tmp, ch, 4);
00200     var.push_back(tmp);
00201     ch += 4;
00202     count -= 4;
00203 #else
00204     char* c_tmp = (char*)&tmp;
00205     c_tmp +=3;
00206     for(int i=0; i < 4; i++)
00207       *(c_tmp--) = *(ch++);
00208 
00209     var.push_back(tmp);
00210     count -= 4;
00211 #endif
00212   }
00213   MSG_DEBUG( "action", " (%s) Pushing string : %s",
00214   ActionHandler::GetInstance()->GetActionName(m_type).c_str(), val.c_str());
00215 }

Here is the call graph for this function:

void Action::Push ( double  val  ) 

Definition at line 158 of file action.cpp.

00159 {
00160   Uint32 tmp[2];
00161   memcpy(&tmp, &val, 8);
00162 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
00163   var.push_back(tmp[0]);
00164   var.push_back(tmp[1]);
00165 #else
00166   var.push_back(tmp[1]);
00167   var.push_back(tmp[0]);
00168 #endif
00169 
00170   MSG_DEBUG( "action", " (%s) Pushing double : %f",
00171         ActionHandler::GetInstance()->GetActionName(m_type).c_str(), val);
00172 }

Here is the call graph for this function:

void Action::Push ( int  val  ) 

Definition at line 148 of file action.cpp.

00149 {
00150   Uint32 tmp;
00151   memcpy(&tmp, &val, 4);
00152   var.push_back(tmp);
00153   MSG_DEBUG( "action", " (%s) Pushing int : %i",
00154         ActionHandler::GetInstance()->GetActionName(m_type).c_str(), val);
00155 
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action::RetrieveCharacter (  ) 

Definition at line 339 of file action.cpp.

00340 {
00341   int team_no = PopInt();
00342   int char_no = PopInt();
00343   Character * c = teams_list.FindPlayingByIndex(team_no)->FindByIndex(char_no);
00344   c->SetXY(PopPoint2i());
00345   c->SetDirection((Body::Direction_t)PopInt());
00346   c->SetFiringAngle(PopDouble());
00347   c->SetEnergy(PopInt());
00348   int disease_damage_per_turn = PopInt();
00349   int disease_duration = PopInt();
00350   c->SetDiseaseDamage(disease_damage_per_turn, disease_duration);
00351   c->SetSpeedXY(PopPoint2d());
00352   if((bool)PopInt()) { // If active characters, retrieve stored animation
00353     if(c->GetTeam().IsActiveTeam())
00354       ActiveTeam().SelectCharacter(char_no);
00355     c->SetClothe(PopString());
00356     c->SetMovement(PopString());
00357     c->GetBody()->SetFrame((uint)PopInt());
00358   }
00359 }

Here is the call graph for this function:

void Action::SetTimestamp ( uint  timestamp  ) 

Definition at line 111 of file action.cpp.

00112 {
00113   m_timestamp = timestamp;
00114 }

void Action::StoreActiveCharacter (  ) 

Definition at line 312 of file action.cpp.

00313 {
00314   StoreCharacter(ActiveCharacter().GetTeamIndex() ,ActiveCharacter().GetCharacterIndex());
00315 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action::StoreCharacter ( uint  team_no,
uint  char_no 
)

Definition at line 317 of file action.cpp.

00318 {
00319   Push((int)team_no);
00320   Push((int)char_no);
00321   Character * c = teams_list.FindPlayingByIndex(team_no)->FindByIndex(char_no);
00322   Push(c->GetPosition());
00323   Push((int)c->GetDirection());
00324   Push(c->GetAbsFiringAngle());
00325   Push(c->GetEnergy());
00326   Push((int)c->GetDiseaseDamage());
00327   Push((int)c->GetDiseaseDuration());
00328   Push(c->GetSpeed());
00329   if(c->IsActiveCharacter()) { // If active character, store step animation
00330     Push((int)true);
00331     Push(ActiveTeam().ActiveCharacter().GetBody()->GetClothe());
00332     Push(ActiveTeam().ActiveCharacter().GetBody()->GetMovement());
00333     Push((int)ActiveTeam().ActiveCharacter().GetBody()->GetFrame());
00334   } else {
00335     Push((int)false);
00336   }
00337 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action::WritePacket ( char *&  packet,
int &  size 
)

Definition at line 122 of file action.cpp.

00123 {
00124   size = 4  //Size of the type;
00125         + 4 //Size of the timestamp
00126         + 4 //Size of the number of variable
00127         + int(var.size()) * 4;
00128 
00129   packet = (char*)malloc(size);
00130   char* os = packet;
00131 
00132   SDLNet_Write32(m_type, os);
00133   os += 4;
00134   SDLNet_Write32(m_timestamp, os);
00135   os += 4;
00136   Uint32 param_size = (Uint32)var.size();
00137   SDLNet_Write32(param_size, os);
00138   os += 4;
00139 
00140   for(std::list<Uint32>::iterator val = var.begin(); val!=var.end(); val++)
00141   {
00142     SDLNet_Write32(*val, os);
00143     os += 4;
00144   }
00145 }


Member Data Documentation

const Action_t Action::ACTION_FIRST = ACTION_MOVE_LEFT [static]

Definition at line 71 of file action.h.

const Action_t Action::ACTION_LAST = ACTION_CHAT [static]

Definition at line 72 of file action.h.

uint Action::m_timestamp [protected]

Definition at line 118 of file action.h.

Action_t Action::m_type [protected]

Definition at line 117 of file action.h.

std::list<Uint32> Action::var [private]

Definition at line 37 of file action.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:31:45 2007 for Wormux by  doxygen 1.4.7