/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Knecht co-programmer: Silvan Nellen */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY #include "executor/executor.h" #include "space_ship.h" #include "util/loading/resource_manager.h" #include "weapons/test_gun.h" #include "weapons/light_blaster.h" #include "weapons/medium_blaster.h" #include "weapons/heavy_blaster.h" #include "weapons/swarm_missile.h" #include "weapons/boomerang_gun.h" #include "weapons/turret.h" #include "weapons/cannon.h" #include "particles/dot_emitter.h" #include "particles/sprite_particles.h" #include "util/loading/factory.h" #include "key_mapper.h" #include "network_game_manager.h" #include "shared_network_data.h" #include "power_ups/weapon_power_up.h" #include "power_ups/param_power_up.h" #include "graphics_engine.h" #include "plane.h" #include "state.h" #include "player.h" #include "util/loading/load_param.h" #include "time.h" // #include "lib/gui/gl_gui/glgui_bar.h" // #include "lib/gui/gl_gui/glgui_pushbutton.h" #include "class_id_DEPRECATED.h" ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); CREATE_FACTORY(SpaceShip); #include "script_class.h" CREATE_SCRIPTABLE_CLASS(SpaceShip, addMethod("hasPlayer", Executor0ret(&Playable::hasPlayer)) ->addMethod("fire", Executor1(&Playable::fire)) ->addMethod("loadModel", Executor2(&WorldEntity::loadModel2)) ->addMethod("setName", Executor1(&BaseObject::setName)) ->addMethod("hide", Executor0(&WorldEntity::hide)) ->addMethod("unhide", Executor0(&WorldEntity::unhide)) //Coordinates ->addMethod("setAbsCoor", Executor3(&PNode::setAbsCoor)) ->addMethod("getAbsCoorX", Executor0ret(&PNode::getAbsCoorX)) ->addMethod("getAbsCoorY", Executor0ret(&PNode::getAbsCoorY)) ->addMethod("getAbsCoorZ", Executor0ret(&PNode::getAbsCoorZ)) //->addMethod("setCameraSpeed", Executor1(&SpaceShip::setCameraSpeed)) ); /** * destructs the spaceship, deletes alocated memory */ SpaceShip::~SpaceShip () { this->setPlayer(NULL); } /** * loads a Spaceships information from a specified file. * @param fileName the name of the File to load the spaceship from (absolute path) */ SpaceShip::SpaceShip(const std::string& fileName) : secWeaponMan(this) //, //supportedPlaymodes(Playable::Vertical) , //playmode(Playable::Vertical) { this->init(); TiXmlDocument doc(fileName); if(!doc.LoadFile()) { PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); return; } this->loadParams(doc.RootElement()); } /** * creates a new Spaceship from Xml Data * @param root the xml element containing spaceship data @todo add more parameters to load */ SpaceShip::SpaceShip(const TiXmlElement* root) : secWeaponMan(this) //, //supportedPlaymodes(Playable::Vertical) , //playmode(Playable::Vertical) { this->init(); if (root != NULL) this->loadParams(root); } /** * initializes a Spaceship */ void SpaceShip::init() { this->setSupportedPlaymodes(Playable::Vertical); // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); this->registerObject(this, SpaceShip::_objectList); PRINTF(4)("SPACESHIP INIT\n"); secWeaponMan.showCrosshair(); //weapons: Weapon* wpRight1 = new LightBlaster (); wpRight1->setName("Light Blaster Right"); Weapon* wpLeft1 = new LightBlaster (); wpLeft1->setName("Medium Blaster Left"); Weapon* wpRight2 = new MediumBlaster (); wpRight2->setName("Medium Blaster Right"); Weapon* wpLeft2 = new MediumBlaster (); wpLeft2->setName("Medium Blaster Left"); Weapon* wpRight3 = new HeavyBlaster (); wpRight3->setName("Heavy Blaster Right"); Weapon* wpLeft3 = new HeavyBlaster (); wpLeft3->setName("Heavy Blaster Left"); Weapon* cannon = new SwarmMissile(); cannon->setName("Swarm Missile"); this->weaponMan.addWeapon( wpLeft1, 0, 0); this->weaponMan.addWeapon( wpRight1, 0, 1); this->weaponMan.addWeapon( wpLeft2, 0, 2); this->weaponMan.addWeapon( wpRight2, 0, 3); this->weaponMan.addWeapon( wpLeft3, 0, 4); this->weaponMan.addWeapon( wpRight3, 0, 5); this->secWeaponMan.addWeapon( cannon, 0, 0); this->weaponMan.changeWeaponConfig(0); wpRight1->requestAction(WA_ACTIVATE); wpLeft1->requestAction(WA_ACTIVATE); wpRight2->requestAction(WA_ACTIVATE); wpLeft2->requestAction(WA_ACTIVATE); wpRight3->requestAction(WA_ACTIVATE); wpLeft3->requestAction(WA_ACTIVATE); cannon->requestAction(WA_ACTIVATE); curWeaponPrimary = 0; curWeaponSecondary = 0; Playable::weaponConfigChanged(); reactorOutput = 10; weaponEnergyRegen = 10; // 10 einheiten pro Sekunde engineSpeedBase = 5; shieldRegen = 2; shieldEnergyShare = 0.3; weaponEnergyShare = 0.3; engineEnergyShare = 0.4; shieldCur = 20; shieldMax = 100; shieldTH = .2* shieldMax; // shield power must be 20% before shield kicks in again electronicCur = 10; electronicMax = 50; electronicRegen = 3; electronicTH = .7 * electronicMax; // 30% of eDamage can be handled by the ship /* this->addWeapon(wpLeft, 1, 0); this->addWeapon(wpRight,1 ,1); //this->addWeapon(cannon, 0, 6); this->getWeaponManager().changeWeaponConfig(1); */ this->loadModel("models/ships/mantawing.obj"); //this->setVisibiliy(false); bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; /* xMouse = yMouse = 0; yInvert = 1; mouseSensitivity = 0.001; airViscosity = 0.9; controlVelocityX = 25; controlVelocityY = 150; shipInertia = 1.5; */ // cycle = 0.0; this->setHealthMax(shieldMax); this->setHealth(shieldCur); this->travelNode = new PNode(); // camera - issue //this->cameraNode = State::getCameraNode(); this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); /* this->velocity = this->getAbsDirX()*travelSpeed; this->mouseDir = this->getAbsDir(); this->pitchDir = this->getAbsDir(); */ // GLGuiButton* button = new GLGuiPushButton(); // button->show(); // button->setLabel("orxonox"); // button->setBindNode(this); // GLGuiBar* bar = new GLGuiBar(); // bar->show(); // bar->setValue(7.0); // bar->setMaximum(10); // bar->setSize2D( 20, 100); // bar->setAbsCoor2D( 10, 200); //add events to the eventlist registerEvent(KeyMapper::PEV_FORWARD); registerEvent(KeyMapper::PEV_BACKWARD); registerEvent(KeyMapper::PEV_LEFT); registerEvent(KeyMapper::PEV_RIGHT); //registerEvent(SDLK_q); //registerEvent(SDLK_e); registerEvent(KeyMapper::PEV_FIRE1); registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support registerEvent(KeyMapper::PEV_NEXT_WEAPON); registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); //registerEvent(SDLK_PAGEUP); //registerEvent(SDLK_PAGEDOWN); registerEvent(EV_MOUSE_MOTION); this->weaponMan.setSlotCount(6); this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0)); this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0)); this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5)); this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5)); this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); this->weaponMan.setSlotPosition(4, Vector(-1.5, -.5, .5)); this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); this->weaponMan.setSlotPosition(5, Vector(-1.5, -.5, -.5)); this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); this->secWeaponMan.setSlotCount(6); this->secWeaponMan.setSlotPosition(0, Vector(1.5, -1, 0)); this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->secWeaponMan.setSlotPosition(1, Vector(2.6, .1, 3.0)); this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->secWeaponMan.setSlotPosition(2, Vector(1.5, .5, -.5)); this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); this->secWeaponMan.setSlotPosition(3, Vector(1.5, .5, .5)); this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); this->secWeaponMan.setSlotPosition(4, Vector(1.5, -.5, .5)); this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); this->secWeaponMan.setSlotPosition(5, Vector(1.5, -.5, -.5)); this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); // // this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); // this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); // // this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); // this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: this->weaponMan.getFixedTarget()->setParent(this); this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); this->secWeaponMan.getFixedTarget()->setParent(this); this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); this->secWeaponMan.setRotationSpeed(0); dynamic_cast(this->weaponMan.getFixedTarget())->setVisibility( false); this->burstEmitter = new DotEmitter(200, 0.0, .01); this->burstEmitter->setParent(this); this->burstEmitter->setRelCoor(-1, .5, 0); this->burstEmitter->setName("SpaceShip_Burst_emitter"); this->burstSystem = new SpriteParticles(1000); this->burstSystem->addEmitter(this->burstEmitter); this->burstSystem->setName("SpaceShip_Burst_System"); ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); this->burstSystem->setLifeSpan(1.0, .3); this->burstSystem->setRadius(0.0, 1.0); this->burstSystem->setRadius(0.05, 1.0); this->burstSystem->setRadius(.5, .8); this->burstSystem->setRadius(1.0, 0); this->burstSystem->setColor(0.0, .7,.7,1,.7); this->burstSystem->setColor(0.2, 0,0,0.8,.5); this->burstSystem->setColor(0.5, .5,.5,.8,.8); this->burstSystem->setColor(1.0, .8,.8,.8,.0); /* registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); */ registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); //this->airFriction = 0.5f; this->travelDistancePlus = Vector2D(38.0, 43.0); this->travelDistanceMinus = Vector2D(-38.0, -43.0); this->travelSpeed = 80; this->cameraSpeed = 40; this->cameraLook = 0.0f; this->acceleration = 120.0f; //this->airFriction = 0.0f; srand(time(0)); //initaialize RNG this->travelNode->debugDraw(); } /** * loads the Settings of a SpaceShip from an XML-element. * @param root the XML-element to load the Spaceship's properties from */ void SpaceShip::loadParams(const TiXmlElement* root) { Playable::loadParams(root); } void SpaceShip::setPlayDirection(const Quaternion& rot, float speed) { this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); } void SpaceShip::setTravelSpeed(float travelSpeed) { this->travelSpeed = travelSpeed; } /* void SpaceShip::setTravelHeight(float travelHeight) { if (this->toTravelHeight == NULL) this->toTravelHeight = new float; *this->toTravelHeight = travelHeight; } */ /* void SpaceShip::setTravelDistance(const Vector2D& distance) { this->travelDistance = distance; } void SpaceShip::setTravelDistance(float x, float y) { this->setTravelDistance(Vector2D(x, y)); } */ void SpaceShip::reset() { bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; //xMouse = yMouse = 0; this->setHealth(80); this->velocity = Vector(0.0, 0.0, 0.0); } void SpaceShip::enter() { this->secWeaponMan.showCrosshair(); //dynamic_cast(this->secWeaponMan.getFixedTarget())->setVisibility( true); if (!this->setPlaymode(Playable::Vertical)) std::cout << "playmode not supported"; //this->attachCamera(); } void SpaceShip::leave() { this->secWeaponMan.hideCrosshair(); //dynamic_cast(this->secWeaponMan.getFixedTarget())->setVisibility( false); //this->detachCamera(); } /** * effect that occurs after the SpaceShip is spawned */ void SpaceShip::postSpawn () { //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); } /** * the action occuring if the spaceship left the game */ void SpaceShip::leftWorld () {} WorldEntity* ref = NULL; /** * this function is called, when two entities collide * @param entity: the world entity with whom it collides * * Implement behaviour like damage application or other miscellaneous collision stuff in this function */ void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) { } /** * draws the spaceship after transforming it. */ void SpaceShip::draw () const { WorldEntity::draw(); //this->debug(0); } /** * the function called for each passing timeSnap * @param time The timespan passed since last update */ void SpaceShip::tick (float time) { // Playable::tick(time);$ // Own Tick Setup, as a different fire routine is used on the weapon manager this->weaponMan.tick(time); this->secWeaponMan.tick(time); if( this->systemFailure() ) bFire = bSecFire = false; if( this->bFire) { this->weaponMan.fire(); } if( this->bSecFire) { this->secWeaponMan.fire(); this->bSecFire = !this->bSecFire; // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed } // Shield Regeneration and other regular calculations on the ship this->regen(time); // Weapon Regeneration and other regular calculations on the ship this->weaponRegen(time); // current engine speed output this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare; /* if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) { if (xMouse > controlVelocityX) xMouse = controlVelocityX; else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; if (yMouse > controlVelocityY) yMouse = controlVelocityY; else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); xMouse = yMouse = 0; } */ // spaceship controlled movement fire(bool bF){ this->bFire = bF;} //if (this->getOwner() == this->getHostID()) //is->calculateVelocity(time); //vector move = velocity*time; /* //orient the velocity in the direction of the spaceship. travelSpeed = velocity.len(); velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; velocity = (velocity.getNormalized())*travelSpeed; */ this->movement(time); // TRYING TO FIX PNode. this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); this->burstEmitter->setEmissionRate(travelSpeed); this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); //orient the spaceship in direction of the mouse /* rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) this->setAbsDir( rotQuat); //this->setAbsDirSoft(mouseDir,5); */ // this is the air friction (necessary for a smooth control) /* if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; */ //other physics (gravity) //if(travelSpeed < 120) //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; //hoover effect //cycle += time; //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); //readjust //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); /* this->shiftCoor(move); */ // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); } /* void SpaceShip::calculateVelocity (float time) { Vector accel(0.0, 0.0, 0.0); /* calculate the direction in which the craft is heading */ /* if( this->bUp ) { accel += (this->getAbsDirX())*acceleration; } if( this->bDown ) { accel -= (this->getAbsDirX())*0.5*acceleration; } if( this->bLeft) { this->shiftDir(Quaternion(time, Vector(0,1,0))); } if( this->bRight) { this->shiftDir(Quaternion(-time, Vector(0,1,0))); } if( this->bRollL) { mouseDir *= Quaternion(-time*2, Vector(1,0,0)); } if( this->bRollR) { mouseDir *= Quaternion(time*2, Vector(1,0,0)); } if (this->bAscend ) { this->shiftDir(Quaternion(time, Vector(0,0,1))); } if (this->bDescend ) { this->shiftDir(Quaternion(-time, Vector(0,0,1))); } velocity += accel*time*10; } */ /** * @todo switch statement ?? */ void SpaceShip::process(const Event &event) { //Playable::process(event); if( event.type == KeyMapper::PEV_LEFT) this->bLeft = event.bPressed; else if( event.type == KeyMapper::PEV_RIGHT) this->bRight = event.bPressed; else if( event.type == KeyMapper::PEV_FORWARD) this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); else if( event.type == KeyMapper::PEV_BACKWARD) this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); else if( event.type == KeyMapper::PEV_FIRE2) this->bSecFire = event.bPressed; else if( event.type == KeyMapper::PEV_FIRE1) this->bFire = event.bPressed; /* else if( event.type == EV_MOUSE_MOTION) { this->xMouse += event.xRel; this->yMouse += event.yRel; } */ } void SpaceShip::destroy( WorldEntity* killer ) { PRINTF(0)("spaceship destroy\n"); } void SpaceShip::respawn( ) { toList( OM_PLAYERS ); } void SpaceShip::damage(float pDamage, float eDamage){ if( this->shieldActive) { if( this->shieldCur > pDamage) { this->shieldCur = this->shieldCur - pDamage; } else { // shield <= pDamage this->shieldCur -=pDamage; this->shieldActive = false; //shield collapses pDamage = pDamage - this->shieldCur; if( !this->shieldActive) { this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate this->electronicCur -= eDamage; } } } else { this->armorCur = this->armorCur - pDamage; this->electronicCur = this->electronicCur - eDamage; } if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } } void SpaceShip::regen(float time){ float tmp; if (this->armorCur != this->armorMax || this->armorRegen != 0){ tmp = this->armorCur + this->armorRegen * time; if ( tmp > electronicMax) this->armorCur = this->armorMax; else this->armorCur = tmp; } if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ tmp = this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time; if( tmp > shieldMax) this->shieldCur = this->shieldMax; else this->shieldCur = tmp; this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); } this->setHealth( this->shieldCur); // FIXME currently just to test share system if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ tmp = this->electronicCur + this->electronicRegen * time; if ( tmp > electronicMax) this->electronicCur = this->electronicMax; else this->electronicCur = tmp; } } /** * Weapon regeneration * does not use any reactor capacity, as it wouldn't work in a consistent way. */ void SpaceShip::weaponRegen(float time) { float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; Weapon* weapon; for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) { weapon = this->weaponMan.getWeapon(i); if( weapon != NULL && weapon->isActive()) { weapon->increaseEnergy( energy); } } // weaponMan.increaseAmmunition( weapon, energy); } bool SpaceShip::systemFailure() { return (this->electronicCur < /*this->rand() */ this->electronicTH); //TODO cleanup } void SpaceShip::enterPlaymode(Playable::Playmode playmode) { switch(playmode) { case Playable::Full3D: /* if (State::getCameraNode != NULL) { Vector absCoor = this->getAbsCoor(); this->setParent(PNode::getNullParent()); this->setAbsCoor(absCoor); State::getCameraNode()->setParentSoft(&this->cameraNode); State::getCameraNode()->setRelCoorSoft(-10, 0,0); State::getCameraTargetNode()->setParentSoft(&this->cameraNode); State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); } */ //break; case Playable::Vertical: if (State::getCameraNode != NULL) { this->debugNode(1); this->travelNode->debugNode(1); this->travelNode->setAbsCoor(this->getAbsCoor()); this->travelNode->updateNode(0.01f); this->setParent(this->travelNode); this->setRelCoor(0,0,0); State::getCameraNode()->setParentSoft(this->travelNode); State::getCameraNode()->setRelCoorSoft(-0.01, 40,0); State::getCameraTargetNode()->setParentSoft(this->travelNode); State::getCameraTargetNode()->setRelCoorSoft(0,0,0); this->debugNode(1); this->travelNode->debugNode(1); } break; default: PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); } std::cout << Playable::playmodeToString(this->getPlaymode()); } /** * @brief calculate the velocity * @param time the timeslice since the last frame */ void SpaceShip::movement (float dt) { //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so //the ship doesn't slide too much. float airCoeff = 2.5; float pi = 3.14; // these routines will change the travel movement into zero in a short amout of time, if the player // doesn't press any buttons. if (this->velocity.x >= 0) { if (this->velocity.x > airCoeff*this->acceleration * dt) this->velocity.x -= airCoeff* this->acceleration * dt; else this->velocity.x = 0; } else { if (this->velocity.x < -airCoeff*this->acceleration * dt) this->velocity.x += airCoeff* this->acceleration * dt; else this->velocity.x = 0; } if (this->velocity.z >= 0) { if (this->velocity.z > airCoeff*this->acceleration * dt) this->velocity.z -= airCoeff* this->acceleration * dt; else this->velocity.z = 0; } else { if (this->velocity.z < -airCoeff*this->acceleration * dt) this->velocity.z += airCoeff* this->acceleration * dt; else this->velocity.z = 0; } // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons // and its continuing to slide a bit. Vector oldCoor = this->getRelCoor(); if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z); if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z); if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y); if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y); if( this->systemFailure() ) bForward = bBackward = bLeft = bRight = false; if( this->bForward ) { if(this->getRelCoor().x < this->travelDistancePlus.x) { if (this->velocity.x < this->travelSpeed) { this->velocity.x += (airCoeff + 1.0)*this->acceleration*dt; } else { this->velocity.x = this->travelSpeed; } } else { this->velocity.x = 0.0f; } } if( this->bBackward ) { if(this->getRelCoor().x > this->travelDistanceMinus.x) { if (this->velocity.x > -this->travelSpeed) { this->velocity.x -= (airCoeff + 1.0)*this->acceleration*dt; } else { this->velocity.x = -this->travelSpeed; } } else { this->velocity.x = 0.0f; } } if( this->bLeft) { if(this->getRelCoor().z > this->travelDistanceMinus.y) { if (this->velocity.z > -this->travelSpeed) { this->velocity.z -= (airCoeff + 1.0)*this->acceleration*dt; } else { this->velocity.z = -this->travelSpeed; } } else { this->velocity.z = 0.0f; } } if( this->bRight) { if(this->getRelCoor().z < this->travelDistancePlus.y) { if (this->velocity.z < this->travelSpeed) { this->velocity.z += (airCoeff + 1.0)*this->acceleration*dt; } else { this->velocity.z = this->travelSpeed; } } else { this->velocity.z = 0.0f; } } this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); this->shiftCoor (this->velocity * dt); float angle = this->velocity.z / travelSpeed * pi / 3; if (angle > pi/3) angle = pi/3; if (angle < -pi/3) angle = -pi/3; this->setRelDirSoft(Quaternion(angle, Vector(1,0,0)), 5.0f); /* switch(this->getPlaymode()) { case Playable::Vertical: break; default: PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); } */ }