Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2007, 3:02:03 PM (16 years ago)
Author:
rgrieder
Message:
  • updated to current revision from Visual studio directory
  • hopefully working libraries with cmake
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto/src/weapon/ammunition_dump.cc

    r190 r267  
    2626 */
    2727
     28#include "run_manager.h"
     29
    2830#include "ammunition_dump.h"
    2931
     
    3335
    3436  AmmunitionDump::AmmunitionDump()
     37    : numberOfAmmos_(RunManager::getSingletonPtr()->getNumberOfAmmos()),
     38      stock_(new int[numberOfAmmos_]),
     39      capacity_(new int[numberOfAmmos_])
    3540  {
     41    for (int i = 0; i < numberOfAmmos_; i++)
     42    {
     43      stock_[i] = 0;
     44      capacity_[i] = 0;
     45    }
    3646  }
    3747
     
    3949  AmmunitionDump::~AmmunitionDump()
    4050  {
     51    if (stock_)
     52      delete stock_;
     53    if (capacity_)
     54      delete capacity_;
    4155  }
    4256
     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  }
    43108}
    44109}
Note: See TracChangeset for help on using the changeset viewer.