function [reservations_out,flights] = LEM_gen_reservations1(airways,...
    a_flights,reservations,t,n)
% LEM_gen_reservations - generate new lane reservations
% On input:
%     airways (airways struct): airways info
%     a_flights (flight struct): flights info
%     reservations (reservations struct): lane reservations
%     t (float): current time
%     n (int): number of new flights
% On output:
%     reservations_out (reservations struct): updated lane reservations
%     flights (flights struct): new flight plans
% Call:
%     [r1,f1] = LEM_gen_reservations(airways,reservations,12.4,3);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

T_START_OFFSET = 1;
T_END_OFFSET = 20;
PLANNED = 1;

reservations_out = reservations;
flights = [];

ht = 2;

launch_lane_vertexes = airways.launch_lane_vertexes;
num_launch_lane_vertexes = length(launch_lane_vertexes);
land_lane_vertexes = airways.land_lane_vertexes;
num_land_lane_vertexes = length(land_lane_vertexes);
num_flights = length(a_flights);
num_flight_plans = 0;
for k = 1:n
    v1 = launch_lane_vertexes(randi(num_launch_lane_vertexes));
    v2 = land_lane_vertexes(randi(num_land_lane_vertexes));
    t1 = t + T_START_OFFSET;
    t2 = t1 + T_END_OFFSET;
    speed = 5;
    tic
    [fp,reservations_out] = LEM_reserve_fp(reservations_out,airways,t1,...
        t2,speed,v1,v2,ht);
    dct = toc;
    if ~isempty(fp)
        num_flight_plans = num_flight_plans + 1;
        num_flights = num_flights + 1;
        num_steps = length(fp(:,4));
        for s = 1:num_steps
            reservations_out(fp(s,4)).flights(end,1) = num_flights;
        end
        flights(num_flight_plans).type = PLANNED;
        flights(num_flight_plans).decon_time = dct;
        flights(num_flight_plans).plan = fp;
        flights(num_flight_plans).route = LEM_plan2route(fp,airways);
        lane_index = fp(1,4);
        lane_vertex1 = airways.lane_edges(lane_index,1);
        pt1 = airways.lane_vertexes(lane_vertex1,:);
        lane_vertex2 = airways.lane_edges(lane_index,2);
        pt2 = airways.lane_vertexes(lane_vertex2,:);
        dir1 = pt2 - pt1;
        dir1 = dir1/norm(dir1);
        flights(num_flight_plans).telemetry = [pt1 dir1 fp(1,3)];
    end
end
tch = 0;
