Ejemplo n.º 1
0
        /// <summary>
        /// Uninitializes data.
        /// </summary>
        private void DeInitialize()
        {
            Global.LevelLoaded = false;

            Log.Info(this, "DeInitialize");

            Global.DeInitialize();
            Detours.Dispose();
            Global.DisposeHandlers();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when level is unloading.
        /// </summary>
        public override void OnLevelUnloading()
        {
            Log.Debug(this, "OnLevelUnloading", "End");

            try
            {
                Detours.LogCounts();
                this.DeInitialize();
            }
            catch (Exception ex)
            {
                Log.Error(this, "OnLevelUnloading", ex);
            }
            finally
            {
                Log.Debug(this, "OnLevelUnloading", "Base");
                base.OnLevelUnloading();
            }

            Log.Debug(this, "OnLevelUnloading", "End");
            Log.FlushBuffer();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when game updates.
        /// </summary>
        /// <param name="realTimeDelta">The real time delta.</param>
        /// <param name="simulationTimeDelta">The simulation time delta.</param>
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (this.isBroken)
            {
                return;
            }

            try
            {
                if (this.threadingManager.simulationPaused)
                {
                    if (!this.called || (Global.CurrentFrame - Log.LastFlush >= Global.LogFlushDelay))
                    {
                        Log.FlushBuffer();
                    }

                    return;
                }

                Global.SimulationTime += simulationTimeDelta;

                uint simulationFrame = this.threadingManager.simulationFrame;

                if (Global.CurrentFrame == simulationFrame)
                {
                    return;
                }

                if (Global.CurrentFrame == 0)
                {
                    Global.LogDebugLists();
                }

                if (Global.CurrentFrame == 0 && simulationFrame > 0)
                {
                    this.lastDebugListLog = simulationFrame;
                }

                if (this.started && Detours.InitNeeded)
                {
                    Detours.Initialize();
                }

                Global.CurrentFrame = simulationFrame;

                if (Global.ServiceProblems != null && Global.CurrentFrame - Global.ServiceProblems.LastUpdate >= Global.ProblemUpdateDelay)
                {
                    Global.ServiceProblems.Update();
                }

                if (Global.Settings.DispatchAnyVehicles || Global.Settings.AutoEmptyAnyBuildings)
                {
                    // Do building stuff.
                    if (Global.Buildings != null)
                    {
                        // Update buildings.
                        Global.Buildings.Update();
                    }

                    // Do vehicle based stuff.
                    if (Global.Vehicles != null)
                    {
                        // Update vehicles.
                        Global.Vehicles.Update();
                    }

                    // Do building based stuff.
                    if (Global.Buildings != null)
                    {
                        // Dispatch hearses.
                        if (Global.Settings.DeathCare.DispatchVehicles && Global.HearseDispatcher != null)
                        {
                            Global.HearseDispatcher.Dispatch();
                        }

                        // Dispatch garbage trucks;
                        if (Global.Settings.Garbage.DispatchVehicles && Global.GarbageTruckDispatcher != null)
                        {
                            Global.GarbageTruckDispatcher.Dispatch();
                        }

                        // Dispatch ambulances.
                        if (Global.Settings.HealthCare.DispatchVehicles && Global.AmbulanceDispatcher != null)
                        {
                            Global.AmbulanceDispatcher.Dispatch();
                        }
                    }

                    if (Global.TransferOffersCleaningNeeded || Global.CurrentFrame - this.lastTransferOffersClean > Global.CleanTransferOffersDelay)
                    {
                        if (Global.CleanTransferOffers)
                        {
                            TransferManagerHelper.CleanTransferOffers();
                        }

                        this.lastTransferOffersClean        = Global.CurrentFrame;
                        Global.TransferOffersCleaningNeeded = false;
                    }
                }

                if (Global.CurrentFrame - this.lastDebugListLog >= Global.DebugListLogDelay)
                {
                    this.lastDebugListLog = Global.CurrentFrame;

                    Global.LogDebugLists();
                }
                else if (!this.started || (Global.CurrentFrame - Log.LastFlush >= Global.LogFlushDelay))
                {
                    Log.FlushBuffer();
                }

                this.started = true;
                if (this.exceptionCount > 0)
                {
                    this.exceptionCount--;
                }
            }
            catch (Exception ex)
            {
                this.exceptionCount++;
                if (this.exceptionCount > MaxExceptionCount)
                {
                    try
                    {
                        Detours.Revert();
                    }
                    catch (Exception rex)
                    {
                        Log.Error(this, "OnUpdate", rex);
                    }

                    this.isBroken = true;
                }

                Log.Error(this, "OnUpdate", ex);
            }
            finally
            {
                this.called = true;
                base.OnUpdate(realTimeDelta, simulationTimeDelta);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method overriding GarbageTruckAI.TryCollectGarbage.
        /// </summary>
        /// <param name="garbageTruckAI">The garbage truck AI instance.</param>
        /// <param name="vehicleID">The vehicle identifier.</param>
        /// <param name="vehicleData">The vehicle data.</param>
        /// <param name="frameData">The frame data.</param>
        /// <param name="buildingID">The building identifier.</param>
        /// <param name="building">The building.</param>
        private static void GarbageTruckAI_TryCollectGarbage_Override(GarbageTruckAI garbageTruckAI, ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ushort buildingID, ref Building building)
        {
            try
            {
                Tries++;

                if (garbageTruckAI == null || vehicleID == 0 || buildingID == 0)
                {
                    return;
                }

                if (vehicleData.m_targetBuilding == 0)
                {
                    GarbageTruckAI_TryCollectGarbage_Original(garbageTruckAI, vehicleID, ref vehicleData, ref frameData, buildingID, ref building);
                    return;
                }

                if (vehicleData.m_targetBuilding == buildingID)
                {
                    GarbageTruckAI_TryCollectGarbage_Original(garbageTruckAI, vehicleID, ref vehicleData, ref frameData, buildingID, ref building);
                    return;
                }

                int freeCapacity = garbageTruckAI.m_cargoCapacity - vehicleData.m_transferSize;
                if (freeCapacity < 0)
                {
                    freeCapacity = 0;
                }

                int buildingMax;
                int buildingAmount;
                building.Info.m_buildingAI.GetMaterialAmount(buildingID, ref building, (TransferManager.TransferReason)vehicleData.m_transferType, out buildingAmount, out buildingMax);

                if (buildingAmount > freeCapacity)
                {
                    Limitations++;

                    return;
                }

                Building[] buildings      = Singleton <BuildingManager> .instance.m_buildings.m_buffer;
                Building   targetBuilding = buildings[vehicleData.m_targetBuilding];

                int targetBuildingAmount;
                targetBuilding.Info.m_buildingAI.GetMaterialAmount(vehicleData.m_targetBuilding, ref building, (TransferManager.TransferReason)vehicleData.m_transferType, out targetBuildingAmount, out buildingMax);

                if (buildingAmount + targetBuildingAmount > freeCapacity)
                {
                    Limitations++;
                    return;
                }

                GarbageTruckAI_TryCollectGarbage_Original(garbageTruckAI, vehicleID, ref vehicleData, ref frameData, buildingID, ref building);
            }
            catch (Exception ex)
            {
                Log.Error(typeof(GarbageTruckAITryCollectGarbageDetour), "GarbageTruckAI_TryCollectGarbage_Override", ex);

                Detours.Abort(Detours.Methods.GarbageTruckAI_TryCollectGarbage);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Logs the debug lists.
        /// </summary>
        /// <param name="initializing">if set to <c>true</c> level is loading.</param>
        /// <param name="deInitializing">if set to <c>true</c> level is unloading.</param>
        private static void LogDebugLists(bool initializing, bool deInitializing)
        {
            try
            {
                bool flush = false;

                if (initializing)
                {
                    if (Log.LogDebugLists)
                    {
                        Log.Debug(typeof(Global), "LogDebugLists", "Initializing");
                    }
                }
                else if (deInitializing)
                {
                    if (Log.LogDebugLists)
                    {
                        Log.Debug(typeof(Global), "LogDebugLists", "DeInitializing");
                    }
                }
                else if (CurrentFrame == 0)
                {
                    if (Log.LogDebugLists)
                    {
                        Log.Debug(typeof(Global), "LogDebugLists", "Started");

                        Detours.LogInfo();
                        TransferManagerHelper.LogInfo();
                        VehicleHelper.DebugListLog();
                        BuildingHelper.DebugListLog();
                        TransferManagerHelper.DebugListLog();

                        flush = true;
                    }
                }
                else if (CurrentFrame > 0)
                {
                    if (Log.LogDebugLists)
                    {
                        Log.Debug(typeof(Global), "LogDebugLists", "Running");

                        if (Global.Buildings != null)
                        {
                            Global.Buildings.DebugListLogBuildings();
                        }

                        if (Global.Vehicles != null)
                        {
                            Global.Vehicles.DebugListLogVehicles();
                        }

                        TransferManagerHelper.DebugListLog();
                        flush = true;
                    }

                    if (Global.ServiceProblems != null)
                    {
                        Global.ServiceProblems.DebugListLogServiceProblems();
                        flush = true;
                    }
                }

                if (flush)
                {
                    Log.FlushBuffer();
                }
            }
            catch (Exception ex)
            {
                Log.Error(typeof(Global), "LogDebugLists", ex);
            }
        }