/// <summary> /// Used to add reservation on flight /// </summary> internal void BookFlightTicket(Passenger passenger) { if (Status == FlightStatus.OpenForReservation) { Reservations.Add(new Reservation(passenger, this)); FlightInfo?.Invoke($"{passenger.FirstName} has booked a ticket to {Destination}"); } else { throw new Exception("Reservation failed, flight is full!"); } }
/// <summary> /// Used to update flight statuses /// </summary> internal void UpdateFlightStatuses(SimulationTime time) { // Gets the time until takeoff double timeToTakeoff = Departure.Subtract(time.DateTime).TotalMinutes; // When reservations count is to small // Cancel the flight if (Status != FlightStatus.OpenForReservation && Reservations.Count < 20) { if (ChangeStatusIfNewer(FlightStatus.Canceled)) { BadFlightInfo?.Invoke($"{Name} got canceled due to reservation amount was < 20"); } } // Updates the different flight states if (ChangeStatusInsidePeriod(timeToTakeoff, 360, 900, FlightStatus.FarAway)) { FlightInfo?.Invoke($"{Name} is now closed for reservations"); } if (ChangeStatusInsidePeriod(timeToTakeoff, 70, 360, FlightStatus.OnTheWay)) { FlightInfo?.Invoke($"{Name} is 290 min from the airport"); } if (ChangeStatusInsidePeriod(timeToTakeoff, 60, 70, FlightStatus.Landing)) { FlightInfo?.Invoke($"{Name} has just landed"); } if (ChangeStatusInsidePeriod(timeToTakeoff, 30, 60, FlightStatus.Refilling)) { FlightInfo?.Invoke($"{Name} is being filled with luggages"); } if (ChangeStatusInsidePeriod(timeToTakeoff, 5, 30, FlightStatus.Boarding)) { FlightInfo?.Invoke($"{Name} is now boading"); } if (ChangeStatusInsidePeriod(timeToTakeoff, 0, 5, FlightStatus.Takeoff)) { if (GetCheckinAmount() == Reservations.Count) { FlightInfo?.Invoke($"{Name} is about to takeoff with all booked passengers"); } else { BadFlightInfo?.Invoke($"{Name} is about to takeoff with missing passengers due to bustle"); } } }
/// <summary> /// Used to auto generate reservations on flight /// </summary> /// <param name="bustleLevel"></param> internal void AutoBookFlightTickets(int minSeats) { // Limit min seats if (minSeats > SeatsAmount) { minSeats = SeatsAmount - 1; } // Generates random amount of reservations int amount = rng.Next(minSeats, SeatsAmount); for (int i = 0; i < amount; i++) { BookFlightTicket(AutoGenerator.CreateRandomPassenger()); } FlightInfo?.Invoke($"{amount} auto generated people has made a reservation on {Name}"); }