Ejemplo n.º 1
0
        private void PushResources(string resourceName)
        {
            if (!part.Resources.Contains(resourceName))
            {
                return;
            }
            var brokRes = part.Resources[resourceName];
            //Put remaining parts in warehouses
            var wh    = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleCleaningBin");
            var count = wh.Count;

            for (int i = 0; i < count; ++i)
            {
                var p = wh[i];
                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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ConsumeResource(ResourceRatio resourceRatio, double percentage)
        {
            var resourceName = resourceRatio.ResourceName;
            var needed       = resourceRatio.Ratio * percentage;

            var sourceParts = LogisticsTools.GetRegionalWarehouses(vessel, nameof(USI_ModuleResourceWarehouse));

            foreach (var sourcePart in sourceParts)
            {
                if (sourcePart != part)
                {
                    var warehouse = sourcePart.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (warehouse != null &&
                        warehouse.localTransferEnabled &&
                        sourcePart.Resources.Contains(resourceName))
                    {
                        var resource = sourcePart.Resources[resourceName];
                        if (resource.flowState)
                        {
                            if (resource.amount >= needed)
                            {
                                resource.amount -= needed;
                                needed           = 0;
                                break;
                            }
                            else
                            {
                                needed         -= resource.amount;
                                resource.amount = 0;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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");
            var count   = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                var whp = whpList[i];
                if (whp == part)
                {
                    continue;
                }

                var whc = whp.FindModulesImplementing <BaseConverter>();
                if (whc.Count > 0)
                {
                    continue;
                }


                if (whp.Modules.Contains("USI_ModuleResourceWarehouse"))
                {
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (!wh.localTransferEnabled)
                    {
                        continue;
                    }
                }
                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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private bool HasResource(ResourceRatio resInfo)
        {
            var resourceName   = resInfo.ResourceName;
            var costMultiplier = USI_ConverterOptions.ConverterSwapCostMultiplierValue;

            if (costMultiplier <= ResourceUtilities.FLOAT_TOLERANCE)
            {
                return(true);
            }

            var needed  = resInfo.Ratio * costMultiplier;
            var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");

            //EC we're a lot less picky...
            if (resInfo.ResourceName == "ElectricCharge")
            {
                whpList.AddRange(part.vessel.parts);
            }
            var count = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                var whp = whpList[i];
                if (whp == part)
                {
                    continue;
                }

                if (resInfo.ResourceName != "ElectricCharge")
                {
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (wh != null)
                    {
                        if (!wh.localTransferEnabled)
                        {
                            continue;
                        }
                    }
                }
                if (whp.Resources.Contains(resourceName))
                {
                    var res = whp.Resources[resourceName];
                    if (res.amount >= needed)
                    {
                        needed = 0;
                        break;
                    }
                    else
                    {
                        needed -= res.amount;
                    }
                }
            }
            return(needed < ResourceUtilities.FLOAT_TOLERANCE);
        }
Ejemplo n.º 5
0
        private void TakeResources(ResourceRatio resInfo)
        {
            var resourceName   = resInfo.ResourceName;
            var costMultiplier = USI_ConverterOptions.ConverterSwapCostMultiplierValue;

            if (costMultiplier > 0)
            {
                var needed = resInfo.Ratio * costMultiplier;
                //Pull in from warehouses

                var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");
                var count   = whpList.Count;
                for (int i = 0; i < count; ++i)
                {
                    var whp = whpList[i];
                    if (whp == part)
                    {
                        continue;
                    }
                    var wh = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                    if (wh != null)
                    {
                        if (!wh.localTransferEnabled)
                        {
                            continue;
                        }
                    }
                    if (whp.Resources.Contains(resourceName))
                    {
                        var res = whp.Resources[resourceName];
                        if (res.amount >= needed)
                        {
                            res.amount -= needed;
                            needed      = 0;
                            break;
                        }
                        else
                        {
                            needed    -= res.amount;
                            res.amount = 0;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void SwapResources(string fetchName, string storeName)
        {
            if (!part.Resources.Contains(storeName))
            {
                return;
            }

            var brokRes = part.Resources[storeName];
            var needed  = brokRes.maxAmount - brokRes.amount;
            //Pull in from warehouses
            var whpList = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");
            var count   = whpList.Count;

            for (int i = 0; i < count; ++i)
            {
                var whp = whpList[i];
                var wh  = whp.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                if (wh != null)
                {
                    if (!wh.localTransferEnabled)
                    {
                        continue;
                    }
                }

                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;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void ConsumeResource(ResourceRatio resInfo, double percentage)
        {
            var resourceName = resInfo.ResourceName;
            var needed       = resInfo.Ratio * percentage;
            //Pull in from warehouses

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

            foreach (var sourcePart in sourceParts)
            {
                if (sourcePart == part)
                {
                    continue;
                }
                var warehouse = sourcePart.FindModuleImplementing <USI_ModuleResourceWarehouse>();
                if (warehouse != null)
                {
                    if (!warehouse.localTransferEnabled)
                    {
                        continue;
                    }
                }
                if (sourcePart.Resources.Contains(resourceName))
                {
                    var res = sourcePart.Resources[resourceName];
                    if (res.amount >= needed)
                    {
                        res.amount -= needed;
                        needed      = 0;
                        break;
                    }
                    else
                    {
                        needed    -= res.amount;
                        res.amount = 0;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private double FindResources(ResourceRatio resInfo)
        {
            var resourceName = resInfo.ResourceName;
            var needed       = resInfo.Ratio;

            if (needed < ResourceUtilities.FLOAT_TOLERANCE)
            {
                return(1d);
            }
            var available   = 0d;
            var sourceParts = LogisticsTools.GetRegionalWarehouses(vessel, "USI_ModuleResourceWarehouse");

            foreach (var sourcePart in sourceParts)
            {
                if (sourcePart == part)
                {
                    continue;
                }

                var warehouse = sourcePart.FindModuleImplementing <USI_ModuleResourceWarehouse>();

                if (resInfo.ResourceName != "ElectricCharge" && warehouse != null) //EC we're a lot less picky...
                {
                    if (!warehouse.localTransferEnabled)
                    {
                        continue;
                    }
                }
                if (sourcePart.Resources.Contains(resourceName))
                {
                    available += sourcePart.Resources[resourceName].amount;
                    if (available >= needed)
                    {
                        return(1d);
                    }
                }
            }
            return(available / needed);
        }