Beispiel #1
0
        public static void RecalculateEditorBuildTime(ShipConstruct ship)
        {
            KCTDebug.Log("Recalculating build time");
            List <ConfigNode> partNodes = ship.SaveShip().GetNodes("PART").ToList();

            KCT_GUI.PartsInUse.Clear();
            if (KCT_GUI.useInventory)
            {
                foreach (ConfigNode part in partNodes)
                {
                    string name = PartNameFromNode(part) + GetTweakScaleSize(part);
                    if (!KCT_GUI.PartsInUse.ContainsKey(name))
                    {
                        KCT_GUI.PartsInUse.Add(name, 1);
                    }
                    else
                    {
                        ++KCT_GUI.PartsInUse[name];
                    }
                }
            }

            if (!KCT_GameStates.EditorShipEditingMode)
            {
                KCT_GameStates.EditorBuildTime = KCT_Utilities.GetBuildTime(partNodes, true, KCT_GUI.useInventory);
            }
            else
            {
                List <string> partsForInventory = new List <string>();
                if (KCT_GUI.useInventory)
                {
                    List <string> newParts     = new List <string>(PartDictToList(KCT_GUI.PartsInUse));
                    List <string> theInventory = new List <string>(PartDictToList(KCT_GameStates.PartInventory));
                    foreach (string s in PartDictToList(KCT_GameStates.EditedVesselParts))
                    {
                        if (newParts.Contains(s))
                        {
                            newParts.Remove(s);
                        }
                    }

                    foreach (string s in newParts)
                    {
                        if (theInventory.Contains(s))
                        {
                            theInventory.Remove(s);
                            partsForInventory.Add(s);
                        }
                    }
                }
                foreach (string s in KCT_GameStates.editedVessel.InventoryParts)
                {
                    partsForInventory.Add(s);
                }

                KCT_GameStates.EditorBuildTime = KCT_Utilities.GetBuildTime(partNodes, true, partsForInventory);
            }
        }
Beispiel #2
0
        public KCT_BuildListVessel NewCopy(bool RecalcTime)
        {
            KCT_BuildListVessel ret = new KCT_BuildListVessel(this.shipName, this.launchSite, this.buildPoints, this.flag, this.cost);

            ret.shipNode = this.shipNode.CreateCopy();
            ret.id       = Guid.NewGuid();
            if (RecalcTime)
            {
                ret.buildPoints = KCT_Utilities.GetBuildTime(ret.ExtractedPartNodes, true, this.InventoryParts.Count > 0);
            }
            return(ret);
        }
        public static void DelayedStart()
        {
            if (!updateChecked)
            {
                if (KCT_GameStates.settings.CheckForUpdates && !KCT_GameStates.firstStart) //Check for updates
                {
                    KCT_UpdateChecker.CheckForUpdate(false, KCT_GameStates.settings.VersionSpecific);
                }
                updateChecked = true;
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.buildSimulatedVessel)
            {
                KCT_GameStates.buildSimulatedVessel = false;
                KCT_BuildListVessel toBuild = KCT_GameStates.launchedVessel.NewCopy(false);
                toBuild.buildPoints = KCT_Utilities.GetBuildTime(toBuild.ExtractedPartNodes, true, KCT_GUI.useInventory);
                KCT_Utilities.AddVesselToBuildList(toBuild, KCT_GUI.useInventory);
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsToChargeAtSimEnd != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsToChargeAtSimEnd);
                KCT_GameStates.FundsToChargeAtSimEnd = 0;
            }
            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsGivenForVessel != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsGivenForVessel);
                KCT_GameStates.FundsGivenForVessel = 0;
            }

            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated)
            {
                KCT_GUI.hideAll();
                if (FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                {
                    bool removed = KCT_GameStates.launchedVessel.RemoveFromBuildList();
                    if (removed) //Only do these when the vessel is first removed from the list
                    {
                        //Add the cost of the ship to the funds so it can be removed again by KSP
                        KCT_Utilities.AddFunds(KCT_Utilities.GetTotalVesselCost(FlightGlobals.ActiveVessel.protoVessel));
                        FlightGlobals.ActiveVessel.vesselName = KCT_GameStates.launchedVessel.shipName;
                    }
                }

                List <VesselType> invalidTypes = new List <VesselType> {
                    VesselType.Debris, VesselType.SpaceObject, VesselType.Unknown
                };
                if (!invalidTypes.Contains(FlightGlobals.ActiveVessel.vesselType) && !KCT_GameStates.BodiesVisited.Contains(FlightGlobals.ActiveVessel.mainBody.bodyName))
                {
                    KCT_GameStates.BodiesVisited.Add(FlightGlobals.ActiveVessel.mainBody.bodyName);
                    var message = new ScreenMessage("[KCT] New simulation body unlocked: " + FlightGlobals.ActiveVessel.mainBody.bodyName, 4.0f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage(message, true);
                    KCTDebug.Log("Unlocked sim body: " + FlightGlobals.ActiveVessel.mainBody.bodyName);
                }
            }
            if (HighLogic.LoadedSceneIsFlight && KCT_GameStates.flightSimulated)
            {
                KCTDebug.Log("Simulation started");
                KCT_GUI.hideAll();
                KCT_GUI.showSimulationWindow = true;
                KCT_GUI.showTimeRemaining    = true;
            }
            if (HighLogic.LoadedSceneIsEditor)
            {
                if (KCT_GameStates.EditorShipEditingMode)
                {
                    KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName);
                    EditorLogic.fetch.shipNameField.Text = KCT_GameStates.editedVessel.shipName;
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    if (KCT_GameStates.settings.OverrideLaunchButton)
                    {
                        KCTDebug.Log("Taking control of launch button");
                        EditorLogic.fetch.launchBtn.methodToInvoke           = "ShowLaunchAlert";
                        EditorLogic.fetch.launchBtn.scriptWithMethodToInvoke = Kerbal_Construction_Time.instance;
                    }
                    else
                    {
                        InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTLaunchLock");
                    }
                }
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                if (KCT_Utilities.CurrentGameHasScience() && KCT_GameStates.TotalUpgradePoints == 0)
                {
                    ConfigNode CN = new ConfigNode();
                    ResearchAndDevelopment.Instance.snapshot.Save(CN);
                    ConfigNode[] techNodes = CN.GetNodes("Tech");
                    KCTDebug.Log("technodes length: " + techNodes.Length);
                    KCT_GameStates.TotalUpgradePoints = techNodes.Length + 14;
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showBuildList = KCT_GameStates.showWindows[0];
                    KCT_GUI.ResetBLWindow();
                }
                else
                {
                    KCT_GUI.showBuildList         = false;
                    KCT_GameStates.showWindows[0] = false;
                }
                if (KCT_GameStates.firstStart)
                {
                    KCTDebug.Log("Showing first start.");
                    KCT_GUI.showFirstRun = true;
                }
                KCT_GameStates.firstStart = false;
            }
        }
Beispiel #4
0
        public static KCT_BuildListVessel AddVesselToBuildList(Dictionary <String, int> inventory)
        {
            KCT_BuildListVessel blv = new KCT_BuildListVessel(EditorLogic.fetch.ship, EditorLogic.fetch.launchSiteName, KCT_Utilities.GetBuildTime(EditorLogic.fetch.ship.SaveShip().GetNodes("PART").ToList(), true, inventory), EditorLogic.FlagURL);

            blv.shipName = EditorLogic.fetch.shipNameField.Text;
            return(AddVesselToBuildList(blv, inventory));
        }
Beispiel #5
0
        public static void MoveVesselToWarehouse(int ListIdentifier, int index)
        {
            if (ToolbarManager.ToolbarAvailable)
            {
                KCT_GameStates.kctToolbarButton.Important = true; //Show the button if it is hidden away
                startedFlashing = DateTime.Now;                   //Set the time to start flashing
            }

            if (KCT_GameStates.settings.ForceStopWarp && TimeWarp.CurrentRateIndex != 0)
            {
                TimeWarp.SetRate(0, true);
                KCT_GameStates.warpInitiated = false;
            }

            StringBuilder Message = new StringBuilder();

            Message.AppendLine("The following vessel is complete:");
            KCT_BuildListVessel vessel = null;

            if (ListIdentifier == 0) //VAB list
            {
                vessel = KCT_GameStates.VABList[index];
                KCT_GameStates.VABList.RemoveAt(index);
                KCT_GameStates.VABWarehouse.Add(vessel);

                Message.AppendLine(vessel.shipName);
                Message.AppendLine("Please check the VAB Storage to launch it.");
            }
            else if (ListIdentifier == 1)//SPH list
            {
                vessel = KCT_GameStates.SPHList[index];
                KCT_GameStates.SPHList.RemoveAt(index);
                KCT_GameStates.SPHWarehouse.Add(vessel);

                Message.AppendLine(vessel.shipName);
                Message.AppendLine("Please check the SPH Storage to launch it.");
            }

            //Assign science based on science rate
            if (CurrentGameHasScience() && !vessel.cannotEarnScience)
            {
                AddScienceWithMessage((float)(KCT_GameStates.RDUpgrades[0] * 0.5 * vessel.buildPoints / 86400));
            }

            //Add parts to the tracker
            if (!vessel.cannotEarnScience)
            {
                List <string> trackedParts = new List <string>();
                foreach (ConfigNode p in vessel.ExtractedPartNodes)
                {
                    if (!trackedParts.Contains(PartNameFromNode(p) + GetTweakScaleSize(p)))
                    {
                        AddPartToTracker(PartNameFromNode(p) + GetTweakScaleSize(p));
                        trackedParts.Add(PartNameFromNode(p) + GetTweakScaleSize(p));
                    }
                }
            }

            string stor = ListIdentifier == 0 ? "VAB" : "SPH";

            KCTDebug.Log("Moved vessel " + vessel.shipName + " to " + stor + " storage.");

            foreach (KCT_BuildListVessel blv in KCT_GameStates.VABList)
            {
                double newTime = KCT_Utilities.GetBuildTime(blv.ExtractedPartNodes, true, blv.InventoryParts); //Use only the parts that were originally used when recalculating
                if (newTime < blv.buildPoints)
                {
                    blv.buildPoints = blv.buildPoints - ((blv.buildPoints - newTime) * (100 - blv.ProgressPercent()) / 100.0); //If progress=0% then set to new build time, 100%=no change, 50%=half of difference.
                }
            }
            foreach (KCT_BuildListVessel blv in KCT_GameStates.SPHList)
            {
                double newTime = KCT_Utilities.GetBuildTime(blv.ExtractedPartNodes, true, blv.InventoryParts);
                if (newTime < blv.buildPoints)
                {
                    blv.buildPoints = blv.buildPoints - ((blv.buildPoints - newTime) * (100 - blv.ProgressPercent()) / 100.0); //If progress=0% then set to new build time, 100%=no change, 50%=half of difference.
                }
            }
            KCT_GUI.ResetBLWindow();
            if (!KCT_GameStates.settings.DisableAllMessages)
            {
                DisplayMessage("Vessel Complete!", Message, MessageSystemButton.MessageButtonColor.GREEN, MessageSystemButton.ButtonIcons.COMPLETE);
            }
        }