[189] | 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 | |
---|
[232] | 28 | #include "run_manager.h" |
---|
| 29 | |
---|
[189] | 30 | #include "ammunition_dump.h" |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | namespace orxonox { |
---|
| 34 | namespace weapon { |
---|
| 35 | |
---|
[232] | 36 | AmmunitionDump::AmmunitionDump() |
---|
| 37 | : numberOfAmmos_(RunManager::getSingletonPtr()->getNumberOfAmmos()), |
---|
| 38 | stock_(new int[numberOfAmmos_]), |
---|
| 39 | capacity_(new int[numberOfAmmos_]) |
---|
[189] | 40 | { |
---|
[232] | 41 | for (int i = 0; i < numberOfAmmos_; i++) |
---|
| 42 | { |
---|
| 43 | stock_[i] = 0; |
---|
| 44 | capacity_[i] = 0; |
---|
| 45 | } |
---|
[189] | 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | AmmunitionDump::~AmmunitionDump() |
---|
| 50 | { |
---|
[232] | 51 | if (stock_) |
---|
| 52 | delete stock_; |
---|
| 53 | if (capacity_) |
---|
| 54 | delete capacity_; |
---|
[189] | 55 | } |
---|
| 56 | |
---|
[232] | 57 | void AmmunitionDump::setDumpSize(const Ogre::String &name, int size) |
---|
[198] | 58 | { |
---|
[232] | 59 | if (size < 0) |
---|
| 60 | return; |
---|
| 61 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 62 | if (id == -1) |
---|
| 63 | return; |
---|
| 64 | capacity_[id] = size; |
---|
[198] | 65 | } |
---|
| 66 | |
---|
[232] | 67 | |
---|
| 68 | int AmmunitionDump::store(const Ogre::String &name, int quantity) |
---|
[198] | 69 | { |
---|
[232] | 70 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 71 | if (id == -1) |
---|
| 72 | return quantity; |
---|
| 73 | stock_[id] += quantity; |
---|
| 74 | if (stock_[id] > capacity_[id]) |
---|
[198] | 75 | { |
---|
[232] | 76 | quantity = capacity_[id] - stock_[id]; |
---|
| 77 | stock_[id] = capacity_[id]; |
---|
[198] | 78 | return quantity; |
---|
| 79 | } |
---|
| 80 | else |
---|
[232] | 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 |
---|
[198] | 93 | { |
---|
[232] | 94 | quantity = stock_[id]; |
---|
| 95 | stock_[id] = 0; |
---|
[198] | 96 | } |
---|
[232] | 97 | return quantity; |
---|
[198] | 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
[232] | 101 | int AmmunitionDump::getStockSize(const Ogre::String &name) |
---|
[198] | 102 | { |
---|
[232] | 103 | int id = RunManager::getSingletonPtr()->getAmmunitionID(name); |
---|
| 104 | if (id = -1) |
---|
| 105 | return -1; |
---|
| 106 | return stock_[id]; |
---|
[198] | 107 | } |
---|
[189] | 108 | } |
---|
| 109 | } |
---|