[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 | |
---|
| 23 | #include "test_gun.h" |
---|
[6434] | 24 | #include "world_entities/projectiles/projectile.h" |
---|
[3618] | 25 | |
---|
| 26 | #include "world_entity.h" |
---|
[6022] | 27 | #include "static_model.h" |
---|
[4955] | 28 | #include "weapon_manager.h" |
---|
[7193] | 29 | #include "util/loading/factory.h" |
---|
[3618] | 30 | |
---|
[3851] | 31 | #include "animation3d.h" |
---|
[3618] | 32 | |
---|
[9869] | 33 | #include "loading/fast_factory.h" |
---|
[4287] | 34 | |
---|
[10114] | 35 | |
---|
| 36 | ObjectListDefinition(TestGun); |
---|
[9869] | 37 | CREATE_FACTORY(TestGun); |
---|
[3618] | 38 | /** |
---|
[4836] | 39 | * standard constructor |
---|
[3618] | 40 | |
---|
| 41 | creates a new weapon |
---|
| 42 | */ |
---|
[5750] | 43 | TestGun::TestGun ( int leftRight) |
---|
| 44 | : Weapon() |
---|
[3683] | 45 | { |
---|
[4974] | 46 | this->init(); |
---|
| 47 | |
---|
| 48 | |
---|
[3755] | 49 | this->leftRight = leftRight; |
---|
[3752] | 50 | |
---|
[3886] | 51 | this->objectComponent1 = new PNode(); |
---|
[4895] | 52 | Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
| 53 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 54 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3986] | 55 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
[5382] | 56 | this->addChild(this->objectComponent1); |
---|
[3755] | 57 | |
---|
[4893] | 58 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 59 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 60 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
[4972] | 61 | |
---|
[3886] | 62 | if( this->leftRight == W_LEFT) |
---|
[4972] | 63 | { |
---|
[5459] | 64 | this->setEmissionPoint(1.0, -0.6, -0.2); |
---|
[3888] | 65 | |
---|
[5062] | 66 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 67 | animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 68 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 69 | |
---|
[5062] | 70 | animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 71 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 72 | |
---|
[5062] | 73 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 74 | animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 75 | } |
---|
[3886] | 76 | else if( this->leftRight == W_RIGHT) |
---|
[4972] | 77 | { |
---|
[5459] | 78 | this->setEmissionPoint(1.0, -0.6, 0.3); |
---|
[3888] | 79 | |
---|
[4972] | 80 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
[5062] | 81 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 82 | animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 83 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 84 | |
---|
[5062] | 85 | animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 86 | animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3993] | 87 | |
---|
[5062] | 88 | animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 89 | animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 90 | } |
---|
| 91 | } |
---|
[4885] | 92 | |
---|
| 93 | |
---|
[4972] | 94 | TestGun::TestGun(const TiXmlElement* root) |
---|
| 95 | { |
---|
| 96 | this->init(); |
---|
[7084] | 97 | if (root != NULL) |
---|
| 98 | this->loadParams(root); |
---|
[4972] | 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * standard deconstructor |
---|
| 103 | */ |
---|
| 104 | TestGun::~TestGun () |
---|
| 105 | { |
---|
| 106 | // model will be deleted from WorldEntity-destructor |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | void TestGun::init() |
---|
| 111 | { |
---|
[9869] | 112 | this->registerObject(this, TestGun::_objectList); |
---|
[5053] | 113 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
[4972] | 114 | |
---|
[5053] | 115 | this->loadModel("models/guns/test_gun.obj"); |
---|
| 116 | |
---|
[5457] | 117 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 118 | this->setStateDuration(WS_RELOADING, .1); |
---|
[4910] | 119 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 120 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 121 | |
---|
[9002] | 122 | this->setEnergyMax(10000); |
---|
| 123 | this->increaseEnergy(10000); |
---|
[4927] | 124 | //this->minCharge = 2; |
---|
[4885] | 125 | |
---|
[10415] | 126 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
| 127 | this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[4934] | 128 | |
---|
[5819] | 129 | |
---|
[5441] | 130 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[9869] | 131 | this->setProjectileTypeC("Laser"); |
---|
[8983] | 132 | this->prepareProjectiles(100); |
---|
[5457] | 133 | |
---|
[3683] | 134 | } |
---|
[3618] | 135 | |
---|
| 136 | |
---|
[4972] | 137 | void TestGun::loadParams(const TiXmlElement* root) |
---|
[3618] | 138 | { |
---|
[6512] | 139 | Weapon::loadParams(root); |
---|
[4972] | 140 | |
---|
[3618] | 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | /** |
---|
[4836] | 145 | * this activates the weapon |
---|
[3618] | 146 | |
---|
[4592] | 147 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 148 | activation can be connected with an animation. for example the weapon is |
---|
| 149 | been armed out. |
---|
[3618] | 150 | */ |
---|
| 151 | void TestGun::activate() |
---|
[3980] | 152 | { |
---|
| 153 | } |
---|
[3618] | 154 | |
---|
| 155 | |
---|
| 156 | /** |
---|
[4836] | 157 | * this deactivates the weapon |
---|
[3618] | 158 | |
---|
[4592] | 159 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 160 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 161 | been armed out. |
---|
| 162 | */ |
---|
| 163 | void TestGun::deactivate() |
---|
[3980] | 164 | { |
---|
| 165 | } |
---|
[3618] | 166 | |
---|
| 167 | |
---|
| 168 | /** |
---|
[4836] | 169 | * fires the weapon |
---|
[4592] | 170 | |
---|
[3618] | 171 | this is called from the player.cc, when fire-button is been pushed |
---|
[4836] | 172 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 173 | */ |
---|
| 174 | void TestGun::fire() |
---|
[3620] | 175 | { |
---|
[5356] | 176 | Projectile* pj = this->getProjectile(); |
---|
| 177 | if (pj == NULL) |
---|
| 178 | return; |
---|
[3888] | 179 | |
---|
[9656] | 180 | // set the owner |
---|
| 181 | pj->setOwner(this->getOwner()); |
---|
| 182 | |
---|
[6074] | 183 | pj->setParent(PNode::getNullParent()); |
---|
[5000] | 184 | |
---|
[6162] | 185 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
[4955] | 186 | |
---|
[4927] | 187 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 188 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 189 | pj->activate(); |
---|
[3620] | 190 | } |
---|
[3618] | 191 | |
---|
| 192 | |
---|
[8777] | 193 | |
---|
[3618] | 194 | /** |
---|
[4836] | 195 | * this will draw the weapon |
---|
[3618] | 196 | */ |
---|
[5500] | 197 | void TestGun::draw () const |
---|
[3750] | 198 | { |
---|
[3886] | 199 | /* draw gun body */ |
---|
[3750] | 200 | glMatrixMode(GL_MODELVIEW); |
---|
| 201 | glPushMatrix(); |
---|
[4592] | 202 | glTranslatef (this->getAbsCoor ().x, |
---|
| 203 | this->getAbsCoor ().y, |
---|
| 204 | this->getAbsCoor ().z); |
---|
[5000] | 205 | |
---|
| 206 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 207 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 208 | |
---|
[3886] | 209 | if( this->leftRight == W_RIGHT) |
---|
| 210 | glScalef(1.0, 1.0, -1.0); |
---|
[6022] | 211 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
[3752] | 212 | glPopMatrix(); |
---|
| 213 | |
---|
[3886] | 214 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
[3752] | 215 | glPushMatrix(); |
---|
[4592] | 216 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
| 217 | this->objectComponent1->getAbsCoor ().y, |
---|
| 218 | this->objectComponent1->getAbsCoor ().z); |
---|
[5000] | 219 | tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis(); |
---|
| 220 | glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[6022] | 221 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
[3750] | 222 | glPopMatrix(); |
---|
| 223 | } |
---|
[3618] | 224 | |
---|