| 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 "turret.h" |
|---|
| 18 | |
|---|
| 19 | #include "weapon_manager.h" |
|---|
| 20 | #include "projectile.h" |
|---|
| 21 | |
|---|
| 22 | #include "model.h" |
|---|
| 23 | |
|---|
| 24 | #include "state.h" |
|---|
| 25 | #include "animation3d.h" |
|---|
| 26 | |
|---|
| 27 | #include "factory.h" |
|---|
| 28 | |
|---|
| 29 | CREATE_FACTORY(Turret, CL_TURRET); |
|---|
| 30 | |
|---|
| 31 | using namespace std; |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * standard constructor |
|---|
| 35 | * |
|---|
| 36 | * creates a new Turret |
|---|
| 37 | */ |
|---|
| 38 | Turret::Turret () |
|---|
| 39 | : Weapon() |
|---|
| 40 | { |
|---|
| 41 | this->init(); |
|---|
| 42 | |
|---|
| 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"); |
|---|
| 46 | |
|---|
| 47 | this->loadModel("models/guns/turret1.obj"); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * creates a new Turret from a TiXmlElement |
|---|
| 52 | */ |
|---|
| 53 | Turret::Turret(const TiXmlElement* root) |
|---|
| 54 | { |
|---|
| 55 | this->init(); |
|---|
| 56 | this->loadParams(root); |
|---|
| 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 | |
|---|
| 71 | |
|---|
| 72 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
|---|
| 73 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
|---|
| 74 | |
|---|
| 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 | |
|---|
| 80 | animation1->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 81 | animation2->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 82 | |
|---|
| 83 | this->setStateDuration(WS_SHOOTING, .1); |
|---|
| 84 | this->setStateDuration(WS_RELOADING, .1); |
|---|
| 85 | this->setStateDuration(WS_ACTIVATING, .4); |
|---|
| 86 | this->setStateDuration(WS_DEACTIVATING, .4); |
|---|
| 87 | |
|---|
| 88 | this->setMaximumEnergy(10000, 50); |
|---|
| 89 | this->increaseEnergy(100000); |
|---|
| 90 | //this->minCharge = 2; |
|---|
| 91 | |
|---|
| 92 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
|---|
| 93 | this->setProjectileType(CL_ROCKET); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | this->setEmissionPoint(1.684, 0.472, 0); |
|---|
| 97 | //this->getProjectileFactory()->prepare(100); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void Turret::loadParams(const TiXmlElement* root) |
|---|
| 101 | { |
|---|
| 102 | static_cast<Weapon*>(this)->loadParams(root); |
|---|
| 103 | |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | void Turret::activate() |
|---|
| 107 | { |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | void Turret::deactivate() |
|---|
| 111 | { |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | void Turret::tick(float dt) |
|---|
| 115 | { |
|---|
| 116 | Quaternion quat; |
|---|
| 117 | Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();*/ |
|---|
| 118 | |
|---|
| 119 | direction.normalize(); |
|---|
| 120 | |
|---|
| 121 | if (likely (this->getParent() != NULL)) |
|---|
| 122 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
|---|
| 123 | else |
|---|
| 124 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
|---|
| 125 | |
|---|
| 126 | this->setAbsDirSoft(quat, 5); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | void Turret::fire() |
|---|
| 130 | { |
|---|
| 131 | Projectile* pj = this->getProjectile(); |
|---|
| 132 | if (pj == NULL) |
|---|
| 133 | return; |
|---|
| 134 | |
|---|
| 135 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */ |
|---|
| 136 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | pj->setParent(PNode::getNullParent()); |
|---|
| 140 | pj->setAbsCoor(this->getEmissionPoint()); |
|---|
| 141 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 142 | pj->activate(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | void Turret::destroy () |
|---|
| 146 | {} |
|---|