Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7994 was 7989, checked in by patrick, 19 years ago

cr: other interface, no stdarg

File size: 6.0 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);
73  void subscribeReaction(CREngine::CRType type, long target1);
74  void subscribeReaction(CREngine::CRType type, long target1, long target2);
75  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
76  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
77
78  void unsubscribeReaction(CREngine::CRType type);
79  void unsubscribeReaction();
80
81  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
82  /** @return true if there is at least on collision reaction subscribed */
83  inline bool isReactive() const { return this->bReactive; }
84
85
86  /* @returns the Count of Faces on this WorldEntity */
87  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
88  //  void addAbility(Ability* ability);
89  //  void removeAbility(Ability* ability);
90  //  void setCharacterAttributes(CharacterAttributes* charAttr);
91  //  CharacterAttributes* getCharacterAttributes();
92
93  /* --- Object Manager Block --- */
94  void toList(OM_LIST list);
95  /** @returns a Reference to the objectListNumber to set. */
96  OM_LIST& getOMListNumber() { return this->objectListNumber; }
97  /** @returns a Reference to the Iterator */
98  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
99
100  /* --- Network Block --- */
101  int       writeState(const byte* data, int length, int sender);
102  int       readState(byte* data, int maxLength );
103
104  /* --- Character Attribute Block --- */
105  /** @returns the Energy of the entity */
106  float getHealth() const { return this->health; };
107  /** @returns the Maximum energy this entity can be charged with */
108  float getHealthMax() const { return this->healthMax; }
109  float increaseHealth(float health);
110  float decreaseHealth(float health);
111  void increaseHealthMax(float increaseHealth);
112  OrxGui::GLGuiWidget* getHealthWidget();
113  bool hasHealthWidget() const { return this->healthWidget; };
114
115  /* --- Misc Stuff Block --- */
116  void debugWE() { this->debugEntity(); }
117  ;  ///FIXME
118  void debugEntity() const;
119
120
121protected:
122  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
123  void setHealthWidgetVisibilit(bool visibility);
124  void setHealthMax(float healthMax);
125  void createHealthWidget();
126
127  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
128private:
129  void updateHealthWidget();
130
131private:
132  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
133  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
134  float                   healthMax;          //!< The Maximal energy this entity can take.
135  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
136
137  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
138  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
139  std::string             modelLODName;       //!< the name of the model lod file
140  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
141
142  bool                    bCollide;           //!< If it should be considered for the collisiontest.
143  bool                    bVisible;           //!< If it should be visible.
144
145  OM_LIST                           objectListNumber;             //!< The ObjectList from ObjectManager this Entity is in.
146  ObjectManager::EntityList::iterator objectListIterator;         //!< The iterator position of this Entity in the given list of the ObjectManager.
147
148  float                   scaling;                                //!< the scaling of the model
149  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
150  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
151
152
153};
154
155#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.