[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 | |
---|
[5355] | 27 | #include "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(); |
---|
[4597] | 43 | |
---|
[5559] | 44 | this->loadModel("models/guns/turret2.obj"); |
---|
[3752] | 45 | |
---|
[4973] | 46 | |
---|
| 47 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
[5819] | 48 | this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav"); |
---|
[4973] | 49 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[5527] | 53 | AimingTurret::AimingTurret(const TiXmlElement* root) |
---|
[4973] | 54 | { |
---|
| 55 | this->init(); |
---|
| 56 | this->loadParams(root); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * standard deconstructor |
---|
| 61 | */ |
---|
[5527] | 62 | AimingTurret::~AimingTurret () |
---|
[4973] | 63 | { |
---|
| 64 | // model will be deleted from WorldEntity-destructor |
---|
[5574] | 65 | // delete this->target; |
---|
[4973] | 66 | } |
---|
| 67 | |
---|
[5527] | 68 | void AimingTurret::init() |
---|
[4973] | 69 | { |
---|
[5527] | 70 | this->setClassID(CL_AIMING_TURRET, "AimingTurret"); |
---|
[4973] | 71 | |
---|
[4964] | 72 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 73 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3755] | 74 | |
---|
[4964] | 75 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 76 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 77 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 78 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 79 | |
---|
[4893] | 80 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 81 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
[3888] | 82 | |
---|
[6760] | 83 | this->setStateDuration(WS_SHOOTING, .9); |
---|
[5064] | 84 | this->setStateDuration(WS_RELOADING, .1); |
---|
[4910] | 85 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 86 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 87 | |
---|
[6671] | 88 | this->setEnergyMax(10000); |
---|
[5064] | 89 | this->increaseEnergy(100000); |
---|
[4885] | 90 | |
---|
[5441] | 91 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
[6426] | 92 | this->setProjectileType(CL_ROCKET); |
---|
[4964] | 93 | |
---|
[4973] | 94 | |
---|
[4964] | 95 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[4948] | 96 | //this->getProjectileFactory()->prepare(100); |
---|
[5527] | 97 | |
---|
[5567] | 98 | this->target = new Aim(this); |
---|
[5560] | 99 | this->target->setVisibility(false); |
---|
[6760] | 100 | this->target->setRange(400); |
---|
| 101 | this->target->setAngle(M_PI_2); |
---|
[3683] | 102 | } |
---|
[3618] | 103 | |
---|
[5527] | 104 | void AimingTurret::loadParams(const TiXmlElement* root) |
---|
[4973] | 105 | { |
---|
[6512] | 106 | Weapon::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 | { |
---|
[6738] | 122 | if (!Weapon::tickW(dt)) |
---|
| 123 | return; |
---|
[5001] | 124 | Quaternion quat; |
---|
[5527] | 125 | Vector direction = this->target->getAbsCoor() - this->getAbsCoor(); |
---|
[5001] | 126 | |
---|
[4964] | 127 | direction.normalize(); |
---|
[5001] | 128 | |
---|
[4969] | 129 | if (likely (this->getParent() != NULL)) |
---|
[5001] | 130 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
[4969] | 131 | else |
---|
[5001] | 132 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 133 | |
---|
[5559] | 134 | this->setAbsDirSoft(quat, 5); |
---|
| 135 | |
---|
| 136 | this->target->tick(dt); |
---|
[4964] | 137 | } |
---|
| 138 | |
---|
[5527] | 139 | void AimingTurret::fire() |
---|
[3620] | 140 | { |
---|
[5356] | 141 | Projectile* pj = this->getProjectile(); |
---|
| 142 | if (pj == NULL) |
---|
| 143 | return; |
---|
[3888] | 144 | |
---|
[5915] | 145 | pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13) |
---|
[5440] | 146 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
[4955] | 147 | |
---|
[6074] | 148 | pj->setParent(PNode::getNullParent()); |
---|
[4927] | 149 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 150 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 151 | pj->activate(); |
---|
[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 | |
---|