[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 | |
---|
| 27 | #include "factory.h" |
---|
| 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(); |
---|
| 50 | this->loadParams(root); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * standard deconstructor |
---|
| 55 | */ |
---|
| 56 | TargetingTurret::~TargetingTurret () |
---|
| 57 | { |
---|
| 58 | // model will be deleted from WorldEntity-destructor |
---|
| 59 | // delete this->target; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void TargetingTurret::init() |
---|
| 63 | { |
---|
| 64 | this->setClassID(CL_TARGETING_TURRET, "TargetingTurret"); |
---|
| 65 | |
---|
| 66 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 67 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 68 | |
---|
| 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 | |
---|
| 74 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 75 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 76 | |
---|
| 77 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 78 | this->setStateDuration(WS_RELOADING, .1); |
---|
| 79 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 80 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 81 | |
---|
[6671] | 82 | this->setEnergyMax(10000); |
---|
[6255] | 83 | this->increaseEnergy(100000); |
---|
| 84 | |
---|
| 85 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
| 86 | this->setProjectileType(CL_GUIDED_MISSILE); |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
| 90 | //this->getProjectileFactory()->prepare(100); |
---|
| 91 | |
---|
| 92 | this->target = new Aim(this); |
---|
| 93 | this->target->setVisibility(false); |
---|
[6637] | 94 | this->target->setRange(100); |
---|
| 95 | this->target->setAngle(M_PI_4/2); |
---|
| 96 | this->lockedTime = 0; |
---|
| 97 | this->neededLockTime = 2; |
---|
| 98 | this->lockedTarget->setParent(PNode::getNullParent()); |
---|
[6255] | 99 | this->loadModel("models/guns/turret2.obj"); |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
| 103 | this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav"); |
---|
| 104 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void TargetingTurret::loadParams(const TiXmlElement* root) |
---|
| 108 | { |
---|
[6512] | 109 | Weapon::loadParams(root); |
---|
[6255] | 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void TargetingTurret::activate() |
---|
| 114 | { |
---|
| 115 | this->target->setVisibility(true); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void TargetingTurret::deactivate() |
---|
| 119 | { |
---|
| 120 | this->target->setVisibility(false); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void TargetingTurret::tick(float dt) |
---|
| 124 | { |
---|
[6637] | 125 | if( lockedTime >= neededLockTime ) |
---|
| 126 | { |
---|
| 127 | lockedTarget = this->target->getParent(); |
---|
| 128 | lockedTime = 0; |
---|
| 129 | } |
---|
[6434] | 130 | |
---|
[6255] | 131 | this->target->tick(dt); |
---|
[6637] | 132 | |
---|
| 133 | if(this->target->getParent() == PNode::getNullParent()) |
---|
| 134 | lockedTime = 0; |
---|
| 135 | else |
---|
| 136 | lockedTime += dt; |
---|
| 137 | |
---|
[6255] | 138 | } |
---|
| 139 | |
---|
| 140 | void TargetingTurret::fire() |
---|
| 141 | { |
---|
| 142 | Projectile* pj = this->getProjectile(); |
---|
| 143 | if (pj == NULL) |
---|
| 144 | return; |
---|
| 145 | |
---|
| 146 | pj->setVelocity(this->getVelocity() + /*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13) |
---|
| 147 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
| 148 | |
---|
| 149 | pj->setTarget(this->target->getParent()); |
---|
| 150 | pj->setParent(PNode::getNullParent()); |
---|
| 151 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 152 | pj->setAbsDir(this->getAbsDir()); |
---|
| 153 | pj->activate(); |
---|
[6637] | 154 | this->target->searchTarget(); |
---|
[6255] | 155 | } |
---|
| 156 | |
---|
| 157 | void TargetingTurret::destroy () |
---|
| 158 | {} |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * draws the TargetingTurret |
---|
| 162 | */ |
---|
| 163 | void TargetingTurret::draw () const |
---|
| 164 | { |
---|
| 165 | /* draw gun body */ |
---|
| 166 | glMatrixMode(GL_MODELVIEW); |
---|
| 167 | glPushMatrix(); |
---|
| 168 | glTranslatef (this->getAbsCoor ().x, |
---|
| 169 | this->getAbsCoor ().y, |
---|
| 170 | this->getAbsCoor ().z); |
---|
| 171 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 172 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 173 | if (this->getModel() != NULL) |
---|
| 174 | this->getModel()->draw(); |
---|
| 175 | glPopMatrix(); |
---|
| 176 | } |
---|
| 177 | |
---|