[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 |
---|
[10763] | 12 | main-programmer: Nicolas Schlumberger |
---|
[10618] | 13 | co-programmer: |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
[10648] | 17 | #include "nadion_laser.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 | // |
---|
[10661] | 32 | ObjectListDefinition(NadionLaser); |
---|
[10648] | 33 | CREATE_FACTORY(NadionLaser); |
---|
[9975] | 34 | /** |
---|
| 35 | * Standard constructor |
---|
| 36 | */ |
---|
[10648] | 37 | NadionLaser::NadionLaser () |
---|
[9975] | 38 | : Weapon() |
---|
| 39 | { |
---|
| 40 | this->init(); |
---|
| 41 | } |
---|
| 42 | |
---|
[10648] | 43 | NadionLaser::NadionLaser (const TiXmlElement* root = NULL) |
---|
[9972] | 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 | */ |
---|
[10648] | 54 | NadionLaser::~NadionLaser() |
---|
[9975] | 55 | { |
---|
[10763] | 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 | |
---|
[10648] | 64 | void NadionLaser::loadParams(const TiXmlElement* root) |
---|
[9975] | 65 | { |
---|
| 66 | Weapon::loadParams(root); |
---|
| 67 | } |
---|
[9972] | 68 | |
---|
[10648] | 69 | void NadionLaser::init() |
---|
[9975] | 70 | { |
---|
[10648] | 71 | this->setScaling(.45); |
---|
[9975] | 72 | |
---|
[10648] | 73 | this->loadModel("models/guns/nadion_laser.obj", this->getScaling()); |
---|
[9998] | 74 | |
---|
[10763] | 75 | this->setStateDuration(WS_SHOOTING, 0.1666); // 6 shots per second |
---|
[10648] | 76 | |
---|
[9975] | 77 | this->setStateDuration(WS_RELOADING, 0); |
---|
[10649] | 78 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 79 | this->setStateDuration(WS_DEACTIVATING, 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"); |
---|
[10648] | 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); |
---|
[10702] | 90 | this->setProjectileTypeC("NadionBlast"); |
---|
[10649] | 91 | this->prepareProjectiles(20); |
---|
[9975] | 92 | |
---|
[10286] | 93 | |
---|
| 94 | this->setBarrels(1); |
---|
[10648] | 95 | this->setSegs(1); |
---|
[10286] | 96 | this->activeBarrel = 0; |
---|
| 97 | |
---|
| 98 | this->objComp = new PNode**[this->getBarrels()]; |
---|
[10648] | 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()]; |
---|
[10648] | 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 | |
---|
[10648] | 117 | this->emissionPoint[0]->setRelCoor(Vector(1.680, 0.0, 0.0) * this->getScaling()); |
---|
[10286] | 118 | |
---|
[9975] | 119 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 120 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 121 | |
---|
| 122 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 123 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 124 | |
---|
| 125 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 126 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 127 | |
---|
| 128 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 129 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
[10648] | 133 | void NadionLaser::fire() |
---|
[9975] | 134 | { |
---|
| 135 | Projectile* pj = this->getProjectile(); |
---|
| 136 | if (pj == NULL) |
---|
| 137 | return; |
---|
| 138 | |
---|
| 139 | // set the owner |
---|
| 140 | pj->setOwner(this->getOwner()); |
---|
| 141 | |
---|
| 142 | pj->setParent(PNode::getNullParent()); |
---|
| 143 | |
---|
[10733] | 144 | Vector dir = (this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor()).getNormalized(); |
---|
| 145 | // HACK direction AbsDir calulation |
---|
| 146 | Vector up = dir.cross(VECTOR_RAND(1)); |
---|
[9975] | 147 | |
---|
[10733] | 148 | //force a resoable up vector |
---|
| 149 | while (up.len() < .0001) |
---|
| 150 | up = dir.cross(VECTOR_RAND(1)); |
---|
[10719] | 151 | |
---|
[10733] | 152 | pj->setVelocity(this->getParent()->getVelocity() + (dir)*160); |
---|
| 153 | |
---|
[9975] | 154 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[10721] | 155 | // pj->setAbsDir(Quaternion(this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(), Vector(0,0,0))); |
---|
[10728] | 156 | // pj->setAbsDir(Quaternion(tmp.getNormalized(), this->getParent()->getAbsDir().apply(Vector(0,1,0)))); |
---|
[10737] | 157 | // pj->setAbsDir(Quaternion(dir, up.getNormalized())); |
---|
| 158 | pj->setAbsDir(Quaternion(dir, Vector(1,0,0))); |
---|
| 159 | |
---|
[10721] | 160 | pj->setAbsDir(this->getAbsDir()); |
---|
[9975] | 161 | pj->activate(); |
---|
[10286] | 162 | |
---|
[9975] | 163 | } |
---|
| 164 | |
---|
[10516] | 165 | |
---|
[9975] | 166 | /** |
---|
| 167 | * this activates the weapon |
---|
| 168 | */ |
---|
[10648] | 169 | void NadionLaser::activate() |
---|
[9975] | 170 | { |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | /** |
---|
| 174 | * this deactivates the weapon |
---|
| 175 | */ |
---|
[10648] | 176 | void NadionLaser::deactivate() |
---|
[9975] | 177 | { |
---|
| 178 | } |
---|
| 179 | |
---|
[10648] | 180 | void NadionLaser::draw() const |
---|
[9975] | 181 | { |
---|
[10702] | 182 | glPushMatrix(); |
---|
[10286] | 183 | glMatrixMode(GL_MODELVIEW); |
---|
[10548] | 184 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 185 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 186 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[10648] | 187 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
[10286] | 188 | glPopMatrix(); |
---|
[9975] | 189 | } |
---|
[10516] | 190 | |
---|
[10648] | 191 | void NadionLaser::tick(float dt) |
---|
[10516] | 192 | { |
---|
[10539] | 193 | if (!Weapon::tickW(dt)) |
---|
| 194 | return; |
---|
[10516] | 195 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 196 | { |
---|
| 197 | this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png"); |
---|
| 198 | this->setEnergyWidgetInitialized(true); |
---|
| 199 | } |
---|
| 200 | } |
---|