| 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 | |
|---|
| 16 | |
|---|
| 17 | #include "turret.h" |
|---|
| 18 | |
|---|
| 19 | #include "weapon_manager.h" |
|---|
| 20 | #include "test_bullet.h" |
|---|
| 21 | |
|---|
| 22 | #include "state.h" |
|---|
| 23 | #include "vector.h" |
|---|
| 24 | #include "list.h" |
|---|
| 25 | #include "animation3d.h" |
|---|
| 26 | #include "sound_engine.h" |
|---|
| 27 | |
|---|
| 28 | #include "fast_factory.h" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | using namespace std; |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * standard constructor |
|---|
| 36 | |
|---|
| 37 | creates a new weapon |
|---|
| 38 | */ |
|---|
| 39 | Turret::Turret (WeaponManager* weaponManager) |
|---|
| 40 | : Weapon(weaponManager) |
|---|
| 41 | { |
|---|
| 42 | this->setClassID(CL_TURRET, "Turret"); |
|---|
| 43 | |
|---|
| 44 | this->model = (Model*)ResourceManager::getInstance()->load("models/turret1.obj", OBJ, RP_CAMPAIGN); |
|---|
| 45 | |
|---|
| 46 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
|---|
| 47 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
|---|
| 48 | |
|---|
| 49 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 50 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 51 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 52 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
|---|
| 53 | |
|---|
| 54 | animation1->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 55 | animation2->setInfinity(ANIM_INF_CONSTANT); |
|---|
| 56 | |
|---|
| 57 | this->setStateDuration(WS_SHOOTING, .4); |
|---|
| 58 | this->setStateDuration(WS_RELOADING, 2); |
|---|
| 59 | this->setStateDuration(WS_ACTIVATING, .4); |
|---|
| 60 | this->setStateDuration(WS_DEACTIVATING, .4); |
|---|
| 61 | |
|---|
| 62 | this->setMaximumEnergy(1000, 10); |
|---|
| 63 | this->increaseEnergy(100); |
|---|
| 64 | //this->minCharge = 2; |
|---|
| 65 | |
|---|
| 66 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
|---|
| 67 | |
|---|
| 68 | this->setProjectile(CL_TEST_BULLET); |
|---|
| 69 | |
|---|
| 70 | this->setEmissionPoint(1.684, 0.472, 0); |
|---|
| 71 | //this->getProjectileFactory()->prepare(100); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * standard deconstructor |
|---|
| 77 | */ |
|---|
| 78 | Turret::~Turret () |
|---|
| 79 | { |
|---|
| 80 | // model will be deleted from WorldEntity-destructor |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | void Turret::activate() |
|---|
| 84 | { |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void Turret::deactivate() |
|---|
| 88 | { |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void Turret::tick(float dt) |
|---|
| 92 | { |
|---|
| 93 | Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor(); |
|---|
| 94 | direction.normalize(); |
|---|
| 95 | Quaternion quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
|---|
| 96 | |
|---|
| 97 | this->setAbsDir(quat); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * fires the weapon |
|---|
| 102 | |
|---|
| 103 | this is called from the player.cc, when fire-button is been pushed |
|---|
| 104 | */ |
|---|
| 105 | void Turret::fire() |
|---|
| 106 | { |
|---|
| 107 | Projectile* pj = dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect()); |
|---|
| 108 | |
|---|
| 109 | PNode* target = this->getWeaponManager()->getFixedTarget(); |
|---|
| 110 | |
|---|
| 111 | if (target != NULL) |
|---|
| 112 | { |
|---|
| 113 | pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity()); |
|---|
| 114 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 115 | } |
|---|
| 116 | else |
|---|
| 117 | pj->setVelocity(target->getVelocity()); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | pj->setAbsCoor(this->getEmissionPoint()); |
|---|
| 121 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 122 | State::getWorldEntityList()->add(pj); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * is called, when the weapon is destroyed |
|---|
| 128 | |
|---|
| 129 | this is in conjunction with the hit function, so when a weapon is able to get |
|---|
| 130 | hit, it can also be destoryed. |
|---|
| 131 | */ |
|---|
| 132 | void Turret::destroy () |
|---|
| 133 | {} |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | * this will draw the weapon |
|---|
| 137 | */ |
|---|
| 138 | void Turret::draw () |
|---|
| 139 | { |
|---|
| 140 | this->getWeaponManager()->getFixedTarget()->debugDraw(10); |
|---|
| 141 | |
|---|
| 142 | /* draw gun body */ |
|---|
| 143 | glMatrixMode(GL_MODELVIEW); |
|---|
| 144 | glPushMatrix(); |
|---|
| 145 | float matrix[4][4]; |
|---|
| 146 | glTranslatef (this->getAbsCoor ().x, |
|---|
| 147 | this->getAbsCoor ().y, |
|---|
| 148 | this->getAbsCoor ().z); |
|---|
| 149 | this->getAbsDir ().matrix (matrix); |
|---|
| 150 | glMultMatrixf((float*)matrix); |
|---|
| 151 | |
|---|
| 152 | this->model->draw(); |
|---|
| 153 | glPopMatrix(); |
|---|
| 154 | } |
|---|
| 155 | |
|---|