//loads the random events private static void LoadRandomEvents() { var doc = new XmlDocument(); doc.Load(AppSettings.GetDataPath() + "\\addons\\events\\RandomEvents.xml"); XmlElement root = doc.DocumentElement; XmlNodeList eventsList = root?.SelectNodes("//event"); if (eventsList != null) foreach (XmlElement element in eventsList) { string section = root.Name; var effects = (XmlElement) element.SelectSingleNode("effects"); var demand = (XmlElement) element.SelectSingleNode("demand"); var valid = (XmlElement) element.SelectSingleNode("valid"); string uid = element.Attributes["uid"].Value; var eventType = new RandomEvent.EventType(); string type = element.Attributes["type"].Value; string focus = element.Attributes["type"].Value; var eventFocus = new RandomEvent.Focus(); switch (type) { case "Safety": eventType = RandomEvent.EventType.Safety; break; case "Security": eventType = RandomEvent.EventType.Security; break; case "Customer": eventType = RandomEvent.EventType.Customer; break; case "Employee": eventType = RandomEvent.EventType.Employee; break; case "Maintenance": eventType = RandomEvent.EventType.Maintenance; break; case "Political": eventType = RandomEvent.EventType.Political; break; } switch (focus) { case "Airline": eventFocus = RandomEvent.Focus.Airline; break; case "Aircraft": eventFocus = RandomEvent.Focus.Aircraft; break; case "Airport": eventFocus = RandomEvent.Focus.Airport; break; } string name = element.Attributes["name"].Value; string message = element.Attributes["text"].Value; int frequency = int.Parse(element.Attributes["frequency"].Value)/3; DateTime start = valid != null && valid.HasAttribute("from") ? DateTime.Parse(valid.Attributes["from"].Value) : DateTime.Now.AddYears(100); DateTime end = valid != null && valid.HasAttribute("to") ? DateTime.Parse(valid.Attributes["to"].Value) : DateTime.Now.AddYears(100); bool critical = Convert.ToBoolean(element.Attributes["important"].Value); // if (int.Parse(effects.Attributes["important"].Value) == 1) critical = true; else critical = false;< if (effects != null) { int effectLength = int.Parse(effects.Attributes["duration"].Value); int chEffect = effects.HasAttribute("customerHappiness") ? int.Parse(effects.Attributes["customerHappiness"].Value) : 0; int ehEffect = effects.HasAttribute("employeeHappiness") ? int.Parse(effects.Attributes["employeeHappiness"].Value) : 0; int aSecurityEffect = effects.HasAttribute("airlineSecurity") ? int.Parse(effects.Attributes["airlineSecurity"].Value) : 0; int aSafetyEffect = effects.HasAttribute("airlineSafety") ? int.Parse(effects.Attributes["airlineSafety"].Value) : 0; int damageEffect = effects.HasAttribute("aircraftDamage") ? int.Parse(effects.Attributes["aircraftDamage"].Value) : 0; int financial = effects.HasAttribute("financial") ? int.Parse(effects.Attributes["financial"].Value) : 0; double paxDemand = demand != null && demand.HasAttribute("passenger") ? double.Parse(demand.Attributes["passenger"].Value) : 0; double cargoDemand = demand != null && demand.HasAttribute("cargo") ? double.Parse(demand.Attributes["cargo"].Value) : 0; var rEvent = new RandomEvent( eventType, eventFocus, aSafetyEffect, financial, uid, frequency, start, end, name, message, critical, chEffect, damageEffect, aSecurityEffect, ehEffect, paxDemand, cargoDemand, effectLength); RandomEvents.AddEvent(rEvent); } } }
//gets x number of random events of a given type public static List<RandomEvent> GetEvents(RandomEvent.EventType type, int number, Airline airline) { var rnd = new Random(); var rEvents = new Dictionary<int, RandomEvent>(); List<RandomEvent> tEvents = GetEvents(type); int i = 1; int j = 0; foreach (RandomEvent r in tEvents) { if (r.Start <= GameObject.GetInstance().GameTime && r.End >= GameObject.GetInstance().GameTime) { { r.DateOccurred = MathHelpers.GetRandomDate( GameObject.GetInstance().GameTime, GameObject.GetInstance().GameTime.AddMonths(12)); r.Airline = airline; r.Airliner = AirlinerHelpers.GetRandomAirliner(airline); r.Route = r.Airliner.Routes[rnd.Next(r.Airliner.Routes.Count())]; r.Country = r.Route.Destination1.Profile.Country; r.Airport = r.Route.Destination1; if (r.focus == RandomEvent.Focus.Airline) { r.Airliner = null; r.Airport = null; r.Country = null; r.Route = null; } rEvents.Add(i, r); i++; } } } tEvents.Clear(); while (j < number) { int item = rnd.Next(rEvents.Count()); tEvents.Add(rEvents[item]); j++; } return tEvents; }
//gets all events of a given type public static List<RandomEvent> GetEvents(RandomEvent.EventType type) { return GetEvents().FindAll((rEvent => rEvent.Type == type)); }
public static void AddEvent(RandomEvent rEvent) { _events.Add(rEvent.EventName, rEvent); }
public void AddEvent(Airline airline, RandomEvent rEvent) { airline.EventLog.Add(rEvent); }
public static void RemoveEvent(Airline airline, RandomEvent rEvent) { airline.EventLog.Remove(rEvent); }