Exemplo n.º 1
0
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated)
            {
                return;
            }

            if (!_helper.GameLoaded)
            {
                return;
            }

            try
            {
                if (!_initialized)
                {
                    if (!Helper.IsOverwatched())
                    {
                        _helper.NotifyPlayer("Skylines Overwatch not found. Terminating...");
                        _terminated = true;

                        return;
                    }

                    SkylinesOverwatch.Settings.Instance.Enable.BuildingMonitor = true;
                    SkylinesOverwatch.Settings.Instance.Enable.VehicleMonitor  = true;

                    _cemeteries      = new Dictionary <ushort, Cemetery>();
                    _master          = new Dictionary <ushort, Claimant>();
                    _stopped         = new HashSet <ushort>();
                    _updated         = new HashSet <ushort>();
                    _oldtargets      = new Dictionary <ushort, HashSet <ushort> >();
                    _lasttargets     = new Dictionary <ushort, ushort>();
                    _lastchangetimes = new Dictionary <ushort, DateTime>();
                    _PathfindCount   = new Dictionary <ushort, ushort>();

                    RedirectionHelper.RedirectCalls(Loader.m_redirectionStates, typeof(HearseAI), typeof(CustomHearseAI), "SetTarget", 3);

                    _initialized = true;

                    _helper.NotifyPlayer("Initialized");
                }
                else if (!_baselined)
                {
                    CreateBaseline();
                }
                else
                {
                    ProcessNewCemeteries();
                    ProcessRemovedCemeteries();

                    ProcessNewPickups();

                    if (!SimulationManager.instance.SimulationPaused && Identity.ModConf.MinimizeHearses)
                    {
                        ProcessIdleHearses();
                    }
                    UpdateHearses();
                    _lastProcessedFrame = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                }
            }
            catch (Exception e)
            {
                string error = String.Format("Failed to {0}\r\n", !_initialized ? "initialize" : "update");
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                _helper.Log(error);

                if (!_initialized)
                {
                    _terminated = true;
                }
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }