Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Line of sight

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Line of sight Page: [1]
Login
Message << Older Topic   Newer Topic >>
Line of sight - 4/24/2019 6:15:45 PM   
gosnold

 

Posts: 190
Joined: 7/10/2013
Status: offline
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.
Post #: 1
RE: Line of sight - 4/29/2019 8:15:28 AM   
lumiere

 

Posts: 94
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 >

(in reply to gosnold)
Post #: 2
RE: Line of sight - 5/1/2019 11:12:29 AM   
gosnold

 

Posts: 190
Joined: 7/10/2013
Status: offline
Thanks! Using the radar horizon equation is a great idea, I will try out your script.

(in reply to lumiere)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Line of sight Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.102