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