[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 | |
---|
| 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * standard constructor |
---|
| 31 | */ |
---|
| 32 | CRObjectDamage::CRObjectDamage () |
---|
| 33 | : CollisionReaction() |
---|
| 34 | { |
---|
| 35 | this->setClassID(CL_CR_OBJECT_DAMAGE, "CRObjectDamage"); |
---|
| 36 | |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * standard deconstructor |
---|
| 42 | */ |
---|
| 43 | CRObjectDamage::~CRObjectDamage () |
---|
| 44 | { |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * caluculates and applys the reaction to a specific collision |
---|
| 50 | * @param collision the collision |
---|
| 51 | */ |
---|
| 52 | void CRObjectDamage::reactToCollision(Collision* collision) |
---|
| 53 | { |
---|
[8110] | 54 | float damage; |
---|
[8006] | 55 | |
---|
[8166] | 56 | assert(collision->getEntityA() != NULL); |
---|
| 57 | assert(collision->getEntityB() != NULL); |
---|
| 58 | |
---|
[8129] | 59 | PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n", |
---|
| 60 | collision->getEntityA()->getClassName(), |
---|
| 61 | collision->getEntityB()->getClassName()); |
---|
[8111] | 62 | |
---|
[8110] | 63 | // the collision damage been dealed by the entity |
---|
| 64 | if( collision->isEntityACollide()) { |
---|
| 65 | damage = collision->getEntityB()->getHealthMax(); |
---|
| 66 | collision->getEntityA()->decreaseHealth(damage); |
---|
| 67 | } |
---|
| 68 | if( collision->isEntityBCollide()) { |
---|
| 69 | damage = collision->getEntityA()->getHealthMax(); |
---|
| 70 | collision->getEntityB()->decreaseHealth(damage); |
---|
| 71 | } |
---|
[8047] | 72 | |
---|
[8129] | 73 | collision->flushCollisionEvents(); |
---|
| 74 | collision->dispatched(); |
---|
| 75 | |
---|
[8106] | 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 | // } |
---|
| 83 | |
---|
[8006] | 84 | } |
---|
| 85 | |
---|