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