/* $Id: player.hpp,v 1.41.4.1 2006/01/20 11:33:53 chfreund Exp $ */ #ifndef _PLAYER_HPP_ #define _PLAYER_HPP_ /**********************************************************/ #include #include #include "global.hpp" #include "serializable.hpp" #include "string.hpp" #include "spriteset.hpp" #include "weapon.hpp" #include "constants.hpp" #include "scorekeeper.hpp" // Forward declaration instead of header including, since class Avatar // does need the interface of class Player to declare two methods of // class Player as friends. class Avatar; /**********************************************************/ //! This class contains all information about a single player /*! This is the class, that represents the player in WoP. The player * is separated from its avatar.
* If the a Player class is created, it must be added to the world * using the function World::addPlayer. World::addPlayer will create * the according avatar object (therefor the World uses the ID stored * in m_avatarType) and add it in the list of objects, that live in * the world, and attach it to the Player class. After that the avatar * is reachable using the function getAvatar(), and this Player object * can be reached from the Avatar object via getPlayer(), vice versa. * If the Player object is removed from the world by calling * World::removePlayer(), its avatar is also removed from the world * and deleted and detached from the player object. So * note: the avatar belonging to a Player object is exactly as long * existent and reachable, as long the Player object is added to the * world. */ class Player : public Serializable { public: static const int m_MAX_WEAPONS = 13, m_IGNORE_N_LAST_WEAPONS = 3; protected: // configurable properties of the player String m_name; //!< the player's name Uint32 m_playerColor; //!< individual color of the player Uint8 m_teamID; //!< team ID in team play Uint32 m_avatarType; //!< object ID of the avatar // internal data Uint8 m_playerID; bool m_isLocalPlayer; //!< true, if this is the local player Avatar *m_avatar; //!< pointer to the players avatar Weapon* m_weapon[m_MAX_WEAPONS]; Uint8 m_activeWeaponIndex; public: Player(); virtual ~Player(); //! returns the player's name const String& getName() const { return m_name; } //! sets the player's name void setName( const char* const name ) { m_name = name; } //! returns the player's color Uint32 getPlayerColor() const { return m_playerColor; } //! sets the player's color == the avatar's player color void setPlayerColor( const Uint32 color ); //! returns the team ID Uint8 getTeamID() const { return m_teamID; } //! sets the team ID void setTeamID( const Uint8 teamID ) { DBG( 2 ) CHECK( teamID < MAX_NUMBER_OF_PLAYERS, "Player::setTeamID: invalid team number\n" ); m_teamID = teamID; } //! returns the player or team ID depending on team play Uint8 getPlayerOrTeamID( void ) const; //! returns the player ID Uint8 getPlayerID( void ) const { return m_playerID; } //! sets the player ID void setPlayerID( const Uint8 playerID ) { m_playerID = playerID; } //! returns true, if this is the local player bool isLocalPlayer() const { return m_isLocalPlayer; } //! sets the flag for the local player and updates the focus priority of its avatar object void setLocalPlayer( const bool flag = true ); //! returns pointer to the player's avatar Avatar* getAvatar() const { return m_avatar; } //! attaches an Avatar object to this player void attachAvatar( Avatar* const avatar ); //! detaches the Avatar object from this player Avatar* detachAvatar(); //! returns the object ID of the player's avatar Uint32 getAvatarType() const { return m_avatarType; } Weapon* getWeapon( int index ) { DBG( 1 ) if( index < 0 || index >= m_MAX_WEAPONS ) { CHECK( false, "Player::getWeapon: weapon index out of range (%i)\n", index ); return NULL; } return m_weapon[index]; } Uint8 getActiveWeaponIndex() const { return m_activeWeaponIndex; } Weapon* getActiveWeapon() { return m_weapon[m_activeWeaponIndex]; } void setActiveWeapon( Uint8 index ) { m_activeWeaponIndex = index; } void rechargeWeaponsNow() { for( int w = 0; w < m_MAX_WEAPONS; w++ ) { m_weapon[w]->rechargeNow(); } } virtual void update(); //! \name (de)serialization //@{ virtual Uint32 getSerializeBufferSize() const; virtual void serialize( Uint8*& bufferPointer ) const; virtual void deserialize( Uint8*& bufferPointer ); //@} void dump( std::ostream& out ) const; private: void updateAvatarData(); }; #endif // _PLAYER_HPP_