public override bool Update() { // get to the game data GameData gameData = DataController.m_instance.m_gameData; // get to the player data PlayerData playerData = DataController.m_instance.m_playerData; // are we currently transitioning? if (m_isTransitioning) { // has the map stopped fading yet? if (!SpaceflightController.m_instance.m_viewport.IsFading()) { // we are not transitioning any more m_isTransitioning = false; // which location do we want to switch to? switch (m_nextLocation) { case PD_General.Location.DockingBay: Debug.Log("Player exited maneuver while near starport - switching to the docking bay location."); // switch to the docking bay location SpaceflightController.m_instance.SwitchLocation(PD_General.Location.DockingBay); // play the docking bay door close animation SpaceflightController.m_instance.m_dockingBay.StartLandingAnimation(); // turn off the maneuver function SpaceflightController.m_instance.m_buttonController.ClearCurrentButton(); break; case PD_General.Location.InOrbit: Debug.Log("Player exited maneuver while near a planet - switching to the in orbit location."); // switch to the in orbit location SpaceflightController.m_instance.SwitchLocation(PD_General.Location.InOrbit); // turn off the maneuver function SpaceflightController.m_instance.m_buttonController.ClearCurrentButton(); break; case PD_General.Location.StarSystem: Debug.Log("Player is breaking orbit - switching to the star system location."); // switch to the in orbit location SpaceflightController.m_instance.SwitchLocation(PD_General.Location.StarSystem); break; } } return(true); } // check if we want to stop maneuvering if (InputController.m_instance.m_submit) { InputController.m_instance.Debounce(); // turn off the engines SpaceflightController.m_instance.m_playerShip.TurnOffEngines(); // are we in a star system? if (playerData.m_general.m_location == PD_General.Location.StarSystem) { // yep - do we have a planet to orbit? if (SpaceflightController.m_instance.m_starSystem.m_planetToOrbitId != -1) { // yep - remember the planet playerData.m_general.m_currentPlanetId = SpaceflightController.m_instance.m_starSystem.m_planetToOrbitId; // fade the map to black SpaceflightController.m_instance.m_viewport.StartFade(0.0f, 2.0f); // we are now transitioning m_isTransitioning = true; // play the activate sound SoundController.m_instance.PlaySound(SoundController.Sound.Activate); // is this arth? if (SpaceflightController.m_instance.m_starSystem.m_planetToOrbitId == gameData.m_misc.m_arthPlanetId) { // yes - transition to the docking bay m_nextLocation = PD_General.Location.DockingBay; // display message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Initiating docking procedure...</color>"); } else { // no - transition to in orbit m_nextLocation = PD_General.Location.InOrbit; // display message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Initiating orbital maneuver...</color>"); } } } if (m_isTransitioning) { // remove the "active" dot from the current button SpaceflightController.m_instance.m_buttonController.UpdateButtonSprites(); // play the deactivate sound SoundController.m_instance.PlaySound(SoundController.Sound.Deactivate); } else { // deactivate the current button SpaceflightController.m_instance.m_buttonController.DeactivateButton(); } } else { // get the controller stick position float x = InputController.m_instance.m_x; float z = InputController.m_instance.m_y; // create our 3d move vector from the controller position Vector3 moveVector = new Vector3(x, 0.0f, z); // check if the move vector will actually move the ship (that the controller is not centered) if (moveVector.magnitude > 0.5f) { // normalize the move vector to a length of 1.0 moveVector.Normalize(); // update the direction playerData.m_general.m_currentDirection = Vector3.Slerp(playerData.m_general.m_currentDirection, moveVector, Time.deltaTime * 2.0f); // turn the engines on SpaceflightController.m_instance.m_playerShip.TurnOnEngines(); } else { // turn the engines off SpaceflightController.m_instance.m_playerShip.TurnOffEngines(); } } // returning true prevents the default spaceflight update from running return(true); }
public override bool Execute() { // get to the player data PlayerData playerData = DataController.m_instance.m_playerData; // where are we? switch (playerData.m_general.m_location) { case PD_General.Location.DockingBay: case PD_General.Location.Planetside: // play the error sound SoundController.m_instance.PlaySound(SoundController.Sound.Error); // display the error message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Standing by to launch.</color>"); // turn off the button light SpaceflightController.m_instance.m_buttonController.UpdateButtonSprites(); // return false to not make the button active return(false); case PD_General.Location.JustLaunched: Debug.Log("Player is maneuvering - switching to the star system location."); // yes - switch to the star system location SpaceflightController.m_instance.SwitchLocation(PD_General.Location.StarSystem); break; case PD_General.Location.StarSystem: // show the system display SpaceflightController.m_instance.m_displayController.ChangeDisplay(SpaceflightController.m_instance.m_displayController.m_systemDisplay); break; case PD_General.Location.InOrbit: // fade the map to black SpaceflightController.m_instance.m_viewport.StartFade(0.0f, 2.0f); // we are now transitioning m_isTransitioning = true; // transition to the star system m_nextLocation = PD_General.Location.StarSystem; // display message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Leaving orbit...</color>"); break; } // reset the current speed playerData.m_general.m_currentSpeed = 0.0f; // return true to keep the button lit and active return(true); }
public override bool Update() { // get to the player data var playerData = DataController.m_instance.m_playerData; // are we currently transitioning? if (m_isTransitioning) { // has the map stopped fading yet? if (!SpaceflightController.m_instance.m_viewport.IsFading()) { // we are not transitioning any more m_isTransitioning = false; // switch to the next location SpaceflightController.m_instance.SwitchLocation(m_nextLocation); // turn off the maneuver function SpaceflightController.m_instance.m_buttonController.ClearCurrentButton(); } return(true); } // check if we want to stop moving if (InputController.m_instance.m_submit) { // debounce the input InputController.m_instance.Debounce(); // turn off the engines SpaceflightController.m_instance.m_terrainVehicle.TurnOffEngines(); // stop playing the diesel engine sound SoundController.m_instance.StopSound(SoundController.Sound.DieselEngine); // calculate ship coordinates var shipCoordinates = Tools.LatLongToWorldCoordinates(playerData.m_general.m_selectedLatitude, playerData.m_general.m_selectedLongitude); shipCoordinates = SpaceflightController.m_instance.m_disembarked.ApplyElevation(shipCoordinates, false); // calculate vector from TV to ship coordinates var vectorToShip = shipCoordinates - playerData.m_general.m_lastDisembarkedCoordinates; // how far is it in kilometers? var distanceInKm = vectorToShip.magnitude * 225.0f / 2048.0f - 2.0f; // are we near the ship? if (distanceInKm <= 0.0f) { // yes - make sure the planetside terrain grid has been updated SpaceflightController.m_instance.m_planetside.UpdateTerrainGridNow(); // fade the map to black SpaceflightController.m_instance.m_viewport.StartFade(0.0f, 2.0f); // we are now transitioning m_isTransitioning = true; // play the activate sound SoundController.m_instance.PlaySound(SoundController.Sound.Activate); // transition to planetside m_nextLocation = PD_General.Location.Planetside; // display message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Refueling terrain vehicle and transferring all cargo...</color>"); } if (m_isTransitioning) { // remove the "active" dot from the current button SpaceflightController.m_instance.m_buttonController.UpdateButtonSprites(); // play the deactivate sound SoundController.m_instance.PlaySound(SoundController.Sound.Deactivate); } else { // deactivate the current button SpaceflightController.m_instance.m_buttonController.DeactivateButton(); } } else { // check if we are out of fuel if (playerData.m_terrainVehicle.GetPercentFuelRemaining() <= -3) { if (!m_outOfFuel) { // remember we already did this m_outOfFuel = true; // turn the engines off SpaceflightController.m_instance.m_terrainVehicle.TurnOffEngines(); // play the error sound SoundController.m_instance.PlaySound(SoundController.Sound.Error); // stop playing the diesel engine sound SoundController.m_instance.StopSound(SoundController.Sound.DieselEngine); // remove the "active" dot from the current button SpaceflightController.m_instance.m_buttonController.UpdateButtonSprites(); // play the deactivate sound SoundController.m_instance.PlaySound(SoundController.Sound.Deactivate); } } else { // get the controller stick position var x = InputController.m_instance.m_x; var z = InputController.m_instance.m_y; // create our 3d move vector from the controller position var moveVector = new Vector3(x, 0.0f, z); // check if the move vector will actually move the ship (that the controller is not centered) if (moveVector.magnitude > 0.5f) { // normalize the move vector to a length of 1.0 moveVector.Normalize(); // update the direction playerData.m_general.m_currentDirection = Vector3.Slerp(playerData.m_general.m_currentDirection, moveVector, Time.deltaTime * 2.0f); // turn the engines on SpaceflightController.m_instance.m_terrainVehicle.TurnOnEngines(); } else { // turn the engines off SpaceflightController.m_instance.m_terrainVehicle.TurnOffEngines(); } } } // returning true prevents the default spaceflight update from running return(true); }
public void Reset(int encounterId) { // get access to the game data var gameData = DataController.m_instance.m_gameData; // remember the encounter id m_encounterId = encounterId; // get access to the encounter m_encounter = gameData.m_encounterList[encounterId]; // set the location (translated) switch (m_encounter.m_location) { case 0: m_location = PD_General.Location.Hyperspace; break; case 1: m_location = PD_General.Location.StarSystem; break; case 2: m_location = PD_General.Location.InOrbit; break; } if (m_location != PD_General.Location.Hyperspace) { foreach (var star in gameData.m_starList) { if (star.m_xCoordinate == m_encounter.m_xCoordinate) { if (star.m_yCoordinate == m_encounter.m_yCoordinate) { m_starId = star.m_id; break; } } } } // set the home position if (m_location == PD_General.Location.Hyperspace) { m_homeCoordinates = Tools.GameToWorldCoordinates(new Vector3(m_encounter.m_xCoordinate, 0.0f, m_encounter.m_yCoordinate)); } else if (m_location == PD_General.Location.StarSystem) { var randomPosition = UnityEngine.Random.insideUnitCircle * (8192.0f - 512.0f); m_homeCoordinates = new Vector3(randomPosition.x, 0.0f, randomPosition.y); } else { m_homeCoordinates = Vector3.zero; } // set the current coordinates to be at home m_currentCoordinates = m_homeCoordinates; // allocate and initialize each of the alien ships in the encounter m_alienShipList = new PD_AlienShip[m_encounter.m_maxNumShips]; for (var i = 0; i < m_alienShipList.Length; i++) { var alienShip = new PD_AlienShip(); alienShip.Initialize(m_encounter); m_alienShipList[i] = alienShip; } // allocate the shown comm list m_shownCommList = new List <int>(); // initialize the encounter distance m_currentDistance = float.MaxValue; }
// call this to switch to the correct location public void SwitchLocation(PD_General.Location newLocation) { // switch to the correct mode Debug.Log("Switching to location " + newLocation); // get to the player data var playerData = DataController.m_instance.m_playerData; // are we switching to a new location? bool locationIsDifferent = false; if (playerData.m_general.m_location != newLocation) { // yes - remember the last location playerData.m_general.m_lastLocation = playerData.m_general.m_location; // update the player location playerData.m_general.m_location = newLocation; // remember that the new location is different locationIsDifferent = true; } // make sure the display is updated (in case we are loading from a save game) m_messages.Refresh(); // stop all looping sounds SoundController.m_instance.StopAllLoopingSounds(); // switching to starport is a special case if (playerData.m_general.m_location == PD_General.Location.Starport) { // force shields to lower and weapons to disarm playerData.m_playerShip.DropShields(); playerData.m_playerShip.DisarmWeapons(); // start fading out the spaceflight scene SceneFadeController.m_instance.FadeOut("Starport"); } else { // hide everything HideEverything(); // make sure the map is visible m_viewport.StartFade(1.0f, 2.0f); // switch the location switch (playerData.m_general.m_location) { case PD_General.Location.DockingBay: m_dockingBay.Show(); break; case PD_General.Location.JustLaunched: m_viewport.StartFade(0.0f, 0.0f); m_messages.Clear(); m_messages.AddText("<color=white>Starport clear.\nStanding by to maneuver.</color>"); break; case PD_General.Location.StarSystem: m_starSystem.Initialize(); m_starSystem.Show(); m_playerShip.Show(); break; case PD_General.Location.InOrbit: m_starSystem.Initialize(); m_inOrbit.Show(); break; case PD_General.Location.Planetside: m_starSystem.Initialize(); m_planetside.Show(); break; case PD_General.Location.Disembarked: m_starSystem.Initialize(); m_disembarked.Show(); break; case PD_General.Location.Hyperspace: m_hyperspace.Show(); m_playerShip.Show(); break; case PD_General.Location.Encounter: m_encounter.Show(); m_playerShip.Show(); break; } } // did we switch to a new location? if (locationIsDifferent) { // yes - save the player data since the location was changed DataController.m_instance.SaveActiveGame(); } }
public override bool Execute() { // get to the player data PlayerData playerData = DataController.m_instance.m_playerData; switch (playerData.m_general.m_location) { case PD_General.Location.DockingBay: // Debug.Log( "Player is disembarking - switching to starport." ); // play the update sound SoundController.m_instance.PlaySound(SoundController.Sound.Update); // make sure we are standing in the middle of the transporter pad playerData.m_general.m_lastStarportCoordinates = new Vector3(0.0f, 0.5f, 0.0f); // switch to the starport location SpaceflightController.m_instance.SwitchLocation(PD_General.Location.Starport); return(true); case PD_General.Location.JustLaunched: case PD_General.Location.InOrbit: case PD_General.Location.StarSystem: case PD_General.Location.Hyperspace: case PD_General.Location.Encounter: SoundController.m_instance.PlaySound(SoundController.Sound.Error); SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>We can't disembark in space!</color>"); SpaceflightController.m_instance.m_buttonController.UpdateButtonSprites(); break; case PD_General.Location.Planetside: // move the player to the arth ship coordinates on the surface playerData.m_general.m_lastDisembarkedCoordinates = Tools.LatLongToWorldCoordinates(playerData.m_general.m_selectedLatitude, playerData.m_general.m_selectedLongitude); // nudge the terrain vehicle to the south a bit playerData.m_general.m_lastDisembarkedCoordinates += Vector3.back * 16.0f; // update the terrain grid SpaceflightController.m_instance.m_disembarked.UpdateTerrainGridNow(); // fade the map to black SpaceflightController.m_instance.m_viewport.StartFade(0.0f, 2.0f); // we are now transitioning m_isTransitioning = true; // transition to the star system m_nextLocation = PD_General.Location.Disembarked; // display message SpaceflightController.m_instance.m_messages.Clear(); SpaceflightController.m_instance.m_messages.AddText("<color=white>Stand by, scanning planet...</color>"); // refuel the terrain vehicle playerData.m_terrainVehicle.Refuel(); // reset the message state and timer m_messageState = 0; m_messageTimer = 0.0f; return(true); } return(false); }