[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 | |
---|
[4973] | 47 | } |
---|
| 48 | |
---|
[5750] | 49 | /** |
---|
| 50 | * creates a new Turret from a TiXmlElement |
---|
| 51 | */ |
---|
[4973] | 52 | Turret::Turret(const TiXmlElement* root) |
---|
| 53 | { |
---|
| 54 | this->init(); |
---|
[6547] | 55 | if (root != NULL) |
---|
| 56 | this->loadParams(root); |
---|
[4973] | 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * standard deconstructor |
---|
| 61 | */ |
---|
| 62 | Turret::~Turret () |
---|
| 63 | { |
---|
| 64 | // model will be deleted from WorldEntity-destructor |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void Turret::init() |
---|
| 68 | { |
---|
| 69 | this->setClassID(CL_TURRET, "Turret"); |
---|
| 70 | |
---|
[5819] | 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 | |
---|
[5064] | 83 | this->setStateDuration(WS_SHOOTING, .1); |
---|
[6306] | 84 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
[4910] | 85 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 86 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 87 | |
---|
[6306] | 88 | this->setMaximumEnergy(100, 5); |
---|
| 89 | this->increaseEnergy(100); |
---|
[4927] | 90 | //this->minCharge = 2; |
---|
[4885] | 91 | |
---|
[5441] | 92 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
[5456] | 93 | this->setProjectileType(CL_ROCKET); |
---|
[4964] | 94 | |
---|
[6561] | 95 | this->loadModel("models/guns/turret1.obj"); |
---|
[4973] | 96 | |
---|
[4964] | 97 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[4948] | 98 | //this->getProjectileFactory()->prepare(100); |
---|
[6589] | 99 | this->loadModel("models/guns/turret1.obj"); |
---|
| 100 | |
---|
[3683] | 101 | } |
---|
[3618] | 102 | |
---|
[4973] | 103 | void Turret::loadParams(const TiXmlElement* root) |
---|
| 104 | { |
---|
[6512] | 105 | Weapon::loadParams(root); |
---|
[3618] | 106 | } |
---|
| 107 | |
---|
[4963] | 108 | void Turret::activate() |
---|
[3980] | 109 | { |
---|
| 110 | } |
---|
[3618] | 111 | |
---|
[4963] | 112 | void Turret::deactivate() |
---|
[3980] | 113 | { |
---|
| 114 | } |
---|
[3618] | 115 | |
---|
[4964] | 116 | void Turret::tick(float dt) |
---|
| 117 | { |
---|
[6565] | 118 | /* |
---|
[5001] | 119 | Quaternion quat; |
---|
[6565] | 120 | Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
[5001] | 121 | |
---|
[4964] | 122 | direction.normalize(); |
---|
[5001] | 123 | |
---|
[4969] | 124 | if (likely (this->getParent() != NULL)) |
---|
[5001] | 125 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
[4969] | 126 | else |
---|
[5001] | 127 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 128 | |
---|
[6565] | 129 | this->setAbsDirSoft(quat, 5);*/ |
---|
[4964] | 130 | } |
---|
| 131 | |
---|
[4963] | 132 | void Turret::fire() |
---|
[3620] | 133 | { |
---|
[5356] | 134 | Projectile* pj = this->getProjectile(); |
---|
| 135 | if (pj == NULL) |
---|
| 136 | return; |
---|
[3888] | 137 | |
---|
[5819] | 138 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */ |
---|
[5440] | 139 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
[4955] | 140 | |
---|
[5819] | 141 | |
---|
[6074] | 142 | pj->setParent(PNode::getNullParent()); |
---|
[4927] | 143 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 144 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 145 | pj->activate(); |
---|
[3620] | 146 | } |
---|
[3618] | 147 | |
---|
[4963] | 148 | void Turret::destroy () |
---|
[3618] | 149 | {} |
---|