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