Beispiel #1
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 #2
0
        public override void OnDecodeFromConfigNode()
        {
            KCT_GameStates.VABList.Clear();
            KCT_GameStates.SPHList.Clear();
            KCT_GameStates.VABWarehouse.Clear();
            KCT_GameStates.SPHWarehouse.Clear();

            foreach (BuildListItem b in VABBuildList)
            {
                KCT_BuildListVessel blv = b.ToBuildListVessel();
                //if (ListContains(blv, KCT_GameStates.VABList) < 0)
                KCT_GameStates.VABList.Add(blv);
            }
            foreach (BuildListItem b in SPHBuildList)
            {
                KCT_BuildListVessel blv = b.ToBuildListVessel();
                //if (ListContains(blv, KCT_GameStates.SPHList) < 0)
                KCT_GameStates.SPHList.Add(blv);
            }
            foreach (BuildListItem b in VABWarehouse)
            {
                KCT_BuildListVessel blv = b.ToBuildListVessel();
                // if (ListContains(blv, KCT_GameStates.VABWarehouse) < 0)
                KCT_GameStates.VABWarehouse.Add(blv);
            }
            foreach (BuildListItem b in SPHWarehouse)
            {
                KCT_BuildListVessel blv = b.ToBuildListVessel();
                // if (ListContains(blv, KCT_GameStates.SPHWarehouse) < 0)
                KCT_GameStates.SPHWarehouse.Add(blv);
            }
            KCT_GameStates.LaunchPadReconditioning = LPRecon;
        }
Beispiel #3
0
        public static KCT_BuildListVessel NextShipToFinish()
        {
            KCT_BuildListVessel ship = null;
            double shortestTime      = double.PositiveInfinity;

            foreach (KCT_BuildListVessel blv in KCT_GameStates.VABList)
            {
                double time = blv.timeLeft;
                if (time < shortestTime)
                {
                    ship         = blv;
                    shortestTime = time;
                }
            }
            foreach (KCT_BuildListVessel blv in KCT_GameStates.SPHList)
            {
                double time = blv.timeLeft;
                if (time < shortestTime)
                {
                    ship         = blv;
                    shortestTime = time;
                }
            }
            return(ship);
        }
Beispiel #4
0
        public static KCT_BuildListVessel AddVesselToBuildList(KCT_BuildListVessel blv, bool useInventory)
        {
            Dictionary <String, int> inventory = new Dictionary <string, int>();

            if (useInventory)
            {
                inventory = KCT_GameStates.PartInventory;
            }
            return(AddVesselToBuildList(blv, inventory));
        }
Beispiel #5
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);
        }
Beispiel #6
0
            public KCT_BuildListVessel ToBuildListVessel()
            {
                KCT_BuildListVessel ret = new KCT_BuildListVessel(shipName, launchSite, buildTime, flag, cost);

                ret.progress = progress;
                if (InventoryParts != null)
                {
                    ret.InventoryParts = InventoryParts;
                }
                ret.id = new Guid(shipID);
                ret.cannotEarnScience = cannotEarnScience;
                return(ret);
            }
Beispiel #7
0
 public static double GetBuildRate(KCT_BuildListVessel ship)
 {
     if (ship.type == KCT_BuildListVessel.ListType.VAB)
     {
         return(GetBuildRate(KCT_GameStates.VABList.IndexOf(ship), ship.type));
     }
     else if (ship.type == KCT_BuildListVessel.ListType.SPH)
     {
         return(GetBuildRate(KCT_GameStates.SPHList.IndexOf(ship), ship.type));
     }
     else
     {
         return(0);
     }
 }
Beispiel #8
0
            public BuildListItem FromBuildListVessel(KCT_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.InventoryParts    = blv.InventoryParts;
                this.shipID            = blv.id.ToString();
                this.cannotEarnScience = blv.cannotEarnScience;
                this.cost = blv.cost;

                return(this);
            }
Beispiel #9
0
        public static KCT_BuildListVessel AddVesselToBuildList(KCT_BuildListVessel blv, Dictionary <String, int> inventory)
        {
            if (CurrentGameIsCareer())
            {
                float  totalCost = blv.cost;
                double prevFunds = Funding.Instance.Funds;
                double newFunds  = SpendFunds(totalCost);
                if (prevFunds == newFunds)
                {
                    KCTDebug.Log("Tried to add " + blv.shipName + " to build list but not enough funds.");
                    KCTDebug.Log("Vessel cost: " + blv.cost + ", Current funds: " + newFunds);
                    var msg = new ScreenMessage("Not Enough Funds To Build!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(msg, true);
                    return(blv);
                }
            }
            string type = "";

            if (blv.type == KCT_BuildListVessel.ListType.VAB)
            {
                KCT_GameStates.VABList.Add(blv);
                type = "VAB";
            }
            else if (blv.type == KCT_BuildListVessel.ListType.SPH)
            {
                KCT_GameStates.SPHList.Add(blv);
                type = "SPH";
            }
            if (inventory.Count > 0)
            {
                foreach (ConfigNode p in blv.ExtractedPartNodes)
                {
                    if (KCT_Utilities.RemovePartFromInventory(p, inventory))
                    {
                        blv.InventoryParts.Add(PartNameFromNode(p) + GetTweakScaleSize(p));
                    }
                }
            }
            KCTDebug.Log("Added " + blv.shipName + " to " + type + " build list. Cost: " + blv.cost);
            //KCTDebug.Log("Cost Breakdown (total, parts, fuel): " + blv.totalCost + ", " + blv.dryCost + ", " + blv.fuelCost);
            var message = new ScreenMessage("[KCT] Added " + blv.shipName + " to " + type + " build list.", 4.0f, ScreenMessageStyle.UPPER_CENTER);

            ScreenMessages.PostScreenMessage(message, true);
            return(blv);
        }
Beispiel #10
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.GetPartNames(), true, this.InventoryParts.Count > 0);
     }
     return ret;
 }
Beispiel #11
0
 public static double GetBuildRate(KCT_BuildListVessel ship)
 {
     if (ship.type == KCT_BuildListVessel.ListType.VAB)
         return GetBuildRate(KCT_GameStates.VABList.IndexOf(ship), ship.type);
     else if (ship.type == KCT_BuildListVessel.ListType.SPH)
         return GetBuildRate(KCT_GameStates.SPHList.IndexOf(ship), ship.type);
     else
         return 0;
 }
Beispiel #12
0
 public static double GetBuildRate(int index, KCT_BuildListVessel.ListType type)
 {
     double ret = 0;
     if (type == KCT_BuildListVessel.ListType.VAB)
     {
         if (KCT_GameStates.VABUpgrades.Count - 1 >= index)
         {
             ret = KCT_GameStates.VABUpgrades[index] * (index+1) * 0.05;
             if (index == 0) ret += 0.1;
         }
     }
     else if (type == KCT_BuildListVessel.ListType.SPH)
     {
         if (KCT_GameStates.SPHUpgrades.Count - 1 >= index)
         {
             ret = KCT_GameStates.SPHUpgrades[index] * (index+1) * 0.05;
             if (index == 0) ret += 0.1;
         }
     }
     else if (type == KCT_BuildListVessel.ListType.TechNode)
     {
         ret = Math.Pow(2, KCT_GameStates.RDUpgrades[1] + 1) / 86400.0;
     }
     return ret;
 }
Beispiel #13
0
 public static KCT_BuildListVessel AddVesselToBuildList(KCT_BuildListVessel blv, Dictionary<String, int> inventory)
 {
     if (CurrentGameIsCareer())
     {
         float totalCost = blv.cost;
         double prevFunds = Funding.Instance.Funds;
         double newFunds = SpendFunds(totalCost);
         if (prevFunds == newFunds)
         {
             Debug.Log("[KCT] Tried to add " + blv.shipName + " to build list but not enough funds.");
             Debug.Log("[KCT] Vessel cost: " + blv.cost + ", Current funds: " + newFunds);
             var msg = new ScreenMessage("Not Enough Funds To Build!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
             ScreenMessages.PostScreenMessage(msg, true);
             return blv;
         }
     }
     string type = "";
     if (blv.type == KCT_BuildListVessel.ListType.VAB)
     {
         KCT_GameStates.VABList.Add(blv);
         type = "VAB";
     }
     else if (blv.type == KCT_BuildListVessel.ListType.SPH)
     {
         KCT_GameStates.SPHList.Add(blv);
         type = "SPH";
     }
     if (inventory.Count > 0)
     {
         foreach (string p in blv.GetPartNames())
         {
             if (KCT_Utilities.RemovePartFromInventory(p, inventory))
                 blv.InventoryParts.Add(p);
         }
     }
     Debug.Log("[KCT] Added " + blv.shipName + " to " + type + " build list. Cost: "+blv.cost);
     //Debug.Log("[KCT] Cost Breakdown (total, parts, fuel): " + blv.totalCost + ", " + blv.dryCost + ", " + blv.fuelCost);
     var message = new ScreenMessage("[KCT] Added " + blv.shipName + " to " + type + " build list.", 4.0f, ScreenMessageStyle.UPPER_CENTER);
     ScreenMessages.PostScreenMessage(message, true);
     return blv;
 }
Beispiel #14
0
            public BuildListItem FromBuildListVessel(KCT_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.InventoryParts = blv.InventoryParts;
                this.shipID = blv.id.ToString();
                this.cannotEarnScience = blv.cannotEarnScience;
                this.cost = blv.cost;

                return this;
            }
Beispiel #15
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);
            }
        }
        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 #17
0
 private int ListContains(KCT_BuildListVessel blv, List<KCT_BuildListVessel> list)
 {
     for (int i=0; i<list.Count; i++)
     {
         if (blv.id == list[i].id)
         {
           //  Debug.Log("[KCT] Ship found");
             return i;
         }
     }
        // Debug.Log("[KCT] Ship not found");
     return -1;
 }
Beispiel #18
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.Parts, true, inventory), EditorLogic.FlagURL);
     blv.shipName = EditorLogic.fetch.shipNameField.Text;
     return AddVesselToBuildList(blv, inventory);
 }
Beispiel #19
0
 public KCT_BuildListVessel ToBuildListVessel()
 {
     KCT_BuildListVessel ret = new KCT_BuildListVessel(shipName, launchSite, buildTime, flag, cost);
     ret.progress = progress;
     if (InventoryParts != null)
         ret.InventoryParts = InventoryParts;
     ret.id = new Guid(shipID);
     ret.cannotEarnScience = cannotEarnScience;
     return ret;
 }
Beispiel #20
0
 public static KCT_BuildListVessel AddVesselToBuildList(KCT_BuildListVessel blv, bool useInventory)
 {
     Dictionary<String, int> inventory = new Dictionary<string, int>();
     if (useInventory)
         inventory = KCT_GameStates.PartInventory;
     return AddVesselToBuildList(blv, inventory);
 }