public VehicleSeat GetNextEmptySeat(sbyte seatId, bool next) { var seat = Seats.LookupByKey(seatId); if (seat == null) { return(null); } var newSeatId = seatId; while (!seat.IsEmpty() || HasPendingEventForSeat(newSeatId) || (!seat.SeatInfo.CanEnterOrExit() && !seat.SeatInfo.IsUsableByOverride())) { if (next) { if (!Seats.ContainsKey(++newSeatId)) { newSeatId = 0; } } else { if (!Seats.ContainsKey(newSeatId)) { newSeatId = SharedConst.MaxVehicleSeats; } --newSeatId; } // Make sure we don't loop indefinetly if (newSeatId == seatId) { return(null); } seat = Seats[newSeatId]; } return(seat); }