Changeset 232 for code/branches/main_reto_vs05/src/weapon
- Timestamp:
- Nov 21, 2007, 12:44:02 AM (18 years ago)
- Location:
- code/branches/main_reto_vs05/src/weapon
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/weapon/ammunition_dump.cc
r198 r232 26 26 */ 27 27 28 #include "run_manager.h" 29 28 30 #include "ammunition_dump.h" 29 31 … … 32 34 namespace weapon { 33 35 34 AmmunitionDump::AmmunitionDump(int capacity) 35 : stock_(0), capacity_(capacity) 36 AmmunitionDump::AmmunitionDump() 37 : numberOfAmmos_(RunManager::getSingletonPtr()->getNumberOfAmmos()), 38 stock_(new int[numberOfAmmos_]), 39 capacity_(new int[numberOfAmmos_]) 36 40 { 41 for (int i = 0; i < numberOfAmmos_; i++) 42 { 43 stock_[i] = 0; 44 capacity_[i] = 0; 45 } 37 46 } 38 47 … … 40 49 AmmunitionDump::~AmmunitionDump() 41 50 { 51 if (stock_) 52 delete stock_; 53 if (capacity_) 54 delete capacity_; 55 } 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; 42 65 } 43 66 44 67 45 void AmmunitionDump::store(int quantity)68 int AmmunitionDump::store(const Ogre::String &name, int quantity) 46 69 { 47 stock_ += quantity; 48 if (stock_ > capacity_) 49 stock_ = capacity_; 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; 50 82 } 51 83 52 84 53 int AmmunitionDump::getAmmunition( int quantity)85 int AmmunitionDump::getAmmunition(const Ogre::String &name, int quantity) 54 86 { 55 i f (stock_ >= quantity)56 {57 stock_ -= quantity;58 return quantity;59 }87 int id = RunManager::getSingletonPtr()->getAmmunitionID(name); 88 if (id == -1) 89 return 0; 90 if (stock_[id] >= quantity) 91 stock_[id] -= quantity; 60 92 else 61 93 { 62 quantity = stock_; 63 stock_ = 0; 64 return quantity; 94 quantity = stock_[id]; 95 stock_[id] = 0; 65 96 } 97 return quantity; 66 98 } 67 99 68 100 69 int AmmunitionDump::getStockSize( )101 int AmmunitionDump::getStockSize(const Ogre::String &name) 70 102 { 71 return stock_; 103 int id = RunManager::getSingletonPtr()->getAmmunitionID(name); 104 if (id = -1) 105 return -1; 106 return stock_[id]; 72 107 } 73 108 } -
code/branches/main_reto_vs05/src/weapon/ammunition_dump.h
r198 r232 41 41 { 42 42 public: 43 AmmunitionDump(int capacity);43 AmmunitionDump(); 44 44 ~AmmunitionDump(); 45 45 46 void s tore(int quantiy);46 void setDumpSize(const Ogre::String &name, int size); 47 47 48 int getAmmunition(int quantity);48 int store(const Ogre::String &name, int quantiy); 49 49 50 int getStockSize(); 50 int getAmmunition(const Ogre::String &name, int quantity); 51 52 int getStockSize(const Ogre::String &name); 51 53 52 54 protected: 53 int stock_; 54 int capacity_; 55 int numberOfAmmos_; 56 int *stock_; 57 int *capacity_; 55 58 56 59 protected: -
code/branches/main_reto_vs05/src/weapon/base_weapon.cpp
r198 r232 37 37 #include "inertial_node.h" 38 38 #include "ammunition_dump.h" 39 #include "run_manager.h" 39 40 40 41 #include "base_weapon.h" … … 45 46 using namespace Ogre; 46 47 47 BaseWeapon::BaseWeapon(SceneManager *sceneMgr, InertialNode *node, 48 BulletManager *bulletManager, AmmunitionDump *ammoDump) 49 : sceneMgr_(sceneMgr), node_(node), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), 52 bulletManager_(bulletManager), secondaryFired_(false), 53 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING), 54 name_("Base Weapon"), primaryFirePower_(100), secondaryFirePower_(500), 55 primaryFiringRate_(10), secondaryFiringRate_(2), primaryBulletSpeed_(1000), 56 secondaryBulletSpeed_(500), magazineSize_(25), ammoDump_(ammoDump) 48 BaseWeapon::BaseWeapon(InertialNode *node, AmmunitionDump *ammoDump) 49 : sceneMgr_(RunManager::getSingletonPtr()->getSceneManagerPtr()), node_(node), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), 52 bulletManager_(RunManager::getSingletonPtr()->getBulletManagerPtr()), 53 secondaryFired_(false), 54 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING), 55 ammoDump_(ammoDump) 57 56 { 58 leftAmmo_ = ammoDump_->getAmmunition(magazineSize_);57 leftAmmo_ = 0; 59 58 } 60 59 … … 84 83 85 84 86 void BaseWeapon::primaryFire()87 {88 if (leftAmmo_ < 1)89 {90 currentState_ = IDLE;91 return;92 }93 94 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(95 node_->getSceneNode()->getWorldPosition(),96 node_->getSceneNode()->getWorldOrientation());97 98 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"99 + StringConverter::toString(bulletCounter_++), "Barrel.mesh");100 101 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))102 .normalisedCopy() * primaryBulletSpeed_;103 speed += node_->getWorldSpeed();104 105 temp->setScale(Vector3(1, 1, 1) * 4);106 temp->yaw(Degree(-90));107 108 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));109 110 --leftAmmo_;111 }112 113 114 void BaseWeapon::primaryFiring(unsigned int time)115 {116 if (time > 100)117 {118 currentState_ = IDLE;119 }120 }121 122 123 85 void BaseWeapon::secondaryFireRequest() 124 86 { 125 87 secondaryFireRequest_ = true; 126 }127 128 129 void BaseWeapon::secondaryFire()130 {131 if (leftAmmo_ < 5)132 {133 currentState_ = IDLE;134 return;135 }136 137 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(138 node_->getSceneNode()->getWorldPosition(),139 node_->getSceneNode()->getWorldOrientation());140 141 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"142 + StringConverter::toString(bulletCounter_++), "Barrel.mesh");143 144 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))145 .normalisedCopy() * secondaryBulletSpeed_*0.5;146 speed += node_->getWorldSpeed();147 148 temp->setScale(Vector3(1, 1, 1) * 10);149 temp->yaw(Degree(-90));150 151 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));152 153 leftAmmo_ -= 5;154 }155 156 157 void BaseWeapon::secondaryFiring(unsigned int time)158 {159 if (time > 250)160 currentState_ = IDLE;161 88 } 162 89 … … 181 108 { 182 109 case RELOAD: 183 leftAmmo_ += ammoDump_->getAmmunition( magazineSize_ - leftAmmo_);110 leftAmmo_ += ammoDump_->getAmmunition("Barrel", magazineSize_ - leftAmmo_); 184 111 break; 185 112 -
code/branches/main_reto_vs05/src/weapon/base_weapon.h
r198 r232 58 58 59 59 public: 60 BaseWeapon(Ogre::SceneManager*, InertialNode*, BulletManager*, 61 AmmunitionDump*); 60 BaseWeapon(InertialNode*, AmmunitionDump*); 62 61 virtual ~BaseWeapon(); 63 62 … … 73 72 74 73 protected: 75 v oid primaryFire();74 virtual void primaryFire() = 0; 76 75 77 v oid primaryFiring(unsigned int);76 virtual void primaryFiring(unsigned int) = 0; 78 77 79 v oid secondaryFire();78 virtual void secondaryFire() = 0; 80 79 81 v oid secondaryFiring(unsigned int);80 virtual void secondaryFiring(unsigned int) = 0; 82 81 83 82 public:
Note: See TracChangeset
for help on using the changeset viewer.