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