private void ConduitUpdate(float dt)
    {
        ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType);

        if (flowManager.HasConduit(inputCell))
        {
            ConduitFlow.ConduitContents contents = flowManager.GetContents(inputCell);
            if (!(contents.mass <= 0f))
            {
                int cell = outputCell;
                ConduitFlow.ConduitContents contents2 = flowManager.GetContents(cell);
                if (contents2.mass > 0f)
                {
                    cell      = secondaryOutput.Cell;
                    contents2 = flowManager.GetContents(cell);
                }
                if (contents2.mass <= 0f)
                {
                    float num = flowManager.AddElement(cell, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                    if (num > 0f)
                    {
                        flowManager.RemoveElement(inputCell, num);
                    }
                }
            }
        }
    }
示例#2
0
    private void OnConduitTick(float dt)
    {
        bool value = false;

        if (this.operational.IsOperational)
        {
            ConduitFlow gasFlow = Conduit.GetFlowManager(this.portInfo.conduitType);

            ConduitFlow.ConduitContents contentsI1 = gasFlow.GetContents(this.inputCell1);
            ConduitFlow.ConduitContents contentsI2 = gasFlow.GetContents(this.inputCell2);

            //Debug.Log("contentsI1.mass: " + contentsI1.mass);
            //Debug.Log("contentsI2.mass: " + contentsI2.mass);

            //int num = (contents.element != this.filteredElem) ? this.outputCell : this.filteredCell;
            ConduitFlow.ConduitContents contentsO = gasFlow.GetContents(this.outputCell);

            if (contentsI1.element != SimHashes.Hydrogen || contentsI2.element != SimHashes.Oxygen)
            {
                base.Trigger((int)GameHashes.DoBuildingDamage, new BuildingHP.DamageSourceInfo
                {
                    damage    = 1,
                    source    = STRINGS.BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                    popString = STRINGS.UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                });
                gasFlow.RemoveElement(this.inputCell1, 0.111999989f);
                gasFlow.RemoveElement(this.inputCell2, 0.888f);
            }
            else
            {
                if (contentsI1.mass > 0.111999989f &&
                    contentsI2.mass > 0.888f &&
                    contentsO.mass <= 0f)
                {
                    value = true;
                    //float num2 = flowManager.AddElement(num, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                    float outputTemperature = contentsI1.temperature * 0.111999989f + contentsI2.temperature * 0.888f;
                    //Debug.Log("outputTemperature: " + outputTemperature);
                    ConduitFlow liquidFlow = Conduit.GetFlowManager(ConduitType.Liquid);
                    float       num2       = liquidFlow.AddElement(this.outputCell, SimHashes.Water, 1f, outputTemperature, contentsI1.diseaseIdx, 0);
                    if (num2 > 0f)
                    {
                        gasFlow.RemoveElement(this.inputCell1, 0.111999989f);
                        gasFlow.RemoveElement(this.inputCell2, 0.888f);
                    }
                }
            }
        }
        this.operational.SetActive(value, false);
    }
            public static bool Prefix(ConduitConsumer __instance, ConduitFlow conduit_mgr, int ___utilityCell)
            {
                // if we don't have the component, do nothing special
                if (__instance.gameObject.GetComponent <InfiniteStorage>() == null)
                {
                    return(true);
                }

                var contents = conduit_mgr.GetContents(___utilityCell);

                var storage = __instance.gameObject.GetComponent <Storage>();

                if (storage == null)
                {
                    return(true);
                }

                var filterable = __instance.gameObject.GetComponent <TreeFilterable>();

                if (filterable == null)
                {
                    return(true);
                }

                // If it doesn't contain the tag, return false, don't consume
                var tag = ElementLoader.FindElementByHash(contents.element).tag;
                var ret = filterable.AcceptedTags.Contains(tag);

                return(ret);
            }
    private float GetContainedMass()
    {
        int         cell        = Grid.PosToCell(this);
        ConduitFlow flowManager = Conduit.GetFlowManager(conduitType);

        return(flowManager.GetContents(cell).mass);
    }
示例#5
0
 protected override void UpdateVisualState(bool force = false)
 {
     if (wasOn != switchedOn || force)
     {
         wasOn = switchedOn;
         if (switchedOn)
         {
             animController.Play(ConduitSensor.ON_ANIMS, KAnim.PlayMode.Loop);
             int         cell        = Grid.PosToCell(this);
             ConduitFlow flowManager = Conduit.GetFlowManager(conduitType);
             ConduitFlow.ConduitContents contents = flowManager.GetContents(cell);
             Color32 c = Color.white;
             if (contents.diseaseIdx != 255)
             {
                 Disease disease = Db.Get().Diseases[contents.diseaseIdx];
                 c = disease.overlayColour;
             }
             animController.SetSymbolTint(TINT_SYMBOL, c);
         }
         else
         {
             animController.Play(ConduitSensor.OFF_ANIMS, KAnim.PlayMode.Once);
         }
     }
 }
    private void OnConduitUpdate(float dt)
    {
        ConduitFlow liquidConduitFlow = Game.Instance.liquidConduitFlow;
        bool        flag = liquidConduitFlow.GetContents(outputCell).mass > 0f;

        smi.sm.outputBlocked.Set(flag, smi);
        operational.SetFlag(coolantOutputPipeEmpty, !flag);
    }
 private void OnConduitUpdate(float dt)
 {
     if (GetSMI() != null)
     {
         ConduitFlow liquidConduitFlow = Game.Instance.liquidConduitFlow;
         bool        value             = liquidConduitFlow.GetContents(outputCell).mass > 0f && base.smi.HasContaminatedMass();
         base.smi.sm.outputBlocked.Set(value, base.smi);
     }
 }
    private void OnConduitTick(float dt)
    {
        bool value = false;

        if (this.operational.IsOperational)
        {
            ConduitFlow flowManager = Conduit.GetFlowManager(this.portInfo.conduitType);

            ConduitFlow.ConduitContents contents = flowManager.GetContents(this.inputCell);
            //int num = (contents.element != this.filteredElem) ? this.outputCell : this.filteredCell;
            ConduitFlow.ConduitContents contentsO = flowManager.GetContents(this.outputCell);
            ConduitFlow.ConduitContents contents2 = flowManager.GetContents(this.sInputCell);
            if (contents.mass > 0.111999989f &&
                contents2.mass > 0.888f &&
                contentsO.mass <= 0f)
            {
                if (contents.element != SimHashes.Hydrogen || contents2.element != SimHashes.Oxygen)
                {
                    base.Trigger(-794517298, new BuildingHP.DamageSourceInfo
                    {
                        damage    = 1,
                        source    = STRINGS.BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                        popString = STRINGS.UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                    });
                    flowManager.RemoveElement(this.inputCell, 0.111999989f);
                    flowManager.RemoveElement(this.sInputCell, 0.888f);
                }
                else
                {
                    value = true;
                    //float num2 = flowManager.AddElement(num, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                    float num2 = flowManager.AddElement(this.outputCell, SimHashes.Steam, 1f, 523.15f, contents.diseaseIdx, 0);
                    if (num2 > 0f)
                    {
                        flowManager.RemoveElement(this.inputCell, 0.111999989f);
                        flowManager.RemoveElement(this.sInputCell, 0.888f);
                    }
                }
            }
        }
        this.operational.SetActive(value, false);
    }
示例#9
0
    private void OnConduitTick(float dt)
    {
        bool value = false;

        UpdateConduitBlockedStatus();
        if (operational.IsOperational)
        {
            ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType);
            ConduitFlow.ConduitContents contents = flowManager.GetContents(inputCell);
            int num = (contents.element != filteredElem) ? outputCell : filteredCell;
            ConduitFlow.ConduitContents contents2 = flowManager.GetContents(num);
            if (contents.mass > 0f && contents2.mass <= 0f)
            {
                value = true;
                float num2 = flowManager.AddElement(num, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                if (num2 > 0f)
                {
                    flowManager.RemoveElement(inputCell, num2);
                }
            }
        }
        operational.SetActive(value, false);
    }
示例#10
0
        protected override void ConduitUpdate(float dt)
        {
            int         cell        = Grid.PosToCell(this);
            ConduitFlow flowManager = Conduit.GetFlowManager(this.conduitType);

            this.currentValue = flowManager.GetContents(cell).mass * 1000;

            // spawn code should never toggle as it crashes on load
            if (dt < 0)
            {
                return;
            }

            if (this.activateAboveThreshold)
            {
                // Empty is always false
                if (this.currentValue <= 0f)
                {
                    if (base.IsSwitchedOn)
                    {
                        this.Toggle();
                    }
                    return;
                }

                // Full is always true
                if (this.currentValue >= this.max)
                {
                    if (!base.IsSwitchedOn)
                    {
                        this.Toggle();
                    }
                    return;
                }

                if ((this.currentValue > this.threshold && !base.IsSwitchedOn) || (this.currentValue <= this.threshold && base.IsSwitchedOn))
                {
                    this.Toggle();
                }
            }
            else if ((this.currentValue > this.threshold && base.IsSwitchedOn) || (this.currentValue <= this.threshold && !base.IsSwitchedOn))
            {
                this.Toggle();
            }
        }
示例#11
0
    private void ConduitUpdate(float dt)
    {
        ConduitFlow flowManager = Conduit.GetFlowManager(type);

        if (flowManager.HasConduit(inputCell))
        {
            ConduitFlow.ConduitContents contents = flowManager.GetContents(inputCell);
            if (contents.mass > 0f)
            {
                float num = flowManager.AddElement(outputCell, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                if (num > 0f)
                {
                    flowManager.RemoveElement(inputCell, num);
                    Game.Instance.accumulators.Accumulate(accumulator, contents.mass);
                }
            }
        }
    }
示例#12
0
    protected override void ConduitUpdate(float dt)
    {
        ConduitFlow flowManager = Conduit.GetFlowManager(conduitType);
        int         cell        = Grid.PosToCell(base.transform.GetPosition());

        ConduitFlow.ConduitContents contents = flowManager.GetContents(cell);
        if (base.IsSwitchedOn)
        {
            if (contents.element != desiredElement)
            {
                Toggle();
            }
        }
        else if (contents.element == desiredElement)
        {
            Toggle();
        }
    }
示例#13
0
        //Since our input/output ports are inert, we must define the behavior of the ports ourself.
        //float dt is the amount of time that has passed. typically not used as far as i am aware, likely always just 1 (1 second)
        private void OnConduitTick(float dt)
        {
            //The ConduitFlow task is an overarching flow manager for a specific conduit type. If our bridge is a liquid bridge, we will get the liquid manager.
            ConduitFlow flowManager = Conduit.GetFlowManager(conduitType);

            //If there is a pipe connected to the location of the input port, and a pipe connected to the location of the output port
            if (flowManager.HasConduit(inputPort.GetPortCell()) && flowManager.HasConduit(outputPort.GetPortCell()))
            {
                //Get the contents of the input pipe
                ConduitFlow.ConduitContents contents = flowManager.GetContents(inputPort.GetPortCell());
                if (contents.mass > 0f)
                {
                    //The AddElement method will attempt to move as much fluid from the input to the output as it can, and will return the amount successfully moved (if any).
                    //This method also handles things such as merging disease amounts and temperature based on how much is moved
                    float amountMOved = flowManager.AddElement(outputPort.GetPortCell(), contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount);
                    if (amountMOved > 0f)
                    {
                        //RemoveElement, similar to AddElement, automatically reduces the disease count (if any germs are present)
                        flowManager.RemoveElement(inputPort.GetPortCell(), amountMOved);
                    }
                }
            }
        }
示例#14
0
        protected override void ConduitTick(float delta)
        {
            if (!AlwaysConsume && !operational.IsOperational)
            {
                return;
            }
            IConduitFlow conduitFlow = GetConduitManager();

            if (ConduitType != ConduitType.Solid)
            {
                ConduitFlow mngr = conduitFlow as ConduitFlow;
                ConduitFlow.ConduitContents contents = mngr.GetContents(portCell);
                if (contents.mass <= 0)
                {
                    return;
                }
                Element element         = ElementLoader.FindElementByHash(contents.element);
                bool    matchesTag      = StoreTag == GameTags.Any || element.HasTag(StoreTag);
                float   rateAmount      = ConsumptionRate * delta;
                float   maxTake         = 0f;
                float   storageContains = storage.MassStored();
                float   storageLeft     = storage.capacityKg - storageContains;
                float   portContains    = StoreTag == GameTags.Any ? storageContains : storage.GetMassAvailable(StoreTag);
                float   portLeft        = MaximumStore - portContains;
                maxTake = Mathf.Min(storageLeft, portLeft);
                maxTake = Mathf.Min(rateAmount, maxTake);
                float removed = 0f;
                if (maxTake > 0f)
                {
                    ConduitFlow.ConduitContents removedContents = mngr.RemoveElement(portCell, maxTake);
                    removed             = removedContents.mass;
                    LastConsumedElement = removedContents.element;
                    float ratio = removed / contents.mass;
                    if (!matchesTag)
                    {
                        BuildingHP.DamageSourceInfo damage = new BuildingHP.DamageSourceInfo
                        {
                            damage    = 1,
                            source    = BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                            popString = UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                        };
                        Trigger((int)GameHashes.DoBuildingDamage, damage);
                        if (WrongElement == WrongElementResult.Dump)
                        {
                            int buildingCell = Grid.PosToCell(_parent.transform.GetPosition());
                            SimMessages.AddRemoveSubstance(buildingCell, contents.element, CellEventLogger.Instance.ConduitConsumerWrongElement, removed, contents.temperature, contents.diseaseIdx, contents.diseaseIdx);
                            return;
                        }
                    }
                    if (ConduitType == ConduitType.Gas)
                    {
                        if (!element.IsGas)
                        {
                            Debug.LogWarning($"[MultIO] Gas input port attempted to consume non gass: {element.id.ToString()}");
                        }
                        else
                        {
                            storage.AddGasChunk(element.id, removed, contents.temperature, contents.diseaseIdx, contents.diseaseCount, KeepZeroMassObject, false);
                        }
                    }
                    else if (ConduitType == ConduitType.Liquid)
                    {
                        if (!element.IsLiquid)
                        {
                            Debug.LogWarning($"[MultIO] Liquid input port attempted to consume non liquid: {element.id.ToString()}");
                        }
                        else
                        {
                            storage.AddLiquid(element.id, removed, contents.temperature, contents.diseaseIdx, contents.diseaseCount, KeepZeroMassObject, false);
                        }
                    }
                }
            }
            else
            {
                SolidConduitFlow mngr = conduitFlow as SolidConduitFlow;
                SolidConduitFlow.ConduitContents contents = mngr.GetContents(portCell);
                if (contents.pickupableHandle.IsValid() && (AlwaysConsume || operational.IsOperational))
                {
                    float stored           = StoreTag == GameTags.Any ? storage.MassStored() : storage.GetMassAvailable(StoreTag);
                    float maxStorage       = Mathf.Min(storage.capacityKg, MaximumStore);
                    float availableStorage = Mathf.Max(0f, maxStorage - stored);
                    if (availableStorage > 0f)
                    {
                        Pickupable tmp        = mngr.GetPickupable(contents.pickupableHandle);
                        bool       matchesTag = StoreTag == GameTags.Any || tmp.HasTag(StoreTag);
                        if (matchesTag)
                        {
                            if (tmp.PrimaryElement.Mass <= stored || tmp.PrimaryElement.Mass > maxStorage)
                            {
                                Pickupable take = mngr.RemovePickupable(portCell);
                                if (take != null)
                                {
                                    storage.Store(take.gameObject, true);
                                }
                            }
                        }
                        else
                        {
                            Pickupable take = mngr.RemovePickupable(portCell);
                            take.transform.SetPosition(Grid.CellToPos(portCell));
                            //TODO: Add a PopFX. Likely will not do damage.
                        }
                    }
                }
            }
        }
    private void Consume(float dt, ConduitFlow conduit_mgr)
    {
        IsSatisfied = false;
        if (building.Def.CanMove)
        {
            utilityCell = GetInputCell();
        }
        if (IsConnected)
        {
            ConduitFlow.ConduitContents contents = conduit_mgr.GetContents(utilityCell);
            if (!(contents.mass <= 0f))
            {
                IsSatisfied = true;
                if (alwaysConsume || operational.IsOperational)
                {
                    float a = ConsumptionRate * dt;
                    a = Mathf.Min(a, space_remaining_kg);
                    float num = 0f;
                    if (a > 0f)
                    {
                        ConduitFlow.ConduitContents conduitContents = conduit_mgr.RemoveElement(utilityCell, a);
                        num = conduitContents.mass;
                        lastConsumedElement = conduitContents.element;
                    }
                    Element element = ElementLoader.FindElementByHash(contents.element);
                    bool    flag    = element.HasTag(capacityTag);
                    if (num > 0f && capacityTag != GameTags.Any && !flag)
                    {
                        Trigger(-794517298, new BuildingHP.DamageSourceInfo
                        {
                            damage    = 1,
                            source    = (string)BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                            popString = (string)UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                        });
                    }
                    if (flag || wrongElementResult == WrongElementResult.Store || contents.element == SimHashes.Vacuum || capacityTag == GameTags.Any)
                    {
                        if (num > 0f)
                        {
                            int     disease_count = (int)((float)contents.diseaseCount * (num / contents.mass));
                            Element element2      = ElementLoader.FindElementByHash(contents.element);
                            switch (conduitType)
                            {
                            case ConduitType.Liquid:
                                if (element2.IsLiquid)
                                {
                                    storage.AddLiquid(contents.element, num, contents.temperature, contents.diseaseIdx, disease_count, keepZeroMassObject, false);
                                }
                                else
                                {
                                    Debug.LogWarning("Liquid conduit consumer consuming non liquid: " + element2.id.ToString());
                                }
                                break;

                            case ConduitType.Gas:
                                if (element2.IsGas)
                                {
                                    storage.AddGasChunk(contents.element, num, contents.temperature, contents.diseaseIdx, disease_count, keepZeroMassObject, false);
                                }
                                else
                                {
                                    Debug.LogWarning("Gas conduit consumer consuming non gas: " + element2.id.ToString());
                                }
                                break;
                            }
                        }
                    }
                    else if (num > 0f && wrongElementResult == WrongElementResult.Dump)
                    {
                        int disease_count2 = (int)((float)contents.diseaseCount * (num / contents.mass));
                        int gameCell       = Grid.PosToCell(base.transform.GetPosition());
                        SimMessages.AddRemoveSubstance(gameCell, contents.element, CellEventLogger.Instance.ConduitConsumerWrongElement, num, contents.temperature, contents.diseaseIdx, disease_count2, true, -1);
                    }
                }
            }
        }
    }
    private void Consume(float dt, ConduitFlow conduit_mgr)
    {
        this.IsSatisfied = false;
        if (this.building.Def.CanMove)
        {
            this.utilityCell = this.GetInputCell();
        }
        if (!this.IsConnected)
        {
            return;
        }
        ConduitFlow.ConduitContents contents = conduit_mgr.GetContents(this.utilityCell);
        if ((double)contents.mass <= 0.0)
        {
            return;
        }
        this.IsSatisfied = true;
        if (!this.alwaysConsume && !this.operational.IsOperational)
        {
            return;
        }
        float delta = Mathf.Min(this.ConsumptionRate * dt, this.space_remaining_kg);
        float mass  = 0.0f;

        if ((double)delta > 0.0)
        {
            ConduitFlow.ConduitContents conduitContents = conduit_mgr.RemoveElement(this.utilityCell, delta);
            mass = conduitContents.mass;
            this.lastConsumedElement = conduitContents.element;
        }
        bool flag = ElementLoader.FindElementByHash(contents.element).HasTag(this.capacityTag);

        if ((double)mass > 0.0 && this.capacityTag != GameTags.Any && !flag)
        {
            this.Trigger(-794517298, (object)new BuildingHP.DamageSourceInfo()
            {
                damage    = 1,
                source    = (string)BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                popString = (string)UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
            });
        }
        if (flag || this.wrongElementResult == ConduitConsumer2.WrongElementResult.Store || (contents.element == SimHashes.Vacuum || this.capacityTag == GameTags.Any))
        {
            if ((double)mass <= 0.0)
            {
                return;
            }
            int     disease_count = (int)((double)contents.diseaseCount * ((double)mass / (double)contents.mass));
            Element elementByHash = ElementLoader.FindElementByHash(contents.element);
            switch (this.conduitType)
            {
            case ConduitType.Gas:
                if (elementByHash.IsGas)
                {
                    this.storage.AddGasChunk(contents.element, mass, contents.temperature, contents.diseaseIdx, disease_count, this.keepZeroMassObject, false);
                    break;
                }
                Debug.LogWarning((object)("Gas conduit consumer consuming non gas: " + elementByHash.id.ToString()));
                break;

            case ConduitType.Liquid:
                if (elementByHash.IsLiquid)
                {
                    this.storage.AddLiquid(contents.element, mass, contents.temperature, contents.diseaseIdx, disease_count, this.keepZeroMassObject, false);
                    break;
                }
                Debug.LogWarning((object)("Liquid conduit consumer consuming non liquid: " + elementByHash.id.ToString()));
                break;
            }
        }
        else
        {
            if ((double)mass <= 0.0 || this.wrongElementResult != ConduitConsumer2.WrongElementResult.Dump)
            {
                return;
            }
            int disease_count = (int)((double)contents.diseaseCount * ((double)mass / (double)contents.mass));
            SimMessages.AddRemoveSubstance(Grid.PosToCell(this.transform.GetPosition()), contents.element, CellEventLogger.Instance.ConduitConsumerWrongElement, mass, contents.temperature, contents.diseaseIdx, disease_count, true, -1);
        }
    }
示例#17
0
        public static void RequestFluidFromChannel(ValveBase requestor, int channelNo)
        {
            Logger.LogFormat("==Entry WarpSpaceManager.RequestFluidFromChannel(requestor={0}, channelNo={1})", requestor.GetInstanceID(), channelNo);
            try
            {
                ConduitFlow flowManager = null;
                if (requestor.conduitType == LiquidWarpConfig.CONDUIT_TYPE)
                {
                    flowManager = Conduit.GetFlowManager(ConduitType.Liquid);
                }
                else if (requestor.conduitType == GasWarpConfig.CONDUIT_TYPE)
                {
                    flowManager = Conduit.GetFlowManager(ConduitType.Gas);
                }
                else
                {
                    Logger.Log("unable to determine correct ConduitType.");
                    return;
                }

                ValveChannels channels = getChannelsForConduitType(requestor.conduitType);
                ValvesList    providers;

                if (!channels.TryGetValue(channelNo, out providers) || (providers.Count == 0))
                {
                    Logger.LogFormat("No providers for channel {0} found.", channelNo);
                    return;
                }

                ValveBase provider = providers.getNext();
                ValveBase start    = provider;
                if (null == provider)
                {
                    Logger.Log("You should never see this message! provider is null");
                    return;
                }
                int toCell = (int)valveBaseOutputCellFieldInfo.GetValue(requestor);
                ConduitFlow.ConduitContents requestorContents = flowManager.GetContents(toCell);
                // Fill input cell from various providers, in case when provider's conduit is not full
                do
                {
                    Logger.LogFormat("Trying to request from valveBase {0}", provider.GetInstanceID());
                    int fromCell = (int)valveBaseInputCellFieldInfo.GetValue(provider);
                    if (provider != requestor && flowManager.HasConduit(fromCell))
                    {
                        ConduitFlow.ConduitContents providerContents = flowManager.GetContents(fromCell);
                        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)
                        {
                            Logger.LogFormat("Adding Element to cell: requestor={0} provider={1} actually added mass={2}, element type={3}", requestor.GetInstanceID(), provider.GetInstanceID(), addedMass, providerContents.element);
                            flowManager.RemoveElement(fromCell, addedMass);
                            Game.Instance.accumulators.Accumulate(requestor.AccumulatorHandle, addedMass);
                        }
                    }
                    if (flowManager.IsConduitFull(toCell))
                    {
                        break;
                    }
                    provider = providers.getNext();
                } while (provider != start);
            }
            catch (Exception ex)
            {
                Logger.LogFormat("Exception in WarpSpaceManager.RequestFluidFromChannel: {0}\n{1}", ex.Message, ex.StackTrace);
            }
            Logger.Log("==Exit WarpSpaceManager.RequestFluidFromChannel");
        }
示例#18
0
    public void UpdateOverlayColours()
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();
        Diseases diseases    = Db.Get().Diseases;
        Color32  color       = new Color32(0, 0, 0, byte.MaxValue);

        for (int i = 0; i < headers.Count; i++)
        {
            DiseaseContainer       payload    = payloads[i];
            DiseaseHeader          header     = headers[i];
            KBatchedAnimController controller = payload.controller;
            if ((UnityEngine.Object)controller != (UnityEngine.Object)null)
            {
                Color32 c        = color;
                Vector3 position = controller.transform.GetPosition();
                if (visibleArea.Min <= (Vector2)position && (Vector2)position <= visibleArea.Max)
                {
                    int num           = 0;
                    int disease_idx   = 255;
                    int disease_count = 0;
                    GetVisualDiseaseIdxAndCount(header, ref payload, out disease_idx, out disease_count);
                    if (disease_idx != 255)
                    {
                        c   = diseases[disease_idx].overlayColour;
                        num = disease_count;
                    }
                    if (payload.isContainer)
                    {
                        Storage           component = header.primaryElement.GetComponent <Storage>();
                        List <GameObject> items     = component.items;
                        for (int j = 0; j < items.Count; j++)
                        {
                            GameObject gameObject = items[j];
                            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
                            {
                                HandleVector <int> .Handle handle = GetHandle(gameObject);
                                if (handle.IsValid())
                                {
                                    DiseaseHeader header2 = GetHeader(handle);
                                    if (header2.diseaseCount > num && header2.diseaseIdx != 255)
                                    {
                                        num = header2.diseaseCount;
                                        c   = diseases[header2.diseaseIdx].overlayColour;
                                    }
                                }
                            }
                        }
                    }
                    c.a = SimUtil.DiseaseCountToAlpha254(num);
                    if (payload.conduitType != 0)
                    {
                        ConduitFlow flowManager = Conduit.GetFlowManager(payload.conduitType);
                        int         cell        = Grid.PosToCell(position);
                        ConduitFlow.ConduitContents contents = flowManager.GetContents(cell);
                        if (contents.diseaseIdx != 255 && contents.diseaseCount > num)
                        {
                            num = contents.diseaseCount;
                            c   = diseases[contents.diseaseIdx].overlayColour;
                            c.a = byte.MaxValue;
                        }
                    }
                }
                controller.OverlayColour = c;
            }
        }
    }
示例#19
0
        private void UpdateConduit(ConduitFlow conduitFlow, ConduitType conduitType, int cellPos, Element cellElement, ref int cellCount)
        {
            var building = Grid.Objects[cellPos, (int)GetObjectLayer(conduitType)];

            if (building == null || building.GetComponent <BuildingComplete>() == null)
            {
                return;
            }

            var pipe        = building.GetComponent <PrimaryElement>();
            var pipeElement = pipe.Element;
            int pipeCount   = pipe.DiseaseIdx == radiationIdx ? pipe.DiseaseCount : 0;

            var content = conduitFlow.GetContents(cellPos);

            //string typeLog = $"{cellElement.tag}, {pipeElement.tag}";

            if (content.mass > 0)
            {
                var contentElement = ElementLoader.FindElementByHash(content.element);
                //typeLog += $", {contentElement.tag}";

                int contentCount = content.diseaseIdx == radiationIdx ? content.diseaseCount : 0;
                int diff         = contentCount - pipeCount;

                var   growth         = diff > 0 ? radiationDisease.GetGrowthRuleForElement(contentElement) : radiationDisease.GetGrowthRuleForElement(pipeElement);
                float diffusionScale = Mathf.Min(growth.diffusionScale * 10, 1);
                int   increase       = Mathf.RoundToInt(diff * diffusionScale / 2);

                if (increase != 0)
                {
                    int oldPipe    = pipeCount;
                    int oldContent = contentCount;

                    content.diseaseCount = contentCount - increase;
                    content.diseaseIdx   = radiationIdx;
                    conduitFlow.SetContents(cellPos, content);

                    pipe.AddDisease(radiationIdx, increase, "Radioactivity.UpdateConduit");
                    pipeCount += increase;

                    //Log.Spam($"{cellPos} increase {increase} ({diffusionScale}), content {oldContent} => {content.diseaseCount}, pipe {oldPipe} =>{pipe.DiseaseCount}");
                }
            }

            if (cellElement.id != SimHashes.Vacuum && cellElement.id != SimHashes.Void)
            {
                int diff = pipeCount - cellCount;

                var   growth         = diff > 0 ? radiationDisease.GetGrowthRuleForElement(pipeElement) : radiationDisease.GetGrowthRuleForElement(cellElement);
                float diffusionScale = Mathf.Min(growth.diffusionScale * 10, 1);
                int   increase       = Mathf.RoundToInt(diff * diffusionScale / 2);

                if (increase != 0)
                {
                    int oldPipe = pipeCount;
                    int oldCell = cellCount;

                    pipe.AddDisease(radiationIdx, -increase, "Radioactivity.UpdateConduit");

                    SimMessages.ModifyDiseaseOnCell(cellPos, radiationIdx, increase);
                    cellCount += increase;

                    //Log.Spam($"{cellPos} increase {increase} ({diffusionScale}), pipe {oldPipe} => {pipe.DiseaseCount}, grid {oldCell} => {Grid.DiseaseCount[cellPos]}");
                }
            }

            //Log.Spam($"{cellPos} {typeLog}");
        }
 private void Consume(float dt, ConduitFlow conduit_mgr)
 {
     if (this.building.Def.CanMove)
     {
         this.utilityCell = this.GetInputCell();
     }
     if (this.IsConnected)
     {
         ConduitFlow.ConduitContents contents = conduit_mgr.GetContents(this.utilityCell);
         if (contents.mass > 0f)
         {
             this.IsSatisfied = true;
             if (this.alwaysConsume || this.operational.IsOperational)
             {
                 float num  = (!(this.capacityTag != GameTags.Any)) ? this.storage.MassStored() : this.storage.GetMassAvailable(this.capacityTag);
                 float b    = Mathf.Min(this.storage.RemainingCapacity(), this.capacityKG - num);
                 float num2 = this.ConsumptionRate * dt;
                 num2 = Mathf.Min(num2, b);
                 float num3 = 0f;
                 if (num2 > 0f)
                 {
                     num3 = conduit_mgr.RemoveElement(this.utilityCell, num2).mass;
                 }
                 Element element = ElementLoader.FindElementByHash(contents.element);
                 bool    flag    = element.HasTag(this.capacityTag);
                 if (num3 > 0f && this.capacityTag != GameTags.Any && !flag)
                 {
                     base.Trigger(-794517298, new BuildingHP.DamageSourceInfo
                     {
                         damage    = 1,
                         source    = BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                         popString = UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                     });
                 }
                 if (flag || this.wrongElementResult == ConduitConsumer.WrongElementResult.Store || contents.element == SimHashes.Vacuum || this.capacityTag == GameTags.Any)
                 {
                     if (num3 > 0f)
                     {
                         int         disease_count = (int)((float)contents.diseaseCount * (num3 / contents.mass));
                         Element     element2      = ElementLoader.FindElementByHash(contents.element);
                         ConduitType conduitType   = this.conduitType;
                         if (conduitType != ConduitType.Liquid)
                         {
                             if (conduitType == ConduitType.Gas)
                             {
                                 if (element2.IsGas)
                                 {
                                     this.storage.AddGasChunk(contents.element, num3, contents.temperature, contents.diseaseIdx, disease_count, this.keepZeroMassObject, false);
                                 }
                                 else
                                 {
                                     global::Debug.LogWarning("Gas conduit consumer consuming non gas: " + element2.id.ToString());
                                 }
                             }
                         }
                         else if (element2.IsLiquid)
                         {
                             this.storage.AddLiquid(contents.element, num3, contents.temperature, contents.diseaseIdx, disease_count, this.keepZeroMassObject, false);
                         }
                         else
                         {
                             global::Debug.LogWarning("Liquid conduit consumer consuming non liquid: " + element2.id.ToString());
                         }
                     }
                 }
                 else if (num3 > 0f && this.wrongElementResult == ConduitConsumer.WrongElementResult.Dump)
                 {
                     int disease_count2 = (int)((float)contents.diseaseCount * (num3 / contents.mass));
                     int gameCell       = Grid.PosToCell(base.transform.GetPosition());
                     SimMessages.AddRemoveSubstance(gameCell, contents.element, CellEventLogger.Instance.ConduitConsumerWrongElement, num3, contents.temperature, contents.diseaseIdx, disease_count2, true, -1);
                 }
             }
         }
         else
         {
             this.IsSatisfied = false;
         }
     }
     else
     {
         this.IsSatisfied = false;
     }
 }
示例#21
0
        private void ConduitUpdate(float dt)
        {
            ConduitFlow flowManager = Conduit.GetFlowManager(type);

            if (!flowManager.HasConduit(inputCell))
            {
                return;
            }

            if (IsOperational)
            {
                ConduitFlow.ConduitContents contents = flowManager.GetContents(inputCell);
                if (contents.mass <= 0.0)
                {
                    return;
                }

                ConduitFlow.ConduitContents contentOutput1 = flowManager.GetContents(outputCell);
                ConduitFlow.ConduitContents contentOutput2 = flowManager.GetContents(secondaryOutputCell);

                var maxMass  = Traverse.Create(flowManager).Field("MaxMass").GetValue <float>();                //type == ConduitType.Liquid ? 10f : 1f;
                var halfMass = contents.mass / 2f;

                var willFitInOutput1 = maxMass - contentOutput1.mass;
                var willFitInOutput2 = maxMass - contentOutput2.mass;

                float delta1 = 0;
                float delta2 = 0;

                if (Math.Abs(willFitInOutput1) < 0.001f && Math.Abs(willFitInOutput2) < 0.001f)
                {
                    //do nothing
                }
                else if (!flowManager.HasConduit(secondaryOutputCell))
                {
                    delta1 = flowManager.AddElement(outputCell, contents.element, contents.mass, contents.temperature,
                                                    contents.diseaseIdx, contents.diseaseCount);
                }
                else if (!flowManager.HasConduit(outputCell))
                {
                    delta2 = flowManager.AddElement(secondaryOutputCell, contents.element, contents.mass, contents.temperature,
                                                    contents.diseaseIdx, contents.diseaseCount);
                }
                else if (willFitInOutput1 >= halfMass && willFitInOutput2 >= halfMass)
                {
                    delta1 = flowManager.AddElement(outputCell, contents.element, halfMass, contents.temperature,
                                                    contents.diseaseIdx, contents.diseaseCount / 2);
                    delta2 = flowManager.AddElement(secondaryOutputCell, contents.element, halfMass, contents.temperature,
                                                    contents.diseaseIdx, contents.diseaseCount / 2);
                }
                else if (willFitInOutput1 < halfMass)
                {
                    var overflowOutput1 = halfMass - willFitInOutput1;
                    var ratio           = (halfMass - overflowOutput1) / halfMass;
                    delta1 = flowManager.AddElement(outputCell, contents.element, halfMass - overflowOutput1,
                                                    contents.temperature, contents.diseaseIdx, (int)((contents.diseaseCount / 2f) * ratio));
                    delta2 = flowManager.AddElement(secondaryOutputCell, contents.element, halfMass + overflowOutput1,
                                                    contents.temperature, contents.diseaseIdx, (int)((contents.diseaseCount / 2f) * (1f / ratio)));
                }
                else
                {
                    var overflowOutput2 = halfMass - willFitInOutput2;
                    var ratio           = (halfMass - overflowOutput2) / halfMass;
                    delta1 = flowManager.AddElement(secondaryOutputCell, contents.element, halfMass - overflowOutput2,
                                                    contents.temperature, contents.diseaseIdx, (int)((contents.diseaseCount / 2f) * ratio));
                    delta2 = flowManager.AddElement(outputCell, contents.element, halfMass + overflowOutput2,
                                                    contents.temperature, contents.diseaseIdx, (int)((contents.diseaseCount / 2f) * (1f / ratio)));
                }

                flowManager.RemoveElement(inputCell, delta1);
                flowManager.RemoveElement(inputCell, delta2);

                Game.Instance.accumulators.Accumulate(accumulator, contents.mass);
            }
        }