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