[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" |
---|
[9970] | 25 | #include "weapons/light_blaster.h" |
---|
| 26 | #include "weapons/medium_blaster.h" |
---|
| 27 | #include "weapons/heavy_blaster.h" |
---|
[10023] | 28 | #include "weapons/swarm_launcher.h" |
---|
[9970] | 29 | #include "weapons/boomerang_gun.h" |
---|
[6868] | 30 | #include "weapons/turret.h" |
---|
| 31 | #include "weapons/cannon.h" |
---|
| 32 | |
---|
[9869] | 33 | #include "particles/dot_emitter.h" |
---|
[10073] | 34 | #include "particles/emitter_node.h" |
---|
[9869] | 35 | #include "particles/sprite_particles.h" |
---|
[10081] | 36 | #include "effects/explosion.h" |
---|
| 37 | #include "effects/trail.h" |
---|
[6868] | 38 | |
---|
[7193] | 39 | #include "util/loading/factory.h" |
---|
[6868] | 40 | #include "key_mapper.h" |
---|
| 41 | |
---|
| 42 | #include "network_game_manager.h" |
---|
[8708] | 43 | #include "shared_network_data.h" |
---|
[6868] | 44 | |
---|
| 45 | #include "power_ups/weapon_power_up.h" |
---|
| 46 | #include "power_ups/param_power_up.h" |
---|
| 47 | |
---|
| 48 | #include "graphics_engine.h" |
---|
| 49 | |
---|
| 50 | #include "plane.h" |
---|
| 51 | |
---|
| 52 | #include "state.h" |
---|
| 53 | #include "player.h" |
---|
| 54 | |
---|
[7193] | 55 | #include "util/loading/load_param.h" |
---|
[10020] | 56 | #include "time.h" |
---|
[6868] | 57 | |
---|
[10096] | 58 | #include "track/track.h" |
---|
[7056] | 59 | |
---|
[10096] | 60 | |
---|
[6868] | 61 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 62 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
| 63 | |
---|
| 64 | |
---|
[9869] | 65 | #include "class_id_DEPRECATED.h" |
---|
| 66 | ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); |
---|
| 67 | CREATE_FACTORY(SpaceShip); |
---|
[9406] | 68 | |
---|
[9061] | 69 | #include "script_class.h" |
---|
[9869] | 70 | CREATE_SCRIPTABLE_CLASS(SpaceShip, |
---|
| 71 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
| 72 | ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire)) |
---|
| 73 | ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2)) |
---|
| 74 | ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName)) |
---|
| 75 | ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) |
---|
| 76 | ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) |
---|
| 77 | //Coordinates |
---|
| 78 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 79 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 80 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 81 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
[10017] | 82 | //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed)) |
---|
[9061] | 83 | ); |
---|
[6868] | 84 | |
---|
| 85 | /** |
---|
| 86 | * destructs the spaceship, deletes alocated memory |
---|
| 87 | */ |
---|
| 88 | SpaceShip::~SpaceShip () |
---|
| 89 | { |
---|
[6986] | 90 | this->setPlayer(NULL); |
---|
[6868] | 91 | } |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * loads a Spaceships information from a specified file. |
---|
| 95 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 96 | */ |
---|
[7221] | 97 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
[10019] | 98 | : secWeaponMan(this) //, |
---|
| 99 | //supportedPlaymodes(Playable::Vertical) , |
---|
| 100 | //playmode(Playable::Vertical) |
---|
[6868] | 101 | { |
---|
| 102 | this->init(); |
---|
| 103 | TiXmlDocument doc(fileName); |
---|
| 104 | |
---|
| 105 | if(!doc.LoadFile()) |
---|
| 106 | { |
---|
[7221] | 107 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
[6868] | 108 | return; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | this->loadParams(doc.RootElement()); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * creates a new Spaceship from Xml Data |
---|
| 116 | * @param root the xml element containing spaceship data |
---|
| 117 | |
---|
| 118 | @todo add more parameters to load |
---|
| 119 | */ |
---|
| 120 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
[10019] | 121 | : secWeaponMan(this) //, |
---|
| 122 | //supportedPlaymodes(Playable::Vertical) , |
---|
| 123 | //playmode(Playable::Vertical) |
---|
[6868] | 124 | { |
---|
| 125 | this->init(); |
---|
[10081] | 126 | //this->setParentMode(PNODE_REPARENT_DELETE_CHILDREN); |
---|
[6868] | 127 | if (root != NULL) |
---|
| 128 | this->loadParams(root); |
---|
| 129 | |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * initializes a Spaceship |
---|
| 135 | */ |
---|
| 136 | void SpaceShip::init() |
---|
| 137 | { |
---|
[9998] | 138 | |
---|
[10022] | 139 | srand(time(0)); //initialize Random Nomber Generator |
---|
| 140 | |
---|
[9869] | 141 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 142 | this->registerObject(this, SpaceShip::_objectList); |
---|
[6868] | 143 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 144 | |
---|
| 145 | //weapons: |
---|
[10098] | 146 | |
---|
[9996] | 147 | Weapon* wpRight1 = new LightBlaster (); |
---|
[10073] | 148 | wpRight1->setName( "LightBlaster"); |
---|
| 149 | wpRight1->setParent( this); |
---|
[9996] | 150 | Weapon* wpLeft1 = new LightBlaster (); |
---|
[10073] | 151 | wpLeft1->setName( "LightBlaster"); |
---|
[10098] | 152 | wpLeft1->setParent( this); |
---|
[6868] | 153 | |
---|
[9996] | 154 | Weapon* wpRight2 = new MediumBlaster (); |
---|
[10073] | 155 | wpRight2->setName( "MediumBlaster"); |
---|
| 156 | wpRight2->setParent( this); |
---|
[9996] | 157 | Weapon* wpLeft2 = new MediumBlaster (); |
---|
[10073] | 158 | wpLeft2->setName( "MediumBlaster"); |
---|
| 159 | wpLeft2->setParent( this); |
---|
[10098] | 160 | |
---|
[10030] | 161 | Weapon* wpRight3 = new HeavyBlaster (); |
---|
[10073] | 162 | wpRight3->setName( "HeavyBlaster"); |
---|
| 163 | wpRight3->setParent( this); |
---|
[9996] | 164 | Weapon* wpLeft3 = new HeavyBlaster (); |
---|
[10073] | 165 | wpLeft3->setName( "HeavyBlaster"); |
---|
[10098] | 166 | wpLeft3->setParent( this); |
---|
[9996] | 167 | |
---|
[10023] | 168 | Weapon* cannon = new SwarmLauncher(); |
---|
[10073] | 169 | cannon->setName( "SwarmLauncher"); |
---|
| 170 | cannon->setParent( this); |
---|
[6868] | 171 | |
---|
[9961] | 172 | |
---|
[10098] | 173 | this->weaponMan.addWeapon( wpLeft1, 0, 0); |
---|
| 174 | this->weaponMan.addWeapon( wpRight1, 0, 1); |
---|
[10016] | 175 | this->weaponMan.addWeapon( wpLeft2, 0, 2); |
---|
| 176 | this->weaponMan.addWeapon( wpRight2, 0, 3); |
---|
[10098] | 177 | this->weaponMan.addWeapon( wpLeft3, 0, 4); |
---|
| 178 | this->weaponMan.addWeapon( wpRight3, 0, 5); |
---|
[9998] | 179 | |
---|
[10023] | 180 | this->secWeaponMan.addWeapon( cannon, 1, 0); |
---|
[9961] | 181 | |
---|
[9965] | 182 | this->weaponMan.changeWeaponConfig(0); |
---|
[10023] | 183 | this->secWeaponMan.changeWeaponConfig(1); |
---|
[9961] | 184 | |
---|
[10098] | 185 | wpRight1->requestAction(WA_ACTIVATE); |
---|
| 186 | wpLeft1->requestAction(WA_ACTIVATE); |
---|
[9996] | 187 | wpRight2->requestAction(WA_ACTIVATE); |
---|
| 188 | wpLeft2->requestAction(WA_ACTIVATE); |
---|
[10098] | 189 | wpRight3->requestAction(WA_ACTIVATE); |
---|
| 190 | wpLeft3->requestAction(WA_ACTIVATE); |
---|
[9998] | 191 | |
---|
[9961] | 192 | cannon->requestAction(WA_ACTIVATE); |
---|
[9965] | 193 | |
---|
[9970] | 194 | curWeaponPrimary = 0; |
---|
| 195 | curWeaponSecondary = 0; |
---|
[9965] | 196 | |
---|
| 197 | Playable::weaponConfigChanged(); |
---|
| 198 | |
---|
[9970] | 199 | reactorOutput = 10; |
---|
[9965] | 200 | |
---|
[9970] | 201 | weaponEnergyRegen = 10; // 10 einheiten pro Sekunde |
---|
| 202 | engineSpeedBase = 5; |
---|
| 203 | shieldRegen = 2; |
---|
| 204 | |
---|
| 205 | shieldEnergyShare = 0.3; |
---|
| 206 | weaponEnergyShare = 0.3; |
---|
| 207 | engineEnergyShare = 0.4; |
---|
| 208 | |
---|
| 209 | shieldCur = 20; |
---|
| 210 | shieldMax = 100; |
---|
[10020] | 211 | shieldTH = .2* shieldMax; // shield power must be 20% before shield kicks in again |
---|
[9970] | 212 | |
---|
[10024] | 213 | electronicCur = 50; |
---|
[10022] | 214 | electronicMax = 50; |
---|
[10020] | 215 | electronicRegen = 3; |
---|
| 216 | electronicTH = .7 * electronicMax; // 30% of eDamage can be handled by the ship |
---|
| 217 | |
---|
[6868] | 218 | |
---|
[9970] | 219 | this->loadModel("models/ships/mantawing.obj"); |
---|
[10017] | 220 | //this->setVisibiliy(false); |
---|
[6868] | 221 | |
---|
[10017] | 222 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
| 223 | |
---|
[6868] | 224 | |
---|
[9970] | 225 | this->setHealthMax(shieldMax); |
---|
| 226 | this->setHealth(shieldCur); |
---|
[6868] | 227 | |
---|
[10017] | 228 | this->travelNode = new PNode(); |
---|
| 229 | |
---|
| 230 | // camera - issue |
---|
| 231 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 232 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
| 233 | |
---|
[6868] | 234 | |
---|
[9965] | 235 | |
---|
[6868] | 236 | //add events to the eventlist |
---|
[6997] | 237 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 238 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6868] | 239 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 240 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 241 | //registerEvent(SDLK_q); |
---|
| 242 | //registerEvent(SDLK_e); |
---|
| 243 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
[9958] | 244 | registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support |
---|
[6868] | 245 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 246 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 247 | //registerEvent(SDLK_PAGEUP); |
---|
| 248 | //registerEvent(SDLK_PAGEDOWN); |
---|
| 249 | registerEvent(EV_MOUSE_MOTION); |
---|
| 250 | |
---|
[10073] | 251 | this->weaponMan.setParentEntity( this); |
---|
| 252 | this->secWeaponMan.setParentEntity( this); |
---|
| 253 | |
---|
[9965] | 254 | this->weaponMan.setSlotCount(6); |
---|
[6868] | 255 | |
---|
[10064] | 256 | this->weaponMan.setSlotPosition(0, Vector(-2.6, 0, -3.0)); |
---|
[9965] | 257 | this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 258 | |
---|
[10064] | 259 | this->weaponMan.setSlotPosition(1, Vector(-2.6, 0, 3.0)); |
---|
[9965] | 260 | this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6868] | 261 | |
---|
[10064] | 262 | this->weaponMan.setSlotPosition(2, Vector(-1.5, 0, -.5)); |
---|
[9965] | 263 | this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 264 | |
---|
[10064] | 265 | this->weaponMan.setSlotPosition(3, Vector(-1.5, 0, .5)); |
---|
[9965] | 266 | this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
[6868] | 267 | |
---|
[10064] | 268 | this->weaponMan.setSlotPosition(4, Vector(-1.5, 0, .5)); |
---|
[9965] | 269 | this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
[6868] | 270 | |
---|
[10064] | 271 | this->weaponMan.setSlotPosition(5, Vector(-1.5, 0, -.5)); |
---|
[9965] | 272 | this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9961] | 273 | |
---|
| 274 | this->secWeaponMan.setSlotCount(6); |
---|
| 275 | |
---|
[10073] | 276 | this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0)); |
---|
[9961] | 277 | this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 278 | |
---|
[10073] | 279 | this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0)); |
---|
[9961] | 280 | this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 281 | |
---|
[10073] | 282 | this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5)); |
---|
[9961] | 283 | this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 284 | |
---|
[10073] | 285 | this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5)); |
---|
[9961] | 286 | this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 287 | |
---|
[10073] | 288 | this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5)); |
---|
[9961] | 289 | this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 290 | |
---|
[10073] | 291 | this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5)); |
---|
[9961] | 292 | this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
[9965] | 293 | |
---|
[6868] | 294 | |
---|
[9965] | 295 | this->weaponMan.getFixedTarget()->setParent(this); |
---|
| 296 | this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[10004] | 297 | |
---|
[9998] | 298 | |
---|
[9961] | 299 | this->secWeaponMan.getFixedTarget()->setParent(this); |
---|
| 300 | this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
[10004] | 301 | this->secWeaponMan.setRotationSpeed(0); |
---|
[6868] | 302 | |
---|
[9965] | 303 | dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false); |
---|
[9961] | 304 | |
---|
[6868] | 305 | |
---|
[10017] | 306 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
| 307 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
| 308 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 309 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 310 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
| 311 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
[10023] | 312 | registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER)); |
---|
[10017] | 313 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); |
---|
| 314 | |
---|
| 315 | //this->airFriction = 0.5f; |
---|
[10019] | 316 | this->travelDistancePlus = Vector2D(38.0, 43.0); |
---|
| 317 | this->travelDistanceMinus = Vector2D(-38.0, -43.0); |
---|
[10017] | 318 | this->cameraSpeed = 40; |
---|
[10019] | 319 | this->cameraLook = 0.0f; |
---|
| 320 | //this->airFriction = 0.0f; |
---|
[10017] | 321 | |
---|
[10020] | 322 | srand(time(0)); //initaialize RNG |
---|
| 323 | |
---|
[10017] | 324 | this->travelNode->debugDraw(); |
---|
[10032] | 325 | |
---|
| 326 | this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical); |
---|
[10081] | 327 | |
---|
| 328 | |
---|
[10098] | 329 | this->trail = new Trail( 10, 10, .2, this); |
---|
[10095] | 330 | //this->trail->setParent( this); |
---|
[10081] | 331 | this->trail->setTexture( "maps/engine.png"); |
---|
| 332 | |
---|
[10098] | 333 | this->trailL = new Trail( 10, 10, .2, this); |
---|
[10095] | 334 | //this->trailL->setParent( this); |
---|
[10081] | 335 | this->trailL->setTexture( "maps/engine.png"); |
---|
| 336 | |
---|
[10098] | 337 | this->trailR = new Trail( 10, 10, .2, this); |
---|
[10095] | 338 | //this->trailR->setParent( this); |
---|
[10081] | 339 | this->trailR->setTexture( "maps/engine.png"); |
---|
[10098] | 340 | |
---|
| 341 | |
---|
| 342 | this->toList(OM_GROUP_00); |
---|
[6868] | 343 | } |
---|
| 344 | |
---|
| 345 | |
---|
| 346 | /** |
---|
| 347 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 348 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 349 | */ |
---|
| 350 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 351 | { |
---|
| 352 | Playable::loadParams(root); |
---|
[10032] | 353 | |
---|
| 354 | LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML); |
---|
[6868] | 355 | } |
---|
| 356 | |
---|
[10032] | 357 | |
---|
[10017] | 358 | void SpaceShip::setPlayDirection(const Quaternion& rot, float speed) |
---|
[7056] | 359 | { |
---|
[10032] | 360 | //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
[7056] | 361 | } |
---|
[6868] | 362 | |
---|
[7085] | 363 | void SpaceShip::reset() |
---|
| 364 | { |
---|
[10017] | 365 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
[7056] | 366 | |
---|
[10017] | 367 | //xMouse = yMouse = 0; |
---|
[7085] | 368 | |
---|
| 369 | this->setHealth(80); |
---|
| 370 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
[6868] | 374 | void SpaceShip::enter() |
---|
| 375 | { |
---|
[10004] | 376 | this->secWeaponMan.showCrosshair(); |
---|
[10095] | 377 | this->toList( OM_GROUP_01 ); |
---|
[10109] | 378 | |
---|
[10095] | 379 | for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++) |
---|
[10078] | 380 | { |
---|
[10095] | 381 | if( likely( dynamic_cast<Weapon*>(*it) != NULL)) |
---|
[10098] | 382 | dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_01); |
---|
[10109] | 383 | } |
---|
[10004] | 384 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true); |
---|
[10019] | 385 | //this->attachCamera(); |
---|
[10032] | 386 | // this->setPlaymode(Playable::Horizontal); |
---|
[6868] | 387 | } |
---|
| 388 | |
---|
| 389 | void SpaceShip::leave() |
---|
| 390 | { |
---|
[10004] | 391 | this->secWeaponMan.hideCrosshair(); |
---|
[10095] | 392 | this->toList( OM_GROUP_00); |
---|
[10109] | 393 | |
---|
[10095] | 394 | for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++) |
---|
[10078] | 395 | { |
---|
[10095] | 396 | if( likely( dynamic_cast<Weapon*>(*it) != NULL)) |
---|
[10098] | 397 | dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00); |
---|
[10109] | 398 | } |
---|
[10004] | 399 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false); |
---|
[10019] | 400 | //this->detachCamera(); |
---|
[6868] | 401 | } |
---|
| 402 | |
---|
| 403 | |
---|
| 404 | /** |
---|
| 405 | * effect that occurs after the SpaceShip is spawned |
---|
| 406 | */ |
---|
| 407 | void SpaceShip::postSpawn () |
---|
| 408 | { |
---|
| 409 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | /** |
---|
| 413 | * the action occuring if the spaceship left the game |
---|
| 414 | */ |
---|
| 415 | void SpaceShip::leftWorld () |
---|
[10073] | 416 | { |
---|
| 417 | |
---|
[10064] | 418 | } |
---|
[6868] | 419 | |
---|
| 420 | WorldEntity* ref = NULL; |
---|
| 421 | /** |
---|
| 422 | * this function is called, when two entities collide |
---|
| 423 | * @param entity: the world entity with whom it collides |
---|
| 424 | * |
---|
| 425 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 426 | */ |
---|
| 427 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 428 | { |
---|
[10081] | 429 | PRINTF(0)("SPACESHIP COLLIDED WITH %s\n",entity->getCName()); |
---|
[6868] | 430 | } |
---|
| 431 | |
---|
| 432 | /** |
---|
| 433 | * draws the spaceship after transforming it. |
---|
| 434 | */ |
---|
| 435 | void SpaceShip::draw () const |
---|
| 436 | { |
---|
| 437 | WorldEntity::draw(); |
---|
| 438 | |
---|
[10081] | 439 | glMatrixMode(GL_MODELVIEW); |
---|
| 440 | glPushMatrix(); |
---|
| 441 | |
---|
| 442 | float matrix[4][4]; |
---|
| 443 | glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z); |
---|
| 444 | this->getAbsDir().matrix (matrix); |
---|
| 445 | glMultMatrixf((float*)matrix); |
---|
| 446 | //glScalef(2.0, 2.0, 2.0); // no double rescale |
---|
| 447 | |
---|
| 448 | this->trail->draw(); |
---|
| 449 | |
---|
| 450 | glTranslatef(0,0,-.5); |
---|
| 451 | this->trailL->draw(); |
---|
| 452 | |
---|
| 453 | glTranslatef(0,0,1); |
---|
| 454 | this->trailR->draw(); |
---|
| 455 | glPopMatrix(); |
---|
[6868] | 456 | //this->debug(0); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | /** |
---|
| 460 | * the function called for each passing timeSnap |
---|
| 461 | * @param time The timespan passed since last update |
---|
| 462 | */ |
---|
| 463 | void SpaceShip::tick (float time) |
---|
| 464 | { |
---|
[9961] | 465 | // Playable::tick(time);$ |
---|
[6868] | 466 | |
---|
[9961] | 467 | // Own Tick Setup, as a different fire routine is used on the weapon manager |
---|
[9965] | 468 | this->weaponMan.tick(time); |
---|
[9961] | 469 | this->secWeaponMan.tick(time); |
---|
| 470 | |
---|
[10020] | 471 | if( this->systemFailure() ) |
---|
| 472 | bFire = bSecFire = false; |
---|
| 473 | |
---|
[10037] | 474 | // fire reqeust/release for primary weapons |
---|
[9965] | 475 | if( this->bFire) |
---|
| 476 | this->weaponMan.fire(); |
---|
[10036] | 477 | else |
---|
| 478 | this->weaponMan.releaseFire(); |
---|
| 479 | |
---|
[10037] | 480 | // fire reqeust/release for secondary weapons |
---|
[9961] | 481 | if( this->bSecFire) |
---|
| 482 | this->secWeaponMan.fire(); |
---|
[10036] | 483 | else |
---|
| 484 | this->secWeaponMan.releaseFire(); |
---|
[10096] | 485 | |
---|
| 486 | // Tracktick |
---|
| 487 | if(this->entityTrack) |
---|
| 488 | this->entityTrack->tick(time); |
---|
[9961] | 489 | |
---|
[9970] | 490 | |
---|
| 491 | // Shield Regeneration and other regular calculations on the ship |
---|
| 492 | this->regen(time); |
---|
| 493 | |
---|
| 494 | // Weapon Regeneration and other regular calculations on the ship |
---|
[9965] | 495 | this->weaponRegen(time); |
---|
| 496 | |
---|
[9970] | 497 | // current engine speed output |
---|
| 498 | this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare; |
---|
| 499 | |
---|
[10043] | 500 | // calculation of maxSpeed and acceleration: |
---|
| 501 | this->travelSpeed = this->engineSpeedCur * 5; |
---|
| 502 | this->acceleration = this->travelSpeed * 2; |
---|
[9970] | 503 | |
---|
[10017] | 504 | this->movement(time); |
---|
| 505 | |
---|
| 506 | // TRYING TO FIX PNode. |
---|
| 507 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
| 508 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
| 509 | |
---|
[10095] | 510 | |
---|
| 511 | this->velocity = (this->getAbsCoor() - this->oldPos) / time; |
---|
| 512 | this->oldPos = this->getAbsCoor(); |
---|
| 513 | |
---|
[10081] | 514 | this->trail->tick(time); |
---|
| 515 | this->trailL->tick(time); |
---|
| 516 | this->trailR->tick(time); |
---|
[10095] | 517 | |
---|
[6868] | 518 | //orient the spaceship in direction of the mouse |
---|
[10017] | 519 | /* |
---|
[9869] | 520 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
| 521 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6868] | 522 | this->setAbsDir( rotQuat); |
---|
[9869] | 523 | //this->setAbsDirSoft(mouseDir,5); |
---|
[10017] | 524 | */ |
---|
[6868] | 525 | |
---|
| 526 | // this is the air friction (necessary for a smooth control) |
---|
[10017] | 527 | /* |
---|
[6868] | 528 | if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; |
---|
| 529 | else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; |
---|
[10017] | 530 | */ |
---|
[6868] | 531 | |
---|
| 532 | //other physics (gravity) |
---|
| 533 | //if(travelSpeed < 120) |
---|
| 534 | //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; |
---|
| 535 | |
---|
| 536 | //hoover effect |
---|
| 537 | //cycle += time; |
---|
| 538 | //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
| 539 | |
---|
| 540 | //readjust |
---|
| 541 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 542 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 543 | |
---|
| 544 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 545 | |
---|
[10017] | 546 | /* |
---|
[6868] | 547 | this->shiftCoor(move); |
---|
[10017] | 548 | */ |
---|
[6868] | 549 | |
---|
[9869] | 550 | // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); |
---|
[6868] | 551 | |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /** |
---|
| 555 | * @todo switch statement ?? |
---|
| 556 | */ |
---|
| 557 | void SpaceShip::process(const Event &event) |
---|
| 558 | { |
---|
[9961] | 559 | //Playable::process(event); |
---|
[6868] | 560 | |
---|
| 561 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[10017] | 562 | this->bLeft = event.bPressed; |
---|
[6868] | 563 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[10017] | 564 | this->bRight = event.bPressed; |
---|
[6997] | 565 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[10017] | 566 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 567 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[10017] | 568 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[9961] | 569 | else if( event.type == KeyMapper::PEV_FIRE2) |
---|
| 570 | this->bSecFire = event.bPressed; |
---|
[9958] | 571 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
[9965] | 572 | this->bFire = event.bPressed; |
---|
[10017] | 573 | |
---|
| 574 | |
---|
| 575 | /* |
---|
[6868] | 576 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 577 | { |
---|
[9961] | 578 | |
---|
[6868] | 579 | this->xMouse += event.xRel; |
---|
| 580 | this->yMouse += event.yRel; |
---|
| 581 | } |
---|
[10017] | 582 | */ |
---|
[6868] | 583 | } |
---|
| 584 | |
---|
[9235] | 585 | void SpaceShip::destroy( WorldEntity* killer ) |
---|
[9008] | 586 | { |
---|
[10107] | 587 | PRINTF(5)("spaceship destroy\n"); |
---|
[10095] | 588 | |
---|
[10073] | 589 | EmitterNode* node = NULL; |
---|
| 590 | DotEmitter* emitter = NULL; |
---|
| 591 | SpriteParticles* explosionParticles = NULL; |
---|
[10064] | 592 | |
---|
[10107] | 593 | explosionParticles = new SpriteParticles(200); |
---|
| 594 | explosionParticles->setName("SpaceShipExplosionParticles"); |
---|
| 595 | explosionParticles->setLifeSpan(.2, .3); |
---|
[10073] | 596 | explosionParticles->setRadius(0.0, 10.0); |
---|
| 597 | explosionParticles->setRadius(.5, 6.0); |
---|
| 598 | explosionParticles->setRadius(1.0, 3.0); |
---|
[10098] | 599 | explosionParticles->setColor(0.0, 1,1,1,.9); |
---|
| 600 | explosionParticles->setColor(0.1, 1,1,0,.9); |
---|
| 601 | explosionParticles->setColor(0.5, .8,.4,0,.5); |
---|
[10107] | 602 | explosionParticles->setColor(1.0, .2,.2,.2,.5); |
---|
[10064] | 603 | |
---|
[10073] | 604 | |
---|
[10107] | 605 | emitter = new DotEmitter( 2000, 70, 360); |
---|
| 606 | //emitter->setSpread( 0, M_2_PI); |
---|
| 607 | emitter->setEmissionRate( 200.0); |
---|
[10098] | 608 | //emitter->setEmissionVelocity( 200.0); |
---|
[10107] | 609 | //emitter->setSystem( explosionParticles); |
---|
| 610 | //emitter->setAbsCoor( this->getAbsCoor()); |
---|
[10064] | 611 | |
---|
[10107] | 612 | node = new EmitterNode( .1f); |
---|
[10073] | 613 | node->setupParticle( emitter, explosionParticles); |
---|
[10107] | 614 | node->setAbsDir( this->getAbsDir()); |
---|
| 615 | node->setVelocity( this->getVelocity() * .9f); |
---|
[10073] | 616 | node->setAbsCoor( this->getAbsCoor()); |
---|
[10107] | 617 | if( !node->start()) |
---|
| 618 | PRINTF(0)("Explosion node not correctly started!"); |
---|
| 619 | |
---|
[10095] | 620 | /* |
---|
[10081] | 621 | PNode* node = new PNode(); |
---|
| 622 | node->setAbsCoor(this->getAbsCoor()); |
---|
| 623 | Explosion* explosion = new Explosion(); |
---|
| 624 | explosion->explode( node, Vector(5,5,5)); |
---|
[10095] | 625 | */ |
---|
[10073] | 626 | |
---|
[10107] | 627 | if( this->hasPlayer()) |
---|
| 628 | { |
---|
| 629 | this->setAbsCoor(Vector(-10000,10000,10000)); |
---|
| 630 | this->hide(); |
---|
| 631 | } |
---|
| 632 | else |
---|
| 633 | { |
---|
| 634 | this->setAbsCoor( this->getAbsCoor() + Vector(150,0,0) + Vector(1,0,0) * VECTOR_RAND(50).dot(Vector(1,0,0))); |
---|
| 635 | } |
---|
| 636 | |
---|
[9008] | 637 | } |
---|
[6868] | 638 | |
---|
[9008] | 639 | void SpaceShip::respawn( ) |
---|
| 640 | { |
---|
[10107] | 641 | this->unhide(); |
---|
[10081] | 642 | /*for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++) |
---|
| 643 | { |
---|
| 644 | if( dynamic_cast<WorldEntity*>(*it) != NULL) |
---|
| 645 | dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00); |
---|
| 646 | }*/ |
---|
[10098] | 647 | /* |
---|
[10095] | 648 | if( this->hasPlayer()) |
---|
| 649 | { |
---|
[10081] | 650 | this->toList( OM_GROUP_01); |
---|
[10095] | 651 | for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++) |
---|
| 652 | { |
---|
| 653 | if( likely( dynamic_cast<Weapon*>(*it) != NULL)) |
---|
| 654 | dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00_PROJ); |
---|
| 655 | } |
---|
| 656 | } |
---|
[10081] | 657 | else |
---|
[10095] | 658 | { |
---|
| 659 | this->toList( OM_GROUP_00); |
---|
| 660 | for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++) |
---|
| 661 | { |
---|
| 662 | if( likely( dynamic_cast<Weapon*>(*it) != NULL)) |
---|
| 663 | dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_01_PROJ); |
---|
| 664 | } |
---|
[10098] | 665 | }*/ |
---|
[10081] | 666 | |
---|
[9008] | 667 | } |
---|
[6868] | 668 | |
---|
| 669 | |
---|
[9957] | 670 | void SpaceShip::damage(float pDamage, float eDamage){ |
---|
[10081] | 671 | PRINTF(0)("ship hit for (%f,%f) \n",pDamage,eDamage); |
---|
| 672 | |
---|
[10064] | 673 | if( this->shieldActive) { |
---|
[9950] | 674 | if( this->shieldCur > pDamage) { |
---|
| 675 | this->shieldCur = this->shieldCur - pDamage; |
---|
| 676 | } |
---|
| 677 | else { // shield <= pDamage |
---|
[9987] | 678 | this->shieldCur -=pDamage; |
---|
| 679 | this->shieldActive = false; //shield collapses |
---|
[10081] | 680 | pDamage += this->shieldCur; |
---|
[9950] | 681 | if( !this->shieldActive) { |
---|
[9957] | 682 | this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate |
---|
[9953] | 683 | this->electronicCur -= eDamage; |
---|
[9950] | 684 | } |
---|
| 685 | } |
---|
| 686 | } |
---|
| 687 | else { |
---|
| 688 | this->armorCur = this->armorCur - pDamage; |
---|
| 689 | this->electronicCur = this->electronicCur - eDamage; |
---|
| 690 | } |
---|
| 691 | if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } |
---|
[10064] | 692 | this->destroy(this); |
---|
[9950] | 693 | } |
---|
| 694 | |
---|
[9987] | 695 | |
---|
[9957] | 696 | void SpaceShip::regen(float time){ |
---|
| 697 | float tmp; |
---|
[9963] | 698 | if (this->armorCur != this->armorMax || this->armorRegen != 0){ |
---|
| 699 | tmp = this->armorCur + this->armorRegen * time; |
---|
| 700 | if ( tmp > electronicMax) |
---|
| 701 | this->armorCur = this->armorMax; |
---|
| 702 | else |
---|
| 703 | this->armorCur = tmp; |
---|
| 704 | } |
---|
| 705 | if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ |
---|
[9970] | 706 | tmp = this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time; |
---|
[9957] | 707 | if( tmp > shieldMax) |
---|
[9953] | 708 | this->shieldCur = this->shieldMax; |
---|
| 709 | else |
---|
[9957] | 710 | this->shieldCur = tmp; |
---|
| 711 | this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); |
---|
[9953] | 712 | } |
---|
[9970] | 713 | |
---|
| 714 | this->setHealth( this->shieldCur); // FIXME currently just to test share system |
---|
| 715 | |
---|
[9963] | 716 | if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ |
---|
[9957] | 717 | tmp = this->electronicCur + this->electronicRegen * time; |
---|
| 718 | if ( tmp > electronicMax) |
---|
[9953] | 719 | this->electronicCur = this->electronicMax; |
---|
| 720 | else |
---|
[9957] | 721 | this->electronicCur = tmp; |
---|
[9953] | 722 | } |
---|
[9950] | 723 | } |
---|
[9965] | 724 | |
---|
[9987] | 725 | |
---|
[9965] | 726 | /** |
---|
| 727 | * Weapon regeneration |
---|
| 728 | * does not use any reactor capacity, as it wouldn't work in a consistent way. |
---|
| 729 | */ |
---|
| 730 | void SpaceShip::weaponRegen(float time) |
---|
| 731 | { |
---|
| 732 | float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; |
---|
| 733 | Weapon* weapon; |
---|
[9987] | 734 | for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) |
---|
[9965] | 735 | { |
---|
| 736 | weapon = this->weaponMan.getWeapon(i); |
---|
| 737 | if( weapon != NULL && weapon->isActive()) |
---|
| 738 | { |
---|
| 739 | weapon->increaseEnergy( energy); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | } |
---|
| 743 | // weaponMan.increaseAmmunition( weapon, energy); |
---|
| 744 | } |
---|
[9975] | 745 | |
---|
[9987] | 746 | |
---|
[9975] | 747 | void SpaceShip::enterPlaymode(Playable::Playmode playmode) |
---|
| 748 | { |
---|
[10017] | 749 | switch(playmode) |
---|
| 750 | { |
---|
| 751 | case Playable::Full3D: |
---|
| 752 | /* |
---|
| 753 | if (State::getCameraNode != NULL) |
---|
| 754 | { |
---|
| 755 | Vector absCoor = this->getAbsCoor(); |
---|
| 756 | this->setParent(PNode::getNullParent()); |
---|
| 757 | this->setAbsCoor(absCoor); |
---|
| 758 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 759 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 760 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
| 761 | State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); |
---|
| 762 | |
---|
| 763 | } |
---|
| 764 | */ |
---|
| 765 | //break; |
---|
| 766 | |
---|
[10032] | 767 | break; |
---|
| 768 | case Playable::Horizontal: |
---|
[10017] | 769 | if (State::getCameraNode != NULL) |
---|
| 770 | { |
---|
| 771 | this->debugNode(1); |
---|
| 772 | this->travelNode->debugNode(1); |
---|
| 773 | |
---|
| 774 | this->travelNode->setAbsCoor(this->getAbsCoor()); |
---|
| 775 | this->travelNode->updateNode(0.01f); |
---|
| 776 | |
---|
[10098] | 777 | this->setParent(this->travelNode); |
---|
[10017] | 778 | this->setRelCoor(0,0,0); |
---|
| 779 | |
---|
[10098] | 780 | State::getCameraNode()->setParentSoft(this->travelNode); |
---|
| 781 | //State::getCameraNode()->setParentSoft(this); |
---|
[10032] | 782 | State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0); |
---|
[10098] | 783 | State::getCameraTargetNode()->setParentSoft(this->travelNode); |
---|
| 784 | //State::getCameraTargetNode()->setParentSoft(this); |
---|
[10019] | 785 | State::getCameraTargetNode()->setRelCoorSoft(0,0,0); |
---|
[10017] | 786 | |
---|
| 787 | this->debugNode(1); |
---|
| 788 | this->travelNode->debugNode(1); |
---|
| 789 | } |
---|
| 790 | break; |
---|
| 791 | |
---|
| 792 | default: |
---|
| 793 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
| 794 | } |
---|
[9975] | 795 | } |
---|
| 796 | |
---|
[10017] | 797 | /** |
---|
| 798 | * @brief calculate the velocity |
---|
| 799 | * @param time the timeslice since the last frame |
---|
| 800 | */ |
---|
[9987] | 801 | |
---|
[9975] | 802 | void SpaceShip::movement (float dt) |
---|
| 803 | { |
---|
[10019] | 804 | //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so |
---|
| 805 | //the ship doesn't slide too much. |
---|
| 806 | float airCoeff = 2.5; |
---|
| 807 | float pi = 3.14; |
---|
[10098] | 808 | |
---|
[10017] | 809 | |
---|
[10032] | 810 | switch(this->getPlaymode()) |
---|
[10017] | 811 | { |
---|
[10032] | 812 | case Playable::Horizontal: |
---|
[10017] | 813 | { |
---|
[10032] | 814 | // these routines will change the travel movement into zero in a short amout of time, if the player |
---|
| 815 | // doesn't press any buttons. |
---|
[10098] | 816 | if (this->travelVelocity.x >= 0) |
---|
[10017] | 817 | { |
---|
[10098] | 818 | if (this->travelVelocity.x > airCoeff*this->acceleration * dt) |
---|
| 819 | this->travelVelocity.x -= airCoeff* this->acceleration * dt; |
---|
[10032] | 820 | else |
---|
[10098] | 821 | this->travelVelocity.x = 0; |
---|
[10017] | 822 | } |
---|
| 823 | else |
---|
| 824 | { |
---|
[10098] | 825 | if (this->travelVelocity.x < -airCoeff*this->acceleration * dt) |
---|
| 826 | this->travelVelocity.x += airCoeff* this->acceleration * dt; |
---|
[10032] | 827 | else |
---|
[10098] | 828 | this->travelVelocity.x = 0; |
---|
[10017] | 829 | } |
---|
[10098] | 830 | if (this->travelVelocity.z >= 0) |
---|
[10017] | 831 | { |
---|
[10098] | 832 | if (this->travelVelocity.z > airCoeff*this->acceleration * dt) |
---|
| 833 | this->travelVelocity.z -= airCoeff* this->acceleration * dt; |
---|
[10032] | 834 | else |
---|
[10098] | 835 | this->travelVelocity.z = 0; |
---|
[10017] | 836 | } |
---|
| 837 | else |
---|
| 838 | { |
---|
[10098] | 839 | if (this->travelVelocity.z < -airCoeff*this->acceleration * dt) |
---|
| 840 | this->travelVelocity.z += airCoeff* this->acceleration * dt; |
---|
[10032] | 841 | else |
---|
[10098] | 842 | this->travelVelocity.z = 0; |
---|
[10017] | 843 | } |
---|
[10032] | 844 | |
---|
| 845 | // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons |
---|
| 846 | // and its continuing to slide a bit. |
---|
| 847 | Vector oldCoor = this->getRelCoor(); |
---|
| 848 | if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z); |
---|
| 849 | if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z); |
---|
| 850 | if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y); |
---|
| 851 | if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y); |
---|
| 852 | |
---|
| 853 | if( this->systemFailure() ) |
---|
| 854 | bForward = bBackward = bLeft = bRight = false; |
---|
| 855 | |
---|
| 856 | if( this->bForward ) |
---|
[10019] | 857 | { |
---|
[10032] | 858 | if(this->getRelCoor().x < this->travelDistancePlus.x) |
---|
| 859 | { |
---|
[10098] | 860 | if (this->travelVelocity.x < this->travelSpeed) |
---|
[10032] | 861 | { |
---|
[10098] | 862 | this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10032] | 863 | } |
---|
| 864 | else |
---|
| 865 | { |
---|
[10098] | 866 | this->travelVelocity.x = this->travelSpeed; |
---|
[10032] | 867 | } |
---|
| 868 | } |
---|
| 869 | else |
---|
| 870 | { |
---|
[10098] | 871 | this->travelVelocity.x = 0.0f; |
---|
[10032] | 872 | } |
---|
[10019] | 873 | } |
---|
[10032] | 874 | |
---|
| 875 | if( this->bBackward ) |
---|
[10019] | 876 | { |
---|
[10032] | 877 | if(this->getRelCoor().x > this->travelDistanceMinus.x) |
---|
| 878 | { |
---|
[10098] | 879 | if (this->travelVelocity.x > -this->travelSpeed) |
---|
[10032] | 880 | { |
---|
[10098] | 881 | this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10032] | 882 | } |
---|
| 883 | else |
---|
| 884 | { |
---|
[10098] | 885 | this->travelVelocity.x = -this->travelSpeed; |
---|
[10032] | 886 | } |
---|
| 887 | } |
---|
| 888 | else |
---|
| 889 | { |
---|
[10098] | 890 | this->travelVelocity.x = 0.0f; |
---|
[10032] | 891 | } |
---|
[10019] | 892 | } |
---|
[10032] | 893 | |
---|
| 894 | if( this->bLeft) |
---|
[10019] | 895 | { |
---|
[10032] | 896 | if(this->getRelCoor().z > this->travelDistanceMinus.y) |
---|
| 897 | { |
---|
[10098] | 898 | if (this->travelVelocity.z > -this->travelSpeed) |
---|
[10032] | 899 | { |
---|
[10098] | 900 | this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10032] | 901 | } |
---|
| 902 | else |
---|
| 903 | { |
---|
[10098] | 904 | this->travelVelocity.z = -this->travelSpeed; |
---|
[10032] | 905 | } |
---|
| 906 | } |
---|
| 907 | else |
---|
| 908 | { |
---|
[10098] | 909 | this->travelVelocity.z = 0.0f; |
---|
[10032] | 910 | } |
---|
[10043] | 911 | this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6); |
---|
[10019] | 912 | } |
---|
[10032] | 913 | |
---|
| 914 | if( this->bRight) |
---|
[10019] | 915 | { |
---|
[10032] | 916 | if(this->getRelCoor().z < this->travelDistancePlus.y) |
---|
| 917 | { |
---|
[10098] | 918 | if (this->travelVelocity.z < this->travelSpeed) |
---|
[10032] | 919 | { |
---|
[10098] | 920 | this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt; |
---|
[10032] | 921 | } |
---|
| 922 | else |
---|
| 923 | { |
---|
[10098] | 924 | this->travelVelocity.z = this->travelSpeed; |
---|
[10032] | 925 | } |
---|
| 926 | } |
---|
| 927 | else |
---|
| 928 | { |
---|
[10098] | 929 | this->travelVelocity.z = 0.0f; |
---|
[10032] | 930 | } |
---|
[10043] | 931 | this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6); |
---|
[10019] | 932 | } |
---|
[10032] | 933 | if (!this->bRight && !this->bLeft) |
---|
| 934 | { |
---|
[10043] | 935 | this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6); |
---|
[10032] | 936 | } |
---|
| 937 | |
---|
[10043] | 938 | //normalisation of the vectors (vector sum must be <= travelspeed) |
---|
[10098] | 939 | float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2)); |
---|
[10043] | 940 | if (xzNorm > this->travelSpeed) |
---|
| 941 | { |
---|
[10098] | 942 | this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed; |
---|
| 943 | this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed; |
---|
[10043] | 944 | } |
---|
[10032] | 945 | |
---|
[10099] | 946 | //this moves camera and ship along the travel path. |
---|
[10043] | 947 | this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); |
---|
[10099] | 948 | |
---|
[10043] | 949 | break; |
---|
[10019] | 950 | } |
---|
[10032] | 951 | case Playable::Vertical: |
---|
| 952 | break; |
---|
[10017] | 953 | default: |
---|
[10032] | 954 | PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
[10017] | 955 | } |
---|
[10099] | 956 | //set new coordinates calculated through key- events. |
---|
[10098] | 957 | this->shiftCoor (this->travelVelocity * dt); |
---|
[9975] | 958 | } |
---|
[10017] | 959 | |
---|
[10032] | 960 | void SpaceShip::setPlaymodeXML(const std::string& playmode) |
---|
| 961 | { |
---|
| 962 | this->setPlaymode(Playable::stringToPlaymode(playmode)); |
---|
| 963 | } |
---|
| 964 | |
---|