[6255] | 1 | /* |
---|
| 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 |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: |
---|
| 14 | */ |
---|
| 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 16 | |
---|
| 17 | #include "targeting_turret.h" |
---|
| 18 | |
---|
| 19 | #include "weapon_manager.h" |
---|
| 20 | #include "aim.h" |
---|
[6434] | 21 | #include "world_entities/projectiles/projectile.h" |
---|
[6255] | 22 | |
---|
| 23 | #include "model.h" |
---|
| 24 | |
---|
| 25 | #include "animation3d.h" |
---|
| 26 | |
---|
[7193] | 27 | #include "util/loading/factory.h" |
---|
[6255] | 28 | |
---|
| 29 | CREATE_FACTORY(TargetingTurret, CL_TARGETING_TURRET); |
---|
| 30 | |
---|
| 31 | using namespace std; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * standard constructor |
---|
| 36 | |
---|
| 37 | creates a new weapon |
---|
| 38 | */ |
---|
| 39 | TargetingTurret::TargetingTurret () |
---|
| 40 | : Weapon() |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
| 43 | |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | TargetingTurret::TargetingTurret(const TiXmlElement* root) |
---|
| 48 | { |
---|
| 49 | this->init(); |
---|
[6695] | 50 | if( root != NULL) |
---|
| 51 | this->loadParams(root); |
---|
[6255] | 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * standard deconstructor |
---|
| 56 | */ |
---|
| 57 | TargetingTurret::~TargetingTurret () |
---|
| 58 | { |
---|
| 59 | // model will be deleted from WorldEntity-destructor |
---|
| 60 | // delete this->target; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void TargetingTurret::init() |
---|
| 64 | { |
---|
| 65 | this->setClassID(CL_TARGETING_TURRET, "TargetingTurret"); |
---|
| 66 | |
---|
| 67 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 68 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 69 | |
---|
| 70 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 71 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 72 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 73 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 74 | |
---|
| 75 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 76 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 77 | |
---|
[7072] | 78 | this->setStateDuration(WS_SHOOTING, .5); |
---|
| 79 | this->setStateDuration(WS_RELOADING, 1.0); |
---|
[6255] | 80 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 81 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 82 | |
---|
[7072] | 83 | this->setEnergyMax(100); |
---|
| 84 | this->increaseEnergy(100); |
---|
[6255] | 85 | |
---|
| 86 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
| 87 | this->setProjectileType(CL_GUIDED_MISSILE); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
| 91 | //this->getProjectileFactory()->prepare(100); |
---|
| 92 | |
---|
| 93 | this->target = new Aim(this); |
---|
| 94 | this->target->setVisibility(false); |
---|
[6760] | 95 | this->target->setRange(1000); |
---|
| 96 | this->target->setAngle(M_PI_4); |
---|
[7070] | 97 | this->lockedTarget = this->target; |
---|
| 98 | |
---|
[6637] | 99 | this->lockedTime = 0; |
---|
| 100 | this->neededLockTime = 2; |
---|
| 101 | this->lockedTarget->setParent(PNode::getNullParent()); |
---|
[6255] | 102 | this->loadModel("models/guns/turret2.obj"); |
---|
| 103 | |
---|
| 104 | |
---|
[7070] | 105 | this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav"); |
---|
[6255] | 106 | this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav"); |
---|
| 107 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void TargetingTurret::loadParams(const TiXmlElement* root) |
---|
| 111 | { |
---|
[6512] | 112 | Weapon::loadParams(root); |
---|
[6255] | 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void TargetingTurret::activate() |
---|
| 117 | { |
---|
[7081] | 118 | // TODO move this back in |
---|
| 119 | //this->target->setVisibility(true); |
---|
[6255] | 120 | } |
---|
| 121 | |
---|
| 122 | void TargetingTurret::deactivate() |
---|
| 123 | { |
---|
| 124 | this->target->setVisibility(false); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | void TargetingTurret::tick(float dt) |
---|
| 128 | { |
---|
[6738] | 129 | if (!Weapon::tickW(dt)) |
---|
| 130 | return; |
---|
| 131 | |
---|
[6637] | 132 | if( lockedTime >= neededLockTime ) |
---|
| 133 | { |
---|
| 134 | lockedTarget = this->target->getParent(); |
---|
| 135 | lockedTime = 0; |
---|
| 136 | } |
---|
[6434] | 137 | |
---|
[6255] | 138 | this->target->tick(dt); |
---|
[6637] | 139 | |
---|
| 140 | if(this->target->getParent() == PNode::getNullParent()) |
---|
| 141 | lockedTime = 0; |
---|
| 142 | else |
---|
| 143 | lockedTime += dt; |
---|
| 144 | |
---|
[6255] | 145 | } |
---|
| 146 | |
---|
| 147 | void TargetingTurret::fire() |
---|
| 148 | { |
---|
| 149 | Projectile* pj = this->getProjectile(); |
---|
| 150 | if (pj == NULL) |
---|
| 151 | return; |
---|
| 152 | |
---|
| 153 | pj->setVelocity(this->getVelocity() + /*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13) |
---|
| 154 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
| 155 | |
---|
[6724] | 156 | pj->setTarget(lockedTarget); |
---|
[6255] | 157 | pj->setParent(PNode::getNullParent()); |
---|
| 158 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 159 | pj->setAbsDir(this->getAbsDir()); |
---|
| 160 | pj->activate(); |
---|
[6738] | 161 | |
---|
[6255] | 162 | } |
---|
| 163 | |
---|
| 164 | void TargetingTurret::destroy () |
---|
| 165 | {} |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * draws the TargetingTurret |
---|
| 169 | */ |
---|
| 170 | void TargetingTurret::draw () const |
---|
| 171 | { |
---|
| 172 | /* draw gun body */ |
---|
| 173 | glMatrixMode(GL_MODELVIEW); |
---|
| 174 | glPushMatrix(); |
---|
| 175 | glTranslatef (this->getAbsCoor ().x, |
---|
| 176 | this->getAbsCoor ().y, |
---|
| 177 | this->getAbsCoor ().z); |
---|
| 178 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 179 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 180 | if (this->getModel() != NULL) |
---|
| 181 | this->getModel()->draw(); |
---|
| 182 | glPopMatrix(); |
---|
| 183 | } |
---|
| 184 | |
---|