Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto_vs05/src/weapon/base_weapon.cpp @ 232

Last change on this file since 232 was 232, checked in by rgrieder, 16 years ago
  • 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 size: 4.0 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 modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (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, see <http://www.gnu.org/licenses/>.
19 *
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 "bullet.h"
36#include "bullet_manager.h"
37#include "inertial_node.h"
38#include "ammunition_dump.h"
39#include "run_manager.h"
40
41#include "base_weapon.h"
42
43
44namespace orxonox {
45namespace weapon {
46  using namespace Ogre;
47
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)
56  {
57    leftAmmo_ = 0;
58  }
59
60
61  BaseWeapon::~BaseWeapon()
62  {
63  }
64
65
66  bool BaseWeapon::addAction(const Action act)
67  {
68    if (nextAction_ == NOTHING)
69    {
70      nextAction_ = act;
71      actionAdded_ = true;
72      return true;
73    }
74    else
75      return false;
76  }
77
78
79  void BaseWeapon::primaryFireRequest()
80  {
81    primaryFireRequest_ = true;
82  }
83
84
85  void BaseWeapon::secondaryFireRequest()
86  {
87    secondaryFireRequest_ = true;
88  }
89
90
91  bool BaseWeapon::tick(unsigned long time, Real deltaTime)
92  {
93    // process action adder
94    if (actionAdded_)
95    {
96      timeSinceNextActionAdded_ = time;
97      actionAdded_ = false;
98    }
99
100    switch (currentState_)
101    {
102    case IDLE:
103      // first, process next action
104      if (nextAction_ != NOTHING)
105      {
106        actionStartTime_ = time;
107        switch (nextAction_)
108        {
109        case RELOAD:
110          leftAmmo_ += ammoDump_->getAmmunition("Barrel", magazineSize_ - leftAmmo_);
111          break;
112
113        case CHANGE_AMMO:
114          break;
115
116        case SPECIAL:
117          break;
118
119        default:
120          break;
121        }
122
123        // pay attention when multithreaded!
124        nextAction_ = NOTHING;
125      }
126      else
127      {
128        // secondly, execute firing
129        if (primaryFireRequest_ && !(secondaryFired_ && secondaryFireRequest_))
130        {
131          actionStartTime_ = time;
132          currentState_ = PRIMARY_FIRE;
133          secondaryFired_ = false;
134          primaryFire();
135        }
136        else if (secondaryFireRequest_)
137        {
138          actionStartTime_ = time;
139          currentState_ = SECONDARY_FIRE;
140          secondaryFired_ = true;
141          secondaryFire();
142        }
143      }
144
145      break;
146
147    case PRIMARY_FIRE:
148      primaryFiring((unsigned int)(time - actionStartTime_));
149      break;
150
151    case SECONDARY_FIRE:
152      secondaryFiring((unsigned int)(time - actionStartTime_));
153      break;
154
155    case RELOADING:
156      break;
157
158    case CHANGING_AMMO:
159      break;
160    }
161
162    primaryFireRequest_ = false;
163    secondaryFireRequest_ = false;
164
165    if (time - timeSinceNextActionAdded_ > nextActionValidityPeriod_)
166      nextAction_ = NOTHING;
167
168    return true;
169  }
170
171
172  int BaseWeapon::getAmmoState()
173  {
174    return leftAmmo_;
175  }
176}
177}
Note: See TracBrowser for help on using the repository browser.