Created
August 1, 2020 02:24
-
-
Save rurounijones/774224dfee15e06b9179aa3fc63a44c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local logger = CinCLogger | |
local world = world | |
local ipairs = ipairs | |
local coord = coord | |
local coroutine = coroutine | |
local atmosphere = atmosphere | |
local math = math | |
local command = function (_) | |
logger.info("Command get_airbases called") | |
local airfield_loop = coroutine.create(function() | |
local data = world.getAirbases() | |
local result = {} | |
for i, v in ipairs(data) do | |
local airbase_properties = {} | |
airbase_properties["id"] = v:getID() | |
airbase_properties["name"] = v:getName() | |
airbase_properties["category"] = v:getDesc()['category'] | |
airbase_properties["coalition"] = v:getCoalition() | |
local latitude, longitude, altitude = coord.LOtoLL(v:getPoint()) | |
airbase_properties["latitude"] = latitude | |
airbase_properties["longitude"] = longitude | |
airbase_properties["altitude"] = altitude | |
-- Taken from https://github.com/VEAF/VEAF-Mission-Creation-Tools/blob/master/src/scripts/veaf/veaf.lua#L402 by Zip | |
-- Get wind velocity vector | |
local point = v:getPoint() | |
-- Add some height to make sure we don't get 0 AGL because that is ground level which DCS considers invalid. | |
-- Also real world ATIS measures 10 meters up which is handy. | |
point.y = point.y + 10 | |
local windvec3 = atmosphere.getWind(point) | |
local direction = math.deg(math.atan2(windvec3.z, windvec3.x)) | |
if direction < 0 then | |
direction = direction + 360 | |
end | |
-- Convert TO direction to FROM direction. | |
if direction > 180 then | |
direction = direction-180 | |
else | |
direction = direction+180 | |
end | |
-- Calc 2D strength. | |
local strength = math.sqrt((windvec3.x)^2+(windvec3.z)^2) | |
airbase_properties["wind_heading"] = direction | |
airbase_properties["wind_speed"] = strength -- m/s | |
result[i] = airbase_properties | |
coroutine.yield() | |
end | |
return result | |
end) | |
return coroutine.resume(airfield_loop) | |
end | |
CinCServer.add_command('get_airbases', command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment