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