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