/// <summary>Gets the state of a city event in the specified building.</summary> /// <param name="buildingId">The building ID to check events in.</param> /// <param name="latestStart">The latest start time of events to consider.</param> /// <returns> /// The state of an event that meets the specified criteria, or <see cref="CityEventState.None"/> if none found. /// </returns> public CityEventState GetEventState(ushort buildingId, DateTime latestStart) { if (buildingId == 0) { return(CityEventState.None); } ushort eventId = buildingManager.GetEvent(buildingId); if (eventId != 0) { EventData.Flags vanillaEventState = eventManager.GetEventFlags(eventId); if ((vanillaEventState & (EventData.Flags.Preparing | EventData.Flags.Ready)) != 0) { if (eventManager.TryGetEventInfo(eventId, out _, out DateTime startTime, out _, out _) && startTime <= latestStart) { return(CityEventState.Upcoming); } return(CityEventState.None); } if ((vanillaEventState & EventData.Flags.Active) != 0) { return(CityEventState.Ongoing); } if (vanillaEventState != EventData.Flags.None) { return(CityEventState.Finished); } } if (activeEvent != null && activeEvent.BuildingId == buildingId) { return(CityEventState.Ongoing); } if (lastActiveEvent != null && lastActiveEvent.BuildingId == buildingId) { return(CityEventState.Finished); } if (upcomingEvents.FirstOrDefaultNode(e => e.BuildingId == buildingId && e.StartTime <= latestStart) != null) { return(CityEventState.Upcoming); } return(CityEventState.None); }
private bool MustCancelEvent(ICityEvent cityEvent) { if (!config.AreEventsEnabled && cityEvent is RealTimeCityEvent) { return(true); } const Building.Flags flags = Building.Flags.Abandoned | Building.Flags.BurnedDown | Building.Flags.Collapsed | Building.Flags.Deleted | Building.Flags.Demolishing | Building.Flags.Evacuating | Building.Flags.Flooded; if (buildingManager.BuildingHasFlags(cityEvent.BuildingId, flags, includeZero: 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)) != 0); } return(false); }