示例#1
0
        internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, Vessel vsl, out int numSharedVessels)
        {
            //In the event that a vessel is not loaded, we just return the cached value.
            if (!vsl.loaded)
            {
                numSharedVessels = 0;
                return(sourceVessel.CachedHabTime);
            }

            double totHabSpace = sourceVessel.ExtraHabSpace;
            double totHabMult  = sourceVessel.VesselHabMultiplier;

            int totCurCrew = sourceVessel.NumCrew;
            int totMaxCrew = sourceVessel.CrewCap;

            numSharedVessels = 0;

            var vList  = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false);
            var hList  = new List <Vessel>();
            var vCount = vList.Count;

            for (int i = 0; i < vCount; ++i)
            {
                var v = vList[i];
                //Hab time starts with our baseline of the crew hab plus extra hab.
                //We then multiply it out based on the crew ratio, our global multiplier, and the vessel's multipler.
                //First - crew capacity.
                int crewCap = v.GetCrewCapacity();
                totMaxCrew += crewCap;
                totCurCrew += v.GetCrewCount();

                if (crewCap > 0)
                {
                    numSharedVessels++;
                    hList.Add(v);
                }
            }
            totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew);

            var hCount = hList.Count;

            for (int i = 0; i < hCount; ++i)
            {
                var v = hList[i];
                // Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew
                totHabSpace += CalculateVesselHabExtraTime(v);
                totHabMult  *= Math.Min(1, CalculateVesselHabMultiplier(v, totCurCrew));
            }

            totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex);
            double habTotal = totHabSpace / (double)totCurCrew * (totHabMult + 1) * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier;

            //print(String.Format("THS: {0} TC:{1} THM: {2} HM: {3}", totHabSpace, totCurCrew, totHabMult, LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier));
            sourceVessel.CachedHabTime = Math.Max(0, habTotal * LifeSupportUtilities.SecondsPerMonth());
            LifeSupportManager.Instance.TrackVessel(sourceVessel);
            return(sourceVessel.CachedHabTime);
        }
示例#2
0
        internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, out int numSharedVessels)
        {
            var    vsl         = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == sourceVessel.VesselId);
            double totHabSpace = (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *sourceVessel.CrewCap) + sourceVessel.ExtraHabSpace;
            double totHabMult  = sourceVessel.VesselHabMultiplier;

            int totCurCrew = sourceVessel.NumCrew;
            int totMaxCrew = sourceVessel.CrewCap;

            numSharedVessels = 0;

            var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false);
            var hList = new List <Vessel>();

            foreach (var v in vList)
            {
                //Hab time starts with our baseline of the crew hab plus extra hab.
                //We then multiply it out based on the crew ratio, our global multiplier, and the vessel's multipler.
                //First - crew capacity.
                int crewCap = v.GetCrewCapacity();
                totMaxCrew += crewCap;
                totCurCrew += v.GetCrewCount();

                if (crewCap > 0)
                {
                    numSharedVessels++;
                    hList.Add(v);
                }
            }

            foreach (var v in hList)
            {
                // Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew
                totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew) + CalculateVesselHabExtraTime(v);
                totHabMult  += CalculateVesselHabMultiplier(v, totCurCrew);
            }
            totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex);
            double habTotal = totHabSpace / (double)totCurCrew * (totHabMult + 1) * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier;

            //print(String.Format("THS: {0} TC:{1} THM: {2} HM: {3}", totHabSpace, totCurCrew, totHabMult, LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier));

            return(Math.Max(0, habTotal * LifeSupportUtilities.SecondsPerMonth()));
        }
示例#3
0
        private void UpdateGUIInfo(ShipConstruct ship)
        {
            ResetValues();
            if (EditorLogic.fetch != null)
            {
                var parts = EditorLogic.fetch.ship.parts;
                var count = parts.Count;
                for (int i = 0; i < count; ++i)
                {
                    var part = parts[i];
                    maxCrew += part.CrewCapacity;
                }

                var dialog = KSP.UI.CrewAssignmentDialog.Instance;

                if (dialog != null)
                {
                    VesselCrewManifest manifest = dialog.GetManifest();
                    if (manifest != null)
                    {
                        curCrew = manifest.CrewCount;
                    }
                }

                for (int i = 0; i < count; ++i)
                {
                    var part        = parts[i];
                    var swapOptions = part.FindModulesImplementing <AbstractSwapOption>();
                    var bays        = part.FindModulesImplementing <USI_SwappableBay>();
                    if (swapOptions != null && bays != null && swapOptions.Count > 0 && bays.Count > 0)
                    {
                        for (int x = 0; x < bays.Count; x++)
                        {
                            var bay     = bays[x];
                            var loadout = swapOptions[bay.currentLoadout] as USILS_HabitationSwapOption;
                            if (loadout != null)
                            {
                                habs.Add(loadout);
                                //Certain modules, in addition to crew capacity, have living space.
                                extraHabTime += loadout.BaseKerbalMonths;
                                //Some modules act more as 'multipliers', dramatically extending a hab's workable lifespan.
                                habMult += loadout.BaseHabMultiplier * Math.Min(1, loadout.CrewCapacity / Math.Max(curCrew, 1));
                            }
                        }
                    }
                    if (part.Resources.Contains("ColonySupplies"))
                    {
                        colonySupplies += part.Resources["ColonySupplies"].amount;
                    }
                    if (part.Resources.Contains("Fertilizer"))
                    {
                        fertilizer += part.Resources["Fertilizer"].amount;
                    }
                    if (part.Resources.Contains("Supplies"))
                    {
                        supplies += part.Resources["Supplies"].amount;
                    }
                    if (part.Resources.Contains("ElectricCharge"))
                    {
                        batteryAmount += part.Resources["ElectricCharge"].maxAmount;
                    }
                }

                totalHabSpace = (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *maxCrew) + extraHabTime;
                //A Kerbal month is 30 six-hour Kerbin days.
                totalHabMult        = habMult * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier *LifeSupportUtilities.SecondsPerMonth();
                totalBatteryTime    = batteryAmount / LifeSupportScenario.Instance.settings.GetSettings().ECAmount;
                totalSupplyTime     = supplies / LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount;
                totalFertilizerTime = fertilizer * 10 / LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount;

                if (EditorLogic.fetch.ship.parts.Count > 0)
                {
                    for (int i = 0; i < count; ++i)
                    {
                        var part        = parts[i];
                        var swapOptions = part.FindModulesImplementing <AbstractSwapOption>();
                        var bays        = part.FindModulesImplementing <USI_SwappableBay>();
                        if (swapOptions != null && bays != null && swapOptions.Count > 0 && bays.Count > 0)
                        {
                            for (int x = 0; x < bays.Count; x++)
                            {
                                var bay     = bays[x];
                                var loadout = swapOptions[bay.currentLoadout] as USILS_LifeSupportRecyclerSwapOption;
                                if (loadout != null)
                                {
                                    this.recyclers.Add(loadout);
                                }
                            }
                        }
                    }
                    var recyclerMultiplier_curCrew = LifeSupportManager.GetRecyclerMultiplierForParts(EditorLogic.fetch.ship.parts, curCrew);
                    var recyclerMultiplier_maxCrew = LifeSupportManager.GetRecyclerMultiplierForParts(EditorLogic.fetch.ship.parts, maxCrew);

                    supply_curCrew = LifeSupportUtilities.DurationDisplay(
                        totalSupplyTime /
                        Math.Max(1, curCrew) /
                        recyclerMultiplier_curCrew
                        );
                    supply_maxCrew = LifeSupportUtilities.DurationDisplay(
                        totalSupplyTime /
                        Math.Max(1, maxCrew) /
                        recyclerMultiplier_maxCrew
                        );

                    hab_curCrew = LifeSupportUtilities.DurationDisplay(totalHabSpace / Math.Max(1, curCrew) * totalHabMult);
                    hab_maxCrew = LifeSupportUtilities.DurationDisplay(totalHabSpace / Math.Max(1, maxCrew) * totalHabMult);

                    supplyExt_curCrew = LifeSupportUtilities.DurationDisplay(
                        (totalSupplyTime + totalFertilizerTime) /
                        Math.Max(1, curCrew) /
                        recyclerMultiplier_curCrew
                        );
                    supplyExt_maxCrew = LifeSupportUtilities.DurationDisplay(
                        (totalSupplyTime + totalFertilizerTime) /
                        Math.Max(1, maxCrew) /
                        recyclerMultiplier_maxCrew
                        );
                    //Standard is half a colony supply per hour, or 0.000139 per second.
                    var csupPerSecond = 0.000139d;
                    habExt_curCrew = LifeSupportUtilities.DurationDisplay((totalHabSpace / Math.Max(1, curCrew) * totalHabMult) + (colonySupplies / csupPerSecond / curCrew));
                    habExt_maxCrew = LifeSupportUtilities.DurationDisplay((totalHabSpace / Math.Max(1, maxCrew) * totalHabMult) + (colonySupplies / csupPerSecond / maxCrew));
                }
            }
        }
        private void UpdateGUIInfo(ShipConstruct ship)
        {
            ResetValues();
            if (EditorLogic.fetch != null)
            {
                foreach (var part in EditorLogic.fetch.ship.parts)
                {
                    maxCrew += part.CrewCapacity;
                }

                var dialog = KSP.UI.CrewAssignmentDialog.Instance;

                if (dialog != null)
                {
                    VesselCrewManifest manifest = dialog.GetManifest();
                    if (manifest != null)
                    {
                        curCrew = manifest.CrewCount;
                    }
                }


                foreach (var part in EditorLogic.fetch.ship.parts)
                {
                    var hab = part.Modules.GetModule <ModuleHabitation>();
                    if (hab != null)
                    {
                        var conList = part.Modules.GetModules <BaseConverter>();
                        var bayList = part.Modules.GetModules <ModuleSwappableConverter>();
                        if (bayList == null || bayList.Count == 0)
                        {
                            habs.Add(hab);
                            //Certain modules, in addition to crew capacity, have living space.
                            extraHabTime += hab.KerbalMonths;
                            //Some modules act more as 'multipliers', dramatically extending a hab's workable lifespan.
                            habMult += hab.HabMultiplier * Math.Min(1, hab.CrewCapacity / Math.Max(curCrew, 1));
                        }
                        else
                        {
                            foreach (var bay in bayList)
                            {
                                var con = conList[bay.currentLoadout] as ModuleHabitation;
                                if (con != null)
                                {
                                    habs.Add(con);
                                    extraHabTime += con.KerbalMonths;
                                    habMult      += con.HabMultiplier * Math.Min(1, con.CrewCapacity / Math.Max(curCrew, 1));
                                }
                            }
                        }
                    }
                    if (part.Resources.Contains("Supplies"))
                    {
                        supplies += part.Resources["Supplies"].amount;
                    }
                    if (part.Resources.Contains("ElectricCharge"))
                    {
                        batteryAmount += part.Resources["ElectricCharge"].maxAmount;
                    }
                }


                totalHabSpace = (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *maxCrew) + extraHabTime;
                //A Kerbal month is 30 six-hour Kerbin days.
                totalHabMult     = habMult * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier *LifeSupportUtilities.SecondsPerMonth();
                totalBatteryTime = batteryAmount / LifeSupportScenario.Instance.settings.GetSettings().ECAmount;
                totalSupplyTime  = supplies / LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount;

                if (EditorLogic.fetch.ship.parts.Count > 0)
                {
                    foreach (var p in EditorLogic.fetch.ship.parts)
                    {
                        var rec = p.Modules.GetModule <ModuleLifeSupportRecycler>();
                        if (rec != null)
                        {
                            var conList = p.Modules.GetModules <BaseConverter>();
                            var bayList = p.Modules.GetModules <ModuleSwappableConverter>();
                            if (bayList == null || bayList.Count == 0)
                            {
                                recyclers.Add(rec);
                            }
                            else
                            {
                                foreach (var bay in bayList)
                                {
                                    var con = conList[bay.currentLoadout] as ModuleLifeSupportRecycler;
                                    if (con != null)
                                    {
                                        recyclers.Add(con);
                                    }
                                }
                            }
                        }
                    }
                    var recyclerMultiplier_curCrew = LifeSupportManager.GetRecyclerMultiplierForParts(EditorLogic.fetch.ship.parts, curCrew);
                    var recyclerMultiplier_maxCrew = LifeSupportManager.GetRecyclerMultiplierForParts(EditorLogic.fetch.ship.parts, maxCrew);

                    supply_curCrew = LifeSupportUtilities.SecondsToKerbinTime(
                        totalSupplyTime /
                        Math.Max(1, curCrew) /
                        recyclerMultiplier_curCrew
                        );
                    supply_maxCrew = LifeSupportUtilities.SecondsToKerbinTime(
                        totalSupplyTime /
                        Math.Max(1, maxCrew) /
                        recyclerMultiplier_maxCrew
                        );

                    hab_curCrew = LifeSupportUtilities.SecondsToKerbinTime(totalHabSpace / Math.Max(1, curCrew) * totalHabMult);
                    hab_maxCrew = LifeSupportUtilities.SecondsToKerbinTime(totalHabSpace / Math.Max(1, maxCrew) * totalHabMult);
                }
            }
        }