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