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