Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2007, 12:44:02 AM (16 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.