Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2007, 3:02:03 PM (17 years ago)
Author:
rgrieder
Message:
  • updated to current revision from Visual studio directory
  • hopefully working libraries with cmake
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  
    22
    33# create a few variables to simplify life
    4 SET(SRC_FILES
    5         orxonox.cc
    6         main.cc
     4SET( ORXONOX_SRC
    75        camera_manager.cc
    86        inertial_node.cc
     7        main.cc
    98        ogre_control.cc
     9        orxonox.cc
    1010        orxonox_scene.cc
    1111        orxonox_ship.cc
    12         run_manager.cc)
     12        run_manager.cc
    1313
    14 SET(INC_FILES
    1514        camera_manager.h
    1615        inertial_node.h
     
    2019        orxonox_scene.h
    2120        orxonox_ship.h
    22         run_manager.h)
     21        run_manager.h
     22   )
    2323
    2424#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})
     25ADD_EXECUTABLE(../bin/main ${ORXONOX_SRC} )
    2826
    2927#add weapon source dir
    30 ADD_SUBDIRECTORY(weapon)
     28#ADD_SUBDIRECTORY(weapon)
     29
     30#Links the executable against OGRE and OIS
     31TARGET_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  
    3131#include "orxonox.h"
    3232
     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
    3340#ifdef __cplusplus
    3441extern "C" {
     
    4350#endif
    4451  {
     52#if 1
    4553    try {
    4654      // create an orxonox application and run it
     
    6068    }
    6169
     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
    62115    return 0;
    63116  }
  • code/branches/main_reto/src/orxonox_prerequisites.h

    r190 r267  
    4646    class Bullet;
    4747    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;
    5058
    5159  }
  • code/branches/main_reto/src/orxonox_scene.cc

    r171 r267  
    9898  void OrxonoxScene::createScene()
    9999  {
    100           sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3));
     100          sceneMgr_->setAmbientLight(ColourValue(0.3,0.3,0.3)*2);
    101101
    102102          //create first entity
     
    110110
    111111          // set up skybox
    112           sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox2");
     112          sceneMgr_->setSkyBox(true, "Examples/SceneSkyBox1");
    113113
    114114          // set up one light_ source
  • code/branches/main_reto/src/orxonox_ship.cc

    r192 r267  
    2626 */
    2727
    28 #include "OgreSceneManager.h"
     28#include "OgreMath.h"
     29#include "OgreVector3.h"
     30#include "OgreQuaternion.h"
    2931#include "OgreSceneNode.h"
    3032#include "OgreEntity.h"
    31 #include "OgreVector3.h"
    32 #include "OgreStringConverter.h"
     33#include "OgreSceneManager.h"
     34#include "OgreParticleSystem.h"
    3335
    3436#include "inertial_node.h"
     37#include "run_manager.h"
    3538#include "weapon/bullet.h"
    3639#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"
    3844
    3945#include "orxonox_ship.h"
     
    6571  * @param mNode The scene node which the ship will be attached to later.
    6672  */
    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)
    7277  {
    7378    rootNode_ = new InertialNode(node, Vector3::ZERO);
     
    8388    if (mainWeapon_)
    8489      delete mainWeapon_;
     90    if (railGunStation_)
     91      delete railGunStation_;
    8592    if (rootNode_)
    8693      delete rootNode_;
     
    110117
    111118    // initialise weapon(s)
     119    ammoDump_ = new AmmunitionDump();
     120    ammoDump_->setDumpSize("Barrel", 1000);
     121    ammoDump_->store("Barrel", 420);
     122
    112123    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
    116139
    117140          return true;
     
    197220  * @return Bullet containing speed and entity.
    198221  */
    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");
    202231  }
    203232
  • code/branches/main_reto/src/orxonox_ship.h

    r190 r267  
    4040  {
    4141  public:
    42     OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode*, weapon::BulletManager*);
     42    OrxonoxShip(Ogre::SceneNode*);
    4343          virtual ~OrxonoxShip();
    4444
     
    5454    Ogre::Vector3 getSpeed();
    5555
    56           void fire();
     56    weapon::BaseWeapon* getMainWeapon();
     57
     58    int getAmmoStock();
    5759
    5860          bool tick(unsigned long, Ogre::Real);
     
    7476          //Ogre::Vector3 bulletSpeed_;
    7577
    76     weapon::WeaponManager *mainWeapon_;
     78    weapon::BaseWeapon *mainWeapon_;
     79    weapon::WeaponStation *railGunStation_;
     80
     81    weapon::AmmunitionDump *ammoDump_;
    7782  };
    7883
  • code/branches/main_reto/src/run_manager.cc

    r192 r267  
    5656#include "weapon/bullet.h"
    5757#include "weapon/bullet_manager.h"
    58 #include "weapon/weapon_manager.h"
     58#include "weapon/base_weapon.h"
     59
     60#include "hud/hud_overlay.h"
    5961
    6062#include "run_manager.h"
     63
     64namespace Ogre {
     65  using namespace orxonox;
     66  template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;
     67}
    6168
    6269namespace orxonox {
    6370  using namespace Ogre;
    6471  using namespace weapon;
     72  using namespace hud;
    6573
    6674  /**
     
    7785  */
    7886
     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
    7996
    8097  /**
     
    88105  */
    89106  RunManager::RunManager(OgreControl * ogre)
    90         : ogre_(ogre), window_(ogre->getRenderWindow()), leftButtonDown_(false),
     107        : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false),
    91108        statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0),
    92109        filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0),
     
    94111        debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0)
    95112  {
    96 
    97113    // SETTING UP THE SCENE
    98114
    99115    // create one new SceneManger
    100     sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "backgroundScene_");
     116    sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "Orxonox Scene");
    101117
    102118    // background scene (world objects, skybox, lights, etc.)
     
    108124    // create a bullet manager
    109125    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;*/
    116126
    117127
     
    131141
    132142    // 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)));
    135145
    136146
     
    153163    createViewports();
    154164
     165    // create HUD
     166    hud_ = new HUDOverlay();
     167    hud_->show();
     168
    155169
    156170    // Set default mipmap level (NB some APIs ignore this)
     
    163177    using namespace OIS;
    164178
    165     debugOverlay_ = OverlayManager::getSingleton()
    166       .getByName("Core/DebugOverlay");
     179    //debugOverlay_ = OverlayManager::getSingleton()
     180    //  .getByName("Core/DebugOverlay");
     181   
    167182
    168183    LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
     
    194209    windowResized(window_);
    195210
    196     showDebugOverlay(true);
     211    //showDebugOverlay(true);
    197212
    198213    // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE
     
    218233    if (bulletManager_)
    219234      delete bulletManager_;
    220 
    221     WeaponManager::destroyWeapons();
    222 
    223     // clean up the bullet list
    224     /*for (int i = 0; i < bulletsIndex_; i++)
    225       delete bullets_[i];
    226     delete bullets_;*/
    227235  }
    228236
     
    251259
    252260    // Update the 'HUD'
    253     updateStats();
     261    //updateStats();
    254262
    255263    // update the bullet positions
    256264    bulletManager_->tick(time, deltaTime);
    257265
    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     }*/
    264266
    265267    // HUMAN INTERFACE
     
    293295    // keep rendering
    294296    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;
    295331  }
    296332
     
    367403      playerShip_->setYThrust(0);
    368404
     405    if (keyboard_->isKeyDown(KC_G))
     406      playerShip_->getMainWeapon()->addAction(BaseWeapon::RELOAD);
     407
    369408    if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) )
    370409      return false;
     
    373412    {
    374413      statsOn_ = !statsOn_;
    375       showDebugOverlay(statsOn_);
     414      //showDebugOverlay(statsOn_);
    376415      timeUntilNextToggle_ = 1;
    377416    }
     
    398437      MaterialManager::getSingleton().setDefaultAnisotropy(aniso_);
    399438
    400       showDebugOverlay(statsOn_);
     439      //showDebugOverlay(statsOn_);
    401440      timeUntilNextToggle_ = 1;
    402441    }
     
    434473    if(displayCameraDetails)
    435474      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());
    437481    // debugText_ = "P: " + StringConverter::toString(camera_
    438482    //      ->getDerivedPosition()) + " " + "O: "
     
    457501    const MouseState &ms = mouse_->getMouseState();
    458502
    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
    493509    playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_));
    494510    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);
    497511
    498512    // keep rendering
     
    565579
    566580
    567 
    568581  /**
    569582  * Simple camera creator.
     
    583596  /**
    584597  * Simple viewport creator.
    585   * TODO: fully understand the concept of viewports concerning orxnox.
    586   * E.g. do we need splitscreen mode?
    587598  * For now the viewport uses the entire render window and is based on the one
    588599  * camera created so far.
  • code/branches/main_reto/src/run_manager.h

    r190 r267  
    3333#include "OgreWindowEventUtilities.h"
    3434#include "OgreTextureManager.h"
     35#include "OgreSingleton.h"
    3536
    3637#include <OIS/OISPrereqs.h>
     
    4344  // let the class inherit from WindowEventListener in order for the RunMgr
    4445  // 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>
    4648  {
    4749  public:
    48           RunManager(OgreControl*);
     50    RunManager(OgreControl*);
    4951
    50           virtual ~RunManager();
     52    virtual ~RunManager();
     53    //void initialise(OgreControl*);
    5154
    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
    5371
    5472  protected:
    55           virtual void createCamera(void);
     73          void createCamera(void);
    5674
    57           virtual void createViewports(void);
     75          void createViewports(void);
    5876
    5977
     
    6179
    6280          //Adjust mouse clipping area
    63           virtual void windowResized(Ogre::RenderWindow*);
     81          void windowResized(Ogre::RenderWindow*);
    6482
    6583          //Unattach OIS before window shutdown (very important under Linux)
    66           virtual void windowClosed(Ogre::RenderWindow*);
     84          void windowClosed(Ogre::RenderWindow*);
    6785
    6886
    6987          /** INPUT PROCESSING **/
    70           virtual bool processUnbufferedKeyInput();
     88          bool processUnbufferedKeyInput();
    7189
    72           virtual bool processUnbufferedMouseInput();
     90          bool processUnbufferedMouseInput();
    7391
    7492
    7593          /** OUTPUT **/
    7694
    77           virtual void updateStats(void);
     95          void updateStats(void);
    7896
    79           virtual void showDebugOverlay(bool);
     97          void showDebugOverlay(bool);
    8098
    8199  protected:
     100    // directly Ogre related fields
    82101          Ogre::SceneManager *sceneMgr_;
    83102          Ogre::RenderWindow *window_;
    84103          Ogre::Camera       *camera_;
     104
     105
     106    // self made orxonox fields
    85107          OgreControl  *ogre_;
    86108          OrxonoxScene *backgroundScene_;
    87109          OrxonoxShip  *playerShip_;
     110    hud::HUDOverlay   *hud_;
    88111
     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
    89122          bool statsOn_;
    90123          std::string debugText_;
     
    93126          // just to stop toggles flipping too fast
    94127          Ogre::Real timeUntilNextToggle_;
    95           bool leftButtonDown_;
     128          //bool leftButtonDown_;
    96129          Ogre::TextureFilterOptions filtering_;
    97130          int aniso_;
    98 
    99131          int sceneDetailIndex_;
    100132          Ogre::Overlay* debugOverlay_;
     
    106138          OIS::JoyStick* joystick_;
    107139
    108     const Ogre::Real mouseSensitivity_;
    109 
    110     // Bullet array
    111           /*Bullet **bullets_;
    112           int bulletsSize_;
    113           int bulletsIndex_;*/
    114     weapon::BulletManager *bulletManager_;
    115 
    116           // previously elapsed render time
    117           unsigned long totalTime_;
    118 
    119140  };
    120141
  • 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.