Ejemplo n.º 1
0
        public List <Vessel> GetPowerDistributors()
        {
            var distributors  = new List <Vessel>();
            var nearbyVessels = LogisticsTools.GetNearbyVessels(LogisticsTools.PHYSICS_RANGE, false,
                                                                vessel, true);

            var count = nearbyVessels.Count;

            for (int i = 0; i < count; ++i)
            {
                var v     = nearbyVessels[i];
                var range = LogisticsTools.GetRange(vessel, v);

                var pCount = v.parts.Count;
                for (int x = 0; x < pCount; ++x)
                {
                    var p   = v.parts[x];
                    var mod = p.FindModuleImplementing <ModulePowerDistributor>();
                    if (mod == null)
                    {
                        continue;
                    }

                    if (mod.ActiveDistributionRange >= range)
                    {
                        distributors.Add(v);
                    }
                }
            }
            return(distributors);
        }
Ejemplo n.º 2
0
        public List <Vessel> GetResourceStockpiles()
        {
            var depots  = new List <Vessel>();
            var potDeps = LogisticsTools.GetNearbyVessels(LogisticsSetup.Instance.Config.ScavangeRange, false, vessel, true);
            var count   = potDeps.Count;

            for (int i = 0; i < count; ++i)
            {
                if (potDeps[i].FindPartModulesImplementing <USI_ModuleResourceWarehouse>().Count > 0)
                {
                    depots.Add(potDeps[i]);
                }
            }

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

            count = nearbyVesselList.Count;
            for (int i = 0; i < count; ++i)
            {
                var v      = nearbyVesselList[i];
                var range  = LogisticsTools.GetRange(vessel, v);
                var pCount = v.parts.Count;

                for (int q = 0; q < pCount; ++q)
                {
                    var p = v.parts[q];
                    if (p.FindModuleImplementing <ModuleResourceDistributor>() == null)
                    {
                        continue;
                    }
                    if (!LogisticsTools.HasCrew(p.vessel, "Pilot"))
                    {
                        continue;
                    }

                    var m = p.FindModuleImplementing <ModuleResourceDistributor>();
                    if (range <= m.ResourceDistributionRange)
                    {
                        //Now find ones adjacent to our depot.
                        var potStock = LogisticsTools.GetNearbyVessels(m.ResourceDistributionRange, false, vessel, true);
                        var potCount = potStock.Count;

                        for (int z = 0; z < potCount; ++z)
                        {
                            var s = potStock[z];
                            if (s.FindPartModulesImplementing <USI_ModuleResourceWarehouse>().Count == 0)
                            {
                                continue;
                            }
                            if (!depots.Contains(s))
                            {
                                depots.Add(s);
                            }
                        }
                    }
                }
            }
            return(depots);
        }
Ejemplo n.º 3
0
        private void PushResources(string resourceName, double amount)
        {
            var vessels = LogisticsTools.GetNearbyVessels(2000, true, vessel, false);
            var count   = vessels.Count;

            for (int i = 0; i < count; ++i)
            {
                var v = vessels[i];
                //Put recycled stuff into recycleable places
                var parts  = v.parts;
                var pCount = parts.Count;
                for (int x = 0; x < pCount; ++x)
                {
                    var p = parts[x];
                    if (p == part || !p.Modules.Contains("USI_ModuleRecycleBin"))
                    {
                        continue;
                    }

                    if (!p.Resources.Contains(resourceName))
                    {
                        continue;
                    }

                    var partRes  = p.Resources[resourceName];
                    var partNeed = partRes.maxAmount - partRes.amount;
                    if (partNeed > 0 && amount > 0)
                    {
                        if (partNeed > amount)
                        {
                            partNeed = amount;
                        }
                        partRes.amount += partNeed;
                        amount         -= partNeed;
                    }
                }
            }
            if (amount > 1f)
            {
                ScreenMessages.PostScreenMessage(String.Format("{0:0} units of {1} were lost due to lack of recycle space", amount, ResourceName), 5f, ScreenMessageStyle.UPPER_CENTER);
            }
        }