Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 11, 2007, 2:24:50 PM (17 years ago)
Author:
rgrieder
Message:
  • added primary and secondary fire in continuous mode
  • weapon manager yet very inflexible (one weapon, static values, etc.)
File:
1 edited

Legend:

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