Exemple #1
0
        protected override void ProduceGoods(ushort buildingID, ref Building buildingData, ref Building.Frame frameData, int productionRate, int finalProductionRate, ref Citizen.BehaviourData behaviour, int aliveWorkerCount, int totalWorkerCount, int workPlaceCount, int aliveVisitorCount, int totalVisitorCount, int visitPlaceCount)
        {
            productionRate = 0;
            TerrainManager  instance        = Singleton <TerrainManager> .instance;
            WaterSimulation waterSimulation = instance.WaterSimulation;

            if (this.m_standingWaterDepth > 0 && buildingData.m_waterSource == 0)
            {
                HandleWaterSource(buildingID, ref buildingData, true, (int)this.m_standingWaterDepth * 10, 1000, 1);
            }
            else if (this.m_standingWaterDepth > 0)
            {
                WaterSource watersourceData = waterSimulation.LockWaterSource(buildingData.m_waterSource);

                float waterSurfaceElevation = Singleton <TerrainManager> .instance.WaterLevel(VectorUtils.XZ(buildingData.m_position));

                if (waterSurfaceElevation > watersourceData.m_target)
                {
                    watersourceData.m_outputRate = 0u;
                }
                else if (watersourceData.m_outputRate == 0u)
                {
                    watersourceData.m_outputRate = ((50u * watersourceData.m_water) / 1000u) - ((50u * watersourceData.m_water) / 1000u) % 50 + 50;
                }
                if (watersourceData.m_water < 50u)
                {
                    watersourceData.m_outputRate += 50u;
                    watersourceData.m_water       = 1000u * (watersourceData.m_outputRate / 50);
                }
                waterSimulation.UnlockWaterSource(buildingData.m_waterSource, watersourceData);
            }
            base.ProduceGoods(buildingID, ref buildingData, ref frameData, productionRate, finalProductionRate, ref behaviour, aliveWorkerCount, totalWorkerCount, workPlaceCount, aliveVisitorCount, totalVisitorCount, visitPlaceCount);
        }
Exemple #2
0
        public override string GetLocalizedStats(ushort buildingID, ref Building data)
        {
            StringBuilder sb = new StringBuilder();


            string floatFormat = "F1";

            if (this.m_standingWaterDepth > 0)
            {
                float bottomElevation       = data.m_position.y;
                float waterSurfaceElevation = Singleton <TerrainManager> .instance.WaterLevel(VectorUtils.XZ(data.m_position));

                float           targetElevation = data.m_position.y + this.m_standingWaterDepth;
                TerrainManager  instance        = Singleton <TerrainManager> .instance;
                WaterSimulation waterSimulation = instance.WaterSimulation;
                if (data.m_waterSource != 0)
                {
                    WaterSource sourceData = waterSimulation.LockWaterSource(data.m_waterSource);
                    targetElevation = sourceData.m_target;

                    //sb.AppendLine("Flow Rate: " + sourceData.m_flow.ToString(floatFormat));

                    /*sb.AppendLine("Water: " + sourceData.m_water.ToString(floatFormat));
                     * sb.AppendLine("Target Elevation: " + targetElevation2.ToString(floatFormat));*/

                    waterSimulation.UnlockWaterSource(data.m_waterSource, sourceData);
                }
                sb.AppendLine("Bottom Elevation:" + bottomElevation.ToString(floatFormat));
                sb.AppendLine("Ground Water Elevation: " + targetElevation.ToString(floatFormat));
                sb.AppendLine("Water Surface Elevation: " + waterSurfaceElevation.ToString(floatFormat));
            }

            return(sb.ToString());
        }
        private int HandleWaterSource(ushort buildingID, ref Building data, bool output, int rate, int max, float radius)
        {
            uint num = (uint)(Mathf.Min(rate, max) >> 1);

            if (num == 0u)
            {
                return(0);
            }
            TerrainManager  instance        = Singleton <TerrainManager> .instance;
            WaterSimulation waterSimulation = instance.WaterSimulation;

            if (data.m_waterSource != 0)
            {
                bool        flag       = false;
                WaterSource sourceData = waterSimulation.LockWaterSource(data.m_waterSource);
                try
                {
                    if (output)
                    {
                        uint num2 = num;
                        if (num2 < sourceData.m_water >> 3)
                        {
                            num2 = sourceData.m_water >> 3;
                        }
                        sourceData.m_outputRate = num2 + 3u >> 2;
                        sourceData.m_water     += num;
                    }
                    else
                    {
                        uint num3 = num;
                        if (num3 < sourceData.m_water >> 3)
                        {
                            num3 >>= 1;
                        }
                        sourceData.m_inputRate = num3 + 3u >> 2;
                        if (num > sourceData.m_water)
                        {
                            num = sourceData.m_water;
                        }
                        if (sourceData.m_water != 0u)
                        {
                            data.m_waterPollution  = (byte)Mathf.Min(255f, 255u * sourceData.m_pollution / sourceData.m_water);
                            sourceData.m_pollution = (uint)((ulong)sourceData.m_pollution * (ulong)(sourceData.m_water - num) / (ulong)sourceData.m_water);
                        }
                        else
                        {
                            data.m_waterPollution = 0;
                        }
                        sourceData.m_water -= num;
                        Vector3 vector = sourceData.m_inputPosition;
                        if (!instance.HasWater(VectorUtils.XZ(vector)))
                        {
                            vector = data.CalculatePosition(this.m_waterLocationOffset);
                            if (instance.GetClosestWaterPos(ref vector, radius))
                            {
                                sourceData.m_inputPosition  = vector;
                                sourceData.m_outputPosition = vector;
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                    }
                }
                finally
                {
                    waterSimulation.UnlockWaterSource(data.m_waterSource, sourceData);
                }
                if (flag)
                {
                    waterSimulation.ReleaseWaterSource(data.m_waterSource);
                    data.m_waterSource = 0;
                }
            }
            else
            {
                Vector3 vector2 = data.CalculatePosition(this.m_waterLocationOffset);

                WaterSource sourceData2 = default(WaterSource);
                sourceData2.m_type           = 2;
                sourceData2.m_inputPosition  = vector2;
                sourceData2.m_outputPosition = vector2;

                if (output)
                {
                    sourceData2.m_outputRate = num + 3u >> 2;
                    sourceData2.m_water      = num;
                    //  sourceData2.m_pollution = num * (uint)this.m_outletPollution / (uint)Mathf.Max(100, waterSimulation.GetPollutionDisposeRate() * 100);
                    if (!waterSimulation.CreateWaterSource(out data.m_waterSource, sourceData2))
                    {
                        num = 0u;
                    }
                }
                else
                {
                    sourceData2.m_inputRate = num + 3u >> 2;
                    waterSimulation.CreateWaterSource(out data.m_waterSource, sourceData2);
                    num = 0u;
                }
            }
            return((int)((int)num << 1));
        }