[3618] | 1 | |
---|
| 2 | |
---|
[4592] | 3 | /* |
---|
[3618] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[4592] | 15 | co-programmer: |
---|
[3631] | 16 | |
---|
| 17 | |
---|
[4836] | 18 | @todo: direction in which the projectile flights |
---|
| 19 | @todo: a target to set/hit |
---|
[3618] | 20 | */ |
---|
[5357] | 21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3618] | 22 | |
---|
[5621] | 23 | #include "cannon.h" |
---|
[3618] | 24 | |
---|
| 25 | #include "world_entity.h" |
---|
[3677] | 26 | #include "model.h" |
---|
[6434] | 27 | #include "world_entities/projectiles/projectile.h" |
---|
[4955] | 28 | #include "weapon_manager.h" |
---|
[7193] | 29 | #include "util/loading/factory.h" |
---|
[3618] | 30 | |
---|
| 31 | #include "vector.h" |
---|
[3851] | 32 | #include "animation3d.h" |
---|
[3618] | 33 | |
---|
[4940] | 34 | #include "fast_factory.h" |
---|
[4287] | 35 | |
---|
[4931] | 36 | |
---|
[3618] | 37 | |
---|
[9406] | 38 | |
---|
[5622] | 39 | CREATE_FACTORY(Cannon, CL_CANNON); |
---|
[3618] | 40 | |
---|
| 41 | /** |
---|
[4836] | 42 | * standard constructor |
---|
[3618] | 43 | |
---|
| 44 | creates a new weapon |
---|
| 45 | */ |
---|
[5745] | 46 | Cannon::Cannon () |
---|
| 47 | : Weapon() |
---|
[3683] | 48 | { |
---|
[4974] | 49 | this->init(); |
---|
[4972] | 50 | } |
---|
[4885] | 51 | |
---|
| 52 | |
---|
[5621] | 53 | Cannon::Cannon(const TiXmlElement* root) |
---|
[4972] | 54 | { |
---|
| 55 | this->init(); |
---|
[6517] | 56 | if (root != NULL) |
---|
| 57 | this->loadParams(root); |
---|
[4972] | 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * standard deconstructor |
---|
| 62 | */ |
---|
[5621] | 63 | Cannon::~Cannon () |
---|
[4972] | 64 | { |
---|
| 65 | // model will be deleted from WorldEntity-destructor |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
[5621] | 69 | void Cannon::init() |
---|
[4972] | 70 | { |
---|
[5621] | 71 | this->setClassID(CL_CANNON, "Cannon"); |
---|
[4972] | 72 | |
---|
[5053] | 73 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
[4972] | 74 | |
---|
[6811] | 75 | this->loadModel("models/guns/cannon.obj", 1.0); |
---|
[5053] | 76 | |
---|
[5744] | 77 | this->setStateDuration(WS_SHOOTING, 2.0); |
---|
[5457] | 78 | this->setStateDuration(WS_RELOADING, .1); |
---|
[5744] | 79 | this->setStateDuration(WS_ACTIVATING, .1); |
---|
[4910] | 80 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 81 | |
---|
[6671] | 82 | this->setEnergyMax(100); |
---|
[5828] | 83 | this->increaseEnergy(100); |
---|
[4927] | 84 | //this->minCharge = 2; |
---|
[4885] | 85 | |
---|
[5819] | 86 | this->setActionSound(WA_SHOOT, "sound/explo.wav"); |
---|
| 87 | this->setActionSound(WA_ACTIVATE, "sound/voices/cannon.wav"); |
---|
[4934] | 88 | |
---|
[6803] | 89 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_HEAVY); |
---|
[5744] | 90 | this->setProjectileType(CL_BOMB); |
---|
| 91 | this->prepareProjectiles(5); |
---|
[5457] | 92 | |
---|
[5623] | 93 | // this->objectComponent1 = new PNode(); |
---|
| 94 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
| 95 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 96 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 97 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
| 98 | // this->addChild(this->objectComponent1); |
---|
| 99 | |
---|
| 100 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 101 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 102 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 103 | |
---|
| 104 | this->setEmissionPoint(3.8, 1.2, 0); |
---|
| 105 | |
---|
| 106 | // animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 107 | // animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 108 | // animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
| 109 | |
---|
| 110 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 111 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 112 | |
---|
| 113 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 114 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3683] | 115 | } |
---|
[3618] | 116 | |
---|
| 117 | |
---|
[5621] | 118 | void Cannon::loadParams(const TiXmlElement* root) |
---|
[3618] | 119 | { |
---|
[6512] | 120 | Weapon::loadParams(root); |
---|
[3618] | 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /** |
---|
[4836] | 125 | * this activates the weapon |
---|
[3618] | 126 | |
---|
[4592] | 127 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 128 | activation can be connected with an animation. for example the weapon is |
---|
| 129 | been armed out. |
---|
[3618] | 130 | */ |
---|
[5621] | 131 | void Cannon::activate() |
---|
[3980] | 132 | { |
---|
| 133 | } |
---|
[3618] | 134 | |
---|
| 135 | |
---|
| 136 | /** |
---|
[4836] | 137 | * this deactivates the weapon |
---|
[3618] | 138 | |
---|
[4592] | 139 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 140 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 141 | been armed out. |
---|
| 142 | */ |
---|
[5621] | 143 | void Cannon::deactivate() |
---|
[3980] | 144 | { |
---|
| 145 | } |
---|
[3618] | 146 | |
---|
| 147 | |
---|
| 148 | /** |
---|
[4836] | 149 | * fires the weapon |
---|
[4592] | 150 | |
---|
[3618] | 151 | this is called from the player.cc, when fire-button is been pushed |
---|
[4836] | 152 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 153 | */ |
---|
[5621] | 154 | void Cannon::fire() |
---|
[3620] | 155 | { |
---|
[5356] | 156 | Projectile* pj = this->getProjectile(); |
---|
| 157 | if (pj == NULL) |
---|
| 158 | return; |
---|
[3888] | 159 | |
---|
[6074] | 160 | pj->setParent(PNode::getNullParent()); |
---|
[5000] | 161 | |
---|
[5744] | 162 | pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5)); |
---|
[4955] | 163 | |
---|
[4927] | 164 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 165 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 166 | pj->activate(); |
---|
[3620] | 167 | } |
---|
[3618] | 168 | |
---|
| 169 | |
---|
| 170 | /** |
---|
[4836] | 171 | * this will draw the weapon |
---|
[3618] | 172 | */ |
---|
[5621] | 173 | void Cannon::draw () const |
---|
[3750] | 174 | { |
---|
[3886] | 175 | /* draw gun body */ |
---|
[3750] | 176 | glMatrixMode(GL_MODELVIEW); |
---|
| 177 | glPushMatrix(); |
---|
[4592] | 178 | glTranslatef (this->getAbsCoor ().x, |
---|
| 179 | this->getAbsCoor ().y, |
---|
| 180 | this->getAbsCoor ().z); |
---|
[5000] | 181 | |
---|
| 182 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 183 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 184 | |
---|
[5994] | 185 | this->getModel()->draw(); |
---|
[3752] | 186 | glPopMatrix(); |
---|
| 187 | |
---|
[3886] | 188 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
[5621] | 189 | /* glMatrixMode(GL_MODELVIEW); |
---|
[3752] | 190 | glPushMatrix(); |
---|
[4592] | 191 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
| 192 | this->objectComponent1->getAbsCoor ().y, |
---|
| 193 | this->objectComponent1->getAbsCoor ().z); |
---|
[5000] | 194 | tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis(); |
---|
| 195 | glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[3752] | 196 | this->model->draw(0); |
---|
[5621] | 197 | |
---|
| 198 | glPopMatrix();*/ |
---|
[3750] | 199 | } |
---|
[3618] | 200 | |
---|