[10579] | 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 | |
---|
[9972] | 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 | |
---|
[10516] | 29 | #include "elements/glgui_energywidgetvertical.h" |
---|
| 30 | |
---|
[9972] | 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 | { |
---|
[10261] | 54 | |
---|
[10170] | 55 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 56 | { |
---|
[10261] | 57 | delete [] this->shootAnim[i]; |
---|
| 58 | delete [] this->objComp[i]; |
---|
| 59 | } |
---|
| 60 | delete [] this->emissionPoint; |
---|
| 61 | delete [] this->shootAnim; |
---|
| 62 | delete [] this->objComp; |
---|
[10170] | 63 | |
---|
[9972] | 64 | } |
---|
| 65 | |
---|
| 66 | void LightBlaster::loadParams(const TiXmlElement* root) |
---|
| 67 | { |
---|
| 68 | Weapon::loadParams(root); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void LightBlaster::init() |
---|
| 72 | { |
---|
| 73 | |
---|
[10471] | 74 | this->loadModel("models/guns/gatling.obj", 0.333); |
---|
[9972] | 75 | |
---|
[10415] | 76 | |
---|
[9998] | 77 | this->setStateDuration(WS_SHOOTING, 0.05); // 20 Schuss pro Sekunde |
---|
[9972] | 78 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 79 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 80 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 81 | |
---|
[9998] | 82 | this->setEnergyMax(500); |
---|
| 83 | this->increaseEnergy(500); |
---|
[9972] | 84 | //this->minCharge = 2; |
---|
| 85 | |
---|
[10415] | 86 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
[10516] | 87 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[10415] | 88 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
[9972] | 89 | |
---|
| 90 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10516] | 91 | this->setProjectileTypeC("LBolt"); |
---|
[9972] | 92 | this->prepareProjectiles(100); |
---|
| 93 | |
---|
[10152] | 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); //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles |
---|
| 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 | for (int i = 0; i < this->getBarrels(); i++ ) |
---|
| 118 | this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1)); |
---|
| 119 | |
---|
| 120 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this); |
---|
[9972] | 121 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 122 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 123 | |
---|
[10152] | 124 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[9972] | 125 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 126 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 127 | |
---|
[10152] | 128 | // this->setEmissionPoint(3.8, 1.2, 0); |
---|
[9972] | 129 | |
---|
[10152] | 130 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
[10170] | 131 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR); |
---|
| 132 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR); |
---|
[10152] | 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
[9972] | 136 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 137 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 138 | |
---|
| 139 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 140 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | void LightBlaster::fire() |
---|
| 144 | { |
---|
| 145 | Projectile* pj = this->getProjectile(); |
---|
| 146 | if (pj == NULL) |
---|
| 147 | return; |
---|
| 148 | |
---|
[9975] | 149 | // set the owner |
---|
| 150 | pj->setOwner(this->getOwner()); |
---|
| 151 | |
---|
[9972] | 152 | pj->setParent(PNode::getNullParent()); |
---|
| 153 | |
---|
[10044] | 154 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
[10046] | 155 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180); |
---|
[9972] | 156 | |
---|
[10152] | 157 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
[9972] | 158 | pj->setAbsDir(this->getAbsDir()); |
---|
[10152] | 159 | // pj->toList(OM_GROUP_01_PROJ); |
---|
[9972] | 160 | pj->activate(); |
---|
[10152] | 161 | |
---|
| 162 | for (int i = 0; i < this->getSegs(); i++) |
---|
| 163 | this->shootAnim[this->activeBarrel][i]->replay(); |
---|
| 164 | |
---|
| 165 | // switch barrel |
---|
| 166 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
---|
[9972] | 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | * this activates the weapon |
---|
| 171 | */ |
---|
| 172 | void LightBlaster::activate() |
---|
| 173 | { |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * this deactivates the weapon |
---|
| 178 | */ |
---|
| 179 | void LightBlaster::deactivate() |
---|
| 180 | { |
---|
[9975] | 181 | } |
---|
| 182 | |
---|
| 183 | void LightBlaster::draw() const |
---|
| 184 | { |
---|
[10152] | 185 | glMatrixMode(GL_MODELVIEW); |
---|
| 186 | glPushMatrix(); |
---|
| 187 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 188 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 189 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 190 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 191 | glPopMatrix(); |
---|
[10516] | 192 | |
---|
[9975] | 193 | } |
---|
[10516] | 194 | |
---|
| 195 | void LightBlaster::tick(float dt) |
---|
| 196 | { |
---|
[10539] | 197 | if (!Weapon::tickW(dt)) |
---|
| 198 | return; |
---|
[10516] | 199 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 200 | { |
---|
| 201 | this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png"); |
---|
| 202 | this->setEnergyWidgetInitialized(true); |
---|
| 203 | } |
---|
| 204 | } |
---|