[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 | { |
---|
[10261] | 36 | |
---|
[10170] | 37 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 38 | { |
---|
[10261] | 39 | delete [] this->shootAnim[i]; |
---|
| 40 | delete [] this->objComp[i]; |
---|
| 41 | } |
---|
| 42 | delete [] this->emissionPoint; |
---|
| 43 | delete [] this->shootAnim; |
---|
| 44 | delete [] this->objComp; |
---|
[10170] | 45 | |
---|
[9972] | 46 | } |
---|
| 47 | |
---|
| 48 | void LightBlaster::loadParams(const TiXmlElement* root) |
---|
| 49 | { |
---|
| 50 | Weapon::loadParams(root); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void LightBlaster::init() |
---|
| 54 | { |
---|
| 55 | |
---|
[10484] | 56 | this->loadModel("models/guns/gatling.obj", 0.333); |
---|
[9972] | 57 | |
---|
[10415] | 58 | |
---|
[9998] | 59 | this->setStateDuration(WS_SHOOTING, 0.05); // 20 Schuss pro Sekunde |
---|
[9972] | 60 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 61 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 62 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 63 | |
---|
[9998] | 64 | this->setEnergyMax(500); |
---|
| 65 | this->increaseEnergy(500); |
---|
[9972] | 66 | //this->minCharge = 2; |
---|
| 67 | |
---|
[10415] | 68 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
[10484] | 69 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[10415] | 70 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
[9972] | 71 | |
---|
| 72 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10484] | 73 | this->setProjectileTypeC("LBolt"); |
---|
[9972] | 74 | this->prepareProjectiles(100); |
---|
| 75 | |
---|
[10152] | 76 | this->setBarrels(3); |
---|
| 77 | this->setSegs(1); |
---|
| 78 | this->activeBarrel = 0; |
---|
| 79 | |
---|
| 80 | this->objComp = new PNode**[this->getBarrels()]; |
---|
| 81 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
| 82 | this->shootAnim = new Animation3D**[this->getBarrels()]; |
---|
| 83 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 84 | { |
---|
| 85 | this->objComp[i] = new PNode* [this->getSegs()]; |
---|
| 86 | this->emissionPoint[i] = new PNode; |
---|
| 87 | 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 |
---|
| 88 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
| 89 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 90 | this->shootAnim[i] = new Animation3D* [this->getSegs()]; |
---|
| 91 | for(int j = 0; j < this->getSegs(); j++) |
---|
| 92 | { |
---|
| 93 | this->objComp[i][j] = new PNode; |
---|
| 94 | this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]); |
---|
| 95 | this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | for (int i = 0; i < this->getBarrels(); i++ ) |
---|
| 100 | this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1)); |
---|
| 101 | |
---|
| 102 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this); |
---|
[9972] | 103 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 104 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 105 | |
---|
[10152] | 106 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[9972] | 107 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 108 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 109 | |
---|
[10152] | 110 | // this->setEmissionPoint(3.8, 1.2, 0); |
---|
[9972] | 111 | |
---|
[10152] | 112 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
[10170] | 113 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR); |
---|
| 114 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR); |
---|
[10152] | 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
[9972] | 118 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 119 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 120 | |
---|
| 121 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 122 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | void LightBlaster::fire() |
---|
| 127 | { |
---|
| 128 | Projectile* pj = this->getProjectile(); |
---|
| 129 | if (pj == NULL) |
---|
| 130 | return; |
---|
| 131 | |
---|
[9975] | 132 | // set the owner |
---|
| 133 | pj->setOwner(this->getOwner()); |
---|
| 134 | |
---|
[9972] | 135 | pj->setParent(PNode::getNullParent()); |
---|
| 136 | |
---|
[10044] | 137 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
[10046] | 138 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180); |
---|
[9972] | 139 | |
---|
[10152] | 140 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
[9972] | 141 | pj->setAbsDir(this->getAbsDir()); |
---|
[10152] | 142 | // pj->toList(OM_GROUP_01_PROJ); |
---|
[9972] | 143 | pj->activate(); |
---|
[10152] | 144 | |
---|
| 145 | for (int i = 0; i < this->getSegs(); i++) |
---|
| 146 | this->shootAnim[this->activeBarrel][i]->replay(); |
---|
| 147 | |
---|
| 148 | // switch barrel |
---|
| 149 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
---|
[9972] | 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * this activates the weapon |
---|
| 154 | */ |
---|
| 155 | void LightBlaster::activate() |
---|
| 156 | { |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /** |
---|
| 160 | * this deactivates the weapon |
---|
| 161 | */ |
---|
| 162 | void LightBlaster::deactivate() |
---|
| 163 | { |
---|
[9975] | 164 | } |
---|
| 165 | |
---|
| 166 | void LightBlaster::draw() const |
---|
| 167 | { |
---|
[10152] | 168 | glMatrixMode(GL_MODELVIEW); |
---|
| 169 | glPushMatrix(); |
---|
| 170 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 171 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 172 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 173 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 174 | glPopMatrix(); |
---|
[9975] | 175 | } |
---|