diff --git a/src/RealTime/Config/RealTimeConfig.cs b/src/RealTime/Config/RealTimeConfig.cs index dc902b1c..15aa7f9f 100644 --- a/src/RealTime/Config/RealTimeConfig.cs +++ b/src/RealTime/Config/RealTimeConfig.cs @@ -137,30 +137,37 @@ public RealTimeConfig() public uint OnTimeQuota { get; set; } /// <summary> - /// Gets or sets the daytime hour when the earliest event on a week day can start. + /// Gets or sets a value indicating whether the custom events are enabled. /// </summary> [ConfigItem("3Events", 0)] + [ConfigItemCheckBox] + public bool AreEventsEnabled { get; set; } + + /// <summary> + /// Gets or sets the daytime hour when the earliest event on a week day can start. + /// </summary> + [ConfigItem("3Events", 1)] [ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)] public float EarliestHourEventStartWeekday { get; set; } /// <summary> /// Gets or sets the daytime hour when the latest event on a week day can start. /// </summary> - [ConfigItem("3Events", 1)] + [ConfigItem("3Events", 2)] [ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)] public float LatestHourEventStartWeekday { get; set; } /// <summary> /// Gets or sets the daytime hour when the earliest event on a Weekend day can start. /// </summary> - [ConfigItem("3Events", 2)] + [ConfigItem("3Events", 3)] [ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)] public float EarliestHourEventStartWeekend { get; set; } /// <summary> /// Gets or sets the daytime hour when the latest event on a Weekend day can start. /// </summary> - [ConfigItem("3Events", 3)] + [ConfigItem("3Events", 4)] [ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)] public float LatestHourEventStartWeekend { get; set; } @@ -297,6 +304,7 @@ public void ResetToDefaults() LocalBuildingSearchQuota = 60; OnTimeQuota = 80; + AreEventsEnabled = true; EarliestHourEventStartWeekday = 16f; LatestHourEventStartWeekday = 20f; EarliestHourEventStartWeekend = 8f; diff --git a/src/RealTime/Events/RealTimeEventManager.cs b/src/RealTime/Events/RealTimeEventManager.cs index 484f49bb..89cc9b83 100644 --- a/src/RealTime/Events/RealTimeEventManager.cs +++ b/src/RealTime/Events/RealTimeEventManager.cs @@ -228,7 +228,7 @@ public void ProcessEvents() lastProcessed = timeInfo.Now; Update(); - if (upcomingEvents.Count >= MaximumEventsCount) + if (upcomingEvents.Count >= MaximumEventsCount || !config.AreEventsEnabled) { return; } @@ -318,15 +318,14 @@ private void Update() foreach (ushort eventId in eventManager.GetUpcomingEvents(timeInfo.Now, timeInfo.Now.AddDays(1))) { eventManager.TryGetEventInfo(eventId, out ushort buildingId, out DateTime startTime, out float duration, out float ticketPrice); - if (upcomingEvents.Concat(new[] { activeEvent }) .OfType<VanillaEvent>() - .Any(e => e.BuildingId == buildingId && e.StartTime == startTime)) + .Any(e => e.BuildingId == buildingId && e.StartTime.Date == startTime.Date)) { continue; } - var newEvent = new VanillaEvent(duration, ticketPrice); + var newEvent = new VanillaEvent(eventId, duration, ticketPrice); newEvent.Configure(buildingId, buildingManager.GetBuildingName(buildingId), startTime); eventsChanged = true; Log.Debug(timeInfo.Now, $"Vanilla event registered for {newEvent.BuildingId}, start time {newEvent.StartTime}, end time {newEvent.EndTime}"); @@ -404,10 +403,27 @@ private bool RemoveCanceledEvents() private bool MustCancelEvent(ICityEvent cityEvent) { + if (!config.AreEventsEnabled && cityEvent is RealTimeCityEvent) + { + return true; + } + Building.Flags flags = Building.Flags.Abandoned | Building.Flags.BurnedDown | Building.Flags.Collapsed | Building.Flags.Deleted | Building.Flags.Demolishing | Building.Flags.Evacuating | Building.Flags.Flooded; - return buildingManager.BuildingHasFlags(cityEvent.BuildingId, flags, true); + if (buildingManager.BuildingHasFlags(cityEvent.BuildingId, flags, true)) + { + return true; + } + + if (cityEvent is VanillaEvent vanillaEvent) + { + EventData.Flags eventFlags = eventManager.GetEventFlags(vanillaEvent.EventId); + return eventFlags == 0 + || (eventFlags & (EventData.Flags.Cancelled | EventData.Flags.Deleted | EventData.Flags.Expired)) != 0; + } + + return false; } private void CreateRandomEvent(ushort buildingId) diff --git a/src/RealTime/Events/VanillaEvent.cs b/src/RealTime/Events/VanillaEvent.cs index 487119b5..c59e4bbb 100644 --- a/src/RealTime/Events/VanillaEvent.cs +++ b/src/RealTime/Events/VanillaEvent.cs @@ -15,14 +15,19 @@ internal sealed class VanillaEvent : CityEventBase private readonly float ticketPrice; /// <summary>Initializes a new instance of the <see cref="VanillaEvent"/> class.</summary> + /// <param name="id">The event ID.</param> /// <param name="duration">The city event duration in hours.</param> /// <param name="ticketPrice">The event ticket price.</param> - public VanillaEvent(float duration, float ticketPrice) + public VanillaEvent(ushort id, float duration, float ticketPrice) { this.duration = duration; this.ticketPrice = ticketPrice; + EventId = id; } + /// <summary>Gets the vanilla event ID.</summary> + public ushort EventId { get; } + /// <summary>Accepts an event attendee with specified properties.</summary> /// <param name="age">The attendee age.</param> /// <param name="gender">The attendee gender.</param> diff --git a/src/RealTime/GameConnection/EventManagerConnection.cs b/src/RealTime/GameConnection/EventManagerConnection.cs index 6b3b06aa..bda580d7 100644 --- a/src/RealTime/GameConnection/EventManagerConnection.cs +++ b/src/RealTime/GameConnection/EventManagerConnection.cs @@ -42,6 +42,12 @@ public IEnumerable<ushort> GetUpcomingEvents(DateTime earliestTime, DateTime lat continue; } + if ((eventData.m_flags + & (EventData.Flags.Cancelled | EventData.Flags.Completed | EventData.Flags.Deleted | EventData.Flags.Expired)) != 0) + { + continue; + } + if (eventData.StartTime >= earliestTime && eventData.StartTime < latestTime) { yield return i; diff --git a/src/RealTime/Localization/Translations/de.xml b/src/RealTime/Localization/Translations/de.xml index ab634dfa..40bd2bba 100644 --- a/src/RealTime/Localization/Translations/de.xml +++ b/src/RealTime/Localization/Translations/de.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="Anteil der Cims, die keine Überstunden machen und pünktlich zur und von der Arbeit gehen" /> <translation id="3Events" value="Ereignisse" /> + <translation id="AreEventsEnabled" value="Zusätzliche Ereignisse" /> + <translation id="AreEventsEnabledTooltip" value="Wenn deaktiviert, nur Ereignisse aus dem Originalspiel können stattfinden" /> <translation id="EarliestHourEventStartWeekday" value="Frühester Beginn unter der Woche" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="Der früheste Zeitpunkt, wann ein Ereignis am Tag unter der Woche beginnen kann" /> <translation id="LatestHourEventStartWeekday" value="Spätester Beginn unter der Woche" /> diff --git a/src/RealTime/Localization/Translations/en.xml b/src/RealTime/Localization/Translations/en.xml index ae5af97f..ed969039 100644 --- a/src/RealTime/Localization/Translations/en.xml +++ b/src/RealTime/Localization/Translations/en.xml @@ -47,7 +47,9 @@ <translation id="OnTimeQuota" value="On-time ratio" /> <translation id="OnTimeQuotaTooltip" value="The percentage of the Cims that will go to and leave their work on time" /> - <translation id="3Events" value="Events" /> + <translation id="3Events" value="Events" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Earliest weekday event" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="The earliest time when an event can start on a weekday" /> <translation id="LatestHourEventStartWeekday" value="Latest weekday event" /> diff --git a/src/RealTime/Localization/Translations/es.xml b/src/RealTime/Localization/Translations/es.xml index 92e289fd..ab94fa80 100644 --- a/src/RealTime/Localization/Translations/es.xml +++ b/src/RealTime/Localization/Translations/es.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="Porcentaje de ciudadanos que irán a trabajar y saldrán del trabajo con puntualidad" /> <translation id="3Events" value="Eventos" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Día laboral: Hora mínima de inicio" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="Hora más temprana en la cual pueden empezar los eventos entre semana" /> <translation id="LatestHourEventStartWeekday" value="Día laboral: Hora máxima de inicio" /> diff --git a/src/RealTime/Localization/Translations/fr.xml b/src/RealTime/Localization/Translations/fr.xml index bb0e91ec..a04a8239 100644 --- a/src/RealTime/Localization/Translations/fr.xml +++ b/src/RealTime/Localization/Translations/fr.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="Le pourcentage de citoyens qui iront et quitteront leur travail à temps" /> <translation id="3Events" value="Événements" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Premier événement en semaine" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="La première fois qu'un événement peut commenccer un jour de semaine" /> <translation id="LatestHourEventStartWeekday" value="Dernier événement de la semaine" /> diff --git a/src/RealTime/Localization/Translations/ko.xml b/src/RealTime/Localization/Translations/ko.xml index d3ec3323..511f7d69 100644 --- a/src/RealTime/Localization/Translations/ko.xml +++ b/src/RealTime/Localization/Translations/ko.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="일반적인 근무시간에 일하는 시민들의 비율을 정합니다." /> <translation id="3Events" value="이벤트" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="주중 이벤트 빠른 시작 시간" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="이벤트가 주중에 최대한 일찍 시작할 시간을 설정합니다" /> <translation id="LatestHourEventStartWeekday" value="주중 이벤트 늦은 시작 시간" /> diff --git a/src/RealTime/Localization/Translations/pl.xml b/src/RealTime/Localization/Translations/pl.xml index 7ade76e2..486b44a3 100644 --- a/src/RealTime/Localization/Translations/pl.xml +++ b/src/RealTime/Localization/Translations/pl.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="The percentage of the Cims that will go to and leave their work on time" /> <translation id="3Events" value="Events" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Earliest weekday event" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="The earliest time when an event can start on a weekday" /> <translation id="LatestHourEventStartWeekday" value="Latest weekday event" /> diff --git a/src/RealTime/Localization/Translations/pt.xml b/src/RealTime/Localization/Translations/pt.xml index d194ff29..1da7abe6 100644 --- a/src/RealTime/Localization/Translations/pt.xml +++ b/src/RealTime/Localization/Translations/pt.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="The percentage of the Cims that will go to and leave their work on time" /> <translation id="3Events" value="Events" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Earliest weekday event" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="The earliest time when an event can start on a weekday" /> <translation id="LatestHourEventStartWeekday" value="Latest weekday event" /> diff --git a/src/RealTime/Localization/Translations/ru.xml b/src/RealTime/Localization/Translations/ru.xml index b6e69fe9..d77762ca 100644 --- a/src/RealTime/Localization/Translations/ru.xml +++ b/src/RealTime/Localization/Translations/ru.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="Процент жителей, которые будут ходить на работу без сверхурочных" /> <translation id="3Events" value="Мероприятия" /> + <translation id="AreEventsEnabled" value="Активировать дополнительные события" /> + <translation id="AreEventsEnabledTooltip" value="Если выключено, то только события из оригинальной игры могут проходить в городе" /> <translation id="EarliestHourEventStartWeekday" value="Самое раннее по будням" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="Самое раннее время, когда мероприятие может начаться в будний день" /> <translation id="LatestHourEventStartWeekday" value="Самое позднее по будням" /> diff --git a/src/RealTime/Localization/Translations/zh.xml b/src/RealTime/Localization/Translations/zh.xml index cfdd7508..d5fd3506 100644 --- a/src/RealTime/Localization/Translations/zh.xml +++ b/src/RealTime/Localization/Translations/zh.xml @@ -48,6 +48,8 @@ <translation id="OnTimeQuotaTooltip" value="The percentage of the Cims that will go to and leave their work on time" /> <translation id="3Events" value="Events" /> + <translation id="AreEventsEnabled" value="Enable custom events" /> + <translation id="AreEventsEnabledTooltip" value="If disabled, only vanilla game events can occur in the city" /> <translation id="EarliestHourEventStartWeekday" value="Earliest weekday event" /> <translation id="EarliestHourEventStartWeekdayTooltip" value="The earliest time when an event can start on a weekday" /> <translation id="LatestHourEventStartWeekday" value="Latest weekday event" />