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