[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[6655] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[6655] | 18 | #include "ammo_container.h" |
---|
[1853] | 19 | |
---|
[6655] | 20 | #include "weapon.h" |
---|
| 21 | |
---|
| 22 | #include <assert.h> |
---|
| 23 | |
---|
[1853] | 24 | |
---|
[9869] | 25 | ObjectListDefinition(AmmoContainer); |
---|
[3245] | 26 | /** |
---|
[4838] | 27 | * standard constructor |
---|
| 28 | * @todo this constructor is not jet implemented - do it |
---|
[3245] | 29 | */ |
---|
[9869] | 30 | AmmoContainer::AmmoContainer (const ClassID& projectileType, float maxEnergy) |
---|
[3365] | 31 | { |
---|
[9869] | 32 | this->registerObject(this, AmmoContainer::_objectList); |
---|
[4320] | 33 | |
---|
[9869] | 34 | this->projectileType = projectileType; |
---|
| 35 | this->maxEnergy = maxEnergy; |
---|
[6846] | 36 | |
---|
[9869] | 37 | this->energy = 0.0; |
---|
[3365] | 38 | } |
---|
[1853] | 39 | |
---|
| 40 | |
---|
[3245] | 41 | /** |
---|
[4838] | 42 | * standard deconstructor |
---|
[3245] | 43 | */ |
---|
[6655] | 44 | AmmoContainer::~AmmoContainer () |
---|
[3543] | 45 | { |
---|
| 46 | // delete what has to be deleted here |
---|
| 47 | } |
---|
[6655] | 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | float AmmoContainer::increaseEnergy(float energy) |
---|
| 52 | { |
---|
| 53 | this->energy += energy; |
---|
| 54 | |
---|
| 55 | if (unlikely(this->energy > this->maxEnergy)) |
---|
| 56 | { |
---|
| 57 | float retEnergy = this->energy - this->maxEnergy; |
---|
| 58 | this->energy = this->maxEnergy; |
---|
| 59 | return retEnergy; |
---|
| 60 | } |
---|
| 61 | else |
---|
| 62 | return 0.0f; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | float AmmoContainer::decreaseEnergy(float energy) |
---|
| 67 | { |
---|
| 68 | this->energy -= energy; |
---|
| 69 | |
---|
| 70 | if (unlikely(this->energy < 0)) |
---|
| 71 | { |
---|
| 72 | float retEnergy = 0 - this->energy; |
---|
| 73 | this->energy = 0; |
---|
| 74 | return retEnergy; |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | return 0.0f; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | bool AmmoContainer::weaponValid(const Weapon* weapon) |
---|
| 81 | { |
---|
| 82 | return (weapon->isA(this->projectileType)); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | void AmmoContainer::fillWeapon(Weapon* weapon) |
---|
| 87 | { |
---|
| 88 | assert (weapon != NULL); |
---|
[6664] | 89 | assert (this->weaponValid(weapon)); |
---|
[6655] | 90 | |
---|
| 91 | float fillEnergy = weapon->getEnergyMax(); |
---|
| 92 | |
---|
| 93 | float restEnergy = weapon->increaseEnergy(fillEnergy); |
---|
| 94 | this->decreaseEnergy(fillEnergy - restEnergy); |
---|
| 95 | } |
---|