1 | /*! |
---|
2 | * @file world_entity.h |
---|
3 | * Definition of the basic WorldEntity |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _WORLD_ENTITY_H |
---|
7 | #define _WORLD_ENTITY_H |
---|
8 | |
---|
9 | #include "p_node.h" |
---|
10 | #include "synchronizeable.h" |
---|
11 | #include "model.h" |
---|
12 | |
---|
13 | #include "cr_engine.h" |
---|
14 | #include "object_manager.h" |
---|
15 | #include "glincl.h" |
---|
16 | #include <vector> |
---|
17 | |
---|
18 | #include "physics_interface.h" |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | // FORWARD DECLARATION |
---|
23 | namespace OrxSound { class SoundBuffer; class SoundSource; } |
---|
24 | namespace OrxGui { class GLGuiWidget; class GLGuiBar; }; |
---|
25 | |
---|
26 | class BVTree; |
---|
27 | class BoundingVolume; |
---|
28 | class Model; |
---|
29 | class CollisionHandle; |
---|
30 | class Collision; |
---|
31 | |
---|
32 | |
---|
33 | //class CharacterAttributes; |
---|
34 | |
---|
35 | |
---|
36 | //! Basis-class all interactive stuff in the world is derived from |
---|
37 | class WorldEntity : public PNode |
---|
38 | { |
---|
39 | public: |
---|
40 | WorldEntity(); |
---|
41 | virtual ~WorldEntity (); |
---|
42 | |
---|
43 | virtual void loadParams(const TiXmlElement* root); |
---|
44 | |
---|
45 | void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4); |
---|
46 | void setModel(Model* model, unsigned int modelNumber = 0); |
---|
47 | Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; |
---|
48 | |
---|
49 | inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } |
---|
50 | |
---|
51 | /** @param visibility if the Entity should be visible (been draw) */ |
---|
52 | void setVisibiliy (bool visibility) { this->bVisible = visibility; }; |
---|
53 | /** @returns true if the entity is visible, false otherwise */ |
---|
54 | inline bool isVisible() const { return this->bVisible; }; |
---|
55 | |
---|
56 | virtual void reset(); |
---|
57 | |
---|
58 | virtual void postSpawn (); |
---|
59 | virtual void leaveWorld (); |
---|
60 | virtual void destroy() {}; |
---|
61 | |
---|
62 | virtual void tick (float time); |
---|
63 | virtual void draw () const; |
---|
64 | |
---|
65 | /* --- Collision Detection Block --- */ |
---|
66 | bool buildObbTree(int depth); |
---|
67 | virtual void collidesWith (WorldEntity* entity, const Vector& location); |
---|
68 | /** @returns a reference to the obb tree of this worldentity */ |
---|
69 | inline BVTree* getOBBTree() const { return this->obbTree; }; |
---|
70 | void drawBVTree(int depth, int drawMode) const; |
---|
71 | |
---|
72 | /* --- Collision Reaction Block --- */ |
---|
73 | void subscribeReaction(CREngine::CRType type); |
---|
74 | void subscribeReaction(CREngine::CRType type, long target1); |
---|
75 | void subscribeReaction(CREngine::CRType type, long target1, long target2); |
---|
76 | void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3); |
---|
77 | void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4); |
---|
78 | |
---|
79 | void unsubscribeReaction(CREngine::CRType type); |
---|
80 | void unsubscribeReaction(); |
---|
81 | |
---|
82 | bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB); |
---|
83 | /** @return true if there is at least on collision reaction subscribed */ |
---|
84 | inline bool isReactive() const { return this->bReactive; } |
---|
85 | |
---|
86 | CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; } |
---|
87 | |
---|
88 | |
---|
89 | /* @returns the Count of Faces on this WorldEntity */ |
---|
90 | //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; }; |
---|
91 | // void addAbility(Ability* ability); |
---|
92 | // void removeAbility(Ability* ability); |
---|
93 | // void setCharacterAttributes(CharacterAttributes* charAttr); |
---|
94 | // CharacterAttributes* getCharacterAttributes(); |
---|
95 | |
---|
96 | /* --- Object Manager Block --- */ |
---|
97 | void toList(OM_LIST list); |
---|
98 | /** @returns a Reference to the objectListNumber to set. */ |
---|
99 | OM_LIST& getOMListNumber() { return this->objectListNumber; } |
---|
100 | /** @returns a Reference to the Iterator */ |
---|
101 | ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; } |
---|
102 | |
---|
103 | /* --- Network Block --- */ |
---|
104 | int writeState(const byte* data, int length, int sender); |
---|
105 | int readState(byte* data, int maxLength ); |
---|
106 | |
---|
107 | /* --- Character Attribute Block --- */ |
---|
108 | /** @returns the damage dealt by this world entity */ |
---|
109 | float getDamage() const { return this->damage; } |
---|
110 | /** sets the damage dealt to @param damage damage per second */ |
---|
111 | void setDamage(float damage) { this->damage = damage; } |
---|
112 | /** @returns the Energy of the entity */ |
---|
113 | float getHealth() const { return this->health; }; |
---|
114 | /** @returns the Maximum energy this entity can be charged with */ |
---|
115 | float getHealthMax() const { return this->healthMax; } |
---|
116 | float increaseHealth(float health); |
---|
117 | float decreaseHealth(float health); |
---|
118 | void increaseHealthMax(float increaseHealth); |
---|
119 | OrxGui::GLGuiWidget* getHealthWidget(); |
---|
120 | bool hasHealthWidget() const { return this->healthWidget; }; |
---|
121 | |
---|
122 | |
---|
123 | //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars |
---|
124 | /* --- Physics Interface --- */ |
---|
125 | inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; } |
---|
126 | inline float getMass() const { return this->physicsInterface.getMass(); } |
---|
127 | inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); } |
---|
128 | |
---|
129 | |
---|
130 | /* --- Misc Stuff Block --- */ |
---|
131 | void debugWE() { this->debugEntity(); } |
---|
132 | ; ///FIXME |
---|
133 | void debugEntity() const; |
---|
134 | |
---|
135 | |
---|
136 | protected: |
---|
137 | void setHealth(float health) { this->health = health; this->updateHealthWidget();}; |
---|
138 | void setHealthWidgetVisibilit(bool visibility); |
---|
139 | void setHealthMax(float healthMax); |
---|
140 | void createHealthWidget(); |
---|
141 | |
---|
142 | // CharacterAttributes* charAttr; //!< the character attributes of a world_entity |
---|
143 | private: |
---|
144 | void updateHealthWidget(); |
---|
145 | |
---|
146 | private: |
---|
147 | /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC |
---|
148 | float damage; //!< the damage dealt to other objects by colliding. |
---|
149 | float health; //!< The Energy of this Entity, if the Entity has any energy at all. |
---|
150 | float healthMax; //!< The Maximal energy this entity can take. |
---|
151 | OrxGui::GLGuiBar* healthWidget; //!< The Slider (if wanted). |
---|
152 | |
---|
153 | std::vector<Model*> models; //!< The model that should be loaded for this entity. |
---|
154 | std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this |
---|
155 | std::string modelLODName; //!< the name of the model lod file |
---|
156 | BVTree* obbTree; //!< this is the obb tree reference needed for collision detection |
---|
157 | |
---|
158 | bool bCollide; //!< If it should be considered for the collisiontest. |
---|
159 | bool bVisible; //!< If it should be visible. |
---|
160 | |
---|
161 | OM_LIST objectListNumber; //!< The ObjectList from ObjectManager this Entity is in. |
---|
162 | ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. |
---|
163 | |
---|
164 | float scaling; //!< the scaling of the model |
---|
165 | CollisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions |
---|
166 | bool bReactive; //!< true if there is at least one collision reaction subscibed |
---|
167 | |
---|
168 | PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity |
---|
169 | |
---|
170 | }; |
---|
171 | |
---|
172 | #endif /* _WORLD_ENTITY_H */ |
---|