Example #1
0
        public static MissionProfile CreateFromRecording(Vessel vessel, FlightRecording recording)
        {
            var profile = new MissionProfile();

            profile.profileName      = recording.profileName;
            profile.vesselName       = vessel.vesselName.ToString();
            profile.missionType      = recording.missionType;
            profile.launchCost       = recording.launchCost;
            profile.launchMass       = recording.launchMass - recording.payloadMass;
            profile.payloadMass      = recording.payloadMass;
            profile.minAltitude      = recording.minAltitude;
            profile.maxAltitude      = recording.maxAltitude;
            profile.bodyName         = recording.launchBodyName;
            profile.missionDuration  = recording.deploymentTime - recording.startTime;
            profile.crewCapacity     = vessel.GetCrewCapacity() - vessel.GetCrewCount(); // Capacity at the end of the mission, so we can use it for oneway- as well als return-trips.
            profile.dockingPortTypes = recording.dockingPortTypes;

            if (vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.SPLASHED)
            {
                profile.oneWayMission = false;
                profile.launchCost   -= recording.GetCurrentVesselValue();
                if (profile.launchCost < 0)
                {
                    profile.launchCost = 0; // Shouldn't happen
                }
            }
            else
            {
                profile.oneWayMission = true;
            }

            return(profile);
        }
Example #2
0
        public static void LoadMissions(ConfigNode node)
        {
            MissionController.missionProfiles.Clear();
            var missionProfilesNode = node.GetNode("MissionProfiles");

            if (missionProfilesNode != null)
            {
                foreach (var missionProfileNode in missionProfilesNode.GetNodes())
                {
                    var missionProfile = MissionProfile.CreateFromConfigNode(missionProfileNode);
                    MissionController.missionProfiles.Add(missionProfile.profileName, missionProfile);
                }
            }

            MissionController.missions.Clear();
            var missionsNode = node.GetNode("Missions");

            if (missionsNode != null)
            {
                foreach (var missionNode in missionsNode.GetNodes())
                {
                    MissionController.missions.Add(Mission.CreateFromConfigNode(missionNode));
                }
            }
        }
        // Displays the currently selected mission-profile and returns true, if the player has deselected the profile:
        public bool DisplaySelected(string showDetails = SELECTED_DETAILS_ALTITUDE)
        {
            CheckInternals();
            if (this.selectedProfile == null)
            {
                return(true);
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("<size=14><b>Mission Profile:</b></size>", new GUIStyle(GUI.labelStyle)
            {
                stretchWidth = true
            });

            var details = "N/A";

            if (showDetails == SELECTED_DETAILS_ALTITUDE)
            {
                details = "Max Altitude: " + GUI.FormatAltitude(selectedProfile.maxAltitude);
            }
            else if (showDetails == SELECTED_DETAILS_PAYLOAD)
            {
                details = "Max Payload: " + this.selectedProfile.payloadMass.ToString("0.00t");
            }
            if (GUILayout.Button("<size=14><color=#F9FA86><b>" + this.selectedProfile.profileName + "</b></color> (" + details + ")</size>", new GUIStyle(GUI.buttonStyle)
            {
                alignment = TextAnchor.MiddleRight, stretchWidth = false, fixedWidth = 320
            }))
            {
                this.selectedProfile = null; // Back to the previous selection
                this.selectedIndex   = -1;
            }
            GUILayout.EndHorizontal();
            return(this.selectedProfile == null);
        }
Example #4
0
 public GUICrewTransferSelector(CachedShipTemplate targetTemplate, MissionProfile missionProfile)
 {
     this.targetTemplate = targetTemplate;
     this.missionProfile = missionProfile;
     crewToDeliver       = new List <string>();
     crewToCollect       = new List <string>();
 }
Example #5
0
 public GUICrewTransferSelector(Vessel targetVessel, MissionProfile missionProfile)
 {
     this.targetVessel   = targetVessel;
     this.missionProfile = missionProfile;
     crewToDeliver       = new List <string>();
     crewToCollect       = new List <string>();
 }
 // Makes sure that the cached settings are still valid (eg if the player has deleted the selected profile):
 private void CheckInternals()
 {
     if (!MissionController.missionProfiles.Values.Contains(selectedProfile) || selectedIndex < 0 || selectedIndex >= MissionController.missionProfiles.Count)
     {
         selectedProfile = null;
         selectedIndex   = -1;
     }
 }
Example #7
0
 public GUIOrbitEditor(MissionProfile missionProfile)
 {
     // TODO: Maybe add a switch for complex and simple orbits, the complex editor might also include an option to copy an orbit from a reference-object ...
     this.body                = FlightGlobals.GetHomeBody();
     this.missionProfile      = missionProfile;
     this.altitudeSelector    = new GUIRichValueSelector("Altitude", Math.Floor(this.missionProfile.maxAltitude), "m", Math.Ceiling(this.missionProfile.minAltitude), Math.Floor(this.missionProfile.maxAltitude), true, "#,##0");
     this.inclinationSelector = new GUIRichValueSelector("Inclination", 0, "°", -180, 180, true, "+0.00;-0.00");
 }
Example #8
0
        public static void CreateMissionProfile(Vessel vessel, FlightRecording recording)
        {
            var profile = MissionProfile.CreateFromRecording(vessel, recording);

            // Make the profile-name unique to use it as a key:
            profile.profileName = MissionController.GetUniqueProfileName(profile.profileName);

            MissionController.missionProfiles.Add(profile.profileName, profile);
            Debug.Log("[KSTS] saved new mission profile '" + profile.profileName + "'");
        }
Example #9
0
 public GUIOrbitEditor(MissionProfile missionProfile)
 {
     this.body = FlightGlobals.GetBodyByName(missionProfile.bodyName);
     if (this.body == null)  // in case this flight was registered on a now-invalid body
     {
         this.body = FlightGlobals.GetHomeBody();
     }
     this.missionProfile = missionProfile;
     Reset();
 }
Example #10
0
        public static void CreateMissionProfile(Vessel vessel, FlightRecording recording)
        {
            var profile = MissionProfile.CreateFromRecording(vessel, recording);

            // Make the profile-name unique to use it as a key:
            profile.profileName = MissionController.GetUniqueProfileName(profile.profileName);

            MissionController.missionProfiles.Add(profile.profileName, profile);
            Log.Warning("saved new mission profile '" + profile.profileName + "'" + "   Total of " + MissionController.missionProfiles.Count + " missions saved");
        }
Example #11
0
        public static Mission CreateTransport(Vessel target, MissionProfile profile, List <PayloadResource> resources, List <CrewTransferOrder> crewTransfers)
        {
            var mission = new Mission
            {
                missionType    = MissionType.TRANSPORT,
                profileName    = profile.profileName,
                eta            = Planetarium.GetUniversalTime() + profile.missionDuration,
                targetVesselId = target.protoVessel.vesselID
            };

            if (resources != null)
            {
                mission.resourcesToDeliver = new Dictionary <string, double>();
                foreach (var resource in resources)
                {
                    if (resource.amount > 0)
                    {
                        mission.resourcesToDeliver.Add(resource.name, resource.amount);
                    }
                }
            }
            if (crewTransfers != null)
            {
                foreach (var crewTransfer in crewTransfers)
                {
                    switch (crewTransfer.direction)
                    {
                    case CrewTransferOrder.CrewTransferDirection.DELIVER:
                        if (mission.crewToDeliver == null)
                        {
                            mission.crewToDeliver = new List <string>();
                        }

                        mission.crewToDeliver.Add(crewTransfer.kerbalName);
                        break;

                    case CrewTransferOrder.CrewTransferDirection.COLLECT:
                        if (mission.crewToCollect == null)
                        {
                            mission.crewToCollect = new List <string>();
                        }

                        mission.crewToCollect.Add(crewTransfer.kerbalName);
                        break;

                    default:
                        throw new Exception("unknown transfer-direction: '" + crewTransfer.direction.ToString() + "'");
                    }
                }
            }

            return(mission);
        }
Example #12
0
        public static void ChangeMissionProfileName(string name, string newName)
        {
            MissionProfile profile = null;

            if (!MissionController.missionProfiles.TryGetValue(name, out profile))
            {
                return;
            }
            MissionController.missionProfiles.Remove(name);
            profile.profileName = MissionController.GetUniqueProfileName(newName);
            MissionController.missionProfiles.Add(profile.profileName, profile);
        }
 public GUITransportSelector(Vessel targetVessel, MissionProfile missionProfile)
 {
     this.targetVessel   = targetVessel;
     this.missionProfile = missionProfile;
     resourceSelectors   = new List <GUIRichValueSelector>();
     availableResources  = TargetVessel.GetFreeResourcesCapacities(targetVessel);
     foreach (var availablePayload in availableResources)
     {
         var selector = new GUIRichValueSelector(availablePayload.name, 0, "", 0, Math.Round(availablePayload.amount, 2), true, "#,##0.00");
         resourceSelectors.Add(selector);
     }
     crewTransferSelector = new GUICrewTransferSelector(targetVessel, missionProfile);
 }
Example #14
0
        // Checks if the given vessel is a valid target for a mission, optionally by comparing it also to the given mission-profile parameters:
        public static bool IsValidTarget(Vessel vessel, MissionProfile profile = null)
        {
            if (vessel.situation != Vessel.Situations.ORBITING)
            {
                return(false);
            }
            if (vessel.orbit == null)
            {
                return(false);
            }

            var dockingPortTypes = GetVesselDockingPortTypes(vessel);

            if (dockingPortTypes.Count == 0)
            {
                return(false);                             // We have to dock for a transport-mission.
            }
            if (profile == null)
            {
                if (vessel.orbit.referenceBody != FlightGlobals.GetHomeBody())
                {
                    return(false);                                                           // Can only record orbits around the launch body if there's no profile
                }
            }
            else
            {
                if (vessel.orbit.referenceBody.bodyName != profile.bodyName)
                {
                    return(false);                                                         // Can only record orbits around the same body as the profile
                }
                var hasMatchingPort = false;
                foreach (var dockingPortType in dockingPortTypes)
                {
                    if (profile.dockingPortTypes.Contains(dockingPortType))
                    {
                        hasMatchingPort = true;
                        break;
                    }
                }
                if (!hasMatchingPort)
                {
                    return(false);
                }

                if (vessel.orbit.ApA > profile.maxAltitude)
                {
                    return(false);                                        // The target must have moved ...
                }
            }
            return(true);
        }
Example #15
0
        // Checks if the given vessel is a valid target for a mission, optionally by comparing it also to the given mission-profile parameters:
        public static bool IsValidTarget(Vessel vessel, MissionProfile profile = null)
        {
            if (vessel.situation != Vessel.Situations.ORBITING)
            {
                return(false);
            }
            if (vessel.orbit == null)
            {
                return(false);
            }
            if (vessel.orbit.referenceBody != FlightGlobals.GetHomeBody())
            {
                return(false);                                                           // We simply assume that we can only launch missions from our home-planet.
            }
            List <string> dockingPortTypes = GetVesselDockingPortTypes(vessel);

            if (dockingPortTypes.Count == 0)
            {
                return(false);                             // We have to dock for a transport-mission.
            }
            if (profile != null)
            {
                bool hasMatchingPort = false;
                foreach (string dockingPortType in dockingPortTypes)
                {
                    if (profile.dockingPortTypes.Contains(dockingPortType))
                    {
                        hasMatchingPort = true;
                        break;
                    }
                }
                if (!hasMatchingPort)
                {
                    return(false);
                }

                if (vessel.orbit.ApA > profile.maxAltitude)
                {
                    return(false);                                        // The target must have moved ...
                }
            }
            return(true);
        }
Example #16
0
        public static Mission CreateConstruction(string shipName, ShipTemplate template, Vessel spaceDock, MissionProfile profile, List <string> crew, string flagURL, double constructionTime)
        {
            var mission = new Mission
            {
                missionType          = MissionType.CONSTRUCT,
                shipTemplateFilename = SanitizePath(template.filename),
                targetVesselId       = spaceDock.protoVessel.vesselID,
                shipName             = shipName,
                profileName          = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + constructionTime,
                crewToDeliver = crew,
                flagURL       = flagURL
            };

            // The crew we want the new vessel to start with.

            if (KACWrapper.APIReady && MissionController.useKACifAvailable)
            {
                var KACalarmID = KACWrapper.KAC.CreateAlarm(
                    KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                    "Construction: " + shipName,
                    mission.eta
                    );
                var a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                if (a != null)
                {
                    a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                    a.AlarmMargin = 0;
                    //a.VesselID = FlightGlobals.ActiveVessel.id.ToString();
                    a.Notes = "Construction of " + shipName + " by Kerbal Space Transport System";
                }
            }
            if (MissionController.useStockAlarmClock)
            {
                AlarmTypeRaw alarmToSet = new AlarmTypeRaw
                {
                    title       = "KSTS Construction",
                    description = "Construction of " + shipName + " by Kerbal Space Transport System",
                    actions     =
                    {
                        warp    = AlarmActions.WarpEnum.KillWarp,
                        message = AlarmActions.MessageEnum.Yes
                    },
                    ut = mission.eta
                };
                AlarmClockScenario.AddAlarm(alarmToSet);
            }

            return(mission);
        }
        // Shows a list of all available mission-profiles and returns true, if the player has selected one:
        public bool DisplayList()
        {
            CheckInternals();
            GUILayout.Label("<size=14><b>Mission Profile:</b></size>");
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle);
            var green = "#00FF00";
            var red   = "#FF0000";

            // Show a list with all possible mission-profiles:
            if (MissionController.missionProfiles.Count == 0)
            {
                GUILayout.Label("No recordings found, switch to a new vessel to start recording a mission.");
            }
            else
            {
                var contents       = new List <GUIContent>();
                var invalidIndices = new List <int>(); // Profiles which fall out of the defined filters will get noted here.
                var index          = 0;
                foreach (var missionProfile in MissionController.missionProfiles.Values)
                {
                    var isValidProfile = true;
                    var color          = "";

                    // Build the descriptive text with highlighting:
                    var description = "<color=#F9FA86><b>" + missionProfile.profileName + "</b></color> <color=#FFFFFF>(" + missionProfile.vesselName + ")\n";
                    description += "<b>Mass:</b> " + missionProfile.launchMass.ToString("0.0t") + ", Cost: " + missionProfile.launchCost.ToString("#,##0√") + ", ";

                    // One-Way or Round-Trip:
                    var missionRouteDetails = "";
                    if (missionProfile.oneWayMission)
                    {
                        missionRouteDetails = "one-way";
                    }
                    else
                    {
                        missionRouteDetails = "round-trip";
                    }
                    if (this.filterRoundTrip != null)
                    {
                        if (this.filterRoundTrip != missionProfile.oneWayMission)
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        missionRouteDetails = "<color=" + color + ">" + missionRouteDetails + "</color>";
                    }
                    description += missionRouteDetails + "\n";

                    // Mission-Type:
                    var missionType = MissionProfile.GetMissionProfileTypeName(missionProfile.missionType);
                    if (this.filterMissionType != null)
                    {
                        if (this.filterMissionType != missionProfile.missionType)
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        missionType = "<color=" + color + ">" + missionType + "</color>";
                    }
                    description += "<b>Type:</b> " + missionType + ", ";

                    description += "<b>Duration:</b> " + GUI.FormatDuration(missionProfile.missionDuration) + "\n";

                    // Docking-Ports:
                    var dockingPorts = "";
                    if (missionProfile.missionType == MissionProfileType.TRANSPORT || this.filterDockingPortTypes != null)
                    {
                        var hasFittingPort = false;
                        var portNumber     = 0;
                        if (missionProfile.dockingPortTypes != null)
                        {
                            foreach (var portType in missionProfile.dockingPortTypes)
                            {
                                if (portNumber > 0)
                                {
                                    dockingPorts += ", ";
                                }
                                if (this.filterDockingPortTypes != null && this.filterDockingPortTypes.Contains(portType))
                                {
                                    hasFittingPort = true;
                                    dockingPorts  += "<color=" + green + ">" + TargetVessel.TranslateDockingPortName(portType) + "</color>";
                                }
                                else
                                {
                                    dockingPorts += TargetVessel.TranslateDockingPortName(portType);
                                }
                                portNumber++;
                            }
                        }
                        if (portNumber == 0)
                        {
                            dockingPorts = "N/A";
                        }
                        if (this.filterDockingPortTypes != null && !hasFittingPort)
                        {
                            dockingPorts   = "<color=" + red + ">" + dockingPorts + "</color>";
                            isValidProfile = false;
                        }
                    }
                    if (dockingPorts != "")
                    {
                        description += "<b>Docking-Ports:</b> " + dockingPorts + "\n";
                    }

                    // Payload:
                    var payloadMass = missionProfile.payloadMass.ToString("0.0t");
                    if (this.filterMass != null)
                    {
                        // We only display one digit after the pount, so we should round here to avoid confustion:
                        if (Math.Round((double)this.filterMass, 1) > Math.Round(missionProfile.payloadMass, 1))
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        payloadMass = "<color=" + color + ">" + payloadMass + "</color>";
                    }
                    description += "<b>Payload:</b> " + payloadMass;

                    // Body:
                    var bodyName = missionProfile.bodyName;
                    if (this.filterBody != null)
                    {
                        if (this.filterBody.bodyName != missionProfile.bodyName)
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        bodyName = "<color=" + color + ">" + bodyName + "</color>";
                    }
                    description += " to " + bodyName;

                    // Altitude:
                    var maxAltitude = GUI.FormatAltitude(missionProfile.maxAltitude);
                    if (this.filterAltitude != null)
                    {
                        if (this.filterAltitude > missionProfile.maxAltitude)
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        maxAltitude = "<color=" + color + ">" + maxAltitude + "</color>";
                    }
                    description += " @ " + maxAltitude + "\n";

                    // Crew-Capacity:
                    var crewCapacity = missionProfile.crewCapacity.ToString("0");
                    if (this.filterCrewCapacity != null)
                    {
                        if (this.filterCrewCapacity > missionProfile.crewCapacity)
                        {
                            isValidProfile = false; color = red;
                        }
                        else
                        {
                            color = green;
                        }
                        crewCapacity = "<color=" + color + ">" + crewCapacity + "</color>";
                    }
                    description += "<b>Crew-Capacity:</b> " + crewCapacity;

                    description += "</color>";
                    contents.Add(new GUIContent(description, GUI.GetVesselThumbnail(missionProfile.vesselName)));

                    if (!isValidProfile)
                    {
                        invalidIndices.Add(index);
                    }
                    index++;
                }

                var newSelection = GUILayout.SelectionGrid(selectedIndex, contents.ToArray(), 1, GUI.selectionGridStyle);
                if (newSelection != selectedIndex && !invalidIndices.Contains(newSelection))
                {
                    selectedIndex   = newSelection;
                    selectedProfile = MissionController.missionProfiles.Values.ToList()[selectedIndex];
                }
            }

            GUILayout.EndScrollView();
            return(this.selectedProfile != null);
        }
Example #18
0
        public static void Display()
        {
            if (!initialized)
            {
                Initialize();
            }
            Vessel          vessel    = FlightGlobals.ActiveVessel;
            FlightRecording recording = null;

            if (vessel)
            {
                recording = FlightRecoorder.GetFlightRecording(vessel);
            }
            if (!vessel || recording == null)
            {
                Reset();

                // Show list of recorded profiles:
                missionProfileSelector.DisplayList();
                if (missionProfileSelector.selectedProfile != null)
                {
                    if (missionProfileSelector.selectedProfile != lastSelectedProfile)
                    {
                        // The selecte profile was switched:
                        lastSelectedProfile   = missionProfileSelector.selectedProfile;
                        newMissionProfileName = missionProfileSelector.selectedProfile.profileName;
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("<size=14><b>Profile name:</b></size>", new GUIStyle(GUI.labelStyle)
                    {
                        stretchWidth = false
                    });
                    newMissionProfileName = GUILayout.TextField(newMissionProfileName, new GUIStyle(GUI.textFieldStyle)
                    {
                        stretchWidth = true
                    });
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Save Profile", GUI.buttonStyle))
                    {
                        MissionController.ChangeMissionProfileName(missionProfileSelector.selectedProfile.profileName, newMissionProfileName);
                        missionProfileSelector = new GUIMissionProfileSelector(); // Deselect & Reset
                    }
                    if (GUILayout.Button("Delete Profile", GUI.buttonStyle))
                    {
                        MissionController.DeleteMissionProfile(missionProfileSelector.selectedProfile.profileName);
                        missionProfileSelector = new GUIMissionProfileSelector(); // Deselect & Reset
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                // During the recording, allow the player to change the name of the new flight-profile:
                GUILayout.BeginHorizontal();
                GUILayout.Label("<size=14><b>Profile name:</b></size>", new GUIStyle(GUI.labelStyle)
                {
                    stretchWidth = false
                });
                if (recording.status != FlightRecordingStatus.PRELAUNCH)
                {
                    recording.profileName = GUILayout.TextField(recording.profileName, new GUIStyle(GUI.textFieldStyle)
                    {
                        stretchWidth = true
                    });
                }
                else
                {
                    GUILayout.Label(recording.profileName, new GUIStyle(GUI.labelStyle)
                    {
                        stretchWidth = true
                    });
                }
                GUILayout.EndHorizontal();

                // Display all Information about the current recording:
                GUILayout.BeginScrollView(new Vector2(0, 0), new GUIStyle(GUI.scrollStyle)
                {
                    stretchHeight = true
                });
                List <KeyValuePair <string, string> > displayAttributes = recording.GetDisplayAttributes();
                foreach (KeyValuePair <string, string> displayAttribute in displayAttributes)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("<b>" + displayAttribute.Key + "</b>");
                    GUILayout.Label(displayAttribute.Value + "  ", new GUIStyle(GUI.labelStyle)
                    {
                        alignment = TextAnchor.MiddleRight
                    });
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();

                // Display payload selector:
                if (recording.status == FlightRecordingStatus.ASCENDING || recording.status == FlightRecordingStatus.PRELAUNCH)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("<size=14><b>Mission Type:</b></size>");
                    string[] missionTypeStrings = new string[] { "Deploy", "Transport" };
                    selectedMissionTypeTab = GUILayout.Toolbar(selectedMissionTypeTab, missionTypeStrings);
                    GUILayout.EndHorizontal();

                    scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle, GUILayout.Height(210), GUILayout.MaxHeight(210));
                    if (selectedMissionTypeTab == 0)
                    {
                        // Show all deployable payloads:
                        if (!recording.CanPerformMission(MissionProfileType.DEPLOY))
                        {
                            GUILayout.Label("Deployment missions can only be performed if the vessel has detachable parts which haven't been used during the flight (no resource consumption, inactive, uncrewed, etc).");
                        }
                        else
                        {
                            // Show all detachable subassemblies:
                            foreach (PayloadAssembly payloadAssembly in recording.GetPayloadAssemblies())
                            {
                                GUILayout.BeginHorizontal();
                                if (GUILayout.Toggle(selectedPayloadAssemblyIds.Contains(payloadAssembly.id), "<b>" + payloadAssembly.name + "</b>"))
                                {
                                    if (!selectedPayloadAssemblyIds.Contains(payloadAssembly.id))
                                    {
                                        selectedPayloadAssemblyIds.Add(payloadAssembly.id);
                                    }
                                }
                                else if (selectedPayloadAssemblyIds.Contains(payloadAssembly.id))
                                {
                                    selectedPayloadAssemblyIds.Remove(payloadAssembly.id);
                                }
                                GUILayout.Label(payloadAssembly.partCount.ToString() + " parts, " + payloadAssembly.mass.ToString("#,##0.00 t") + "   ", new GUIStyle(GUI.labelStyle)
                                {
                                    alignment = TextAnchor.MiddleRight
                                });
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    else
                    {
                        if (!recording.CanPerformMission(MissionProfileType.TRANSPORT))
                        {
                            GUILayout.Label("Transport missions can only be performed with vessels which have at least one docking port as well as RCS thrusters.");
                        }
                        else
                        {
                            // Show all payload-resources:
                            double totalPayloadMass = 0;
                            foreach (PayloadResource payloadResource in recording.GetPayloadResources())
                            {
                                double selectedAmount = 0;
                                selectedPayloadDeploymentResources.TryGetValue(payloadResource.name, out selectedAmount);

                                GUILayout.BeginHorizontal();
                                GUILayout.Label("<b>" + payloadResource.name + "</b>");
                                GUILayout.Label(((selectedAmount / payloadResource.amount) * 100).ToString("0.00") + "% (" + selectedAmount.ToString("#,##0.00") + " / " + payloadResource.amount.ToString("#,##0.00") + "): " + (selectedAmount * payloadResource.mass).ToString("#,##0.00 t") + "  ", new GUIStyle(GUI.labelStyle)
                                {
                                    alignment = TextAnchor.MiddleRight
                                });
                                GUILayout.EndHorizontal();

                                selectedAmount = GUILayout.HorizontalSlider((float)selectedAmount, 0, (float)payloadResource.amount);
                                if (selectedAmount < 0)
                                {
                                    selectedAmount = 0;
                                }
                                if (selectedAmount > payloadResource.amount)
                                {
                                    selectedAmount = payloadResource.amount;
                                }
                                if (payloadResource.amount - selectedAmount < 0.01)
                                {
                                    selectedAmount = payloadResource.amount;
                                }
                                totalPayloadMass += selectedAmount * payloadResource.mass;

                                if (selectedPayloadDeploymentResources.ContainsKey(payloadResource.name))
                                {
                                    selectedPayloadDeploymentResources[payloadResource.name] = selectedAmount;
                                }
                                else
                                {
                                    selectedPayloadDeploymentResources.Add(payloadResource.name, selectedAmount);
                                }
                            }

                            GUILayout.BeginHorizontal();
                            GUILayout.Label("<b>Total Payload</b>");
                            GUILayout.Label(totalPayloadMass.ToString("#,##0.00 t  "), new GUIStyle(GUI.labelStyle)
                            {
                                alignment = TextAnchor.MiddleRight
                            });
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndScrollView();
                }

                // Bottom pane with action-buttons:
                GUILayout.BeginHorizontal();
                if (recording.status == FlightRecordingStatus.PRELAUNCH && GUILayout.Button("Record", GUI.buttonStyle))
                {
                    // Start Recording:
                    FlightRecoorder.StartRecording(vessel);
                }

                if (recording.CanDeploy() && GUILayout.Button("Release Payload", GUI.buttonStyle))
                {
                    if (selectedMissionTypeTab == 0)
                    {
                        List <PayloadAssembly> payloadAssemblies         = recording.GetPayloadAssemblies();
                        List <PayloadAssembly> selectedPayloadAssemblies = new List <PayloadAssembly>();
                        foreach (PayloadAssembly payloadAssembly in recording.GetPayloadAssemblies())
                        {
                            if (selectedPayloadAssemblyIds.Contains(payloadAssembly.id))
                            {
                                selectedPayloadAssemblies.Add(payloadAssembly);
                            }
                        }
                        if (selectedPayloadAssemblies.Count > 0)
                        {
                            recording.DeployPayloadAssembly(selectedPayloadAssemblies);
                        }
                    }
                    else
                    {
                        recording.DeployPayloadResources(selectedPayloadDeploymentResources);
                    }
                }

                if (recording.CanFinish() && GUILayout.Button("Stop & Save", GUI.buttonStyle))
                {
                    // Stop recording and create a mission-profile:
                    FlightRecoorder.SaveRecording(vessel);
                }

                if (recording.status != FlightRecordingStatus.PRELAUNCH && GUILayout.Button("Abort", GUI.buttonStyle))
                {
                    // Cancel runnig recording:
                    FlightRecoorder.CancelRecording(vessel);
                }
                GUILayout.EndHorizontal();
            }
        }
Example #19
0
        public static Mission CreateDeployment(string shipName, ShipTemplate template, Orbit orbit, MissionProfile profile, List <string> crew, string flagURL)
        {
            var mission = new Mission
            {
                missionType          = MissionType.DEPLOY,
                shipTemplateFilename = SanitizePath(template.filename),
                orbit         = orbit,
                shipName      = shipName,
                profileName   = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + profile.missionDuration,
                crewToDeliver = crew,
                flagURL       = flagURL,
            };

            Log.Info("CreateDeployment, current time: " + Planetarium.GetUniversalTime().ToString("F0") + ", eta: " + mission.eta.ToString("F0"));
            if (KACWrapper.APIReady && MissionController.useKACifAvailable)
            {
                Log.Info("Setting KAC Alarm");
                var KACalarmID = KACWrapper.KAC.CreateAlarm(
                    KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                    "Deployment: " + shipName,
                    mission.eta
                    );
                var a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                if (a != null)
                {
                    a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                    a.AlarmMargin = 0;
                    //a.VesselID = FlightGlobals.ActiveVessel.id.ToString();
                    a.Notes = "Vessel deployment of " + shipName + " by Kerbal Space Transport System";
                }
            }
            if (MissionController.useStockAlarmClock)
            {
                Log.Info("Setting stock alarm");
                AlarmTypeRaw alarmToSet = new AlarmTypeRaw
                {
                    title       = "KSTS Vessel Deployment",
                    description = "Vessel deployment of " + shipName + " by Kerbal Space Transport System",
                    actions     =
                    {
                        warp    = AlarmActions.WarpEnum.KillWarp,
                        message = AlarmActions.MessageEnum.Yes
                    },
                    ut = mission.eta
                };
                AlarmClockScenario.AddAlarm(alarmToSet);
            }
            // The filename contains silly portions like "KSP_x64_Data/..//saves", which break savegames because "//" starts a comment in the savegame ...
            // The crew we want the new vessel to start with.

            return(mission);
        }
Example #20
0
        public static Mission CreateTransport(Vessel target, MissionProfile profile, List <PayloadResource> resources, List <CrewTransferOrder> crewTransfers)
        {
            var mission = new Mission
            {
                missionType    = MissionType.TRANSPORT,
                profileName    = profile.profileName,
                eta            = Planetarium.GetUniversalTime() + profile.missionDuration,
                targetVesselId = target.protoVessel.vesselID
            };

            string transport = "";

            if (resources != null)
            {
                mission.resourcesToDeliver = new Dictionary <string, double>();
                foreach (var resource in resources)
                {
                    if (resource.amount > 0)
                    {
                        mission.resourcesToDeliver.Add(resource.name, resource.amount);
                        if (transport == "")
                        {
                            transport = resource.name;
                        }
                        else
                        {
                            transport += ", " + resource.name;
                        }
                    }
                }
            }
            if (crewTransfers != null)
            {
                foreach (var crewTransfer in crewTransfers)
                {
                    switch (crewTransfer.direction)
                    {
                    case CrewTransferOrder.CrewTransferDirection.DELIVER:
                        if (mission.crewToDeliver == null)
                        {
                            mission.crewToDeliver = new List <string>();
                        }

                        mission.crewToDeliver.Add(crewTransfer.kerbalName);

                        if (transport == "")
                        {
                            transport = crewTransfer.kerbalName;
                        }
                        else
                        {
                            transport += ", " + crewTransfer.kerbalName;
                        }

                        break;

                    case CrewTransferOrder.CrewTransferDirection.COLLECT:
                        if (mission.crewToCollect == null)
                        {
                            mission.crewToCollect = new List <string>();
                        }

                        mission.crewToCollect.Add(crewTransfer.kerbalName);

                        mission.crewToDeliver.Add(crewTransfer.kerbalName);

                        if (transport == "")
                        {
                            transport = crewTransfer.kerbalName;
                        }
                        else
                        {
                            transport += ", " + crewTransfer.kerbalName;
                        }

                        break;

                    default:
                        throw new Exception("unknown transfer-direction: '" + crewTransfer.direction.ToString() + "'");
                    }
                }
            }

            if (KACWrapper.APIReady)
            {
                var KACalarmID = KACWrapper.KAC.CreateAlarm(
                    KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                    "Transport",
                    mission.eta
                    );
                var a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                if (a != null)
                {
                    a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                    a.AlarmMargin = 0;
                    //a.VesselID = FlightGlobals.ActiveVessel.id.ToString();
                    a.Notes = "Transport " + transport + " to " + target.protoVessel.GetDisplayName() + " by Kerbal Space Transport System";
                }
            }

            return(mission);
        }
Example #21
0
        public static Mission CreateDeployment(string shipName, ShipTemplate template, Orbit orbit, MissionProfile profile, List <string> crew, string flagURL)
        {
            var mission = new Mission
            {
                missionType          = MissionType.DEPLOY,
                shipTemplateFilename = SanitizePath(template.filename),
                orbit         = orbit,
                shipName      = shipName,
                profileName   = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + profile.missionDuration,
                crewToDeliver = crew,
                flagURL       = flagURL
            };

            // The filename contains silly portions like "KSP_x64_Data/..//saves", which break savegames because "//" starts a comment in the savegame ...
            // The crew we want the new vessel to start with.

            return(mission);
        }
Example #22
0
        public static Mission CreateConstruction(string shipName, ShipTemplate template, Vessel spaceDock, MissionProfile profile, List <string> crew, string flagURL, double constructionTime)
        {
            var mission = new Mission
            {
                missionType          = MissionType.CONSTRUCT,
                shipTemplateFilename = SanitizePath(template.filename),
                targetVesselId       = spaceDock.protoVessel.vesselID,
                shipName             = shipName,
                profileName          = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + constructionTime,
                crewToDeliver = crew,
                flagURL       = flagURL
            };

            // The crew we want the new vessel to start with.

            if (KACWrapper.APIReady)
            {
                var KACalarmID = KACWrapper.KAC.CreateAlarm(
                    KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                    "Construction: " + shipName,
                    mission.eta
                    );
                var a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                if (a != null)
                {
                    a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                    a.AlarmMargin = 0;
                    //a.VesselID = FlightGlobals.ActiveVessel.id.ToString();
                    a.Notes = "Construction of " + shipName + " by Kerbal Space Transport System";
                }
            }

            return(mission);
        }
Example #23
0
 public GUIOrbitEditor(MissionProfile missionProfile)
 {
     this.body           = FlightGlobals.GetHomeBody();
     this.missionProfile = missionProfile;
     Reset();
 }
Example #24
0
        public static MissionProfile CreateFromConfigNode(ConfigNode node)
        {
            var missionProfile = new MissionProfile();

            return((MissionProfile)CreateFromConfigNode(node, missionProfile));
        }
Example #25
0
        public static Mission CreateConstruction(string shipName, ShipTemplate template, Vessel spaceDock, MissionProfile profile, List <string> crew, string flagURL, double constructionTime)
        {
            var mission = new Mission
            {
                missionType          = MissionType.CONSTRUCT,
                shipTemplateFilename = SanitizePath(template.filename),
                targetVesselId       = spaceDock.protoVessel.vesselID,
                shipName             = shipName,
                profileName          = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + constructionTime,
                crewToDeliver = crew,
                flagURL       = flagURL
            };

            // The crew we want the new vessel to start with.

            return(mission);
        }
Example #26
0
        public static Mission CreateDeployment(string shipName, ShipTemplate template, Orbit orbit, MissionProfile profile, List <string> crew, string flagURL)
        {
            var mission = new Mission
            {
                missionType          = MissionType.DEPLOY,
                shipTemplateFilename = SanitizePath(template.filename),
                orbit         = orbit,
                shipName      = shipName,
                profileName   = profile.profileName,
                eta           = Planetarium.GetUniversalTime() + profile.missionDuration,
                crewToDeliver = crew,
                flagURL       = flagURL,
            };

            if (KACWrapper.APIReady)
            {
                var KACalarmID = KACWrapper.KAC.CreateAlarm(
                    KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                    "Deployment: " + shipName,
                    mission.eta
                    );
                var a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                if (a != null)
                {
                    a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                    a.AlarmMargin = 0;
                    //a.VesselID = FlightGlobals.ActiveVessel.id.ToString();
                    a.Notes = "Vessel deployment of " + shipName + " by Kerbal Space Transport System";
                }
            }
            // The filename contains silly portions like "KSP_x64_Data/..//saves", which break savegames because "//" starts a comment in the savegame ...
            // The crew we want the new vessel to start with.

            return(mission);
        }