Exemple #1
0
        public virtual void RebuildDistributionCache()
        {
            WBIDistributionManager.Log("[WBIResourceDistributor] - Rebuilding distribution cache.");
            List <string>      requiredResourceNames = new List <string>();
            int                index, totalCount;
            PartResource       resource;
            EDistributionModes mode;

            //Clear the lists passed in.
            sharedResourcesCache.Clear();
            requiredResourcesCache.Clear();

            //Now go through our resource list and divide them up between the two lists
            totalCount = this.part.Resources.Count;
            for (index = 0; index < totalCount; index++)
            {
                resource = this.part.Resources[index];

                //See if the resource is on the ignore list
                if (resourceBlacklist.Contains(resource.resourceName))
                {
                    WBIDistributionManager.Log("[WBIResourceDistributor] - Skipping " + resource.resourceName + ", it is blacklisted.");
                    continue;
                }

                //Add to the appropriate list
                if (distributionMap.ContainsKey(resource.resourceName) == false)
                {
                    WBIDistributionManager.Log("[WBIResourceDistributor] - Skipping " + resource.resourceName + ", it is not in the resource map.");
                    continue;
                }
                mode = distributionMap[resource.resourceName];
                switch (mode)
                {
                case EDistributionModes.DistributionModeShare:
                    //Share the resource
                    WBIDistributionManager.Log("[WBIResourceDistributor] - Added " + resource.resourceName + " to shared resources");
                    sharedResourcesCache.Add(resource);
                    break;

                case EDistributionModes.DistributionModeConsume:
                case EDistributionModes.DistributionModeRequired:
                    //Consume if our resource isn't full
                    if (resource.amount < resource.maxAmount)
                    {
                        WBIDistributionManager.Log("[WBIResourceDistributor] - Added " + resource.resourceName + " to required resources");
                        requiredResourcesCache.Add(resource);
                    }
                    break;

                default:
                    WBIDistributionManager.Log("[WBIResourceDistributor] - Skipping " + resource.resourceName + ", it is ignored.");
                    break;
                }
            }
        }
Exemple #2
0
 public void Start()
 {
     Instance       = this;
     cycleStartTime = Planetarium.GetUniversalTime();
     elapsedTime    = 0f;
     if (HighLogic.LoadedSceneIsFlight)
     {
         debugMode = PathfinderSettings.LoggingEnabled;
     }
 }
Exemple #3
0
        public virtual void RebuildDistributionList()
        {
            WBIDistributionManager.Log("[WBIResourceDistributor] - Rebuilding distribution list.");
            List <BaseConverter> converters = null;
            int           index, totalCount, totalRequired, reqIndex;
            BaseConverter converter;
            PartResource  resource;
            ResourceRatio ratio;

            //Clear the map
            distributionMap.Clear();

            //Build the base list
            totalCount = this.part.Resources.Count;
            for (index = 0; index < totalCount; index++)
            {
                resource = this.part.Resources[index];
                if (resourceBlacklist.Contains(resource.resourceName) == false && distributionMap.ContainsKey(resource.resourceName) == false)
                {
                    distributionMap.Add(resource.resourceName, EDistributionModes.DistributionModeOff);
                }
                if (isConsumer)
                {
                    distributionMap[resource.resourceName] = EDistributionModes.DistributionModeConsume;
                }
            }

            //Find all the required resources (if any)
            //Required resources are automatically set to consumer
            converters = this.part.FindModulesImplementing <BaseConverter>();
            totalCount = converters.Count;
            for (index = 0; index < totalCount; index++)
            {
                converter     = converters[index];
                totalRequired = converter.reqList.Count;
                for (reqIndex = 0; reqIndex < totalRequired; reqIndex++)
                {
                    //Get the resource
                    ratio = converter.reqList[reqIndex];

                    //Setup the distribution map
                    if (distributionMap.ContainsKey(ratio.ResourceName))
                    {
                        distributionMap[ratio.ResourceName] = EDistributionModes.DistributionModeRequired;
                    }
                }
            }

            //Rebuild the cache
            RebuildDistributionCache();
        }
Exemple #4
0
        public virtual void GetResourcesToDistribute(out List <PartResource> sharedList, out List <PartResource> requiredList)
        {
            //If the part does not particupate in resource distribution then we're done.
            if (!isParticipating)
            {
                WBIDistributionManager.Log("[WBIResourceDistributor] - This part is not participating in resource distribution");
                sharedList   = null;
                requiredList = null;
                return;
            }

            //Log info
            WBIDistributionManager.Log("[WBIResourceDistributor] - " + this.part.partInfo.title + " is gathering resources to distribute.");

            RebuildDistributionCache();
            sharedList   = this.sharedResourcesCache;
            requiredList = this.requiredResourcesCache;
        }
Exemple #5
0
        public override void SetVisible(bool newValue)
        {
            base.SetVisible(newValue);
            if (distributionMap == null)
            {
                Debug.Log("[DistributionView] - distributionMap is null!!");
                distributionMap = new Dictionary <string, EDistributionModes>();
            }
            if (!newValue)
            {
                if (rebuildCache != null)
                {
                    WBIDistributionManager.Log("Calling rebuildCache");
                    rebuildCache();
                }

                if (HighLogic.LoadedSceneIsFlight)
                {
                    WBIDistributionManager.Log("Calling distribute resources");
                    WBIDistributionManager.Instance.DistributeResourcesImmediately();
                }
            }
        }
 public void Start()
 {
     Instance       = this;
     cycleStartTime = Planetarium.GetUniversalTime();
     elapsedTime    = 0f;
 }