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
Location:
code/branches/main_reto/src/weapon
Files:
6 added
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto/src/weapon/CMakeLists.txt

    r206 r267  
    22
    33# create a few variables to simplify life
    4 SET(WPN_CC_FILES
     4SET( WEAPON_SRC
    55        ammunition_dump.cc
     6        barrel_gun.cc
     7        base_weapon.cc
    68        bullet.cc
    79        bullet_manager.cc
    8         weapon_manager.cc)
    9 SET(WPN_H_FILES
     10        weapon_station.cc
     11
    1012        ammunition_dump.h
     13        barrel_gun.h
     14        base_weapon.h
    1115        bullet.h
    1216        bullet_manager.h
    13         weapon.h
    14         weapon_manager.h)
     17        weapon_station.h
     18   )
    1519
     20#ADD_LIBRARY(WEAPON ${WEAPON_SRC} )
  • 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}
  • code/branches/main_reto/src/weapon/ammunition_dump.h

    r190 r267  
    4141  {
    4242  public:
    43           AmmunitionDump();
     43    AmmunitionDump();
    4444          ~AmmunitionDump();
    4545
     46    void setDumpSize(const Ogre::String &name, int size);
     47
     48    int store(const Ogre::String &name, int quantiy);
     49
     50    int getAmmunition(const Ogre::String &name, int quantity);
     51
     52    int getStockSize(const Ogre::String &name);
     53
    4654  protected:
     55    int numberOfAmmos_;
     56    int *stock_;
     57    int *capacity_;
    4758
    4859  protected:
Note: See TracChangeset for help on using the changeset viewer.