1 | /*! |
---|
2 | * @file world_entity.h |
---|
3 | * Definition of the basic WorldEntity |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _WORLD_ENTITY_H |
---|
7 | #define _WORLD_ENTITY_H |
---|
8 | |
---|
9 | #include "p_node.h" |
---|
10 | #include "synchronizeable.h" |
---|
11 | #include "model.h" |
---|
12 | |
---|
13 | #include "object_manager.h" |
---|
14 | #include "glincl.h" |
---|
15 | #include <vector> |
---|
16 | |
---|
17 | // FORWARD DECLARATION |
---|
18 | class SoundBuffer; |
---|
19 | class SoundSource; |
---|
20 | class BVTree; |
---|
21 | class Model; |
---|
22 | |
---|
23 | class GLGuiWidget; |
---|
24 | class GLGuiBar; |
---|
25 | |
---|
26 | //class CharacterAttributes; |
---|
27 | |
---|
28 | |
---|
29 | //! Basis-class all interactive stuff in the world is derived from |
---|
30 | class WorldEntity : public PNode |
---|
31 | { |
---|
32 | public: |
---|
33 | WorldEntity(); |
---|
34 | virtual ~WorldEntity (); |
---|
35 | |
---|
36 | virtual void loadParams(const TiXmlElement* root); |
---|
37 | |
---|
38 | void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4); |
---|
39 | void setModel(Model* model, unsigned int modelNumber = 0); |
---|
40 | Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; |
---|
41 | |
---|
42 | inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } |
---|
43 | |
---|
44 | /** @param visibility if the Entity should be visible (been draw) */ |
---|
45 | void setVisibiliy (bool visibility) { this->bVisible = visibility; }; |
---|
46 | /** @returns true if the entity is visible, false otherwise */ |
---|
47 | inline bool isVisible() const { return this->bVisible; }; |
---|
48 | |
---|
49 | virtual void reset(); |
---|
50 | |
---|
51 | virtual void postSpawn (); |
---|
52 | virtual void leaveWorld (); |
---|
53 | virtual void destroy() {}; |
---|
54 | |
---|
55 | virtual void tick (float time); |
---|
56 | virtual void draw () const; |
---|
57 | |
---|
58 | bool buildObbTree(int depth); |
---|
59 | virtual void collidesWith (WorldEntity* entity, const Vector& location); |
---|
60 | /** @returns a reference to the obb tree of this worldentity */ |
---|
61 | inline BVTree* getOBBTree() const { return this->obbTree; }; |
---|
62 | void drawBVTree(int depth, int drawMode) const; |
---|
63 | |
---|
64 | void debugWE() { this->debugEntity(); } |
---|
65 | ; ///FIXME |
---|
66 | void debugEntity() const; |
---|
67 | |
---|
68 | |
---|
69 | /* @returns the Count of Faces on this WorldEntity */ |
---|
70 | //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; }; |
---|
71 | // void addAbility(Ability* ability); |
---|
72 | // void removeAbility(Ability* ability); |
---|
73 | // void setCharacterAttributes(CharacterAttributes* charAttr); |
---|
74 | // CharacterAttributes* getCharacterAttributes(); |
---|
75 | |
---|
76 | void toList(OM_LIST list); |
---|
77 | |
---|
78 | |
---|
79 | /** @returns a Reference to the objectListNumber to set. */ |
---|
80 | OM_LIST& getOMListNumber() { return this->objectListNumber; } |
---|
81 | /** @returns a Reference to the Iterator */ |
---|
82 | std::list<WorldEntity*>::iterator& getEntityIterator() { return this->objectListIterator; } |
---|
83 | |
---|
84 | int writeState(const byte* data, int length, int sender); |
---|
85 | int readState(byte* data, int maxLength ); |
---|
86 | |
---|
87 | /** @returns the Energy of the entity */ |
---|
88 | float getHealth() const { return this->health; }; |
---|
89 | /** @returns the Maximum energy this entity can be charged with */ |
---|
90 | float getHealthMax() const { return this->healthMax; } |
---|
91 | float increaseHealth(float health); |
---|
92 | float decreaseHealth(float health); |
---|
93 | void increaseHealthMax(float increaseHealth); |
---|
94 | GLGuiWidget* getHealthWidget(); |
---|
95 | bool hasHealthWidget() const { return this->healthWidget; }; |
---|
96 | |
---|
97 | protected: |
---|
98 | void setHealth(float health) { this->health = health; this->updateHealthWidget();}; |
---|
99 | void setHealthWidgetVisibilit(bool visibility); |
---|
100 | void setHealthMax(float healthMax); |
---|
101 | void createHealthWidget(); |
---|
102 | |
---|
103 | // CharacterAttributes* charAttr; //!< the character attributes of a world_entity |
---|
104 | private: |
---|
105 | void updateHealthWidget(); |
---|
106 | |
---|
107 | private: |
---|
108 | /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC |
---|
109 | float health; //!< The Energy of this Entity, if the Entity has any energy at all. |
---|
110 | float healthMax; //!< The Maximal energy this entity can take. |
---|
111 | GLGuiBar* healthWidget; //!< The Slider (if wanted). |
---|
112 | |
---|
113 | std::vector<Model*> models; //!< The model that should be loaded for this entity. |
---|
114 | std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this |
---|
115 | std::string modelLODName; //!< the name of the model lod file |
---|
116 | BVTree* obbTree; //!< this is the obb tree reference needed for collision detection |
---|
117 | |
---|
118 | bool bCollide; //!< If it should be considered for the collisiontest. |
---|
119 | bool bVisible; //!< If it should be visible. |
---|
120 | |
---|
121 | OM_LIST objectListNumber; //!< The ObjectList from ObjectManager this Entity is in. |
---|
122 | std::list<WorldEntity*>::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. |
---|
123 | |
---|
124 | float scaling; |
---|
125 | |
---|
126 | |
---|
127 | }; |
---|
128 | |
---|
129 | #endif /* _WORLD_ENTITY_H */ |
---|