moving reference points to align with changing threat axis

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

moving reference points to align with changing threat axis

Post by orca »

I want to move reference points for a CAP so that they are always located between the my carrier strike group (CSG) and the enemy CSG. Both CSGs are moving and therefore need to set/move the RPs every so often.

I plan to use 4 RPs which I will label CAP-1, CAP-2, CAP-3, and CAP-4.

I think there is a way to check the bearing between my group (or carrier) and them enemy and then set/move the CAP RPs based on this bearing +/- the appropriate degree and the range for the RP that I want, but I can't figure it out. I would run this every 15 min or so to keep the CAP is proper position relative to the enemy.

Thanks in advance for any help!
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: moving reference points to align with changing threat axis

Post by KnightHawk75 »

Assuming for the sake of argument using relative bearing to the carrier and adjusting the 'distance' property that's available when that's set doesn't work for what you're doing, yeah you can just brute force it.

Run something like this every 15 minutes.

Code: Select all

 -- This function assumes only 4pts in the feed rps param and disttbl tables.
 -- copy and adjust as needed for different shapes and designs etc.
 -- when providing thebear and therange override params slat,slon,tlat,tlon can all be nil.
 -- otherwise they are required.
 local function handle4pBoxPTzone(slat,slon,tlat,tlon,rps,disttbl,pct,thebear,therange)
     if thebear ==nil then thebear = Tool_Bearing({latitude=slat, longitude=slon},{latitude=tlat, longitude=tlon}); end
     if therange ==nil then therange = Tool_Range({latitude=slat, longitude=slon},{latitude=tlat, longitude=tlon}); end
     local centerpoint = World_GetPointFromBearing({latitude=slat,longitude=slon,BEARING=thebear,DISTANCE=(therange * pct)})
     local,retval1,retval2,adjbear,bFlag = false,nil,0,false;
     for k,v in pairs(rps) do
        if k == 1 then adjbear = (thebear + (k * 45)) %360; --original bearing 45d offset from that starting point
        else adjbear = (adjbear + 90)%360;  end  --90d offset from ^starting point or later.. lastpoint.
         local therp = World_GetPointFromBearing({latitude=centerpoint.latitude,longitude=centerpoint.longitude,BEARING=adjbear,DISTANCE=disttbl[k]});
          --a simple v.latitude,v.longitude=therp.latitude,therp.longitude here will not actually update it,must use setrefpt. 
         retval1,retval2 = pcall(ScenEdit_SetReferencePoint,{guid=v.guid,side=v.side,latitude=therp.latitude,longitude=therp.longitude});
         if retval1 ==false then print("Error updating ref point: " .. tostring(retval2)); bFlag = true; end
     end
     if bFlag then return false; else return true;end
 end

Code: Select all

 local function UpdatePatrolMissionRPSourceToTarget(mname,mside,sname,sside,tname,tside,pct,nenm,senm,swnm,nwnm,pznm)
     if mname ==nil or mside == nil or tname ==nil or tside ==nil or sname==nil or sside==nil then 
         print("One or more of missionname,missionside,sourcename,sourceside,targetname,targetside params are missing."); return;
     end
     if pct == nil then pct = 0.50;end  if pznm == nil then pznm = 50.0;end
     if nenm == nil then nenm = 50.0;end  if senm == nil then senm = 50.0;end
     if swnm == nil then swnm = 50.0;end  if nwnm == nil then nwnm = 50.0;end
     local m = ScenEdit_GetMission(mside,mname);
     local s = ScenEdit_GetUnit({name=sname,side=sside});
     local t = ScenEdit_GetUnit({name=tname,side=tside});
     if m==nil or t==nil or s==nil then print("Could not get mission or source or target."); return end --sanity check.

Code: Select all

    local tmparea = {};
     if (m.patrolmission.PatrolZone ~=nil) and #m.patrolmission.PatrolZone == 4 then
         for i =1,#m.patrolmission.PatrolZone do
           tmparea[i] = m.patrolmission.PatrolZone[i].name
         end
         local ppoints = ScenEdit_GetReferencePoints({side=m.side, area=tmparea});
         handle4pBoxPTzone(s.latitude,s.longitude,t.latitude,t.longitude,ppoints,{nenm,senm,swnm,nwnm},pct)
     end
     if (m.patrolmission.ProsecutionZone ~=nil) and #m.patrolmission.ProsecutionZone == 4 then
         tmparea = {};
         for i =1,#m.patrolmission.ProsecutionZone do
           tmparea[i] = m.patrolmission.ProsecutionZone[i].name
         end
         local ppoints = ScenEdit_GetReferencePoints({side=m.side, area=tmparea})
         handle4pBoxPTzone(s.latitude,s.longitude,t.latitude,t.longitude,ppoints,{nenm+pznm,senm+pznm,swnm+pznm,nwnm+pznm},pct)
     end
 end
 

Code: Select all

 --call update to a square box centered 50% distance to target with 50nm extra add on for prosecution rp's if any.
 UpdatePatrolMissionRPSourceToTarget("Testy","China","Shandong Carrier Strike Group","China","Abraham Lincoln Strike Group","United States",0.50,100,100,100,100,50);
 
 --call update to a polygon centered 40% distance to target with 30nm extra add on for prosecution rp's if any.
 UpdatePatrolMissionRPSourceToTarget("Testy","China","Shandong Carrier Strike Group","China","Abraham Lincoln Strike Group","United States",0.40,125,50,50,125,30);

Above test usage assumes an AAW patrol mission "Testy" exists for side "China", and has 4, and only 4 rp's in it's patrol zone and or prosecution zone, and of course the group\unit names used exist. Obviously if not using mission assigned rp's you can just adjust the code to handle your own area= arrayofnames and forgo all the lookup code, but I provide it cause it's a common case.
Post Reply

Return to “Lua Legion”