Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/world_entity.h @ 9805

Last change on this file since 9805 was 9715, checked in by bensch, 18 years ago

renamed newclassid to classid and newobjectlist to objectlist

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