src/include/action.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Define all Wormux actions.
00020  *****************************************************************************/
00021 
00022 #ifndef ACTION_H
00023 #define ACTION_H
00024 //-----------------------------------------------------------------------------
00025 #include <SDL.h>
00026 #include <string>
00027 #include <iostream>
00028 #include <list>
00029 #include "base.h"
00030 #include "../tool/point.h"
00031 
00032 //-----------------------------------------------------------------------------
00033 
00034 class Action
00035 {
00036 private:
00037   std::list<Uint32> var;
00038   Action ( const Action& an_action);
00039 public:
00040   typedef enum
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;
00070 
00071   static const Action_t ACTION_FIRST = ACTION_MOVE_LEFT; /* keep this as the first name in enum */
00072   static const Action_t ACTION_LAST  = ACTION_CHAT; /* keep this as the last name in enum */
00073 
00074   //inline Action_t &operator++() { ;}
00075 
00076   // Action without parameter
00077   Action (Action_t type);
00078   // Action with various parameter
00079   Action (Action_t type, int value);
00080   Action (Action_t type, double value);
00081   Action (Action_t type, double value1, int value2);
00082   Action (Action_t type, double value1, double value2);
00083   Action (Action_t type, const std::string& value);
00084 
00085   // Build an action from a network packet
00086   Action (const char* is);
00087 
00088   ~Action();
00089 
00090   std::ostream& out(std::ostream &os) const;
00091   // Push / Back functions to add / retreive datas
00092   // Work as a FIFO container, inspiteof the name of methods !
00093   void Push(int val);
00094   void Push(double val);
00095   void Push(std::string val);
00096   void Push(const Point2i& val);
00097   void Push(const Point2d& val);
00098   int PopInt();
00099   double PopDouble();
00100   std::string PopString();
00101   Point2i PopPoint2i();
00102   Point2d PopPoint2d();
00103   bool IsEmpty() const;
00104 
00105   // Store character's information
00106   void StoreCharacter(uint team_no, uint char_no);
00107   void StoreActiveCharacter();
00108   void RetrieveCharacter();
00109 
00110   // Timestamp handling
00111   void SetTimestamp(uint timestamp);
00112   uint GetTimestamp();
00113 
00114   void WritePacket(char* & packet, int & size);
00115   Action_t GetType() const;
00116 protected:
00117   Action_t m_type;
00118   uint m_timestamp;
00119 };
00120 
00121 //-----------------------------------------------------------------------------
00122 // Output action in a ostream (for debug)
00123 std::ostream& operator<<(std::ostream& os, const Action &a);
00124 
00125 //-----------------------------------------------------------------------------
00126 #endif

Generated on Mon Jan 1 13:10:57 2007 for Wormux by  doxygen 1.4.7