| [3618] | 1 |  | 
|---|
 | 2 |  | 
|---|
| [4592] | 3 | /* | 
|---|
| [3618] | 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 5 |  | 
|---|
 | 6 |    Copyright (C) 2004 orx | 
|---|
 | 7 |  | 
|---|
 | 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 9 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 11 |    any later version. | 
|---|
 | 12 |  | 
|---|
 | 13 |    ### File Specific | 
|---|
 | 14 |    main-programmer: Patrick Boenzli | 
|---|
| [4592] | 15 |    co-programmer: | 
|---|
| [3631] | 16 |  | 
|---|
 | 17 |  | 
|---|
| [4836] | 18 |    @todo: direction in which the projectile flights | 
|---|
 | 19 |    @todo: a target to set/hit | 
|---|
| [3618] | 20 | */ | 
|---|
| [5357] | 21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| [3618] | 22 |  | 
|---|
| [5621] | 23 | #include "cannon.h" | 
|---|
| [3618] | 24 |  | 
|---|
 | 25 | #include "world_entity.h" | 
|---|
| [3677] | 26 | #include "model.h" | 
|---|
| [3710] | 27 | #include "test_bullet.h" | 
|---|
| [4955] | 28 | #include "weapon_manager.h" | 
|---|
| [5355] | 29 | #include "factory.h" | 
|---|
| [3618] | 30 |  | 
|---|
 | 31 | #include "vector.h" | 
|---|
| [3629] | 32 | #include "list.h" | 
|---|
| [3851] | 33 | #include "animation3d.h" | 
|---|
| [3618] | 34 |  | 
|---|
| [4979] | 35 | #include "null_parent.h" | 
|---|
 | 36 |  | 
|---|
| [4940] | 37 | #include "fast_factory.h" | 
|---|
| [4287] | 38 |  | 
|---|
| [4931] | 39 |  | 
|---|
| [3618] | 40 | using namespace std; | 
|---|
 | 41 |  | 
|---|
| [5622] | 42 | CREATE_FACTORY(Cannon, CL_CANNON); | 
|---|
| [3618] | 43 |  | 
|---|
 | 44 | /** | 
|---|
| [4836] | 45 |  *  standard constructor | 
|---|
| [3618] | 46 |  | 
|---|
 | 47 |    creates a new weapon | 
|---|
 | 48 | */ | 
|---|
| [5745] | 49 | Cannon::Cannon () | 
|---|
 | 50 |   : Weapon() | 
|---|
| [3683] | 51 | { | 
|---|
| [4974] | 52 |   this->init(); | 
|---|
| [4972] | 53 | } | 
|---|
| [4885] | 54 |  | 
|---|
 | 55 |  | 
|---|
| [5621] | 56 | Cannon::Cannon(const TiXmlElement* root) | 
|---|
| [4972] | 57 | { | 
|---|
 | 58 |   this->init(); | 
|---|
 | 59 |   this->loadParams(root); | 
|---|
 | 60 | } | 
|---|
 | 61 |  | 
|---|
 | 62 | /** | 
|---|
 | 63 |  *  standard deconstructor | 
|---|
 | 64 | */ | 
|---|
| [5621] | 65 | Cannon::~Cannon () | 
|---|
| [4972] | 66 | { | 
|---|
 | 67 |   // model will be deleted from WorldEntity-destructor | 
|---|
 | 68 | } | 
|---|
 | 69 |  | 
|---|
 | 70 |  | 
|---|
| [5621] | 71 | void Cannon::init() | 
|---|
| [4972] | 72 | { | 
|---|
| [5621] | 73 |   this->setClassID(CL_CANNON, "Cannon"); | 
|---|
| [4972] | 74 |  | 
|---|
| [5053] | 75 | //  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); | 
|---|
| [4972] | 76 |  | 
|---|
| [5621] | 77 |   this->loadModel("models/guns/cannon.obj"); | 
|---|
| [5053] | 78 |  | 
|---|
| [5744] | 79 |   this->setStateDuration(WS_SHOOTING, 2.0); | 
|---|
| [5457] | 80 |   this->setStateDuration(WS_RELOADING, .1); | 
|---|
| [5744] | 81 |   this->setStateDuration(WS_ACTIVATING, .1); | 
|---|
| [4910] | 82 |   this->setStateDuration(WS_DEACTIVATING, .4); | 
|---|
| [4885] | 83 |  | 
|---|
| [5828] | 84 |   this->setMaximumEnergy(100, 20); | 
|---|
 | 85 |   this->increaseEnergy(100); | 
|---|
| [4927] | 86 |   //this->minCharge = 2; | 
|---|
| [4885] | 87 |  | 
|---|
| [5819] | 88 |   this->setActionSound(WA_SHOOT, "sound/explo.wav"); | 
|---|
 | 89 |   this->setActionSound(WA_ACTIVATE, "sound/voices/cannon.wav"); | 
|---|
| [4934] | 90 |  | 
|---|
| [5441] | 91 |   this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); | 
|---|
| [5744] | 92 |   this->setProjectileType(CL_BOMB); | 
|---|
 | 93 |   this->prepareProjectiles(5); | 
|---|
| [5457] | 94 |  | 
|---|
| [5623] | 95 | //  this->objectComponent1 = new PNode(); | 
|---|
 | 96 | //  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); | 
|---|
 | 97 |   Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); | 
|---|
 | 98 |   Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); | 
|---|
 | 99 |   //parent->addChild(this->objectComponent1, PNODE_ALL); | 
|---|
 | 100 | //  this->addChild(this->objectComponent1); | 
|---|
 | 101 |  | 
|---|
 | 102 | //  animation1->setInfinity(ANIM_INF_CONSTANT); | 
|---|
 | 103 |   animation2->setInfinity(ANIM_INF_CONSTANT); | 
|---|
 | 104 |   animation3->setInfinity(ANIM_INF_CONSTANT); | 
|---|
 | 105 |  | 
|---|
 | 106 |   this->setEmissionPoint(3.8, 1.2, 0); | 
|---|
 | 107 |  | 
|---|
 | 108 | //     animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 109 | //     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 110 | //     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 111 |  | 
|---|
 | 112 |   animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 113 |   animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 114 |  | 
|---|
 | 115 |   animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
 | 116 |   animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
| [3683] | 117 | } | 
|---|
| [3618] | 118 |  | 
|---|
 | 119 |  | 
|---|
| [5621] | 120 | void Cannon::loadParams(const TiXmlElement* root) | 
|---|
| [3618] | 121 | { | 
|---|
| [4972] | 122 |  | 
|---|
 | 123 |  | 
|---|
| [3618] | 124 | } | 
|---|
 | 125 |  | 
|---|
 | 126 |  | 
|---|
 | 127 | /** | 
|---|
| [4836] | 128 |  *  this activates the weapon | 
|---|
| [3618] | 129 |  | 
|---|
| [4592] | 130 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
 | 131 |    activation can be connected with an animation. for example the weapon is | 
|---|
 | 132 |    been armed out. | 
|---|
| [3618] | 133 | */ | 
|---|
| [5621] | 134 | void Cannon::activate() | 
|---|
| [3980] | 135 | { | 
|---|
 | 136 | } | 
|---|
| [3618] | 137 |  | 
|---|
 | 138 |  | 
|---|
 | 139 | /** | 
|---|
| [4836] | 140 |  *  this deactivates the weapon | 
|---|
| [3618] | 141 |  | 
|---|
| [4592] | 142 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
 | 143 |    activation can be connected with an animation. for example the weapon is | 
|---|
| [3618] | 144 |    been armed out. | 
|---|
 | 145 | */ | 
|---|
| [5621] | 146 | void Cannon::deactivate() | 
|---|
| [3980] | 147 | { | 
|---|
 | 148 | } | 
|---|
| [3618] | 149 |  | 
|---|
 | 150 |  | 
|---|
 | 151 | /** | 
|---|
| [4836] | 152 |  *  fires the weapon | 
|---|
| [4592] | 153 |  | 
|---|
| [3618] | 154 |    this is called from the player.cc, when fire-button is been pushed | 
|---|
| [4836] | 155 |    @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent | 
|---|
| [3618] | 156 | */ | 
|---|
| [5621] | 157 | void Cannon::fire() | 
|---|
| [3620] | 158 | { | 
|---|
| [5356] | 159 |   Projectile* pj =  this->getProjectile(); | 
|---|
 | 160 |   if (pj == NULL) | 
|---|
 | 161 |     return; | 
|---|
| [3888] | 162 |  | 
|---|
| [4979] | 163 |   pj->setParent(NullParent::getInstance()); | 
|---|
| [5000] | 164 |  | 
|---|
| [5744] | 165 |   pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5)); | 
|---|
| [4955] | 166 |  | 
|---|
| [4927] | 167 |   pj->setAbsCoor(this->getEmissionPoint()); | 
|---|
| [3708] | 168 |   pj->setAbsDir(this->getAbsDir()); | 
|---|
| [5443] | 169 |   pj->activate(); | 
|---|
| [3620] | 170 | } | 
|---|
| [3618] | 171 |  | 
|---|
 | 172 | /** | 
|---|
| [4836] | 173 |  *  is called, when the weapon is destroyed | 
|---|
| [5498] | 174 |  * | 
|---|
 | 175 |  * this is in conjunction with the hit function, so when a weapon is able to get | 
|---|
 | 176 |  * hit, it can also be destoryed. | 
|---|
| [3618] | 177 | */ | 
|---|
| [5621] | 178 | void Cannon::destroy () | 
|---|
| [3618] | 179 | {} | 
|---|
 | 180 |  | 
|---|
 | 181 | /** | 
|---|
| [4836] | 182 |  *  this will draw the weapon | 
|---|
| [3618] | 183 | */ | 
|---|
| [5621] | 184 | void Cannon::draw () const | 
|---|
| [3750] | 185 | { | 
|---|
| [3886] | 186 |   /* draw gun body */ | 
|---|
| [3750] | 187 |   glMatrixMode(GL_MODELVIEW); | 
|---|
 | 188 |   glPushMatrix(); | 
|---|
| [4592] | 189 |   glTranslatef (this->getAbsCoor ().x, | 
|---|
 | 190 |                 this->getAbsCoor ().y, | 
|---|
 | 191 |                 this->getAbsCoor ().z); | 
|---|
| [5000] | 192 |  | 
|---|
 | 193 |   Vector tmpRot = this->getAbsDir().getSpacialAxis(); | 
|---|
 | 194 |   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
 | 195 |  | 
|---|
| [5994] | 196 |   this->getModel()->draw(); | 
|---|
| [3752] | 197 |   glPopMatrix(); | 
|---|
 | 198 |  | 
|---|
| [3886] | 199 |   /* draw objectComponent1: gun coil - animated stuff */ | 
|---|
| [5621] | 200 | /*  glMatrixMode(GL_MODELVIEW); | 
|---|
| [3752] | 201 |   glPushMatrix(); | 
|---|
| [4592] | 202 |   glTranslatef (this->objectComponent1->getAbsCoor ().x, | 
|---|
 | 203 |                 this->objectComponent1->getAbsCoor ().y, | 
|---|
 | 204 |                 this->objectComponent1->getAbsCoor ().z); | 
|---|
| [5000] | 205 |   tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis(); | 
|---|
 | 206 |   glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| [3752] | 207 |   this->model->draw(0); | 
|---|
| [5621] | 208 |  | 
|---|
 | 209 |   glPopMatrix();*/ | 
|---|
| [3750] | 210 | } | 
|---|
| [3618] | 211 |  | 
|---|