[8006] | 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" |
---|
[8049] | 19 | #include "collision_event.h" |
---|
[8006] | 20 | |
---|
[8049] | 21 | #include "physics_interface.h" |
---|
| 22 | |
---|
| 23 | #include "world_entity.h" |
---|
[8006] | 24 | #include "cr_object_damage.h" |
---|
| 25 | |
---|
[8362] | 26 | #include "debug.h" |
---|
| 27 | |
---|
[8006] | 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * standard constructor |
---|
| 33 | */ |
---|
| 34 | CRObjectDamage::CRObjectDamage () |
---|
| 35 | : CollisionReaction() |
---|
| 36 | { |
---|
| 37 | this->setClassID(CL_CR_OBJECT_DAMAGE, "CRObjectDamage"); |
---|
| 38 | |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * standard deconstructor |
---|
| 44 | */ |
---|
| 45 | CRObjectDamage::~CRObjectDamage () |
---|
| 46 | { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * caluculates and applys the reaction to a specific collision |
---|
| 52 | * @param collision the collision |
---|
| 53 | */ |
---|
| 54 | void CRObjectDamage::reactToCollision(Collision* collision) |
---|
| 55 | { |
---|
[8490] | 56 | float damage = 0.0f; |
---|
[8006] | 57 | |
---|
[8779] | 58 | PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n", |
---|
[8129] | 59 | collision->getEntityA()->getClassName(), |
---|
| 60 | collision->getEntityB()->getClassName()); |
---|
[8111] | 61 | |
---|
[8110] | 62 | // the collision damage been dealed by the entity |
---|
| 63 | if( collision->isEntityACollide()) { |
---|
[8169] | 64 | damage = collision->getEntityB()->getDamage(); |
---|
[8724] | 65 | collision->getEntityA()->hit(damage); |
---|
[8110] | 66 | } |
---|
[8490] | 67 | PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName()); |
---|
[8168] | 68 | |
---|
[8110] | 69 | if( collision->isEntityBCollide()) { |
---|
[8169] | 70 | damage = collision->getEntityA()->getDamage(); |
---|
[8724] | 71 | collision->getEntityB()->hit(damage); |
---|
[8110] | 72 | } |
---|
[8490] | 73 | PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName()); |
---|
[8047] | 74 | |
---|
[8129] | 75 | collision->flushCollisionEvents(); |
---|
| 76 | collision->dispatched(); |
---|
| 77 | |
---|
[8106] | 78 | // const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); |
---|
| 79 | // std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); |
---|
| 80 | // for(; it != collisionEvents->end(); it++) |
---|
| 81 | // { |
---|
| 82 | // // go through the collisions and try to estimate the damage |
---|
| 83 | // mass = (*it)->getEntityA()->getMass(); |
---|
| 84 | // } |
---|
| 85 | |
---|
[8006] | 86 | } |
---|
| 87 | |
---|