Example #1
0
        // Tries to request fluid for current requestor in specified list of Warp Gates
        // returns false when all providers are dry at the moment and no more fluid can be transfered in this channel
        private static bool RequestFluid(ValvesList warpGates)
        {
            var requestor = warpGates.getCurrentRequestor();
            var provider  = warpGates.getNextProvider();
            var start     = provider;

            if (null == provider || null == requestor)
            {
                return(false);
            }
            int toCell      = requestor.GetOutputCell();
            var flowManager = warpGates.FlowManager;

            // Fill input cell from various providers, in case when provider's conduit is not full
            do
            {
                int fromCell = provider.GetInputCell();
                if (provider != requestor)
                {
                    ConduitFlow.Conduit         providerConduit  = flowManager.GetConduit(fromCell);
                    ConduitFlow.ConduitContents providerContents = providerConduit.GetContents(flowManager);
                    if (!SimHashes.Vacuum.Equals(providerContents.element))
                    {
                        ConduitFlow.Conduit         requestorConduit  = flowManager.GetConduit(toCell);
                        ConduitFlow.ConduitContents requestorContents = requestorConduit.GetContents(flowManager);
#if DEBUG
                        Logger.LogFormat("Trying to move {0} kg. of {1} from {2} to {3}", providerContents.mass, providerContents.element, fromCell, toCell);
                        Logger.LogFormat("Requestor contents is: {0} kg. of {1}", requestorContents.mass, requestorContents.element);
#endif
                        if (requestorContents.mass < 1f && requestorContents.element != providerContents.element && requestorContents.element != SimHashes.Vacuum)
                        {
                            flowManager.RemoveElement(requestorConduit, requestorContents.mass);
                        }
                        float addedMass = flowManager.AddElement(toCell, providerContents.element, providerContents.mass, providerContents.temperature, providerContents.diseaseIdx, providerContents.diseaseCount);
                        Game.Instance.accumulators.Accumulate(provider.AccumulatorHandle, addedMass);
                        if (addedMass > 0f)
                        {
#if DEBUG
                            Logger.LogFormat("Moved {0} kg. from {1} to {2}", addedMass, fromCell, toCell);
#endif
                            ConduitFlow.ConduitContents removed = flowManager.RemoveElement(providerConduit, addedMass);
                            Game.Instance.accumulators.Accumulate(requestor.AccumulatorHandle, addedMass);
                        }
                    }
                }
                if (flowManager.IsConduitFull(toCell))
                {
                    return(true);
                }
                provider = warpGates.getNextProvider();
            } while (provider != start);
            return(false);
        }
        public static void SetProviderValveChannel(ValveBase valveBase, int newChannel)
        {
            Logger.LogFormat("==Enter WaprSpaceManager.SetProviderValveChannel(valveBase={0}, valveChannel={1})", valveBase.GetInstanceID(), newChannel);
            ValveChannels providers = getChannelsForConduitType(valveBase.conduitType);

            foreach (var item in providers)
            {
                if (null != item.Value)
                {
                    item.Value.Remove(valveBase);
                }
            }
            ValvesList valves;

            if (!providers.TryGetValue(newChannel, out valves))
            {
                valves = new ValvesList(getFlowManager(valveBase.conduitType));
                providers[newChannel] = valves;
            }

            valves.Add(valveBase);
            Logger.Log("==Exit WaprSpaceManager.SetProviderValveChannel");
        }