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