Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon_system/BaseWeapon.cc @ 680

Last change on this file since 680 was 680, checked in by rgrieder, 16 years ago
  • removed some gcc warnings in weapon system
File size: 4.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OgreMath.h"
29#include "OgreVector3.h"
30#include "OgreStringConverter.h"
31#include "OgreSceneNode.h"
32#include "OgreEntity.h"
33#include "OgreSceneManager.h"
34
35#include "../../Orxonox.h"
36
37#include "Bullet.h"
38#include "BulletManager.h"
39#include "AmmunitionDump.h"
40
41#include "BaseWeapon.h"
42
43
44namespace orxonox {
45  using namespace Ogre;
46 
47  //CreateFactory(BaseWeapon);
48
49  float BaseWeapon::nextActionValidityPeriod_s = 0.5;
50
51  BaseWeapon::BaseWeapon()
52    : sceneMgr_(Orxonox::getSingleton()->getSceneManager()),
53      bulletCounter_(0),
54      bulletManager_(Orxonox::getSingleton()->getBulletMgr()),
55      ammoDump_(NULL),
56      primaryFireRequest_(false), secondaryFireRequest_(false),
57      totalTime_(0.0f), actionStartTime_(0.0f),
58      currentState_(IDLE), secondaryFired_(false),
59      nextAction_(NOTHING), actionAdded_(false),
60      timeSinceNextActionAdded_(0.0f),
61      leftAmmo_(0)
62  {
63    RegisterObject(BaseWeapon);
64  }
65
66
67  BaseWeapon::~BaseWeapon()
68  {
69  }
70
71
72  bool BaseWeapon::addAction(const Action act)
73  {
74    if (nextAction_ == NOTHING)
75    {
76      nextAction_ = act;
77      actionAdded_ = true;
78      return true;
79    }
80    else
81      return false;
82  }
83
84
85  void BaseWeapon::primaryFireRequest()
86  {
87    primaryFireRequest_ = true;
88  }
89
90
91  void BaseWeapon::secondaryFireRequest()
92  {
93    secondaryFireRequest_ = true;
94  }
95
96
97  void BaseWeapon::tick(float dt)
98  {
99    totalTime_ += dt;
100    // process action adder
101    if (actionAdded_)
102    {
103      timeSinceNextActionAdded_ = totalTime_;
104      actionAdded_ = false;
105    }
106
107    switch (currentState_)
108    {
109    case IDLE:
110      break;
111
112    case PRIMARY_FIRE:
113      primaryFiring(totalTime_ - actionStartTime_);
114      break;
115
116    case SECONDARY_FIRE:
117      secondaryFiring(totalTime_ - actionStartTime_);
118      break;
119
120    case RELOADING:
121      break;
122
123    case CHANGING_AMMO:
124      break;
125    }
126
127    if (currentState_ == IDLE)
128    {
129      // first, process next action
130      if (nextAction_ != NOTHING)
131      {
132        actionStartTime_ = totalTime_;
133        switch (nextAction_)
134        {
135        case RELOAD:
136          leftAmmo_ += ammoDump_->getAmmunition("Barrel", magazineSize_ - leftAmmo_);
137          break;
138
139        case CHANGE_AMMO:
140          break;
141
142        case SPECIAL:
143          break;
144
145        default:
146          break;
147        }
148
149        // pay attention when multithreaded!
150        nextAction_ = NOTHING;
151      }
152      else
153      {
154        // secondly, execute firing
155        if (primaryFireRequest_ && !(secondaryFired_ && secondaryFireRequest_))
156        {
157          actionStartTime_ = totalTime_;
158          currentState_ = PRIMARY_FIRE;
159          secondaryFired_ = false;
160          primaryFire();
161        }
162        else if (secondaryFireRequest_)
163        {
164          actionStartTime_ = totalTime_;
165          currentState_ = SECONDARY_FIRE;
166          secondaryFired_ = true;
167          secondaryFire();
168        }
169      }
170    }
171
172    primaryFireRequest_ = false;
173    secondaryFireRequest_ = false;
174
175    if (totalTime_ - timeSinceNextActionAdded_ > nextActionValidityPeriod_s)
176      nextAction_ = NOTHING;
177  }
178
179
180  int BaseWeapon::getAmmoState()
181  {
182    return leftAmmo_;
183  }
184
185  void BaseWeapon::setAmmoDump(AmmunitionDump* dump)
186  {
187    this->ammoDump_ = dump;
188  }
189}
Note: See TracBrowser for help on using the repository browser.