function res = LEM_sim3(t_max,del_t,num_flights,sigma)
% LEM_sim3 - Jerome simulation prototype 500 flights (4 Nov 2020)
% On input:
%     t_max (float): max sim time
%     del_t (float): time step
%     num_flights (int): number of flights along the same route
% On output:
%     res (results struct): results of simulation
%       .reservations (reservations struct):
%       .flights (flights struct):
% Call:
%     res = LEM_sim3(400,0.5,500);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

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

roads = LEM_grid_roads(-100,100,-100,100,20,20);
airways = LEM_gen_airways(roads,[1:20],[101:120],2);
num_lanes = length(airways.lanes(:,1));
for k = 1:num_lanes
    reservations(k).flights = [];
end

for f = 1:num_flights
    [fp,reservations] = LEM_reserve_fp(reservations,airways,2,1200,5,...
        982,1002,1);
    flights(f).type = PLANNED;
    flights(f).plan = fp;
    flights(f).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(f).telemetry = [pt1 dir1 fp(1,3)];
end

t = 0;
wb = waitbar(0,'Flight Sim');
while t<t_max
    waitbar(t/t_max);
    t = t + del_t;
    [t,t_max]
    flights = LEM_advance_flights(flights,t,del_t,sigma);
end
close(wb);
res.roads = roads;
res.airways = airways;
res.reservations = reservations;
res.flights = flights;
