[10023] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
[10104] | 4 | Copyright (C) 2004-2006 orx |
---|
[10023] | 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 |
---|
[10104] | 12 | main-programmer: Marc Schaerrer |
---|
[10023] | 13 | co-programmer: |
---|
| 14 | */ |
---|
| 15 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 16 | |
---|
| 17 | #include "swarm_launcher.h" |
---|
| 18 | |
---|
| 19 | #include "weapon_manager.h" |
---|
| 20 | #include "world_entities/projectiles/projectile.h" |
---|
[10080] | 21 | #include "world_entities/projectiles/swarm_projectile.h" |
---|
[10023] | 22 | |
---|
| 23 | #include "model.h" |
---|
[10539] | 24 | #include "world_entities/npcs/npc.h" |
---|
[10023] | 25 | |
---|
| 26 | #include "state.h" |
---|
| 27 | #include "animation3d.h" |
---|
| 28 | |
---|
[10073] | 29 | #include <list> |
---|
| 30 | #include <iterator> |
---|
| 31 | #include "util/state.h" |
---|
| 32 | |
---|
| 33 | #include "math/quaternion.h" |
---|
| 34 | |
---|
[10023] | 35 | #include "util/loading/factory.h" |
---|
| 36 | |
---|
[10516] | 37 | #include "elements/glgui_energywidgetvertical.h" |
---|
[10023] | 38 | |
---|
[10366] | 39 | |
---|
[10516] | 40 | |
---|
[10073] | 41 | using namespace std; |
---|
| 42 | |
---|
[10366] | 43 | ObjectListDefinition(SwarmLauncher); |
---|
[10023] | 44 | CREATE_FACTORY(SwarmLauncher); |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * standard constructor |
---|
| 48 | * |
---|
| 49 | * creates a new SwarmLauncher |
---|
| 50 | */ |
---|
| 51 | SwarmLauncher::SwarmLauncher() |
---|
| 52 | : Weapon() |
---|
| 53 | { |
---|
| 54 | this->init(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * creates a new SwarmLauncher from a TiXmlElement |
---|
| 59 | */ |
---|
| 60 | SwarmLauncher::SwarmLauncher(const TiXmlElement* root) |
---|
| 61 | { |
---|
| 62 | this->init(); |
---|
| 63 | if (root != NULL) |
---|
| 64 | this->loadParams(root); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * standard deconstructor |
---|
| 69 | */ |
---|
| 70 | SwarmLauncher::~SwarmLauncher () |
---|
| 71 | { |
---|
| 72 | // model will be deleted from WorldEntity-destructor |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void SwarmLauncher::init() |
---|
| 76 | { |
---|
| 77 | this->registerObject(this, SwarmLauncher::_objectList); |
---|
| 78 | |
---|
| 79 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 80 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 81 | |
---|
| 82 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 83 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 84 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 85 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 86 | |
---|
| 87 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 88 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 89 | |
---|
| 90 | this->setStateDuration(WS_SHOOTING, .6); |
---|
| 91 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
| 92 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 93 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 94 | |
---|
| 95 | this->setEnergyMax(10); |
---|
| 96 | this->increaseEnergy(10); |
---|
| 97 | //this->minCharge = 2; |
---|
| 98 | |
---|
| 99 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
| 100 | this->setProjectileTypeC("SwarmProjectile"); |
---|
| 101 | |
---|
| 102 | this->loadModel("models/guns/turret1.obj", 1.0); |
---|
| 103 | |
---|
| 104 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[10079] | 105 | this->getProjectileFactory()->prepare(50); |
---|
[10023] | 106 | |
---|
[10415] | 107 | this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_1.wav"); |
---|
[10419] | 108 | this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav"); |
---|
| 109 | this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav"); |
---|
[10023] | 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void SwarmLauncher::loadParams(const TiXmlElement* root) |
---|
| 114 | { |
---|
| 115 | Weapon::loadParams(root); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void SwarmLauncher::activate() |
---|
| 119 | { |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | void SwarmLauncher::deactivate() |
---|
| 123 | { |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void SwarmLauncher::tick(float dt) |
---|
| 127 | { |
---|
| 128 | if (!Weapon::tickW(dt)) |
---|
| 129 | return; |
---|
| 130 | |
---|
| 131 | Quaternion quat; |
---|
| 132 | Vector direction; |
---|
| 133 | if (this->getDefaultTarget() == NULL) |
---|
| 134 | direction = this->getAbsCoor(); |
---|
| 135 | else |
---|
| 136 | direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
| 137 | |
---|
| 138 | direction.normalize(); |
---|
| 139 | |
---|
| 140 | if (likely (this->getParent() != NULL)) |
---|
| 141 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 142 | else |
---|
| 143 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 144 | |
---|
| 145 | this->setAbsDirSoft(quat, 5); |
---|
[10516] | 146 | |
---|
| 147 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 148 | { |
---|
| 149 | this->energyWidget->setDisplayedImage("textures/gui/gui_swarm_missiles.png"); |
---|
| 150 | this->setEnergyWidgetInitialized(true); |
---|
| 151 | } |
---|
[10023] | 152 | } |
---|
| 153 | |
---|
| 154 | void SwarmLauncher::fire() |
---|
| 155 | { |
---|
[10107] | 156 | bool fired = false; |
---|
| 157 | |
---|
[10533] | 158 | PRINTF(0)("fire\n"); |
---|
[10077] | 159 | Projectile* pj = NULL; |
---|
[10539] | 160 | for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++) |
---|
[10073] | 161 | { |
---|
[10539] | 162 | if( ((*eIterator)->getOMListNumber() != (this->getOMListNumber())) && ((*eIterator)->getClassCName() != "Weapon") && ((*eIterator)->getClassCName() != "Projectile") && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 300) |
---|
[10073] | 163 | { |
---|
| 164 | pj = this->getProjectile(); |
---|
| 165 | if (pj == NULL) |
---|
| 166 | return; |
---|
[10366] | 167 | |
---|
[10107] | 168 | fired = true; |
---|
[10079] | 169 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*115.0 + VECTOR_RAND(10))); |
---|
| 170 | |
---|
| 171 | pj->setParent(PNode::getNullParent()); |
---|
| 172 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 173 | pj->setAbsDir(this->getAbsDir()); |
---|
[10080] | 174 | dynamic_cast<SwarmProjectile*>(pj)->setTarget( (PNode*)(*eIterator) ); |
---|
[10079] | 175 | pj->activate(); |
---|
[10073] | 176 | } |
---|
| 177 | } |
---|
[10107] | 178 | if( !fired) |
---|
| 179 | this->increaseEnergy( this->getProjectile()->getMinEnergy()); |
---|
[10023] | 180 | } |
---|