Line of sight (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


gosnold -> Line of sight (4/24/2019 6:15:45 PM)

Hello,

Is there a way to check with lua if two units of the same side are within line of sight of each other? I would like to model a satellite ground station, so that the satellite is out of comms for most of the time, and regains them when it is close to the ground station.

I think there is a way to do it by defining an area around the ground station and checking when the satellite is in the area, but I was wondering if there is a more straightforward solution.




lumiere -> RE: Line of sight (4/29/2019 8:15:28 AM)

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




gosnold -> RE: Line of sight (5/1/2019 11:12:29 AM)

Thanks! Using the radar horizon equation is a great idea, I will try out your script.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0234375