| 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 "base_weapon.h" | 
|---|
| 40 |  | 
|---|
| 41 | #include "barrel_gun.h" | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | namespace orxonox { | 
|---|
| 45 | namespace weapon { | 
|---|
| 46 |   using namespace Ogre; | 
|---|
| 47 |  | 
|---|
| 48 |   BarrelGun::BarrelGun(InertialNode *node, AmmunitionDump *ammoDump) | 
|---|
| 49 |         : BaseWeapon(node, ammoDump) | 
|---|
| 50 |   { | 
|---|
| 51 |     name_ = "Barrel Gun"; | 
|---|
| 52 |     primaryFirePower_ = 100; | 
|---|
| 53 |     secondaryFirePower_ = 500; | 
|---|
| 54 |     primaryFiringRate_ = 10; | 
|---|
| 55 |     secondaryFiringRate_ = 2; | 
|---|
| 56 |     primaryBulletSpeed_ = 1000; | 
|---|
| 57 |     secondaryBulletSpeed_ = 500; | 
|---|
| 58 |     magazineSize_ = 25; | 
|---|
| 59 |   } | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 |   BarrelGun::~BarrelGun() | 
|---|
| 63 |   { | 
|---|
| 64 |   } | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 |   void BarrelGun::primaryFire() | 
|---|
| 68 |   { | 
|---|
| 69 |     if (leftAmmo_ < 1) | 
|---|
| 70 |     { | 
|---|
| 71 |       currentState_ = IDLE; | 
|---|
| 72 |       return; | 
|---|
| 73 |     } | 
|---|
| 74 |  | 
|---|
| 75 |     SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( | 
|---|
| 76 |           node_->getSceneNode()->getWorldPosition(), | 
|---|
| 77 |           node_->getSceneNode()->getWorldOrientation()); | 
|---|
| 78 |  | 
|---|
| 79 |     Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" | 
|---|
| 80 |           + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); | 
|---|
| 81 |  | 
|---|
| 82 |     Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1)) | 
|---|
| 83 |           .normalisedCopy() * primaryBulletSpeed_; | 
|---|
| 84 |     speed += node_->getWorldSpeed(); | 
|---|
| 85 |  | 
|---|
| 86 |           temp->setScale(Vector3(1, 1, 1) * 4); | 
|---|
| 87 |           temp->yaw(Degree(-90)); | 
|---|
| 88 |  | 
|---|
| 89 |           bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); | 
|---|
| 90 |  | 
|---|
| 91 |     --leftAmmo_; | 
|---|
| 92 |   } | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 |   void BarrelGun::primaryFiring(unsigned int time) | 
|---|
| 96 |   { | 
|---|
| 97 |     if (time > (unsigned int)1000/primaryFiringRate_) | 
|---|
| 98 |     { | 
|---|
| 99 |       currentState_ = IDLE; | 
|---|
| 100 |     } | 
|---|
| 101 |   } | 
|---|
| 102 |  | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 |   void BarrelGun::secondaryFire() | 
|---|
| 106 |   { | 
|---|
| 107 |     if (leftAmmo_ < 5) | 
|---|
| 108 |     { | 
|---|
| 109 |       currentState_ = IDLE; | 
|---|
| 110 |       return; | 
|---|
| 111 |     } | 
|---|
| 112 |  | 
|---|
| 113 |     SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( | 
|---|
| 114 |           node_->getSceneNode()->getWorldPosition(), | 
|---|
| 115 |           node_->getSceneNode()->getWorldOrientation()); | 
|---|
| 116 |  | 
|---|
| 117 |     Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" | 
|---|
| 118 |           + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); | 
|---|
| 119 |  | 
|---|
| 120 |     Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1)) | 
|---|
| 121 |           .normalisedCopy() * secondaryBulletSpeed_*0.5; | 
|---|
| 122 |     speed += node_->getWorldSpeed(); | 
|---|
| 123 |  | 
|---|
| 124 |           temp->setScale(Vector3(1, 1, 1) * 10); | 
|---|
| 125 |           temp->yaw(Degree(-90)); | 
|---|
| 126 |  | 
|---|
| 127 |           bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); | 
|---|
| 128 |  | 
|---|
| 129 |     leftAmmo_ -= 5; | 
|---|
| 130 |   } | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 |   void BarrelGun::secondaryFiring(unsigned int time) | 
|---|
| 134 |   { | 
|---|
| 135 |     if (time > (unsigned int)1000/secondaryFiringRate_) | 
|---|
| 136 |       currentState_ = IDLE; | 
|---|
| 137 |   } | 
|---|
| 138 |  | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|