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