Changeset 8190 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jun 7, 2006, 3:00:01 PM (18 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/projectiles/projectile.cc
r7460 r8190 38 38 this->target = NULL; 39 39 this->removeNode(); 40 41 /* character attributes */ 42 this->setHealth(1.0f); 43 this->setDamage(100.0f); // default damage of a projectile set to 100.0 damage points 40 44 41 45 this->explosionBuffer = NULL; -
trunk/src/world_entities/world_entity.cc
r8186 r8190 32 32 #include "camera.h" 33 33 34 #include "cr_engine.h"35 34 #include "collision_handle.h" 35 #include "collision_event.h" 36 37 #include <stdarg.h> 36 38 37 39 … … 59 61 this->healthMax = 1.0f; 60 62 this->health = 1.0f; 63 this->damage = 0.0f; // no damage dealt by a default entity 61 64 this->scaling = 1.0f; 62 65 … … 68 71 this->objectListIterator = NULL; 69 72 73 // reset all collision handles to NULL == unsubscribed state 74 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 75 this->collisionHandles[i] = NULL; 76 this->bReactive = false; 77 78 // registering default reactions: 79 this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY); 80 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND, CL_TERRAIN); 81 70 82 this->toList(OM_NULL); 71 83 … … 91 103 if (this->healthWidget != NULL) 92 104 delete this->healthWidget; 105 106 this->unsubscribeReaction(); 93 107 } 94 108 … … 249 263 * subscribes this world entity to a collision reaction 250 264 * @param type the type of reaction to subscribe to 265 * @param target1 a filter target (classID) 266 */ 267 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1) 268 { 269 this->subscribeReaction(type); 270 271 // add the target filter 272 this->collisionHandles[type]->addTarget(target1); 273 } 274 275 276 /** 277 * subscribes this world entity to a collision reaction 278 * @param type the type of reaction to subscribe to 279 * @param target1 a filter target (classID) 280 */ 281 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2) 282 { 283 this->subscribeReaction(type); 284 285 // add the target filter 286 this->collisionHandles[type]->addTarget(target1); 287 this->collisionHandles[type]->addTarget(target2); 288 } 289 290 291 /** 292 * subscribes this world entity to a collision reaction 293 * @param type the type of reaction to subscribe to 294 * @param target1 a filter target (classID) 295 */ 296 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3) 297 { 298 this->subscribeReaction(type); 299 300 // add the target filter 301 this->collisionHandles[type]->addTarget(target1); 302 this->collisionHandles[type]->addTarget(target2); 303 this->collisionHandles[type]->addTarget(target3); 304 } 305 306 307 /** 308 * subscribes this world entity to a collision reaction 309 * @param type the type of reaction to subscribe to 310 * @param target1 a filter target (classID) 311 */ 312 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4) 313 { 314 this->subscribeReaction(type); 315 316 // add the target filter 317 this->collisionHandles[type]->addTarget(target1); 318 this->collisionHandles[type]->addTarget(target2); 319 this->collisionHandles[type]->addTarget(target3); 320 this->collisionHandles[type]->addTarget(target4); 321 } 322 323 324 /** 325 * subscribes this world entity to a collision reaction 326 * @param type the type of reaction to subscribe to 251 327 * @param nrOfTargets number of target filters 252 328 * @param ... the targets as classIDs 253 329 */ 254 void WorldEntity::subscribeReaction(CREngine::CRType type, int nrOfTargets, ...) 255 {} 330 void WorldEntity::subscribeReaction(CREngine::CRType type) 331 { 332 if( this->collisionHandles[type] != NULL) { 333 PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n"); 334 return; 335 } 336 337 this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type); 338 339 // now there is at least one collision reaction subscribed 340 this->bReactive = true; 341 } 342 343 344 /** 345 * unsubscribes a specific reaction from the worldentity 346 * @param type the reaction to unsubscribe 347 */ 348 void WorldEntity::unsubscribeReaction(CREngine::CRType type) 349 { 350 if( this->collisionHandles[type] == NULL) 351 return; 352 353 CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]); 354 this->collisionHandles[type] = NULL; 355 356 // check if there is still any handler registered 357 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 358 { 359 if( this->collisionHandles[i] != NULL) 360 { 361 this->bReactive = true; 362 return; 363 } 364 } 365 this->bReactive = false; 366 } 367 368 369 /** 370 * unsubscribes all collision reactions 371 */ 372 void WorldEntity::unsubscribeReaction() 373 { 374 for( int i = 0; i < CREngine::CR_NUMBER; i++) 375 this->unsubscribeReaction((CREngine::CRType)i); 376 377 // there are no reactions subscribed from now on 378 this->bReactive = false; 379 } 380 381 382 /** 383 * registers a new collision event to this world entity 384 * @param entityA entity of the collision 385 * @param entityB entity of the collision 386 * @param bvA colliding bounding volume of entityA 387 * @param bvB colliding bounding volume of entityA 388 */ 389 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 390 { 391 // is there any handler listening? 392 if( !this->bReactive) 393 return false; 394 395 // get a collision event 396 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 397 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 398 c->collide(entityA, entityB, bvA, bvB); 399 400 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 401 if( this->collisionHandles[i] != NULL) 402 this->collisionHandles[i]->registerCollisionEvent(c); 403 } 404 405 406 /** 407 * registers a new collision event to this woeld entity 408 * @param entity the entity that collides 409 * @param plane it stands on 410 * @param position it collides on the plane 411 */ 412 bool WorldEntity::registerCollision(WorldEntity* entity, Plane* plane, Vector position) 413 { 414 // is there any handler listening? 415 if( !this->bReactive) 416 return false; 417 418 // get a collision event 419 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 420 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 421 c->collide(entity, plane, position); 422 423 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 424 if( this->collisionHandles[i] != NULL) 425 this->collisionHandles[i]->registerCollisionEvent(c); 426 } 256 427 257 428 … … 324 495 void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2) 325 496 { 326 497 327 498 // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() ); 328 499 329 500 Vector v = this->getAbsDirX(); 330 501 v.x *= 10; … … 332 503 v.z *= 10; 333 504 Vector u = this->getAbsDirY(); 334 505 335 506 if(feet.x == (u.x+this->getAbsCoor().x) && feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z) 336 507 { 337 508 338 509 this->setAbsCoor(ray_2 - v); 339 510 } … … 342 513 if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z) 343 514 { 344 this->setAbsCoor(feet -u ); 345 } 346 347 this->setAbsCoor(ray_2 - v); 348 515 this->setAbsCoor(feet -u ); 516 } 517 518 this->setAbsCoor(ray_2 - v); 519 349 520 } 350 521 } -
trunk/src/world_entities/world_entity.h
r8186 r8190 15 15 #include "glincl.h" 16 16 #include <vector> 17 #include <stdarg.h> 17 18 #include "physics_interface.h" 18 19 19 20 … … 24 25 25 26 class BVTree; 27 class BoundingVolume; 26 28 class Model; 27 29 class CollisionHandle; 30 class Collision; 31 class Plane; 28 32 29 33 … … 72 76 73 77 /* --- Collision Reaction Block --- */ 74 void subscribeReaction(CREngine::CRType type, int nrOfTargets, ...); 78 void subscribeReaction(CREngine::CRType type); 79 void subscribeReaction(CREngine::CRType type, long target1); 80 void subscribeReaction(CREngine::CRType type, long target1, long target2); 81 void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3); 82 void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4); 83 84 void unsubscribeReaction(CREngine::CRType type); 85 void unsubscribeReaction(); 86 87 bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB); 88 bool registerCollision(WorldEntity* entity, Plane* plane, Vector position); 89 /** @return true if there is at least on collision reaction subscribed */ 90 inline bool isReactive() const { return this->bReactive; } 91 92 CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; } 75 93 76 94 … … 98 116 99 117 /* --- Character Attribute Block --- */ 118 /** @returns the damage dealt by this world entity */ 119 float getDamage() const { return this->damage; } 120 /** sets the damage dealt to @param damage damage per second */ 121 void setDamage(float damage) { this->damage = damage; } 100 122 /** @returns the Energy of the entity */ 101 123 float getHealth() const { return this->health; }; … … 107 129 OrxGui::GLGuiWidget* getHealthWidget(); 108 130 bool hasHealthWidget() const { return this->healthWidget; }; 109 131 110 132 virtual void varChangeHandler( std::list<int> & id ); 133 134 135 //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars 136 /* --- Physics Interface --- */ 137 inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; } 138 inline float getMass() const { return this->physicsInterface.getMass(); } 139 inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); } 140 111 141 112 142 /* --- Misc Stuff Block --- */ … … 128 158 private: 129 159 /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC 160 float damage; //!< the damage dealt to other objects by colliding. 130 161 float health; //!< The Energy of this Entity, if the Entity has any energy at all. 131 162 float healthMax; //!< The Maximal energy this entity can take. … … 140 171 bool bVisible; //!< If it should be visible. 141 172 142 OM_LIST objectListNumber;//!< The ObjectList from ObjectManager this Entity is in.143 ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.173 OM_LIST objectListNumber; //!< The ObjectList from ObjectManager this Entity is in. 174 ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. 144 175 145 146 //network stuff147 148 float scaling; //!< model's scaling factor149 int scaling_handle; //!< handle for syncing var150 151 std::string modelFileName; //!< model's file name152 int modelFileName_handle; //!< handle for syncing var153 CollisionHandle** collisionHandles;154 176 177 178 float scaling; //!< model's scaling factor 179 int scaling_handle; //!< handle for syncing var 180 181 std::string modelFileName; //!< model's file name 182 int modelFileName_handle; //!< handle for syncing var 183 184 CollisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions 185 bool bReactive; //!< true if there is at least one collision reaction subscibed 186 187 PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity 155 188 156 189 };
Note: See TracChangeset
for help on using the changeset viewer.