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