Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon_system/ammunition_dump.cc @ 654

Last change on this file since 654 was 637, checked in by rgrieder, 17 years ago
File size: 2.8 KB
Line 
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
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (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, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "orxonox/Orxonox.h"
29#include "bullet_manager.h"
30#include "tinyxml/tinyxml.h"
31
32#include "ammunition_dump.h"
33
34
35namespace orxonox {
36  CreateFactory(AmmunitionDump);
37
38  AmmunitionDump::AmmunitionDump()
39    : numberOfAmmos_(Orxonox::getSingleton()->getBulletMgr()->getNumberOfAmmos()),
40      stock_(new int[numberOfAmmos_]),
41      capacity_(new int[numberOfAmmos_])
42  {
43    RegisterObject(AmmunitionDump);
44
45    for (int i = 0; i < numberOfAmmos_; i++)
46    {
47      stock_[i] = 0;
48      capacity_[i] = 0;
49    }
50  }
51
52
53  AmmunitionDump::~AmmunitionDump()
54  {
55    if (stock_)
56      delete stock_;
57    if (capacity_)
58      delete capacity_;
59  }
60
61  void AmmunitionDump::setDumpSize(const Ogre::String &name, int size)
62  {
63    if (size < 0)
64      return;
65    int id = Orxonox::getSingleton()->getBulletMgr()->getAmmunitionID(name);
66    if (id == -1)
67      return;
68    capacity_[id] = size;
69  }
70
71
72  int AmmunitionDump::store(const Ogre::String &name, int quantity)
73  {
74    int id = Orxonox::getSingleton()->getBulletMgr()->getAmmunitionID(name);
75    if (id == -1)
76      return quantity;
77    stock_[id] += quantity;
78    if (stock_[id] > capacity_[id])
79    {
80      quantity = capacity_[id] - stock_[id];
81      stock_[id] = capacity_[id];
82      return quantity;
83    }
84    else
85      return 0;
86  }
87
88
89  int AmmunitionDump::getAmmunition(const Ogre::String &name, int quantity)
90  {
91    int id = Orxonox::getSingleton()->getBulletMgr()->getAmmunitionID(name);
92    if (id == -1)
93      return 0;
94    if (stock_[id] >= quantity)
95      stock_[id] -= quantity;
96    else
97    {
98      quantity = stock_[id];
99      stock_[id] = 0;
100    }
101    return quantity;
102  }
103
104
105  int AmmunitionDump::getStockSize(const Ogre::String &name)
106  {
107    int id = Orxonox::getSingleton()->getBulletMgr()->getAmmunitionID(name);
108    if (id = -1)
109      return -1;
110    return stock_[id];
111  }
112}
Note: See TracBrowser for help on using the repository browser.