Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2007, 12:44:02 AM (17 years ago)
Author:
rgrieder
Message:
  • modified the AmmunitionDump to hold different types of ammo
  • converted the RunManager into a Singleton
  • added some methods to address ammo by string
  • created a BaseWeapon class
  • derived BarrelGun from BaseWeapon
Location:
code/branches/main_reto_vs05/src
Files:
24 added
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto_vs05/src/main.cc

    r178 r232  
    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_vs05/src/orxonox_prerequisites.h

    r198 r232  
    4747    class BulletManager;
    4848    class BaseWeapon;
     49    class BarrelGun;
    4950    class WeaponStation;
    5051
  • code/branches/main_reto_vs05/src/orxonox_ship.cc

    r198 r232  
    3434
    3535#include "inertial_node.h"
     36#include "run_manager.h"
    3637#include "weapon/bullet.h"
    3738#include "weapon/bullet_manager.h"
    3839#include "weapon/weapon_station.h"
    3940#include "weapon/base_weapon.h"
     41#include "weapon/barrel_gun.h"
    4042#include "weapon/ammunition_dump.h"
    4143
     
    6870  * @param mNode The scene node which the ship will be attached to later.
    6971  */
    70   OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node,
    71         BulletManager *bulletManager)
    72               : sceneMgr_(sceneMgr),
    73         baseThrust_(1000), currentThrust_(Vector3::ZERO),
    74         objectCounter_(0), bulletManager_(bulletManager)
     72  OrxonoxShip::OrxonoxShip(SceneNode *node)
     73    : sceneMgr_(RunManager::getSingletonPtr()->getSceneManagerPtr()),
     74      bulletManager_(RunManager::getSingletonPtr()->getBulletManagerPtr()),
     75      baseThrust_(1000), currentThrust_(Vector3::ZERO), objectCounter_(0)
    7576  {
    7677    rootNode_ = new InertialNode(node, Vector3::ZERO);
     
    115116
    116117    // initialise weapon(s)
    117     ammoDump_ = new AmmunitionDump(420);
    118     ammoDump_->store(420);
     118    ammoDump_ = new AmmunitionDump();
     119    ammoDump_->setDumpSize("Barrel", 1000);
     120    ammoDump_->store("Barrel", 420);
    119121
    120122    InertialNode *mainWeaponNode = rootNode_->createChildNode();
    121     mainWeapon_ = new BaseWeapon(sceneMgr_, mainWeaponNode,
    122           bulletManager_, ammoDump_);
     123    mainWeapon_ = new BarrelGun(mainWeaponNode, ammoDump_);
    123124
    124125    railGunStation_ = new WeaponStation(4);
     
    216217  int OrxonoxShip::getAmmoStock()
    217218  {
    218     return ammoDump_->getStockSize();
     219    return ammoDump_->getStockSize("Barrel");
    219220  }
    220221
  • code/branches/main_reto_vs05/src/orxonox_ship.h

    r198 r232  
    4040  {
    4141  public:
    42     OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode*, weapon::BulletManager*);
     42    OrxonoxShip(Ogre::SceneNode*);
    4343          virtual ~OrxonoxShip();
    4444
  • code/branches/main_reto_vs05/src/run_manager.cc

    r198 r232  
    6060#include "run_manager.h"
    6161
     62namespace Ogre {
     63  using namespace orxonox;
     64  template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;
     65}
     66
    6267namespace orxonox {
    6368  using namespace Ogre;
     
    7782  */
    7883
     84  RunManager* RunManager::getSingletonPtr(void)
     85  {
     86      return ms_Singleton;
     87  }
     88  RunManager& RunManager::getSingleton(void)
     89  { 
     90      assert( ms_Singleton );  return ( *ms_Singleton ); 
     91  }
     92
    7993
    8094  /**
     
    94108        debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0)
    95109  {
    96 
    97110    // SETTING UP THE SCENE
    98111
    99112    // create one new SceneManger
    100     sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "backgroundScene_");
     113    sceneMgr_ = ogre_->getRoot()->createSceneManager(ST_GENERIC, "Orxonox Scene");
    101114
    102115    // background scene (world objects, skybox, lights, etc.)
     
    125138
    126139    // Construct a new spaceship and give it the node
    127     playerShip_ = new OrxonoxShip(sceneMgr_, sceneMgr_->getRootSceneNode()
    128       ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)), bulletManager_);
     140    playerShip_ = new OrxonoxShip(sceneMgr_->getRootSceneNode()
     141      ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)));
    129142
    130143
     
    274287    // keep rendering
    275288    return true;
     289  }
     290
     291
     292  SceneManager& RunManager::getSceneManager()
     293  {
     294    return *sceneMgr_;
     295  }
     296
     297  SceneManager* RunManager::getSceneManagerPtr()
     298  {
     299    return sceneMgr_;
     300  }
     301
     302  BulletManager* RunManager::getBulletManagerPtr()
     303  {
     304    return bulletManager_;
     305  }
     306
     307  int RunManager::getAmmunitionID(const Ogre::String &ammoName)
     308  {
     309    Ogre::String ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" };
     310    int ammoTypesLength = 3;
     311
     312    for (int i = 0; i < ammoTypesLength; i++)
     313    {
     314      if (ammoTypes[i] == ammoName)
     315        return i;
     316    }
     317    return -1;
     318  }
     319
     320  int RunManager::getNumberOfAmmos()
     321  {
     322    return 3;
    276323  }
    277324
  • code/branches/main_reto_vs05/src/run_manager.h

    r194 r232  
    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:
  • code/branches/main_reto_vs05/src/weapon/ammunition_dump.cc

    r198 r232  
    2626 */
    2727
     28#include "run_manager.h"
     29
    2830#include "ammunition_dump.h"
    2931
     
    3234namespace weapon {
    3335
    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_])
    3640  {
     41    for (int i = 0; i < numberOfAmmos_; i++)
     42    {
     43      stock_[i] = 0;
     44      capacity_[i] = 0;
     45    }
    3746  }
    3847
     
    4049  AmmunitionDump::~AmmunitionDump()
    4150  {
     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;
    4265  }
    4366
    4467 
    45   void AmmunitionDump::store(int quantity)
     68  int AmmunitionDump::store(const Ogre::String &name, int quantity)
    4669  {
    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;
    5082  }
    5183
    5284
    53   int AmmunitionDump::getAmmunition(int quantity)
     85  int AmmunitionDump::getAmmunition(const Ogre::String &name, int quantity)
    5486  {
    55     if (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;
    6092    else
    6193    {
    62       quantity = stock_;
    63       stock_ = 0;
    64       return quantity;
     94      quantity = stock_[id];
     95      stock_[id] = 0;
    6596    }
     97    return quantity;
    6698  }
    6799
    68100
    69   int AmmunitionDump::getStockSize()
     101  int AmmunitionDump::getStockSize(const Ogre::String &name)
    70102  {
    71     return stock_;
     103    int id = RunManager::getSingletonPtr()->getAmmunitionID(name);
     104    if (id = -1)
     105      return -1;
     106    return stock_[id];
    72107  }
    73108}
  • code/branches/main_reto_vs05/src/weapon/ammunition_dump.h

    r198 r232  
    4141  {
    4242  public:
    43           AmmunitionDump(int capacity);
     43    AmmunitionDump();
    4444          ~AmmunitionDump();
    4545
    46     void store(int quantiy);
     46    void setDumpSize(const Ogre::String &name, int size);
    4747
    48     int getAmmunition(int quantity);
     48    int store(const Ogre::String &name, int quantiy);
    4949
    50     int getStockSize();
     50    int getAmmunition(const Ogre::String &name, int quantity);
     51
     52    int getStockSize(const Ogre::String &name);
    5153
    5254  protected:
    53     int stock_;
    54     int capacity_;
     55    int numberOfAmmos_;
     56    int *stock_;
     57    int *capacity_;
    5558
    5659  protected:
  • code/branches/main_reto_vs05/src/weapon/base_weapon.cpp

    r198 r232  
    3737#include "inertial_node.h"
    3838#include "ammunition_dump.h"
     39#include "run_manager.h"
    3940
    4041#include "base_weapon.h"
     
    4546  using namespace Ogre;
    4647
    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)
    5756  {
    58     leftAmmo_ = ammoDump_->getAmmunition(magazineSize_);
     57    leftAmmo_ = 0;
    5958  }
    6059
     
    8483
    8584
    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 
    12385  void BaseWeapon::secondaryFireRequest()
    12486  {
    12587    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;
    16188  }
    16289
     
    181108        {
    182109        case RELOAD:
    183           leftAmmo_ += ammoDump_->getAmmunition(magazineSize_ - leftAmmo_);
     110          leftAmmo_ += ammoDump_->getAmmunition("Barrel", magazineSize_ - leftAmmo_);
    184111          break;
    185112
  • code/branches/main_reto_vs05/src/weapon/base_weapon.h

    r198 r232  
    5858
    5959  public:
    60     BaseWeapon(Ogre::SceneManager*, InertialNode*, BulletManager*,
    61           AmmunitionDump*);
     60    BaseWeapon(InertialNode*, AmmunitionDump*);
    6261          virtual ~BaseWeapon();
    6362
     
    7372
    7473  protected:
    75     void primaryFire();
     74    virtual void primaryFire() = 0;
    7675
    77     void primaryFiring(unsigned int);
     76    virtual void primaryFiring(unsigned int) = 0;
    7877
    79     void secondaryFire();
     78    virtual void secondaryFire() = 0;
    8079
    81     void secondaryFiring(unsigned int);
     80    virtual void secondaryFiring(unsigned int) = 0;
    8281
    8382  public:
Note: See TracChangeset for help on using the changeset viewer.