Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/lib/collision_reaction/cr_object_damage.cc @ 10003

Last change on this file since 10003 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 2.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
17
18#include "collision.h"
19#include "collision_event.h"
20
21#include "physics_interface.h"
22
23#include "world_entity.h"
24#include "cr_object_damage.h"
25
26#include "debug.h"
27
28
29
30ObjectListDefinition(CRObjectDamage);
31/**
32 *  standard constructor
33 */
34CRObjectDamage::CRObjectDamage ()
35  : CollisionReaction()
36{
37  this->registerObject(this, CRObjectDamage::_objectList);
38}
39
40
41/**
42 *  standard deconstructor
43 */
44CRObjectDamage::~CRObjectDamage ()
45{
46}
47
48
49/**
50 * caluculates and applys the reaction to a specific collision
51 *  @param collision the collision
52 */
53void CRObjectDamage::reactToCollision(Collision* collision)
54{
55  float damage = 0.0f;
56
57  PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
58            collision->getEntityA()->getClassCName(),
59            collision->getEntityB()->getClassCName());
60
61  // the collision damage been dealed by the entity
62  if( collision->isEntityACollide()) {
63    damage = collision->getEntityB()->getDamage();
64    collision->getEntityA()->hit(damage, collision->getEntityB());
65    PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName());
66  }
67
68  if( collision->isEntityBCollide()) {
69    damage = collision->getEntityA()->getDamage();
70    collision->getEntityB()->hit(damage, collision->getEntityA());
71    PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName());
72  }
73
74  collision->flushCollisionEvents();
75  collision->dispatched();
76
77//   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
78//   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
79//   for(; it != collisionEvents->end(); it++)
80//   {
81//     // go through the collisions and try to estimate the damage
82//     mass = (*it)->getEntityA()->getMass();
83//   }
84
85}
86
Note: See TracBrowser for help on using the repository browser.