[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> |
---|
[5511] | 17 | |
---|
[8724] | 18 | #include "aabb_tree_node.h" |
---|
| 19 | |
---|
[8190] | 20 | #include "physics_interface.h" |
---|
[7927] | 21 | |
---|
| 22 | |
---|
[8190] | 23 | |
---|
[4885] | 24 | // FORWARD DECLARATION |
---|
[7460] | 25 | namespace OrxSound { class SoundBuffer; class SoundSource; } |
---|
[10102] | 26 | namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; class GLGuiEnergyWidgetVertical; }; |
---|
[7779] | 27 | |
---|
[5143] | 28 | class BVTree; |
---|
[8190] | 29 | class BoundingVolume; |
---|
[8724] | 30 | class AABBTreeNode; |
---|
[5511] | 31 | class Model; |
---|
[7927] | 32 | class CollisionHandle; |
---|
[8190] | 33 | class Collision; |
---|
[10088] | 34 | class Track; |
---|
| 35 | class TiXmlElement; |
---|
[6440] | 36 | |
---|
[7927] | 37 | |
---|
[5498] | 38 | //class CharacterAttributes; |
---|
[4682] | 39 | |
---|
[5498] | 40 | |
---|
[9869] | 41 | |
---|
[4885] | 42 | //! Basis-class all interactive stuff in the world is derived from |
---|
[6498] | 43 | class WorldEntity : public PNode |
---|
[4680] | 44 | { |
---|
[9869] | 45 | ObjectListDeclaration(WorldEntity); |
---|
[6430] | 46 | public: |
---|
| 47 | WorldEntity(); |
---|
[3221] | 48 | virtual ~WorldEntity (); |
---|
[3365] | 49 | |
---|
[6512] | 50 | virtual void loadParams(const TiXmlElement* root); |
---|
[5994] | 51 | |
---|
[7711] | 52 | void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4); |
---|
[9235] | 53 | void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);} |
---|
[5994] | 54 | void setModel(Model* model, unsigned int modelNumber = 0); |
---|
[9869] | 55 | Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; |
---|
[5994] | 56 | |
---|
[7221] | 57 | inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } |
---|
[6222] | 58 | |
---|
[4885] | 59 | /** @param visibility if the Entity should be visible (been draw) */ |
---|
| 60 | void setVisibiliy (bool visibility) { this->bVisible = visibility; }; |
---|
| 61 | /** @returns true if the entity is visible, false otherwise */ |
---|
[5511] | 62 | inline bool isVisible() const { return this->bVisible; }; |
---|
[5026] | 63 | |
---|
[7085] | 64 | virtual void reset(); |
---|
[3583] | 65 | |
---|
[3229] | 66 | virtual void postSpawn (); |
---|
[6959] | 67 | virtual void leaveWorld (); |
---|
[3583] | 68 | |
---|
[5501] | 69 | virtual void tick (float time); |
---|
| 70 | virtual void draw () const; |
---|
[6005] | 71 | |
---|
[7927] | 72 | /* --- Collision Detection Block --- */ |
---|
[7711] | 73 | bool buildObbTree(int depth); |
---|
[5029] | 74 | virtual void collidesWith (WorldEntity* entity, const Vector& location); |
---|
[8186] | 75 | virtual void collidesWithGround(const Vector& location); |
---|
| 76 | virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2); |
---|
| 77 | |
---|
| 78 | |
---|
[9869] | 79 | /** @returns a reference to the obb tree of this worldentity */ |
---|
[7711] | 80 | inline BVTree* getOBBTree() const { return this->obbTree; }; |
---|
[9235] | 81 | inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; } |
---|
[7711] | 82 | void drawBVTree(int depth, int drawMode) const; |
---|
[9235] | 83 | inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;} |
---|
[5501] | 84 | |
---|
[7927] | 85 | /* --- Collision Reaction Block --- */ |
---|
[8190] | 86 | void subscribeReaction(CREngine::CRType type); |
---|
[9869] | 87 | void subscribeReaction(CREngine::CRType type, const ClassID& target1); |
---|
| 88 | void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2); |
---|
| 89 | void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3); |
---|
| 90 | void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4); |
---|
[6424] | 91 | |
---|
[8190] | 92 | void unsubscribeReaction(CREngine::CRType type); |
---|
| 93 | void unsubscribeReaction(); |
---|
[6424] | 94 | |
---|
[8190] | 95 | bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB); |
---|
[8894] | 96 | bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false); |
---|
[8190] | 97 | /** @return true if there is at least on collision reaction subscribed */ |
---|
| 98 | inline bool isReactive() const { return this->bReactive; } |
---|
| 99 | |
---|
| 100 | CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; } |
---|
| 101 | |
---|
[9003] | 102 | /** @returns true if this entity is standing on ground (BSP model) */ |
---|
| 103 | bool isOnGround() const { return this->bOnGround; } |
---|
| 104 | /** @param flag: marks if this entity is standing on ground */ |
---|
| 105 | void setOnGround(bool flag) { this->bOnGround = flag; } |
---|
| 106 | |
---|
[9008] | 107 | virtual void hit(float damage, WorldEntity* killer); |
---|
| 108 | |
---|
[9235] | 109 | virtual void destroy( WorldEntity* killer ); |
---|
[8190] | 110 | |
---|
[8724] | 111 | |
---|
[5510] | 112 | /* @returns the Count of Faces on this WorldEntity */ |
---|
| 113 | //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; }; |
---|
| 114 | // void addAbility(Ability* ability); |
---|
| 115 | // void removeAbility(Ability* ability); |
---|
| 116 | // void setCharacterAttributes(CharacterAttributes* charAttr); |
---|
| 117 | // CharacterAttributes* getCharacterAttributes(); |
---|
[4680] | 118 | |
---|
[7927] | 119 | /* --- Object Manager Block --- */ |
---|
[6142] | 120 | void toList(OM_LIST list); |
---|
[9656] | 121 | void toListS(const std::string& listName); |
---|
[8037] | 122 | |
---|
| 123 | void toReflectionList(); |
---|
| 124 | void removeFromReflectionList(); |
---|
| 125 | |
---|
[6142] | 126 | /** @returns a Reference to the objectListNumber to set. */ |
---|
| 127 | OM_LIST& getOMListNumber() { return this->objectListNumber; } |
---|
| 128 | /** @returns a Reference to the Iterator */ |
---|
[7370] | 129 | ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; } |
---|
[6222] | 130 | |
---|
[8894] | 131 | void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); } |
---|
[9869] | 132 | void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); } |
---|
[8894] | 133 | |
---|
| 134 | |
---|
[7927] | 135 | /* --- Character Attribute Block --- */ |
---|
[9298] | 136 | /** @returns the scaling of the model */ |
---|
[9869] | 137 | float getScaling(){return this->scaling;} |
---|
[8190] | 138 | /** @returns the damage dealt by this world entity */ |
---|
| 139 | float getDamage() const { return this->damage; } |
---|
| 140 | /** sets the damage dealt to @param damage damage per second */ |
---|
| 141 | void setDamage(float damage) { this->damage = damage; } |
---|
[6430] | 142 | /** @returns the Energy of the entity */ |
---|
[6700] | 143 | float getHealth() const { return this->health; }; |
---|
[6430] | 144 | /** @returns the Maximum energy this entity can be charged with */ |
---|
[6700] | 145 | float getHealthMax() const { return this->healthMax; } |
---|
| 146 | float increaseHealth(float health); |
---|
| 147 | float decreaseHealth(float health); |
---|
| 148 | void increaseHealthMax(float increaseHealth); |
---|
[7779] | 149 | OrxGui::GLGuiWidget* getHealthWidget(); |
---|
[10107] | 150 | bool hasHealthWidget() const { return this->healthWidget != NULL; }; |
---|
[8190] | 151 | |
---|
[7954] | 152 | virtual void varChangeHandler( std::list<int> & id ); |
---|
[6430] | 153 | |
---|
[8190] | 154 | |
---|
| 155 | //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars |
---|
| 156 | /* --- Physics Interface --- */ |
---|
| 157 | inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; } |
---|
| 158 | inline float getMass() const { return this->physicsInterface.getMass(); } |
---|
| 159 | inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); } |
---|
[8490] | 160 | inline void setVelocity(const Vector& vel) { this->velocity = vel; } |
---|
[8190] | 161 | |
---|
| 162 | |
---|
[7927] | 163 | /* --- Misc Stuff Block --- */ |
---|
| 164 | void debugWE() { this->debugEntity(); } |
---|
| 165 | ; ///FIXME |
---|
| 166 | void debugEntity() const; |
---|
| 167 | |
---|
| 168 | |
---|
[6430] | 169 | protected: |
---|
[7095] | 170 | void setHealth(float health) { this->health = health; this->updateHealthWidget();}; |
---|
[6700] | 171 | void setHealthWidgetVisibilit(bool visibility); |
---|
| 172 | void setHealthMax(float healthMax); |
---|
| 173 | void createHealthWidget(); |
---|
[7711] | 174 | |
---|
[5994] | 175 | // CharacterAttributes* charAttr; //!< the character attributes of a world_entity |
---|
[6430] | 176 | private: |
---|
[6700] | 177 | void updateHealthWidget(); |
---|
[10088] | 178 | void addTrack(const TiXmlElement* root); |
---|
[5994] | 179 | |
---|
[6430] | 180 | private: |
---|
| 181 | /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC |
---|
[8190] | 182 | float damage; //!< the damage dealt to other objects by colliding. |
---|
[6700] | 183 | float health; //!< The Energy of this Entity, if the Entity has any energy at all. |
---|
| 184 | float healthMax; //!< The Maximal energy this entity can take. |
---|
[10101] | 185 | OrxGui::GLGuiEnergyWidgetVertical* healthWidget; //!< The Slider (if wanted). |
---|
[6341] | 186 | |
---|
[6142] | 187 | std::vector<Model*> models; //!< The model that should be loaded for this entity. |
---|
[7221] | 188 | std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this |
---|
| 189 | std::string modelLODName; //!< the name of the model lod file |
---|
[6142] | 190 | BVTree* obbTree; //!< this is the obb tree reference needed for collision detection |
---|
[8724] | 191 | AABBTreeNode* aabbNode; //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension |
---|
[4680] | 192 | |
---|
[6142] | 193 | bool bCollide; //!< If it should be considered for the collisiontest. |
---|
| 194 | bool bVisible; //!< If it should be visible. |
---|
| 195 | |
---|
[8190] | 196 | OM_LIST objectListNumber; //!< The ObjectList from ObjectManager this Entity is in. |
---|
| 197 | ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. |
---|
[8894] | 198 | OM_LIST lastObjectListNumber; //!< the last ObjectList from the ObjectManager this Entity was is in |
---|
[6142] | 199 | |
---|
[6341] | 200 | |
---|
| 201 | |
---|
[8190] | 202 | float scaling; //!< model's scaling factor |
---|
| 203 | int scaling_handle; //!< handle for syncing var |
---|
| 204 | |
---|
| 205 | std::string modelFileName; //!< model's file name |
---|
| 206 | int modelFileName_handle; //!< handle for syncing var |
---|
| 207 | |
---|
[9008] | 208 | int list_write; //!< entity's list |
---|
| 209 | int list_handle; //!< handle for list changes |
---|
[9235] | 210 | |
---|
[9110] | 211 | float health_write; |
---|
| 212 | int health_handle; |
---|
[9235] | 213 | |
---|
[9110] | 214 | float healthMax_write; |
---|
| 215 | int healthMax_handle; |
---|
[9008] | 216 | |
---|
[8190] | 217 | CollisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions |
---|
| 218 | bool bReactive; //!< true if there is at least one collision reaction subscibed |
---|
| 219 | |
---|
| 220 | PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity |
---|
[9003] | 221 | bool bOnGround; //!< true if this entity is standing on the ground |
---|
[8190] | 222 | |
---|
[9869] | 223 | protected: |
---|
[8490] | 224 | Vector velocity; //!< speed of the entity |
---|
[10096] | 225 | Track* entityTrack; //!< this is the track this entity follows (or NULL if none) |
---|
[8490] | 226 | |
---|
[2036] | 227 | }; |
---|
| 228 | |
---|
[3224] | 229 | #endif /* _WORLD_ENTITY_H */ |
---|