コード例 #1
0
        public static object ShowPopUp(SpecialContract contract)
        {
            PopUpWindow window = new PopUpShowSpecialContract(contract);
            window.ShowDialog();

            return window.Selected;
        }
コード例 #2
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            SpecialContractMVVM sct = (SpecialContractMVVM)((Button)sender).Tag;

            DateTime startdate;

            if (sct.Type.IsFixedDate)
                startdate = sct.Type.Period.From;
            else
                startdate = GameObject.GetInstance().GameTime;

            SpecialContract sc = new SpecialContract(sct.Type, startdate,GameObject.GetInstance().HumanAirline);
            GameObject.GetInstance().HumanAirline.SpecialContracts.Add(sc);

            GameObject.GetInstance().Contracts.Remove(sct.Type);
            this.Contracts.Remove(sct);

              if (this.Contracts.Count == 0)
                this.Close();
        }
コード例 #3
0
        public PopUpShowSpecialContract(SpecialContract contract)
        {
            this.ContractName = contract.Type.Name;
            this.Content = contract;

            this.Requirements = new List<RequirementMVVM>();
            this.Routes = new List<SpecialRouteMVVM>();

            foreach (ContractRequirement requirement in contract.Type.Requirements)
            {
                string text="";
                string value="";

                if (requirement.Type == ContractRequirement.RequirementType.ClassType)
                {
                    text = new TextUnderscoreConverter().Convert(requirement.ClassType).ToString();
                    value = string.Format("{0} passengers",requirement.MinSeats);
                }
                else if (requirement.Type == ContractRequirement.RequirementType.Destination)
                {
                    text = requirement.Departure.Profile.Name;
                    value = requirement.Destination.Profile.Name;
                }

                this.Requirements.Add(new RequirementMVVM(requirement.Type, text,value));
            }

            foreach (SpecialContractRoute route in contract.Type.Routes)
            {
                this.Routes.Add(new SpecialRouteMVVM(route.Departure, route.Destination));

                if (route.BothWays)
                    this.Routes.Add(new SpecialRouteMVVM(route.Destination, route.Departure));
            }

            InitializeComponent();
        }
コード例 #4
0
        //checks for a special contract returns true if not successed or overdue
        public static bool CheckSpecialContract(SpecialContract sc)
        {
            bool isOk = true;

            foreach (ContractRequirement cr in sc.Type.Requirements)
            {
                foreach (SpecialContractRoute scr in sc.Type.Routes)
                {
                    SpecialContractRoute scr1 = scr;
                    IEnumerable<Route> routes =
                        sc.Routes.Where(
                            r =>
                            r.HasAirliner &&
                            ((r.Destination1 == scr1.Departure && r.Destination2 == scr1.Destination) || (scr1.BothWays && r.Destination2 == scr1.Departure && r.Destination1 == scr1.Destination)));
                    if (cr.Type == ContractRequirement.RequirementType.ClassType)
                    {
                        if (routes.FirstOrDefault(r => ((PassengerRoute) r).GetRouteAirlinerClass(cr.ClassType) != null) == null)
                            isOk = false;
                    }
                    else if (cr.Type == ContractRequirement.RequirementType.Destination)
                    {
                        if (!routes.Any())
                            isOk = false;
                    }
                }
            }

            if (!isOk)
            {
                if (sc.Airline.IsHuman)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.FlightNews,
                                      GameObject.GetInstance().GameTime,
                                      Translator.GetInstance().GetString("News", "1016"),
                                      string.Format(
                                          Translator.GetInstance().GetString("News", "1016", "message"),
                                          sc.Type.Name,
                                          new ValueCurrencyConverter().Convert(sc.Type.Penalty))));
                }

                AddAirlineInvoice(sc.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.AirlineExpenses, -sc.Type.Penalty);
            }

            bool overdue = sc.Type.IsFixedDate ? GameObject.GetInstance().GameTime > sc.Type.Period.To : GameObject.GetInstance().GameTime >= sc.Date;

            if (isOk && overdue)
            {
                if (sc.Airline.IsHuman)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.FlightNews,
                                      GameObject.GetInstance().GameTime,
                                      Translator.GetInstance().GetString("News", "1017"),
                                      string.Format(
                                          Translator.GetInstance().GetString("News", "1017", "message"),
                                          sc.Type.Name,
                                          new ValueCurrencyConverter().Convert(sc.Type.Payment))));
                }

                AddAirlineInvoice(sc.Airline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.AirlineExpenses, sc.Type.Payment);

                return true;
            }

            return !isOk;
        }
コード例 #5
0
 public SpecialContractMVVM(SpecialContract contract, DateTime startdate, DateTime enddate)
 {
     Contract = contract;
     StartDate = startdate;
     EndDate = enddate;
 }
コード例 #6
0
        private static void DoDailyUpdate()
        {
            //Clear stats when it on daily update
            if (Infrastructure.Settings.GetInstance().ClearStats == Intervals.Daily)
            {
                ClearAllUsedStats();
            }

            //Auto save when it on daily
            if (Infrastructure.Settings.GetInstance().AutoSave == Intervals.Daily)
            {
                SerializedLoadSaveHelpers.SaveGame("autosave");
            }

            //Clearing stats as an RAM work-a-round
            Airports.GetAllAirports().ForEach(a => a.ClearDestinationPassengerStatistics());
            Airports.GetAllAirports().ForEach(a => a.ClearDestinationCargoStatistics());

            List<Airline> humanAirlines = Airlines.GetAirlines(a => a.IsHuman);

            //Console.WriteLine(GameObject.GetInstance().GameTime.ToShortDateString() + ": " + DateTime.Now.Subtract(LastTime).TotalMilliseconds + " ms." + " : routes: " + totalRoutes + " airliners on route: " + totalAirlinersOnRoute);

            _lastTime = DateTime.Now;
            //changes the fuel prices
            double fuelDiff = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year + 1).FuelPrice
                              - Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice;
            double fuelPrice = (Rnd.NextDouble()*(fuelDiff/4));

            GameObject.GetInstance().FuelPrice =
                Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice + fuelPrice;
            //checks for airports due to close in 14 days
            List<Airport> closingAirports =
                Airports.GetAllAirports(
                    a =>
                    a.Profile.Period.To.ToShortDateString()
                    == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString());
            List<Airport> openingAirports =
                Airports.GetAllAirports(
                    a =>
                    a.Profile.Period.From.ToShortDateString()
                    == GameObject.GetInstance().GameTime.AddDays(14).ToShortDateString());

            foreach (Airport airport in closingAirports)
            {
                Airport reallocatedAirport = openingAirports.Find(a => a.Profile.Town == airport.Profile.Town);

                if (reallocatedAirport == null)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      "Airport closing",
                                      $"The airport [LI airport={airport.Profile.IATACode}]({new AirportCodeConverter().Convert(airport)}) is closing in 14 days.\n\rPlease move all routes to another destination."));
                }
                else
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      "Airport closing",
                                      string.Format(
                                          "The airport [LI airport={0}]({1}) is closing in 14 days.\n\rThe airport will be replaced by {2}({3}) and all gates and routes from {0} will be reallocated to {2}.",
                                          airport.Profile.IATACode,
                                          new AirportCodeConverter().Convert(airport),
                                          reallocatedAirport.Profile.Name,
                                          new AirportCodeConverter().Convert(reallocatedAirport))));
                }

                CalendarItems.AddCalendarItem(
                    new CalendarItem(
                        CalendarItem.ItemType.AirportClosing,
                        airport.Profile.Period.To,
                        "Airport closing",
                        $"{airport.Profile.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}"));
            }

            foreach (Airport airport in openingAirports)
            {
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirportNews,
                                  GameObject.GetInstance().GameTime,
                                  "Airport opening",
                                  $"A new airport {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) is opening in 14 days in {airport.Profile.Town.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}."));
                CalendarItems.AddCalendarItem(
                    new CalendarItem(
                        CalendarItem.ItemType.AirportOpening,
                        airport.Profile.Period.From,
                        "Airport opening",
                        $"{airport.Profile.Name}, {((Country) new CountryCurrentCountryConverter().Convert(airport.Profile.Country)).Name}"));
            }
            //checks for new airports which are opening
            List<Airport> openedAirports =
                Airports.GetAllAirports(
                    a =>
                    a.Profile.Period.From.ToShortDateString()
                    == GameObject.GetInstance().GameTime.ToShortDateString());
            List<Airport> closedAirports =
                Airports.GetAllAirports(
                    a =>
                    a.Profile.Period.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString());

            //checks for airports which are closing down
            foreach (Airport airport in closedAirports)
            {
                //check for airport which are reallocated
                Airport reallocatedAirport = openedAirports.Find(a => a.Profile.Town == airport.Profile.Town);

                if (reallocatedAirport != null)
                {
                    IEnumerable<Airline> airlines =
                        new List<Airline>(from c in airport.AirlineContracts select c.Airline).Distinct();
                    foreach (Airline airline in airlines)
                    {
                        AirlineHelpers.ReallocateAirport(airport, reallocatedAirport, airline);

                        if (airline.IsHuman)
                        {
                            GameObject.GetInstance()
                                      .NewsBox.AddNews(
                                          new News(
                                              News.NewsType.AirportNews,
                                              GameObject.GetInstance().GameTime,
                                              "Airport operations changed",
                                              $"All your gates, routes and facilities has been moved from {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) to [LI airport={reallocatedAirport.Profile.IATACode}]({new AirportCodeConverter().Convert(reallocatedAirport)})"));
                        }
                    }
                }

                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirportNews,
                                  GameObject.GetInstance().GameTime,
                                  "Airport closed",
                                  $"The airport {airport.Profile.Name}({new AirportCodeConverter().Convert(airport)}) has now been closed. \n\rAll routes to and from the airports has been cancelled."));

                Airport airport1 = airport;
                IEnumerable<Route> obsoleteRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes)
                                                     where r.Destination1 == airport1 || r.Destination2 == airport1
                                                     select r);

                foreach (Route route in obsoleteRoutes)
                {
                    route.Banned = true;

                    foreach (FleetAirliner airliner in route.GetAirliners())
                    {
                        if (airliner.Homebase == airport)
                        {
                            if (airliner.Airliner.Airline.IsHuman)
                            {
                                airliner.Homebase = (Airport) PopUpNewAirlinerHomebase.ShowPopUp(airliner);
                            }
                            else
                            {
                                AIHelpers.SetAirlinerHomebase(airliner);
                            }
                        }
                    }
                }
            }
            //checks for new airliner types for purchase
            foreach (
                AirlinerType aType in
                    AirlinerTypes.GetTypes(
                        a =>
                        a.Produced.From.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                )
            {
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirlinerNews,
                                  GameObject.GetInstance().GameTime,
                                  "New airliner type available",
                                  $"{aType.Manufacturer.Name} has finished the design of {aType.Name} and it is now available for purchase"));

                if (
                    !AirlineFacilities.GetFacilities(f => f is PilotTrainingFacility)
                                      .Exists(f => ((PilotTrainingFacility) f).AirlinerFamily == aType.AirlinerFamily))
                {
                    AirlineFacilities.AddFacility(
                        new PilotTrainingFacility(
                            "airlinefacilities",
                            aType.AirlinerFamily,
                            9000,
                            1000,
                            GameObject.GetInstance().GameTime.Year,
                            0,
                            0,
                            aType.AirlinerFamily));
                }
            }
            //checks for airliner types which are out of production
            foreach (
                AirlinerType aType in
                    AirlinerTypes.GetTypes(
                        a => a.Produced.To.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                )
            {
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirlinerNews,
                                  GameObject.GetInstance().GameTime,
                                  "Airliner type out of production",
                                  $"{aType.Manufacturer.Name} has taken {aType.Name} out of production"));

                Boolean lastFromManufacturer =
                    AirlinerTypes.GetAllTypes().Count(t => (t.Manufacturer == aType.Manufacturer
                                                            && t.Produced.To > GameObject.GetInstance().GameTime)) == 0;

                if (lastFromManufacturer)
                {
                    AirlinerType type = aType;
                    IEnumerable<Airline> manufacturerContracts =
                        Airlines.GetAllAirlines()
                                .Where(a => a.Contract != null && a.Contract.Manufacturer == type.Manufacturer);

                    foreach (Airline contractedAirline in manufacturerContracts)
                    {
                        contractedAirline.Contract = null;
                    }
                }
            }
            //checks for airport facilities for the human airline
            IEnumerable<AirlineAirportFacility> humanAirportFacilities =
                (from f in humanAirlines.SelectMany(ai => ai.Airports.SelectMany(a => a.GetAirportFacilities(ai)))
                 where f.FinishedDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()
                 select f);

            foreach (AirlineAirportFacility facility in humanAirportFacilities)
            {
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirportNews,
                                  GameObject.GetInstance().GameTime,
                                  "Airport facility",
                                  $"Your airport facility {facility.Facility.Name} at [LI airport={facility.Airport.Profile.IATACode}] is now finished building"));
                facility.FinishedDate = GameObject.GetInstance().GameTime;
            }
            //checks for changed flight restrictions
            foreach (
                FlightRestriction restriction in
                    FlightRestrictions.GetRestrictions()
                                      .FindAll(
                                          r =>
                                          r.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()
                                          || r.EndDate.ToShortDateString()
                                          == GameObject.GetInstance().GameTime.ToShortDateString()))
            {
                string restrictionNewsText = "";
                if (restriction.Type == FlightRestriction.RestrictionType.Flights)
                {
                    restrictionNewsText = string.Format(restriction.StartDate.ToShortDateString()
                                                        == GameObject.GetInstance().GameTime.ToShortDateString() ? "All flights from {0} to {1} have been banned" : "The ban for all flights from {0} to {1} have been lifted", restriction.From.Name, restriction.To.Name);
                }
                if (restriction.Type == FlightRestriction.RestrictionType.Airlines)
                {
                    restrictionNewsText = string.Format(restriction.StartDate.ToShortDateString()
                                                        == GameObject.GetInstance().GameTime.ToShortDateString() ? "All airlines flying from {0} flying to {1} have been blacklisted" : "The blacklist on all airlines from {0} flying to {1} have been lifted", restriction.From.Name, restriction.To.Name);
                }
                if (restriction.StartDate.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                {
                    if (restriction.Type == FlightRestriction.RestrictionType.Flights)
                    {
                        IEnumerable<Route> bannedRoutes = (from r in Airlines.GetAllAirlines().SelectMany(a => a.Routes)
                                                           where
                                                               FlightRestrictions.HasRestriction(
                                                                   r.Destination1.Profile.Country,
                                                                   r.Destination2.Profile.Country,
                                                                   GameObject.GetInstance().GameTime)
                                                           select r);

                        foreach (Route route in bannedRoutes)
                        {
                            route.Banned = true;
                        }
                    }
                }
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.StandardNews,
                                  GameObject.GetInstance().GameTime,
                                  "Flight restriction",
                                  restrictionNewsText));
            }
            //checks for historic events
            foreach (HistoricEvent e in HistoricEvents.GetHistoricEvents(GameObject.GetInstance().GameTime))
            {
                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(News.NewsType.StandardNews, GameObject.GetInstance().GameTime, e.Name, e.Text));

                foreach (HistoricEventInfluence influence in e.Influences)
                {
                    SetHistoricEventInfluence(influence, false);
                }
            }
            //checks for historic events influences ending
            foreach (
                HistoricEventInfluence influence in
                    HistoricEvents.GetHistoricEventInfluences(GameObject.GetInstance().GameTime))
            {
                SetHistoricEventInfluence(influence, true);
            }

            //updates airports
            //Parallel.ForEach(
            //    Airports.GetAllActiveAirports(),
            //    airport =>
            foreach (Airport airport in Airports.GetAllActiveAirports())
            {
                //AirportHelpers.CreateAirportWeather(airport);

                if (Infrastructure.Settings.GetInstance().MailsOnBadWeather
                    && humanAirlines.SelectMany(a => a.Airports.FindAll(aa => aa == airport)).Any()
                    && (airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.ViolentStorm
                        || airport.Weather[airport.Weather.Length - 1].WindSpeed == Weather.eWindSpeed.Hurricane))
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.AirportNews,
                                      GameObject.GetInstance().GameTime,
                                      Translator.GetInstance().GetString("News", "1002"),
                                      string.Format(
                                          Translator.GetInstance().GetString("News", "1002", "message"),
                                          airport.Profile.IATACode,
                                          GameObject.GetInstance().GameTime.AddDays(airport.Weather.Length - 1).DayOfWeek)));
                }
                // chs, 2011-01-11 changed for delivery of terminals
                foreach (Terminal terminal in airport.Terminals.GetTerminals())
                {
                    if (terminal.DeliveryDate.Year == GameObject.GetInstance().GameTime.Year
                        && terminal.DeliveryDate.Month == GameObject.GetInstance().GameTime.Month
                        && terminal.DeliveryDate.Day == GameObject.GetInstance().GameTime.Day)
                    {
                        if (terminal.Airline == null)
                        {
                            GameObject.GetInstance()
                                      .NewsBox.AddNews(
                                          new News(
                                              News.NewsType.AirportNews,
                                              GameObject.GetInstance().GameTime,
                                              "Construction of terminal",
                                              $"[LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} has build a new terminal with {terminal.Gates.NumberOfGates} gates"));
                        }

                        if (terminal.Airline != null && terminal.Airline.IsHuman)
                        {
                            GameObject.GetInstance()
                                      .NewsBox.AddNews(
                                          new News(
                                              News.NewsType.AirportNews,
                                              GameObject.GetInstance().GameTime,
                                              "Construction of terminal",
                                              $"Your terminal at [LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} is now finished and ready for use."));
                        }

                        if (terminal.Airline != null)
                        {
                            Terminal terminal1 = terminal;
                            IEnumerable<AirportContract> oldContracts = new List<AirportContract>(airport.GetAirlineContracts(terminal.Airline)).Where(c => c.TerminalType == terminal1.Type);

                            var airportContracts = oldContracts as AirportContract[] ?? oldContracts.ToArray();
                            if (airportContracts.Any())
                            {
                                int totalGates = airportContracts.Sum(c => c.NumberOfGates);

                                int gatesDiff = totalGates - terminal.Gates.NumberOfGates;

                                if (gatesDiff > 0)
                                {
                                    int length = airportContracts.Max(c => c.Length);
                                    var newContract = new AirportContract(
                                        terminal.Airline,
                                        airport,
                                        AirportContract.ContractType.Full,
                                        terminal.Type,
                                        GameObject.GetInstance().GameTime,
                                        gatesDiff,
                                        length,
                                        AirportHelpers.GetYearlyContractPayment(
                                            airport,
                                            AirportContract.ContractType.Full,
                                            gatesDiff,
                                            length)/2,
                                        true);

                                    AirportHelpers.AddAirlineContract(newContract);
                                }

                                foreach (AirportContract oldContract in airportContracts)
                                {
                                    airport.RemoveAirlineContract(oldContract);

                                    for (int i = 0; i < oldContract.NumberOfGates; i++)
                                    {
                                        Gate oldGate =
                                            airport.Terminals.GetGates().First(g => terminal != null && g.Airline == terminal.Airline);
                                        oldGate.Airline = null;
                                    }
                                }
                            }
                            double yearlyPayment = AirportHelpers.GetYearlyContractPayment(
                                airport,
                                AirportContract.ContractType.Full,
                                terminal.Gates.NumberOfGates,
                                20);

                            AirportHelpers.AddAirlineContract(
                                new AirportContract(
                                    terminal.Airline,
                                    airport,
                                    AirportContract.ContractType.Full,
                                    terminal.Type,
                                    GameObject.GetInstance().GameTime,
                                    terminal.Gates.NumberOfGates,
                                    20,
                                    yearlyPayment*0.75,
                                    true));

                            if (
                                terminal.Airport.GetAirportFacility(
                                    terminal.Airline,
                                    AirportFacility.FacilityType.CheckIn).TypeLevel == 0)
                            {
                                AirportFacility checkinFacility =
                                    AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn)
                                                     .Find(f => f.TypeLevel == 1);

                                terminal.Airport.AddAirportFacility(
                                    terminal.Airline,
                                    checkinFacility,
                                    GameObject.GetInstance().GameTime);
                            }
                        }
                    }
                        //new gates in an existing terminal
                    else
                    {
                        int numberOfNewGates =
                            terminal.Gates.GetGates()
                                    .Count(
                                        g =>
                                        g.DeliveryDate.ToShortDateString()
                                        == GameObject.GetInstance().GameTime.ToShortDateString());

                        if (numberOfNewGates > 0)
                        {
                            GameObject.GetInstance()
                                      .NewsBox.AddNews(
                                          new News(
                                              News.NewsType.AirportNews,
                                              GameObject.GetInstance().GameTime,
                                              "Expansion of terminal",
                                              $"[LI airport={airport.Profile.IATACode}], {airport.Profile.Country.Name} has expanded {terminal.Name} with {numberOfNewGates} gates"));

                            double yearlyPayment = AirportHelpers.GetYearlyContractPayment(
                                airport,
                                AirportContract.ContractType.Full,
                                numberOfNewGates + terminal.Gates.NumberOfGates,
                                20);

                            AirportContract terminalContract =
                                airport.AirlineContracts.Find(c => c.Terminal != null && c.Terminal == terminal);

                            if (terminalContract != null)
                            {
                                terminalContract.NumberOfGates += numberOfNewGates;
                                terminalContract.YearlyPayment = yearlyPayment;

                                for (int i = 0; i < numberOfNewGates; i++)
                                {
                                    Gate newGate = airport.Terminals.GetGates().First(g => g.Airline == null);
                                    newGate.Airline = terminalContract.Airline;
                                }
                            }
                        }
                    }
                    //expired contracts
                    var airlineContracts =
                        new List<AirportContract>(
                            airport.AirlineContracts.FindAll(
                                c =>
                                c.ExpireDate.ToShortDateString()
                                == GameObject.GetInstance().GameTime.ToShortDateString()));

                    foreach (AirportContract contract in airlineContracts)
                    {
                        if (contract.AutoRenew)
                        {
                            contract.ContractDate = GameObject.GetInstance().GameTime;
                            contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length);

                            if (contract.Airline.IsHuman)
                            {
                                GameObject.GetInstance()
                                          .NewsBox.AddNews(
                                              new News(
                                                  News.NewsType.AirportNews,
                                                  GameObject.GetInstance().GameTime,
                                                  "Airport contract renewed",
                                                  $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now been renewed"));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < contract.NumberOfGates; i++)
                            {
                                Gate gate =
                                    airport.Terminals.GetGates().First(g => contract != null && g.Airline == contract.Airline);
                                gate.Airline = null;
                            }

                            if (contract.Airline.IsHuman)
                            {
                                int totalContractGates =
                                    airport.AirlineContracts.Where(c => c.Airline.IsHuman).Sum(c => c.NumberOfGates);

                                var airlineRoutes =
                                    new List<Route>(AirportHelpers.GetAirportRoutes(airport, contract.Airline));

                                var remainingContracts =
                                    new List<AirportContract>(
                                        airport.AirlineContracts.FindAll(
                                            c => c.Airline == contract.Airline && c != contract));

                                Boolean canFillRoutes = AirportHelpers.CanFillRoutesEntries(
                                    airport,
                                    contract.Airline,
                                    remainingContracts,
                                    Weather.Season.AllYear);

                                if (!canFillRoutes)
                                {
                                    GameObject.GetInstance()
                                              .NewsBox.AddNews(
                                                  new News(
                                                      News.NewsType.AirportNews,
                                                      GameObject.GetInstance().GameTime,
                                                      "Airport contract expired",
                                                      $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now expired, and a number of routes has been cancelled"));

                                    int currentRoute = 0;
                                    while (!canFillRoutes)
                                    {
                                        Route routeToDelete = airlineRoutes[currentRoute];

                                        foreach (FleetAirliner fAirliner in routeToDelete.GetAirliners())
                                        {
                                            fAirliner.Status = FleetAirliner.AirlinerStatus.Stopped;
                                            fAirliner.RemoveRoute(routeToDelete);
                                        }

                                        contract.Airline.RemoveRoute(routeToDelete);

                                        currentRoute++;

                                        canFillRoutes = AirportHelpers.CanFillRoutesEntries(
                                            airport,
                                            contract.Airline,
                                            remainingContracts,
                                            Weather.Season.AllYear);
                                    }
                                }
                                else
                                {
                                    GameObject.GetInstance()
                                              .NewsBox.AddNews(
                                                  new News(
                                                      News.NewsType.AirportNews,
                                                      GameObject.GetInstance().GameTime,
                                                      "Airport contract expired",
                                                      $"Your contract for {contract.NumberOfGates} gates at [LI airport={contract.Airport.Profile.IATACode}], {contract.Airport.Profile.Country.Name} is now expired"));
                                }

                                airport.RemoveAirlineContract(contract);
                            }
                            else
                            {
                                int numberOfRoutes = AirportHelpers.GetAirportRoutes(airport, contract.Airline).Count;

                                if (numberOfRoutes > 0)
                                {
                                    contract.ContractDate = GameObject.GetInstance().GameTime;
                                    contract.ExpireDate = GameObject.GetInstance().GameTime.AddYears(contract.Length);
                                }
                                else
                                {
                                    airport.RemoveAirlineContract(contract);
                                }
                            }
                        }
                    }
                }
                //checks for airport expansions
                foreach (AirportExpansion expansion in airport.Profile.Expansions.Where(e => e.Date.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString()))
                {
                    AirportHelpers.SetAirportExpansion(airport, expansion);
                }
            } //);
            //checks for airliners for the human airline
            foreach (
                FleetAirliner airliner in
                    humanAirlines.SelectMany(
                        a =>
                        a.Fleet.FindAll(
                            f =>
                            f.Airliner.BuiltDate == GameObject.GetInstance().GameTime
                            && f.Purchased != FleetAirliner.PurchasedType.BoughtDownPayment)))
            {
                if (airliner.Airliner.Airline == GameObject.GetInstance().HumanAirline)
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.FleetNews,
                                      GameObject.GetInstance().GameTime,
                                      "Delivery of airliner",
                                      $"Your new airliner [LI airliner={airliner.Airliner.TailNumber}] as been delivered to your fleet.\nThe airliner is currently at [LI airport={airliner.Homebase.Profile.IATACode}], {airliner.Homebase.Profile.Country.Name}"));
                }
                else
                {
                    GameObject.GetInstance()
                              .NewsBox.AddNews(
                                  new News(
                                      News.NewsType.FleetNews,
                                      GameObject.GetInstance().GameTime,
                                      "Delivery of airliner",
                                      $"The new airliner [LI airliner={airliner.Airliner.TailNumber}] as been delivered for [LI airline={airliner.Airliner.Airline.Profile.IATACode}].\nThe airliner is currently at [LI airport={airliner.Homebase.Profile.IATACode}], {airliner.Homebase.Profile.Country.Name}"));
                }
            }

            //Parallel.ForEach(
            //    Airlines.GetAllAirlines(),
            //    airline =>
            foreach (Airline airline in Airlines.GetAllAirlines())

            {
                lock (airline.Fleet)
                {
                    var fleet = new List<FleetAirliner>(airline.Fleet);
                    foreach (FleetAirliner airliner in
                        fleet.FindAll(
                            a =>
                            a != null
                            && a.Airliner.BuiltDate.ToShortDateString()
                               == GameObject.GetInstance().GameTime.ToShortDateString()
                            && a.Purchased == FleetAirliner.PurchasedType.BoughtDownPayment))
                    {
                        if (airline.Money >= airliner.Airliner.Type.Price)
                        {
                            AirlineHelpers.AddAirlineInvoice(
                                airline,
                                GameObject.GetInstance().GameTime,
                                Invoice.InvoiceType.Purchases,
                                -airliner.Airliner.Type.Price);
                            airliner.Purchased = FleetAirliner.PurchasedType.Bought;
                        }
                        else
                        {
                            airline.RemoveAirliner(airliner);

                            if (airline.IsHuman)
                            {
                                GameObject.GetInstance()
                                          .NewsBox.AddNews(
                                              new News(
                                                  News.NewsType.FleetNews,
                                                  GameObject.GetInstance().GameTime,
                                                  "Delivery of airliner",
                                                  $"Your new airliner {airliner.Name} can't be delivered to your fleet.\nYou don't have enough money to purchase it."));
                            }
                        }
                    }
                }

                if (airline.Contract != null
                    && airline.Contract.ExpireDate.ToShortDateString()
                    == GameObject.GetInstance().GameTime.ToShortDateString())
                {
                    int missingAirliners = airline.Contract.Airliners - airline.Contract.PurchasedAirliners;

                    if (missingAirliners > 0)
                    {
                        double missingFee = (airline.Contract.GetTerminationFee()/(airline.Contract.Length*2))
                                            *missingAirliners;
                        AirlineHelpers.AddAirlineInvoice(
                            airline,
                            GameObject.GetInstance().GameTime,
                            Invoice.InvoiceType.Purchases,
                            -missingFee);

                        if (airline.IsHuman)
                        {
                            GameObject.GetInstance()
                                      .NewsBox.AddNews(
                                          new News(
                                              News.NewsType.FleetNews,
                                              GameObject.GetInstance().GameTime,
                                              "Contract expired",
                                              $"Your contract with {airline.Contract.Manufacturer.Name} has now expired.\nYou didn't purchased enough airliners with costs a fee of {missingFee:C} for missing {missingAirliners} airliners"));
                        }
                    }
                    else if (airline.IsHuman)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.FleetNews,
                                          GameObject.GetInstance().GameTime,
                                          "Contract expired",
                                          $"Your contract with {airline.Contract.Manufacturer.Name} has now expired."));
                    }

                    airline.Contract = null;
                }
                //checks for students educated
                IEnumerable<PilotStudent> educatedStudents =
                    airline.FlightSchools.SelectMany(
                        f =>
                        f.Students.FindAll(
                            s =>
                            s.EndDate.ToShortDateString()
                            == GameObject.GetInstance().GameTime.ToShortDateString()));

                foreach (PilotStudent student in educatedStudents)
                {
                    var pilot = new Pilot(student.Profile, GameObject.GetInstance().GameTime, student.Rating);

                    if (student.AirlinerFamily != "")
                    {
                        pilot.AddAirlinerFamily(student.AirlinerFamily);
                    }

                    student.Instructor.RemoveStudent(student);
                    student.Instructor.FlightSchool.RemoveStudent(student);
                    student.Instructor = null;

                    airline.AddPilot(pilot);

                    if (airline.IsHuman)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.FlightNews,
                                          GameObject.GetInstance().GameTime,
                                          Translator.GetInstance().GetString("News", "1006"),
                                          string.Format(
                                              Translator.GetInstance().GetString("News", "1006", "message"),
                                              pilot.Profile.Name)));
                    }
                }

                IEnumerable<Pilot> trainedPilots =
                    airline.Pilots.Where(
                        p =>
                        p.Training != null
                        && p.Training.EndDate.ToShortDateString()
                        == GameObject.GetInstance().GameTime.ToShortDateString());

                foreach (Pilot pilot in trainedPilots)
                {
                    pilot.AddAirlinerFamily(pilot.Training.AirlinerFamily);

                    if (airline.IsHuman)
                    {
                        GameObject.GetInstance()
                                  .NewsBox.AddNews(
                                      new News(
                                          News.NewsType.FlightNews,
                                          GameObject.GetInstance().GameTime,
                                          Translator.GetInstance().GetString("News", "1015"),
                                          string.Format(
                                              Translator.GetInstance().GetString("News", "1015", "message"),
                                              pilot.Profile.Name,
                                              pilot.Training.AirlinerFamily)));
                    }

                    pilot.Training = null;
                }
            } //);
            //checks for mergers
            foreach (AirlineMerger merger in AirlineMergers.GetAirlineMergers(GameObject.GetInstance().GameTime))
            {
                if (merger.Type == AirlineMerger.MergerType.Merger)
                {
                    AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1);

                    Airlines.RemoveAirline(merger.Airline2);

                    if (merger.NewName != null && merger.NewName.Length > 1)
                    {
                        merger.Airline1.Profile.Name = merger.NewName;
                    }
                }
                if (merger.Type == AirlineMerger.MergerType.Subsidiary)
                {
                    string oldLogo = merger.Airline2.Profile.Logo;

                    var sAirline = new SubsidiaryAirline(
                        merger.Airline1,
                        merger.Airline2.Profile,
                        merger.Airline2.Mentality,
                        merger.Airline2.MarketFocus,
                        merger.Airline2.License,
                        merger.Airline2.AirlineRouteFocus);

                    AirlineHelpers.SwitchAirline(merger.Airline2, merger.Airline1);

                    merger.Airline1.AddSubsidiaryAirline(sAirline);

                    Airlines.RemoveAirline(merger.Airline2);

                    sAirline.Profile.Logos = merger.Airline2.Profile.Logos;
                    sAirline.Profile.Color = merger.Airline2.Profile.Color;
                }

                GameObject.GetInstance()
                          .NewsBox.AddNews(
                              new News(
                                  News.NewsType.AirlineNews,
                                  GameObject.GetInstance().GameTime,
                                  "Airline merger",
                                  merger.Name));
            }
            /*
            //does monthly budget work
               DateTime budgetExpires = GameObject.GetInstance().HumanAirline.Budget.BudgetExpires;
            if (budgetExpires <= GameObject.GetInstance().GameTime.AddDays(30))
            {
                GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Airline_News, GameObject.GetInstance().GameTime, "Budget Expires Soon", "Your budget will expire within the next 30 days. Please go to the budget screen and adjust it as needed and click 'Apply'."));
            }
            else if (budgetExpires <= GameObject.GetInstance().GameTime)
            {
                //GraphicsModel.PageModel.PageFinancesModel.PageFinances.ResetValues();
            }

            if (GameObject.GetInstance().HumanAirline.Money < GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12)
            {
                WPFMessageBox.Show("Low Cash!", "Your current cash is less than your budget deduction for the month! Decrease your budget immediately or you will be negative!", WPFMessageBoxButtons.Ok);
            }
            else { GameObject.GetInstance().HumanAirline.Money -= GameObject.GetInstance().HumanAirline.Budget.TotalBudget / 12; }
             * */

            //check for insurance settlements and do maintenance
            foreach (Airline a in Airlines.GetAllAirlines())
            {
                AirlineHelpers.CheckInsuranceSettlements(a);

                var airliners = new List<FleetAirliner>(a.Fleet);
                foreach (FleetAirliner airliner in airliners)
                {
                    if (airliner != null)
                    {
                        FleetAirlinerHelpers.DoMaintenance(airliner);
                        FleetAirlinerHelpers.RestoreMaintRoutes(airliner);
                    }
                }

                //checks for special contracts
                var sContracts = new List<SpecialContract>(a.SpecialContracts.Where(s => s.Date <= GameObject.GetInstance().GameTime));

                foreach (SpecialContract sc in sContracts)
                {
                    if (sc.Date.ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString() && sc.Type.IsFixedDate)
                    {
                        foreach (SpecialContractRoute route in sc.Type.Routes)
                        {
                            PassengerHelpers.ChangePaxDemand(route.Departure, route.Destination, (int) route.PassengersPerDay);

                            if (route.BothWays)
                                PassengerHelpers.ChangePaxDemand(route.Destination, route.Departure, (int) route.PassengersPerDay);
                        }
                    }
                    if (AirlineHelpers.CheckSpecialContract(sc))
                    {
                        a.SpecialContracts.Remove(sc);

                        if (sc.Type.IsFixedDate)
                        {
                            foreach (SpecialContractRoute route in sc.Type.Routes)
                            {
                                PassengerHelpers.ChangePaxDemand(route.Departure, route.Destination, -(int) route.PassengersPerDay);

                                if (route.BothWays)
                                    PassengerHelpers.ChangePaxDemand(route.Destination, route.Departure, -(int) route.PassengersPerDay);
                            }
                        }
                    }
                }
            }

            if (GameObject.GetInstance().GameTime.Day%7 == 0)
            {
                foreach (Airline airline in Airlines.GetAllAirlines())
                    airline.OverallScore += StatisticsHelpers.GetWeeklyScore(airline);
                // GameObject.GetInstance().HumanAirline.OverallScore +=
                //   StatisticsHelpers.GetWeeklyScore(GameObject.GetInstance().HumanAirline);
            }
            //checks for new special contract types
            List<SpecialContractType> randomSpecialContracts = SpecialContractTypes.GetRandomTypes();
            List<SpecialContractType> fixedSpecialContracts =
                SpecialContractTypes.GetTypes().FindAll(s => s.IsFixedDate && GameObject.GetInstance().GameTime.ToShortDateString() == s.Period.From.AddMonths(-1).ToShortDateString());

            var existingContracts = new List<SpecialContractType>(GameObject.GetInstance().Contracts);

            foreach (SpecialContractType sct in existingContracts)
            {
                if (sct.LastDate.AddMonths(1).ToShortDateString() == GameObject.GetInstance().GameTime.ToShortDateString())
                    GameObject.GetInstance().Contracts.Remove(sct);
                else
                {
                    Boolean taken = false;
                    int i = 0;

                    while (!taken && i < Airlines.GetAirlines(a => !a.IsHuman).Count)
                    {
                        Airline airline = Airlines.GetAirlines(a => !a.IsHuman)[i];
                        taken = AIHelpers.WillTakeSpecialContract(airline, sct);

                        if (taken)
                        {
                            DateTime startdate = sct.IsFixedDate ? sct.Period.From : GameObject.GetInstance().GameTime;

                            var sc = new SpecialContract(sct, startdate, airline);
                            airline.SpecialContracts.Add(sc);

                            GameObject.GetInstance().Contracts.Remove(sct);
                        }

                        i++;
                    }
                }
            }

            foreach (SpecialContractType sct in fixedSpecialContracts)
            {
                if (sct.LastDate == DateTime.MinValue)
                    sct.LastDate = GameObject.GetInstance().GameTime;

                GameObject.GetInstance().Contracts.Add(sct);
            }

            foreach (SpecialContractType sct in randomSpecialContracts)
            {
                if (sct.LastDate == DateTime.MinValue)
                    sct.LastDate = GameObject.GetInstance().GameTime;

                int monthsSinceLast = MathHelpers.GetAgeMonths(sct.LastDate);

                int monthsFrequency = 12/sct.Frequency;

                //mf = 12, ms = 1 => procent = lille, mf = 6, ms = 6 => procent = medium, mf = 1, ms = 12 => procent = høj

                int value = 100 - (monthsSinceLast - monthsFrequency);

                Boolean createContract = !GameObject.GetInstance().Contracts.Contains(sct) && Rnd.Next(value) == 0;

                if (createContract)
                {
                    sct.LastDate = GameObject.GetInstance().GameTime;

                    GameObject.GetInstance().Contracts.Add(sct);
                }
            }
        }