Changeset 267 for code/branches/main_reto
- Timestamp:
- Nov 27, 2007, 3:02:03 PM (17 years ago)
- Location:
- code/branches/main_reto
- Files:
-
- 7 added
- 3 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto/src/CMakeLists.txt
r207 r267 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES 5 orxonox.cc 6 main.cc 4 SET( ORXONOX_SRC 7 5 camera_manager.cc 8 6 inertial_node.cc 7 main.cc 9 8 ogre_control.cc 9 orxonox.cc 10 10 orxonox_scene.cc 11 11 orxonox_ship.cc 12 run_manager.cc )12 run_manager.cc 13 13 14 SET(INC_FILES15 14 camera_manager.h 16 15 inertial_node.h … … 20 19 orxonox_scene.h 21 20 orxonox_ship.h 22 run_manager.h) 21 run_manager.h 22 ) 23 23 24 24 #Creates an executable 25 ADD_EXECUTABLE(../bin/main ${SRC_FILES, weapon/WPN_CC_FILES} ${INC_FILES, weapon/WPN_H_FILES}) 26 #Links the executable against OGRE and OIS 27 TARGET_LINK_LIBRARIES(../bin/main ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OGRE_LIBRARIES}) 25 ADD_EXECUTABLE(../bin/main ${ORXONOX_SRC} ) 28 26 29 27 #add weapon source dir 30 ADD_SUBDIRECTORY(weapon) 28 #ADD_SUBDIRECTORY(weapon) 29 30 #Links the executable against OGRE and OIS 31 TARGET_LINK_LIBRARIES(../bin/main WEAPON ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OGRE_LIBRARIES}) 32 #TARGET_LINK_LIBRARIES(../bin/main ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OGRE_LIBRARIES}) -
code/branches/main_reto/src/main.cc
r190 r267 31 31 #include "orxonox.h" 32 32 33 #include "class_hierarchy/BaseObject.h" 34 #include "class_hierarchy/Test.h" 35 #include "class_hierarchy/test1.h" 36 #include "class_hierarchy/test2.h" 37 #include "class_hierarchy/test3.h" 38 39 33 40 #ifdef __cplusplus 34 41 extern "C" { … … 43 50 #endif 44 51 { 52 #if 1 45 53 try { 46 54 // create an orxonox application and run it … … 60 68 } 61 69 70 #else 71 #define testandcout(code) \ 72 std::cout << #code << " " << code << "\n" 73 74 using namespace orxonox; 75 76 std::cout << "Test 8\n"; 77 78 std::cout << "1\n"; 79 Test1* test8_01 = new Test1; 80 Test1* asdf = new Test1; 81 Test3* test8_03 = new Test3; 82 test8_03->usefullClassesIsATest(test8_01); 83 84 std::cout << "2\n"; 85 Test2* test8_02 = new Test2; 86 test8_03->usefullClassesIsATest(test8_02); 87 88 std::cout << "3\n"; 89 test8_01->setUsefullClass1(Class(Test1)); 90 test8_01->setUsefullClass1(test8_02->getIdentifier()); 91 test8_01->setUsefullClass2(Class(Test2)); 92 test8_01->setUsefullClassOfTypeTest3(Class(Test3)); 93 test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier()); 94 95 96 testandcout(test8_01->isA(Class(Test1))); 97 testandcout(test8_01->isA(Class(Test2))); 98 testandcout(test8_01->isA(Class(Test3))); 99 100 Test2* test8_04 = new Test2; 101 testandcout(test8_02->isA(Class(Test1))); 102 testandcout(test8_02->isA(Class(Test2))); 103 testandcout(test8_02->isA(Class(Test3))); 104 105 Test3* test8_05 = new Test3; 106 testandcout(test8_03->isA(Class(Test1))); 107 testandcout(test8_03->isA(Class(Test2))); 108 testandcout(test8_03->isA(Class(Test3))); 109 110 delete test8_01; 111 delete test8_02; 112 delete test8_03; 113 114 #endif 62 115 return 0; 63 116 } -
code/branches/main_reto/src/orxonox_prerequisites.h
r190 r267 46 46 class Bullet; 47 47 class BulletManager; 48 class Weapon; 49 class WeaponManager; 48 class BaseWeapon; 49 class BarrelGun; 50 class WeaponStation; 51 52 } 53 54 55 namespace hud { 56 57 class HUDOverlay; 50 58 51 59 } -
code/branches/main_reto/src/orxonox_scene.cc
r171 r267 98 98 void OrxonoxScene::createScene() 99 99 { 100 sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3) );100 sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3)*2); 101 101 102 102 //create first entity … … 110 110 111 111 // set up skybox 112 sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox 2");112 sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox1"); 113 113 114 114 // set up one light_ source -
code/branches/main_reto/src/orxonox_ship.cc
r192 r267 26 26 */ 27 27 28 #include "OgreSceneManager.h" 28 #include "OgreMath.h" 29 #include "OgreVector3.h" 30 #include "OgreQuaternion.h" 29 31 #include "OgreSceneNode.h" 30 32 #include "OgreEntity.h" 31 #include "Ogre Vector3.h"32 #include "Ogre StringConverter.h"33 #include "OgreSceneManager.h" 34 #include "OgreParticleSystem.h" 33 35 34 36 #include "inertial_node.h" 37 #include "run_manager.h" 35 38 #include "weapon/bullet.h" 36 39 #include "weapon/bullet_manager.h" 37 #include "weapon/weapon_manager.h" 40 #include "weapon/weapon_station.h" 41 #include "weapon/base_weapon.h" 42 #include "weapon/barrel_gun.h" 43 #include "weapon/ammunition_dump.h" 38 44 39 45 #include "orxonox_ship.h" … … 65 71 * @param mNode The scene node which the ship will be attached to later. 66 72 */ 67 OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node, 68 BulletManager *bulletManager) 69 : sceneMgr_(sceneMgr), //currentSpeed_(Vector3(0, 0, 0)), 70 baseThrust_(1000), currentThrust_(Vector3::ZERO), 71 objectCounter_(0), bulletManager_(bulletManager)//, bulletSpeed_(400) 73 OrxonoxShip::OrxonoxShip(SceneNode *node) 74 : sceneMgr_(RunManager::getSingletonPtr()->getSceneManagerPtr()), 75 bulletManager_(RunManager::getSingletonPtr()->getBulletManagerPtr()), 76 baseThrust_(1000), currentThrust_(Vector3::ZERO), objectCounter_(0) 72 77 { 73 78 rootNode_ = new InertialNode(node, Vector3::ZERO); … … 83 88 if (mainWeapon_) 84 89 delete mainWeapon_; 90 if (railGunStation_) 91 delete railGunStation_; 85 92 if (rootNode_) 86 93 delete rootNode_; … … 110 117 111 118 // initialise weapon(s) 119 ammoDump_ = new AmmunitionDump(); 120 ammoDump_->setDumpSize("Barrel", 1000); 121 ammoDump_->store("Barrel", 420); 122 112 123 InertialNode *mainWeaponNode = rootNode_->createChildNode(); 113 mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode, 114 bulletManager_, 1); 115 mainWeapon_->addWeapon("Barrel Gun"); 124 mainWeapon_ = new BarrelGun(mainWeaponNode, ammoDump_); 125 126 railGunStation_ = new WeaponStation(4); 127 railGunStation_->addWeapon(mainWeapon_); 128 railGunStation_->selectWeapon(0); 129 130 // create some nice effects 131 132 ParticleSystem *particles = RunManager::getSingletonPtr() 133 ->getSceneManagerPtr()->createParticleSystem("asdf", "Examples/Smoke"); 134 135 fishNode->getSceneNode()->attachObject(particles); 136 137 138 116 139 117 140 return true; … … 197 220 * @return Bullet containing speed and entity. 198 221 */ 199 void OrxonoxShip::fire() 200 { 201 mainWeapon_->primaryFireRequest(); 222 BaseWeapon* OrxonoxShip::getMainWeapon() 223 { 224 return mainWeapon_; 225 } 226 227 228 int OrxonoxShip::getAmmoStock() 229 { 230 return ammoDump_->getStockSize("Barrel"); 202 231 } 203 232 -
code/branches/main_reto/src/orxonox_ship.h
r190 r267 40 40 { 41 41 public: 42 OrxonoxShip(Ogre::Scene Manager*, Ogre::SceneNode*, weapon::BulletManager*);42 OrxonoxShip(Ogre::SceneNode*); 43 43 virtual ~OrxonoxShip(); 44 44 … … 54 54 Ogre::Vector3 getSpeed(); 55 55 56 void fire(); 56 weapon::BaseWeapon* getMainWeapon(); 57 58 int getAmmoStock(); 57 59 58 60 bool tick(unsigned long, Ogre::Real); … … 74 76 //Ogre::Vector3 bulletSpeed_; 75 77 76 weapon::WeaponManager *mainWeapon_; 78 weapon::BaseWeapon *mainWeapon_; 79 weapon::WeaponStation *railGunStation_; 80 81 weapon::AmmunitionDump *ammoDump_; 77 82 }; 78 83 -
code/branches/main_reto/src/run_manager.cc
r192 r267 56 56 #include "weapon/bullet.h" 57 57 #include "weapon/bullet_manager.h" 58 #include "weapon/weapon_manager.h" 58 #include "weapon/base_weapon.h" 59 60 #include "hud/hud_overlay.h" 59 61 60 62 #include "run_manager.h" 63 64 namespace Ogre { 65 using namespace orxonox; 66 template<> RunManager* Singleton<RunManager>::ms_Singleton = 0; 67 } 61 68 62 69 namespace orxonox { 63 70 using namespace Ogre; 64 71 using namespace weapon; 72 using namespace hud; 65 73 66 74 /** … … 77 85 */ 78 86 87 RunManager* RunManager::getSingletonPtr(void) 88 { 89 return ms_Singleton; 90 } 91 RunManager& RunManager::getSingleton(void) 92 { 93 assert( ms_Singleton ); return ( *ms_Singleton ); 94 } 95 79 96 80 97 /** … … 88 105 */ 89 106 RunManager::RunManager(OgreControl * ogre) 90 : ogre_(ogre), window_(ogre->getRenderWindow()), leftButtonDown_(false),107 : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false), 91 108 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 92 109 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), … … 94 111 debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0) 95 112 { 96 97 113 // SETTING UP THE SCENE 98 114 99 115 // create one new SceneManger 100 sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, " backgroundScene_");116 sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "Orxonox Scene"); 101 117 102 118 // background scene (world objects, skybox, lights, etc.) … … 108 124 // create a bullet manager 109 125 bulletManager_ = new BulletManager(sceneMgr_); 110 WeaponManager::loadWeapons();111 112 // TODO: Use STL to make life easier. But it works this way too..113 /*bullets_ = new Bullet*[10];114 bulletsIndex_ = 0;115 bulletsSize_ = 10;*/116 126 117 127 … … 131 141 132 142 // Construct a new spaceship and give it the node 133 playerShip_ = new OrxonoxShip(sceneMgr_ , sceneMgr_->getRootSceneNode()134 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)) , bulletManager_);143 playerShip_ = new OrxonoxShip(sceneMgr_->getRootSceneNode() 144 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20))); 135 145 136 146 … … 153 163 createViewports(); 154 164 165 // create HUD 166 hud_ = new HUDOverlay(); 167 hud_->show(); 168 155 169 156 170 // Set default mipmap level (NB some APIs ignore this) … … 163 177 using namespace OIS; 164 178 165 debugOverlay_ = OverlayManager::getSingleton() 166 .getByName("Core/DebugOverlay"); 179 //debugOverlay_ = OverlayManager::getSingleton() 180 // .getByName("Core/DebugOverlay"); 181 167 182 168 183 LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); … … 194 209 windowResized(window_); 195 210 196 showDebugOverlay(true);211 //showDebugOverlay(true); 197 212 198 213 // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE … … 218 233 if (bulletManager_) 219 234 delete bulletManager_; 220 221 WeaponManager::destroyWeapons();222 223 // clean up the bullet list224 /*for (int i = 0; i < bulletsIndex_; i++)225 delete bullets_[i];226 delete bullets_;*/227 235 } 228 236 … … 251 259 252 260 // Update the 'HUD' 253 updateStats();261 //updateStats(); 254 262 255 263 // update the bullet positions 256 264 bulletManager_->tick(time, deltaTime); 257 265 258 /*for (int i = 0; i < bulletsIndex_; i++)259 {260 bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime);261 bullets_[i]->node_->yaw(Degree(deltaTime*100));262 bullets_[i]->node_->roll(Degree(deltaTime*300));263 }*/264 266 265 267 // HUMAN INTERFACE … … 293 295 // keep rendering 294 296 return true; 297 } 298 299 300 SceneManager& RunManager::getSceneManager() 301 { 302 return *sceneMgr_; 303 } 304 305 SceneManager* RunManager::getSceneManagerPtr() 306 { 307 return sceneMgr_; 308 } 309 310 BulletManager* RunManager::getBulletManagerPtr() 311 { 312 return bulletManager_; 313 } 314 315 int RunManager::getAmmunitionID(const Ogre::String &ammoName) 316 { 317 Ogre::String ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" }; 318 int ammoTypesLength = 3; 319 320 for (int i = 0; i < ammoTypesLength; i++) 321 { 322 if (ammoTypes[i] == ammoName) 323 return i; 324 } 325 return -1; 326 } 327 328 int RunManager::getNumberOfAmmos() 329 { 330 return 3; 295 331 } 296 332 … … 367 403 playerShip_->setYThrust(0); 368 404 405 if (keyboard_->isKeyDown(KC_G)) 406 playerShip_->getMainWeapon()->addAction(BaseWeapon::RELOAD); 407 369 408 if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) ) 370 409 return false; … … 373 412 { 374 413 statsOn_ = !statsOn_; 375 showDebugOverlay(statsOn_);414 //showDebugOverlay(statsOn_); 376 415 timeUntilNextToggle_ = 1; 377 416 } … … 398 437 MaterialManager::getSingleton().setDefaultAnisotropy(aniso_); 399 438 400 showDebugOverlay(statsOn_);439 //showDebugOverlay(statsOn_); 401 440 timeUntilNextToggle_ = 1; 402 441 } … … 434 473 if(displayCameraDetails) 435 474 debugText_ = " | Speed = " 436 + StringConverter::toString(playerShip_->getSpeed()); 475 + StringConverter::toString(playerShip_->getSpeed()) 476 + " | Left Ammo = " 477 + StringConverter::toString(playerShip_ 478 ->getMainWeapon()->getAmmoState()) 479 + " | Ammo stock = " 480 + StringConverter::toString(playerShip_->getAmmoStock()); 437 481 // debugText_ = "P: " + StringConverter::toString(camera_ 438 482 // ->getDerivedPosition()) + " " + "O: " … … 457 501 const MouseState &ms = mouse_->getMouseState(); 458 502 459 // This is a 'hack' to show some flying barrels.. 460 // Usually, the Bullet created by the ship should be managed 461 // by the physics engine.. 462 if (ms.buttonDown(MB_Left) && !leftButtonDown_) 463 { 464 // Prevent continuous fire for the moment. 465 leftButtonDown_ = true; 466 467 playerShip_->fire(); 468 469 // let ship fire one shot with its only weapon (Barrels..) 470 /*Bullet *tempBullet = playerShip_->fire(); 471 472 // resize array if neccessary (double the size then) 473 if (bulletsIndex_ >= bulletsSize_) 474 { 475 // redimension the array 476 Bullet **tempArray = new Bullet*[2*bulletsSize_]; 477 for (int i = 0; i < bulletsSize_; i++) 478 tempArray[i] = bullets_[i]; 479 bulletsSize_ *= 2; 480 delete bullets_; 481 bullets_ = tempArray; 482 } 483 484 // add the bullet to the list 485 bullets_[bulletsIndex_++] = tempBullet;*/ 486 487 } 488 else if (!ms.buttons) 489 leftButtonDown_ = false; 490 491 // space ship steering. This should definitely be done in the steering object 492 // Simply give it the mouse movements. 503 if (ms.buttonDown(MB_Left)) 504 playerShip_->getMainWeapon()->primaryFireRequest(); 505 506 if (ms.buttonDown(MB_Right)) 507 playerShip_->getMainWeapon()->secondaryFireRequest(); 508 493 509 playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_)); 494 510 playerShip_->turnLeftAndRight(Radian(ms.X.rel * mouseSensitivity_)); 495 //playerShip_->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL);496 //playerShip_->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT);497 511 498 512 // keep rendering … … 565 579 566 580 567 568 581 /** 569 582 * Simple camera creator. … … 583 596 /** 584 597 * Simple viewport creator. 585 * TODO: fully understand the concept of viewports concerning orxnox.586 * E.g. do we need splitscreen mode?587 598 * For now the viewport uses the entire render window and is based on the one 588 599 * camera created so far. -
code/branches/main_reto/src/run_manager.h
r190 r267 33 33 #include "OgreWindowEventUtilities.h" 34 34 #include "OgreTextureManager.h" 35 #include "OgreSingleton.h" 35 36 36 37 #include <OIS/OISPrereqs.h> … … 43 44 // let the class inherit from WindowEventListener in order for the RunMgr 44 45 // to act as the central point of all the calcuations in Orxonox 45 class RunManager : Ogre::WindowEventListener 46 class RunManager : public Ogre::WindowEventListener, 47 public Ogre::Singleton<RunManager> 46 48 { 47 49 public: 48 50 RunManager(OgreControl*); 49 51 50 virtual ~RunManager(); 52 virtual ~RunManager(); 53 //void initialise(OgreControl*); 51 54 52 virtual bool tick(unsigned long, Ogre::Real); 55 bool tick(unsigned long, Ogre::Real); 56 57 Ogre::SceneManager& getSceneManager(); 58 59 Ogre::SceneManager* getSceneManagerPtr(); 60 61 weapon::BulletManager* getBulletManagerPtr(); 62 63 int getAmmunitionID(const Ogre::String&); 64 65 int getNumberOfAmmos(); 66 67 static RunManager& getSingleton(void); 68 69 static RunManager* getSingletonPtr(void); 70 53 71 54 72 protected: 55 v irtual void createCamera(void);73 void createCamera(void); 56 74 57 v irtual void createViewports(void);75 void createViewports(void); 58 76 59 77 … … 61 79 62 80 //Adjust mouse clipping area 63 v irtual void windowResized(Ogre::RenderWindow*);81 void windowResized(Ogre::RenderWindow*); 64 82 65 83 //Unattach OIS before window shutdown (very important under Linux) 66 v irtual void windowClosed(Ogre::RenderWindow*);84 void windowClosed(Ogre::RenderWindow*); 67 85 68 86 69 87 /** INPUT PROCESSING **/ 70 virtualbool processUnbufferedKeyInput();88 bool processUnbufferedKeyInput(); 71 89 72 virtualbool processUnbufferedMouseInput();90 bool processUnbufferedMouseInput(); 73 91 74 92 75 93 /** OUTPUT **/ 76 94 77 v irtual void updateStats(void);95 void updateStats(void); 78 96 79 v irtual void showDebugOverlay(bool);97 void showDebugOverlay(bool); 80 98 81 99 protected: 100 // directly Ogre related fields 82 101 Ogre::SceneManager *sceneMgr_; 83 102 Ogre::RenderWindow *window_; 84 103 Ogre::Camera *camera_; 104 105 106 // self made orxonox fields 85 107 OgreControl *ogre_; 86 108 OrxonoxScene *backgroundScene_; 87 109 OrxonoxShip *playerShip_; 110 hud::HUDOverlay *hud_; 88 111 112 // Bullet manager 113 weapon::BulletManager *bulletManager_; 114 115 const Ogre::Real mouseSensitivity_; 116 117 // previously elapsed render time 118 unsigned long totalTime_; 119 120 121 // fields from the example framework 89 122 bool statsOn_; 90 123 std::string debugText_; … … 93 126 // just to stop toggles flipping too fast 94 127 Ogre::Real timeUntilNextToggle_; 95 bool leftButtonDown_;128 //bool leftButtonDown_; 96 129 Ogre::TextureFilterOptions filtering_; 97 130 int aniso_; 98 99 131 int sceneDetailIndex_; 100 132 Ogre::Overlay* debugOverlay_; … … 106 138 OIS::JoyStick* joystick_; 107 139 108 const Ogre::Real mouseSensitivity_;109 110 // Bullet array111 /*Bullet **bullets_;112 int bulletsSize_;113 int bulletsIndex_;*/114 weapon::BulletManager *bulletManager_;115 116 // previously elapsed render time117 unsigned long totalTime_;118 119 140 }; 120 141 -
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.