[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 | |
---|
[4940] | 33 | #include "fast_factory.h" |
---|
[4287] | 34 | |
---|
[4931] | 35 | |
---|
[3618] | 36 | using namespace std; |
---|
| 37 | |
---|
[5750] | 38 | CREATE_FACTORY(TestGun, CL_TEST_GUN); |
---|
[3618] | 39 | |
---|
| 40 | /** |
---|
[4836] | 41 | * standard constructor |
---|
[3618] | 42 | |
---|
| 43 | creates a new weapon |
---|
| 44 | */ |
---|
[5750] | 45 | TestGun::TestGun ( int leftRight) |
---|
| 46 | : Weapon() |
---|
[3683] | 47 | { |
---|
[4974] | 48 | this->init(); |
---|
| 49 | |
---|
| 50 | |
---|
[3755] | 51 | this->leftRight = leftRight; |
---|
[3752] | 52 | |
---|
[3886] | 53 | this->objectComponent1 = new PNode(); |
---|
[4895] | 54 | Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
| 55 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 56 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3986] | 57 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
[5382] | 58 | this->addChild(this->objectComponent1); |
---|
[3755] | 59 | |
---|
[4893] | 60 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 61 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 62 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
[4972] | 63 | |
---|
[3886] | 64 | if( this->leftRight == W_LEFT) |
---|
[4972] | 65 | { |
---|
[5459] | 66 | this->setEmissionPoint(1.0, -0.6, -0.2); |
---|
[3888] | 67 | |
---|
[5062] | 68 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 69 | animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 70 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 71 | |
---|
[5062] | 72 | animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 73 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 74 | |
---|
[5062] | 75 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 76 | animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 77 | } |
---|
[3886] | 78 | else if( this->leftRight == W_RIGHT) |
---|
[4972] | 79 | { |
---|
[5459] | 80 | this->setEmissionPoint(1.0, -0.6, 0.3); |
---|
[3888] | 81 | |
---|
[4972] | 82 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
[5062] | 83 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 84 | animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 85 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 86 | |
---|
[5062] | 87 | animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 88 | animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3993] | 89 | |
---|
[5062] | 90 | animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 91 | animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 92 | } |
---|
| 93 | } |
---|
[4885] | 94 | |
---|
| 95 | |
---|
[4972] | 96 | TestGun::TestGun(const TiXmlElement* root) |
---|
| 97 | { |
---|
| 98 | this->init(); |
---|
[7084] | 99 | if (root != NULL) |
---|
| 100 | this->loadParams(root); |
---|
[4972] | 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * standard deconstructor |
---|
| 105 | */ |
---|
| 106 | TestGun::~TestGun () |
---|
| 107 | { |
---|
| 108 | // model will be deleted from WorldEntity-destructor |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | void TestGun::init() |
---|
| 113 | { |
---|
| 114 | this->setClassID(CL_TEST_GUN, "TestGun"); |
---|
| 115 | |
---|
[5053] | 116 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
[4972] | 117 | |
---|
[5053] | 118 | this->loadModel("models/guns/test_gun.obj"); |
---|
| 119 | |
---|
[5457] | 120 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 121 | this->setStateDuration(WS_RELOADING, .1); |
---|
[4910] | 122 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 123 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 124 | |
---|
[7095] | 125 | this->setEnergyMax(100000); |
---|
| 126 | this->increaseEnergy(100000); |
---|
[4927] | 127 | //this->minCharge = 2; |
---|
[4885] | 128 | |
---|
[5819] | 129 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
| 130 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
[4934] | 131 | |
---|
[5819] | 132 | |
---|
[5441] | 133 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[5456] | 134 | this->setProjectileType(CL_LASER); |
---|
[5356] | 135 | this->prepareProjectiles(20); |
---|
[5457] | 136 | |
---|
[3683] | 137 | } |
---|
[3618] | 138 | |
---|
| 139 | |
---|
[4972] | 140 | void TestGun::loadParams(const TiXmlElement* root) |
---|
[3618] | 141 | { |
---|
[6512] | 142 | Weapon::loadParams(root); |
---|
[4972] | 143 | |
---|
[3618] | 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
[4836] | 148 | * this activates the weapon |
---|
[3618] | 149 | |
---|
[4592] | 150 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 151 | activation can be connected with an animation. for example the weapon is |
---|
| 152 | been armed out. |
---|
[3618] | 153 | */ |
---|
| 154 | void TestGun::activate() |
---|
[3980] | 155 | { |
---|
| 156 | } |
---|
[3618] | 157 | |
---|
| 158 | |
---|
| 159 | /** |
---|
[4836] | 160 | * this deactivates the weapon |
---|
[3618] | 161 | |
---|
[4592] | 162 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 163 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 164 | been armed out. |
---|
| 165 | */ |
---|
| 166 | void TestGun::deactivate() |
---|
[3980] | 167 | { |
---|
| 168 | } |
---|
[3618] | 169 | |
---|
| 170 | |
---|
| 171 | /** |
---|
[4836] | 172 | * fires the weapon |
---|
[4592] | 173 | |
---|
[3618] | 174 | this is called from the player.cc, when fire-button is been pushed |
---|
[4836] | 175 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 176 | */ |
---|
| 177 | void TestGun::fire() |
---|
[3620] | 178 | { |
---|
[5356] | 179 | Projectile* pj = this->getProjectile(); |
---|
| 180 | if (pj == NULL) |
---|
| 181 | return; |
---|
[3888] | 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 | |
---|