[6868] | 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 Knecht |
---|
| 13 | co-programmer: Silvan Nellen |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
| 19 | #include "executor/executor.h" |
---|
| 20 | #include "space_ship.h" |
---|
| 21 | |
---|
[7193] | 22 | #include "util/loading/resource_manager.h" |
---|
[6868] | 23 | |
---|
| 24 | #include "weapons/test_gun.h" |
---|
| 25 | #include "weapons/turret.h" |
---|
| 26 | #include "weapons/cannon.h" |
---|
| 27 | |
---|
[9869] | 28 | #include "particles/dot_emitter.h" |
---|
| 29 | #include "particles/sprite_particles.h" |
---|
[6868] | 30 | |
---|
[7193] | 31 | #include "util/loading/factory.h" |
---|
[6868] | 32 | #include "key_mapper.h" |
---|
| 33 | |
---|
| 34 | #include "network_game_manager.h" |
---|
[8708] | 35 | #include "shared_network_data.h" |
---|
[6868] | 36 | |
---|
| 37 | #include "power_ups/weapon_power_up.h" |
---|
| 38 | #include "power_ups/param_power_up.h" |
---|
| 39 | |
---|
| 40 | #include "graphics_engine.h" |
---|
| 41 | |
---|
| 42 | #include "plane.h" |
---|
| 43 | |
---|
| 44 | #include "state.h" |
---|
| 45 | #include "player.h" |
---|
| 46 | |
---|
[7193] | 47 | #include "util/loading/load_param.h" |
---|
[6868] | 48 | |
---|
[7056] | 49 | |
---|
[6868] | 50 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 51 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
| 52 | |
---|
| 53 | |
---|
[9869] | 54 | #include "class_id_DEPRECATED.h" |
---|
| 55 | ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); |
---|
| 56 | CREATE_FACTORY(SpaceShip); |
---|
[9406] | 57 | |
---|
[9061] | 58 | #include "script_class.h" |
---|
[9869] | 59 | CREATE_SCRIPTABLE_CLASS(SpaceShip, |
---|
| 60 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
| 61 | ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire)) |
---|
| 62 | ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2)) |
---|
| 63 | ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName)) |
---|
| 64 | ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) |
---|
| 65 | ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) |
---|
| 66 | //Coordinates |
---|
| 67 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 68 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 69 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 70 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
[9061] | 71 | ); |
---|
[6868] | 72 | |
---|
| 73 | /** |
---|
| 74 | * destructs the spaceship, deletes alocated memory |
---|
| 75 | */ |
---|
| 76 | SpaceShip::~SpaceShip () |
---|
| 77 | { |
---|
[6986] | 78 | this->setPlayer(NULL); |
---|
[6868] | 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * loads a Spaceships information from a specified file. |
---|
| 83 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 84 | */ |
---|
[7221] | 85 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
[9965] | 86 | : secWeaponMan(this), |
---|
[9961] | 87 | supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical), |
---|
| 88 | playmode(Playable::Full3D) |
---|
[6868] | 89 | { |
---|
| 90 | this->init(); |
---|
| 91 | TiXmlDocument doc(fileName); |
---|
| 92 | |
---|
| 93 | if(!doc.LoadFile()) |
---|
| 94 | { |
---|
[7221] | 95 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
[6868] | 96 | return; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | this->loadParams(doc.RootElement()); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * creates a new Spaceship from Xml Data |
---|
| 104 | * @param root the xml element containing spaceship data |
---|
| 105 | |
---|
| 106 | @todo add more parameters to load |
---|
| 107 | */ |
---|
| 108 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
[9965] | 109 | : secWeaponMan(this), |
---|
[9961] | 110 | supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical), |
---|
| 111 | playmode(Playable::Full3D) |
---|
[6868] | 112 | { |
---|
| 113 | this->init(); |
---|
| 114 | if (root != NULL) |
---|
| 115 | this->loadParams(root); |
---|
| 116 | |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | * initializes a Spaceship |
---|
| 122 | */ |
---|
| 123 | void SpaceShip::init() |
---|
| 124 | { |
---|
[9869] | 125 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 126 | this->registerObject(this, SpaceShip::_objectList); |
---|
[6868] | 127 | |
---|
| 128 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 129 | |
---|
| 130 | //weapons: |
---|
| 131 | Weapon* wpRight = new TestGun(0); |
---|
| 132 | wpRight->setName("testGun Right"); |
---|
| 133 | Weapon* wpLeft = new TestGun(1); |
---|
| 134 | wpLeft->setName("testGun Left"); |
---|
| 135 | |
---|
[9961] | 136 | Weapon* cannon = new Cannon(); |
---|
| 137 | cannon->setName("BFG"); |
---|
[6868] | 138 | |
---|
[9961] | 139 | |
---|
[9965] | 140 | this->weaponMan.addWeapon( wpLeft, 0, 0); |
---|
| 141 | this->weaponMan.addWeapon( wpRight, 0, 1); |
---|
| 142 | this->secWeaponMan.addWeapon( cannon, 0, 0); |
---|
[9961] | 143 | |
---|
[9965] | 144 | this->weaponMan.changeWeaponConfig(0); |
---|
[9961] | 145 | |
---|
| 146 | wpRight->requestAction(WA_ACTIVATE); |
---|
| 147 | wpLeft->requestAction(WA_ACTIVATE); |
---|
| 148 | cannon->requestAction(WA_ACTIVATE); |
---|
[9965] | 149 | |
---|
| 150 | this->curWeaponPrimary = 0; |
---|
| 151 | this->curWeaponSecondary = 0; |
---|
| 152 | |
---|
| 153 | Playable::weaponConfigChanged(); |
---|
| 154 | |
---|
| 155 | weaponEnergyRegen = 10; // 10 einheiten pro Sekunde |
---|
| 156 | |
---|
[9961] | 157 | /* |
---|
[6868] | 158 | this->addWeapon(wpLeft, 1, 0); |
---|
| 159 | this->addWeapon(wpRight,1 ,1); |
---|
[7087] | 160 | //this->addWeapon(cannon, 0, 6); |
---|
[6868] | 161 | |
---|
[7337] | 162 | this->getWeaponManager().changeWeaponConfig(1); |
---|
[9961] | 163 | */ |
---|
[6868] | 164 | |
---|
[9961] | 165 | this->loadModel("models/ships/hoverglider_mainbody.obj"); |
---|
[6868] | 166 | |
---|
[9965] | 167 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
[9961] | 168 | |
---|
[6868] | 169 | xMouse = yMouse = 0; |
---|
| 170 | yInvert = 1; |
---|
| 171 | mouseSensitivity = 0.001; |
---|
[7122] | 172 | airViscosity = 0.9; |
---|
[6868] | 173 | controlVelocityX = 25; |
---|
| 174 | controlVelocityY = 150; |
---|
| 175 | shipInertia = 1.5; |
---|
[9869] | 176 | // cycle = 0.0; |
---|
[6868] | 177 | |
---|
| 178 | this->setHealthMax(100); |
---|
| 179 | this->setHealth(80); |
---|
| 180 | |
---|
[6947] | 181 | travelSpeed = 0.0; |
---|
[6868] | 182 | acceleration = 3; |
---|
| 183 | this->velocity = this->getAbsDirX()*travelSpeed; |
---|
| 184 | this->mouseDir = this->getAbsDir(); |
---|
| 185 | this->pitchDir = this->getAbsDir(); |
---|
| 186 | |
---|
[9965] | 187 | |
---|
[9869] | 188 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 189 | // button->show(); |
---|
| 190 | // button->setLabel("orxonox"); |
---|
| 191 | // button->setBindNode(this); |
---|
| 192 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 193 | // bar->show(); |
---|
| 194 | // bar->setValue(7.0); |
---|
| 195 | // bar->setMaximum(10); |
---|
| 196 | // bar->setSize2D( 20, 100); |
---|
| 197 | // bar->setAbsCoor2D( 10, 200); |
---|
[6868] | 198 | |
---|
| 199 | //add events to the eventlist |
---|
[6997] | 200 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 201 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6868] | 202 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 203 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 204 | //registerEvent(SDLK_q); |
---|
| 205 | //registerEvent(SDLK_e); |
---|
| 206 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
[9958] | 207 | registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support |
---|
[6868] | 208 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 209 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 210 | //registerEvent(SDLK_PAGEUP); |
---|
| 211 | //registerEvent(SDLK_PAGEDOWN); |
---|
| 212 | registerEvent(EV_MOUSE_MOTION); |
---|
| 213 | |
---|
[9965] | 214 | this->weaponMan.setSlotCount(6); |
---|
[6868] | 215 | |
---|
[9965] | 216 | this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 217 | this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 218 | |
---|
[9965] | 219 | this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 220 | this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 221 | |
---|
[9965] | 222 | this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 223 | this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 224 | |
---|
[9965] | 225 | this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 226 | this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 227 | |
---|
[9965] | 228 | this->weaponMan.setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 229 | this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
[6868] | 230 | |
---|
[9965] | 231 | this->weaponMan.setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 232 | this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9961] | 233 | |
---|
| 234 | this->secWeaponMan.setSlotCount(6); |
---|
| 235 | |
---|
[9965] | 236 | this->secWeaponMan.setSlotPosition(0, Vector(2.6, -2.5, 0)); |
---|
[9961] | 237 | this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 238 | |
---|
| 239 | this->secWeaponMan.setSlotPosition(1, Vector(2.6, .1, 3.0)); |
---|
| 240 | this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 241 | |
---|
| 242 | this->secWeaponMan.setSlotPosition(2, Vector(1.5, .5, -.5)); |
---|
| 243 | this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 244 | |
---|
| 245 | this->secWeaponMan.setSlotPosition(3, Vector(1.5, .5, .5)); |
---|
| 246 | this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 247 | |
---|
| 248 | this->secWeaponMan.setSlotPosition(4, Vector(1.5, -.5, .5)); |
---|
| 249 | this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 250 | |
---|
| 251 | this->secWeaponMan.setSlotPosition(5, Vector(1.5, -.5, -.5)); |
---|
| 252 | this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9965] | 253 | |
---|
[9869] | 254 | // |
---|
| 255 | // this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 256 | // this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 257 | // |
---|
| 258 | // this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 259 | // this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
[6868] | 260 | |
---|
[9965] | 261 | this->weaponMan.getFixedTarget()->setParent(this); |
---|
| 262 | this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[6868] | 263 | |
---|
[9961] | 264 | this->secWeaponMan.getFixedTarget()->setParent(this); |
---|
| 265 | this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[6868] | 266 | |
---|
[9965] | 267 | dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false); |
---|
[9961] | 268 | |
---|
[6868] | 269 | this->burstEmitter = new DotEmitter(200, 0.0, .01); |
---|
| 270 | this->burstEmitter->setParent(this); |
---|
| 271 | this->burstEmitter->setRelCoor(-1, .5, 0); |
---|
| 272 | this->burstEmitter->setName("SpaceShip_Burst_emitter"); |
---|
| 273 | |
---|
| 274 | this->burstSystem = new SpriteParticles(1000); |
---|
| 275 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
| 276 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
| 277 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 278 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
| 279 | this->burstSystem->setRadius(0.0, 1.0); |
---|
| 280 | this->burstSystem->setRadius(0.05, 1.0); |
---|
| 281 | this->burstSystem->setRadius(.5, .8); |
---|
| 282 | this->burstSystem->setRadius(1.0, 0); |
---|
| 283 | this->burstSystem->setColor(0.0, .7,.7,1,.7); |
---|
| 284 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
| 285 | this->burstSystem->setColor(0.5, .5,.5,.8,.8); |
---|
| 286 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
[9008] | 287 | |
---|
[9656] | 288 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); |
---|
[7954] | 289 | registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); |
---|
[6868] | 290 | |
---|
[7954] | 291 | registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); |
---|
| 292 | registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); |
---|
| 293 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 294 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 295 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
| 296 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
| 297 | registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); |
---|
| 298 | registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); |
---|
[6868] | 299 | } |
---|
| 300 | |
---|
| 301 | |
---|
| 302 | /** |
---|
| 303 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 304 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 305 | */ |
---|
| 306 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 307 | { |
---|
| 308 | Playable::loadParams(root); |
---|
| 309 | } |
---|
| 310 | |
---|
[7346] | 311 | void SpaceShip::setPlayDirection(const Quaternion& quat, float speed) |
---|
[7056] | 312 | { |
---|
[7095] | 313 | this->mouseDir = quat; |
---|
[7056] | 314 | } |
---|
[6868] | 315 | |
---|
[7056] | 316 | |
---|
[7085] | 317 | void SpaceShip::reset() |
---|
| 318 | { |
---|
[9965] | 319 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
[7056] | 320 | |
---|
[7085] | 321 | xMouse = yMouse = 0; |
---|
| 322 | |
---|
| 323 | this->setHealth(80); |
---|
| 324 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | |
---|
[6868] | 328 | void SpaceShip::enter() |
---|
| 329 | { |
---|
[7337] | 330 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
[6868] | 331 | this->attachCamera(); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | void SpaceShip::leave() |
---|
| 335 | { |
---|
[7337] | 336 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6868] | 337 | this->detachCamera(); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | /** |
---|
| 342 | * effect that occurs after the SpaceShip is spawned |
---|
| 343 | */ |
---|
| 344 | void SpaceShip::postSpawn () |
---|
| 345 | { |
---|
| 346 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | /** |
---|
| 350 | * the action occuring if the spaceship left the game |
---|
| 351 | */ |
---|
| 352 | void SpaceShip::leftWorld () |
---|
| 353 | {} |
---|
| 354 | |
---|
| 355 | WorldEntity* ref = NULL; |
---|
| 356 | /** |
---|
| 357 | * this function is called, when two entities collide |
---|
| 358 | * @param entity: the world entity with whom it collides |
---|
| 359 | * |
---|
| 360 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 361 | */ |
---|
| 362 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 363 | { |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | /** |
---|
| 367 | * draws the spaceship after transforming it. |
---|
| 368 | */ |
---|
| 369 | void SpaceShip::draw () const |
---|
| 370 | { |
---|
| 371 | WorldEntity::draw(); |
---|
| 372 | |
---|
| 373 | //this->debug(0); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | /** |
---|
| 377 | * the function called for each passing timeSnap |
---|
| 378 | * @param time The timespan passed since last update |
---|
| 379 | */ |
---|
| 380 | void SpaceShip::tick (float time) |
---|
| 381 | { |
---|
[9961] | 382 | // Playable::tick(time);$ |
---|
[6868] | 383 | |
---|
[9961] | 384 | // Own Tick Setup, as a different fire routine is used on the weapon manager |
---|
[9965] | 385 | this->weaponMan.tick(time); |
---|
[9961] | 386 | this->secWeaponMan.tick(time); |
---|
| 387 | |
---|
[9965] | 388 | if( this->bFire) |
---|
[9961] | 389 | { |
---|
[9965] | 390 | this->weaponMan.fire(); |
---|
[9961] | 391 | } |
---|
| 392 | if( this->bSecFire) |
---|
| 393 | { |
---|
| 394 | this->secWeaponMan.fire(); |
---|
[9965] | 395 | this->bSecFire = !this->bSecFire; // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed |
---|
[9961] | 396 | } |
---|
| 397 | |
---|
[9965] | 398 | this->weaponRegen(time); |
---|
| 399 | |
---|
[8708] | 400 | if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) |
---|
[9869] | 401 | { |
---|
[6868] | 402 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
| 403 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
| 404 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
| 405 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
| 406 | |
---|
| 407 | pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); |
---|
| 408 | |
---|
| 409 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); |
---|
| 410 | xMouse = yMouse = 0; |
---|
[9869] | 411 | } |
---|
[6868] | 412 | |
---|
[9958] | 413 | // Shield Regeneration and other regular calculations on the ship |
---|
| 414 | this->regen(time); |
---|
[6868] | 415 | |
---|
[9958] | 416 | |
---|
[9869] | 417 | // if( this != State::getPlayer()->getControllable()) |
---|
| 418 | // return; |
---|
[6868] | 419 | |
---|
[9235] | 420 | // spaceship controlled movement fire(bool bF){ this->bFire = bF;} |
---|
[7954] | 421 | //if (this->getOwner() == this->getHostID()) |
---|
[9869] | 422 | this->calculateVelocity(time); |
---|
[6868] | 423 | |
---|
[6959] | 424 | |
---|
[6868] | 425 | Vector move = velocity*time; |
---|
| 426 | |
---|
| 427 | //orient the velocity in the direction of the spaceship. |
---|
| 428 | travelSpeed = velocity.len(); |
---|
| 429 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 430 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
| 431 | this->burstEmitter->setEmissionRate(travelSpeed); |
---|
| 432 | this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); |
---|
| 433 | |
---|
| 434 | //orient the spaceship in direction of the mouse |
---|
[9869] | 435 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
| 436 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6868] | 437 | this->setAbsDir( rotQuat); |
---|
[9869] | 438 | //this->setAbsDirSoft(mouseDir,5); |
---|
[6868] | 439 | |
---|
| 440 | // this is the air friction (necessary for a smooth control) |
---|
| 441 | if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; |
---|
| 442 | else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; |
---|
| 443 | |
---|
| 444 | //other physics (gravity) |
---|
| 445 | //if(travelSpeed < 120) |
---|
| 446 | //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; |
---|
| 447 | |
---|
| 448 | //hoover effect |
---|
| 449 | //cycle += time; |
---|
| 450 | //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
| 451 | |
---|
| 452 | //readjust |
---|
| 453 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 454 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 455 | |
---|
| 456 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 457 | |
---|
| 458 | this->shiftCoor(move); |
---|
| 459 | |
---|
[9869] | 460 | // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); |
---|
[6868] | 461 | |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | /** |
---|
| 465 | * calculate the velocity |
---|
| 466 | * @param time the timeslice since the last frame |
---|
| 467 | */ |
---|
| 468 | void SpaceShip::calculateVelocity (float time) |
---|
| 469 | { |
---|
| 470 | Vector accel(0.0, 0.0, 0.0); |
---|
| 471 | /* |
---|
[9235] | 472 | Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter |
---|
[6868] | 473 | */ |
---|
| 474 | //float rotVal = 0.0; |
---|
| 475 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
| 476 | /* calculate the direction in which the craft is heading */ |
---|
| 477 | |
---|
| 478 | //Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
| 479 | |
---|
| 480 | if( this->bUp ) |
---|
[9869] | 481 | { |
---|
| 482 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 483 | //accel += (this->getAbsDirX())*2; |
---|
| 484 | accel += (this->getAbsDirX())*acceleration; |
---|
[6868] | 485 | |
---|
[9869] | 486 | } |
---|
[6868] | 487 | |
---|
| 488 | if( this->bDown ) |
---|
[9869] | 489 | { |
---|
| 490 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 491 | //accel -= (this->getAbsDirX())*2; |
---|
[6868] | 492 | //if(velocity.len() > 50) |
---|
[9869] | 493 | accel -= (this->getAbsDirX())*0.5*acceleration; |
---|
[6868] | 494 | |
---|
| 495 | |
---|
| 496 | |
---|
[9869] | 497 | } |
---|
[6868] | 498 | |
---|
| 499 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
| 500 | { |
---|
| 501 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
[9869] | 502 | // accel -= rightDirection; |
---|
[6868] | 503 | //velocityDir.normalize(); |
---|
| 504 | //rot +=Vector(1,0,0); |
---|
| 505 | //rotVal -= .4; |
---|
| 506 | } |
---|
| 507 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 508 | { |
---|
| 509 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 510 | |
---|
| 511 | // accel += rightDirection; |
---|
| 512 | //velocityDir.normalize(); |
---|
| 513 | //rot += Vector(1,0,0); |
---|
| 514 | //rotVal += .4; |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | |
---|
| 518 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 519 | { |
---|
| 520 | mouseDir *= Quaternion(-time*2, Vector(1,0,0)); |
---|
[9869] | 521 | // accel -= rightDirection; |
---|
[6868] | 522 | //velocityDir.normalize(); |
---|
| 523 | //rot +=Vector(1,0,0); |
---|
| 524 | //rotVal -= .4; |
---|
| 525 | } |
---|
| 526 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 527 | { |
---|
| 528 | mouseDir *= Quaternion(time*2, Vector(1,0,0)); |
---|
| 529 | |
---|
| 530 | // accel += rightDirection; |
---|
| 531 | //velocityDir.normalize(); |
---|
| 532 | //rot += Vector(1,0,0); |
---|
| 533 | //rotVal += .4; |
---|
| 534 | } |
---|
| 535 | if (this->bAscend ) |
---|
| 536 | { |
---|
| 537 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 538 | |
---|
[9869] | 539 | // accel += upDirection; |
---|
[6868] | 540 | //velocityDir.normalize(); |
---|
| 541 | //rot += Vector(0,0,1); |
---|
| 542 | //rotVal += .4; |
---|
| 543 | } |
---|
| 544 | if (this->bDescend ) |
---|
| 545 | { |
---|
| 546 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 547 | |
---|
| 548 | // accel -= upDirection; |
---|
| 549 | //velocityDir.normalize(); |
---|
| 550 | //rot += Vector(0,0,1); |
---|
| 551 | //rotVal -= .4; |
---|
| 552 | } |
---|
| 553 | |
---|
[6959] | 554 | velocity += accel*time*10; |
---|
[6868] | 555 | //rot.normalize(); |
---|
| 556 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
[9961] | 557 | |
---|
[6868] | 558 | } |
---|
| 559 | |
---|
| 560 | /** |
---|
| 561 | * @todo switch statement ?? |
---|
| 562 | */ |
---|
| 563 | void SpaceShip::process(const Event &event) |
---|
| 564 | { |
---|
[9961] | 565 | //Playable::process(event); |
---|
[6868] | 566 | |
---|
| 567 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[9869] | 568 | this->bRollL = event.bPressed; |
---|
[6868] | 569 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[9869] | 570 | this->bRollR = event.bPressed; |
---|
[6997] | 571 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[6868] | 572 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 573 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[6868] | 574 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[9961] | 575 | else if( event.type == KeyMapper::PEV_FIRE2) |
---|
| 576 | this->bSecFire = event.bPressed; |
---|
[9958] | 577 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
[9965] | 578 | this->bFire = event.bPressed; |
---|
[6868] | 579 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 580 | { |
---|
[9961] | 581 | |
---|
[6868] | 582 | this->xMouse += event.xRel; |
---|
| 583 | this->yMouse += event.yRel; |
---|
| 584 | } |
---|
| 585 | } |
---|
| 586 | |
---|
[9235] | 587 | void SpaceShip::destroy( WorldEntity* killer ) |
---|
[9008] | 588 | { |
---|
| 589 | PRINTF(0)("spaceship destroy\n"); |
---|
| 590 | } |
---|
[6868] | 591 | |
---|
[9008] | 592 | void SpaceShip::respawn( ) |
---|
| 593 | { |
---|
| 594 | toList( OM_PLAYERS ); |
---|
| 595 | } |
---|
[6868] | 596 | |
---|
| 597 | |
---|
[9957] | 598 | void SpaceShip::damage(float pDamage, float eDamage){ |
---|
[9950] | 599 | if( this->shieldActive) { |
---|
| 600 | if( this->shieldCur > pDamage) { |
---|
| 601 | this->shieldCur = this->shieldCur - pDamage; |
---|
| 602 | } |
---|
| 603 | else { // shield <= pDamage |
---|
| 604 | this->shieldCur = 0; |
---|
| 605 | this->shieldActive = false; //shield collaptses |
---|
| 606 | pDamage = pDamage - this->shieldCur; |
---|
| 607 | if( !this->shieldActive) { |
---|
[9957] | 608 | this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate |
---|
[9953] | 609 | this->electronicCur -= eDamage; |
---|
[9950] | 610 | } |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | else { |
---|
| 614 | this->armorCur = this->armorCur - pDamage; |
---|
| 615 | this->electronicCur = this->electronicCur - eDamage; |
---|
| 616 | } |
---|
| 617 | if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } |
---|
| 618 | } |
---|
| 619 | |
---|
[9957] | 620 | void SpaceShip::regen(float time){ |
---|
| 621 | float tmp; |
---|
[9963] | 622 | if (this->armorCur != this->armorMax || this->armorRegen != 0){ |
---|
| 623 | tmp = this->armorCur + this->armorRegen * time; |
---|
| 624 | if ( tmp > electronicMax) |
---|
| 625 | this->armorCur = this->armorMax; |
---|
| 626 | else |
---|
| 627 | this->armorCur = tmp; |
---|
| 628 | } |
---|
| 629 | if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ |
---|
[9957] | 630 | tmp = this->shieldCur + this->shieldRegen * time; |
---|
| 631 | if( tmp > shieldMax) |
---|
[9953] | 632 | this->shieldCur = this->shieldMax; |
---|
| 633 | else |
---|
[9957] | 634 | this->shieldCur = tmp; |
---|
| 635 | this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); |
---|
[9953] | 636 | } |
---|
[9963] | 637 | if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ |
---|
[9957] | 638 | tmp = this->electronicCur + this->electronicRegen * time; |
---|
| 639 | if ( tmp > electronicMax) |
---|
[9953] | 640 | this->electronicCur = this->electronicMax; |
---|
| 641 | else |
---|
[9957] | 642 | this->electronicCur = tmp; |
---|
[9953] | 643 | } |
---|
[9950] | 644 | } |
---|
[9965] | 645 | |
---|
| 646 | /** |
---|
| 647 | * Weapon regeneration |
---|
| 648 | * does not use any reactor capacity, as it wouldn't work in a consistent way. |
---|
| 649 | */ |
---|
| 650 | void SpaceShip::weaponRegen(float time) |
---|
| 651 | { |
---|
| 652 | float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; |
---|
| 653 | Weapon* weapon; |
---|
| 654 | for( int i=0; i < this->weaponMan.getSlotCount(); i++) |
---|
| 655 | { |
---|
| 656 | weapon = this->weaponMan.getWeapon(i); |
---|
| 657 | if( weapon != NULL && weapon->isActive()) |
---|
| 658 | { |
---|
| 659 | weapon->increaseEnergy( energy); |
---|
| 660 | weapon->updateWidgets(); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | } |
---|
| 664 | // weaponMan.increaseAmmunition( weapon, energy); |
---|
| 665 | |
---|
| 666 | } |
---|