Changeset 267 for code/branches/main_reto/src/weapon
- Timestamp:
- Nov 27, 2007, 3:02:03 PM (17 years ago)
- 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 2 2 3 3 # create a few variables to simplify life 4 SET( WPN_CC_FILES4 SET( WEAPON_SRC 5 5 ammunition_dump.cc 6 barrel_gun.cc 7 base_weapon.cc 6 8 bullet.cc 7 9 bullet_manager.cc 8 weapon_ manager.cc)9 SET(WPN_H_FILES 10 weapon_station.cc 11 10 12 ammunition_dump.h 13 barrel_gun.h 14 base_weapon.h 11 15 bullet.h 12 16 bullet_manager.h 13 weapon .h14 weapon_manager.h)17 weapon_station.h 18 ) 15 19 20 #ADD_LIBRARY(WEAPON ${WEAPON_SRC} ) -
code/branches/main_reto/src/weapon/ammunition_dump.cc
r190 r267 26 26 */ 27 27 28 #include "run_manager.h" 29 28 30 #include "ammunition_dump.h" 29 31 … … 33 35 34 36 AmmunitionDump::AmmunitionDump() 37 : numberOfAmmos_(RunManager::getSingletonPtr()->getNumberOfAmmos()), 38 stock_(new int[numberOfAmmos_]), 39 capacity_(new int[numberOfAmmos_]) 35 40 { 41 for (int i = 0; i < numberOfAmmos_; i++) 42 { 43 stock_[i] = 0; 44 capacity_[i] = 0; 45 } 36 46 } 37 47 … … 39 49 AmmunitionDump::~AmmunitionDump() 40 50 { 51 if (stock_) 52 delete stock_; 53 if (capacity_) 54 delete capacity_; 41 55 } 42 56 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 } 43 108 } 44 109 } -
code/branches/main_reto/src/weapon/ammunition_dump.h
r190 r267 41 41 { 42 42 public: 43 43 AmmunitionDump(); 44 44 ~AmmunitionDump(); 45 45 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 46 54 protected: 55 int numberOfAmmos_; 56 int *stock_; 57 int *capacity_; 47 58 48 59 protected:
Note: See TracChangeset
for help on using the changeset viewer.