[10641] | 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 "rf_cannon.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 | |
---|
[10661] | 31 | |
---|
| 32 | ObjectListDefinition(RFCannon); |
---|
[10641] | 33 | CREATE_FACTORY(RFCannon); |
---|
[10661] | 34 | |
---|
[10641] | 35 | /** |
---|
| 36 | * Standard constructor |
---|
| 37 | */ |
---|
| 38 | RFCannon::RFCannon () |
---|
| 39 | : Weapon() |
---|
| 40 | { |
---|
| 41 | this->init(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | RFCannon::RFCannon (const TiXmlElement* root = NULL) |
---|
| 45 | : Weapon() |
---|
| 46 | { |
---|
| 47 | this->init(); |
---|
| 48 | if (root != NULL) |
---|
| 49 | this->loadParams(root); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Default destructor |
---|
| 54 | */ |
---|
| 55 | RFCannon::~RFCannon() |
---|
| 56 | { |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void RFCannon::loadParams(const TiXmlElement* root) |
---|
| 60 | { |
---|
| 61 | Weapon::loadParams(root); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void RFCannon::init() |
---|
| 65 | { |
---|
[10648] | 66 | this->setScaling(.2); |
---|
[10641] | 67 | |
---|
[10648] | 68 | this->loadModel("models/guns/rf_cannon.obj", this->getScaling()); |
---|
[10641] | 69 | |
---|
[10648] | 70 | |
---|
[10641] | 71 | this->setStateDuration(WS_SHOOTING, 0.1); // 10 Schuss pro Sekunde |
---|
| 72 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 73 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 74 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 75 | |
---|
| 76 | this->setEnergyMax(500); |
---|
| 77 | this->increaseEnergy(500); |
---|
| 78 | |
---|
| 79 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
| 80 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
| 81 | |
---|
| 82 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10645] | 83 | this->setProjectileTypeC("PlasmaPulse"); |
---|
[10649] | 84 | this->prepareProjectiles(25); |
---|
[10641] | 85 | |
---|
| 86 | this->setBarrels(4); |
---|
[10772] | 87 | // this->setSegs(1); |
---|
[10771] | 88 | this->setActiveBarrel(rand() % 4); |
---|
[10641] | 89 | |
---|
| 90 | |
---|
[10771] | 91 | this->setEmissionPoint(Vector(4.1, 0.0, 0.75) * this->getScaling(), 0); |
---|
| 92 | this->setEmissionPoint(Vector(4.1, 0.45, 0.0) * this->getScaling(), 1); |
---|
| 93 | this->setEmissionPoint(Vector(4.1, 0.0, -0.75) * this->getScaling(), 2); |
---|
| 94 | this->setEmissionPoint(Vector(4.1, -0.45, 0.0) * this->getScaling(), 3); |
---|
[10641] | 95 | |
---|
| 96 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 97 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 98 | |
---|
| 99 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 100 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 101 | |
---|
| 102 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 103 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 104 | |
---|
| 105 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 106 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void RFCannon::fire() |
---|
| 110 | { |
---|
[10702] | 111 | Projectile* pj = this->getProjectile(); |
---|
| 112 | if (pj == NULL) |
---|
| 113 | return; |
---|
[10641] | 114 | |
---|
[10702] | 115 | // set the owner |
---|
| 116 | pj->setOwner(this->getOwner()); |
---|
[10641] | 117 | |
---|
[10702] | 118 | pj->setParent(PNode::getNullParent()); |
---|
[10641] | 119 | |
---|
[10719] | 120 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190); |
---|
| 121 | Vector tmp = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
[10641] | 122 | |
---|
[10722] | 123 | pj->setVelocity(this->getParent()->getVelocity() + (tmp.getNormalized())*190); |
---|
[10719] | 124 | |
---|
[10771] | 125 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 126 | //FIXME pj needs a absDir |
---|
[10719] | 127 | // pj->setAbsDir(this->getAbsDir()); |
---|
[10728] | 128 | // pj->setAbsDir(Quaternion(tmp.getNormalized(), this->getParent()->getAbsDir().apply(Vector(0,1,0)))); |
---|
[10719] | 129 | |
---|
[10702] | 130 | pj->activate(); |
---|
[10641] | 131 | |
---|
[10771] | 132 | this->cycleBarrel(); |
---|
[10641] | 133 | } |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * this activates the weapon |
---|
| 137 | */ |
---|
| 138 | void RFCannon::activate() |
---|
| 139 | { |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * this deactivates the weapon |
---|
| 144 | */ |
---|
| 145 | void RFCannon::deactivate() |
---|
| 146 | { |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | void RFCannon::draw() const |
---|
| 150 | { |
---|
| 151 | glPushMatrix(); |
---|
[10702] | 152 | glMatrixMode(GL_MODELVIEW); |
---|
[10641] | 153 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 154 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 155 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 156 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 157 | glPopMatrix(); |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | void RFCannon::tick(float dt) |
---|
| 162 | { |
---|
| 163 | if (!Weapon::tickW(dt)) |
---|
| 164 | return; |
---|
| 165 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 166 | { |
---|
| 167 | this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png"); |
---|
| 168 | this->setEnergyWidgetInitialized(true); |
---|
| 169 | } |
---|
| 170 | } |
---|