[4680] | 1 | /*! |
---|
[4885] | 2 | * @file world_entity.h |
---|
| 3 | * Definition of the basic WorldEntity |
---|
[7711] | 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 | |
---|
[7927] | 13 | #include "cr_engine.h" |
---|
[6142] | 14 | #include "object_manager.h" |
---|
[5511] | 15 | #include "glincl.h" |
---|
[5995] | 16 | #include <vector> |
---|
[7927] | 17 | #include <stdarg.h> |
---|
[5511] | 18 | |
---|
[7927] | 19 | |
---|
| 20 | |
---|
[4885] | 21 | // FORWARD DECLARATION |
---|
[7460] | 22 | namespace OrxSound { class SoundBuffer; class SoundSource; } |
---|
[7779] | 23 | namespace OrxGui { class GLGuiWidget; class GLGuiBar; }; |
---|
| 24 | |
---|
[5143] | 25 | class BVTree; |
---|
[5511] | 26 | class Model; |
---|
[7927] | 27 | class CollisionHandle; |
---|
[6440] | 28 | |
---|
[7927] | 29 | |
---|
[5498] | 30 | //class CharacterAttributes; |
---|
[4682] | 31 | |
---|
[5498] | 32 | |
---|
[4885] | 33 | //! Basis-class all interactive stuff in the world is derived from |
---|
[6498] | 34 | class WorldEntity : public PNode |
---|
[4680] | 35 | { |
---|
[6430] | 36 | public: |
---|
| 37 | WorldEntity(); |
---|
[3221] | 38 | virtual ~WorldEntity (); |
---|
[3365] | 39 | |
---|
[6512] | 40 | virtual void loadParams(const TiXmlElement* root); |
---|
[5994] | 41 | |
---|
[7711] | 42 | void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4); |
---|
[5994] | 43 | void setModel(Model* model, unsigned int modelNumber = 0); |
---|
[6440] | 44 | Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; |
---|
[5994] | 45 | |
---|
[7221] | 46 | inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } |
---|
[6222] | 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); |
---|
| 60 | virtual void draw () const; |
---|
[6005] | 61 | |
---|
[7927] | 62 | /* --- Collision Detection Block --- */ |
---|
[7711] | 63 | bool buildObbTree(int depth); |
---|
[5029] | 64 | virtual void collidesWith (WorldEntity* entity, const Vector& location); |
---|
[7711] | 65 | /** @returns a reference to the obb tree of this worldentity */ |
---|
| 66 | inline BVTree* getOBBTree() const { return this->obbTree; }; |
---|
| 67 | void drawBVTree(int depth, int drawMode) const; |
---|
[5501] | 68 | |
---|
[7927] | 69 | /* --- Collision Reaction Block --- */ |
---|
| 70 | void subscribeReaction(CREngine::CRType type, int nrOfTargets, ...); |
---|
[6424] | 71 | |
---|
| 72 | |
---|
[5510] | 73 | /* @returns the Count of Faces on this WorldEntity */ |
---|
| 74 | //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; }; |
---|
| 75 | // void addAbility(Ability* ability); |
---|
| 76 | // void removeAbility(Ability* ability); |
---|
| 77 | // void setCharacterAttributes(CharacterAttributes* charAttr); |
---|
| 78 | // CharacterAttributes* getCharacterAttributes(); |
---|
[4680] | 79 | |
---|
[7927] | 80 | /* --- Object Manager Block --- */ |
---|
[6142] | 81 | void toList(OM_LIST list); |
---|
| 82 | /** @returns a Reference to the objectListNumber to set. */ |
---|
| 83 | OM_LIST& getOMListNumber() { return this->objectListNumber; } |
---|
| 84 | /** @returns a Reference to the Iterator */ |
---|
[7370] | 85 | ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; } |
---|
[6222] | 86 | |
---|
[7927] | 87 | /* --- Network Block --- */ |
---|
[6341] | 88 | int writeState(const byte* data, int length, int sender); |
---|
| 89 | int readState(byte* data, int maxLength ); |
---|
[6222] | 90 | |
---|
[7927] | 91 | /* --- Character Attribute Block --- */ |
---|
[6430] | 92 | /** @returns the Energy of the entity */ |
---|
[6700] | 93 | float getHealth() const { return this->health; }; |
---|
[6430] | 94 | /** @returns the Maximum energy this entity can be charged with */ |
---|
[6700] | 95 | float getHealthMax() const { return this->healthMax; } |
---|
| 96 | float increaseHealth(float health); |
---|
| 97 | float decreaseHealth(float health); |
---|
| 98 | void increaseHealthMax(float increaseHealth); |
---|
[7779] | 99 | OrxGui::GLGuiWidget* getHealthWidget(); |
---|
[7064] | 100 | bool hasHealthWidget() const { return this->healthWidget; }; |
---|
[7954] | 101 | |
---|
| 102 | virtual void varChangeHandler( std::list<int> & id ); |
---|
[6430] | 103 | |
---|
[7927] | 104 | /* --- Misc Stuff Block --- */ |
---|
| 105 | void debugWE() { this->debugEntity(); } |
---|
| 106 | ; ///FIXME |
---|
| 107 | void debugEntity() const; |
---|
| 108 | |
---|
| 109 | |
---|
[6430] | 110 | protected: |
---|
[7095] | 111 | void setHealth(float health) { this->health = health; this->updateHealthWidget();}; |
---|
[6700] | 112 | void setHealthWidgetVisibilit(bool visibility); |
---|
| 113 | void setHealthMax(float healthMax); |
---|
| 114 | void createHealthWidget(); |
---|
[7711] | 115 | |
---|
[5994] | 116 | // CharacterAttributes* charAttr; //!< the character attributes of a world_entity |
---|
[6430] | 117 | private: |
---|
[6700] | 118 | void updateHealthWidget(); |
---|
[5994] | 119 | |
---|
[6430] | 120 | private: |
---|
| 121 | /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC |
---|
[6700] | 122 | float health; //!< The Energy of this Entity, if the Entity has any energy at all. |
---|
| 123 | float healthMax; //!< The Maximal energy this entity can take. |
---|
[7779] | 124 | OrxGui::GLGuiBar* healthWidget; //!< The Slider (if wanted). |
---|
[6341] | 125 | |
---|
[6142] | 126 | std::vector<Model*> models; //!< The model that should be loaded for this entity. |
---|
[7221] | 127 | std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this |
---|
| 128 | std::string modelLODName; //!< the name of the model lod file |
---|
[6142] | 129 | BVTree* obbTree; //!< this is the obb tree reference needed for collision detection |
---|
[4680] | 130 | |
---|
[6142] | 131 | bool bCollide; //!< If it should be considered for the collisiontest. |
---|
| 132 | bool bVisible; //!< If it should be visible. |
---|
| 133 | |
---|
| 134 | OM_LIST objectListNumber; //!< The ObjectList from ObjectManager this Entity is in. |
---|
[7370] | 135 | ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. |
---|
[6142] | 136 | |
---|
[7954] | 137 | |
---|
| 138 | //network stuff |
---|
| 139 | |
---|
| 140 | float scaling; //!< model's scaling factor |
---|
| 141 | int scaling_handle; //!< handle for syncing var |
---|
| 142 | |
---|
| 143 | std::string modelFileName; //!< model's file name |
---|
| 144 | int modelFileName_handle; //!< handle for syncing var |
---|
[7927] | 145 | CollisionHandle** collisionHandles; |
---|
[6341] | 146 | |
---|
| 147 | |
---|
[2036] | 148 | }; |
---|
| 149 | |
---|
[3224] | 150 | #endif /* _WORLD_ENTITY_H */ |
---|