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