[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 | |
---|
[4963] | 17 | #include "turret.h" |
---|
[3618] | 18 | |
---|
[4963] | 19 | #include "weapon_manager.h" |
---|
[6434] | 20 | #include "world_entities/projectiles/projectile.h" |
---|
[3618] | 21 | |
---|
[5511] | 22 | #include "model.h" |
---|
| 23 | |
---|
[4829] | 24 | #include "state.h" |
---|
[3851] | 25 | #include "animation3d.h" |
---|
[3618] | 26 | |
---|
[5355] | 27 | #include "factory.h" |
---|
[4287] | 28 | |
---|
[5750] | 29 | CREATE_FACTORY(Turret, CL_TURRET); |
---|
[4931] | 30 | |
---|
[3618] | 31 | using namespace std; |
---|
| 32 | |
---|
| 33 | /** |
---|
[4836] | 34 | * standard constructor |
---|
[5750] | 35 | * |
---|
| 36 | * creates a new Turret |
---|
| 37 | */ |
---|
| 38 | Turret::Turret () |
---|
| 39 | : Weapon() |
---|
[3683] | 40 | { |
---|
[4973] | 41 | this->init(); |
---|
[4597] | 42 | |
---|
[4973] | 43 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
| 44 | this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav"); |
---|
| 45 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
[5819] | 46 | |
---|
| 47 | this->loadModel("models/guns/turret1.obj"); |
---|
[4973] | 48 | } |
---|
| 49 | |
---|
[5750] | 50 | /** |
---|
| 51 | * creates a new Turret from a TiXmlElement |
---|
| 52 | */ |
---|
[4973] | 53 | Turret::Turret(const TiXmlElement* root) |
---|
| 54 | { |
---|
| 55 | this->init(); |
---|
[6547] | 56 | if (root != NULL) |
---|
| 57 | this->loadParams(root); |
---|
[4973] | 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * standard deconstructor |
---|
| 62 | */ |
---|
| 63 | Turret::~Turret () |
---|
| 64 | { |
---|
| 65 | // model will be deleted from WorldEntity-destructor |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void Turret::init() |
---|
| 69 | { |
---|
| 70 | this->setClassID(CL_TURRET, "Turret"); |
---|
| 71 | |
---|
[5819] | 72 | |
---|
[4964] | 73 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 74 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3755] | 75 | |
---|
[4964] | 76 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 77 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 78 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 79 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 80 | |
---|
[4893] | 81 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 82 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
[3888] | 83 | |
---|
[5064] | 84 | this->setStateDuration(WS_SHOOTING, .1); |
---|
[6306] | 85 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
[4910] | 86 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 87 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 88 | |
---|
[6306] | 89 | this->setMaximumEnergy(100, 5); |
---|
| 90 | this->increaseEnergy(100); |
---|
[4927] | 91 | //this->minCharge = 2; |
---|
[4885] | 92 | |
---|
[5441] | 93 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
[5456] | 94 | this->setProjectileType(CL_ROCKET); |
---|
[4964] | 95 | |
---|
[4973] | 96 | |
---|
[4964] | 97 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[4948] | 98 | //this->getProjectileFactory()->prepare(100); |
---|
[3683] | 99 | } |
---|
[3618] | 100 | |
---|
[4973] | 101 | void Turret::loadParams(const TiXmlElement* root) |
---|
| 102 | { |
---|
[6512] | 103 | Weapon::loadParams(root); |
---|
[3618] | 104 | |
---|
| 105 | } |
---|
| 106 | |
---|
[4963] | 107 | void Turret::activate() |
---|
[3980] | 108 | { |
---|
| 109 | } |
---|
[3618] | 110 | |
---|
[4963] | 111 | void Turret::deactivate() |
---|
[3980] | 112 | { |
---|
| 113 | } |
---|
[3618] | 114 | |
---|
[4964] | 115 | void Turret::tick(float dt) |
---|
| 116 | { |
---|
[5001] | 117 | Quaternion quat; |
---|
[5750] | 118 | Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();*/ |
---|
[5001] | 119 | |
---|
[4964] | 120 | direction.normalize(); |
---|
[5001] | 121 | |
---|
[4969] | 122 | if (likely (this->getParent() != NULL)) |
---|
[5001] | 123 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
[4969] | 124 | else |
---|
[5001] | 125 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 126 | |
---|
[5414] | 127 | this->setAbsDirSoft(quat, 5); |
---|
[4964] | 128 | } |
---|
| 129 | |
---|
[4963] | 130 | void Turret::fire() |
---|
[3620] | 131 | { |
---|
[5356] | 132 | Projectile* pj = this->getProjectile(); |
---|
| 133 | if (pj == NULL) |
---|
| 134 | return; |
---|
[3888] | 135 | |
---|
[5819] | 136 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */ |
---|
[5440] | 137 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
[4955] | 138 | |
---|
[5819] | 139 | |
---|
[6074] | 140 | pj->setParent(PNode::getNullParent()); |
---|
[4927] | 141 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 142 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 143 | pj->activate(); |
---|
[3620] | 144 | } |
---|
[3618] | 145 | |
---|
[4963] | 146 | void Turret::destroy () |
---|
[3618] | 147 | {} |
---|