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