Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cr/src/world_entities/world_entity.h @ 7964

Last change on this file since 7964 was 7958, checked in by patrick, 19 years ago

cr: collision reactance introduced

File size: 5.7 KB
Line 
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
19
20
21// FORWARD DECLARATION
22namespace OrxSound { class SoundBuffer; class SoundSource; }
23namespace OrxGui { class GLGuiWidget; class GLGuiBar; };
24
25class BVTree;
26class BoundingVolume;
27class Model;
28class CollisionHandle;
29class Collision;
30
31
32//class CharacterAttributes;
33
34
35//! Basis-class all interactive stuff in the world is derived from
36class WorldEntity : public PNode
37{
38public:
39  WorldEntity();
40  virtual ~WorldEntity ();
41
42  virtual void loadParams(const TiXmlElement* root);
43
44  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
45  void setModel(Model* model, unsigned int modelNumber = 0);
46  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
47
48  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
49
50  /** @param visibility if the Entity should be visible (been draw) */
51  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
52  /** @returns true if the entity is visible, false otherwise */
53  inline bool isVisible() const { return this->bVisible; };
54
55  virtual void reset();
56
57  virtual void postSpawn ();
58  virtual void leaveWorld ();
59  virtual void destroy() {};
60
61  virtual void tick (float time);
62  virtual void draw () const;
63
64  /* --- Collision Detection Block  --- */
65  bool buildObbTree(int depth);
66  virtual void collidesWith (WorldEntity* entity, const Vector& location);
67  /** @returns a reference to the obb tree of this worldentity */
68  inline BVTree* getOBBTree() const { return this->obbTree; };
69  void drawBVTree(int depth, int drawMode) const;
70
71  /* --- Collision Reaction Block --- */
72  void subscribeReaction(CREngine::CRType type, int nrOfTargets, long target, ...);
73  void unsubscribeReaction(CREngine::CRType type);
74  void unsubscribeReaction();
75
76  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
77  /** @return true if there is at least on collision reaction subscribed */
78  inline bool isReactive() const { return this->bReactive; }
79
80
81  /* @returns the Count of Faces on this WorldEntity */
82  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
83  //  void addAbility(Ability* ability);
84  //  void removeAbility(Ability* ability);
85  //  void setCharacterAttributes(CharacterAttributes* charAttr);
86  //  CharacterAttributes* getCharacterAttributes();
87
88  /* --- Object Manager Block --- */
89  void toList(OM_LIST list);
90  /** @returns a Reference to the objectListNumber to set. */
91  OM_LIST& getOMListNumber() { return this->objectListNumber; }
92  /** @returns a Reference to the Iterator */
93  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
94
95  /* --- Network Block --- */
96  int       writeState(const byte* data, int length, int sender);
97  int       readState(byte* data, int maxLength );
98
99  /* --- Character Attribute Block --- */
100  /** @returns the Energy of the entity */
101  float getHealth() const { return this->health; };
102  /** @returns the Maximum energy this entity can be charged with */
103  float getHealthMax() const { return this->healthMax; }
104  float increaseHealth(float health);
105  float decreaseHealth(float health);
106  void increaseHealthMax(float increaseHealth);
107  OrxGui::GLGuiWidget* getHealthWidget();
108  bool hasHealthWidget() const { return this->healthWidget; };
109
110  /* --- Misc Stuff Block --- */
111  void debugWE() { this->debugEntity(); }
112  ;  ///FIXME
113  void debugEntity() const;
114
115
116protected:
117  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
118  void setHealthWidgetVisibilit(bool visibility);
119  void setHealthMax(float healthMax);
120  void createHealthWidget();
121
122  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
123private:
124  void updateHealthWidget();
125
126private:
127  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
128  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
129  float                   healthMax;          //!< The Maximal energy this entity can take.
130  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
131
132  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
133  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
134  std::string             modelLODName;       //!< the name of the model lod file
135  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
136
137  bool                    bCollide;           //!< If it should be considered for the collisiontest.
138  bool                    bVisible;           //!< If it should be visible.
139
140  OM_LIST                           objectListNumber;             //!< The ObjectList from ObjectManager this Entity is in.
141  ObjectManager::EntityList::iterator objectListIterator;         //!< The iterator position of this Entity in the given list of the ObjectManager.
142
143  float                   scaling;                                //!< the scaling of the model
144  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
145  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
146
147
148};
149
150#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.