[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 | |
---|
[9889] | 28 | namespace CoRe |
---|
| 29 | { |
---|
[8006] | 30 | |
---|
[9889] | 31 | ObjectListDefinition(CRObjectDamage); |
---|
| 32 | /** |
---|
| 33 | * standard constructor |
---|
| 34 | */ |
---|
| 35 | CRObjectDamage::CRObjectDamage () |
---|
| 36 | : CollisionReaction() |
---|
| 37 | { |
---|
| 38 | this->registerObject(this, CRObjectDamage::_objectList); |
---|
| 39 | } |
---|
[8006] | 40 | |
---|
| 41 | |
---|
[9889] | 42 | /** |
---|
| 43 | * standard deconstructor |
---|
| 44 | */ |
---|
| 45 | CRObjectDamage::~CRObjectDamage () |
---|
| 46 | {} |
---|
[8006] | 47 | |
---|
| 48 | |
---|
[9889] | 49 | /** |
---|
| 50 | * caluculates and applys the reaction to a specific collision |
---|
| 51 | * @param collision the collision |
---|
| 52 | */ |
---|
| 53 | void CRObjectDamage::reactToCollision(Collision* collision) |
---|
| 54 | { |
---|
| 55 | float damage = 0.0f; |
---|
[8006] | 56 | |
---|
[9889] | 57 | PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n", |
---|
| 58 | collision->getEntityA()->getClassCName(), |
---|
| 59 | collision->getEntityB()->getClassCName()); |
---|
[8006] | 60 | |
---|
[9889] | 61 | // the collision damage been dealed by the entity |
---|
| 62 | if( collision->isEntityACollide()) |
---|
| 63 | { |
---|
| 64 | damage = collision->getEntityB()->getDamage(); |
---|
| 65 | collision->getEntityA()->hit(damage, collision->getEntityB()); |
---|
| 66 | PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName()); |
---|
| 67 | } |
---|
[8111] | 68 | |
---|
[9889] | 69 | if( collision->isEntityBCollide()) |
---|
| 70 | { |
---|
| 71 | damage = collision->getEntityA()->getDamage(); |
---|
| 72 | collision->getEntityB()->hit(damage, collision->getEntityA()); |
---|
| 73 | PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName()); |
---|
| 74 | } |
---|
[8168] | 75 | |
---|
[9889] | 76 | // const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); |
---|
| 77 | // std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); |
---|
| 78 | // for(; it != collisionEvents->end(); it++) |
---|
| 79 | // { |
---|
| 80 | // // go through the collisions and try to estimate the damage |
---|
| 81 | // mass = (*it)->getEntityA()->getMass(); |
---|
| 82 | // } |
---|
[8129] | 83 | |
---|
[9889] | 84 | } |
---|
[8106] | 85 | |
---|
[8006] | 86 | } |
---|