[10179] | 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: Marc Schaerrer |
---|
| 13 | co-programmer: |
---|
| 14 | */ |
---|
| 15 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 16 | |
---|
| 17 | #include "acid_launcher.h" |
---|
| 18 | |
---|
| 19 | #include "weapon_manager.h" |
---|
| 20 | #include "world_entities/projectiles/acid_splash.h" |
---|
| 21 | |
---|
| 22 | #include "model.h" |
---|
| 23 | |
---|
| 24 | #include "state.h" |
---|
| 25 | #include "animation3d.h" |
---|
| 26 | |
---|
| 27 | #include <list> |
---|
| 28 | #include <iterator> |
---|
| 29 | #include "util/state.h" |
---|
| 30 | |
---|
| 31 | #include "util/loading/factory.h" |
---|
| 32 | |
---|
[10516] | 33 | #include "elements/glgui_energywidgetvertical.h" |
---|
[10179] | 34 | |
---|
[10366] | 35 | |
---|
[10516] | 36 | |
---|
[10179] | 37 | using namespace std; |
---|
| 38 | |
---|
[10600] | 39 | ObjectListDefinition ( AcidLauncher ); |
---|
| 40 | CREATE_FACTORY ( AcidLauncher ); |
---|
[10179] | 41 | |
---|
| 42 | /** |
---|
| 43 | * standard constructor |
---|
| 44 | * |
---|
| 45 | * creates a new AcidLauncher |
---|
| 46 | */ |
---|
| 47 | AcidLauncher::AcidLauncher() |
---|
[10600] | 48 | : Weapon() |
---|
[10179] | 49 | { |
---|
| 50 | this->init(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * creates a new AcidLauncher from a TiXmlElement |
---|
| 55 | */ |
---|
[10600] | 56 | AcidLauncher::AcidLauncher ( const TiXmlElement* root ) |
---|
[10179] | 57 | { |
---|
| 58 | this->init(); |
---|
[10600] | 59 | if ( root != NULL ) |
---|
| 60 | this->loadParams ( root ); |
---|
[10179] | 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * standard deconstructor |
---|
| 65 | */ |
---|
| 66 | AcidLauncher::~AcidLauncher () |
---|
| 67 | { |
---|
| 68 | // model will be deleted from WorldEntity-destructor |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void AcidLauncher::init() |
---|
| 72 | { |
---|
[10600] | 73 | this->registerObject ( this, AcidLauncher::_objectList ); |
---|
| 74 | /* |
---|
| 75 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 76 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[10179] | 77 | |
---|
[10600] | 78 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 79 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 80 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 81 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[10179] | 82 | |
---|
[10600] | 83 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 84 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 85 | */ |
---|
| 86 | this->setStateDuration ( WS_SHOOTING, 1.0f ); |
---|
[10345] | 87 | |
---|
[10600] | 88 | this->setStateDuration ( WS_RELOADING, 1.0f ); |
---|
| 89 | this->setStateDuration ( WS_ACTIVATING, .4 ); |
---|
| 90 | this->setStateDuration ( WS_DEACTIVATING, .4 ); |
---|
[10179] | 91 | |
---|
[10600] | 92 | this->setEnergyMax ( 100 ); |
---|
| 93 | this->increaseEnergy ( 100 ); |
---|
[10179] | 94 | //this->minCharge = 2; |
---|
| 95 | |
---|
[10600] | 96 | this->setCapability ( WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT ); |
---|
| 97 | this->setProjectileTypeC ( "AcidSplash" ); |
---|
[10333] | 98 | // this->loadModel("models/guns/turret1.obj", 1.0); |
---|
[10179] | 99 | |
---|
[10600] | 100 | this->setEmissionPoint ( 2.0, 0, 0 ); |
---|
| 101 | this->getProjectileFactory()->prepare ( 10 ); |
---|
[10179] | 102 | |
---|
[10600] | 103 | this->setActionSound ( WA_SHOOT, "sounds/explosions/explosion_1.wav" ); |
---|
| 104 | this->setActionSound ( WA_ACTIVATE, "sounds/voices/rockets.wav" ); |
---|
[10579] | 105 | // this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav"); |
---|
[10179] | 106 | |
---|
| 107 | } |
---|
| 108 | |
---|
[10600] | 109 | void AcidLauncher::loadParams ( const TiXmlElement* root ) |
---|
[10179] | 110 | { |
---|
[10600] | 111 | Weapon::loadParams ( root ); |
---|
[10179] | 112 | } |
---|
| 113 | |
---|
| 114 | void AcidLauncher::activate() |
---|
[10600] | 115 | {} |
---|
[10179] | 116 | |
---|
| 117 | void AcidLauncher::deactivate() |
---|
[10600] | 118 | {} |
---|
[10179] | 119 | |
---|
[10600] | 120 | void AcidLauncher::tick ( float dt ) |
---|
[10179] | 121 | { |
---|
[10600] | 122 | if ( !Weapon::tickW ( dt ) ) |
---|
[10539] | 123 | return; |
---|
[10600] | 124 | if ( this->energyWidget != NULL && !this->isEnergyWidgetInitialized ) { |
---|
| 125 | this->energyWidget->setDisplayedImage ( "textures/gui/gui_acid.png" ); |
---|
[10516] | 126 | this->isEnergyWidgetInitialized = true; |
---|
| 127 | } |
---|
| 128 | |
---|
[10539] | 129 | |
---|
[10179] | 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); |
---|
| 146 | */ |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | void AcidLauncher::fire() |
---|
| 150 | { |
---|
| 151 | bool fired = false; |
---|
| 152 | |
---|
| 153 | Projectile* pj = NULL; |
---|
[10600] | 154 | for ( int i=0; i < 1; i++ ) { |
---|
| 155 | pj = this->getProjectile(); |
---|
| 156 | if ( pj == NULL ) |
---|
| 157 | return; |
---|
[10179] | 158 | |
---|
[10600] | 159 | fired = true; |
---|
| 160 | pj->setVelocity ( this->getVelocity() + ( this->getAbsDir().apply ( Vector ( 1,0,0 ) ) *165.0 + VECTOR_RAND ( 10 ) ) ); |
---|
[10179] | 161 | |
---|
[10600] | 162 | pj->setParent ( PNode::getNullParent() ); |
---|
| 163 | pj->setAbsCoor ( this->getEmissionPoint() + VECTOR_RAND ( .1 ) ); |
---|
| 164 | pj->setAbsDir ( this->getAbsDir() +Quaternion ( 0,VECTOR_RAND ( 5 ) ) ); |
---|
| 165 | pj->activate(); |
---|
[10179] | 166 | } |
---|
| 167 | } |
---|