[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 "medium_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 | |
---|
[10366] | 31 | // |
---|
[10117] | 32 | //ObjectListDefinition(MediumBlaster); |
---|
[9975] | 33 | CREATE_FACTORY(MediumBlaster); |
---|
| 34 | /** |
---|
| 35 | * Standard constructor |
---|
| 36 | */ |
---|
| 37 | MediumBlaster::MediumBlaster () |
---|
| 38 | : Weapon() |
---|
| 39 | { |
---|
| 40 | this->init(); |
---|
| 41 | } |
---|
| 42 | |
---|
[9972] | 43 | MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL) |
---|
| 44 | : Weapon() |
---|
[9975] | 45 | { |
---|
[9972] | 46 | this->init(); |
---|
| 47 | if (root != NULL) |
---|
| 48 | this->loadParams(root); |
---|
[9975] | 49 | } |
---|
[9972] | 50 | |
---|
| 51 | /** |
---|
| 52 | * Default destructor |
---|
| 53 | */ |
---|
| 54 | MediumBlaster::~MediumBlaster() |
---|
[9975] | 55 | { |
---|
[9972] | 56 | // model will be deleted from WorldEntity-destructor |
---|
[10286] | 57 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 58 | { |
---|
| 59 | delete [] this->shootAnim[i]; |
---|
| 60 | } |
---|
| 61 | delete [] this->shootAnim; |
---|
[9975] | 62 | } |
---|
[9972] | 63 | |
---|
[9975] | 64 | void MediumBlaster::loadParams(const TiXmlElement* root) |
---|
| 65 | { |
---|
| 66 | Weapon::loadParams(root); |
---|
| 67 | } |
---|
[9972] | 68 | |
---|
[9975] | 69 | void MediumBlaster::init() |
---|
| 70 | { |
---|
[10698] | 71 | this->setScaling(.3333); |
---|
[9975] | 72 | |
---|
[10698] | 73 | this->loadModel("models/guns/blaster.obj", this->getScaling()); |
---|
| 74 | |
---|
[10036] | 75 | this->setStateDuration(WS_SHOOTING, 0.2); // 5 Schuss pro Sekunde |
---|
[9998] | 76 | |
---|
[9975] | 77 | this->setStateDuration(WS_RELOADING, 0); |
---|
[10132] | 78 | this->setStateDuration(WS_ACTIVATING, .5); //.5); |
---|
| 79 | this->setStateDuration(WS_DEACTIVATING, 1); // 1); |
---|
[9975] | 80 | |
---|
[9998] | 81 | this->setEnergyMax(500); |
---|
| 82 | this->increaseEnergy(500); |
---|
[9975] | 83 | //this->minCharge = 2; |
---|
| 84 | |
---|
[10415] | 85 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
[10698] | 86 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[10415] | 87 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
[9975] | 88 | |
---|
| 89 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10698] | 90 | this->setProjectileTypeC("MBolt"); |
---|
| 91 | this->prepareProjectiles(10); |
---|
[9975] | 92 | |
---|
[10286] | 93 | |
---|
| 94 | this->setBarrels(1); |
---|
| 95 | this->setSegs(2); |
---|
| 96 | this->activeBarrel = 0; |
---|
| 97 | |
---|
| 98 | this->objComp = new PNode**[this->getBarrels()]; |
---|
[10698] | 99 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
[10286] | 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()]; |
---|
[10698] | 104 | this->emissionPoint[i] = new PNode; |
---|
| 105 | this->emissionPoint[i]->setParent(this); //Parenting emissionPoint to Weapon |
---|
| 106 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
| 107 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[10286] | 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++){ |
---|
[10698] | 118 | this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL); |
---|
| 119 | this->shootAnim[i][0]->addKeyFrame(Vector(-1.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL); |
---|
| 120 | this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL); |
---|
[10286] | 121 | |
---|
[10698] | 122 | this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL); |
---|
| 123 | this->shootAnim[i][1]->addKeyFrame(Vector(.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL); |
---|
| 124 | this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL); |
---|
[10286] | 125 | } |
---|
| 126 | |
---|
[9975] | 127 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 128 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 129 | |
---|
| 130 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 131 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 132 | |
---|
[10698] | 133 | this->emissionPoint[0]->setRelCoor(Vector(3.9, 0.0, 0.0) * this->getScaling()); |
---|
[9975] | 134 | |
---|
| 135 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 136 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 137 | |
---|
| 138 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 139 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | void MediumBlaster::fire() |
---|
| 144 | { |
---|
| 145 | Projectile* pj = this->getProjectile(); |
---|
| 146 | if (pj == NULL) |
---|
| 147 | return; |
---|
| 148 | |
---|
| 149 | // set the owner |
---|
| 150 | pj->setOwner(this->getOwner()); |
---|
| 151 | |
---|
| 152 | pj->setParent(PNode::getNullParent()); |
---|
| 153 | |
---|
[10098] | 154 | pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160); |
---|
[9975] | 155 | |
---|
| 156 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 157 | pj->setAbsDir(this->getAbsDir()); |
---|
| 158 | pj->activate(); |
---|
[10286] | 159 | |
---|
| 160 | for (int i = 0; i < this->getSegs(); i++) |
---|
| 161 | this->shootAnim[this->activeBarrel][i]->replay(); |
---|
[9975] | 162 | } |
---|
| 163 | |
---|
[10516] | 164 | |
---|
[9975] | 165 | /** |
---|
| 166 | * this activates the weapon |
---|
| 167 | */ |
---|
| 168 | void MediumBlaster::activate() |
---|
| 169 | { |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * this deactivates the weapon |
---|
| 174 | */ |
---|
| 175 | void MediumBlaster::deactivate() |
---|
| 176 | { |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | void MediumBlaster::draw() const |
---|
| 180 | { |
---|
[10286] | 181 | glMatrixMode(GL_MODELVIEW); |
---|
| 182 | glPushMatrix(); |
---|
[10548] | 183 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 184 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 185 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 186 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
[10286] | 187 | |
---|
| 188 | glPushMatrix(); |
---|
| 189 | glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z); |
---|
| 190 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
| 191 | glPopMatrix(); |
---|
| 192 | |
---|
| 193 | glPushMatrix(); |
---|
[10289] | 194 | glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z); |
---|
[10516] | 195 | static_cast<StaticModel*>(this->getModel())->draw(2); |
---|
[10286] | 196 | glPopMatrix(); |
---|
| 197 | |
---|
| 198 | glPopMatrix(); |
---|
[9975] | 199 | } |
---|
[10516] | 200 | |
---|
| 201 | void MediumBlaster::tick(float dt) |
---|
| 202 | { |
---|
[10539] | 203 | if (!Weapon::tickW(dt)) |
---|
| 204 | return; |
---|
[10516] | 205 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 206 | { |
---|
| 207 | this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png"); |
---|
| 208 | this->setEnergyWidgetInitialized(true); |
---|
| 209 | } |
---|
| 210 | } |
---|