[8870] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 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 |
---|
| 15 | co-programmer: |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | @todo: direction in which the projectile flights |
---|
| 19 | @todo: a target to set/hit |
---|
| 20 | */ |
---|
| 21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 22 | |
---|
| 23 | #include "world_entities/projectiles/projectile.h" |
---|
| 24 | |
---|
| 25 | #include "world_entity.h" |
---|
| 26 | #include "static_model.h" |
---|
| 27 | #include "weapon_manager.h" |
---|
| 28 | #include "util/loading/factory.h" |
---|
[10704] | 29 | #include "debug.h" |
---|
[8870] | 30 | |
---|
| 31 | |
---|
[9869] | 32 | #include "loading/fast_factory.h" |
---|
[8870] | 33 | |
---|
| 34 | #include "fps_sniper_rifle.h" |
---|
| 35 | |
---|
| 36 | |
---|
[9235] | 37 | #include "effects/explosion.h" |
---|
| 38 | |
---|
[8870] | 39 | |
---|
[8871] | 40 | |
---|
[9406] | 41 | |
---|
[10114] | 42 | |
---|
| 43 | ObjectListDefinition(FPSSniperRifle); |
---|
[9869] | 44 | CREATE_FACTORY(FPSSniperRifle); |
---|
[8870] | 45 | |
---|
| 46 | /** |
---|
| 47 | * standard constructor |
---|
| 48 | |
---|
| 49 | creates a new weapon |
---|
| 50 | */ |
---|
[10704] | 51 | FPSSniperRifle::FPSSniperRifle ( int leftRight, OM_LIST list) |
---|
[8870] | 52 | : Weapon() |
---|
| 53 | { |
---|
[10704] | 54 | this->init(list); |
---|
[8870] | 55 | |
---|
| 56 | this->leftRight = leftRight; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | FPSSniperRifle::FPSSniperRifle(const TiXmlElement* root) |
---|
| 61 | { |
---|
[10704] | 62 | this->init( OM_GROUP_01 ); |
---|
[8870] | 63 | |
---|
| 64 | if (root != NULL) |
---|
| 65 | this->loadParams(root); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * standard deconstructor |
---|
| 70 | */ |
---|
| 71 | FPSSniperRifle::~FPSSniperRifle () |
---|
| 72 | { |
---|
| 73 | // model will be deleted from WorldEntity-destructor |
---|
[9003] | 74 | if( this->material != NULL) |
---|
| 75 | delete this->material; |
---|
[8870] | 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
[10704] | 79 | void FPSSniperRifle::init(OM_LIST list) |
---|
[8870] | 80 | { |
---|
[9869] | 81 | this->registerObject(this, FPSSniperRifle::_objectList); |
---|
[8870] | 82 | |
---|
[10710] | 83 | this->setAbsDir( this->getAbsDir() * Quaternion( -PI/2, Vector(1, 0, 0) ) ); |
---|
| 84 | this->loadModel("models/guns/fps_sniper_rifle.obj", 1.5); |
---|
[9003] | 85 | this->material = new Material(); |
---|
| 86 | this->material->setIllum(3); |
---|
| 87 | this->material->setAmbient(1.0, 1.0, 1.0); |
---|
[10710] | 88 | this->material->setDiffuseMap("textures/fps_sniper_rifle.jpg"); |
---|
[8870] | 89 | |
---|
| 90 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 91 | this->setStateDuration(WS_RELOADING, .1); |
---|
| 92 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 93 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 94 | |
---|
| 95 | this->setEnergyMax(100000); |
---|
| 96 | this->increaseEnergy(100000); |
---|
| 97 | //this->minCharge = 2; |
---|
| 98 | |
---|
[10704] | 99 | //this->setActionSound(WA_SHOOT, "sounds/laser.wav"); |
---|
| 100 | //this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[8870] | 101 | |
---|
| 102 | |
---|
| 103 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[10704] | 104 | //this->setProjectileTypeC("Laser"); |
---|
| 105 | //this->prepareProjectiles(20); |
---|
| 106 | this->toList( list ); |
---|
| 107 | this->weapon = new BspWeapon( this->getOMListNumber() ); |
---|
| 108 | this->weapon->setAlwaysHits( true ); |
---|
| 109 | this->weapon->setDamage( 35 ); |
---|
| 110 | this->weapon->setParent( this ); |
---|
| 111 | this->weapon->toList( list ); |
---|
| 112 | |
---|
| 113 | this->bFire = false; |
---|
[8870] | 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | void FPSSniperRifle::loadParams(const TiXmlElement* root) |
---|
| 118 | { |
---|
| 119 | Weapon::loadParams(root); |
---|
| 120 | |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * this activates the weapon |
---|
| 126 | |
---|
| 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. |
---|
| 130 | */ |
---|
| 131 | void FPSSniperRifle::activate() |
---|
| 132 | { |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * this deactivates the weapon |
---|
| 138 | |
---|
| 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 |
---|
| 141 | been armed out. |
---|
| 142 | */ |
---|
| 143 | void FPSSniperRifle::deactivate() |
---|
| 144 | { |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * fires the weapon |
---|
| 150 | |
---|
| 151 | this is called from the player.cc, when fire-button is been pushed |
---|
| 152 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
| 153 | */ |
---|
| 154 | void FPSSniperRifle::fire() |
---|
| 155 | { |
---|
[10704] | 156 | PRINTF(0)("sniper fire\n"); |
---|
| 157 | this->bFire = true; |
---|
[8870] | 158 | } |
---|
| 159 | |
---|
| 160 | |
---|
[9003] | 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * this will draw the weapon |
---|
| 165 | */ |
---|
| 166 | void FPSSniperRifle::draw () const |
---|
| 167 | { |
---|
| 168 | /* draw gun body */ |
---|
| 169 | glMatrixMode(GL_MODELVIEW); |
---|
| 170 | glPushMatrix(); |
---|
| 171 | |
---|
[10710] | 172 | Vector pos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) ); |
---|
[10705] | 173 | glTranslatef (pos.x, |
---|
| 174 | pos.y, |
---|
| 175 | pos.z); |
---|
| 176 | |
---|
[9003] | 177 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 178 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 179 | |
---|
| 180 | if( this->leftRight == W_RIGHT) |
---|
| 181 | glScalef(1.0, 1.0, -1.0); |
---|
| 182 | |
---|
| 183 | this->material->select(); |
---|
[9869] | 184 | this->getModel()->draw(); |
---|
| 185 | //static_cast<StaticModel*>(this->getModel())->draw(); |
---|
[9003] | 186 | |
---|
| 187 | glPopMatrix(); |
---|
| 188 | } |
---|
| 189 | |
---|
[10704] | 190 | void FPSSniperRifle::tick( float dt ) |
---|
| 191 | { |
---|
| 192 | Weapon::tick( dt ); |
---|
| 193 | this->weapon->fire( bFire ); |
---|
| 194 | |
---|
| 195 | if ( bFire ){ |
---|
| 196 | PRINTF(0)("REAL FIRE\n"); |
---|
| 197 | } |
---|
| 198 | bFire = false; |
---|
| 199 | } |
---|
[9003] | 200 | |
---|
| 201 | |
---|
[10704] | 202 | |
---|