[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 | |
---|
[9003] | 83 | this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2); |
---|
| 84 | this->material = new Material(); |
---|
| 85 | this->material->setIllum(3); |
---|
| 86 | this->material->setAmbient(1.0, 1.0, 1.0); |
---|
[10317] | 87 | this->material->setDiffuseMap("textures/rifle01tex.jpg"); |
---|
[8870] | 88 | |
---|
| 89 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 90 | this->setStateDuration(WS_RELOADING, .1); |
---|
| 91 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 92 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 93 | |
---|
| 94 | this->setEnergyMax(100000); |
---|
| 95 | this->increaseEnergy(100000); |
---|
| 96 | //this->minCharge = 2; |
---|
| 97 | |
---|
[10704] | 98 | //this->setActionSound(WA_SHOOT, "sounds/laser.wav"); |
---|
| 99 | //this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[8870] | 100 | |
---|
| 101 | |
---|
| 102 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[10704] | 103 | //this->setProjectileTypeC("Laser"); |
---|
| 104 | //this->prepareProjectiles(20); |
---|
| 105 | this->toList( list ); |
---|
| 106 | this->weapon = new BspWeapon( this->getOMListNumber() ); |
---|
| 107 | this->weapon->setAlwaysHits( true ); |
---|
| 108 | this->weapon->setDamage( 35 ); |
---|
| 109 | this->weapon->setParent( this ); |
---|
| 110 | this->weapon->toList( list ); |
---|
| 111 | |
---|
| 112 | this->bFire = false; |
---|
[8870] | 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | void FPSSniperRifle::loadParams(const TiXmlElement* root) |
---|
| 117 | { |
---|
| 118 | Weapon::loadParams(root); |
---|
| 119 | |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | * this activates the weapon |
---|
| 125 | |
---|
| 126 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 127 | activation can be connected with an animation. for example the weapon is |
---|
| 128 | been armed out. |
---|
| 129 | */ |
---|
| 130 | void FPSSniperRifle::activate() |
---|
| 131 | { |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * this deactivates the weapon |
---|
| 137 | |
---|
| 138 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 139 | activation can be connected with an animation. for example the weapon is |
---|
| 140 | been armed out. |
---|
| 141 | */ |
---|
| 142 | void FPSSniperRifle::deactivate() |
---|
| 143 | { |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
| 148 | * fires the weapon |
---|
| 149 | |
---|
| 150 | this is called from the player.cc, when fire-button is been pushed |
---|
| 151 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
| 152 | */ |
---|
| 153 | void FPSSniperRifle::fire() |
---|
| 154 | { |
---|
[10704] | 155 | PRINTF(0)("sniper fire\n"); |
---|
| 156 | this->bFire = true; |
---|
[8870] | 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
[9003] | 160 | |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * this will draw the weapon |
---|
| 164 | */ |
---|
| 165 | void FPSSniperRifle::draw () const |
---|
| 166 | { |
---|
| 167 | /* draw gun body */ |
---|
| 168 | glMatrixMode(GL_MODELVIEW); |
---|
| 169 | glPushMatrix(); |
---|
| 170 | |
---|
[10705] | 171 | Vector pos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 2, 0, 0 ) ); |
---|
| 172 | glTranslatef (pos.x, |
---|
| 173 | pos.y, |
---|
| 174 | pos.z); |
---|
| 175 | |
---|
[9003] | 176 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 177 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 178 | |
---|
| 179 | if( this->leftRight == W_RIGHT) |
---|
| 180 | glScalef(1.0, 1.0, -1.0); |
---|
| 181 | |
---|
| 182 | this->material->select(); |
---|
[9869] | 183 | this->getModel()->draw(); |
---|
| 184 | //static_cast<StaticModel*>(this->getModel())->draw(); |
---|
[9003] | 185 | |
---|
| 186 | glPopMatrix(); |
---|
| 187 | } |
---|
| 188 | |
---|
[10704] | 189 | void FPSSniperRifle::tick( float dt ) |
---|
| 190 | { |
---|
| 191 | Weapon::tick( dt ); |
---|
| 192 | this->weapon->fire( bFire ); |
---|
| 193 | |
---|
| 194 | if ( bFire ){ |
---|
| 195 | PRINTF(0)("REAL FIRE\n"); |
---|
| 196 | } |
---|
| 197 | bFire = false; |
---|
| 198 | } |
---|
[9003] | 199 | |
---|
| 200 | |
---|
[10704] | 201 | |
---|