public static double GetStorageSpace(string resName)
        {
            double foundStorage = 0;
            var    whpList      = LogisticsTools.GetRegionalWarehouses(FlightGlobals.ActiveVessel, "USI_ModuleResourceWarehouse");
            var    count        = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                var whp = whpList[i];
                if (whp.Modules.Contains("USI_ModuleResourceWarehouse"))
                {
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (!wh.localTransferEnabled)
                    {
                        continue;
                    }
                }
                if (whp.Resources.Contains(resName))
                {
                    var res = whp.Resources[resName];
                    foundStorage += res.maxAmount - res.amount;
                }
            }
            return(foundStorage);
        }
Ejemplo n.º 2
0
        public static string GetDataByKuaidi100(LogisticsTools logisticsTools, string computer, string expressNo)
        {
            string  key  = "29833628d495d7a5";
            string  str2 = "";
            XmlNode node = GetXmlNode().SelectSingleNode("companys");
            string  str3 = "{\"message\": \"ok\",\"content\": ";

            if (node != null)
            {
                str2 = node.Attributes["Kuaidi100NewKey"].Value;
            }
            if (!string.IsNullOrEmpty(str2))
            {
                string expressDataList = new ExpressDataDao().GetExpressDataList(computer, expressNo);
                if (!string.IsNullOrEmpty(expressDataList))
                {
                    str3 = str3 + expressDataList + ",\"type\":\"1\"";
                }
                else
                {
                    str3 = str3 + GetContentByAPI(logisticsTools, str2, computer, expressNo) + ",\"type\":\"2\"";
                }
            }
            else
            {
                str3 = str3 + GetContentByAPI(logisticsTools, key, computer, expressNo) + ",\"type\":\"2\"";
            }
            return(str3 + "}");
        }
Ejemplo n.º 3
0
        public static string GetDataByKuaidi100(LogisticsTools logisticsTools, string computer, string expressNo)
        {
            string      key      = "29833628d495d7a5";
            string      text     = "";
            XmlDocument xmlNode  = ExpressHelper.GetXmlNode();
            XmlNode     xmlNode2 = xmlNode.SelectSingleNode("companys");
            string      str      = "{\"message\": \"ok\",\"content\": ";

            if (xmlNode2 != null)
            {
                text = xmlNode2.Attributes["Kuaidi100NewKey"].Value;
            }
            if (!string.IsNullOrEmpty(text))
            {
                string expressDataList = new ExpressDataDao().GetExpressDataList(computer, expressNo);
                if (!string.IsNullOrEmpty(expressDataList))
                {
                    str += expressDataList;
                    str += ",\"type\":\"1\"";
                }
                else
                {
                    str += ExpressHelper.GetContentByAPI(logisticsTools, text, computer, expressNo);
                    str += ",\"type\":\"2\"";
                }
            }
            else
            {
                str += ExpressHelper.GetContentByAPI(logisticsTools, key, computer, expressNo);
                str += ",\"type\":\"2\"";
            }
            return(str + "}");
        }
        public static void ConsumeResource(PartResourceDefinition resource, double amtToTake)
        {
            double needed  = amtToTake;
            var    resName = resource.name;
            var    whpList = LogisticsTools.GetRegionalWarehouses(FlightGlobals.ActiveVessel, "USI_ModuleResourceWarehouse");
            var    count   = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                var whp = whpList[i];
                if (whp.Modules.Contains("USI_ModuleResourceWarehouse"))
                {
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (!wh.localTransferEnabled)
                    {
                        continue;
                    }
                }
                if (whp.Resources.Contains(resName))
                {
                    var res = whp.Resources[resName];
                    if (res.amount >= needed)
                    {
                        res.amount -= needed;
                        needed      = 0;
                        break;
                    }
                    else
                    {
                        needed    -= res.amount;
                        res.amount = 0;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel)
        {
            var    vsl         = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == sourceVessel.VesselId);
            double totHabSpace = (LifeSupportSetup.Instance.LSConfig.BaseHabTime * sourceVessel.CrewCap) + sourceVessel.ExtraHabSpace;
            double totHabMult  = sourceVessel.VesselHabMultiplier;
            double totCurCrew  = sourceVessel.NumCrew;
            double totMaxCrew  = sourceVessel.CrewCap;

            var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vsl, false);

            foreach (var v in vList)
            {
                var curVsl = LifeSupportManager.Instance.FetchVessel(v.id.ToString());
                //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.
                totHabSpace += (LifeSupportSetup.Instance.LSConfig.BaseHabTime * curVsl.CrewCap) + curVsl.ExtraHabSpace;
                totCurCrew  += curVsl.NumCrew;
                totMaxCrew  += curVsl.CrewCap;
                totHabMult  += curVsl.VesselHabMultiplier;
            }
            totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex);
            double habTotal = totHabSpace / totCurCrew * (totHabMult + 1) * LifeSupportSetup.Instance.LSConfig.HabMultiplier;

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

            return(habTotal * (60d * 60d * 6d * 30d));
        }
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (Math.Abs(Planetarium.GetUniversalTime() - lastCheck) < RepairFrequency)
            {
                return;
            }

            if (part.protoModuleCrew.All(c => c.experienceTrait.TypeName != "Engineer"))
            {
                return;
            }

            lastCheck = Planetarium.GetUniversalTime();

            var nearbyVesselList = LogisticsTools.GetNearbyVessels(RepairRange, true, vessel, false);

            foreach (var v in nearbyVesselList)
            {
                var modList = v.FindPartModulesImplementing <USI_ModuleFieldRepair>();
                foreach (var m in modList)
                {
                    m.FinalizeMaintenance("Automated Maintenance performed on " + m.part.partInfo.title);
                }
            }
        }
Ejemplo n.º 7
0
        private static string GetContentByAPI(LogisticsTools logisticsTools, string key, string computer, string expressNo)
        {
            HttpWebResponse response;

            if (logisticsTools == LogisticsTools.Kuaidiniao)
            {
                return(ExpressTrackingSetService.GetHiShopExpTrackInfo(FormatCompanyCodeByKuaidi100Code(computer), expressNo));
            }
            string         str     = "";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.kuaidi100.com/api?id=" + key + "&com=" + computer + "&nu=" + expressNo);

            request.Timeout = 0x1f40;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch
            {
                return(str);
            }
            if (response.StatusCode == HttpStatusCode.OK)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
                str = reader.ReadToEnd().Replace("&amp;", "").Replace("&nbsp;", "").Replace("&", "");
            }
            return(str);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        internal static double GetRecyclerMultiplier(Vessel vessel)
        {
            if (!LifeSupportSetup.Instance.LSConfig.EnableRecyclers)
            {
                return(1d);
            }

            var recyclerCap = 0f;
            var recyclerTot = 0f;
            var crewCount   = GetColonyCrewCount(vessel);

            foreach (var r in vessel.FindPartModulesImplementing <ModuleLifeSupportRecycler>())
            {
                if (r.RecyclerIsActive && r.IsActivated)
                {
                    if (r.RecyclePercent > recyclerCap)
                    {
                        recyclerCap = r.RecyclePercent;
                    }
                    var recPercent = r.RecyclePercent;
                    if (r.CrewCapacity < crewCount)
                    {
                        recPercent *= r.CrewCapacity / (float)crewCount;
                    }

                    recyclerTot += recPercent;
                }
            }

            var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vessel, false);

            foreach (var v in vList)
            {
                foreach (var r in v.FindPartModulesImplementing <ModuleLifeSupportRecycler>())
                {
                    if (r.IsActivated && r.RecyclerIsActive)
                    {
                        if (r.RecyclePercent > recyclerCap)
                        {
                            recyclerCap = r.RecyclePercent;
                        }
                        var recPercent = r.RecyclePercent;
                        if (r.CrewCapacity < crewCount)
                        {
                            recPercent *= r.CrewCapacity / (float)crewCount;
                        }

                        recyclerTot += recPercent;
                    }
                }
            }
            //Inverse because this is a multiplier - low is good!
            double retVal = 1d - (Math.Min(recyclerTot, recyclerCap));

            return(retVal);
        }
Ejemplo n.º 10
0
        protected bool IsNearTerminal()
        {
            var partModules = LogisticsTools.GetNearbyPartModules <WOLF_TerminalModule>(
                TERMINAL_RANGE,
                vessel,
                false,
                false);

            return(partModules != null && partModules.Any(m => m.IsConnectedToDepot));
        }
Ejemplo n.º 11
0
        public void FixedUpdate()
        {
            try
            {
                if (!HighLogic.LoadedSceneIsFlight)
                {
                    return;
                }

                if (!vessel.LandedOrSplashed)
                {
                    return;
                }

                bool hasSkill = LogisticsTools.NearbyCrew(vessel, 500, "LogisticsSkill");

                //Periodic refresh of the warehouses due to vessel change, etc.
                if (Planetarium.GetUniversalTime() > lastWHCheck + CheckFrequency)
                {
                    _warehouseList = null;
                }

                //PlanLog grabs all things attached to this vessel.
                if (_warehouseList == null)
                {
                    _warehouseList = vessel.FindPartModulesImplementing <USI_ModuleResourceWarehouse>();
                }

                if (_warehouseList != null)
                {
                    foreach (var mod in _warehouseList)
                    {
                        if (!mod.soiTransferEnabled)
                        {
                            continue;
                        }

                        var rCount = mod.part.Resources.Count;
                        for (int i = 0; i < rCount; ++i)
                        {
                            var res = mod.part.Resources[i];
                            if (_blackList.Contains(res.resourceName))
                            {
                                continue;
                            }
                            LevelResources(mod.part, res.resourceName, hasSkill);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                print("ERROR IN ModulePlanetaryLogistics -> FixedUpdate: " + ex.StackTrace);
            }
        }
Ejemplo n.º 12
0
        private static int GetColonyCrewCount(Vessel vsl)
        {
            var crewCount = vsl.GetCrewCount();
            var vList     = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vsl, false);

            foreach (var v in vList)
            {
                crewCount += v.GetCrewCount();
            }
            return(crewCount);
        }
Ejemplo n.º 13
0
        private static int GetColonyCrewCount(Vessel vsl)
        {
            var crewCount = vsl.GetCrewCount();
            var vList     = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false);
            var count     = vList.Count;

            for (int i = 0; i < count; ++i)
            {
                var v = vList[i];
                crewCount += v.GetCrewCount();
            }
            return(crewCount);
        }
Ejemplo n.º 14
0
        private List <ProtoCrewMember> GetNearbyKerbals()
        {
            var activeVessel = FlightGlobals.ActiveVessel;

            if (activeVessel == null)
            {
                return(null);
            }
            // Make sure we have an eligible terminal nearby
            var landedSituations = Vessel.Situations.LANDED |
                                   Vessel.Situations.PRELAUNCH |
                                   Vessel.Situations.SPLASHED;
            var landedOnly = (activeVessel.situation & landedSituations) == landedSituations;
            var terminals  = LogisticsTools.GetNearbyPartModules <WOLF_TerminalModule>(
                TERMINAL_RANGE,
                activeVessel,
                true,
                landedOnly);

            if (terminals == null || terminals.Count < 1)
            {
                return(null);
            }
            var terminalIds = terminals
                              .Where(t => !string.IsNullOrEmpty(t.TerminalId))
                              .Select(t => t.TerminalId);
            var wolfTerminals = _wolf.GetTerminals()
                                .Where(t => terminalIds.Contains(t.Id) &&
                                       t.Body == _selectedFlight.OriginBody &&
                                       t.Biome == _selectedFlight.OriginBiome);

            if (wolfTerminals == null || wolfTerminals.Count() < 1)
            {
                return(null);
            }
            // Get all nearby vessels
            var vessels = LogisticsTools
                          .GetNearbyVessels(TERMINAL_RANGE, true, activeVessel, landedOnly);
            var kerbals = new List <ProtoCrewMember>();

            foreach (var vessel in vessels)
            {
                var crew = vessel
                           .GetVesselCrew()
                           .Where(c => c.type == ProtoCrewMember.KerbalType.Crew ||
                                  c.type == ProtoCrewMember.KerbalType.Tourist);
                kerbals.AddRange(crew);
            }
            return(kerbals);
        }
        public void FixedUpdate()
        {
            try
            {
                if (!HighLogic.LoadedSceneIsFlight)
                {
                    return;
                }

                if (!vessel.LandedOrSplashed)
                {
                    return;
                }

                //PlanLog grabs all things attached to this vessel.
                if (_warehouseList == null)
                {
                    _warehouseList = vessel.FindPartModulesImplementing <USI_ModuleResourceWarehouse>();
                }

                if (_warehouseList != null)
                {
                    foreach (var mod in _warehouseList)
                    {
                        bool hasSkill = LogisticsTools.NearbyCrew(vessel, 500, "LogisticsSkill");

                        if (!mod.soiTransferEnabled)
                        {
                            continue;
                        }

                        var rCount = mod.part.Resources.Count;
                        for (int i = 0; i < rCount; ++i)
                        {
                            var res = mod.part.Resources[i];
                            if (_blackList.Contains(res.resourceName))
                            {
                                continue;
                            }
                            LevelResources(mod.part, res.resourceName, hasSkill);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                print("ERROR IN ModulePlanetaryLogistics -> FixedUpdate");
            }
        }
Ejemplo n.º 16
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (Math.Abs(Planetarium.GetUniversalTime() - lastCheck) < RepairFrequency)
            {
                return;
            }

            var engineerCount = 0;
            var cCount        = part.protoModuleCrew.Count;

            for (int i = 0; i < cCount; ++i)
            {
                if (part.protoModuleCrew[i].experienceTrait.TypeName == "Engineer")
                {
                    engineerCount++;
                }
            }

            if (engineerCount == 0)
            {
                return;
            }

            lastCheck = Planetarium.GetUniversalTime();

            var nearbyVesselList = LogisticsTools.GetNearbyVessels(RepairRange, true, vessel, false);
            var vCount           = nearbyVesselList.Count;

            for (int i = 0; i < vCount; ++i)
            {
                var v       = nearbyVesselList[i];
                var modList = v.FindPartModulesImplementing <USI_ModuleFieldRepair>();
                var mCount  = modList.Count;
                for (int x = 0; x < mCount; ++x)
                {
                    var m = modList[x];
                    m.FinalizeMaintenance("Automated Maintenance performed on " + m.part.partInfo.title);
                }
            }
        }
Ejemplo n.º 17
0
        private static string GetContentByAPI(LogisticsTools logisticsTools, string key, string computer, string expressNo)
        {
            string result;

            if (logisticsTools == LogisticsTools.Kuaidiniao)
            {
                result = ExpressTrackingSetService.GetHiShopExpTrackInfo(ExpressHelper.FormatCompanyCodeByKuaidi100Code(computer), expressNo);
            }
            else
            {
                string         text           = "";
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Concat(new string[]
                {
                    "http://api.kuaidi100.com/api?id=",
                    key,
                    "&com=",
                    computer,
                    "&nu=",
                    expressNo
                }));
                httpWebRequest.Timeout = 8000;
                HttpWebResponse httpWebResponse;
                try
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                }
                catch
                {
                    result = text;
                    return(result);
                }
                if (httpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    Stream       responseStream = httpWebResponse.GetResponseStream();
                    StreamReader streamReader   = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
                    text = streamReader.ReadToEnd();
                    text = text.Replace("&amp;", "");
                    text = text.Replace("&nbsp;", "");
                    text = text.Replace("&", "");
                }
                result = text;
            }
            return(result);
        }
Ejemplo n.º 18
0
        internal static double GetHabChecksum(VesselSupplyStatus sourceVessel, Vessel vsl)
        {
            //This routine just returns the total amount of hab factored by the multiplier.
            //It is used to determine if there was a situation change and thus reset the vessel time.
            //The main use case would be undocking/docking, or flying into range of a base.

            //In the event that a vessel is not loaded, return zero.
            if (!vsl.loaded)
            {
                return(0d);
            }

            int totMaxCrew = sourceVessel.CrewCap;
            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];
                int crewCap = v.GetCrewCapacity();
                totMaxCrew += crewCap;
                if (crewCap > 0)
                {
                    hList.Add(v);
                }
            }

            double totHabSpace = sourceVessel.ExtraHabSpace;
            double totHabMult  = CalculateVesselHabMultiplier(vsl, 1);

            totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew);

            var hCount = hList.Count;

            for (int i = 0; i < hCount; ++i)
            {
                var v = hList[i];
                totHabSpace += CalculateVesselHabExtraTime(v);
                totHabMult  += CalculateVesselHabMultiplier(v, 1);
            }

            return(totHabSpace * (totHabMult + 1));
        }
Ejemplo n.º 19
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()));
        }
        public int GetConstructionPoints()
        {
            var points = 0;

            //Adust parms for our EVA Kerbals
            var vessels = LogisticsTools.GetNearbyVessels(2000, true, vessel, false);
            var count   = vessels.Count;

            for (int i = 0; i < count; ++i)
            {
                var v        = vessels[i];
                var kModules = v.FindPartModulesImplementing <ModuleKonstructionHelper>();
                foreach (var m in kModules)
                {
                    points += m.KonstructionPoints;
                }
            }
            return(points);
        }
        public int GetKerbalQuantity()
        {
            var kerbCount = 0;
            var vessels   = LogisticsTools.GetNearbyVessels(2000, true, vessel, false);
            var count     = vessels.Count;

            for (int i = 0; i < count; ++i)
            {
                var v = vessels[i];
                if (v.isEVA)
                {
                    kerbCount++;
                }
                else
                {
                    kerbCount += v.GetCrewCount();
                }
            }
            return(kerbCount);
        }
        public static void AddResource(PartResourceDefinition resource, double amtToGive)
        {
            double remaining = amtToGive;
            var    resName   = resource.name;
            var    whpList   = LogisticsTools.GetRegionalWarehouses(FlightGlobals.ActiveVessel, "USI_ModuleResourceWarehouse");
            var    count     = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                if (remaining <= ResourceUtilities.FLOAT_TOLERANCE)
                {
                    break;
                }

                var whp = whpList[i];
                if (whp.Modules.Contains("USI_ModuleResourceWarehouse"))
                {
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (!wh.localTransferEnabled)
                    {
                        continue;
                    }
                }
                if (whp.Resources.Contains(resName))
                {
                    var res   = whp.Resources[resName];
                    var space = res.maxAmount - res.amount;
                    if (space >= remaining)
                    {
                        res.amount += remaining;
                        remaining   = 0;
                        break;
                    }
                    else
                    {
                        remaining -= res.amount;
                        res.amount = res.maxAmount;
                    }
                }
            }
        }
        public List <ResourceTransferTargetMetadata> GetResourceTransferTargets()
        {
            var nearbyVessels = LogisticsTools.GetNearbyVessels(
                LOCAL_LOGISTICS_RANGE,
                true,
                FlightGlobals.ActiveVessel,
                false);

            return(nearbyVessels
                   .Where(v => v.Parts.Any(p => p.Resources.Any(r =>
                                                                !BLACKLIST.Contains(r.resourceName) &&
                                                                ResourceTransferTarget.IsTransferable(r))))
                   .Select(v => new ResourceTransferTargetMetadata
            {
                DisplayName = GetVesselDisplayName(v),
                Id = v.id.ToString("N"),
                IsCurrentVessel = v == FlightGlobals.ActiveVessel,
                Resources = ResourceTransferTarget.GetResourceMetadata(v.Parts),
            })
                   .ToList());
        }
Ejemplo n.º 24
0
        protected static List <KolonyVessel> GetKolonyVessels(Vessel thisVessel, float range, bool includeThis = true, bool landedOnly = true)
        {
            List <KolonyVessel> res = new List <KolonyVessel>();

            foreach (var v in LogisticsTools.GetNearbyVessels(range, includeThis, thisVessel, landedOnly))
            {
                KolonyVessel item = new KolonyVessel();
                item.name   = Misc.Name(v);
                item.vessel = v;
                if (v == thisVessel)
                {
                    item.thisVessel = true;
                }
                else
                {
                    item.thisVessel = false;
                    item.distance   = LogisticsTools.GetRange(v, thisVessel);
                }

                res.Add(item);
            }
            return(res);
        }
Ejemplo n.º 25
0
        private List <ArrivalMetadata> GetNearbyTerminals()
        {
            var activeVessel = FlightGlobals.ActiveVessel;

            if (activeVessel == null)
            {
                return(null);
            }
            // Make sure we have an eligible terminal nearby
            var landedSituations = Vessel.Situations.LANDED |
                                   Vessel.Situations.PRELAUNCH |
                                   Vessel.Situations.SPLASHED;
            var landedOnly      = (activeVessel.situation & landedSituations) == landedSituations;
            var terminalModules = LogisticsTools.GetNearbyPartModules <WOLF_TerminalModule>(
                TERMINAL_RANGE,
                activeVessel,
                true,
                landedOnly);

            if (terminalModules == null || terminalModules.Count < 1)
            {
                return(null);
            }
            var terminalIds = terminalModules
                              .Where(t => !string.IsNullOrEmpty(t.TerminalId))
                              .Select(t => t.TerminalId);
            var wolfTerminals = _wolf.GetTerminals()
                                .Where(t => terminalIds.Contains(t.Id) &&
                                       t.Body == _selectedFlight.DestinationBody &&
                                       t.Biome == _selectedFlight.DestinationBiome)
                                .ToList();
            var terminals = new List <ArrivalMetadata>();

            foreach (var wolfTerminal in wolfTerminals)
            {
                var terminalModule = terminalModules
                                     .FirstOrDefault(t => t.TerminalId == wolfTerminal.Id);
                var terminal = new ArrivalMetadata
                {
                    OccupiedSeats = terminalModule.part.protoModuleCrew.Count,
                    TotalSeats    = terminalModule.part.CrewCapacity,
                    TerminalId    = terminalModule.TerminalId,
                    VesselName    = terminalModule.vessel.GetDisplayName(),
                    VesselId      = terminalModule.vessel.id,
                };
                terminals.Add(terminal);
            }
            if (_passengers != null && _passengers.Count > 0 && _selectedTerminal != null)
            {
                foreach (var terminal in terminals)
                {
                    if (terminal.TerminalId == _selectedTerminal.TerminalId)
                    {
                        terminal.OccupiedSeats += _passengers.Count;
                    }
                }
            }
            return(terminals
                   .OrderBy(t => t.VesselName)
                   .ThenBy(t => t.TerminalId)
                   .ToList());
        }
Ejemplo n.º 26
0
        internal static double GetRecyclerMultiplier(Vessel vessel)
        {
            if (!LifeSupportScenario.Instance.settings.GetSettings().EnableRecyclers)
            {
                return(1d);
            }

            var recyclerCap = 0f;
            var recyclerTot = 0f;
            var crewCount   = GetColonyCrewCount(vessel);

            var recList = vessel.FindPartModulesImplementing <ModuleLifeSupportRecycler>();
            var rmCount = recList.Count;

            for (int i = 0; i < rmCount; ++i)
            {
                var r = recList[i];
                if (r.RecyclerIsActive && r.IsActivated)
                {
                    if (r.AdjustedRecyclePercent > recyclerCap)
                    {
                        recyclerCap = r.AdjustedRecyclePercent;
                    }
                    var recPercent = r.AdjustedRecyclePercent;
                    if (r.CrewCapacity < crewCount)
                    {
                        recPercent *= r.CrewCapacity / (float)crewCount;
                    }

                    recyclerTot += recPercent;
                }
            }

            var vList  = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vessel, false);
            var vCount = vList.Count;

            for (int i = 0; i < vCount; ++i)
            {
                var v          = vList[i];
                var subRecList = v.FindPartModulesImplementing <ModuleLifeSupportRecycler>();
                var subRmCount = subRecList.Count;

                for (int x = 0; x < subRmCount; ++x)
                {
                    var r = subRecList[x];
                    if (r.IsActivated && r.RecyclerIsActive)
                    {
                        if (r.AdjustedRecyclePercent > recyclerCap)
                        {
                            recyclerCap = r.AdjustedRecyclePercent;
                        }
                        var recPercent = r.AdjustedRecyclePercent;
                        if (r.CrewCapacity < crewCount)
                        {
                            recPercent *= r.CrewCapacity / (float)crewCount;
                        }

                        recyclerTot += recPercent;
                    }
                }
            }
            //Inverse because this is a multiplier - low is good!
            double retVal = 1d - (Math.Min(recyclerTot, recyclerCap));

            return(retVal);
        }
        public override void LaunchVessel()
        {
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.ORBITING)
            {
                throw new Exception(_notInOrbitErrorText);
            }

            if (string.IsNullOrEmpty(_selectedCraftFilePath))
            {
                throw new Exception(_noVesselSelectedErrorText);
            }

            if (LogisticsTools.AnyNearbyVessels(100d, FlightGlobals.ActiveVessel))
            {
                throw new Exception(_nearbyVesselsErrorText);
            }

            PartUtilities.ConsumeResources(_cachedCostData);

            var vesselOrbit = FlightGlobals.ActiveVessel.orbit;
            var now         = Planetarium.GetUniversalTime();

            vesselOrbit.GetOrbitalStateVectorsAtUT(
                now,
                out Vector3d position,
                out Vector3d velocity);
            position.x += 50d;
            var orbit = new Orbit(vesselOrbit);

            orbit.UpdateFromStateVectors(
                position,
                velocity,
                vesselOrbit.referenceBody,
                now);

            var partNodes = _cachedProtoVessel.protoPartSnapshots
                            .Select(s =>
            {
                var node = new ConfigNode("PART");
                s.Save(node);
                return(node);
            })
                            .ToArray();
            var type = VesselType.Ship;

            _craftConfigNode.TryGetEnum("type", ref type, VesselType.Ship);

            var vesselConfigNode = ProtoVessel.CreateVesselNode(
                _cachedProtoVessel.GetDisplayName(),
                type,
                orbit,
                0,
                partNodes);

            var spawnedProtoVessel = new ProtoVessel(vesselConfigNode, HighLogic.CurrentGame);

            spawnedProtoVessel.Load(HighLogic.CurrentGame.flightState);

            _window.CloseWindow();

            var spawnedVessel = FlightGlobals.Vessels.Last();

            spawnedVessel.protoVessel.stage = int.MaxValue;
            FlightGlobals.SetActiveVessel(spawnedVessel);
        }
Ejemplo n.º 28
0
        internal static double GetRecyclerMultiplier(Vessel vessel)
        {
            if (!LifeSupportScenario.Instance.settings.GetSettings().EnableRecyclers)
            {
                return(1d);
            }

            var recyclerCap = 0f;
            var recyclerTot = 0f;
            var crewCount   = GetColonyCrewCount(vessel);

            var recyclers = vessel.FindConverterAddonsImplementing <USILS_LifeSupportRecyclerConverterAddon>();

            for (int i = 0; i < recyclers.Count; ++i)
            {
                var recycler = recyclers[i];
                if (recycler.IsActive && recycler.IsOperational)
                {
                    if (recycler.RecyclePercent > recyclerCap)
                    {
                        recyclerCap = recycler.RecyclePercent;
                    }
                    var recPercent = recycler.RecyclePercent;
                    if (recycler.CrewCapacity < crewCount)
                    {
                        recPercent *= recycler.CrewCapacity / (float)crewCount;
                    }

                    recyclerTot += recPercent;
                }
            }

            var vessels = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vessel, false);

            for (int i = 0; i < vessels.Count; ++i)
            {
                var v = vessels[i];
                var nearbyRecyclers = v.FindConverterAddonsImplementing <USILS_LifeSupportRecyclerConverterAddon>();
                for (int x = 0; x < nearbyRecyclers.Count; ++x)
                {
                    var recycler = nearbyRecyclers[x];
                    if (recycler.IsActive && recycler.IsOperational)
                    {
                        if (recycler.RecyclePercent > recyclerCap)
                        {
                            recyclerCap = recycler.RecyclePercent;
                        }
                        var recPercent = recycler.RecyclePercent;
                        if (recycler.CrewCapacity < crewCount)
                        {
                            recPercent *= recycler.CrewCapacity / (float)crewCount;
                        }

                        recyclerTot += recPercent;
                    }
                }
            }

            //Inverse because this is a multiplier - low is good!
            double multiplier = 1d - (Math.Min(recyclerTot, recyclerCap));

            return(multiplier);
        }
Ejemplo n.º 29
0
 public static string GetExpressData(LogisticsTools logisticsTools, string computer, string expressNo)
 {
     return(ExpressHelper.GetDataByKuaidi100(logisticsTools, computer, expressNo));
 }
Ejemplo n.º 30
0
 public void Launch()
 {
     if (!_activeWarnings.Any(w => w.Value.PreventsAction))
     {
         var activeVessel     = FlightGlobals.ActiveVessel;
         var landedSituations = Vessel.Situations.LANDED |
                                Vessel.Situations.PRELAUNCH |
                                Vessel.Situations.SPLASHED;
         var landedOnly = (activeVessel.situation & landedSituations) == landedSituations;
         var vessels    = LogisticsTools
                          .GetNearbyVessels(TERMINAL_RANGE, true, activeVessel, landedOnly);
         var passengers = _passengers.Values.Select(p => p.Name);
         foreach (var vessel in vessels)
         {
             var crew = vessel.GetVesselCrew().ToArray();
             foreach (var kerbal in crew)
             {
                 if (passengers.Contains(kerbal.name))
                 {
                     if (_selectedFlight.Embark(new Passenger(kerbal)))
                     {
                         vessel.CrewListSetDirty();
                         var parts = vessel.parts;
                         foreach (var part in parts)
                         {
                             if (part.protoModuleCrew.Contains(kerbal))
                             {
                                 part.RemoveCrewmember(kerbal);
                                 break;
                             }
                         }
                         kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Missing;
                         kerbal.SetTimeForRespawn(double.MaxValue);
                     }
                     else
                     {
                         ShowWarning("Could not launch.", false);
                         return;
                     }
                 }
             }
         }
         _selectedFlight.Launch(Planetarium.GetUniversalTime());
         _passengers.Clear();
         _activeWarnings.Clear();
         var metadata = new FlightMetadata()
         {
             ArrivalBiome   = _selectedFlight.DestinationBiome,
             ArrivalBody    = _selectedFlight.DestinationBody,
             DepartureBiome = _selectedFlight.OriginBiome,
             DepartureBody  = _selectedFlight.OriginBody,
             Duration       = GetDuration(_selectedFlight),
             EconomySeats   = GetEconomySeats(_selectedFlight),
             FlightNumber   = _selectedFlight.FlightNumber,
             LuxurySeats    = GetLuxurySeats(_selectedFlight),
             Status         = _selectedFlight.FlightStatus,
             UniqueId       = _selectedFlight.UniqueId,
         };
         _window.Launched(metadata);
     }
 }