/// <summary>
        /// Checks for mod conflicts and displays user notification if necessary.
        /// </summary>
        /// <returns>True if conflict found, false otherwise</returns>
        public bool CheckConflicts()
        {
            bool   conflictDetected = false;
            string conflictName     = string.Empty;


            // Check for conflicting mods.
            if (IsModEnabled(654707599ul))
            {
                // Original WG Citizen Lifecycle Rebalance.
                conflictDetected = true;
                conflictName     = "WG Citizen Lifecycle Rebalance";
                ErrorNotification.messageText = "Original WG Citizen Lifecycle Rebalance mod detected - Lifecycle Rebalance Revisited is shutting down to protect your game.  Only ONE of these mods can be enabled at the same time; please unsubscribe from WG Citizen Lifecycle Rebalance, which is now deprecated!";
            }
            else if (IsModInstalled(1372431101ul))
            {
                // Painter mod detected.
                conflictDetected = true;
                conflictName     = "Painter";
                ErrorNotification.messageText = "The old Painter mod causes problems with the Harmony libraries used by this mod, resulting in random errors.  Please UNSUBSCRIBE from Painter (merely disabling is NOT sufficient); the Repaint mod can be used as a replacement.";
            }
            else if (IsModInstalled("VanillaGarbageBinBlocker"))
            {
                // Garbage Bin Conroller mod detected.
                conflictDetected = true;
                conflictName     = "Garbage Bin Controller";
                Debugging.Message("Garbage Bin Controller mod detected - Lifecycle Rebalance Revisited exiting");
                ErrorNotification.messageText = "The Garbage Bin Controller mod causes problems with the Harmony libraries used by this mod, resulting in random errors.  Please UNSUBSCRIBE from Garbage Bin Controller (merely disabling is NOT sufficient).";
            }
            else if (IsModInstalled(2097938060) && IsModInstalled(2027161563))
            {
                // Beta and main version simultaneously installed.
                conflictDetected = true;
                conflictName     = "Beta";
                ErrorNotification.messageText = "Lifecycle Rebalance Revisited: both Beta and production versions detected.  Lifecycle Rebalance Revisited is shutting down to protect your game.  Please only subscribe to one of these at a time.";
            }

            // Mod conflict was detected.  Notify the user.
            if (conflictDetected)
            {
                // Show error notification.  Message text has already been set above.
                ErrorNotification notification = new ErrorNotification();
                notification.Create();
                ErrorNotification.headerText = "Mod conflict detected!";
                notification.Show();

                Debugging.Message("incompatible " + conflictName + " mod detected.  Shutting down");
            }

            return(conflictDetected);
        }
        /// <summary>
        /// Called by the game when level loading is complete.
        /// </summary>
        /// <param name="mode">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnLevelLoaded(LoadMode mode)
        {
            // Don't do anything if not in game.
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
            {
                Debugging.Message("not loading into game; exiting");
                return;
            }

            // Don't do anything if we've already been here.
            if (!isModCreated)
            {
                // Check for mod conflicts.
                ModConflicts modConflicts = new ModConflicts();
                if (modConflicts.CheckConflicts())
                {
                    // Conflict detected.  Unpatch everything before exiting without doing anything further.
                    Patcher.UnpatchAll();
                    return;
                }

                Debugging.Message("v" + LifecycleRebalance.Version + " loading");

                // Wait for Harmony if it hasn't already happened.
                if (!Patcher.patched)
                {
                    // Set timeout counter, just in case.
                    DateTime startTime = DateTime.Now;

                    try
                    {
                        Debugging.Message("waiting for Harmony");
                        while (!Patcher.patched)
                        {
                            if (CitiesHarmony.API.HarmonyHelper.IsHarmonyInstalled)
                            {
                                Patcher.PatchAll();
                                break;
                            }

                            // Three minutes should be sufficient wait.
                            if (DateTime.Now > startTime.AddMinutes(3))
                            {
                                throw new TimeoutException("Harmony loading timeout: " + startTime.ToString() + " : " + DateTime.Now.ToString());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.Message("Harmony loading exception");
                        Debugging.LogException(e);

                        // Show error notification to user.
                        ErrorNotification notification = new ErrorNotification();
                        notification.Create();
                        ErrorNotification.headerText  = "Harmony loading error!";
                        ErrorNotification.messageText = "Lifecycle Rebalance Revisited can't load properly because the required Harmony mod dependency didn't load.  In most cases, a simple game restart should be enough to fix this.\r\n\r\nIf this notification persists, please manually subscribe to the Harmony mod on the Steam workshop (if you're already subscribed, try unsubscribing and re-subscribing) and restart your game again.";
                        notification.Show();
                        return;
                    }
                }

                Debugging.Message("Harmony ready, proceeding");

                // Set flag.
                isModCreated = true;

                // Load and apply mod settings (configuration file loaded above).
                settingsFile = Configuration <SettingsFile> .Load();

                ModSettings.VanillaCalcs      = settingsFile.UseVanilla;
                ModSettings.LegacyCalcs       = settingsFile.UseLegacy;
                ModSettings.CustomRetirement  = settingsFile.CustomRetirement;
                ModSettings.RetirementYear    = settingsFile.RetirementYear;
                ModSettings.UseTransportModes = settingsFile.UseTransportModes;
                ModSettings.randomImmigrantEd = settingsFile.RandomImmigrantEd;
                Debugging.UseDeathLog         = settingsFile.LogDeaths;
                Debugging.UseImmigrationLog   = settingsFile.LogImmigrants;
                Debugging.UseTransportLog     = settingsFile.LogTransport;
                Debugging.UseSicknessLog      = settingsFile.LogSickness;

                // Apply sickness probabilities.
                CalculateSicknessProbabilities();

                // Report status and any debugging messages.
                Debugging.Message("death logging " + (Debugging.UseDeathLog ? "enabled" : "disabled") + ", immigration logging " + (Debugging.UseImmigrationLog ? "enabled" : "disabled") + ", transportation logging " + (Debugging.UseTransportLog ? "enabled" : "disabled"));
                Debugging.ReleaseBuffer();

                // Prime Threading.counter to continue from frame index.
                int temp = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex / 4096u);
                Threading.counter = temp % DataStore.lifeSpanMultiplier;
                try
                {
                    WG_XMLBaseVersion xml = new XML_VersionTwo();
                    xml.writeXML(currentFileLocation);
                }
                catch (Exception e)
                {
                    Debugging.LogException(e);
                }

                // Set up options panel event handler.
                OptionsPanel.OptionsEventHook();

                Debugging.Message("successfully loaded");

                // Check if we need to display update notification.
                if (settingsFile.NotificationVersion != 3)
                {
                    // No update notification "Don't show again" flag found; show the notification.
                    UpdateNotification notification = new UpdateNotification();
                    notification.Create();
                    notification.Show();
                }
            }
        }