| [10180] | 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 |
|---|
| [10618] | 12 | main-programmer: Marc Schaerrer, Nicolas Schlumberger |
|---|
| [10180] | 13 | co-programmer: |
|---|
| 14 | */ |
|---|
| 15 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
|---|
| 16 | |
|---|
| 17 | #include "spike_thrower.h" |
|---|
| 18 | |
|---|
| 19 | #include "weapon_manager.h" |
|---|
| 20 | #include "world_entities/projectiles/projectile.h" |
|---|
| 21 | #include "world_entities/projectiles/spike_ball.h" |
|---|
| [10252] | 22 | #include "world_entities/projectiles/spike.h" |
|---|
| [10180] | 23 | |
|---|
| 24 | #include "model.h" |
|---|
| 25 | |
|---|
| 26 | #include "state.h" |
|---|
| 27 | #include "animation3d.h" |
|---|
| 28 | |
|---|
| 29 | #include <list> |
|---|
| 30 | #include "util/state.h" |
|---|
| 31 | |
|---|
| 32 | #include "util/loading/factory.h" |
|---|
| 33 | |
|---|
| [10516] | 34 | #include "elements/glgui_energywidgetvertical.h" |
|---|
| [10180] | 35 | |
|---|
| [10366] | 36 | |
|---|
| [10516] | 37 | |
|---|
| [10180] | 38 | using namespace std; |
|---|
| 39 | |
|---|
| 40 | ObjectListDefinition(SpikeThrower); |
|---|
| 41 | CREATE_FACTORY(SpikeThrower); |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * standard constructor |
|---|
| 45 | * |
|---|
| 46 | * creates a new SpikeThrower |
|---|
| 47 | */ |
|---|
| 48 | SpikeThrower::SpikeThrower() |
|---|
| 49 | : Weapon() |
|---|
| 50 | { |
|---|
| 51 | this->init(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * creates a new SpikeThrower from a TiXmlElement |
|---|
| 56 | */ |
|---|
| 57 | SpikeThrower::SpikeThrower(const TiXmlElement* root) |
|---|
| 58 | { |
|---|
| 59 | this->init(); |
|---|
| 60 | if (root != NULL) |
|---|
| 61 | this->loadParams(root); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * standard deconstructor |
|---|
| 66 | */ |
|---|
| 67 | SpikeThrower::~SpikeThrower () |
|---|
| 68 | { |
|---|
| 69 | |
|---|
| 70 | // model will be deleted from WorldEntity-destructor |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void SpikeThrower::init() |
|---|
| 74 | { |
|---|
| 75 | this->registerObject(this, SpikeThrower::_objectList); |
|---|
| [10256] | 76 | /* |
|---|
| [10180] | 77 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
|---|
| 78 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
|---|
| 79 | |
|---|
| 80 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 81 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 82 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| [10271] | 83 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 84 | |
|---|
| [10180] | 85 | animation1->setInfinity(ANIM_INF_CONSTANT); |
|---|
| [10256] | 86 | animation2->setInfinity(ANIM_INF_CONSTANT);*/ |
|---|
| [10180] | 87 | |
|---|
| 88 | this->setStateDuration(WS_SHOOTING, .6); |
|---|
| 89 | this->setStateDuration(WS_RELOADING, 1.0f); |
|---|
| 90 | this->setStateDuration(WS_ACTIVATING, .4); |
|---|
| 91 | this->setStateDuration(WS_DEACTIVATING, .4); |
|---|
| 92 | |
|---|
| 93 | this->setEnergyMax(10); |
|---|
| 94 | this->increaseEnergy(10); |
|---|
| 95 | //this->minCharge = 2; |
|---|
| 96 | |
|---|
| 97 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
|---|
| [10256] | 98 | this->setProjectileTypeC("SpikeBall"); |
|---|
| [10180] | 99 | |
|---|
| 100 | // this->loadModel("models/guns/turret1.obj", 1.0); |
|---|
| 101 | |
|---|
| [10256] | 102 | this->setEmissionPoint(2, 0, 0); |
|---|
| [10180] | 103 | this->getProjectileFactory()->prepare(50); |
|---|
| 104 | |
|---|
| [10415] | 105 | this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_1.wav"); |
|---|
| [10419] | 106 | this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav"); |
|---|
| [10618] | 107 | // this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav"); |
|---|
| [10180] | 108 | |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | void SpikeThrower::loadParams(const TiXmlElement* root) |
|---|
| 112 | { |
|---|
| 113 | Weapon::loadParams(root); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | void SpikeThrower::activate() |
|---|
| 117 | { |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | void SpikeThrower::deactivate() |
|---|
| 121 | { |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | void SpikeThrower::tick(float dt) |
|---|
| 125 | { |
|---|
| [10516] | 126 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
|---|
| 127 | { |
|---|
| 128 | this->energyWidget->setDisplayedImage("textures/gui/gui_spikeball.png"); |
|---|
| 129 | this->isEnergyWidgetInitialized = true; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| [10180] | 132 | if (!Weapon::tickW(dt)) |
|---|
| 133 | return; |
|---|
| 134 | |
|---|
| 135 | Quaternion quat; |
|---|
| 136 | Vector direction; |
|---|
| 137 | if (this->getDefaultTarget() == NULL) |
|---|
| 138 | direction = this->getAbsCoor(); |
|---|
| 139 | else |
|---|
| 140 | direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
|---|
| 141 | |
|---|
| 142 | direction.normalize(); |
|---|
| 143 | |
|---|
| 144 | if (likely (this->getParent() != NULL)) |
|---|
| 145 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
|---|
| 146 | else |
|---|
| 147 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
|---|
| 148 | |
|---|
| 149 | this->setAbsDirSoft(quat, 5); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | void SpikeThrower::fire() |
|---|
| 153 | { |
|---|
| [10196] | 154 | Projectile* pj = this->getProjectile(); |
|---|
| 155 | if (pj == NULL) |
|---|
| 156 | return; |
|---|
| [10180] | 157 | |
|---|
| [10196] | 158 | // set the owner |
|---|
| 159 | pj->setOwner(this->getOwner()); |
|---|
| [10180] | 160 | |
|---|
| [10196] | 161 | pj->setParent(PNode::getNullParent()); |
|---|
| 162 | |
|---|
| [10271] | 163 | dynamic_cast<SpikeBall*>(pj)->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*110); |
|---|
| [10260] | 164 | |
|---|
| [10196] | 165 | pj->setAbsCoor(this->getEmissionPoint()); |
|---|
| 166 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 167 | pj->activate(); |
|---|
| [10289] | 168 | |
|---|
| 169 | // this->increaseEnergy( - this->getProjectile()->getMinEnergy()); |
|---|
| 170 | |
|---|
| [10180] | 171 | } |
|---|