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