Пример #1
0
        public KCT_BuildListVessel(ShipConstruct s, String ls, double bP, String flagURL)
        {
            ship     = s;
            shipNode = s.SaveShip();
            shipName = s.shipName;
            //Get total ship cost
            float fuel;

            cost      = s.GetShipCosts(out emptyCost, out fuel);
            TotalMass = s.GetShipMass(out emptyMass, out fuel);

            launchSite  = ls;
            buildPoints = bP;
            progress    = 0;
            flag        = flagURL;
            if (s.shipFacility == EditorFacility.VAB)
            {
                type = ListType.VAB;
            }
            else if (s.shipFacility == EditorFacility.SPH)
            {
                type = ListType.SPH;
            }
            else
            {
                type = ListType.None;
            }
            InventoryParts    = new Dictionary <string, int>();
            id                = Guid.NewGuid();
            cannotEarnScience = false;
        }
Пример #2
0
        public KCT_BuildListVessel(ShipConstruct s, String ls, double bP, String flagURL)
        {
            ship     = s;
            shipNode = s.SaveShip();
            shipName = s.shipName;
            //Get total ship cost
            float fuel;

            cost      = s.GetShipCosts(out emptyCost, out fuel);
            TotalMass = s.GetShipMass(out emptyMass, out fuel);

            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;
            buildPoints = bP;
            progress    = 0;
            flag        = flagURL;
            if (s.shipFacility == EditorFacility.VAB)
            {
                type = ListType.VAB;
            }
            else if (s.shipFacility == EditorFacility.SPH)
            {
                type = ListType.SPH;
            }
            else
            {
                type = ListType.None;
            }
            id = Guid.NewGuid();
            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);
                }
            }
        }
Пример #3
0
        private void GetSubassemblyTotalMass(Part rootPart, out double dryMass, out double fuelMass)
        {
            ShipConstruct subassembly = new ShipConstruct();

            AddChildToConstruct(subassembly, rootPart);

            float fltDrymass;
            float fltFuelMass;

            subassembly.GetShipMass(out fltDrymass, out fltFuelMass);

            dryMass  = fltDrymass;
            fuelMass = fltFuelMass;
        }
        bool UpdateEngines(ShipConstruct ship)
        {
            Engines.Clear();
            var thrust = Vector3.zero;

            Mass = DryMass = MinTWR = MaxTWR = 0f;
            ship.GetShipMass(out DryMass, out Mass);
            Mass += DryMass;
            if (TCAScenario.HasTCA && ship.Parts != null)
            {
                (from p in ship.Parts where p.Modules != null
                 from m in p.Modules.GetModules <ModuleEngines>() select m)
                .ForEach(m =>
                {
                    var e = new EngineWrapper(m);
                    Engines.Add(e);
                    e.UpdateThrustInfo();
                    if (CFG != null)
                    {
                        var ecfg = CFG.ActiveProfile.GetConfig(e);
                        if (ecfg == null || ecfg.On)
                        {
                            thrust += e.wThrustDir * e.thrustInfo.thrust;
                        }
                    }
                });
                var T = thrust.magnitude / Utils.G0;
                MinTWR = T / Mass;
                MaxTWR = T / DryMass;
            }
            var ret = Engines.Count > 0;

            if (!ret)
            {
                Reset();
            }
            return(ret);
        }
Пример #5
0
        public KCT_BuildListVessel(ShipConstruct s, String ls, double bP, String flagURL)
        {
            ship = s;
            shipNode = s.SaveShip();
            shipName = s.shipName;
            //Get total ship cost
            float fuel;
            cost = s.GetShipCosts(out emptyCost, out fuel);
            TotalMass = s.GetShipMass(out emptyMass, out fuel);

            launchSite = ls;
            buildPoints = bP;
            progress = 0;
            flag = flagURL;
            if (s.shipFacility == EditorFacility.VAB)
                type = ListType.VAB;
            else if (s.shipFacility == EditorFacility.SPH)
                type = ListType.SPH;
            else
                type = ListType.None;
            InventoryParts = new Dictionary<string, int>();
            id = Guid.NewGuid();
            cannotEarnScience = false;
        }
Пример #6
0
        public KCT_BuildListVessel(ShipConstruct s, String ls, double effCost, double bP, String flagURL)
        {
            ship     = s;
            shipNode = s.SaveShip();
            shipName = s.shipName;
            //Get total ship cost
            float fuel;

            cost      = s.GetShipCosts(out emptyCost, out fuel);
            TotalMass = s.GetShipMass(true, out emptyMass, out fuel);

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

            numStageParts = 0;
            stagePartCost = 0d;
            //for (int i = s.Parts.Count - 1; i >= 0; i--)
            //{
            //    Part p = s.Parts[i];

            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;
            }
            else if (s.shipFacility == EditorFacility.SPH)
            {
                type = ListType.SPH;
            }
            else
            {
                type = ListType.None;
            }
            id = Guid.NewGuid();
            cannotEarnScience = false;

            //get the crew from the editorlogic
            DesiredManifest = new List <string>();
            if (CrewAssignmentDialog.Instance?.GetManifest()?.CrewCount > 0)
            {
                //var pcm = CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List<ProtoCrewMember>();
                //for (int i = pcm.Count - 1; i >= 0; i--)
                //{
                //    ProtoCrewMember crew = pcm[i];
                foreach (ProtoCrewMember crew in CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List <ProtoCrewMember>())
                {
                    DesiredManifest.Add(crew?.name ?? string.Empty);
                }
            }

            if (effectiveCost == default(double))
            {
                // 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 = KCT_Utilities.GetEffectiveCost(shipNode.GetNodes("PART").ToList());
            }

            integrationPoints = KCT_MathParsing.ParseIntegrationTimeFormula(this);
            integrationCost   = (float)KCT_MathParsing.ParseIntegrationCostFormula(this);
        }
        protected ProtoVessel CreateProtoVessel()
        {
            ProtoVessel   protoVessel = null;
            ShipConstruct construct   = null;
            Vessel        vessel      = null;

            try
            {
                // Backup the ship config from the VAB/SPH, load the selected .craft file
                //   and restore the cached config from the VAB/SPH
                var constructBak = ShipConstruction.ShipConfig;
                construct = ShipConstruction.LoadShip(_selectedCraftFilePath);
                ShipConstruction.ShipConfig = constructBak;

                // Calculate vessel cost and mass and generate a thumbnail
                construct.GetShipCosts(out _cachedFundsCost, out _);
                construct.GetShipMass(out _cachedDryMass, out _);
                _cachedThumbnail = _thumbnailService.GetThumbnail(construct);

                // Create an emtpy Vessel and copy the parts from the loaded .craft file
                vessel       = new GameObject().AddComponent <Vessel>();
                vessel.parts = construct.parts;

                // Create an empty ProtoVessel that we'll ultimately use to create the template
                //   for the vessel to be spawned in-game later
                protoVessel = new ProtoVessel(new ConfigNode(), null)
                {
                    vesselName = construct.shipName,
                    vesselRef  = vessel
                };

                // Setup necessary Vessel and Part parameters for the template (also check for launch clamps)
                var launchId  = HighLogic.CurrentGame.launchID++;
                var missionId = (uint)Guid.NewGuid().GetHashCode();
                var rootPart  = construct.parts.First();
                _hasLaunchClamp = false;
                foreach (var part in construct.parts)
                {
                    _hasLaunchClamp |= part.HasModuleImplementing <LaunchClamp>();

                    part.flagURL     = construct.missionFlag ?? HighLogic.CurrentGame.flagURL;
                    part.flightID    = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
                    part.launchID    = launchId;
                    part.missionID   = missionId;
                    part.temperature = Math.Abs(part.temperature);
                    part.UpdateOrgPosAndRot(rootPart);

                    part.vessel = vessel;
                    var partSnapshot = new ProtoPartSnapshot(part, protoVessel);
                    foreach (var resource in partSnapshot.resources)
                    {
                        if (resource.resourceName != "ElectricCharge")
                        {
                            resource.amount = 0d;
                        }
                    }
                    protoVessel.protoPartSnapshots.Add(partSnapshot);
                }
                foreach (var snapshot in protoVessel.protoPartSnapshots)
                {
                    snapshot.storePartRefs();
                }

                // Cache the ProtoVessel to use as the template for spawning the vessel later
                _cachedProtoVessel = protoVessel;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                // ShipConstruction.LoadShip seems to load in all the part meshes for the vessel
                //   (presumably for use in the VAB/SPH), so we need to destroy them
                if (construct != null && construct.parts != null && construct.parts.Count > 0)
                {
                    foreach (var part in construct.parts)
                    {
                        Destroy(part.gameObject);
                    }
                }
                // Destroy the temporary Vessel we created as well
                if (vessel != null)
                {
                    Destroy(vessel.gameObject);
                }
            }

            return(protoVessel);
        }
Пример #8
0
        public BuildListVessel(ShipConstruct s, string ls, double effCost, double bP, string flagURL)
        {
            _ship     = s;
            ShipNode  = s.SaveShip();
            ShipName  = s.shipName;
            Cost      = s.GetShipCosts(out EmptyCost, out _);
            TotalMass = s.GetShipMass(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;
            }
            else if (s.shipFacility == EditorFacility.SPH)
            {
                Type = ListType.SPH;
            }
            else
            {
                Type = ListType.None;
            }
            Id = Guid.NewGuid();
            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);
        }