Esempio n. 1
0
        private void GrabResources(string resourceName)
        {
            if (!part.Resources.Contains(resourceName))
            {
                return;
            }

            var brokRes = part.Resources[resourceName];
            var needed  = brokRes.maxAmount - brokRes.amount;
            //Pull in from warehouses

            var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");

            foreach (var whp in whpList)
            {
                if (whp.Resources.Contains(resourceName))
                {
                    var res = whp.Resources[resourceName];
                    if (res.amount >= needed)
                    {
                        brokRes.amount += needed;
                        res.amount     -= needed;
                        needed          = 0;
                        break;
                    }
                    else
                    {
                        brokRes.amount += res.amount;
                        needed         -= res.amount;
                        res.amount      = 0;
                    }
                }
            }
        }
Esempio n. 2
0
        private void SwapResources(string fetchName, string storeName)
        {
            print("Making sure part contains " + storeName);
            if (!part.Resources.Contains(storeName))
            {
                return;
            }

            print("Resource exists...");
            var brokRes = part.Resources[storeName];
            var needed  = brokRes.maxAmount - brokRes.amount;

            print("We need " + needed);
            //Pull in from warehouses

            var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");

            print("Found " + whpList.Count() + " warehouses...");
            foreach (var whp in whpList)
            {
                if (whp.Resources.Contains(fetchName))
                {
                    print("Found " + fetchName);
                    var res = whp.Resources[fetchName];
                    if (res.amount >= needed)
                    {
                        brokRes.amount += needed;
                        res.amount     -= needed;
                        needed          = 0;
                        break;
                    }
                    else
                    {
                        brokRes.amount += res.amount;
                        needed         -= res.amount;
                        res.amount      = 0;
                    }
                }
            }
        }
Esempio n. 3
0
        private void PushResources(string resourceName)
        {
            var brokRes = part.Resources[resourceName];

            //Put remaining parts in warehouses
            foreach (var p in LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleCleaningBin"))
            {
                if (p.Resources.Contains(resourceName))
                {
                    var partRes  = p.Resources[resourceName];
                    var partNeed = partRes.maxAmount - partRes.amount;
                    if (partNeed > 0 && brokRes.amount > 0)
                    {
                        if (partNeed > brokRes.amount)
                        {
                            partNeed = brokRes.amount;
                        }
                        partRes.amount += partNeed;
                        brokRes.amount -= partNeed;
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnFixedUpdate()
        {
            if (part.Resources.Contains(BrokeredResource) && part.protoModuleCrew.Count == part.CrewCapacity)
            {
                var brokRes = part.Resources[BrokeredResource];
                var needed  = brokRes.maxAmount - brokRes.amount;
                //Pull in from warehouses

                var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");
                foreach (var whp in whpList)
                {
                    if (whp.Resources.Contains(BrokeredResource))
                    {
                        var res = whp.Resources[BrokeredResource];
                        if (res.amount >= needed)
                        {
                            brokRes.amount += needed;
                            res.amount     -= needed;
                            needed          = 0;
                            break;
                        }
                        else
                        {
                            brokRes.amount += res.amount;
                            needed         -= res.amount;
                            res.amount      = 0;
                        }
                    }
                }

                //Push to all parts needing this resource
                foreach (var p in vessel.parts.Where(vp => vp != part && !vp.Modules.Contains("USI_ModuleResourceWarehouse")))
                {
                    if (p.Resources.Contains(BrokeredResource))
                    {
                        var partRes  = p.Resources[BrokeredResource];
                        var partNeed = partRes.maxAmount - partRes.amount;
                        if (partNeed > 0 && brokRes.amount > 0)
                        {
                            if (partNeed > brokRes.amount)
                            {
                                partNeed = brokRes.amount;
                            }
                            partRes.amount += partNeed;
                            brokRes.amount -= partNeed;
                        }
                    }
                }
                //Put remaining parts in warehouses
                foreach (var p in vessel.parts.Where(vp => vp != part && vp.Modules.Contains("USI_ModuleResourceWarehouse")))
                {
                    if (p.Resources.Contains(BrokeredResource))
                    {
                        var partRes  = p.Resources[BrokeredResource];
                        var partNeed = partRes.maxAmount - partRes.amount;
                        if (partNeed > 0 && brokRes.amount > 0)
                        {
                            if (partNeed > brokRes.amount)
                            {
                                partNeed = brokRes.amount;
                            }
                            partRes.amount += partNeed;
                            brokRes.amount -= partNeed;
                        }
                    }
                }
            }
        }