1 | |
---|
2 | /*! |
---|
3 | * @file playable.h |
---|
4 | * Interface for a basic controllable WorldEntity |
---|
5 | */ |
---|
6 | #ifndef _PLAYABLE_H |
---|
7 | #define _PLAYABLE_H |
---|
8 | |
---|
9 | #include "world_entity.h" |
---|
10 | #include "extendable.h" |
---|
11 | #include "event.h" |
---|
12 | #include <vector> |
---|
13 | #include <list> |
---|
14 | |
---|
15 | #include "world_entities/weapons/weapon_manager.h" |
---|
16 | |
---|
17 | class Weapon; |
---|
18 | class DotEmitter; |
---|
19 | class Player; |
---|
20 | class SpriteParticles; |
---|
21 | class Explosion; |
---|
22 | |
---|
23 | //! Basic controllable WorldEntity |
---|
24 | /** |
---|
25 | * |
---|
26 | */ |
---|
27 | class Playable : public WorldEntity, public Extendable |
---|
28 | { |
---|
29 | ObjectListDeclaration(Playable); |
---|
30 | public: |
---|
31 | //! Defines the Playmode of an Entity. |
---|
32 | typedef enum { |
---|
33 | Vertical = 1, //!< Vertical (seen from left or right/move in x-z) |
---|
34 | Horizontal = 2, //!< Horizontal (seet from the top/move in x-y) |
---|
35 | FromBehind = 4, //!< Seen from behind (move in z-y) |
---|
36 | Full3D = 8, //!< Full featured 3D-mode. (move in all directions x-y-z) |
---|
37 | FirstPerson = 16, |
---|
38 | |
---|
39 | PlaymodeCount = 5, |
---|
40 | } Playmode; |
---|
41 | |
---|
42 | |
---|
43 | public: |
---|
44 | virtual ~Playable(); |
---|
45 | |
---|
46 | virtual void loadParams(const TiXmlElement* root); |
---|
47 | void varChangeHandler( std::list< int > & id ); |
---|
48 | |
---|
49 | // Weapon and Pickups |
---|
50 | virtual bool pickup(PowerUp* powerUp); |
---|
51 | bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); |
---|
52 | void removeWeapon(Weapon* weapon); |
---|
53 | void nextWeaponConfig(); |
---|
54 | void previousWeaponConfig(); |
---|
55 | inline WeaponManager& getWeaponManager() { return this->weaponMan; }; |
---|
56 | void weaponConfigChanged(); |
---|
57 | static void addSomeWeapons_CHEAT(); |
---|
58 | |
---|
59 | |
---|
60 | // Player Settup |
---|
61 | bool hasPlayer(){return !(this->currentPlayer == NULL);} |
---|
62 | bool setPlayer(Player* player); |
---|
63 | Player* getCurrentPlayer() const { return this->currentPlayer; }; |
---|
64 | /** @return a List of Events in PEV_* sytle */ |
---|
65 | inline const std::vector<int>& getEventList() { return this->events; }; |
---|
66 | |
---|
67 | |
---|
68 | // Camera and Playmode |
---|
69 | void attachCamera(); |
---|
70 | void detachCamera(); |
---|
71 | void setCameraMode(unsigned int cameraMode = 0); |
---|
72 | bool playmodeSupported(Playable::Playmode playmode) const { return this->supportedPlaymodes & playmode; }; |
---|
73 | bool setPlaymode(Playable::Playmode playmode); |
---|
74 | Playable::Playmode getPlaymode() const { return this->playmode; }; |
---|
75 | virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) = 0; |
---|
76 | void setPlayDirection(float angle, float dirX, float dirY, float dirZ, float speed = 0.0f); |
---|
77 | |
---|
78 | // Networking interface |
---|
79 | inline void setScore( int score ) { this->score = score; } |
---|
80 | inline int getScore() { return this->score; } |
---|
81 | inline void setTeamId( int teamId) { this->teamId = teamId;} |
---|
82 | inline int getTeamId() const { return this->teamId; } |
---|
83 | virtual void setTeam(int teamID); |
---|
84 | |
---|
85 | |
---|
86 | void setEnterRadius(float radius) { this->enterRadius = radius; }; |
---|
87 | /** @returns the EnterRadius (how far away a Player must be to enter this entity) */ |
---|
88 | inline float getEnterRadius() const { return this->enterRadius; }; |
---|
89 | |
---|
90 | // WorldEntity Extensions |
---|
91 | virtual void destroy(WorldEntity* killer); |
---|
92 | virtual void respawn(); |
---|
93 | virtual void process(const Event &event); |
---|
94 | virtual void tick(float dt); |
---|
95 | |
---|
96 | |
---|
97 | inline bool beFire() const { return this->bFire; } |
---|
98 | inline void fire(bool bF) { this->bFire = bF;} |
---|
99 | |
---|
100 | // Transformations: |
---|
101 | static Playable::Playmode stringToPlaymode(const std::string& playmode); |
---|
102 | static const std::string& playmodeToString(Playable::Playmode playmode); |
---|
103 | static const std::string playmodeNames[]; |
---|
104 | |
---|
105 | protected: |
---|
106 | Playable(); |
---|
107 | |
---|
108 | // Player Setup |
---|
109 | virtual void enter() = 0; |
---|
110 | virtual void leave() = 0; |
---|
111 | // Playmode |
---|
112 | void setSupportedPlaymodes(short playmodes) { this->supportedPlaymodes = playmodes; }; |
---|
113 | virtual void enterPlaymode(Playable::Playmode playmode); |
---|
114 | |
---|
115 | // Events. |
---|
116 | void registerEvent(int eventType); |
---|
117 | void unregisterEvent(int eventType); |
---|
118 | |
---|
119 | protected: |
---|
120 | WeaponManager weaponMan; //!< the weapon manager: managing a list of weapon to wepaon-slot mapping |
---|
121 | bool bFire; //!< If the Ship is firing. |
---|
122 | short supportedPlaymodes; //!< What Playmodes are Supported in this Playable. |
---|
123 | Playable::Playmode playmode; //!< The current playmode. |
---|
124 | |
---|
125 | private: |
---|
126 | std::vector<int> events; //!< A list of Events, that are captured for this playable |
---|
127 | |
---|
128 | Player* currentPlayer; //!< The Player currently connected to this Playable (the one that has controll) otherwise NULL |
---|
129 | |
---|
130 | int oldFlags; //!< Used for synchronisation |
---|
131 | |
---|
132 | int score; //!< players score |
---|
133 | int teamChangeHandler; //!< handler id for team changes network sync |
---|
134 | int teamId; //!< id of the current team |
---|
135 | |
---|
136 | bool bDead; |
---|
137 | |
---|
138 | float enterRadius; //!< How far one can be away from the Playable to enter it. |
---|
139 | |
---|
140 | WorldEntity* collider; |
---|
141 | }; |
---|
142 | |
---|
143 | #endif /* _PLAYABLE_H */ |
---|