Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 11, 2007, 2:24:50 PM (16 years ago)
Author:
rgrieder
Message:
  • added primary and secondary fire in continuous mode
  • weapon manager yet very inflexible (one weapon, static values, etc.)
Location:
code/branches/main_reto_vs05/src
Files:
6 edited

Legend:

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

    r193 r194  
    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"
    3334
    3435#include "inertial_node.h"
     
    197198  * @return Bullet containing speed and entity.
    198199  */
    199   void OrxonoxShip::fire()
    200   {
    201     mainWeapon_->primaryFireRequest();
     200  WeaponManager* OrxonoxShip::getMainWeapon()
     201  {
     202    return mainWeapon_;
    202203  }
    203204
  • code/branches/main_reto_vs05/src/orxonox_ship.h

    r189 r194  
    5454    Ogre::Vector3 getSpeed();
    5555
    56           void fire();
     56    weapon::WeaponManager* getMainWeapon();
    5757
    5858          bool tick(unsigned long, Ogre::Real);
  • code/branches/main_reto_vs05/src/run_manager.cc

    r193 r194  
    8888  */
    8989  RunManager::RunManager(OgreControl * ogre)
    90         : ogre_(ogre), window_(ogre->getRenderWindow()), leftButtonDown_(false),
     90        : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false),
    9191        statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0),
    9292        filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0),
     
    109109    bulletManager_ = new BulletManager(sceneMgr_);
    110110    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;*/
    116111
    117112
     
    220215
    221216    WeaponManager::destroyWeapons();
    222 
    223     // clean up the bullet list
    224     /*for (int i = 0; i < bulletsIndex_; i++)
    225       delete bullets_[i];
    226     delete bullets_;*/
    227217  }
    228218
     
    256246    bulletManager_->tick(time, deltaTime);
    257247
    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     }*/
    264248
    265249    // HUMAN INTERFACE
     
    366350    else
    367351      playerShip_->setYThrust(0);
     352
     353    if (keyboard_->isKeyDown(KC_G))
     354      playerShip_->getMainWeapon()->addAction(WeaponManager::RELOAD);
    368355
    369356    if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) )
     
    457444    const MouseState &ms = mouse_->getMouseState();
    458445
    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.
     446    if (ms.buttonDown(MB_Left))
     447      playerShip_->getMainWeapon()->primaryFireRequest();
     448
     449    if (ms.buttonDown(MB_Right))
     450      playerShip_->getMainWeapon()->secondaryFireRequest();
     451
    493452    playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_));
    494453    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);
    497454
    498455    // keep rendering
  • code/branches/main_reto_vs05/src/run_manager.h

    r189 r194  
    9393          // just to stop toggles flipping too fast
    9494          Ogre::Real timeUntilNextToggle_;
    95           bool leftButtonDown_;
     95          //bool leftButtonDown_;
    9696          Ogre::TextureFilterOptions filtering_;
    9797          int aniso_;
  • code/branches/main_reto_vs05/src/weapon/weapon_manager.cc

    r189 r194  
    5252        bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE),
    5353        secondaryFireRequest_(false), selectedWeapon_(0),
    54         bulletManager_(bulletManager),
    55         actionListReadIndex_(0), actionListWriteIndex_(0)
     54        bulletManager_(bulletManager), secondaryFired_(false),
     55        timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING)
    5656  {
    5757        slots_ = new Weapon*[slotSize];
    58     actionList_ = new Action[ACTION_LIST_SIZE];
    59     for (int i = 0; i < ACTION_LIST_SIZE; i++)
    60       actionList_[i] = NOTHING;
    6158  }
    6259
     
    6663    if (slots_)
    6764      delete slots_;
    68     if (actionList_)
    69       delete actionList_;
    7065  }
    7166
     
    9085  bool WeaponManager::addAction(const Action act)
    9186  {
    92     if (actionList_[actionListWriteIndex_] == NOTHING)
    93     {
    94       actionList_[actionListWriteIndex_] = act;
    95       actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;
     87    if (nextAction_ != NOTHING)
     88    {
     89      nextAction_ = act;
     90      actionAdded_ = true;
    9691      return true;
    9792    }
     
    109104  void WeaponManager::primaryFire()
    110105  {
    111     currentState_ = PRIMARY_FIRE;
    112 
    113     // TODO: add the name of the weapon manager. but for that,
    114     // the factory is required.
    115106    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
    116107          node_->getSceneNode()->getWorldPosition(),
     
    124115    speed += node_->getWorldSpeed();
    125116
     117          temp->setScale(Vector3(1, 1, 1) * 4);
     118          temp->yaw(Degree(-90));
     119
     120          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
     121  }
     122
     123
     124  void WeaponManager::primaryFiring(unsigned int time)
     125  {
     126    if (time > 100)
     127    {
     128      currentState_ = IDLE;
     129    }
     130  }
     131
     132
     133  void WeaponManager::secondaryFireRequest()
     134  {
     135    secondaryFireRequest_ = true;
     136  }
     137
     138
     139  void WeaponManager::secondaryFire()
     140  {
     141    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
     142          node_->getSceneNode()->getWorldPosition(),
     143          node_->getSceneNode()->getWorldOrientation());
     144
     145    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
     146          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
     147
     148    Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))
     149          .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_*0.5;
     150    speed += node_->getWorldSpeed();
     151
    126152          temp->setScale(Vector3(1, 1, 1) * 10);
    127153          temp->yaw(Degree(-90));
    128154
    129155          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
    130  
    131     currentState_ = IDLE;
    132   }
    133 
    134 
    135   void WeaponManager::secondaryFireRequest()
    136   {
    137     secondaryFireRequest_ = true;
    138   }
    139 
    140   void WeaponManager::secondaryFire()
    141   {
     156  }
     157
     158
     159  void WeaponManager::secondaryFiring(unsigned int time)
     160  {
     161    if (time > 250)
     162      currentState_ = IDLE;
    142163  }
    143164
     
    149170      return true;
    150171
     172    // process action adder
     173    if (actionAdded_)
     174    {
     175      timeSinceNextActionAdded_ = time;
     176      actionAdded_ = false;
     177    }
     178
    151179    switch (currentState_)
    152180    {
    153181    case IDLE:
    154       // first, process actions
    155       if (actionList_[actionListReadIndex_] != NOTHING)
     182      // first, process next action
     183      if (nextAction_ != NOTHING)
    156184      {
    157         actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE;
    158         break;
     185        actionStartTime_ = time;
     186        switch (nextAction_)
     187        {
     188        case RELOAD:
     189          break;
     190
     191        case CHANGE_AMMO:
     192          break;
     193
     194        case SPECIAL:
     195          break;
     196
     197        default:
     198          break;
     199        }
     200
     201        // pay attention when multithreaded!
     202        nextAction_ = NOTHING;
    159203      }
    160 
    161       switch (actionList_[actionListReadIndex_])
     204      else
    162205      {
    163       case RELOAD:
    164         break;
    165 
    166       case ZOOM_IN:
    167         break;
    168 
    169       case ZOOM_OUT:
    170         break;
    171 
    172       default:
    173         break;
     206        // secondly, execute firing
     207        if (primaryFireRequest_ && !(secondaryFired_ && secondaryFireRequest_))
     208        {
     209          actionStartTime_ = time;
     210          currentState_ = PRIMARY_FIRE;
     211          secondaryFired_ = false;
     212          primaryFire();
     213        }
     214        else if (secondaryFireRequest_)
     215        {
     216          actionStartTime_ = time;
     217          currentState_ = SECONDARY_FIRE;
     218          secondaryFired_ = true;
     219          secondaryFire();
     220        }
    174221      }
    175222
    176       // secondly, execute firing
    177       if (primaryFireRequest_)
    178         primaryFire();
    179       else if (secondaryFireRequest_)
    180         secondaryFire();
    181 
    182223      break;
    183224
    184225    case PRIMARY_FIRE:
     226      primaryFiring((unsigned int)(time - actionStartTime_));
    185227      break;
    186228
    187229    case SECONDARY_FIRE:
     230      secondaryFiring((unsigned int)(time - actionStartTime_));
    188231      break;
    189232
    190233    case RELOADING:
     234      break;
     235
     236    case CHANGING_AMMO:
    191237      break;
    192238    }
     
    194240    primaryFireRequest_ = false;
    195241    secondaryFireRequest_ = false;
     242
     243    if (time - timeSinceNextActionAdded_ > nextActionValidityPeriod_)
     244      nextAction_ = NOTHING;
    196245
    197246    return true;
     
    205254    for (int i = 0; i < 5; i++)
    206255      weaponList_s[i] = NULL;
    207     weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);
     256    weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 1000);
    208257    return true;
    209258  }
  • code/branches/main_reto_vs05/src/weapon/weapon_manager.h

    r189 r194  
    4444      NOTHING  = 0,
    4545      RELOAD   = 1,
    46       ZOOM_IN  = 2,
    47       ZOOM_OUT = 3
     46      CHANGE_AMMO  = 2,
     47      SPECIAL = 3
    4848    };
    4949
     
    5353      PRIMARY_FIRE = 1,
    5454      SECONDARY_FIRE = 2,
    55       RELOADING = 4
     55      RELOADING = 3,
     56      CHANGING_AMMO = 4,
    5657    };
    5758
     
    7778    void primaryFire();
    7879
     80    void primaryFiring(unsigned int);
     81
    7982    void secondaryFire();
     83
     84    void secondaryFiring(unsigned int);
    8085
    8186  public:
     
    97102    bool secondaryFireRequest_;
    98103
     104    unsigned long actionStartTime_;
     105
    99106    State currentState_;
     107    bool secondaryFired_;
    100108
    101     Action *actionList_;
    102     int actionListReadIndex_;
    103     int actionListWriteIndex_;
     109    Action nextAction_;
     110    bool actionAdded_;
     111    unsigned long timeSinceNextActionAdded_;
     112    static const unsigned long nextActionValidityPeriod_ = 500;
    104113
    105114    static Weapon **weaponList_s;
Note: See TracChangeset for help on using the changeset viewer.