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