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