GetResourceFlowMode() public static method

public static GetResourceFlowMode ( int type ) : ResourceFlowMode
type int
return ResourceFlowMode
コード例 #1
0
ファイル: PartSim.cs プロジェクト: vosechu/Engineer
        public void SetResourceDrainRates(List <PartSim> partSims)
        {
            foreach (int type in resourceConsumptions.Types)
            {
                double amount = resourceConsumptions[type];

                switch (ResourceContainer.GetResourceFlowMode(type))
                {
                case ResourceFlowMode.NO_FLOW:
                    this.resourceDrains.Add(type, amount);
                    break;

                case ResourceFlowMode.ALL_VESSEL:
                    SetResourceDrainRateAllVessel(type, amount, partSims);
                    break;

                case ResourceFlowMode.STACK_PRIORITY_SEARCH:
                    SetResourceDrainRateRecursive(type, amount);
                    break;
                }
            }
        }
コード例 #2
0
ファイル: PartSim.cs プロジェクト: vosechu/Engineer
        public bool CanDrawNeededResources(List <PartSim> partSims)
        {
            foreach (int type in resourceConsumptions.Types)
            {
                switch (ResourceContainer.GetResourceFlowMode(type))
                {
                case ResourceFlowMode.NO_FLOW:
                    if (resources[type] < 1f)
                    {
                        return(false);
                    }
                    break;

                case ResourceFlowMode.ALL_VESSEL:
                    foreach (PartSim partSim in partSims)
                    {
                        if (partSim.resources[type] > 1f)
                        {
                            return(true);
                        }
                    }
                    return(false);

                case ResourceFlowMode.STACK_PRIORITY_SEARCH:
                    if (!CanSupplyResourceRecursive(type))
                    {
                        return(false);
                    }
                    break;

                default:
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
ファイル: EngineSim.cs プロジェクト: kevin-ye/Engineer
        public bool SetResourceDrains(List <PartSim> allParts, List <PartSim> allFuelLines, HashSet <PartSim> drainingParts)
        {
            LogMsg log = null;

            // A dictionary to hold a set of parts for each resource
            Dictionary <int, HashSet <PartSim> > sourcePartSets = new Dictionary <int, HashSet <PartSim> >();

            foreach (int type in resourceConsumptions.Types)
            {
                HashSet <PartSim> sourcePartSet = null;
                switch (ResourceContainer.GetResourceFlowMode(type))
                {
                case ResourceFlowMode.NO_FLOW:
                    if (partSim.resources[type] > SimManager.RESOURCE_MIN)
                    {
                        sourcePartSet = new HashSet <PartSim>();
                        //MonoBehaviour.print("SetResourceDrains(" + name + ":" + partId + ") setting sources to just this");
                        sourcePartSet.Add(partSim);
                    }
                    break;

                case ResourceFlowMode.ALL_VESSEL:
                    foreach (PartSim aPartSim in allParts)
                    {
                        if (aPartSim.resources[type] > SimManager.RESOURCE_MIN)
                        {
                            if (sourcePartSet == null)
                            {
                                sourcePartSet = new HashSet <PartSim>();
                            }

                            sourcePartSet.Add(aPartSim);
                        }
                    }
                    break;

                case ResourceFlowMode.STAGE_PRIORITY_FLOW:
                {
                    Dictionary <int, HashSet <PartSim> > stagePartSets = new Dictionary <int, HashSet <PartSim> >();
                    int maxStage = -1;
                    foreach (PartSim aPartSim in allParts)
                    {
                        if (aPartSim.resources[type] > SimManager.RESOURCE_MIN)
                        {
                            //int stage = aPartSim.decoupledInStage;            // Use the number of the stage the tank is decoupled in
                            int stage = aPartSim.DecouplerCount();                      // Use the count of decouplers between tank and root
                            if (stage > maxStage)
                            {
                                maxStage = stage;
                            }
                            if (stagePartSets.ContainsKey(stage))
                            {
                                sourcePartSet = stagePartSets[stage];
                            }
                            else
                            {
                                sourcePartSet = new HashSet <PartSim>();
                                stagePartSets.Add(stage, sourcePartSet);
                            }

                            sourcePartSet.Add(aPartSim);
                        }
                    }

                    while (maxStage >= 0)
                    {
                        if (stagePartSets.ContainsKey(maxStage))
                        {
                            if (stagePartSets[maxStage].Count() > 0)
                            {
                                sourcePartSet = stagePartSets[maxStage];
                                break;
                            }
                        }
                        maxStage--;
                    }
                }
                break;

                case ResourceFlowMode.STACK_PRIORITY_SEARCH:
                    HashSet <PartSim> visited = new HashSet <PartSim>();

                    if (SimManager.logOutput)
                    {
                        log = new LogMsg();
                        log.buf.AppendLine("Find " + ResourceContainer.GetResourceName(type) + " sources for " + partSim.name + ":" + partSim.partId);
                    }
                    sourcePartSet = partSim.GetSourceSet(type, allParts, visited, log, "");
                    if (SimManager.logOutput)
                    {
                        MonoBehaviour.print(log.buf);
                    }
                    break;

                default:
                    MonoBehaviour.print("SetResourceDrains(" + partSim.name + ":" + partSim.partId + ") Unexpected flow type for " + ResourceContainer.GetResourceName(type) + ")");
                    break;
                }

                if (sourcePartSet != null && sourcePartSet.Count > 0)
                {
                    sourcePartSets[type] = sourcePartSet;
                    if (SimManager.logOutput)
                    {
                        log = new LogMsg();
                        log.buf.AppendLine("Source parts for " + ResourceContainer.GetResourceName(type) + ":");
                        foreach (PartSim partSim in sourcePartSet)
                        {
                            log.buf.AppendLine(partSim.name + ":" + partSim.partId);
                        }
                        MonoBehaviour.print(log.buf);
                    }
                }
            }

            // If we don't have sources for all the needed resources then return false without setting up any drains
            foreach (int type in resourceConsumptions.Types)
            {
                if (!sourcePartSets.ContainsKey(type))
                {
                    if (SimManager.logOutput)
                    {
                        MonoBehaviour.print("No source of " + ResourceContainer.GetResourceName(type));
                    }

                    isActive = false;
                    return(false);
                }
            }

            // Now we set the drains on the members of the sets and update the draining parts set
            foreach (int type in resourceConsumptions.Types)
            {
                HashSet <PartSim> sourcePartSet = sourcePartSets[type];
                // Loop through the members of the set
                double amount = resourceConsumptions[type] / sourcePartSet.Count;
                foreach (PartSim partSim in sourcePartSet)
                {
                    if (SimManager.logOutput)
                    {
                        MonoBehaviour.print("Adding drain of " + amount + " " + ResourceContainer.GetResourceName(type) + " to " + partSim.name + ":" + partSim.partId);
                    }

                    partSim.resourceDrains.Add(type, amount);
                    drainingParts.Add(partSim);
                }
            }

            return(true);
        }