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