function res = LEM_EQ_FAA1(vertexes,depots,num_deliveries,num_UAS,speed,...
    hd,EB,count,tt)
% LEM_EQ_FAA1 - earthquake FAA/NASA baseline scenario
% On input:
%     vertexes (nx3 array): ground vertexes
%     depots (kx1 array): depot indexes (in vertexes)
%     num_deliveries (int): number of deliveries per vertex
%     num_UAS (int): number of UAS
%     speed (float): in feet per second
%     hd (float): feet headway separation
%     EB (Booelan): 1 if load pre-computed EB cells, else compute them
% On output:
%     res (): results of simulation
%       .flights (flights struct): flight info
%       .UAS (UAS struct): UAS info
%         (k).scheudule (nx4 array):
%            launch index,land index,launch time,land time
% Call:
%     res = LEM_EQ_LBSD1(roads.vertexes,depots_EB,1,200,100,6,1);
% Author:
%     T. Henderson
%     UU
%     Spring 2021
%

MIN_ALTITUDE = 467;
MAX_ALTITUDE = 534;
MAX_DELAY = Inf;
LOAD_TIME = 300;
UNLOAD_TIME = 300;

res = [];

% Initialize flights
flights = [];

% Initialize UAS info
for k = 1:num_UAS
    UAS(k).schedule = [0,0,0,0];
end

[num_vertexes,dummy] = size(vertexes);

x_min = min(vertexes(:,1));
x_max = max(vertexes(:,1));
y_min = min(vertexes(:,2));
y_max = max(vertexes(:,2));
del_x = 500;
del_y = 500;
launch_sites = vertexes;
land_sites = vertexes;

% Create FAA/NASA  cells
if EB==1
    load('EB_cells');
else
    cells = LEM_gen_FAA_cells(x_min,x_max,y_min,y_max,del_x,del_y,...
        launch_sites,land_sites,hd)
    for k = 1:cells.M*cells.N
        cell_flights(k).flights = [];
    end
end

% Distribute UAS across depot sites
num_depots = length(depots);
for k = 1:num_UAS
    index = rem(k-1,num_depots) + 1;
    UAS(k).schedule(1,1) = depots(index);
end

% repeat the deliveries num_deliveries times
for d = 1:num_deliveries
%wb = waitbar(0,'EQFAA');
    for s = 1:num_vertexes
        [count,tt,d,s,num_vertexes]
        if isempty(find(depots==s)) % don't deliver to depot
            pt4 = vertexes(s,:);
%            h = MIN_ALTITUDE + rand*(MAX_ALTITUDE-MIN_ALTITUDE);
%            pt3 = pt4 + [0,0,h];
            % find UAS
            [u,t] = LEM_get_UAS(UAS,pt4,vertexes);
            launch_site = UAS(u).schedule(end,1);
%            pt1 = vertexes(launch_site,:);
%            pt2 = pt1 + [0,0,h];
            [flights,cell_flights] = LEM_EQ_FAA_reserve(flights,cells,...
                launch_site,s,MIN_ALTITUDE,...
                MAX_ALTITUDE,speed,hd,t,MAX_DELAY,u,cell_flights);
            if flights(end).type==1  % delivery OK; schedule return
                UAS(u).schedule(end,2) = s;
                UAS(u).schedule(end,3) = flights(end).start_time;
                UAS(u).schedule(end,4) = flights(end).end_time;
                UAS(u).schedule = [UAS(u).schedule;s,0,0,0];
                launch_site = s;
                land_site = UAS(u).schedule(end-1,1);
                request_time = flights(end).end_time + UNLOAD_TIME;
                [flights,cell_flights] = LEM_EQ_FAA_reserve(flights,...
                    cells,launch_site,land_site,MIN_ALTITUDE,...
                    MAX_ALTITUDE,speed,hd,request_time,Inf,u,cell_flights);
                if flights(end).type==1
                    UAS(u).schedule(end,2) = land_site;
                    UAS(u).schedule(end,3) = flights(end).start_time;
                    UAS(u).schedule(end,4) = flights(end).end_time;
                    UAS(u).schedule = [UAS(u).schedule;...
                        land_site,0,0,0];
                end
            end
        end
    end
    tch = 0;
end
%close(wb);
res.flights = flights;
res.UAS = UAS;
LEM_deconflict([],[],[],-1);

tch = 0;
