From 76064981e3166db403bce83e1387caec4fd3cb74 Mon Sep 17 00:00:00 2001
From: dymanoid <9433345+dymanoid@users.noreply.github.com>
Date: Sun, 22 Jul 2018 14:23:46 +0200
Subject: [PATCH 1/3] Add custom events switch into the settings
---
src/RealTime/Config/RealTimeConfig.cs | 16 ++++++++++++----
src/RealTime/Localization/Translations/de.xml | 2 ++
src/RealTime/Localization/Translations/en.xml | 4 +++-
src/RealTime/Localization/Translations/es.xml | 2 ++
src/RealTime/Localization/Translations/fr.xml | 2 ++
src/RealTime/Localization/Translations/ko.xml | 2 ++
src/RealTime/Localization/Translations/pl.xml | 2 ++
src/RealTime/Localization/Translations/pt.xml | 2 ++
src/RealTime/Localization/Translations/ru.xml | 2 ++
src/RealTime/Localization/Translations/zh.xml | 2 ++
10 files changed, 31 insertions(+), 5 deletions(-)
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; }
///
- /// 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.
///
[ConfigItem("3Events", 0)]
+ [ConfigItemCheckBox]
+ public bool AreEventsEnabled { get; set; }
+
+ ///
+ /// Gets or sets the daytime hour when the earliest event on a week day can start.
+ ///
+ [ConfigItem("3Events", 1)]
[ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)]
public float EarliestHourEventStartWeekday { get; set; }
///
/// Gets or sets the daytime hour when the latest event on a week day can start.
///
- [ConfigItem("3Events", 1)]
+ [ConfigItem("3Events", 2)]
[ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)]
public float LatestHourEventStartWeekday { get; set; }
///
/// Gets or sets the daytime hour when the earliest event on a Weekend day can start.
///
- [ConfigItem("3Events", 2)]
+ [ConfigItem("3Events", 3)]
[ConfigItemSlider(0, 23.75f, 0.25f, SliderValueType.Time)]
public float EarliestHourEventStartWeekend { get; set; }
///
/// Gets or sets the daytime hour when the latest event on a Weekend day can start.
///
- [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/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 @@
+
+
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 @@
-
+
+
+
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 @@
+
+
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 @@
+
+
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 @@
+
+
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 @@
+
+
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 @@
+
+
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 @@
+
+
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 @@
+
+
From 32cd72cfee57d249693e7855825bf8500800e715 Mon Sep 17 00:00:00 2001
From: dymanoid <9433345+dymanoid@users.noreply.github.com>
Date: Sun, 22 Jul 2018 14:34:53 +0200
Subject: [PATCH 2/3] Allow disabling custom events (closes #70)
---
src/RealTime/Events/RealTimeEventManager.cs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/RealTime/Events/RealTimeEventManager.cs b/src/RealTime/Events/RealTimeEventManager.cs
index 484f49bb..f5b9ef4e 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;
}
@@ -404,6 +404,11 @@ 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;
From ea12ebaf67b57e8900a6452f4d84bcb311aeffd1 Mon Sep 17 00:00:00 2001
From: dymanoid <9433345+dymanoid@users.noreply.github.com>
Date: Sun, 22 Jul 2018 15:26:19 +0200
Subject: [PATCH 3/3] Fix #62 - the invalid vanilla events will be removed from
the queue
---
src/RealTime/Events/RealTimeEventManager.cs | 19 +++++++++++++++----
src/RealTime/Events/VanillaEvent.cs | 7 ++++++-
.../GameConnection/EventManagerConnection.cs | 6 ++++++
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/RealTime/Events/RealTimeEventManager.cs b/src/RealTime/Events/RealTimeEventManager.cs
index f5b9ef4e..89cc9b83 100644
--- a/src/RealTime/Events/RealTimeEventManager.cs
+++ b/src/RealTime/Events/RealTimeEventManager.cs
@@ -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()
- .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}");
@@ -412,7 +411,19 @@ private bool MustCancelEvent(ICityEvent cityEvent)
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;
/// Initializes a new instance of the class.
+ /// The event ID.
/// The city event duration in hours.
/// The event ticket price.
- public VanillaEvent(float duration, float ticketPrice)
+ public VanillaEvent(ushort id, float duration, float ticketPrice)
{
this.duration = duration;
this.ticketPrice = ticketPrice;
+ EventId = id;
}
+ /// Gets the vanilla event ID.
+ public ushort EventId { get; }
+
/// Accepts an event attendee with specified properties.
/// The attendee age.
/// The attendee gender.
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 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;