Example #1
0
 public static void Reset()
 {
     payloadShipSelector    = null;
     missionProfileSelector = null;
     orbitEditor            = null;
     crewTransferSelector   = null;
     flagSelector           = null;
     scrollPos = Vector2.zero;
     shipName  = "";
 }
Example #2
0
 public static void Reset()
 {
     payloadShipSelector    = null;
     missionProfileSelector = null;
     targetVesselSelector   = null;
     crewTransferSelector   = null;
     flagSelector           = null;
     scrollPos        = Vector2.zero;
     shipName         = "";
     constructionTime = 0;
 }
 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 #4
0
        // Adds to given kerbal as a crew-member to the (unloaded) vessel:
        public static void AddCrewMember(Vessel vessel, string kerbonautName)
        {
            // We can only manipulate the crew of an unloaded ship:
            // if (vessel.loaded) throw new Exception("TargetVessel.AddCrewMember can only be called on unloaded vessels");
            try
            {
                // Find the requested Kerbal on the crew-roster:
                ProtoCrewMember kerbonaut = null;
                foreach (var rosterKerbonaut in GUICrewTransferSelector.GetCrewRoster())
                {
                    if (rosterKerbonaut.name == kerbonautName)
                    {
                        kerbonaut = rosterKerbonaut;
                        break;
                    }
                }
                if (kerbonaut == null)
                {
                    // The player must have removed the kerbal from the pool of available kerbonauts:
                    Debug.Log("[KSTS] unable to complete crew-transfer to " + vessel.vesselName + ", kerbonaut " + kerbonautName + " unavailable or missiong");
                    ScreenMessages.PostScreenMessage("Crew-Transfer aborted: Kerbonaut " + kerbonautName + " unavailable for transfer to " + vessel.vesselName);
                    return;
                }

                // Find an available seat on the target-vessel:
                ProtoPartSnapshot targetPart = null;
                foreach (var protoPart in vessel.protoVessel.protoPartSnapshots)
                {
                    if (!KSTS.partDictionary.ContainsKey(protoPart.partName))
                    {
                        continue;
                    }
                    var crewCapacity = KSTS.partDictionary[protoPart.partName].partPrefab.CrewCapacity;
                    if (crewCapacity <= 0)
                    {
                        continue;
                    }
                    if (protoPart.protoCrewNames.Count >= crewCapacity)
                    {
                        continue;
                    }
                    targetPart = protoPart;
                    break;
                }
                if (targetPart == null)
                {
                    // Maybe there was a different transport-mission to the same target-vessel:
                    Debug.Log("[KSTS] unable to complete crew-transfer to " + vessel.vesselName + ", no free seats");
                    ScreenMessages.PostScreenMessage("Crew-Transfer aborted: Vessel " + vessel.vesselName + " had no free seat for Kerbonaut " + kerbonautName);
                    return;
                }

                // Add the kerbonaut to the selected part, using the next available seat:
                var  seatIdx = 0;
                bool seatSwitched;
                do
                {
                    seatSwitched = false;
                    foreach (var crewMember in targetPart.protoModuleCrew)
                    {
                        if (seatIdx == crewMember.seatIdx)
                        {
                            seatIdx++; seatSwitched = true;
                        }
                    }
                }while (seatSwitched);
                targetPart.protoModuleCrew.Add(kerbonaut);
                targetPart.protoCrewNames.Add(kerbonautName);

                // Remove kerbonaut from crew-roster:
                kerbonaut.seatIdx = seatIdx;

                kerbonaut.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                // Add the phases the kerbonaut would have gone through during his launch to his flight-log:
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Launch, Planetarium.fetch.Home.bodyName);
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Flight, Planetarium.fetch.Home.bodyName);
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Suborbit, Planetarium.fetch.Home.bodyName);
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Orbit, Planetarium.fetch.Home.bodyName);

                // Notyfy other mods about the modification of the vessel's crew:
                GameEvents.onVesselCrewWasModified.Fire(vessel);

                Debug.Log("[KSTS] added kerbonaut " + kerbonautName + " to vessel " + vessel.vesselName);
                ScreenMessages.PostScreenMessage("Kerbonaut " + kerbonautName + " transfered to " + vessel.vesselName);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSTS] TargetVessel.AddCrewMember(" + vessel.vesselName + "," + kerbonautName + "): " + e.ToString());
            }
        }
Example #5
0
        private static bool DisplayInner()
        {
            // Payload selection:
            if (payloadShipSelector == null)
            {
                payloadShipSelector = new GUIPayloadShipSelector();
            }
            if (payloadShipSelector.payload == null)
            {
                payloadShipSelector.DisplayList();
                return(false);
            }
            if (payloadShipSelector.DisplaySelected())
            {
                missionProfileSelector = null;
                orbitEditor            = null;
                crewTransferSelector   = null;
                flagSelector           = null;
                return(false);
            }
            currentCost += payloadShipSelector.payload.template.totalCost;

            // Mission-Profile selection:
            if (missionProfileSelector == null)
            {
                missionProfileSelector                   = new GUIMissionProfileSelector();
                missionProfileSelector.filterMass        = payloadShipSelector.payload.template.totalMass;
                missionProfileSelector.filterMissionType = MissionProfileType.DEPLOY;
                shipName = payloadShipSelector.payload.template.shipName;
            }
            if (missionProfileSelector.selectedProfile == null)
            {
                missionProfileSelector.DisplayList();
                return(false);
            }
            if (missionProfileSelector.DisplaySelected())
            {
                orbitEditor          = null;
                crewTransferSelector = null;
                flagSelector         = null;
                return(false);
            }
            currentCost += missionProfileSelector.selectedProfile.launchCost;

            // Mission-Parameters selection:
            if (orbitEditor == null)
            {
                orbitEditor = new GUIOrbitEditor(missionProfileSelector.selectedProfile);
            }
            if (crewTransferSelector == null)
            {
                crewTransferSelector = new GUICrewTransferSelector(payloadShipSelector.payload, missionProfileSelector.selectedProfile);
            }
            if (flagSelector == null)
            {
                flagSelector = new GUIFlagSelector();
            }
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle);

            GUILayout.Label("<size=14><b>Mission Parameters:</b></size>");
            GUILayout.BeginHorizontal();
            GUILayout.Label("Ship name:", new GUIStyle(GUI.labelStyle)
            {
                stretchWidth = true
            });
            shipName = GUILayout.TextField(shipName, new GUIStyle(GUI.textFieldStyle)
            {
                alignment = TextAnchor.MiddleRight, stretchWidth = false, fixedWidth = 320
            });
            GUILayout.EndHorizontal();

            orbitEditor.DisplayEditor();

            // Display crew-selector, if the payload can hold kerbals:
            var selectionIsValid = true;

            if (payloadShipSelector.payload.GetCrewCapacity() > 0)
            {
                GUILayout.Label("");
                GUILayout.Label("<size=14><b>Crew:</b></size>");
                if (!crewTransferSelector.DisplayList())
                {
                    selectionIsValid = false;
                }
            }

            // Show Button for Flag-Selector:
            GUILayout.Label("");
            flagSelector.ShowButton();

            GUILayout.EndScrollView();
            return(selectionIsValid);
        }
Example #6
0
        private static bool DisplayInner()
        {
            // Payload selection:
            if (payloadShipSelector == null)
            {
                payloadShipSelector = new GUIPayloadShipSelector();
            }
            if (payloadShipSelector.payload == null)
            {
                payloadShipSelector.DisplayList();
                return(false);
            }
            if (payloadShipSelector.DisplaySelected())
            {
                targetVesselSelector   = null;
                missionProfileSelector = null;
                crewTransferSelector   = null;
                flagSelector           = null;
                return(false);
            }
            currentCost += payloadShipSelector.payload.template.totalCost;
            var    dryMass           = payloadShipSelector.payload.GetDryMass();
            double totalMass         = payloadShipSelector.payload.template.totalMass;
            var    engineersRequired = (int)Math.Ceiling(Math.Log(Math.Ceiling(dryMass / 10)) / Math.Log(2)) + 1; // One engineer can construct up to 10t, each additional engineer doubles that number

            // Target (space-dock) selection:
            if (targetVesselSelector == null)
            {
                targetVesselSelector = new GUITargetVesselSelector();
                targetVesselSelector.filterVesselType        = VesselType.Station;
                targetVesselSelector.filterHasCrewTrait      = "Engineer"; // There does not seem to be an enum for this.
                targetVesselSelector.filterHasCrewTraitCount = engineersRequired;
            }
            if (targetVesselSelector.targetVessel == null)
            {
                targetVesselSelector.DisplayList();
                return(false);
            }
            if (targetVesselSelector.DisplaySelected())
            {
                missionProfileSelector = null;
                crewTransferSelector   = null;
                flagSelector           = null;
                return(false);
            }

            // Mission-Profile selection:
            if (missionProfileSelector == null)
            {
                missionProfileSelector = new GUIMissionProfileSelector();
                missionProfileSelector.filterAltitude         = targetVesselSelector.targetVessel.orbit.ApA;
                missionProfileSelector.filterBody             = targetVesselSelector.targetVessel.orbit.referenceBody;
                missionProfileSelector.filterDockingPortTypes = TargetVessel.GetVesselDockingPortTypes(targetVesselSelector.targetVessel);
                missionProfileSelector.filterMissionType      = MissionProfileType.TRANSPORT;
                shipName = payloadShipSelector.payload.template.shipName;
            }
            if (missionProfileSelector.selectedProfile == null)
            {
                missionProfileSelector.DisplayList();
                return(false);
            }
            if (missionProfileSelector.DisplaySelected())
            {
                crewTransferSelector = null;
                flagSelector         = null;
                return(false);
            }

            if (crewTransferSelector == null)
            {
                crewTransferSelector = new GUICrewTransferSelector(payloadShipSelector.payload, missionProfileSelector.selectedProfile);
            }
            if (flagSelector == null)
            {
                flagSelector = new GUIFlagSelector();
            }

            // Display Construction-Info:
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle);
            GUILayout.Label("<size=14><b>Construction Info:</b></size>");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Ship name:", new GUIStyle(GUI.labelStyle)
            {
                stretchWidth = true
            });
            shipName = GUILayout.TextField(shipName, new GUIStyle(GUI.textFieldStyle)
            {
                alignment = TextAnchor.MiddleRight, stretchWidth = false, fixedWidth = 320
            });
            GUILayout.EndHorizontal();

            // Calculate and display all the construction-parameters:
            var engineers  = TargetVessel.GetCrewCountWithTrait(targetVesselSelector.targetVessel, "Engineer");
            var scientists = TargetVessel.GetCrewCountWithTrait(targetVesselSelector.targetVessel, "Scientist");

            if (engineers < engineersRequired)
            {
                throw new Exception("not enough engineers on target vessel");
            }
            if (missionProfileSelector.selectedProfile.payloadMass <= 0)
            {
                throw new Exception("mission profile payload too low");
            }
            var flights              = (int)Math.Ceiling(totalMass / missionProfileSelector.selectedProfile.payloadMass);
            var flightTime           = missionProfileSelector.selectedProfile.missionDuration;
            var totalFlightTime      = flightTime * flights;
            var baseConstructionTime = dryMass * 6 * 60 * 60; // 1 (kerbin-) day / ton
            var totalFlightCost      = missionProfileSelector.selectedProfile.launchCost * flights;

            currentCost     += totalFlightCost;
            constructionTime = baseConstructionTime;
            if (scientists > 0)
            {
                constructionTime = baseConstructionTime / (scientists + 1);                 // half the time per scientist
            }
            if (totalFlightTime > constructionTime)
            {
                constructionTime = totalFlightTime;
            }

            var leftLabel = new GUIStyle(GUI.labelStyle)
            {
                stretchWidth = true
            };
            var rightLabel = new GUIStyle(GUI.labelStyle)
            {
                stretchWidth = false, alignment = TextAnchor.MiddleRight
            };

            GUILayout.BeginHorizontal();
            GUILayout.Label("Mass:", leftLabel);
            GUILayout.Label(totalMass.ToString("#,##0.00t") + " / " + dryMass.ToString("#,##0.00t") + " dry", rightLabel);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Dock-Capacity (" + engineers.ToString() + " engineer" + (engineers != 1 ? "s" : "") + "):", leftLabel);
            GUILayout.Label((Math.Pow(2, engineers - 1) * 10).ToString("#,##0.00t") + " dry", rightLabel);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Single Flight (" + (missionProfileSelector.selectedProfile.launchCost / missionProfileSelector.selectedProfile.payloadMass).ToString("#,##0 √/t") + "):", leftLabel);
            GUILayout.Label(missionProfileSelector.selectedProfile.payloadMass.ToString("#,##0.00t") + " in " + GUI.FormatDuration(flightTime) + " for " + missionProfileSelector.selectedProfile.launchCost.ToString("#,##0 √"), rightLabel);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Total Flights:", leftLabel);
            GUILayout.Label(flights.ToString("#,##0") + " in " + GUI.FormatDuration(totalFlightTime) + " for " + totalFlightCost.ToString("#,##0 √"), rightLabel);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Base Construction Time (6h/t):", leftLabel);
            GUILayout.Label(GUI.FormatDuration(baseConstructionTime), rightLabel);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Total Construction Time (" + scientists.ToString() + " scientist" + (scientists != 1 ? "s" : "") + "):", leftLabel);
            GUILayout.Label(GUI.FormatDuration(constructionTime), rightLabel);
            GUILayout.EndHorizontal();

            // Display crew-selector, if the new ship can hold kerbals:
            var selectionIsValid = true;

            if (payloadShipSelector.payload.GetCrewCapacity() > 0)
            {
                GUILayout.Label("");
                GUILayout.Label("<size=14><b>Crew:</b></size>");
                if (!crewTransferSelector.DisplayList())
                {
                    selectionIsValid = false;
                }
            }

            // Show Button for Flag-Selector:
            GUILayout.Label("");
            flagSelector.ShowButton();

            GUILayout.EndScrollView();
            return(selectionIsValid);
        }