예제 #1
0
        public virtual string GetCitizenMessageInitialised()
        {
            string chosenMessage = "";

            if (m_eventInitialisedMessages.Count > 0)
            {
                if (m_eventInitialisedMessages.Count < 4)
                {
                    LoggingWrapper.LogWarning("Event " + m_eventData.m_eventName + " has less than 4 messages for the initialisation. This could get boring.");
                }

                int   days                  = (m_eventData.m_eventStartTime - CityEventManager.CITY_TIME).Days;
                float eventLength           = (float)GetEventLength();
                int   roundedEventLength    = Mathf.FloorToInt(eventLength);
                float eventLengthDifference = eventLength - roundedEventLength;

                string dayString         = days < 1 ? "less than a day" : days + " day" + (days > 1 ? "s" : "");
                string ticketString      = GetCapacity() + " tickets";
                string eventLengthString = (eventLengthDifference > 0.1 ? "more than " : "") + roundedEventLength + " hour" + (roundedEventLength > 1 ? "s" : "") + " long";

                int randomIndex = Singleton <SimulationManager> .instance.m_randomizer.Int32(1, m_eventInitialisedMessages.Count) - 1;

                chosenMessage = string.Format(m_eventInitialisedMessages[randomIndex], dayString, ticketString, eventLengthString);
            }

            LoggingWrapper.Log("Event chirped initialised \"" + chosenMessage + "\"");
            return(chosenMessage);
        }
예제 #2
0
        public bool CreateUserEvent(int ticketsAvailable, float entryCost, List <IncentiveOptionItem> incentives, DateTime startTime)
        {
            bool created = false;

            if (!CityEventManager.instance.EventStartsBetween(startTime, startTime.AddHours(GetEventLength()) - startTime))
            {
                LoggingWrapper.Log("Creating user event");

                m_eventData.m_eventStartTime  = startTime;
                m_eventData.m_eventFinishTime = startTime.AddHours(GetEventLength());
                m_eventData.m_entryCost       = entryCost;
                m_eventData.m_userTickets     = ticketsAvailable;
                m_eventData.m_userEvent       = true;

                LoggingWrapper.Log("Adding incentives");

                if (m_eventData.m_incentives != null)
                {
                    foreach (CityEventDataIncentives dataIncentive in m_eventData.m_incentives)
                    {
                        LoggingWrapper.Log("Adding incentive " + dataIncentive.name);

                        IncentiveOptionItem foundIncentive = incentives.Find(match => match.title == dataIncentive.name);

                        if (foundIncentive != null)
                        {
                            LoggingWrapper.Log("Setting up incentive " + dataIncentive.name);
                            dataIncentive.itemCount  = Mathf.RoundToInt(foundIncentive.sliderValue);
                            dataIncentive.returnCost = foundIncentive.returnCost;
                        }
                        else
                        {
                            LoggingWrapper.LogWarning("Couldn't find the IncentiveOptionItem that matches " + dataIncentive.name);
                        }
                    }

                    TakeInitialAmount();

                    created = true;
                }
                else
                {
                    LoggingWrapper.LogWarning("There are no incentives for " + m_eventData.m_eventName + ". Skipping");
                }
            }
            else
            {
                LoggingWrapper.LogWarning("Event clashes with another event.");
            }

            return(created);
        }
예제 #3
0
 private static void TranslateTab(UIButton tab, string translationKey)
 {
     if (CimTools.CimToolsHandler.CimToolBase.Translation.HasTranslation("OptionGroup_" + translationKey))
     {
         if (tab != null && translationKey != null && translationKey != "")
         {
             tab.text = CimTools.CimToolsHandler.CimToolBase.Translation.GetTranslation("OptionGroup_" + translationKey);
         }
         else
         {
             LoggingWrapper.LogWarning("Couldn't translate tab because important bits were null");
         }
     }
 }
예제 #4
0
        public void ClearDeadEvents()
        {
            bool clearAllEvents = false;

            CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.GetOptionValue("ClearEvents", ref clearAllEvents);

            if (clearAllEvents)
            {
                CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.SetOptionValue("ClearEvents", false);
            }

            if (m_nextEvents.Count > 0)
            {
                for (int index = 0; index < m_nextEvents.Count; ++index)
                {
                    bool      clearEvent = false || clearAllEvents;
                    CityEvent thisEvent  = m_nextEvents[index];

                    if ((thisEvent.m_eventData.m_eventEnded && (CITY_TIME - thisEvent.m_eventData.m_eventFinishTime).TotalHours > _eventEndBuffer))
                    {
                        clearEvent = true;

                        Debug.Log("Event finished");
                        LoggingWrapper.Log("Event finished");
                    }
                    else if (!thisEvent.m_eventData.m_eventStarted && !thisEvent.m_eventData.m_eventEnded && !thisEvent.EventStartsWithin(24 * 7))
                    {
                        clearEvent = true;

                        Debug.LogWarning("Event had more than a week of buffer. Removed.");
                        LoggingWrapper.LogWarning("Event had more than a week of buffer. Removed.");
                    }

                    if (clearEvent)
                    {
                        m_nextEvents.RemoveAt(index);
                        --index;
                    }
                    else
                    {
                        m_nextEvents[index].Update();
                    }
                }
            }
        }
예제 #5
0
        public virtual string GetCitizenMessageEnded()
        {
            string chosenMessage = "";

            if (m_eventEndedMessages.Count > 0)
            {
                if (m_eventEndedMessages.Count < 4)
                {
                    LoggingWrapper.LogWarning("Event " + m_eventData.m_eventName + " has less than 4 messages for the end. This could get boring.");
                }

                int randomIndex = Singleton <SimulationManager> .instance.m_randomizer.Int32(1, m_eventEndedMessages.Count) - 1;

                chosenMessage = m_eventEndedMessages[randomIndex];
            }

            LoggingWrapper.Log("Event chirped ended \"" + chosenMessage + "\"");
            return(chosenMessage);
        }
예제 #6
0
        public void Update()
        {
            SimulationManager _simulationManager = Singleton <SimulationManager> .instance;
            float             currentHour        = _simulationManager.m_currentDayTimeHour;

            if (currentHour < 1D && m_lastDayTimeHour > 23D)
            {
                m_baseTime = m_baseTime.AddDays(1D);
                LoggingWrapper.Log("New day " + m_baseTime.ToShortDateString() + " " + m_baseTime.ToShortTimeString());

                Data.CityTime.year  = m_baseTime.Year;
                Data.CityTime.month = m_baseTime.Month;
                Data.CityTime.day   = m_baseTime.Day;

                Debug.Log("Current date: " + m_baseTime.ToLongTimeString() + ", " + m_baseTime.ToShortDateString());
            }

            if (currentHour > 23D && m_lastDayTimeHour < 1D)
            {
                LoggingWrapper.LogWarning("Time jumped back, but it was prevented.");
            }
            else
            {
                m_lastDayTimeHour = currentHour;
            }

            CITY_TIME = m_baseTime.AddHours(currentHour);

            if (ExperimentsToggle.AllowForcedXMLEvents)
            {
                m_xmlEvents.Clear();
                LoadEvents();
                ExperimentsToggle.AllowForcedXMLEvents = false;
            }

            UpdateEvents();
        }
예제 #7
0
        private static void loadSettingsFromSaveFile()
        {
            CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Safely loading saved data.");

            bool legacy = false;

            if (!CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.LoadOptions())
            {
                CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Loading data from legacy XML file.");
                CimToolsRushHour.Legacy.File.ExportOptionBase.OptionError error = CimTools.CimToolsHandler.LegacyCimToolBase.XMLFileOptions.Load();
                legacy = error == CimToolsRushHour.Legacy.File.ExportOptionBase.OptionError.NoError;

                if (legacy == false)
                {
                    CimTools.CimToolsHandler.CimToolBase.NamedLogger.LogError("Couldn't load up legacy data. " + error.ToString());
                }
            }
            else
            {
                CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Loading data from normal XML file.");
            }

            safelyGetValue("RandomEvents", ref Experiments.ExperimentsToggle.EnableRandomEvents, legacy);
            safelyGetValue("TeamColourOnBar", ref Experiments.ExperimentsToggle.TeamColourOnBar, false);
            safelyGetValue("DisableGameEvents", ref Experiments.ExperimentsToggle.DisableIngameEvents, false);
            safelyGetValue("AvailableInScenarios", ref Experiments.ExperimentsToggle.EnableInScenarios, false);

            safelyGetValue("ForceRandomEvents", ref Experiments.ExperimentsToggle.ForceEventToHappen, legacy);
            safelyGetValue("UseImprovedCommercial1", ref Experiments.ExperimentsToggle.ImprovedDemand, legacy);
            safelyGetValue("UseImprovedResidential", ref Experiments.ExperimentsToggle.ImprovedResidentialDemand, legacy);
            safelyGetValue("GhostMode", ref Experiments.ExperimentsToggle.GhostMode, legacy);
            safelyGetValue("Weekends1", ref Experiments.ExperimentsToggle.EnableWeekends, legacy);
            safelyGetValue("BetterParking", ref Experiments.ExperimentsToggle.ImprovedParkingAI, legacy);
            safelyGetValue("ParkingSearchRadius", ref Experiments.ExperimentsToggle.ParkingSearchRadius, legacy);
            safelyGetValue("LunchRush", ref Experiments.ExperimentsToggle.SimulateLunchTimeRushHour, legacy);
            safelyGetValue("SearchLocally", ref Experiments.ExperimentsToggle.AllowLocalBuildingSearch, false);
            safelyGetValue("LocalSearchChance", ref Experiments.ExperimentsToggle.LocalBuildingPercentage, false);

            safelyGetValue("TwentyFourHourClock", ref Experiments.ExperimentsToggle.NormalClock, legacy);
            safelyGetValue("SlowTimeProgression", ref Experiments.ExperimentsToggle.SlowTimeProgression, legacy);
            safelyGetValue("SlowTimeProgressionSpeed", ref Experiments.ExperimentsToggle.TimeMultiplier, legacy);
            safelyGetValue("SlowTimeProgressionSpeedNight", ref Experiments.ExperimentsToggle.TimeMultiplierNight, legacy);
            safelyGetValue("SunriseHour", ref SimulationManager.SUNRISE_HOUR, legacy);
            safelyGetValue("SunsetHour", ref SimulationManager.SUNSET_HOUR, legacy);
            safelyGetValue("DateFormat", ref Experiments.ExperimentsToggle.DateFormat, legacy);

            safelyGetValue("SchoolStartTime2", ref Chances.m_startSchoolHour, legacy);
            safelyGetValue("SchoolStartTimeVariance2", ref Chances.m_minSchoolHour, legacy);
            safelyGetValue("SchoolEndTime2", ref Chances.m_endSchoolHour, legacy);
            safelyGetValue("SchoolEndTimeVariance2", ref Chances.m_maxSchoolHour, legacy);
            safelyGetValue("SchoolDurationMinimum2", ref Chances.m_minSchoolDuration, legacy);

            safelyGetValue("WorkStartTime2", ref Chances.m_startWorkHour, legacy);
            safelyGetValue("WorkStartTimeVariance2", ref Chances.m_minWorkHour, legacy);
            safelyGetValue("WorkEndTime2", ref Chances.m_endWorkHour, legacy);
            safelyGetValue("WorkEndTimeVariance2", ref Chances.m_maxWorkHour, legacy);
            safelyGetValue("WorkDurationMinimum2", ref Chances.m_minWorkDuration, legacy);

            safelyGetValue("DebugLog", ref Experiments.ExperimentsToggle.WriteDebugLog, false);
            safelyGetValue("PrintMonuments", ref Experiments.ExperimentsToggle.PrintAllMonuments, legacy);
            safelyGetValue("ForceXMLEnabled", ref Experiments.ExperimentsToggle.AllowForcedXMLEvents, legacy);
            safelyGetValue("FixInactiveBuildings", ref Experiments.ExperimentsToggle.AllowActiveCommercialFix, legacy);

            string language = "English";

            safelyGetValue("Language", ref language, legacy);

            List <string> validLanguages = CimTools.CimToolsHandler.CimToolBase.Translation.GetLanguageIDsFromName(language);

            if (validLanguages.Count > 0)
            {
                CimTools.CimToolsHandler.CimToolBase.Translation.TranslateTo(validLanguages[0]);

                if (validLanguages.Count > 1)
                {
                    LoggingWrapper.LogWarning("Language " + language + " has more than one unique ID associated with it. Picked the first one.");
                }
            }
            else
            {
                LoggingWrapper.LogError("Could not switch to language " + language + ", as there are no valid languages with that name!");
            }

            bool loadEventEditor = false;

            safelyGetValue("EditEvents", ref loadEventEditor, legacy);

            if (loadEventEditor)
            {
                try
                {
                    string modPath = CimTools.CimToolsHandler.CimToolBase.Path.GetModPath();

                    if (modPath != null && modPath != "")
                    {
                        Process.Start(modPath + Path.DirectorySeparatorChar + "EventEditor.exe");
                        CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.SetOptionValue("EditEvents", false);
                    }
                    else
                    {
                        UnityEngine.Debug.LogError("Rush Hour: Couldn't find the event editor!");
                    }
                }
                catch
                {
                    UnityEngine.Debug.LogError("Rush Hour: Couldn't load the event editor!");
                }
            }

            CimTools.CimToolsHandler.CimToolBase.Translation.RefreshLanguages();
        }
예제 #8
0
        private void LoadEvents()
        {
            PrintMonuments();

            string modPath = CimTools.CimToolsHandler.CimToolBase.Path.GetModPath();

            if (modPath != null && modPath != "" && Directory.Exists(modPath))
            {
                DirectoryInfo parentPath      = Directory.GetParent(modPath);
                string        searchDirectory = parentPath.FullName;

                string[] allModDirectories = Directory.GetDirectories(searchDirectory);

                foreach (string modDirectory in allModDirectories)
                {
                    if (Directory.Exists(modDirectory))
                    {
                        string rushHourDirectory = modDirectory + System.IO.Path.DirectorySeparatorChar + "RushHour Events";

                        if (Directory.Exists(rushHourDirectory))
                        {
                            string[] eventFiles = Directory.GetFiles(rushHourDirectory, "*.xml");

                            foreach (string foundEventFile in eventFiles)
                            {
                                if (File.Exists(foundEventFile))
                                {
                                    try
                                    {
                                        XmlSerializer eventDeserialiser = new XmlSerializer(typeof(CityEventXml));
                                        TextReader    eventReader       = new StreamReader(foundEventFile);

                                        CityEventXml loadedXmlEvent = eventDeserialiser.Deserialize(eventReader) as CityEventXml;

                                        if (loadedXmlEvent != null)
                                        {
                                            m_xmlEvents.Add(loadedXmlEvent);

                                            if (ExperimentsToggle.AllowForcedXMLEvents)
                                            {
                                                foreach (CityEventXmlContainer individualEvent in loadedXmlEvent._containedEvents)
                                                {
                                                    if (individualEvent._force)
                                                    {
                                                        m_forcedEvent = individualEvent;
                                                        LoggingWrapper.Log("Forcing event " + individualEvent._name);
                                                    }
                                                }
                                            }

                                            LoggingWrapper.Log("Successfully found and loaded " + foundEventFile);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        LoggingWrapper.LogError(ex.Message + "\n" + ex.StackTrace);
                                    }
                                }
                            }
                        }
                        else
                        {
                            LoggingWrapper.Log("No events directory in " + rushHourDirectory);
                        }
                    }
                    else
                    {
                        LoggingWrapper.LogWarning("Directory " + modDirectory + " doesn't exist.");
                    }
                }
            }
            else
            {
                LoggingWrapper.LogWarning("Could not find mod path at " + modPath ?? "null");
            }
        }