[4592] | 1 | /* |
---|
[3618] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 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 |
---|
[4963] | 12 | main-programmer: Benjamin Grauer |
---|
[4592] | 13 | co-programmer: |
---|
[3618] | 14 | */ |
---|
[5357] | 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3618] | 16 | |
---|
[5527] | 17 | #include "aiming_turret.h" |
---|
[3618] | 18 | |
---|
[4963] | 19 | #include "weapon_manager.h" |
---|
[5559] | 20 | #include "aim.h" |
---|
[5511] | 21 | #include "projectile.h" |
---|
[3618] | 22 | |
---|
[5511] | 23 | #include "model.h" |
---|
| 24 | |
---|
[5002] | 25 | #include "null_parent.h" |
---|
[5574] | 26 | |
---|
[3851] | 27 | #include "animation3d.h" |
---|
[3618] | 28 | |
---|
[5355] | 29 | #include "factory.h" |
---|
[4287] | 30 | |
---|
[5622] | 31 | CREATE_FACTORY(AimingTurret, CL_AIMING_TURRET); |
---|
[4931] | 32 | |
---|
[3618] | 33 | using namespace std; |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /** |
---|
[4836] | 37 | * standard constructor |
---|
[3618] | 38 | |
---|
| 39 | creates a new weapon |
---|
| 40 | */ |
---|
[5745] | 41 | AimingTurret::AimingTurret () |
---|
| 42 | : Weapon() |
---|
[3683] | 43 | { |
---|
[4973] | 44 | this->init(); |
---|
[4597] | 45 | |
---|
[5559] | 46 | this->loadModel("models/guns/turret2.obj"); |
---|
[3752] | 47 | |
---|
[4973] | 48 | |
---|
| 49 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
[5819] | 50 | this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav"); |
---|
[4973] | 51 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
[5527] | 55 | AimingTurret::AimingTurret(const TiXmlElement* root) |
---|
[4973] | 56 | { |
---|
| 57 | this->init(); |
---|
| 58 | this->loadParams(root); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * standard deconstructor |
---|
| 63 | */ |
---|
[5527] | 64 | AimingTurret::~AimingTurret () |
---|
[4973] | 65 | { |
---|
| 66 | // model will be deleted from WorldEntity-destructor |
---|
[5574] | 67 | // delete this->target; |
---|
[4973] | 68 | } |
---|
| 69 | |
---|
[5527] | 70 | void AimingTurret::init() |
---|
[4973] | 71 | { |
---|
[5527] | 72 | this->setClassID(CL_AIMING_TURRET, "AimingTurret"); |
---|
[4973] | 73 | |
---|
[4964] | 74 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 75 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3755] | 76 | |
---|
[4964] | 77 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 78 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 79 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 80 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 81 | |
---|
[4893] | 82 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 83 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
[3888] | 84 | |
---|
[5064] | 85 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 86 | this->setStateDuration(WS_RELOADING, .1); |
---|
[4910] | 87 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 88 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 89 | |
---|
[5064] | 90 | this->setMaximumEnergy(10000, 50); |
---|
| 91 | this->increaseEnergy(100000); |
---|
[4885] | 92 | |
---|
[5441] | 93 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
[5915] | 94 | this->setProjectileType(CL_GUIDED_MISSILE); |
---|
[4964] | 95 | |
---|
[4973] | 96 | |
---|
[4964] | 97 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[4948] | 98 | //this->getProjectileFactory()->prepare(100); |
---|
[5527] | 99 | |
---|
[5567] | 100 | this->target = new Aim(this); |
---|
[5560] | 101 | this->target->setVisibility(false); |
---|
[3683] | 102 | } |
---|
[3618] | 103 | |
---|
[5527] | 104 | void AimingTurret::loadParams(const TiXmlElement* root) |
---|
[4973] | 105 | { |
---|
| 106 | static_cast<Weapon*>(this)->loadParams(root); |
---|
[3618] | 107 | |
---|
| 108 | } |
---|
| 109 | |
---|
[5527] | 110 | void AimingTurret::activate() |
---|
[3980] | 111 | { |
---|
[5560] | 112 | this->target->setVisibility(true); |
---|
[3980] | 113 | } |
---|
[3618] | 114 | |
---|
[5527] | 115 | void AimingTurret::deactivate() |
---|
[3980] | 116 | { |
---|
[5560] | 117 | this->target->setVisibility(false); |
---|
[3980] | 118 | } |
---|
[3618] | 119 | |
---|
[5527] | 120 | void AimingTurret::tick(float dt) |
---|
[4964] | 121 | { |
---|
[5001] | 122 | Quaternion quat; |
---|
[5527] | 123 | Vector direction = this->target->getAbsCoor() - this->getAbsCoor(); |
---|
[5001] | 124 | |
---|
[4964] | 125 | direction.normalize(); |
---|
[5001] | 126 | |
---|
[4969] | 127 | if (likely (this->getParent() != NULL)) |
---|
[5001] | 128 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
[4969] | 129 | else |
---|
[5001] | 130 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 131 | |
---|
[5559] | 132 | this->setAbsDirSoft(quat, 5); |
---|
| 133 | |
---|
| 134 | this->target->tick(dt); |
---|
[4964] | 135 | } |
---|
| 136 | |
---|
[5527] | 137 | void AimingTurret::fire() |
---|
[3620] | 138 | { |
---|
[5356] | 139 | Projectile* pj = this->getProjectile(); |
---|
| 140 | if (pj == NULL) |
---|
| 141 | return; |
---|
[3888] | 142 | |
---|
[5915] | 143 | pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13) |
---|
[5440] | 144 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
[4955] | 145 | |
---|
[5915] | 146 | pj->setTarget(this->target->getParent()); |
---|
[5002] | 147 | pj->setParent(NullParent::getInstance()); |
---|
[4927] | 148 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 149 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 150 | pj->activate(); |
---|
[5576] | 151 | this->target->searchTarget(100); |
---|
[3620] | 152 | } |
---|
[3618] | 153 | |
---|
[5527] | 154 | void AimingTurret::destroy () |
---|
[3618] | 155 | {} |
---|
| 156 | |
---|
| 157 | /** |
---|
[5527] | 158 | * draws the AimingTurret |
---|
[3618] | 159 | */ |
---|
[5527] | 160 | void AimingTurret::draw () const |
---|
[3750] | 161 | { |
---|
[3886] | 162 | /* draw gun body */ |
---|
[3750] | 163 | glMatrixMode(GL_MODELVIEW); |
---|
| 164 | glPushMatrix(); |
---|
[4592] | 165 | glTranslatef (this->getAbsCoor ().x, |
---|
| 166 | this->getAbsCoor ().y, |
---|
| 167 | this->getAbsCoor ().z); |
---|
[5000] | 168 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 169 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[3752] | 170 | |
---|
[5994] | 171 | this->getModel()->draw(); |
---|
[3750] | 172 | glPopMatrix(); |
---|
| 173 | } |
---|
[3618] | 174 | |
---|