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