| 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: Nicolas Schlumberger |
|---|
| 13 | co-programmer: |
|---|
| 14 | |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | #include "nadion_laser.h" |
|---|
| 18 | #include "world_entities/projectiles/projectile.h" |
|---|
| 19 | |
|---|
| 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 | |
|---|
| 29 | #include "elements/glgui_energywidgetvertical.h" |
|---|
| 30 | |
|---|
| 31 | // |
|---|
| 32 | ObjectListDefinition(NadionLaser); |
|---|
| 33 | CREATE_FACTORY(NadionLaser); |
|---|
| 34 | /** |
|---|
| 35 | * Standard constructor |
|---|
| 36 | */ |
|---|
| 37 | NadionLaser::NadionLaser () |
|---|
| 38 | : Weapon() |
|---|
| 39 | { |
|---|
| 40 | this->init(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | NadionLaser::NadionLaser (const TiXmlElement* root = NULL) |
|---|
| 44 | : Weapon() |
|---|
| 45 | { |
|---|
| 46 | this->init(); |
|---|
| 47 | if (root != NULL) |
|---|
| 48 | this->loadParams(root); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Default destructor |
|---|
| 53 | */ |
|---|
| 54 | NadionLaser::~NadionLaser() |
|---|
| 55 | { |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void NadionLaser::loadParams(const TiXmlElement* root) |
|---|
| 59 | { |
|---|
| 60 | Weapon::loadParams(root); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | void NadionLaser::init() |
|---|
| 64 | { |
|---|
| 65 | this->setScaling(.45); |
|---|
| 66 | |
|---|
| 67 | this->loadModel("models/guns/nadion_laser.obj", this->getScaling()); |
|---|
| 68 | |
|---|
| 69 | this->setStateDuration(WS_SHOOTING, 0.1666); // 6 shots per second |
|---|
| 70 | |
|---|
| 71 | this->setStateDuration(WS_RELOADING, 0); |
|---|
| 72 | this->setStateDuration(WS_ACTIVATING, .5); |
|---|
| 73 | this->setStateDuration(WS_DEACTIVATING, 1); |
|---|
| 74 | |
|---|
| 75 | this->setEnergyMax(500); |
|---|
| 76 | this->increaseEnergy(500); |
|---|
| 77 | //this->minCharge = 2; |
|---|
| 78 | |
|---|
| 79 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
|---|
| 80 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
|---|
| 81 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
|---|
| 82 | |
|---|
| 83 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
|---|
| 84 | this->setProjectileTypeC("NadionBlast"); |
|---|
| 85 | this->prepareProjectiles(20); |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | // this->setBarrels(1); // could be left out |
|---|
| 89 | // this->setSegs(1); // could be left out |
|---|
| 90 | |
|---|
| 91 | this->setEmissionPoint(Vector(1.680, 0.0, 0.0) * this->getScaling()); |
|---|
| 92 | |
|---|
| 93 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
|---|
| 94 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
|---|
| 95 | |
|---|
| 96 | animation2->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 97 | animation3->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 98 | |
|---|
| 99 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
|---|
| 100 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
|---|
| 101 | |
|---|
| 102 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
|---|
| 103 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void NadionLaser::fire() |
|---|
| 108 | { |
|---|
| 109 | Projectile* pj = this->getProjectile(); |
|---|
| 110 | if (pj == NULL) |
|---|
| 111 | return; |
|---|
| 112 | |
|---|
| 113 | // set the owner |
|---|
| 114 | pj->setOwner(this->getOwner()); |
|---|
| 115 | |
|---|
| 116 | pj->setParent(PNode::getNullParent()); |
|---|
| 117 | |
|---|
| 118 | Vector dir = (this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor()).getNormalized(); |
|---|
| 119 | //FIXME direction calculation is a mess, needs to be cleaned up |
|---|
| 120 | // HACK direction AbsDir calulation |
|---|
| 121 | Vector up = dir.cross(VECTOR_RAND(1)); |
|---|
| 122 | |
|---|
| 123 | //force a resoable up vector |
|---|
| 124 | while (up.len() < .0001) |
|---|
| 125 | up = dir.cross(VECTOR_RAND(1)); |
|---|
| 126 | |
|---|
| 127 | pj->setVelocity(this->getParent()->getVelocity() + (dir)*160); |
|---|
| 128 | |
|---|
| 129 | pj->setAbsCoor(this->getEmissionPoint()); |
|---|
| 130 | // pj->setAbsDir(Quaternion(this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(), Vector(0,0,0))); |
|---|
| 131 | // pj->setAbsDir(Quaternion(tmp.getNormalized(), this->getParent()->getAbsDir().apply(Vector(0,1,0)))); |
|---|
| 132 | // pj->setAbsDir(Quaternion(dir, up.getNormalized())); |
|---|
| 133 | pj->setAbsDir(Quaternion(dir, Vector(1,0,0))); |
|---|
| 134 | |
|---|
| 135 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 136 | pj->activate(); |
|---|
| 137 | |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * this activates the weapon |
|---|
| 143 | */ |
|---|
| 144 | void NadionLaser::activate() |
|---|
| 145 | { |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * this deactivates the weapon |
|---|
| 150 | */ |
|---|
| 151 | void NadionLaser::deactivate() |
|---|
| 152 | { |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | void NadionLaser::draw() const |
|---|
| 156 | { |
|---|
| 157 | glPushMatrix(); |
|---|
| 158 | glMatrixMode(GL_MODELVIEW); |
|---|
| 159 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
|---|
| 160 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
|---|
| 161 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 162 | static_cast<StaticModel*>(this->getModel())->draw(); |
|---|
| 163 | glPopMatrix(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | void NadionLaser::tick(float dt) |
|---|
| 167 | { |
|---|
| 168 | if (!Weapon::tickW(dt)) |
|---|
| 169 | return; |
|---|
| 170 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
|---|
| 171 | { |
|---|
| 172 | this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png"); |
|---|
| 173 | this->setEnergyWidgetInitialized(true); |
|---|
| 174 | } |
|---|
| 175 | } |
|---|