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