Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 7, 2007, 12:39:30 AM (16 years ago)
Author:
rgrieder
Message:
 
File:
1 edited

Legend:

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

    r169 r177  
    2727
    2828#include "OgreSceneManager.h"
     29#include "OgreEntity.h"
     30#include "OgreSceneNode.h"
     31#include "OgreVector3.h"
     32#include "OgreStringConverter.h"
    2933
    3034#include "weapon.h"
     35#include "bullet.h"
     36#include "bullet_manager.h"
    3137#include "weapon_manager.h"
     38
     39#define ACTION_LIST_SIZE 4
    3240
    3341
     
    3846
    3947  WeaponManager::WeaponManager(SceneManager *sceneMgr, SceneNode *node,
    40         int slotSize)
    41         : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0)
     48        BulletManager *bulletManager, int slotSize)
     49        : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0),
     50        bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE),
     51        secondaryFireRequest_(false), selectedWeapon_(0),
     52        bulletManager_(bulletManager),
     53        actionListReadIndex_(0), actionListWriteIndex_(0)
    4254  {
    4355        slots_ = new Weapon*[slotSize];
     56    actionList_ = new Action[ACTION_LIST_SIZE];
     57    for (int i = 0; i < ACTION_LIST_SIZE; i++)
     58      actionList_[i] = NOTHING;
    4459  }
    4560
     
    4964    if (slots_)
    5065      delete slots_;
     66    if (actionList_)
     67      delete actionList_;
    5168  }
    5269
     
    5471  bool WeaponManager::addWeapon(const Ogre::String &name)
    5572  {
     73    if (!weaponList_s)
     74      return false;
     75
    5676    if (name == weaponList_s[0]->name_)
    5777    {
    5878      // this is ugly, but for the time being, it has to fit.
     79      selectedWeapon_ = slotIndex_;
    5980      slots_[slotIndex_++] = weaponList_s[0];
    6081      return true;
     
    6586
    6687
     88  bool WeaponManager::addAction(const Action act)
     89  {
     90    if (actionList_[actionListWriteIndex_] == NOTHING)
     91    {
     92      actionList_[actionListWriteIndex_] = act;
     93      actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;
     94      return true;
     95    }
     96    else
     97      return false;
     98  }
     99
     100
     101  void WeaponManager::primaryFireRequest()
     102  {
     103    primaryFireRequest_ = true;
     104  }
     105
     106
     107  void WeaponManager::primaryFire()
     108  {
     109    currentState_ = PRIMARY_FIRE;
     110
     111    // TODO: add the name of the weapon manager. but for that,
     112    // the factory is required.
     113    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
     114          "BulletNode" + StringConverter::toString(bulletCounter_),
     115          node_->getWorldPosition(), node_->getWorldOrientation());
     116          temp->setScale(Vector3(1, 1, 1) * 10);
     117          temp->yaw(Degree(-90));
     118    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
     119          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
     120    Vector3 speed = (node_->getOrientation() * Vector3(0, 0, -1))
     121          .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_;
     122          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
     123 
     124    currentState_ = IDLE;
     125  }
     126
     127
     128  void WeaponManager::secondaryFireRequest()
     129  {
     130    secondaryFireRequest_ = true;
     131  }
     132
     133  void WeaponManager::secondaryFire()
     134  {
     135  }
     136
     137
     138  bool WeaponManager::tick(unsigned long time, Real deltaTime)
     139  {
     140    // return if no weapon has been added
     141    if (!slots_[slotIndex_])
     142      return true;
     143
     144    switch (currentState_)
     145    {
     146    case IDLE:
     147      // first, process actions
     148      if (actionList_[actionListReadIndex_] != NOTHING)
     149      {
     150        actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE;
     151        break;
     152      }
     153
     154      switch (actionList_[actionListReadIndex_])
     155      {
     156      case RELOAD:
     157        break;
     158
     159      case ZOOM_IN:
     160        break;
     161
     162      case ZOOM_OUT:
     163        break;
     164
     165      default:
     166        break;
     167      }
     168
     169      // secondly, execute firing
     170      if (primaryFireRequest_)
     171        primaryFire();
     172      else if (secondaryFireRequest_)
     173        secondaryFire();
     174
     175      break;
     176
     177    case PRIMARY_FIRE:
     178      break;
     179
     180    case SECONDARY_FIRE:
     181      break;
     182
     183    case RELOADING:
     184      break;
     185    }
     186
     187    primaryFireRequest_ = false;
     188    secondaryFireRequest_ = false;
     189
     190    return true;
     191  }
     192
     193
    67194  // static
    68195  bool WeaponManager::loadWeapons()
    69196  {
    70     weaponList_s[0] = new Weapon("Barrel Gun", 10, 2);
     197    weaponList_s = new Weapon*[5];
     198    for (int i = 0; i < 5; i++)
     199      weaponList_s[i] = NULL;
     200    weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);
    71201    return true;
    72202  }
     
    76206  void WeaponManager::destroyWeapons()
    77207  {
    78     delete weaponList_s[0];
     208    if (weaponList_s)
     209    {
     210      for (int i = 0; i < 5; i++)
     211        if (weaponList_s[i])
     212          delete weaponList_s[i];
     213      delete weaponList_s;
     214    }
    79215  }
    80216
Note: See TracChangeset for help on using the changeset viewer.