Esempio n. 1
0
        private void SetConversionTable()
        {
            var fieldValue = (Dictionary <DisasterType, DisasterInfo>)conversionField.GetValue(disasterWrapper);

            if (fieldValue == null || !fieldValue.Any() || fieldValue.Any(x => x.Value == null))
            {
                logger.Info("DDS: Rebuilding conversion table");
                var conversionDictionary = new Dictionary <DisasterType, DisasterInfo>();
                conversionDictionary[DisasterType.Earthquake]        = DisasterManager.FindDisasterInfo <EarthquakeAI>();
                conversionDictionary[DisasterType.ForestFire]        = DisasterManager.FindDisasterInfo <ForestFireAI>();
                conversionDictionary[DisasterType.MeteorStrike]      = DisasterManager.FindDisasterInfo <MeteorStrikeAI>();
                conversionDictionary[DisasterType.ThunderStorm]      = DisasterManager.FindDisasterInfo <ThunderStormAI>();
                conversionDictionary[DisasterType.Tornado]           = DisasterManager.FindDisasterInfo <TornadoAI>();
                conversionDictionary[DisasterType.Tsunami]           = DisasterManager.FindDisasterInfo <TsunamiAI>();
                conversionDictionary[DisasterType.StructureCollapse] = DisasterManager.FindDisasterInfo <StructureCollapseAI>();
                conversionDictionary[DisasterType.StructureFire]     = DisasterManager.FindDisasterInfo <StructureFireAI>();
                conversionDictionary[DisasterType.Sinkhole]          = DisasterManager.FindDisasterInfo <SinkholeAI>();

                if (conversionDictionary.Any(x => x.Value == null))
                {
                    logger.Info("DDS: Contains null values");
                }

                conversionField.SetValue(disasterWrapper, conversionDictionary);
            }
        }
        public Server(ServerSettings settings)
        {
            // Attempt to load world
            if (!File.Exists(settings.SavePath))
            {
                throw new FileNotFoundException("Save file not found.");
            }

            string         worldData      = File.ReadAllText(settings.SavePath);
            WorldStateData worldStateData = new WorldStateData(worldData);

            this.settings = settings;
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            processorContext = new ServerProcessorContext(this);

            router = new PacketRouter(processorContext);
            foreach (PacketProcessor packetProcessor in PacketProcessor.GetProcessors())
            {
                router.RegisterPacketProcessor(packetProcessor);
            }

            playerConnections        = new Dictionary <Guid, long>();
            playerManager            = new PlayerManager(this);
            simulationManager        = new SimulationManager(this);
            worldStateManager        = new WorldStateManager(this, settings.SavePath, worldStateData);
            worldRequestQueueManager = new WorldRequestQueueManager(this);
            timeManager        = new TimeManager(this);
            environmentManager = new EnvironmentManager(this);
            disasterManager    = new DisasterManager(this);
            Initialize();
        }
Esempio n. 3
0
    //place a disaster in the given i section
    private void PlaceDisaster(int i)
    {
        // Don't place anything if no disaster selected.
        if (selectedDisaster == DisasterType.NotSelected)
        {
            return;
        }

        // Disaster angular width in degrees and radians.
        float disDeg       = 360.0f / numTiles;
        float disRad       = disDeg * Mathf.PI / 180.0f;
        float disArcLength = disRad * earthRadius;

        float disCenterDeg = (float)i * disDeg - 90.0f;
        float disCenterRad = (float)i * disRad;

        // Instantiate the disaster and retrieve its DisasterManager script.
        GameObject      disaster = Instantiate(disasterPrefab);
        DisasterManager manager  = disaster.GetComponent <DisasterManager>();

        Type SelectedDisasterT = DisasterTypeToClass[selectedDisaster];

        manager.disaster = (Disaster)Activator.CreateInstance(SelectedDisasterT); // Give the disaster a type.

        // Countdown to destroy the disaster.
        Destroy(disaster, 2.0f);

        float spriteWidth    = manager.GetSprite().bounds.max[0] - manager.GetSprite().bounds.min[0];
        float spriteHeight   = manager.GetSprite().bounds.max[1] - manager.GetSprite().bounds.min[1];
        float disScaleFactor = disArcLength / spriteWidth;

        // Rotate, translate, and scale the disaster so that it is above the edge of the earth.
        // Quaternion.Euler expects degrees!
        Quaternion tileRot = Quaternion.Euler(0, 0, disCenterDeg);

        // Move the disaster radially outward by earthRadius.
        Vector3 disNormal = new Vector3(Mathf.Cos(disCenterRad), Mathf.Sin(disCenterRad), 0.0f);

        //May need to change the position and scaling factor depending on the actual
        //size of the sprite
        float altitude = manager.disaster.altitude;

        Vector3 disPos = (earthRadius + altitude * spriteHeight) * disNormal;

        disaster.transform.localScale = Vector3.one * disScaleFactor * 2.0f;
        disaster.transform.position   = disPos;
        disaster.transform.rotation   = tileRot;
    }
        public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context)
        {
            ServerProcessorContext processorContext  = (ServerProcessorContext)context;
            SimulationManager      simulationManager = processorContext.Server.SimulationManager;
            DisasterManager        disasterManager   = processorContext.Server.DisasterManager;

            Player?simulationOwner = simulationManager.GetSimulationOwner();

            if (simulationOwner == null || sourcePlayerId != simulationOwner.Value.Id)
            {
                //Deny request if client isn't the simulation owner
                return;
            }

            disasterManager.EndDisaster();
        }
Esempio n. 5
0
    public override void _Ready()
    {
        base._Ready();
        WorldEnvironment we = GetNode(Game.WORLD_ENVIRO_PATH) as WorldEnvironment;

        Godot.Environment env = we.GetEnvironment();

        env.SetBackground(Godot.Environment.BGMode.Sky);
        sky = env.GetSky() as ProceduralSky;
        sky.SetSkyCurve(0.3f);
        sky.SetGroundCurve(0.3f);

        status = Status.DORMANT;

        dm = GetNode(Game.NATURAL_DISASTERS_PATH) as DisasterManager;
    }
        protected void startDisaster(byte intensity)
        {
            DisasterInfo disasterInfo = EnhancedDisastersManager.GetDisasterInfo(DType);

            if (disasterInfo == null)
            {
                return;
            }

            Vector3 targetPosition;
            float   angle;
            bool    targetFound = findTarget(disasterInfo, out targetPosition, out angle);

            if (!targetFound)
            {
                DebugLogger.Log(getDebugStr() + "target not found");
                return;
            }

            DisasterManager dm = Singleton <DisasterManager> .instance;

            ushort disasterIndex;
            bool   disasterCreated = dm.CreateDisaster(out disasterIndex, disasterInfo);

            if (!disasterCreated)
            {
                DebugLogger.Log(getDebugStr() + "could not create disaster");
                return;
            }

            DisasterLogger.StartedByMod = true;

            disasterStarting(disasterInfo);

            dm.m_disasters.m_buffer[(int)disasterIndex].m_targetPosition = targetPosition;
            dm.m_disasters.m_buffer[(int)disasterIndex].m_angle          = angle;
            dm.m_disasters.m_buffer[(int)disasterIndex].m_intensity      = intensity;
            DisasterData[] expr_98_cp_0 = dm.m_disasters.m_buffer;
            ushort         expr_98_cp_1 = disasterIndex;

            expr_98_cp_0[(int)expr_98_cp_1].m_flags = (expr_98_cp_0[(int)expr_98_cp_1].m_flags | DisasterData.Flags.SelfTrigger);
            disasterInfo.m_disasterAI.StartNow(disasterIndex, ref dm.m_disasters.m_buffer[(int)disasterIndex]);

            DebugLogger.Log(getDebugStr() + string.Format("disaster intensity: {0}, area: {1}", intensity, unlocked ? OccurrenceAreaAfterUnlock : OccurrenceAreaBeforeUnlock));
        }
        private void BigRedBtn_eventClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            StringBuilder sb = new StringBuilder();

            VehicleManager vm = Singleton <VehicleManager> .instance;

            for (int i = 1; i < 16384; i++)
            {
                if ((vm.m_vehicles.m_buffer[i].m_flags & Vehicle.Flags.Created) != (Vehicle.Flags) 0)
                {
                    if (vm.m_vehicles.m_buffer[i].Info.m_vehicleAI is MeteorAI)
                    {
                        vm.ReleaseVehicle((ushort)i);
                    }

                    if (vm.m_vehicles.m_buffer[i].Info.m_vehicleAI is VortexAI)
                    {
                        vm.ReleaseVehicle((ushort)i);
                    }
                }
            }

            WaterSimulation ws = Singleton <WaterSimulation> .instance;

            for (int i = ws.m_waterWaves.m_size; i >= 1; i--)
            {
                Singleton <TerrainManager> .instance.WaterSimulation.ReleaseWaterWave((ushort)i);
            }

            DisasterManager dm = Singleton <DisasterManager> .instance;

            for (ushort i = 0; i < dm.m_disasterCount; i++)
            {
                sb.AppendLine(dm.m_disasters.m_buffer[i].Info.name + " flags: " + dm.m_disasters.m_buffer[i].m_flags.ToString());
                if ((dm.m_disasters.m_buffer[i].m_flags & (DisasterData.Flags.Emerging | DisasterData.Flags.Active | DisasterData.Flags.Clearing)) != DisasterData.Flags.None)
                {
                    if (isDisasterCanBeStopped(dm.m_disasters.m_buffer[i].Info.m_disasterAI))
                    {
                        sb.AppendLine("Trying to cancel " + dm.m_disasters.m_buffer[i].Info.name);
                        dm.m_disasters.m_buffer[i].m_flags = ((dm.m_disasters.m_buffer[i].m_flags & ~(DisasterData.Flags.Emerging | DisasterData.Flags.Active | DisasterData.Flags.Clearing)) | DisasterData.Flags.Finished);
                    }
                }
            }
            Debug.Log(sb.ToString());
        }
Esempio n. 8
0
        private IEnumerator StartDisaster(DisasterInfo info, Vector3 target, float angle)
        {
            DisasterManager disasterManager = Singleton <DisasterManager> .instance;

            if (disasterManager.CreateDisaster(out ushort disaster, info))
            {
                disasterManager.m_disasters.m_buffer[disaster].m_targetPosition = target;
                disasterManager.m_disasters.m_buffer[disaster].m_angle          = angle;
                disasterManager.m_disasters.m_buffer[disaster].m_intensity      = (byte)Singleton <SimulationManager> .instance.m_randomizer.Int32(10, 100);

                disasterManager.m_disasters.m_buffer[disaster].m_flags |= DisasterData.Flags.SelfTrigger;
                info.m_disasterAI.StartNow(disaster, ref disasterManager.m_disasters.m_buffer[disaster]);
            }
            yield return((object)0);

            /*Error: Unable to find new state assignment for yield return*/
            ;
        }
        public override void ProcessAction(ulong currentTick, ClientProcessorContext context)
        {
            Player?simulationOwner = context.Client.SimulationManager.GetSimulationOwner();

            if (simulationOwner == null || simulationOwner.Value != context.Client.LocalPlayer)
            {
                return;
            }

            DisasterManager disasterManager = context.Client.DisasterManager;

            if (!disasterManager.AnyDisasterInProgress())
            {
                return;
            }

            // Pull the current time from our disaster proxy
            IDisasterProxy disasterProxy = disasterManager.GetCurrentDisasterProxy();

            disasterManager.UpdateDisaster(disasterProxy.Time);
        }
        public override void OnAfterSimulationFrame()
        {
            if (!Singleton <ExtendedGameOptionsManager> .instance.values.EnableRandomDisastersForScenarios)
            {
                return;
            }

            // If playing a scenario
            if (!string.IsNullOrEmpty(Singleton <SimulationManager> .instance.m_metaData.m_ScenarioAsset))
            {
                DisasterManager dm = Singleton <DisasterManager> .instance;

                // From DisasterManager.SimulationStepImpl
                ItemClass.Availability mode = Singleton <ToolManager> .instance.m_properties.m_mode;
                if ((mode & ItemClass.Availability.Game) != ItemClass.Availability.None)
                {
                    int   areaCount = Singleton <GameAreaManager> .instance.m_areaCount;
                    float num       = dm.m_randomDisastersProbability;
                    if (num > 0.001f)
                    {
                        num *= num;
                        num *= (float)((areaCount > 1) ? (550 + areaCount * 50) : 500);
                        int num2 = Mathf.Max(1, Mathf.RoundToInt(num));
                        if (dm.m_randomDisasterCooldown < 65536 - 49152 * num2 / 1000)
                        {
                            dm.m_randomDisasterCooldown++;
                        }
                        else
                        {
                            SimulationManager instance = Singleton <SimulationManager> .instance;
                            if (instance.m_randomizer.Int32(67108864u) < num2)
                            {
                                dm.StartRandomDisaster();
                                dm.m_randomDisasterCooldown = 0;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
    private void Start()
    {
        disasterManager = UIManager.Instance.disasterManager;

        if (isDebug)
        {
            Disaster tempDefaultDisaster = new Disaster();
            tempDefaultDisaster.clipTitle = defaultVideoClip;
            defaultContent.disasterIcon.SetDisaster(tempDefaultDisaster);
        }

        defaultContent.disasterIcon.OnClick  += DisasterIcon_OnClick;
        disasterContent.disasterIcon.OnClick += DisasterIcon_OnClick;

        worldWindow.videoLoader.OnClipFinish += VideoLoader_OnClipFinish;

        HideDirectContent(disasterContent);

        ShowContent(defaultContent);

        disasterManager.AddDisasterEventListener(OnDisaster);
        disasterManager.AddNoDisasterEventListener(OnNoDisaster);
    }
        private static void HandleFireSpread(CommonBuildingAI CBAI, ushort buildingID, ref Building buildingData, int fireDamage)
        {
            unsafe
            {
                Quad2   quad2    = new Quad2();
                int     width    = buildingData.Width;
                int     length   = buildingData.Length;
                Vector2 vector2  = VectorUtils.XZ(buildingData.m_position);
                Vector2 vector21 = new Vector2(Mathf.Cos(buildingData.m_angle), Mathf.Sin(buildingData.m_angle));
                Vector2 vector22 = new Vector2(vector21.y, -vector21.x);
                float   single   = (float)Singleton <SimulationManager> .instance.m_randomizer.Int32(8, 32);

                quad2.a = (vector2 - (((float)width * 4f + single) * vector21)) - (((float)length * 4f + single) * vector22);
                quad2.b = (vector2 + (((float)width * 4f + single) * vector21)) - (((float)length * 4f + single) * vector22);
                quad2.c = (vector2 + (((float)width * 4f + single) * vector21)) + (((float)length * 4f + single) * vector22);
                quad2.d = (vector2 - (((float)width * 4f + single) * vector21)) + (((float)length * 4f + single) * vector22);
                Vector2 vector23  = quad2.Min();
                Vector2 vector24  = quad2.Max();
                float   mPosition = buildingData.m_position.y - (float)buildingData.m_baseHeight;

                //krn
                //CBAI.m_info is private\instance /use reflection, should do reverse redirect.
                BuildingInfo bldgInfo;
                bldgInfo = (BuildingInfo)CBAI.GetType().GetField("m_info", BindingFlags.Instance | BindingFlags.Public).GetValue(CBAI);
                if (bldgInfo == null && bldgInfo.m_size == null)
                {
                    Logger.dbgLog("bldgInfo was null");
                }

                float mPosition1 = buildingData.m_position.y + bldgInfo.m_size.y;

                //org
                //float mPosition1 = buildingData.m_position.y + this.m_info.m_size.y;
                //end org
                float      mFireIntensity = (float)(buildingData.m_fireIntensity * (64 - Mathf.Abs(fireDamage - 192)));
                InstanceID instanceID     = new InstanceID()
                {
                    Building = buildingID
                };
                InstanceManager.Group group = Singleton <InstanceManager> .instance.GetGroup(instanceID);

                if (group != null)
                {
                    ushort disaster = group.m_ownerInstance.Disaster;
                    if (disaster != 0)
                    {
                        DisasterManager disasterManager       = Singleton <DisasterManager> .instance;
                        DisasterInfo    info                  = disasterManager.m_disasters.m_buffer[disaster].Info;
                        int             fireSpreadProbability = info.m_disasterAI.GetFireSpreadProbability(disaster, ref disasterManager.m_disasters.m_buffer[disaster]);
                        mFireIntensity = mFireIntensity * ((float)fireSpreadProbability * 0.01f);
                    }
                }
                int             num             = Mathf.Max((int)((vector23.x - 72f) / 64f + 135f), 0);
                int             num1            = Mathf.Max((int)((vector23.y - 72f) / 64f + 135f), 0);
                int             num2            = Mathf.Min((int)((vector24.x + 72f) / 64f + 135f), 269);
                int             num3            = Mathf.Min((int)((vector24.y + 72f) / 64f + 135f), 269);
                BuildingManager buildingManager = Singleton <BuildingManager> .instance;
                for (int i = num1; i <= num3; i++)
                {
                    for (int j = num; j <= num2; j++)
                    {
                        ushort   mBuildingGrid = buildingManager.m_buildingGrid[i * 270 + j];
                        int      num4          = 0;
                        object[] paramcall;
                        while (mBuildingGrid != 0)
                        {
                            //Should we change this 262144?
                            if (mBuildingGrid != buildingID && (float)Singleton <SimulationManager> .instance.m_randomizer.Int32(262144) * single < mFireIntensity)
                            {
                                //Logger.dbgLog("Handlefire1");

                                paramcall = new object[] { quad2, mPosition, mPosition1, mBuildingGrid, buildingManager.m_buildings.m_buffer[mBuildingGrid], group };

                                //var x = CBAI.GetType().GetMethod("TrySpreadFire", BindingFlags.Static | BindingFlags.NonPublic).Invoke(CBAI, paramcall);

                                LimitCommonBuildingAI.TrySpreadFire(quad2, mPosition, mPosition1, mBuildingGrid, ref buildingManager.m_buildings.m_buffer[mBuildingGrid], group);

                                //Logger.dbgLog("Handlefire2");

                                //orginal
                                //CommonBuildingAI.TrySpreadFire(quad2, mPosition, mPosition1, mBuildingGrid, ref buildingManager.m_buildings.m_buffer[mBuildingGrid], group);
                            }
                            mBuildingGrid = buildingManager.m_buildings.m_buffer[mBuildingGrid].m_nextGridBuilding;
                            int num5 = num4 + 1;
                            num4 = num5;
                            if (num5 < 49152)
                            {
                                continue;
                            }
                            CODebugBase <LogChannel> .Error(LogChannel.Core, string.Concat("Invalid list detected!\n", Environment.StackTrace));

                            break;
                        }
                    }
                }
                Vector3     vector3     = VectorUtils.X_Y(vector21);
                Vector3     vector31    = VectorUtils.X_Y(vector22);
                int         num6        = Mathf.Max((int)((vector23.x - 32f) / 32f + 270f), 0);
                int         num7        = Mathf.Max((int)((vector23.y - 32f) / 32f + 270f), 0);
                int         num8        = Mathf.Min((int)((vector24.x + 32f) / 32f + 270f), 539);
                int         num9        = Mathf.Min((int)((vector24.y + 32f) / 32f + 270f), 539);
                TreeManager treeManager = Singleton <TreeManager> .instance;
                for (int k = num7; k <= num9; k++)
                {
                    for (int l = num6; l <= num8; l++)
                    {
                        uint mTreeGrid = treeManager.m_treeGrid[k * 540 + l];
                        int  num10     = 0;
                        while (mTreeGrid != 0)
                        {
                            Vector3 position   = treeManager.m_trees.m_buffer[mTreeGrid].Position;
                            Vector3 mPosition2 = position - buildingData.m_position;
                            mPosition2 = mPosition2 - (Mathf.Clamp(Vector3.Dot(mPosition2, vector3), (float)(-width) * 4f, (float)width * 4f) * vector3);
                            mPosition2 = mPosition2 - (Mathf.Clamp(Vector3.Dot(mPosition2, vector31), (float)(-length) * 4f, (float)length * 4f) * vector31);
                            float single1 = mPosition2.magnitude;
                            //Should we change this 131072?
                            //Logger.dbgLog("Handlefire3");

                            if (single1 < 32f && (float)Singleton <SimulationManager> .instance.m_randomizer.Int32(131072) * single1 < mFireIntensity)
                            {
                                treeManager.BurnTree(mTreeGrid, group, (int)buildingData.m_fireIntensity);
                            }
                            mTreeGrid = treeManager.m_trees.m_buffer[mTreeGrid].m_nextGridTree;
                            int num11 = num10 + 1;
                            num10 = num11;
                            if (num11 < LimitTreeManager.Helper.TreeLimit)
                            {
                                continue;
                            }
                            CODebugBase <LogChannel> .Error(LogChannel.Core, string.Concat("Invalid list detected!\n", Environment.StackTrace));

                            break;
                        }
                    }
                }
            }
        }
        new protected int HandleCommonConsumption(ushort buildingID, ref Building data, ref Building.Frame frameData, ref int electricityConsumption, ref int heatingConsumption, ref int waterConsumption, ref int sewageAccumulation, ref int garbageAccumulation, DistrictPolicies.Services policies)
        {
            int             num      = 100;
            DistrictManager instance = Singleton <DistrictManager> .instance;

            Notification.Problem problem = Notification.RemoveProblems(data.m_problems, Notification.Problem.Electricity | Notification.Problem.Water | Notification.Problem.Sewage | Notification.Problem.Flood | Notification.Problem.Heating);
            bool flag             = data.m_electricityProblemTimer != 0;
            bool flag2            = false;
            bool flag3            = false;
            int  electricityUsage = 0;
            int  heatingUsage     = 0;
            int  waterUsage       = 0;
            int  sewageUsage      = 0;

            if (electricityConsumption != 0)
            {
                int num2 = Mathf.RoundToInt((20f - Singleton <WeatherManager> .instance.SampleTemperature(data.m_position, false)) * 8f);
                num2 = Mathf.Clamp(num2, 0, 400);
                int num3 = heatingConsumption;
                heatingConsumption = (num3 * num2 + Singleton <SimulationManager> .instance.m_randomizer.Int32(100u)) / 100;
                if ((policies & DistrictPolicies.Services.PowerSaving) != DistrictPolicies.Services.None)
                {
                    electricityConsumption = Mathf.Max(1, electricityConsumption * 90 / 100);
                    Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.PolicyCost, 32, this.m_info.m_class);
                }
                bool flag4 = false;
                int  num4  = heatingConsumption * 2 - (int)data.m_heatingBuffer;
                if (num4 > 0 && (policies & DistrictPolicies.Services.OnlyElectricity) == DistrictPolicies.Services.None)
                {
                    int num5 = Singleton <WaterManager> .instance.TryFetchHeating(data.m_position, heatingConsumption, num4, out flag4);

                    data.m_heatingBuffer += (ushort)num5;
                }
                if ((int)data.m_heatingBuffer < heatingConsumption)
                {
                    if ((policies & DistrictPolicies.Services.NoElectricity) != DistrictPolicies.Services.None)
                    {
                        flag3 = true;
                        data.m_heatingProblemTimer = (byte)Mathf.Min(255, (int)(data.m_heatingProblemTimer + 1));
                        if (data.m_heatingProblemTimer >= 65)
                        {
                            num     = 0;
                            problem = Notification.AddProblems(problem, Notification.Problem.Heating | Notification.Problem.MajorProblem);
                        }
                        else if (data.m_heatingProblemTimer >= 3)
                        {
                            num    /= 2;
                            problem = Notification.AddProblems(problem, Notification.Problem.Heating);
                        }
                    }
                    else
                    {
                        num2 = ((num2 + 50) * (heatingConsumption - (int)data.m_heatingBuffer) + heatingConsumption - 1) / heatingConsumption;
                        electricityConsumption += (num3 * num2 + Singleton <SimulationManager> .instance.m_randomizer.Int32(100u)) / 100;
                        if (flag4)
                        {
                            flag3 = true;
                            data.m_heatingProblemTimer = (byte)Mathf.Min(255, (int)(data.m_heatingProblemTimer + 1));
                            if (data.m_heatingProblemTimer >= 3)
                            {
                                problem = Notification.AddProblems(problem, Notification.Problem.Heating);
                            }
                        }
                    }
                    heatingUsage         = (int)data.m_heatingBuffer;
                    data.m_heatingBuffer = 0;
                }
                else
                {
                    heatingUsage          = heatingConsumption;
                    data.m_heatingBuffer -= (ushort)heatingConsumption;
                }
                int num6;
                int a;
                if (this.CanStockpileElectricity(buildingID, ref data, out num6, out a))
                {
                    num4 = num6 + electricityConsumption * 2 - (int)data.m_electricityBuffer;
                    if (num4 > 0)
                    {
                        int num7 = electricityConsumption;
                        if ((int)data.m_electricityBuffer < num6)
                        {
                            num7 += Mathf.Min(a, num6 - (int)data.m_electricityBuffer);
                        }
                        int num8 = Singleton <ElectricityManager> .instance.TryFetchElectricity(data.m_position, num7, num4);

                        data.m_electricityBuffer += (ushort)num8;
                        if (num8 < num4 && num8 < num7)
                        {
                            flag2   = true;
                            problem = Notification.AddProblems(problem, Notification.Problem.Electricity);
                            if (data.m_electricityProblemTimer < 64)
                            {
                                data.m_electricityProblemTimer = 64;
                            }
                        }
                    }
                }
                else
                {
                    num4 = electricityConsumption * 2 - (int)data.m_electricityBuffer;
                    if (num4 > 0)
                    {
                        int num9 = Singleton <ElectricityManager> .instance.TryFetchElectricity(data.m_position, electricityConsumption, num4);

                        data.m_electricityBuffer += (ushort)num9;
                    }
                }
                if ((int)data.m_electricityBuffer < electricityConsumption)
                {
                    flag2 = true;
                    data.m_electricityProblemTimer = (byte)Mathf.Min(255, (int)(data.m_electricityProblemTimer + 1));
                    if (data.m_electricityProblemTimer >= 65)
                    {
                        num     = 0;
                        problem = Notification.AddProblems(problem, Notification.Problem.Electricity | Notification.Problem.MajorProblem);
                    }
                    else if (data.m_electricityProblemTimer >= 3)
                    {
                        num    /= 2;
                        problem = Notification.AddProblems(problem, Notification.Problem.Electricity);
                    }
                    electricityUsage         = (int)data.m_electricityBuffer;
                    data.m_electricityBuffer = 0;
                    if (Singleton <UnlockManager> .instance.Unlocked(ItemClass.Service.Electricity))
                    {
                        GuideController properties = Singleton <GuideManager> .instance.m_properties;
                        if (properties != null)
                        {
                            int publicServiceIndex      = ItemClass.GetPublicServiceIndex(ItemClass.Service.Electricity);
                            int electricityCapacity     = instance.m_districts.m_buffer[0].GetElectricityCapacity();
                            int electricityConsumption2 = instance.m_districts.m_buffer[0].GetElectricityConsumption();
                            if (electricityCapacity >= electricityConsumption2)
                            {
                                Singleton <GuideManager> .instance.m_serviceNeeded[publicServiceIndex].Activate(properties.m_serviceNeeded2, ItemClass.Service.Electricity);
                            }
                            else
                            {
                                Singleton <GuideManager> .instance.m_serviceNeeded[publicServiceIndex].Activate(properties.m_serviceNeeded, ItemClass.Service.Electricity);
                            }
                        }
                    }
                }
                else
                {
                    electricityUsage          = electricityConsumption;
                    data.m_electricityBuffer -= (ushort)electricityConsumption;
                }
            }
            else
            {
                heatingConsumption = 0;
            }
            if (!flag2)
            {
                data.m_electricityProblemTimer = 0;
            }
            if (flag != flag2)
            {
                Singleton <BuildingManager> .instance.UpdateBuildingColors(buildingID);
            }
            if (!flag3)
            {
                data.m_heatingProblemTimer = 0;
            }
            bool flag5 = false;
            int  num10 = sewageAccumulation;

            if (waterConsumption != 0)
            {
                if ((policies & DistrictPolicies.Services.WaterSaving) != DistrictPolicies.Services.None)
                {
                    waterConsumption = Mathf.Max(1, waterConsumption * 85 / 100);
                    if (sewageAccumulation != 0)
                    {
                        sewageAccumulation = Mathf.Max(1, sewageAccumulation * 85 / 100);
                    }
                    Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.PolicyCost, 32, this.m_info.m_class);
                }
                int num11;
                int a2;
                if (this.CanStockpileWater(buildingID, ref data, out num11, out a2))
                {
                    int num12 = num11 + waterConsumption * 2 - (int)data.m_waterBuffer;
                    if (num12 > 0)
                    {
                        int num13 = waterConsumption;
                        if ((int)data.m_waterBuffer < num11)
                        {
                            num13 += Mathf.Min(a2, num11 - (int)data.m_waterBuffer);
                        }
                        int num14 = Singleton <WaterManager> .instance.TryFetchWater(data.m_position, num13, num12, ref data.m_waterPollution);

                        data.m_waterBuffer += (ushort)num14;
                        if (num14 < num12 && num14 < num13)
                        {
                            flag5   = true;
                            problem = Notification.AddProblems(problem, Notification.Problem.Water);
                            if (data.m_waterProblemTimer < 64)
                            {
                                data.m_waterProblemTimer = 64;
                            }
                        }
                    }
                }
                else
                {
                    int num15 = waterConsumption * 2 - (int)data.m_waterBuffer;
                    if (num15 > 0)
                    {
                        int num16 = Singleton <WaterManager> .instance.TryFetchWater(data.m_position, waterConsumption, num15, ref data.m_waterPollution);

                        data.m_waterBuffer += (ushort)num16;
                    }
                }
                if ((int)data.m_waterBuffer < waterConsumption)
                {
                    flag5 = true;
                    data.m_waterProblemTimer = (byte)Mathf.Min(255, (int)(data.m_waterProblemTimer + 1));
                    if (data.m_waterProblemTimer >= 65)
                    {
                        num     = 0;
                        problem = Notification.AddProblems(problem, Notification.Problem.Water | Notification.Problem.MajorProblem);
                    }
                    else if (data.m_waterProblemTimer >= 3)
                    {
                        num    /= 2;
                        problem = Notification.AddProblems(problem, Notification.Problem.Water);
                    }
                    num10              = sewageAccumulation * (waterConsumption + (int)data.m_waterBuffer) / (waterConsumption << 1);
                    waterUsage         = (int)data.m_waterBuffer;
                    data.m_waterBuffer = 0;
                    if (Singleton <UnlockManager> .instance.Unlocked(ItemClass.Service.Water))
                    {
                        GuideController properties2 = Singleton <GuideManager> .instance.m_properties;
                        if (properties2 != null)
                        {
                            int publicServiceIndex2 = ItemClass.GetPublicServiceIndex(ItemClass.Service.Water);
                            int waterCapacity       = instance.m_districts.m_buffer[0].GetWaterCapacity();
                            int waterConsumption2   = instance.m_districts.m_buffer[0].GetWaterConsumption();
                            if (waterCapacity >= waterConsumption2)
                            {
                                Singleton <GuideManager> .instance.m_serviceNeeded[publicServiceIndex2].Activate(properties2.m_serviceNeeded2, ItemClass.Service.Water);
                            }
                            else
                            {
                                Singleton <GuideManager> .instance.m_serviceNeeded[publicServiceIndex2].Activate(properties2.m_serviceNeeded, ItemClass.Service.Water);
                            }
                        }
                    }
                }
                else
                {
                    num10               = sewageAccumulation;
                    waterUsage          = waterConsumption;
                    data.m_waterBuffer -= (ushort)waterConsumption;
                }
            }
            int num17;
            int b;

            if (this.CanStockpileWater(buildingID, ref data, out num17, out b))
            {
                int num18 = Mathf.Max(0, num17 + num10 * 2 - (int)data.m_sewageBuffer);
                if (num18 < num10)
                {
                    if (!flag5 && (data.m_problems & Notification.Problem.Water) == Notification.Problem.None)
                    {
                        flag5 = true;
                        data.m_waterProblemTimer = (byte)Mathf.Min(255, (int)(data.m_waterProblemTimer + 1));
                        if (data.m_waterProblemTimer >= 65)
                        {
                            num     = 0;
                            problem = Notification.AddProblems(problem, Notification.Problem.Sewage | Notification.Problem.MajorProblem);
                        }
                        else if (data.m_waterProblemTimer >= 3)
                        {
                            num    /= 2;
                            problem = Notification.AddProblems(problem, Notification.Problem.Sewage);
                        }
                    }
                    sewageUsage         = num18;
                    data.m_sewageBuffer = (ushort)(num17 + num10 * 2);
                }
                else
                {
                    sewageUsage          = num10;
                    data.m_sewageBuffer += (ushort)num10;
                }
                int num19 = num10 + Mathf.Max(num10, b);
                num18 = Mathf.Min(num19, (int)data.m_sewageBuffer);
                if (num18 > 0)
                {
                    int num20 = Singleton <WaterManager> .instance.TryDumpSewage(data.m_position, num19, num18);

                    data.m_sewageBuffer -= (ushort)num20;
                    if (num20 < num19 && num20 < num18 && !flag5 && (data.m_problems & Notification.Problem.Water) == Notification.Problem.None)
                    {
                        flag5   = true;
                        problem = Notification.AddProblems(problem, Notification.Problem.Sewage);
                        if (data.m_waterProblemTimer < 64)
                        {
                            data.m_waterProblemTimer = 64;
                        }
                    }
                }
            }
            else if (num10 != 0)
            {
                int num21 = Mathf.Max(0, num10 * 2 - (int)data.m_sewageBuffer);
                if (num21 < num10)
                {
                    if (!flag5 && (data.m_problems & Notification.Problem.Water) == Notification.Problem.None)
                    {
                        flag5 = true;
                        data.m_waterProblemTimer = (byte)Mathf.Min(255, (int)(data.m_waterProblemTimer + 1));
                        if (data.m_waterProblemTimer >= 65)
                        {
                            num     = 0;
                            problem = Notification.AddProblems(problem, Notification.Problem.Sewage | Notification.Problem.MajorProblem);
                        }
                        else if (data.m_waterProblemTimer >= 3)
                        {
                            num    /= 2;
                            problem = Notification.AddProblems(problem, Notification.Problem.Sewage);
                        }
                    }
                    sewageUsage         = num21;
                    data.m_sewageBuffer = (ushort)(num10 * 2);
                }
                else
                {
                    sewageUsage          = num10;
                    data.m_sewageBuffer += (ushort)num10;
                }
                num21 = Mathf.Min(num10 * 2, (int)data.m_sewageBuffer);
                if (num21 > 0)
                {
                    int num22 = Singleton <WaterManager> .instance.TryDumpSewage(data.m_position, num10 * 2, num21);

                    data.m_sewageBuffer -= (ushort)num22;
                }
            }
            if (!flag5)
            {
                data.m_waterProblemTimer = 0;
            }
            if (garbageAccumulation != 0)
            {
                int num23 = (int)(65535 - data.m_garbageBuffer);
                if (num23 < garbageAccumulation)
                {
                    num = 0;
                    data.m_garbageBuffer = (ushort)num23;
                }
                else
                {
                    //start edit
                    StormDrainAI stormDrainAI = data.Info.m_buildingAI as StormDrainAI;
                    if (stormDrainAI == null)
                    {
                        data.m_garbageBuffer += (ushort)garbageAccumulation;
                    }
                    else if (stormDrainAI.m_filter == false)
                    {
                        data.m_garbageBuffer += (ushort)garbageAccumulation;
                    }
                    else
                    {
                        int pollutantAccumulation = Hydraulics.removePollutants(buildingID, Hydraulics.getPollutants(buildingID));
                        data.m_garbageBuffer += (ushort)pollutantAccumulation;
                        //Debug.Log("[RF]CommonBuildingAI.handleCommonConsumption garbagebuffer = " + data.m_garbageBuffer.ToString());
                    }
                    //end edit
                }
            }
            if (garbageAccumulation != 0)
            {
                int num24 = (int)data.m_garbageBuffer;
                if (num24 >= 200 && Singleton <SimulationManager> .instance.m_randomizer.Int32(5u) == 0 && Singleton <UnlockManager> .instance.Unlocked(ItemClass.Service.Garbage))
                {
                    int num25 = 0;
                    int num26 = 0;
                    int num27 = 0;
                    int num28 = 0;
                    this.CalculateGuestVehicles(buildingID, ref data, TransferManager.TransferReason.Garbage, ref num25, ref num26, ref num27, ref num28);
                    num24 -= num27 - num26;
                    if (num24 >= 200)
                    {
                        TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                        offer.Priority = num24 / 1000;
                        offer.Building = buildingID;
                        offer.Position = data.m_position;
                        offer.Amount   = 1;
                        Singleton <TransferManager> .instance.AddOutgoingOffer(TransferManager.TransferReason.Garbage, offer);
                    }
                }
            }
            bool flag6;

            if (this.CanSufferFromFlood(out flag6))
            {
                float num29 = Singleton <TerrainManager> .instance.WaterLevel(VectorUtils.XZ(data.m_position));

                if (num29 > data.m_position.y)
                {
                    bool flag7 = num29 > data.m_position.y + Mathf.Max(4f, this.m_info.m_collisionHeight);
                    if ((!flag6 || flag7) && (data.m_flags & Building.Flags.Flooded) == Building.Flags.None && data.m_fireIntensity == 0)
                    {
                        DisasterManager instance2 = Singleton <DisasterManager> .instance;
                        ushort          num30     = instance2.FindDisaster <FloodBaseAI>(data.m_position);
                        if (num30 == 0)
                        {
                            DisasterInfo disasterInfo = DisasterManager.FindDisasterInfo <GenericFloodAI>();
                            if (disasterInfo != null && instance2.CreateDisaster(out num30, disasterInfo))
                            {
                                instance2.m_disasters.m_buffer[(int)num30].m_intensity      = 10;
                                instance2.m_disasters.m_buffer[(int)num30].m_targetPosition = data.m_position;
                                disasterInfo.m_disasterAI.StartNow(num30, ref instance2.m_disasters.m_buffer[(int)num30]);
                            }
                        }
                        if (num30 != 0)
                        {
                            InstanceID srcID = default(InstanceID);
                            InstanceID dstID = default(InstanceID);
                            srcID.Disaster = num30;
                            dstID.Building = buildingID;
                            Singleton <InstanceManager> .instance.CopyGroup(srcID, dstID);

                            DisasterInfo info = instance2.m_disasters.m_buffer[(int)num30].Info;
                            info.m_disasterAI.ActivateNow(num30, ref instance2.m_disasters.m_buffer[(int)num30]);
                            if ((instance2.m_disasters.m_buffer[(int)num30].m_flags & DisasterData.Flags.Significant) != DisasterData.Flags.None)
                            {
                                instance2.DetectDisaster(num30, false);
                                instance2.FollowDisaster(num30);
                            }
                        }
                        data.m_flags |= Building.Flags.Flooded;
                    }
                    if (flag7)
                    {
                        frameData.m_constructState = (byte)Mathf.Max(0, (int)frameData.m_constructState - 1088 / this.GetCollapseTime());
                        data.SetFrameData(Singleton <SimulationManager> .instance.m_currentFrameIndex, frameData);
                        InstanceID id = default(InstanceID);
                        id.Building = buildingID;
                        InstanceManager.Group group = Singleton <InstanceManager> .instance.GetGroup(id);

                        if (group != null)
                        {
                            ushort disaster = group.m_ownerInstance.Disaster;
                            if (disaster != 0)
                            {
                                DisasterData[] expr_D18_cp_0 = Singleton <DisasterManager> .instance.m_disasters.m_buffer;
                                ushort         expr_D18_cp_1 = disaster;
                                expr_D18_cp_0[(int)expr_D18_cp_1].m_collapsedCount = (ushort)(expr_D18_cp_0[(int)expr_D18_cp_1].m_collapsedCount + 1);
                            }
                        }
                        if (frameData.m_constructState == 0)
                        {
                            Singleton <InstanceManager> .instance.SetGroup(id, null);
                        }
                        data.m_levelUpProgress = 0;
                        data.m_fireIntensity   = 0;
                        data.m_garbageBuffer   = 0;
                        data.m_flags          |= Building.Flags.Collapsed;
                        num = 0;
                        this.RemovePeople(buildingID, ref data, 90);
                        this.BuildingDeactivated(buildingID, ref data);
                        if (this.m_info.m_hasParkingSpaces != VehicleInfo.VehicleType.None)
                        {
                            Singleton <BuildingManager> .instance.UpdateParkingSpaces(buildingID, ref data);
                        }
                        Singleton <BuildingManager> .instance.UpdateBuildingRenderer(buildingID, true);

                        Singleton <BuildingManager> .instance.UpdateBuildingColors(buildingID);

                        GuideController properties3 = Singleton <GuideManager> .instance.m_properties;
                        if (properties3 != null)
                        {
                            Singleton <BuildingManager> .instance.m_buildingFlooded.Deactivate(buildingID, false);

                            Singleton <BuildingManager> .instance.m_buildingFlooded2.Deactivate(buildingID, false);
                        }
                    }
                    else if (!flag6)
                    {
                        if ((data.m_flags & Building.Flags.RoadAccessFailed) == Building.Flags.None)
                        {
                            int num31 = 0;
                            int num32 = 0;
                            int num33 = 0;
                            int num34 = 0;
                            this.CalculateGuestVehicles(buildingID, ref data, TransferManager.TransferReason.FloodWater, ref num31, ref num32, ref num33, ref num34);
                            if (num31 == 0)
                            {
                                TransferManager.TransferOffer offer2 = default(TransferManager.TransferOffer);
                                offer2.Priority = 5;
                                offer2.Building = buildingID;
                                offer2.Position = data.m_position;
                                offer2.Amount   = 1;
                                Singleton <TransferManager> .instance.AddOutgoingOffer(TransferManager.TransferReason.FloodWater, offer2);
                            }
                        }
                        if (num29 > data.m_position.y + (float)ModSettings.BuildingFloodedTolerance / 100f)
                        {
                            num     = 0;
                            problem = Notification.AddProblems(problem, Notification.Problem.Flood | Notification.Problem.MajorProblem);
                        }
                        else if (num29 > data.m_position.y + (float)ModSettings.BuildingFloodingTolerance / 100f)
                        {
                            num    /= 2;
                            problem = Notification.AddProblems(problem, Notification.Problem.Flood);
                        }
                        GuideController properties4 = Singleton <GuideManager> .instance.m_properties;
                        if (properties4 != null)
                        {
                            if (Singleton <LoadingManager> .instance.SupportsExpansion(Expansion.NaturalDisasters) && Singleton <UnlockManager> .instance.Unlocked(UnlockManager.Feature.WaterPumping))
                            {
                                Singleton <BuildingManager> .instance.m_buildingFlooded2.Activate(properties4.m_buildingFlooded2, buildingID);
                            }
                            else
                            {
                                Singleton <BuildingManager> .instance.m_buildingFlooded.Activate(properties4.m_buildingFlooded, buildingID);
                            }
                        }
                    }
                }
                else if ((data.m_flags & Building.Flags.Flooded) != Building.Flags.None)
                {
                    InstanceID id2 = default(InstanceID);
                    id2.Building = buildingID;
                    Singleton <InstanceManager> .instance.SetGroup(id2, null);

                    data.m_flags &= ~Building.Flags.Flooded;
                }
            }
            byte district = instance.GetDistrict(data.m_position);

            instance.m_districts.m_buffer[(int)district].AddUsageData(electricityUsage, heatingUsage, waterUsage, sewageUsage);
            data.m_problems = problem;
            return(num);
        }
Esempio n. 14
0
        private void GetAmountAndCapacity(string name, out int amount, out int capacity, out bool modded)
        {
            CitizenManager citizenManager;
            NetManager     netManager;
            AudioManager   audioManager;
            VehicleManager vehicleManager;

            switch (name)
            {
            case "Areas":
                GameAreaManager gameAreaManager = Singleton <GameAreaManager> .instance;
                amount   = gameAreaManager.m_areaCount;
                capacity = gameAreaManager.m_maxAreaCount;
                modded   = gameAreaManager.m_maxAreaCount > 9 ? true : false;
                break;

            case "Buildings":
                BuildingManager buildingManager = Singleton <BuildingManager> .instance;
                amount   = buildingManager.m_buildingCount;
                capacity = BuildingManager.MAX_BUILDING_COUNT;
                modded   = false;
                break;

            case "Citizens":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_citizenCount;
                capacity       = CitizenManager.MAX_CITIZEN_COUNT;
                modded         = false;
                break;

            case "Citizen Units":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_unitCount;
                capacity       = CitizenManager.MAX_UNIT_COUNT;
                modded         = false;
                break;

            case "Citizen Instances":
                citizenManager = Singleton <CitizenManager> .instance;
                amount         = citizenManager.m_instanceCount;
                capacity       = CitizenManager.MAX_INSTANCE_COUNT;
                modded         = false;
                break;

            case "Disasters":
                DisasterManager disasterManager = Singleton <DisasterManager> .instance;
                amount   = disasterManager.m_disasterCount;
                capacity = DisasterManager.MAX_DISASTER_COUNT;
                modded   = false;
                break;

            case "Districts":
                DistrictManager districtManager = Singleton <DistrictManager> .instance;
                amount   = districtManager.m_districtCount;
                capacity = DistrictManager.MAX_DISTRICT_COUNT;
                modded   = false;
                break;

            case "Events":
                EventManager eventManager = Singleton <EventManager> .instance;
                amount   = eventManager.m_eventCount;
                capacity = EventManager.MAX_EVENT_COUNT;
                modded   = false;
                break;

            case "Loans":
                EconomyManager economyManager = Singleton <EconomyManager> .instance;
                amount   = economyManager.CountLoans();
                capacity = EconomyManager.MAX_LOANS;
                modded   = false;
                break;

            case "Net Segments":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_segmentCount;
                capacity   = NetManager.MAX_SEGMENT_COUNT;
                modded     = false;
                break;

            case "Net Nodes":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_nodeCount;
                capacity   = NetManager.MAX_NODE_COUNT;
                modded     = false;
                break;

            case "Net Lanes":
                netManager = Singleton <NetManager> .instance;
                amount     = netManager.m_laneCount;
                capacity   = NetManager.MAX_LANE_COUNT;
                modded     = false;
                break;

            case "Path Units":
                PathManager pathManager = Singleton <PathManager> .instance;
                amount   = pathManager.m_pathUnitCount;
                capacity = PathManager.MAX_PATHUNIT_COUNT;
                modded   = false;
                break;

            case "Props":
                PropManager propManager = Singleton <PropManager> .instance;
                amount   = propManager.m_propCount;
                capacity = PropManager.MAX_PROP_COUNT;
                modded   = false;
                break;

            case "Radio Channels":
                audioManager = Singleton <AudioManager> .instance;
                amount       = audioManager.m_radioChannelCount;
                capacity     = AudioManager.MAX_RADIO_CHANNEL_COUNT;
                modded       = false;
                break;

            case "Radio Contents":
                audioManager = Singleton <AudioManager> .instance;
                amount       = audioManager.m_radioContentCount;
                capacity     = AudioManager.MAX_RADIO_CONTENT_COUNT;
                modded       = false;
                break;

            case "Transport Lines":
                TransportManager transportManager = Singleton <TransportManager> .instance;
                amount   = transportManager.m_lineCount;
                capacity = TransportManager.MAX_LINE_COUNT;
                modded   = false;
                break;

            case "Trees":
                TreeManager treeManager = Singleton <TreeManager> .instance;
                amount   = treeManager.m_treeCount;
                capacity = treeManager.m_trees.m_size > 262144 ? (int)treeManager.m_trees.m_size : TreeManager.MAX_TREE_COUNT;
                modded   = treeManager.m_trees.m_size > 262144 ? true : false;
                break;

            case "Vehicles":
                vehicleManager = Singleton <VehicleManager> .instance;
                amount         = vehicleManager.m_vehicleCount;
                capacity       = VehicleManager.MAX_VEHICLE_COUNT;
                modded         = false;
                break;

            case "Vehicles Parked":
                vehicleManager = Singleton <VehicleManager> .instance;
                amount         = vehicleManager.m_parkedCount;
                capacity       = VehicleManager.MAX_PARKED_COUNT;
                modded         = false;
                break;

            case "Zoned Blocks":
                ZoneManager zoneManager = Singleton <ZoneManager> .instance;
                amount   = zoneManager.m_blockCount;
                capacity = ZoneManager.MAX_BLOCK_COUNT;
                modded   = false;
                break;

            default:
                amount   = 0;
                capacity = 0;
                modded   = false;
                break;
            }
        }