Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/weapon/barrel_gun.cc @ 507

Last change on this file since 507 was 341, checked in by rgrieder, 17 years ago
  • removed folder src/class_hierarchy
  • removed a few unnec. files in src/
  • added a few files in src/orxonox to make weapon system and hud work
  • restructured all CMLs
  • adjusted all the #include directives (only one include directory now: src)
  • moved ENET library linkage to CML in src/orxonox
File size: 3.5 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 "orxonox/inertial_node.h"
36
37#include "bullet.h"
38#include "bullet_manager.h"
39#include "ammunition_dump.h"
40#include "base_weapon.h"
41
42#include "barrel_gun.h"
43
44
45namespace orxonox {
46namespace weapon {
47  using namespace Ogre;
48
49  BarrelGun::BarrelGun(InertialNode *node, AmmunitionDump *ammoDump)
50        : BaseWeapon(node, ammoDump)
51  {
52    name_ = "Barrel Gun";
53    primaryFirePower_ = 100;
54    secondaryFirePower_ = 500;
55    primaryFiringRate_ = 10;
56    secondaryFiringRate_ = 2;
57    primaryBulletSpeed_ = 1000;
58    secondaryBulletSpeed_ = 500;
59    magazineSize_ = 25;
60  }
61
62
63  BarrelGun::~BarrelGun()
64  {
65  }
66
67
68  void BarrelGun::primaryFire()
69  {
70    if (leftAmmo_ < 1)
71    {
72      currentState_ = IDLE;
73      return;
74    }
75
76    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
77          node_->getSceneNode()->getWorldPosition(),
78          node_->getSceneNode()->getWorldOrientation());
79
80    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
81          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
82
83    Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))
84          .normalisedCopy() * primaryBulletSpeed_;
85    speed += node_->getWorldSpeed();
86
87          temp->setScale(Vector3(1, 1, 1) * 4);
88          temp->yaw(Degree(-90));
89
90          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
91
92    --leftAmmo_;
93  }
94
95
96  void BarrelGun::primaryFiring(unsigned int time)
97  {
98    if (time > (unsigned int)1000/primaryFiringRate_)
99    {
100      currentState_ = IDLE;
101    }
102  }
103
104
105
106  void BarrelGun::secondaryFire()
107  {
108    if (leftAmmo_ < 5)
109    {
110      currentState_ = IDLE;
111      return;
112    }
113
114    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
115          node_->getSceneNode()->getWorldPosition(),
116          node_->getSceneNode()->getWorldOrientation());
117
118    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
119          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
120
121    Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))
122          .normalisedCopy() * secondaryBulletSpeed_*0.5;
123    speed += node_->getWorldSpeed();
124
125          temp->setScale(Vector3(1, 1, 1) * 10);
126          temp->yaw(Degree(-90));
127
128          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
129
130    leftAmmo_ -= 5;
131  }
132
133
134  void BarrelGun::secondaryFiring(unsigned int time)
135  {
136    if (time > (unsigned int)1000/secondaryFiringRate_)
137      currentState_ = IDLE;
138  }
139
140}
141}
Note: See TracBrowser for help on using the repository browser.