[10618] | 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 "heavy_blaster.h" |
---|
[9975] | 18 | #include "world_entities/projectiles/projectile.h" |
---|
[9972] | 19 | |
---|
[9975] | 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 | |
---|
[9975] | 31 | CREATE_FACTORY(HeavyBlaster); |
---|
[10499] | 32 | |
---|
| 33 | |
---|
[9975] | 34 | /** |
---|
| 35 | * Standard constructor |
---|
| 36 | */ |
---|
[10771] | 37 | HeavyBlaster::HeavyBlaster (int leftRight = W_RIGHT) |
---|
[9975] | 38 | : Weapon() |
---|
| 39 | { |
---|
[10499] | 40 | |
---|
[10152] | 41 | this->init(leftRight); |
---|
[9975] | 42 | } |
---|
| 43 | |
---|
[9972] | 44 | HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL) |
---|
| 45 | : Weapon() |
---|
[9975] | 46 | { |
---|
[10499] | 47 | // this->registerObject(this, HeavyBlaster::_objectList); |
---|
| 48 | |
---|
[10152] | 49 | // TODO add leftRight to params |
---|
| 50 | this->init(0); |
---|
[9972] | 51 | if (root != NULL) |
---|
| 52 | this->loadParams(root); |
---|
[9975] | 53 | } |
---|
[9972] | 54 | |
---|
| 55 | /** |
---|
| 56 | * Default destructor |
---|
| 57 | */ |
---|
| 58 | HeavyBlaster::~HeavyBlaster() |
---|
[9975] | 59 | { |
---|
| 60 | } |
---|
[9972] | 61 | |
---|
[9975] | 62 | void HeavyBlaster::loadParams(const TiXmlElement* root) |
---|
| 63 | { |
---|
| 64 | Weapon::loadParams(root); |
---|
| 65 | } |
---|
[9972] | 66 | |
---|
[10152] | 67 | void HeavyBlaster::init(int leftRight) |
---|
[9975] | 68 | { |
---|
[10152] | 69 | |
---|
| 70 | this->leftRight = leftRight; |
---|
[9975] | 71 | |
---|
[10698] | 72 | this->loadModel("models/guns/frag_cannon2.obj", .4); |
---|
[9975] | 73 | |
---|
[10415] | 74 | |
---|
[9998] | 75 | this->setStateDuration(WS_SHOOTING, 0.5); // 2 Schuss pro Sekunde |
---|
[9975] | 76 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 77 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 78 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 79 | |
---|
[9998] | 80 | this->setEnergyMax(500); |
---|
| 81 | this->increaseEnergy(500); |
---|
[9975] | 82 | |
---|
[10415] | 83 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
[10516] | 84 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[10415] | 85 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
[9975] | 86 | |
---|
| 87 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10516] | 88 | this->setProjectileTypeC("HBolt"); |
---|
[9998] | 89 | this->prepareProjectiles(5); |
---|
[9975] | 90 | |
---|
[10136] | 91 | this->setBarrels(3); |
---|
| 92 | this->setSegs(2); |
---|
| 93 | |
---|
[10133] | 94 | |
---|
[10771] | 95 | if (this->leftRight == W_LEFT) |
---|
[10152] | 96 | { |
---|
[10771] | 97 | this->setEmissionPoint(Vector(1.1, 0.14, -.06), 0); |
---|
| 98 | this->setEmissionPoint(Vector(1.1, -.06, -.14), 1); |
---|
| 99 | this->setEmissionPoint(Vector(1.1, 0.06, 0.14), 2); |
---|
[10152] | 100 | } |
---|
[10159] | 101 | else { |
---|
[10771] | 102 | this->setEmissionPoint(Vector(1.1, 0.14, 0.06), 0); |
---|
| 103 | this->setEmissionPoint(Vector(1.1, -.06, 0.14), 1); |
---|
| 104 | this->setEmissionPoint(Vector(1.1, 0.06, -.14), 2); |
---|
[10159] | 105 | } |
---|
[10152] | 106 | |
---|
| 107 | |
---|
| 108 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
[10771] | 109 | this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL); |
---|
| 110 | this->getShootAnim(i, 0)->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL); |
---|
| 111 | this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
[10133] | 112 | |
---|
[10771] | 113 | this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 114 | this->getShootAnim(i, 1)->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL); |
---|
| 115 | this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
[10152] | 116 | } |
---|
[10133] | 117 | |
---|
[9975] | 118 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 119 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 120 | |
---|
| 121 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 122 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 123 | |
---|
| 124 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 125 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 126 | |
---|
| 127 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 128 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | void HeavyBlaster::fire() |
---|
| 133 | { |
---|
| 134 | Projectile* pj = this->getProjectile(); |
---|
| 135 | if (pj == NULL) |
---|
| 136 | return; |
---|
| 137 | |
---|
| 138 | // set the owner |
---|
| 139 | pj->setOwner(this->getOwner()); |
---|
| 140 | pj->setParent(PNode::getNullParent()); |
---|
| 141 | |
---|
[10044] | 142 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1)); |
---|
[9975] | 143 | |
---|
[10771] | 144 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[9975] | 145 | pj->setAbsDir(this->getAbsDir()); |
---|
| 146 | pj->activate(); |
---|
[10152] | 147 | |
---|
| 148 | // initiate animation |
---|
| 149 | for (int i = 0; i < this->getSegs(); i++) |
---|
[10771] | 150 | this->getShootAnim(this->getActiveBarrel(), i)->replay(); // FIXME needs clean up |
---|
[10152] | 151 | |
---|
[10771] | 152 | this->cycleBarrel(); |
---|
[9975] | 153 | } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | * this activates the weapon |
---|
| 157 | */ |
---|
| 158 | void HeavyBlaster::activate() |
---|
| 159 | { |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * this deactivates the weapon |
---|
| 164 | */ |
---|
| 165 | void HeavyBlaster::deactivate() |
---|
| 166 | { |
---|
| 167 | } |
---|
| 168 | |
---|
[10152] | 169 | |
---|
[9975] | 170 | void HeavyBlaster::draw() const |
---|
| 171 | { |
---|
[10133] | 172 | glMatrixMode(GL_MODELVIEW); |
---|
| 173 | glPushMatrix(); |
---|
| 174 | glTranslatef (this->getAbsCoor ().x, |
---|
| 175 | this->getAbsCoor ().y, |
---|
| 176 | this->getAbsCoor ().z); |
---|
[10548] | 177 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 178 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[10133] | 179 | |
---|
[10152] | 180 | if (this->leftRight == W_LEFT) |
---|
[10771] | 181 | glScalef(1.0, 1.0, -1.0); //FIXME check weather this causes a slowdown... |
---|
[10152] | 182 | |
---|
[10771] | 183 | static_cast<StaticModel*>(this->getModel())->draw(6); |
---|
[10133] | 184 | |
---|
[10771] | 185 | glPushMatrix(); |
---|
| 186 | glTranslatef (this->getObjCompx(0,0), this->getObjCompy(0,0), this->getObjCompz(0,0)); |
---|
| 187 | static_cast<StaticModel*>(this->getModel())->draw(2); |
---|
| 188 | glPopMatrix(); |
---|
[10136] | 189 | |
---|
[10771] | 190 | glPushMatrix(); |
---|
| 191 | glTranslatef (this->getObjCompx(1,0), this->getObjCompy(1,0), this->getObjCompz(1,0)); |
---|
| 192 | static_cast<StaticModel*>(this->getModel())->draw(3); |
---|
| 193 | glPopMatrix(); |
---|
[10133] | 194 | |
---|
[10771] | 195 | glPushMatrix(); |
---|
| 196 | glTranslatef (this->getObjCompx(2,0), this->getObjCompy(2,0), this->getObjCompz(2,0)); |
---|
| 197 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
| 198 | glPopMatrix(); |
---|
[10136] | 199 | |
---|
[10771] | 200 | glPushMatrix(); |
---|
| 201 | glTranslatef (this->getObjCompx(0,1), this->getObjCompy(0,1), this->getObjCompz(0,1)); |
---|
| 202 | static_cast<StaticModel*>(this->getModel())->draw(4); |
---|
| 203 | glPopMatrix(); |
---|
[10152] | 204 | |
---|
[10771] | 205 | glPushMatrix(); |
---|
| 206 | glTranslatef (this->getObjCompx(1,1), this->getObjCompy(1,1), this->getObjCompz(1,1)); |
---|
| 207 | static_cast<StaticModel*>(this->getModel())->draw(5); |
---|
| 208 | glPopMatrix(); |
---|
[10133] | 209 | |
---|
[10771] | 210 | glPushMatrix(); |
---|
| 211 | glTranslatef (this->getObjCompx(2,1), this->getObjCompy(2,1), this->getObjCompz(2,1)); |
---|
| 212 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
| 213 | glPopMatrix(); |
---|
[10133] | 214 | |
---|
| 215 | glPopMatrix(); |
---|
[9975] | 216 | } |
---|
[10516] | 217 | |
---|
| 218 | void HeavyBlaster::tick(float dt) |
---|
| 219 | { |
---|
[10539] | 220 | if (!Weapon::tickW(dt)) |
---|
| 221 | return; |
---|
[10516] | 222 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 223 | { |
---|
| 224 | this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png"); |
---|
| 225 | this->setEnergyWidgetInitialized(true); |
---|
| 226 | } |
---|
| 227 | } |
---|