Example #1
0
        private ValidationResult ProcessFacilityChecks(BuildListVessel blv)
        {
            if (CheckFacilityRequirements)
            {
                //Check if vessel fails facility checks but can still be built
                List <string> facilityChecks = blv.MeetsFacilityRequirements(true);
                if (facilityChecks.Count != 0)
                {
                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "editorChecksFailedPopup",
                                                 "Failed editor checks!",
                                                 "Warning! This vessel did not pass the editor checks! It will still be built, but you will not be able to launch it without upgrading. Listed below are the failed checks:\n"
                                                 + string.Join("\n", facilityChecks.Select(s => $"• {s}").ToArray()),
                                                 "Acknowledged",
                                                 false,
                                                 HighLogic.UISkin);

                    if (!BypassFacilityRequirements)
                    {
                        _failureActions();
                        return(ValidationResult.Fail);
                    }
                }
            }

            return(ValidationResult.Success);
        }
Example #2
0
        private void ProcessPartConfigs(BuildListVessel blv)
        {
            _validationResult = ValidationResult.Undecided;
            if (!CheckPartConfigs)
            {
                _validationResult = ValidationResult.Success;
                return;
            }

            Dictionary <Part, List <PartConfigValidationError> > dict = GetConfigErrorsDict(blv);

            if (dict.Count == 0)
            {
                _validationResult = ValidationResult.Success;
                return;
            }

            DialogGUIBase[] controls = ConstructPartConfigErrorsUI(dict);
            var             dlgRect  = new Rect(0.5f, 0.5f, 400, 100);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                         new MultiOptionDialog("partConfigValidationFailedPopup",
                                                               null,
                                                               "Vessel cannot be built!",
                                                               HighLogic.UISkin,
                                                               dlgRect,
                                                               controls),
                                         false,
                                         HighLogic.UISkin);
        }
Example #3
0
        public BuildListVessel NewCopy(bool RecalcTime)
        {
            BuildListVessel ret = new BuildListVessel(this.shipName, this.launchSite, this.buildPoints, this.flag, this.cost, (int)GetEditorFacility());

            ret.shipNode = this.shipNode.CreateCopy();

            //refresh all inventory parts to new
            foreach (ConfigNode part in ret.ExtractedPartNodes)
            {
                ScrapYardWrapper.RefreshPart(part);
            }

            ret.id = Guid.NewGuid();
            if (RecalcTime)
            {
                ret.buildPoints = KCT_Utilities.GetBuildTime(ret.ExtractedPartNodes);
            }
            ret.TotalMass     = this.TotalMass;
            ret.emptyMass     = this.emptyMass;
            ret.cost          = this.cost;
            ret.emptyCost     = this.emptyCost;
            ret.numStageParts = this.numStageParts;
            ret.numStages     = this.numStages;
            ret.stagePartCost = this.stagePartCost;
            return(ret);
        }
Example #4
0
 public static void DrawRenameWindow(int windowID)
 {
     GUILayout.BeginVertical();
     GUILayout.Label("Name:");
     _newName = GUILayout.TextField(_newName);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("Save"))
     {
         if (!_isRenamingLaunchPad)
         {
             BuildListVessel b = Utilities.FindBLVesselByID(_selectedVesselId);
             b.ShipName = _newName; //Change the name from our point of view
             b.ShipNode.SetValue("ship", _newName);
         }
         else
         {
             KCT_LaunchPad lp = KCTGameStates.ActiveKSC.ActiveLPInstance;
             lp.Rename(_newName);
         }
         GUIStates.ShowRename         = false;
         _centralWindowPosition.width = 150;
         _centralWindowPosition.x     = (Screen.width - 150) / 2;
         GUIStates.ShowBuildList      = true;
     }
     if (GUILayout.Button("Cancel"))
     {
         _centralWindowPosition.width = 150;
         _centralWindowPosition.x     = (Screen.width - 150) / 2;
         GUIStates.ShowRename         = false;
         GUIStates.ShowBuildList      = true;
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
     CenterWindow(ref _centralWindowPosition);
 }
Example #5
0
        public override void OnDecodeFromConfigNode()
        {
            GameStates.ActiveKSC.VABList.Clear();
            GameStates.ActiveKSC.SPHList.Clear();
            GameStates.ActiveKSC.VABWarehouse.Clear();
            GameStates.ActiveKSC.SPHWarehouse.Clear();
            GameStates.ActiveKSC.Recon_Rollout.Clear();

            foreach (BuildListItem b in VABBuildList)
            {
                BuildListVessel blv = b.ToBuildListVessel();
                //if (ListContains(blv, KCT_GameStates.VABList) < 0)
                GameStates.ActiveKSC.VABList.Add(blv);
            }
            foreach (BuildListItem b in SPHBuildList)
            {
                BuildListVessel blv = b.ToBuildListVessel();
                //if (ListContains(blv, KCT_GameStates.SPHList) < 0)
                GameStates.ActiveKSC.SPHList.Add(blv);
            }
            foreach (BuildListItem b in VABWarehouse)
            {
                BuildListVessel blv = b.ToBuildListVessel();
                // if (ListContains(blv, KCT_GameStates.VABWarehouse) < 0)
                GameStates.ActiveKSC.VABWarehouse.Add(blv);
            }
            foreach (BuildListItem b in SPHWarehouse)
            {
                BuildListVessel blv = b.ToBuildListVessel();
                // if (ListContains(blv, KCT_GameStates.SPHWarehouse) < 0)
                GameStates.ActiveKSC.SPHWarehouse.Add(blv);
            }
            GameStates.ActiveKSC.Recon_Rollout.Add(LPRecon);
        }
Example #6
0
        public bool CanLaunchVessel(BuildListVessel vessel, out string reason)
        {
            if (vessel == null)
            {
                reason = "No vessel";
                return(false);
            }
            double mass = vessel.GetTotalMass();

            if (mass > MaxMass)
            {
                reason = $"mass ({mass:0.#}t) is higher than the allowed {MaxMass:0.#}";
                return(false);
            }

            var template = new ShipTemplate();

            template.LoadShip(vessel.ShipNode);
            Vector3 dimensions = ShipConstruction.CalculateCraftSize(template); // Note: For a ShipTemplate, this just returns template.shipSize so is safe.

            if (dimensions.x > MaxSize.x | dimensions.y > MaxSize.y | dimensions.z > MaxSize.z)
            {
                reason = $"size ({dimensions.x:0.#} x {dimensions.y:0.#} x {dimensions.z:0.#} m) is more than the allowed {MaxSize.x:0.#} x {MaxSize.y:0.#} x {MaxSize.z:0.#} m";
                return(false);
            }

            reason = null;
            return(true);
        }
Example #7
0
 public BuildListStorageItem FromBuildListVessel(BuildListVessel blv)
 {
     progress          = blv.Progress;
     effectiveCost     = blv.EffectiveCost;
     buildTime         = blv.BuildPoints;
     integrationTime   = blv.IntegrationPoints;
     launchSite        = blv.LaunchSite;
     flag              = blv.Flag;
     shipName          = blv.ShipName;
     shipID            = blv.Id.ToString();
     cannotEarnScience = blv.CannotEarnScience;
     cost              = blv.Cost;
     integrationCost   = blv.IntegrationCost;
     rushBuildClicks   = blv.RushBuildClicks;
     mass              = blv.TotalMass;
     numStageParts     = blv.NumStageParts;
     numStages         = blv.NumStages;
     stagePartCost     = blv.StagePartCost;
     kscDistance       = blv.DistanceFromKSC;
     EditorFacility    = (int)blv.GetEditorFacility();
     BuildListIndex    = blv.BuildListIndex;
     LaunchPadID       = blv.LaunchSiteID;
     desiredManifest   = blv.DesiredManifest;
     KCTPersistentID   = blv.KCTPersistentID;
     FacilityBuiltIn   = blv.FacilityBuiltIn;
     return(this);
 }
Example #8
0
        public ReconRollout(BuildListVessel vessel, RolloutReconType type, string id, string launchSite = "")
        {
            RRType       = type;
            AssociatedID = id;
            LaunchPadID  = string.IsNullOrEmpty(launchSite) ? vessel.LaunchSite : launchSite;   //For when we add custom launchpads
            Progress     = 0;
            BP           = MathParser.ParseReconditioningFormula(vessel, true);
            //if (type != RolloutReconType.Reconditioning)
            //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;

            if (type == RolloutReconType.Reconditioning)
            {
                //BP *= (1 - KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit);
            }
            else if (type == RolloutReconType.Rollout)
            {
                Cost = MathParser.ParseRolloutCostFormula(vessel);
            }
            else if (type == RolloutReconType.Rollback)
            {
                Progress = BP;
            }
            else if (type == RolloutReconType.Recovery)
            {
                double maxDist = SpaceCenter.Instance.cb.Radius * Math.PI;
                BP += BP * (vessel.DistanceFromKSC / maxDist);
            }
        }
Example #9
0
        public void ProcessVessel(BuildListVessel blv)
        {
            _successActions = SuccessAction + ((_) =>
            {
                InputLockManager.RemoveControlLock(InputLockID);
            });
            _failureActions = FailureAction + (() =>
            {
                InputLockManager.RemoveControlLock(InputLockID);
            });

            if (!Utilities.CurrentGameIsCareer())
            {
                _successActions(blv);
                return;
            }

            if (_routine != null)
            {
                KerbalConstructionTime.Instance.StopCoroutine(_routine);
            }

            InputLockManager.SetControlLock(ControlTypes.EDITOR_UI, InputLockID);
            _routine = RunValidationRoutine(blv);
            KerbalConstructionTime.Instance.StartCoroutine(_routine);
        }
Example #10
0
        public BuildListVessel CreateCopy(bool RecalcTime)
        {
            BuildListVessel ret = new BuildListVessel(ShipName, LaunchSite, EffectiveCost, BuildPoints, IntegrationPoints, Flag, Cost, IntegrationCost, (int)GetEditorFacility())
            {
                ShipNode = ShipNode.CreateCopy()
            };

            //refresh all inventory parts to new
            foreach (var p in ret.ExtractedPartNodes)
            {
                ScrapYardWrapper.RefreshPart(p);
            }

            ret.Id = Guid.NewGuid();
            ret.KCTPersistentID = Guid.NewGuid().ToString();
            ret.TotalMass       = TotalMass;
            ret.EmptyMass       = EmptyMass;
            ret.Cost            = Cost;
            ret.IntegrationCost = IntegrationCost;
            ret.EmptyCost       = EmptyCost;
            ret.NumStageParts   = NumStageParts;
            ret.NumStages       = NumStages;
            ret.StagePartCost   = StagePartCost;
            ret.ShipSize        = ShipSize;

            if (RecalcTime)
            {
                ret.EffectiveCost     = Utilities.GetEffectiveCost(ret.ExtractedPartNodes);
                ret.BuildPoints       = Utilities.GetBuildTime(ret.EffectiveCost);
                ret.IntegrationPoints = MathParser.ParseIntegrationTimeFormula(ret);
                ret.IntegrationCost   = (float)MathParser.ParseIntegrationCostFormula(ret);
            }

            return(ret);
        }
Example #11
0
        public static double ParseReconditioningFormula(BuildListVessel vessel, bool isReconditioning)
        {
            double loadedMass, emptyMass, loadedCost, emptyCost;

            loadedCost = vessel.Cost;
            emptyCost  = vessel.EmptyCost;
            loadedMass = vessel.GetTotalMass();
            emptyMass  = vessel.EmptyMass;

            float LaunchSiteLvl;
            int   EditorLevel, EditorMax, LaunchSiteMax;
            int   isVABVessel = 0;

            if (vessel.Type == BuildListVessel.ListType.VAB)
            {
                EditorLevel   = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteLvl = KCTGameStates.ActiveKSC.ActiveLPInstance.fractionalLevel;
                EditorMax     = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteMax = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.LaunchPad);
                isVABVessel   = 1;
            }
            else
            {
                EditorLevel   = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteLvl = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.Runway);
                EditorMax     = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteMax = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.Runway);
            }
            double BP          = vessel.BuildPoints;
            double OverallMult = PresetManager.Instance.ActivePreset.TimeSettings.OverallMultiplier;
            double ReconEffect = PresetManager.Instance.ActivePreset.TimeSettings.ReconditioningEffect;
            double MaxRecon    = PresetManager.Instance.ActivePreset.TimeSettings.MaxReconditioning;

            var variables = new Dictionary <string, string>
            {
                { "M", loadedMass.ToString() },
                { "m", emptyMass.ToString() },
                { "C", loadedCost.ToString() },
                { "c", emptyCost.ToString() },
                { "VAB", isVABVessel.ToString() },
                { "BP", BP.ToString() },
                { "L", LaunchSiteLvl.ToString() },
                { "LM", LaunchSiteMax.ToString() },
                { "EL", EditorLevel.ToString() },
                { "ELM", EditorMax.ToString() },
                { "O", OverallMult.ToString() },
                { "E", ReconEffect.ToString() },
                { "X", MaxRecon.ToString() },
                { "RE", (isReconditioning ? 1 : 0).ToString() },
                { "S", PresetManager.Instance.ActivePreset.TimeSettings.RolloutReconSplit.ToString() },
                { "SN", vessel.NumStages.ToString() },
                { "SP", vessel.NumStageParts.ToString() },
                { "SC", vessel.StagePartCost.ToString() }
            };

            AddCrewVariables(variables);

            return(GetStandardFormulaValue("Reconditioning", variables));
        }
Example #12
0
        public static double ParseRolloutCostFormula(BuildListVessel vessel)
        {
            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled || !KCT_PresetManager.Instance.ActivePreset.generalSettings.ReconditioningTimes)
            {
                return(0);
            }

            double loadedMass, emptyMass, loadedCost, emptyCost;

            loadedCost = vessel.GetTotalCost();
            emptyCost  = vessel.emptyCost;
            loadedMass = vessel.GetTotalMass();
            emptyMass  = vessel.emptyMass;

            int EditorLevel = 0, LaunchSiteLvl = 0, EditorMax = 0, LaunchSiteMax = 0;
            int isVABVessel = 0;

            if (vessel.type == BuildListVessel.ListType.None)
            {
                vessel.FindTypeFromLists();
            }
            if (vessel.type == BuildListVessel.ListType.VAB)
            {
                EditorLevel   = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteLvl = GameStates.ActiveKSC.ActiveLPInstance.level;//KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
                EditorMax     = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.LaunchPad);
                isVABVessel   = 1;
            }
            else if (vessel.type == BuildListVessel.ListType.SPH)
            {
                EditorLevel   = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteLvl = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.Runway);
                EditorMax     = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteMax = KCT_Utilities.BuildingUpgradeMaxLevel(SpaceCenterFacility.Runway);
            }
            double BP = vessel.buildPoints;

            Dictionary <string, string> variables = new Dictionary <string, string>();

            variables.Add("M", loadedMass.ToString());
            variables.Add("m", emptyMass.ToString());
            variables.Add("C", loadedCost.ToString());
            variables.Add("c", emptyCost.ToString());
            variables.Add("VAB", isVABVessel.ToString());
            variables.Add("BP", BP.ToString());
            variables.Add("L", LaunchSiteLvl.ToString());
            variables.Add("LM", LaunchSiteMax.ToString());
            variables.Add("EL", EditorLevel.ToString());
            variables.Add("ELM", EditorMax.ToString());
            variables.Add("SN", vessel.numStages.ToString());
            variables.Add("SP", vessel.numStageParts.ToString());
            variables.Add("SC", vessel.stagePartCost.ToString());

            AddCrewVariables(variables);

            return(GetStandardFormulaValue("RolloutCost", variables));
        }
Example #13
0
        public AirlaunchPrep(BuildListVessel vessel, string id)
        {
            Direction    = PrepDirection.Mount;
            AssociatedID = id;
            Progress     = 0;

            BP   = MathParser.ParseAirlaunchTimeFormula(vessel);
            Cost = MathParser.ParseAirlaunchCostFormula(vessel);
        }
Example #14
0
        private static Dictionary <string, string> GetIntegrationRolloutVariables(BuildListVessel vessel)
        {
            double loadedMass, emptyMass, loadedCost, emptyCost;

            loadedCost = vessel.Cost;
            emptyCost  = vessel.EmptyCost;
            loadedMass = vessel.GetTotalMass();
            emptyMass  = vessel.EmptyMass;

            int EditorLevel = 0, LaunchSiteLvl = 0, EditorMax = 0, LaunchSiteMax = 0;
            int isVABVessel = 0;

            if (vessel.Type == BuildListVessel.ListType.None)
            {
                vessel.FindTypeFromLists();
            }
            if (vessel.Type == BuildListVessel.ListType.VAB)
            {
                EditorLevel   = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteLvl = KCTGameStates.ActiveKSC.ActiveLPInstance.level;
                EditorMax     = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
                LaunchSiteMax = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.LaunchPad);
                isVABVessel   = 1;
            }
            else if (vessel.Type == BuildListVessel.ListType.SPH)
            {
                EditorLevel   = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteLvl = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.Runway);
                EditorMax     = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.SpaceplaneHangar);
                LaunchSiteMax = Utilities.GetBuildingUpgradeMaxLevel(SpaceCenterFacility.Runway);
            }
            double BP          = vessel.BuildPoints;
            double OverallMult = PresetManager.Instance.ActivePreset.TimeSettings.OverallMultiplier;

            var variables = new Dictionary <string, string>
            {
                { "M", loadedMass.ToString() },
                { "m", emptyMass.ToString() },
                { "C", loadedCost.ToString() },
                { "c", emptyCost.ToString() },
                { "VAB", isVABVessel.ToString() },
                { "E", vessel.EffectiveCost.ToString() },
                { "BP", BP.ToString() },
                { "L", LaunchSiteLvl.ToString() },
                { "LM", LaunchSiteMax.ToString() },
                { "EL", EditorLevel.ToString() },
                { "ELM", EditorMax.ToString() },
                { "O", OverallMult.ToString() },
                { "SN", vessel.NumStages.ToString() },
                { "SP", vessel.NumStageParts.ToString() },
                { "SC", vessel.StagePartCost.ToString() }
            };

            AddCrewVariables(variables);

            return(variables);
        }
Example #15
0
        public static double ParseRolloutCostFormula(BuildListVessel vessel)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled || !PresetManager.Instance.ActivePreset.GeneralSettings.ReconditioningTimes)
            {
                return(0);
            }

            Dictionary <string, string> variables = GetIntegrationRolloutVariables(vessel);

            return(GetStandardFormulaValue("RolloutCost", variables));
        }
Example #16
0
        public static double ParseAirlaunchTimeFormula(BuildListVessel vessel)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled ||
                string.IsNullOrEmpty(PresetManager.Instance.ActivePreset.FormulaSettings.AirlaunchTimeFormula))
            {
                return(0);
            }

            Dictionary <string, string> variables = GetIntegrationRolloutVariables(vessel);

            return(GetStandardFormulaValue("AirlaunchTime", variables));
        }
Example #17
0
        public static BuildListVessel AddVesselToPlansList(BuildListVessel blv)
        {
            ScreenMessage message;

            if (Utilities.CurrentGameIsCareer())
            {
                //Check upgrades
                //First, mass limit
                List <string> facilityChecks = blv.MeetsFacilityRequirements(true);
                if (facilityChecks.Count != 0)
                {
                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "editorChecksFailedPopup", "Failed editor checks!",
                                                 "Warning! This vessel did not pass the editor checks! It will still be added to the plans, but you will not be able to launch it without upgrading. Listed below are the failed checks:\n"
                                                 + string.Join("\n", facilityChecks.ToArray()), "Acknowledged", false, HighLogic.UISkin);
                }
            }
            string type = "";

            if (blv.Type == BuildListVessel.ListType.VAB)
            {
                if (KCTGameStates.ActiveKSC.VABPlans.ContainsKey(blv.ShipName))
                {
                    KCTGameStates.ActiveKSC.VABPlans.Remove(blv.ShipName);
                    message = new ScreenMessage($"[KCT] Replacing previous plan for {blv.ShipName} in the VAB Building Plans list.", 4f, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(message);
                }
                KCTGameStates.ActiveKSC.VABPlans.Add(blv.ShipName, blv);
                type = "VAB";
            }
            else if (blv.Type == BuildListVessel.ListType.SPH)
            {
                if (KCTGameStates.ActiveKSC.SPHPlans.ContainsKey(blv.ShipName))
                {
                    KCTGameStates.ActiveKSC.SPHPlans.Remove(blv.ShipName);
                    message = new ScreenMessage($"[KCT] Replacing previous plan for {blv.ShipName} in the SPH Building Plans list.", 4f, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(message);
                }
                KCTGameStates.ActiveKSC.SPHPlans.Add(blv.ShipName, blv);
                type = "SPH";
            }

            ScrapYardWrapper.ProcessVessel(blv.ExtractedPartNodes);

            KCTDebug.Log($"Added {blv.ShipName} to {type} build list at KSC {KCTGameStates.ActiveKSC.KSCName}. Cost: {blv.Cost}");
            KCTDebug.Log($"Launch site is {blv.LaunchSite}");
            bool   isCommonLine = PresetManager.Instance?.ActivePreset?.GeneralSettings.CommonBuildLine ?? false;
            string text         = isCommonLine ? $"Added {blv.ShipName} to build list." : $"Added {blv.ShipName} to {type} build list.";

            message = new ScreenMessage(text, 4f, ScreenMessageStyle.UPPER_CENTER);
            ScreenMessages.PostScreenMessage(message);
            return(blv);
        }
Example #18
0
        public static double ParseIntegrationTimeFormula(BuildListVessel vessel, List <BuildListVessel> mergedVessels = null)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled ||
                string.IsNullOrEmpty(PresetManager.Instance.ActivePreset.FormulaSettings.IntegrationTimeFormula) ||
                PresetManager.Instance.ActivePreset.FormulaSettings.IntegrationTimeFormula == "0")
            {
                return(0);
            }

            Dictionary <string, string> variables = GetIntegrationRolloutVariables(vessel, mergedVessels);

            return(GetStandardFormulaValue("IntegrationTime", variables));
        }
Example #19
0
        private static void RenderMergeSection(BuildListVessel ship)
        {
            if (!_showMergeSelectionList && KCTGameStates.MergingAvailable && GUILayout.Button("Merge Built Vessel"))
            {
                _showMergeSelectionList = true;
            }

            if (_showMergeSelectionList && KCTGameStates.MergingAvailable)
            {
                if (GUILayout.Button("Hide Merge Selection"))
                {
                    _showMergeSelectionList = false;
                }

                GUILayout.BeginVertical();
                GUILayout.Label("Choose a vessel");

                GUILayout.Label("VAB");
                _vabMergeScroll = GUILayout.BeginScrollView(_vabMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.VABWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.MergedVessels.Exists(x => x.Id == vessel.Id) && GUILayout.Button(vessel.ShipName))
                    {
                        ShipConstruct mergedShip = new ShipConstruct();
                        mergedShip.LoadShip(vessel.ShipNode);
                        EditorLogic.fetch.SpawnConstruct(mergedShip);

                        KCTGameStates.MergedVessels.Add(vessel);
                    }
                }
                GUILayout.EndScrollView();

                GUILayout.Label("SPH");
                _sphMergeScroll = GUILayout.BeginScrollView(_sphMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.SPHWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.MergedVessels.Exists(x => x.Id == vessel.Id) && GUILayout.Button(vessel.ShipName))
                    {
                        ShipConstruct mergedShip = new ShipConstruct();
                        mergedShip.LoadShip(vessel.ShipNode);
                        EditorLogic.fetch.SpawnConstruct(mergedShip);

                        KCTGameStates.MergedVessels.Add(vessel);
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
            }
        }
Example #20
0
            public BuildListVessel ToBuildListVessel()
            {
                BuildListVessel ret = new BuildListVessel(shipName, launchSite, buildTime, flag, cost, EditorFacility);

                ret.progress          = progress;
                ret.id                = new Guid(shipID);
                ret.cannotEarnScience = cannotEarnScience;
                ret.TotalMass         = mass;
                ret.DistanceFromKSC   = kscDistance;
                ret.rushBuildClicks   = rushBuildClicks;
                ret.launchSiteID      = LaunchPadID;
                ret.DesiredManifest   = desiredManifest;
                return(ret);
            }
Example #21
0
        public static double ParseRushCostFormula(BuildListVessel vessel)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled ||
                string.IsNullOrEmpty(PresetManager.Instance.ActivePreset.FormulaSettings.RushCostFormula))
            {
                return(0);
            }

            Dictionary <string, string> variables = GetIntegrationRolloutVariables(vessel);

            variables.Add("TC", vessel.GetTotalCost().ToString());
            variables.Add("RC", vessel.RushBuildClicks.ToString());
            return(GetStandardFormulaValue("RushCost", variables));
        }
Example #22
0
        private void BuildVesselAndShipNodeConfigs(BuildListVessel blv, ref ConfigNode node)
        {
            var storageItem = new BuildListStorageItem();

            storageItem.FromBuildListVessel(blv);
            var cnTemp = new ConfigNode("KCTVessel");

            cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
            var shipNode = new ConfigNode("ShipNode");

            blv.ShipNode.CopyTo(shipNode);
            cnTemp.AddNode(shipNode);
            node.AddNode(cnTemp);
        }
Example #23
0
        public static BuildListVessel AddVesselToPlansList(string launchSite)
        {
            if (string.IsNullOrEmpty(launchSite))
            {
                launchSite = EditorLogic.fetch.launchSiteName;
            }
            double          effCost = Utilities.GetEffectiveCost(EditorLogic.fetch.ship.Parts);
            double          bp      = Utilities.GetBuildTime(effCost);
            BuildListVessel blv     = new BuildListVessel(EditorLogic.fetch.ship, launchSite, effCost, bp, EditorLogic.FlagURL)
            {
                ShipName = EditorLogic.fetch.shipNameField.text
            };

            return(AddVesselToPlansList(blv));
        }
Example #24
0
        private static void HandleLaunch()
        {
            try
            {
                bool isSim = Utilities.IsSimulationActive;
                _airlaunchParams.KCTVesselId   = isSim ? FlightGlobals.ActiveVessel.id : KCTGameStates.LaunchedVessel.Id;
                _airlaunchParams.Altitude      = double.Parse(_sAltitude);
                _airlaunchParams.Velocity      = double.Parse(_sVelocity);
                _airlaunchParams.LaunchAzimuth = double.Parse(_sAzimuth);
                _airlaunchParams.KscDistance   = double.Parse(_sKscDistance) * 1000;
                _airlaunchParams.KscAzimuth    = double.Parse(_sKscAzimuth);

                bool valid = _airlaunchParams.Validate(out _errorMsg);
                if (valid)
                {
                    _errorMsg = null;
                    if (isSim)
                    {
                        var kct = KerbalConstructionTime.Instance;
                        kct.StartCoroutine(kct.AirlaunchRoutine(_airlaunchParams, _airlaunchParams.KCTVesselId, skipCountdown: true));
                        ToggleVisibility(false);
                        return;
                    }

                    KCTGameStates.AirlaunchParams = _airlaunchParams;

                    BuildListVessel b = KCTGameStates.LaunchedVessel;
                    if (!IsCrewable(b.ExtractedParts))
                    {
                        b.Launch();
                    }
                    else
                    {
                        GUIStates.ShowAirlaunch = false;
                        KCTGameStates.ToolbarControl?.SetFalse();
                        _centralWindowPosition.height = 1;
                        AssignInitialCrew();
                        GUIStates.ShowShipRoster = true;
                    }
                }
            }
            catch (Exception ex)
            {
                _errorMsg = ex.Message;
                Debug.LogException(ex);
            }
        }
Example #25
0
 public Recon_Rollout(BuildListVessel vessel, RolloutReconType type, string id, string launchSite = "")
 {
     RRType       = type;
     associatedID = id;
     if (launchSite != "") //For when we add custom launchpads
     {
         launchPadID = launchSite;
     }
     else
     {
         launchPadID = vessel.launchSite;
     }
     //BP = vessel.GetTotalMass() * KCT_GameStates.timeSettings.ReconditioningEffect * KCT_GameStates.timeSettings.OverallMultiplier; //1 day per 50 tons (default) * overall multiplier
     //BP = KCT_MathParsing.GetStandardFormulaValue("Reconditioning", new Dictionary<string, string>() {{"M", vessel.GetTotalMass().ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()},
     //    {"E", KCT_PresetManager.Instance.ActivePreset.timeSettings.ReconditioningEffect.ToString()}, {"X", KCT_PresetManager.Instance.ActivePreset.timeSettings.MaxReconditioning.ToString()}});
     //if (BP > KCT_GameStates.timeSettings.MaxReconditioning) BP = KCT_GameStates.timeSettings.MaxReconditioning;
     progress = 0;
     if (type == RolloutReconType.Reconditioning)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(vessel, true);
         //BP *= (1 - KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit);
         name = "LaunchPad Reconditioning";
     }
     else if (type == RolloutReconType.Rollout)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(vessel, false);
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         name = "Vessel Rollout";
         cost = KCT_MathParsing.ParseRolloutCostFormula(vessel);
     }
     else if (type == RolloutReconType.Rollback)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(vessel, false);
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         progress = BP;
         name     = "Vessel Rollback";
     }
     else if (type == RolloutReconType.Recovery)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(vessel, false);
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         name = "Vessel Recovery";
         double maxDist = SpaceCenter.Instance.cb.Radius * Math.PI;
         BP += BP * (vessel.DistanceFromKSC / maxDist);
     }
 }
Example #26
0
        private IEnumerator RunValidationRoutine(BuildListVessel blv)
        {
            if (ProcessFacilityChecks(blv) != ValidationResult.Success)
            {
                _failureActions();
                yield break;
            }

            ProcessPartAvailability(blv);
            while (_validationResult == ValidationResult.Undecided)
            {
                yield return(null);
            }

            _routine = null;
            if (_validationResult != ValidationResult.Success)
            {
                _failureActions();
                yield break;
            }

            do
            {
                ProcessPartConfigs(blv);
                while (_validationResult == ValidationResult.Undecided)
                {
                    yield return(null);
                }
            }while (_validationResult == ValidationResult.Rerun);

            _routine = null;
            if (_validationResult != ValidationResult.Success)
            {
                _failureActions();
                yield break;
            }

            if (ProcessFundsChecks(blv) != ValidationResult.Success)
            {
                _failureActions();
                yield break;
            }

            _successActions(blv);
        }
Example #27
0
        public ReconRollout(BuildListVessel vessel, RolloutReconType type, string id, string launchSite = "")
        {
            RRType       = type;
            AssociatedID = id;
            if (launchSite != "") //For when we add custom launchpads
            {
                LaunchPadID = launchSite;
            }
            else
            {
                LaunchPadID = vessel.LaunchSite;
            }

            Progress = 0;
            if (type == RolloutReconType.Reconditioning)
            {
                BP = MathParser.ParseReconditioningFormula(vessel, true);
                //BP *= (1 - KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit);
                Name = "LaunchPad Reconditioning";
            }
            else if (type == RolloutReconType.Rollout)
            {
                BP = MathParser.ParseReconditioningFormula(vessel, false);
                //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
                Name = "Vessel Rollout";
                Cost = MathParser.ParseRolloutCostFormula(vessel);
            }
            else if (type == RolloutReconType.Rollback)
            {
                BP = MathParser.ParseReconditioningFormula(vessel, false);
                //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
                Progress = BP;
                Name     = "Vessel Rollback";
            }
            else if (type == RolloutReconType.Recovery)
            {
                BP = MathParser.ParseReconditioningFormula(vessel, false);
                //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
                Name = "Vessel Recovery";
                double maxDist = SpaceCenter.Instance.cb.Radius * Math.PI;
                BP += BP * (vessel.DistanceFromKSC / maxDist);
            }
        }
Example #28
0
 public BuildListItem FromBuildListVessel(BuildListVessel blv)
 {
     this.progress   = blv.progress;
     this.buildTime  = blv.buildPoints;
     this.launchSite = blv.launchSite;
     this.flag       = blv.flag;
     //this.shipURL = blv.shipURL;
     this.shipName          = blv.shipName;
     this.shipID            = blv.id.ToString();
     this.cannotEarnScience = blv.cannotEarnScience;
     this.cost            = blv.cost;
     this.rushBuildClicks = blv.rushBuildClicks;
     this.mass            = blv.TotalMass;
     this.kscDistance     = blv.DistanceFromKSC;
     this.EditorFacility  = (int)blv.GetEditorFacility();
     this.LaunchPadID     = blv.launchSiteID;
     this.desiredManifest = blv.DesiredManifest;
     return(this);
 }
Example #29
0
        private ValidationResult ProcessFundsChecks(BuildListVessel blv)
        {
            if (CheckAvailableFunds)
            {
                double totalCost = blv.GetTotalCost();
                double prevFunds = Funding.Instance.Funds;
                if (totalCost > prevFunds)
                {
                    KCTDebug.Log($"Tried to add {blv.ShipName} to build list but not enough funds.");
                    KCTDebug.Log($"Vessel cost: {Utilities.GetTotalVesselCost(blv.ShipNode)}, Current funds: {prevFunds}");
                    var msg = new ScreenMessage("Not Enough Funds To Build!", 4f, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(msg);

                    return(ValidationResult.Fail);
                }
            }

            return(ValidationResult.Success);
        }
Example #30
0
        public BuildListVessel ToBuildListVessel()
        {
            var ret = new BuildListVessel(shipName, launchSite, effectiveCost, buildTime, integrationTime, flag, cost, integrationCost, EditorFacility)
            {
                Progress          = progress,
                Id                = new Guid(shipID),
                CannotEarnScience = cannotEarnScience,
                TotalMass         = mass,
                NumStageParts     = numStageParts,
                NumStages         = numStages,
                StagePartCost     = stagePartCost,
                DistanceFromKSC   = kscDistance,
                RushBuildClicks   = rushBuildClicks,
                LaunchSiteID      = LaunchPadID,
                BuildListIndex    = BuildListIndex,
                DesiredManifest   = desiredManifest
            };

            return(ret);
        }