lumiere
Posts: 99
Joined: 3/19/2019 From: Japan Status: offline
|
Hope this test scenario helps (of course, you need to have eligible DLC to enable "Communication disruption" feature). Fomula from: https://commons.wikimedia.org/wiki/File:HorizonDistance.png In every 5 minutes, following Lua runs (sorry for chronic popups). local player = ScenEdit_PlayerSide()
local unit1 = 'Johnson Space Center'
local unit2 = 'USA-6'
--get units' altitude
local unit1 = ScenEdit_GetUnit({side=player, name=unit1})
print(unit1)
local unit2 = ScenEdit_GetUnit({side=player, name=unit2})
print(unit2)
print('Altitude of ' .. unit1.name .. ' is ' .. unit1.altitude .. 'm (' .. unit1.altitude*3.281 .. 'ft).')
print('Altitude of ' .. unit2.name .. ' is ' .. unit2.altitude .. 'm (' .. unit2.altitude*3.281 .. 'ft).')
-- calculate line of sight
local los1 = 3.57*math.sqrt(unit1.altitude)
print('Line of sight of ' .. unit1.name .. ' is ' .. los1 .. ' km.')
local los2 = 3.57*math.sqrt(unit2.altitude)
print('Line of sight of ' .. unit2.name .. ' is ' .. los2 .. ' km.')
local los = los1 + los2
print('Line of sight between two units is ' .. los .. ' km/' .. los*1000/1852 .. ' nm.')
-- if actual distance is greater than los, communication disruption occurs.
local range = Tool_Range (unit1.guid, unit2.guid)
print('Current distance between two units is ' .. range .. ' nm.')
if range>=los*1000/1852 then
if unit2.OutOfComms~= true then
ScenEdit_SpecialMessage('United States' ,'<P>It is too far to communicate!<P></P>' .. unit2.name .. ' must close within ' .. los*1000/1852 .. ' nm from ' .. unit1.name .. ' while current distance between two units is ' .. range .. ' nm.</P>')
ScenEdit_SetUnit({guid = unit2.guid, OutOfComms=true})
end
else
if unit2.OutOfComms~= true then
ScenEdit_SpecialMessage('United States' ,'IIt is enough to communicate!')
ScenEdit_SetUnit({guid = unit2.guid, OutOfComms=false})
end
end
Attachment (1)
< Message edited by lumiere -- 4/29/2019 8:17:29 AM >
|