Skip to content

Commit

Permalink
Merge branch 'feature-events'
Browse files Browse the repository at this point in the history
  • Loading branch information
dymanoid committed Jul 22, 2018
2 parents 0e9c8c6 + ea12eba commit 02e56c9
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/RealTime/Config/RealTimeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -297,6 +304,7 @@ public void ResetToDefaults()
LocalBuildingSearchQuota = 60;
OnTimeQuota = 80;

AreEventsEnabled = true;
EarliestHourEventStartWeekday = 16f;
LatestHourEventStartWeekday = 20f;
EarliestHourEventStartWeekend = 8f;
Expand Down
26 changes: 21 additions & 5 deletions src/RealTime/Events/RealTimeEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void ProcessEvents()
lastProcessed = timeInfo.Now;

Update();
if (upcomingEvents.Count >= MaximumEventsCount)
if (upcomingEvents.Count >= MaximumEventsCount || !config.AreEventsEnabled)
{
return;
}
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/RealTime/Events/VanillaEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/RealTime/GameConnection/EventManagerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
4 changes: 3 additions & 1 deletion src/RealTime/Localization/Translations/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/ko.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="주중 이벤트 늦은 시작 시간" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/pt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="Самое позднее по будням" />
Expand Down
2 changes: 2 additions & 0 deletions src/RealTime/Localization/Translations/zh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit 02e56c9

Please sign in to comment.