[190] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software: you can redistribute it and/or modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Reto Grieder |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[341] | 28 | #include "orxonox/run_manager.h" |
---|
[267] | 29 | |
---|
[190] | 30 | #include "ammunition_dump.h" |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | namespace orxonox { |
---|
| 34 | namespace weapon { |
---|
| 35 | |
---|
| 36 | AmmunitionDump::AmmunitionDump() |
---|
[267] | 37 | : numberOfAmmos_(RunManager::getSingletonPtr()->getNumberOfAmmos()), |
---|
| 38 | stock_(new int[numberOfAmmos_]), |
---|
| 39 | capacity_(new int[numberOfAmmos_]) |
---|
[190] | 40 | { |
---|
[267] | 41 | for (int i = 0; i < numberOfAmmos_; i++) |
---|
| 42 | { |
---|
| 43 | stock_[i] = 0; |
---|
| 44 | capacity_[i] = 0; |
---|
| 45 | } |
---|
[190] | 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | AmmunitionDump::~AmmunitionDump() |
---|
| 50 | { |
---|
[267] | 51 | if (stock_) |
---|
| 52 | delete stock_; |
---|
| 53 | if (capacity_) |
---|
| 54 | delete capacity_; |
---|
[190] | 55 | } |
---|
| 56 | |
---|
[267] | 57 | void AmmunitionDump::setDumpSize(const Ogre::String &name, int size) |
---|
| 58 | { |
---|
| 59 | if (size < 0) |
---|
| 60 | return; |
---|
| 61 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 62 | if (id == -1) |
---|
| 63 | return; |
---|
| 64 | capacity_[id] = size; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | int AmmunitionDump::store(const Ogre::String &name, int quantity) |
---|
| 69 | { |
---|
| 70 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 71 | if (id == -1) |
---|
| 72 | return quantity; |
---|
| 73 | stock_[id] += quantity; |
---|
| 74 | if (stock_[id] > capacity_[id]) |
---|
| 75 | { |
---|
| 76 | quantity = capacity_[id] - stock_[id]; |
---|
| 77 | stock_[id] = capacity_[id]; |
---|
| 78 | return quantity; |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | int AmmunitionDump::getAmmunition(const Ogre::String &name, int quantity) |
---|
| 86 | { |
---|
| 87 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 88 | if (id == -1) |
---|
| 89 | return 0; |
---|
| 90 | if (stock_[id] >= quantity) |
---|
| 91 | stock_[id] -= quantity; |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | quantity = stock_[id]; |
---|
| 95 | stock_[id] = 0; |
---|
| 96 | } |
---|
| 97 | return quantity; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | int AmmunitionDump::getStockSize(const Ogre::String &name) |
---|
| 102 | { |
---|
| 103 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 104 | if (id = -1) |
---|
| 105 | return -1; |
---|
| 106 | return stock_[id]; |
---|
| 107 | } |
---|
[190] | 108 | } |
---|
| 109 | } |
---|