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