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