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