function res = LEM_sim1(t_max,del_t,f_prob,sigma)
% LEM_sim1 - first simulation prototype
% On input:
%     t_max (float): max sim time
%     del_t (float): time step
%     f_prob (float): probability of new flight
% On output:
%     res (results struct): results of simulation
%       .reservations (reservations struct):
%       .flights (flights struct):
% Call:
%     res = LEM_sim1(400,0.5,0.2);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

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

t = 0;
wb = waitbar(0,'Flight Sim');
while t<t_max
    waitbar(t/t_max);
    t = t + del_t;
    [t,t_max];
    new_flights = [];
    if rand<f_prob
        [reservations,new_flights] = LEM_gen_reservations(airways,...
            reservations,t,1);
    end
    if ~isempty(new_flights)
        num_new_flights = length(new_flights);
        for k = 1:num_new_flights
            flights(end+1).type = new_flights(k).type;
            flights(end).plan = new_flights(k).plan;
            flights(end).route = new_flights(k).route;
            flights(end).telemetry = new_flights(k).telemetry;
        end
    end
    new_flights = LEM_gen_rogue_flights(airways,flights,t);
    flights = LEM_advance_flights(flights,t,del_t,sigma);
end
close(wb);
res.roads = roads;
res.airways = airways;
res.reservations = reservations;
res.flights = flights;
