| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004-2006 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific |
|---|
| 12 | main-programmer: Marc Schaerrer, Nicolas Schlumberger |
|---|
| 13 | co-programmer: |
|---|
| 14 | |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | #include "light_blaster.h" |
|---|
| 18 | #include "world_entities/projectiles/projectile.h" |
|---|
| 19 | |
|---|
| 20 | #include "world_entity.h" |
|---|
| 21 | #include "static_model.h" |
|---|
| 22 | #include "weapon_manager.h" |
|---|
| 23 | #include "util/loading/factory.h" |
|---|
| 24 | |
|---|
| 25 | #include "animation3d.h" |
|---|
| 26 | |
|---|
| 27 | #include "loading/fast_factory.h" |
|---|
| 28 | |
|---|
| 29 | #include "elements/glgui_energywidgetvertical.h" |
|---|
| 30 | |
|---|
| 31 | CREATE_FACTORY(LightBlaster); |
|---|
| 32 | /** |
|---|
| 33 | * Standard constructor |
|---|
| 34 | */ |
|---|
| 35 | LightBlaster::LightBlaster () |
|---|
| 36 | : Weapon() |
|---|
| 37 | { |
|---|
| 38 | this->init(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | LightBlaster::LightBlaster (const TiXmlElement* root = NULL) |
|---|
| 42 | : Weapon() |
|---|
| 43 | { |
|---|
| 44 | this->init(); |
|---|
| 45 | if (root != NULL) |
|---|
| 46 | this->loadParams(root); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * Default destructor |
|---|
| 51 | */ |
|---|
| 52 | LightBlaster::~LightBlaster() |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | // for (int i = 0; i < this->getBarrels(); i++) |
|---|
| 56 | // { |
|---|
| 57 | // //delete [] this->shootAnim[i]; |
|---|
| 58 | // delete [] this->objComp[i]; |
|---|
| 59 | // } |
|---|
| 60 | // delete [] this->emissionPoint; |
|---|
| 61 | // //delete [] this->shootAnim; |
|---|
| 62 | // delete [] this->objComp; |
|---|
| 63 | |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void LightBlaster::loadParams(const TiXmlElement* root) |
|---|
| 67 | { |
|---|
| 68 | Weapon::loadParams(root); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void LightBlaster::init() |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | this->loadModel("models/guns/gatling.obj", 0.333); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | this->setStateDuration(WS_SHOOTING, 0.05); // 20 Schuss pro Sekunde |
|---|
| 78 | this->setStateDuration(WS_RELOADING, 0); |
|---|
| 79 | this->setStateDuration(WS_ACTIVATING, .5); |
|---|
| 80 | this->setStateDuration(WS_DEACTIVATING, 1); |
|---|
| 81 | |
|---|
| 82 | this->setEnergyMax(500); |
|---|
| 83 | this->increaseEnergy(500); |
|---|
| 84 | //this->minCharge = 2; |
|---|
| 85 | |
|---|
| 86 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
|---|
| 87 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
|---|
| 88 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
|---|
| 89 | |
|---|
| 90 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
|---|
| 91 | this->setProjectileTypeC("LBolt"); |
|---|
| 92 | this->prepareProjectiles(100); |
|---|
| 93 | |
|---|
| 94 | this->setBarrels(3); |
|---|
| 95 | this->setSegs(1); |
|---|
| 96 | this->activeBarrel = 0; |
|---|
| 97 | |
|---|
| 98 | this->objComp = new PNode**[this->getBarrels()]; |
|---|
| 99 | this->emissionPoint = new PNode*[this->getBarrels()]; |
|---|
| 100 | // this->shootAnim = new Animation3D**[this->getBarrels()]; |
|---|
| 101 | for (int i = 0; i < this->getBarrels(); i++) |
|---|
| 102 | { |
|---|
| 103 | this->objComp[i] = new PNode* [this->getSegs()]; |
|---|
| 104 | this->emissionPoint[i] = new PNode; |
|---|
| 105 | this->emissionPoint[i]->setParent(this); |
|---|
| 106 | this->emissionPoint[i]->setName("EmissionPoint"); |
|---|
| 107 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
|---|
| 108 | // this->shootAnim[i] = new Animation3D* [this->getSegs()]; |
|---|
| 109 | for(int j = 0; j < this->getSegs(); j++) |
|---|
| 110 | { |
|---|
| 111 | this->objComp[i][j] = new PNode; |
|---|
| 112 | // this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]); |
|---|
| 113 | // this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | /* |
|---|
| 117 | this->emissionPoint[0]->setRelCoor(Vector(1.19, 0.0, 0.1)); |
|---|
| 118 | this->emissionPoint[1]->setRelCoor(Vector(1.19, -0.07, -0.05)); |
|---|
| 119 | this->emissionPoint[2]->setRelCoor(Vector(1.19, 0.07, -0.05));*/ |
|---|
| 120 | |
|---|
| 121 | this->emissionPoint[0]->setRelCoor(Vector(2.2, 0.0, 0.1)); |
|---|
| 122 | this->emissionPoint[1]->setRelCoor(Vector(2.2, -0.07, -0.05)); |
|---|
| 123 | this->emissionPoint[2]->setRelCoor(Vector(2.2, 0.07, -0.05)); |
|---|
| 124 | |
|---|
| 125 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this); |
|---|
| 126 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
|---|
| 127 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
|---|
| 128 | |
|---|
| 129 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 130 | animation2->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 131 | animation3->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 132 | |
|---|
| 133 | // this->setEmissionPoint(3.8, 1.2, 0); |
|---|
| 134 | |
|---|
| 135 | // for (int i = 0; i < this->getBarrels(); i++){ |
|---|
| 136 | // this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR); |
|---|
| 137 | // this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR); |
|---|
| 138 | // } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
|---|
| 142 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
|---|
| 143 | |
|---|
| 144 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
|---|
| 145 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void LightBlaster::fire() |
|---|
| 149 | { |
|---|
| 150 | Projectile* pj = this->getProjectile(); |
|---|
| 151 | if (pj == NULL) |
|---|
| 152 | return; |
|---|
| 153 | |
|---|
| 154 | // set the owner |
|---|
| 155 | pj->setOwner(this->getOwner()); |
|---|
| 156 | |
|---|
| 157 | pj->setParent(PNode::getNullParent()); |
|---|
| 158 | |
|---|
| 159 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
|---|
| 160 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180); |
|---|
| 161 | |
|---|
| 162 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
|---|
| 163 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 164 | // pj->toList(OM_GROUP_01_PROJ); |
|---|
| 165 | pj->activate(); |
|---|
| 166 | |
|---|
| 167 | // for (int i = 0; i < this->getSegs(); i++) |
|---|
| 168 | // this->shootAnim[this->activeBarrel][i]->replay(); |
|---|
| 169 | |
|---|
| 170 | // switch barrel |
|---|
| 171 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * this activates the weapon |
|---|
| 176 | */ |
|---|
| 177 | void LightBlaster::activate() |
|---|
| 178 | { |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | /** |
|---|
| 182 | * this deactivates the weapon |
|---|
| 183 | */ |
|---|
| 184 | void LightBlaster::deactivate() |
|---|
| 185 | { |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | void LightBlaster::draw() const |
|---|
| 189 | { |
|---|
| 190 | glMatrixMode(GL_MODELVIEW); |
|---|
| 191 | glPushMatrix(); |
|---|
| 192 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
|---|
| 193 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
|---|
| 194 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 195 | static_cast<StaticModel*>(this->getModel())->draw(); |
|---|
| 196 | glPopMatrix(); |
|---|
| 197 | |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | void LightBlaster::tick(float dt) |
|---|
| 201 | { |
|---|
| 202 | if (!Weapon::tickW(dt)) |
|---|
| 203 | return; |
|---|
| 204 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
|---|
| 205 | { |
|---|
| 206 | this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png"); |
|---|
| 207 | this->setEnergyWidgetInitialized(true); |
|---|
| 208 | } |
|---|
| 209 | } |
|---|