Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// For recovered vessels
        /// </summary>
        /// <param name="vessel"></param>
        /// <param name="listType"></param>
        public BuildListVessel(Vessel vessel, ListType listType = ListType.None)
        {
            Id = Guid.NewGuid();
            KCTPersistentID = Guid.NewGuid().ToString();
            ShipName        = vessel.vesselName;
            ShipNode        = FromInFlightVessel(vessel, listType);
            if (listType != ListType.None)
            {
                Type = listType;
            }

            Cost      = Utilities.GetTotalVesselCost(ShipNode);
            EmptyCost = Utilities.GetTotalVesselCost(ShipNode, false);
            TotalMass = 0;
            EmptyMass = 0;

            HashSet <int> stages = new HashSet <int>();

            foreach (ProtoPartSnapshot p in vessel.protoVessel.protoPartSnapshots)
            {
                stages.Add(p.inverseStageIndex);

                if (p.partPrefab != null)
                {
                    if (p.partPrefab.Modules.Contains <LaunchClamp>() || p.partPrefab.HasTag("PadInfrastructure"))
                    {
                        continue;
                    }
                }

                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)rsc.amount;
                    }
                }
            }
            CannotEarnScience = true;
            NumStages         = stages.Count;
            // FIXME ignore stageable part count and cost - it'll be fixed when we put this back in the editor.

            EffectiveCost = Utilities.GetEffectiveCost(ShipNode.GetNodes("PART").ToList());
            BuildPoints   = Utilities.GetBuildTime(EffectiveCost);
            Flag          = HighLogic.CurrentGame.flagURL;

            DistanceFromKSC = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));

            RushBuildClicks   = 0;
            IntegrationPoints = MathParser.ParseIntegrationTimeFormula(this);
            IntegrationCost   = (float)MathParser.ParseIntegrationCostFormula(this);

            Progress = BuildPoints + IntegrationPoints;
        }
Esempio n. 3
0
        public double GetTotalCost()
        {
            if (Cost == 0 || EmptyCost == 0)
            {
                Cost            = Utilities.GetTotalVesselCost(ShipNode);
                EmptyCost       = Utilities.GetTotalVesselCost(ShipNode, false);
                IntegrationCost = (float)MathParser.ParseIntegrationCostFormula(this);
            }

            return(Cost + IntegrationCost);
        }
Esempio n. 4
0
        public BuildListVessel(ShipConstruct s, string ls, double effCost, double bP, string flagURL)
        {
            _ship    = s;
            ShipNode = s.SaveShip();
            // Override KSP sizing of the ship construct
            ShipSize = Utilities.GetShipSize(s, true);
            ShipNode.SetValue("size", KSPUtil.WriteVector(ShipSize));
            ShipName  = s.shipName;
            Cost      = Utilities.GetTotalVesselCost(ShipNode, true);
            EmptyCost = Utilities.GetTotalVesselCost(ShipNode, false);
            TotalMass = Utilities.GetShipMass(s, true, out EmptyMass, out _);

            HashSet <int> stages = new HashSet <int>();

            NumStageParts = 0;
            StagePartCost = 0d;

            foreach (Part p in s.Parts)
            {
                if (p.stagingOn)
                {
                    stages.Add(p.inverseStage);
                    ++NumStageParts;
                    StagePartCost += p.GetModuleCosts(p.partInfo.cost, ModifierStagingSituation.CURRENT) + p.partInfo.cost;
                }
            }
            NumStages = stages.Count;

            LaunchSite    = ls;
            EffectiveCost = effCost;
            BuildPoints   = bP;
            Progress      = 0;
            Flag          = flagURL;
            if (s.shipFacility == EditorFacility.VAB)
            {
                Type            = ListType.VAB;
                FacilityBuiltIn = EditorFacility.VAB;
            }
            else if (s.shipFacility == EditorFacility.SPH)
            {
                Type            = ListType.SPH;
                FacilityBuiltIn = EditorFacility.SPH;
            }
            else
            {
                Type = ListType.None;
            }
            Id = Guid.NewGuid();
            KCTPersistentID   = Guid.NewGuid().ToString();
            CannotEarnScience = false;

            //get the crew from the editorlogic
            DesiredManifest = new List <string>();
            if (CrewAssignmentDialog.Instance?.GetManifest()?.CrewCount > 0)
            {
                foreach (ProtoCrewMember crew in CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List <ProtoCrewMember>())
                {
                    DesiredManifest.Add(crew?.name ?? string.Empty);
                }
            }

            if (EffectiveCost == default)
            {
                // Can only happen in older saves that didn't have Effective cost persisted as a separate field
                // This code should be safe to remove after a while.
                EffectiveCost = Utilities.GetEffectiveCost(ShipNode.GetNodes("PART").ToList());
            }

            IntegrationPoints = MathParser.ParseIntegrationTimeFormula(this);
            IntegrationCost   = (float)MathParser.ParseIntegrationCostFormula(this);
        }