[9972] | 1 | #include "light_blaster.h" |
---|
| 2 | #include "world_entities/projectiles/projectile.h" |
---|
| 3 | |
---|
| 4 | #include "world_entity.h" |
---|
| 5 | #include "static_model.h" |
---|
| 6 | #include "weapon_manager.h" |
---|
| 7 | #include "util/loading/factory.h" |
---|
| 8 | |
---|
| 9 | #include "animation3d.h" |
---|
| 10 | |
---|
| 11 | #include "loading/fast_factory.h" |
---|
| 12 | |
---|
| 13 | CREATE_FACTORY(LightBlaster); |
---|
| 14 | /** |
---|
| 15 | * Standard constructor |
---|
| 16 | */ |
---|
| 17 | LightBlaster::LightBlaster () |
---|
| 18 | : Weapon() |
---|
| 19 | { |
---|
| 20 | this->init(); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | LightBlaster::LightBlaster (const TiXmlElement* root = NULL) |
---|
| 24 | : Weapon() |
---|
| 25 | { |
---|
| 26 | this->init(); |
---|
| 27 | if (root != NULL) |
---|
| 28 | this->loadParams(root); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * Default destructor |
---|
| 33 | */ |
---|
| 34 | LightBlaster::~LightBlaster() |
---|
| 35 | { |
---|
[10170] | 36 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 37 | { |
---|
| 38 | for(int j = 0; j < this->getSegs(); j++) |
---|
| 39 | { |
---|
| 40 | delete this->shootAnim[i][j]; |
---|
| 41 | delete this->objComp[i][j]; |
---|
| 42 | } |
---|
| 43 | delete this->shootAnim[i]; |
---|
| 44 | delete this->objComp[i]; |
---|
| 45 | delete this->emissionPoint[i]; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | this->deconstr(); |
---|
[9972] | 49 | // model will be deleted from WorldEntity-destructor |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void LightBlaster::loadParams(const TiXmlElement* root) |
---|
| 53 | { |
---|
| 54 | Weapon::loadParams(root); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void LightBlaster::init() |
---|
| 58 | { |
---|
| 59 | |
---|
[10152] | 60 | this->loadModel("models/guns/gattling.obj", 0.333); |
---|
[9972] | 61 | |
---|
| 62 | |
---|
[9998] | 63 | this->setStateDuration(WS_SHOOTING, 0.05); // 20 Schuss pro Sekunde |
---|
[9972] | 64 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 65 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 66 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 67 | |
---|
[9998] | 68 | this->setEnergyMax(500); |
---|
| 69 | this->increaseEnergy(500); |
---|
[9972] | 70 | //this->minCharge = 2; |
---|
| 71 | |
---|
| 72 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
| 73 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
| 74 | this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav"); |
---|
| 75 | |
---|
| 76 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[9978] | 77 | //this->setProjectileTypeC("RailProjectile"); // FIXME temp project type until the blaste class exist |
---|
[10044] | 78 | this->setProjectileTypeC("LBolt"); // Working; FIXME: add textures |
---|
[10170] | 79 | // this->setProjectileTypeC("Spike"); // Working; FIXME: add textures |
---|
[9972] | 80 | this->prepareProjectiles(100); |
---|
| 81 | |
---|
[10152] | 82 | this->setBarrels(3); |
---|
| 83 | this->setSegs(1); |
---|
| 84 | this->activeBarrel = 0; |
---|
| 85 | |
---|
| 86 | this->objComp = new PNode**[this->getBarrels()]; |
---|
| 87 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
| 88 | this->shootAnim = new Animation3D**[this->getBarrels()]; |
---|
| 89 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 90 | { |
---|
| 91 | this->objComp[i] = new PNode* [this->getSegs()]; |
---|
| 92 | this->emissionPoint[i] = new PNode; |
---|
| 93 | 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 |
---|
| 94 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
| 95 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 96 | this->shootAnim[i] = new Animation3D* [this->getSegs()]; |
---|
| 97 | for(int j = 0; j < this->getSegs(); j++) |
---|
| 98 | { |
---|
| 99 | this->objComp[i][j] = new PNode; |
---|
| 100 | this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]); |
---|
| 101 | this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | for (int i = 0; i < this->getBarrels(); i++ ) |
---|
| 106 | this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1)); |
---|
| 107 | |
---|
| 108 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this); |
---|
[9972] | 109 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 110 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 111 | |
---|
[10152] | 112 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[9972] | 113 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 114 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 115 | |
---|
[10152] | 116 | // this->setEmissionPoint(3.8, 1.2, 0); |
---|
[9972] | 117 | |
---|
[10152] | 118 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
[10170] | 119 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR); |
---|
| 120 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR); |
---|
[10152] | 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
[9972] | 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 LightBlaster::fire() |
---|
| 133 | { |
---|
| 134 | Projectile* pj = this->getProjectile(); |
---|
| 135 | if (pj == NULL) |
---|
| 136 | return; |
---|
| 137 | |
---|
[9975] | 138 | // set the owner |
---|
| 139 | pj->setOwner(this->getOwner()); |
---|
| 140 | |
---|
[9972] | 141 | pj->setParent(PNode::getNullParent()); |
---|
| 142 | |
---|
[10044] | 143 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
[10046] | 144 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180); |
---|
[9972] | 145 | |
---|
[10152] | 146 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
[9972] | 147 | pj->setAbsDir(this->getAbsDir()); |
---|
[10152] | 148 | // pj->toList(OM_GROUP_01_PROJ); |
---|
[9972] | 149 | pj->activate(); |
---|
[10152] | 150 | |
---|
| 151 | for (int i = 0; i < this->getSegs(); i++) |
---|
| 152 | this->shootAnim[this->activeBarrel][i]->replay(); |
---|
| 153 | |
---|
| 154 | // switch barrel |
---|
| 155 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
---|
[9972] | 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * this activates the weapon |
---|
| 160 | */ |
---|
| 161 | void LightBlaster::activate() |
---|
| 162 | { |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | * this deactivates the weapon |
---|
| 167 | */ |
---|
| 168 | void LightBlaster::deactivate() |
---|
| 169 | { |
---|
[9975] | 170 | } |
---|
| 171 | |
---|
| 172 | void LightBlaster::draw() const |
---|
| 173 | { |
---|
[10152] | 174 | glMatrixMode(GL_MODELVIEW); |
---|
| 175 | glPushMatrix(); |
---|
| 176 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 177 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 178 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 179 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 180 | glPopMatrix(); |
---|
[9975] | 181 | } |
---|