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