Exemplo n.º 1
0
            private static ConduitFlow.ConduitContents SetMaxFlow(ConduitFlow.ConduitContents contents, ConduitBridge bridge, ConduitFlow manager)
            {
                if (bridge.GetComponent <BuildingHP>().HitPoints == 0)
                {
                    //does not actually remove mass from the conduit, just changes what the bridge sees
                    contents.RemoveMass(contents.mass);
                    return(contents);
                }
                int        outputCell   = (int)bridgeOutputCell.GetValue(bridge);
                GameObject outputObject = Grid.Objects[outputCell, Integration.layers[(int)bridge.type]];

                if (outputObject == null)
                {
                    return(contents);
                }
                Pressurized pressure = bridge.GetComponent <Pressurized>();
                float       capacity;

                if (!Pressurized.IsDefault(pressure))
                {
                    capacity = pressure.Info.Capacity;
                }
                else
                {
                    capacity = (float)maxMass.GetValue(manager);
                }

                //If the ConduitBridge is not supposed to support the amount of fluid currently in the contents, only make the bridge's intended max visible
                //Also immediately deal damage if the current contents are higher than the intended max.
                if (capacity < contents.mass)
                {
                    float initial = contents.mass;
                    float removed = contents.RemoveMass(initial - capacity);
                    float ratio   = removed / initial;
                    contents.diseaseCount = (int)((float)contents.diseaseCount * ratio);
                    BuildingHP.DamageSourceInfo damage = Integration.GetPressureDamage();
                    bridge.Trigger((int)GameHashes.DoBuildingDamage, damage);
                }
                {
                    float       targetCapacity;
                    Pressurized outPressure = outputObject.GetComponent <Pressurized>();
                    if (!Pressurized.IsDefault(outPressure))
                    {
                        targetCapacity = outPressure.Info.Capacity;
                    }
                    else
                    {
                        targetCapacity = (float)maxMass.GetValue(manager);
                    }

                    if (contents.mass > targetCapacity * 2)
                    {
                        BuildingHP.DamageSourceInfo damage = Integration.GetPressureDamage();
                        outputObject.Trigger((int)GameHashes.DoBuildingDamage, damage);
                    }
                }
                return(contents);
            }