https://www.youtube.com/watch?v=u9R-59fusCM
Code: Select all
local start_lat = 41
local end_lat = 42
local start_lon = -74
local end_lon = -72
local step = 0.01
local max_elevation = 0
local lat_max = 0
local lon_max = 0
local lat_list = {}
local lon_list = {}
for x = start_lon, end_lon, step do
for y = start_lat, end_lat, step do
local elevation = World_GetElevation({latitude = y, longitude = x})
if elevation and elevation > max_elevation then
lat_max = y
lon_max = x
table.insert(lat_list, lat_max)
table.insert(lon_list, lon_max)
max_elevation = elevation
end
end
end
local number_samples = 10
if #lat_list < number_samples then
number_samples = #lat_list
end
for x = 1, number_samples, 1 do
local y = lat_list[math.floor(#lat_list / x)]
local x = lon_list[math.floor(#lon_list / x)]
print(x .. y)
ScenEdit_AddUnit({type = 'Facility', unitname = 'High Point', dbid = 2349, side = 'marker', Latitude = y, Longitude = x})
end
local best_lat = 0
local best_lon = 0
local best_horizon = 0
local sides = VP_GetSides()
local units = sides[1].units
for k, v in ipairs(units) do
local horizon = Tool_LOS({observer = {guid = v.guid}, target = {alt = 100}, mode = 0, horizon = 1, useRangeLimits = false})
if horizon and horizon > best_horizon then
best_lat = ScenEdit_GetUnit({guid = v.guid, side = 'marker'}).latitude
best_lon = ScenEdit_GetUnit({guid = v.guid, side = 'marker'}).longitude
best_horizon = horizon
end
end
print(best_horizon)
ScenEdit_AddUnit({type = "Facility", unitname = "Best point!", dbid = 2349, side = 'marker', Latitude = best_lat, Longitude = best_lon})