Exemple #1
0
        private void StageRecoverySuccessEvent(Vessel v, float[] infoArray, string reason)
        {
            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }
            KCTDebug.Log("Recovery Success Event triggered.");
            float damage = 0;

            if (infoArray.Length == 3)
            {
                damage = infoArray[0];
            }
            else
            {
                KCTDebug.Log("Malformed infoArray received!");
            }
            System.Random            rand      = new System.Random();
            Dictionary <string, int> destroyed = new Dictionary <string, int>();

            foreach (ProtoPartSnapshot part in v.protoVessel.protoPartSnapshots)
            {
                float random = (float)rand.NextDouble();
                // string name = part.partInfo.name + KCT_Utilities.GetTweakScaleSize(part);
                if (random < damage)
                {
                    KCT_Utilities.AddPartToInventory(part);
                }
                else
                {
                    string commonName = part.partInfo.title + KCT_Utilities.GetTweakScaleSize(part);
                    Debug.Log("[KCT] Part " + commonName + " was too damaged to be used anymore and was scrapped! Chance: " + damage);
                    if (!destroyed.ContainsKey(commonName))
                    {
                        destroyed.Add(commonName, 1);
                    }
                    else
                    {
                        ++destroyed[commonName];
                    }
                }
            }

            if (destroyed.Count > 0 && !KCT_GameStates.settings.DisableAllMessages)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendLine("The following parts were too damaged to be reused and were scrapped:");
                foreach (KeyValuePair <string, int> entry in destroyed)
                {
                    msg.AppendLine(entry.Value + " x " + entry.Key);
                }
                msg.AppendLine("\nChance of failure: " + Math.Round(100 * damage) + "%");
                KCT_Utilities.DisplayMessage("KCT: Parts Scrapped", msg, MessageSystemButton.MessageButtonColor.ORANGE, MessageSystemButton.ButtonIcons.ALERT);
            }
        }
Exemple #2
0
        //private ProtoVessel recovered;

        public KCT_BuildListVessel(Vessel vessel) //For recovered vessels
        {
            /* if (KCT_GameStates.recoveryRequestVessel == null)
             * {
             *   KCTDebug.Log("Somehow tried to recover something that was null!");
             *   return;
             * }*/


            id       = Guid.NewGuid();
            shipName = vessel.vesselName;
            shipNode = FromInFlightVessel(vessel);

            cost           = KCT_Utilities.GetTotalVesselCost(shipNode);
            emptyCost      = KCT_Utilities.GetTotalVesselCost(shipNode, false);
            TotalMass      = 0;
            emptyMass      = 0;
            InventoryParts = new Dictionary <string, int>();
            foreach (ProtoPartSnapshot p in vessel.protoVessel.protoPartSnapshots)
            {
                //InventoryParts.Add(p.partInfo.name + KCT_Utilities.GetTweakScaleSize(p));
                string name = p.partInfo.name;
                int    amt  = 1;
                if (KCT_Utilities.PartIsProcedural(p))
                {
                    float dry, wet;
                    ShipConstruction.GetPartCosts(p, p.partInfo, out dry, out wet);
                    amt = (int)(1000 * dry);
                }
                else
                {
                    name += KCT_Utilities.GetTweakScaleSize(p);
                }
                KCT_Utilities.AddToDict(InventoryParts, name, amt);

                TotalMass += p.mass;
                emptyMass += p.mass;
                foreach (ProtoPartResourceSnapshot rsc in p.resources)
                {
                    PartResourceDefinition def = PartResourceLibrary.Instance.GetDefinition(rsc.resourceName);
                    if (def != null)
                    {
                        TotalMass += def.density * float.Parse(rsc.resourceValues.GetValue("amount"));
                    }
                }
            }
            cannotEarnScience = true;

            buildPoints = KCT_Utilities.GetBuildTime(shipNode.GetNodes("PART").ToList(), true, InventoryParts);
            flag        = HighLogic.CurrentGame.flagURL;
            progress    = buildPoints;

            DistanceFromKSC = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));
        }
Exemple #3
0
        private static void DrawBLPlusWindow(int windowID)
        {
            //bLPlusPosition.xMax = buildListWindowPosition.xMin;
            //bLPlusPosition.width = 100;
            bLPlusPosition.yMin   = buildListWindowPosition.yMin;
            bLPlusPosition.height = 225;
            //bLPlusPosition.height = bLPlusPosition.yMax - bLPlusPosition.yMin;
            KCT_BuildListVessel b = KCT_Utilities.FindBLVesselByID(IDSelected);

            GUILayout.BeginVertical();
            if (GUILayout.Button("Scrap"))
            {
                InputLockManager.SetControlLock(ControlTypes.KSC_ALL, "KCTPopupLock");
                DialogOption[] options = new DialogOption[2];
                options[0] = new DialogOption("Yes", ScrapVessel);
                options[1] = new DialogOption("No", DummyVoid);
                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", windowTitle: "Scrap Vessel", options: options);
                PopupDialog.SpawnPopupDialog(diag, false, windowSkin);
                showBLPlus = false;
                ResetBLWindow();
            }
            if (GUILayout.Button("Edit"))
            {
                showBLPlus = false;
                editorWindowPosition.height = 1;
                string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft";
                b.shipNode.Save(tempFile);
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                KCT_GameStates.editedVessel          = b;
                KCT_GameStates.EditorShipEditingMode = true;
                KCT_GameStates.delayStart            = true;

                InputLockManager.SetControlLock(ControlTypes.EDITOR_EXIT, "KCTEditExit");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LOAD, "KCTEditLoad");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_NEW, "KCTEditNew");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTEditLaunch");

                KCT_GameStates.EditedVesselParts.Clear();
                foreach (ConfigNode node in b.ExtractedPartNodes)
                {
                    string name = KCT_Utilities.PartNameFromNode(node) + KCT_Utilities.GetTweakScaleSize(node);
                    if (!KCT_GameStates.EditedVesselParts.ContainsKey(name))
                    {
                        KCT_GameStates.EditedVesselParts.Add(name, 1);
                    }
                    else
                    {
                        ++KCT_GameStates.EditedVesselParts[name];
                    }
                }

                //EditorDriver.StartAndLoadVessel(tempFile);
                EditorDriver.StartAndLoadVessel(tempFile, b.type == KCT_BuildListVessel.ListType.VAB ? EditorFacility.VAB : EditorFacility.SPH);
            }
            if (GUILayout.Button("Rename"))
            {
                centralWindowPosition.width  = 360;
                centralWindowPosition.x      = (Screen.width - 360) / 2;
                centralWindowPosition.height = 1;
                showBuildList = false;
                showBLPlus    = false;
                showRename    = true;
                newName       = b.shipName;
                //newDesc = b.getShip().shipDescription;
            }
            if (GUILayout.Button("Duplicate"))
            {
                KCT_Utilities.AddVesselToBuildList(b.NewCopy(true), b.InventoryParts.Count > 0);
            }
            if (KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()) != null && GUILayout.Button("Rollback"))
            {
                KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()).SwapRolloutType();
            }
            if (!b.isFinished && GUILayout.Button("Warp To"))
            {
                KCT_GameStates.targetedItem = b;
                KCT_GameStates.canWarp      = true;
                KCT_Utilities.RampUpWarp(b);
                KCT_GameStates.warpInitiated = true;
                showBLPlus = false;
            }
            if (!b.isFinished && GUILayout.Button("Move to Top"))
            {
                if (b.type == KCT_BuildListVessel.ListType.VAB)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.VABList.Insert(0, b);
                }
                else if (b.type == KCT_BuildListVessel.ListType.SPH)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.SPHList.Insert(0, b);
                }
            }
            if (!b.isFinished && GUILayout.Button("Rush Build 10%\n√" + Math.Round(0.2 * b.GetTotalCost())))
            {
                double cost = b.GetTotalCost();
                cost *= 0.2;
                double remainingBP = b.buildPoints - b.progress;
                if (Funding.Instance.Funds >= cost)
                {
                    b.AddProgress(remainingBP * 0.1);
                    KCT_Utilities.SpendFunds(cost, TransactionReasons.None);
                }
            }
            if (GUILayout.Button("Close"))
            {
                showBLPlus = false;
            }
            GUILayout.EndVertical();
            float width = bLPlusPosition.width;

            bLPlusPosition.x     = buildListWindowPosition.x - width;
            bLPlusPosition.width = width;
        }