A way to access detecting unit data for a Contact?

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

So I'm trying to obtain for a contact (or unit ), who has detected that contact, and by who I mean which unit(s), not a side, in LUA.

For example in the gui the following is displayed for a contact:
Image

In this particular case there are detections from 2 sensors on 1 unit 'Stucture2'.

Now I can get the contact wrapper for this contact via VP_GetContact and interrogate .detectionBy field\table but it will only return {Radar=1};
Interestingly it also was nil till the second detection was made by the BigBird-D. Such that when the Bogey first appeared by being detected by the Cheese Board and shown in the gui .detectonBy was still coming back nil. IDK if it's a delay issue or something else such that the first one is being skipped. Additionally shouldn't that read {Radar=2} as pictured since there are now 2 radar sensors detecting it, or is # here the number of units and not sensors?

But now back to what I'm trying to accomplish. I can't seem to find a way of finding what unit(s) made the detection(s), either from information contained in the contact wrapper, or the underlying contact's unit. I can check the unit's .ascontact table but that just provides side,contactguid,name. I can't seem to find any way of getting what I want when the contact is_not being actively fired on, targeted by, targeting or firing on anyone. Is there a way I'm missing?



One might wonder why I wanted this information or an example of how I was going to use it.

So I've been working on a something I call YARC (yet another radar controller) at the moment.
Besides introducing customizable randomization into flipping on\off radars per desired unit(s) (and even per sensor or sensor type per hosting unit), I'm also trying to enable some more intelligence. Things like hey if this unit is currently in the middle of firing on someone maybe now is not the right time to turn a FCR off even if cycle time is up. But another option is to flag the unit-sensor entry as being able to use data from it's side to be arguably more intelligent. Such that if say contact is being tracked by that particular unit, and say only by that unit, maybe you want it not to turn off, or only turn off if range exceeded a certain threshold on it's own detection. That one requires me to know who has detected what - at least relatively recently.

Another option without getting into too much detail was basically using information from other side\allied side sources to know when to override activation\deactivation or not. Such that it might only activate when a contact is inside say munition and FCR range of a host unit using data fed by other units. Which I can do as is, but I wanted to optionally restrict that option relative to other radars\host units proximity who are feeding the data to the host. Such that unit X will turn on based on contact data with-in Y range of X, but only for contacts obtained by units friendly\allied units located with-in 50nm of X or for that matter only if certain comm-link exist between the parties. Basically simulating shared comms\cec as the user permits, but only to a point, not side-wide.

Anyway to do some of that stuff on I need info from the contact's detection table like exists in the gui, namely a detecting-unit guid. Also optionally (and more enabling), the associated sensor guid on that detecting-unit, and the age and range if it's already readily available to pass on to us.

I don't know what's the best place for this information though if added, be it on the contact or the unit or both or some other method. Not sure how many are actually kept either I assume it's similar # to the gui.

A .detectedByUnits table on a Contact wrapper:
{[1] {guid=detecting-unitguidhere,sensor_guid=sensor_guidhere,age=agehere,range=rangehere}
...
[10] {guid=detecting-unitguidhere,sensor_guid=sensor_guidhere,age=agehere,range=rangehere}}

:detectionByUnits() method could work too to avoid default bloat of the wrapper size with a table.

Or on the Unit wrapper as a method?:
:detectionsBy('Sidename' or all if nil) --returns table of contacts this unit has detected that have not timed out.
{ [1] {guid=contactguidhere,side='SidenameOrUnknown'} ...
[XXX] {guid=contactguidhere,side='SidenameOrUnknown'} }

Or maybe I'm just trying to do too much with this stuff. [:)]

Beyond the aforementioned I also ran into this challenge awhile back trying to design a piece of a scene that required the player to have a specific unit not get detected by a specific set of enemy units and enemy sensor dbids (when emissions were not involved). Which couldn't be done without containing each of those to their own separated sides and using detectedBySide as a inartful workaround.
boogabooga
Posts: 973
Joined: Wed Jul 18, 2018 12:05 am

RE: A way to access detecting unit data for a Contact?

Post by boogabooga »

I think that I had a similar issue where the detecting unit data would have been useful. This is the work-around that I came up with. Basically, the strategy is to cross-reference two sides' contact lists and try to pull out the units that I am interested in. Turns into nested loop he**. I used the "targetedBy" attribute as a stand-in since it is often the case that units target the contacts that they can detect. Not foolproof, but a work-around.

Perhaps this will be useful to you but perhaps not...

Code: Select all

 LibyanContacts = ScenEdit_GetContacts('Libya') 
 UnitedStatesContacts = ScenEdit_GetContacts('United States')  
 
 for key,value in pairs(LibyanContacts) do
 	
 	--Check the Libya's contact emissions for the AWG-9 or AWG-10
 	if value.emissions == nil then  
 		--Prevents error being thrown before any emissions are detected
 	elseif value.emissions[1].sensor_dbid == 2003 or value.emissions[1].sensor_dbid == 1443 then
 		USfighter = ScenEdit_GetUnit({guid = value.actualunitid})  
 		
 		--See if the unit associated with that radar is targeting any Libyan A/C
 	    --If so, set that Libyan A/C RTB 
 		for key_1, value_1 in pairs(UnitedStatesContacts) do 
 			
 			if value_1.type == nil then
 				--Prevents error being thrown before types determined
 			elseif value_1.type == 'Air' then
 				LibyanAircraft = ScenEdit_GetUnit({guid = value_1.actualunitid}) 
 				
 				LibyanAircraftThreats = LibyanAircraft.targetedBy
 				
 				if LibyanAircraftThreats ~= nil then 
 					for key_2, value_2 in pairs(LibyanAircraftThreats) do 
 					
 						if value_2 == USfighter.guid and Tool_Range(LibyanAircraft.guid, USfighter.guid) < 35 then
 							ScenEdit_SetUnit({guid = LibyanAircraft.guid, RTB = true})
 						end
 					end
 				end
 			end
 		
 		end
 		
 	end
      
 end
 
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

Yeah unfortunately targetedby doesn't help in most cases for what I'm trying to do. Appreciate the response though.
I'm just gonna not add the intelligence I was going for yet.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: A way to access detecting unit data for a Contact?

Post by michaelm75au »

I have logged a request for this as a place holder.
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

Thanks Michael, appreciated as always.

boogabooga
Posts: 973
Joined: Wed Jul 18, 2018 12:05 am

RE: A way to access detecting unit data for a Contact?

Post by boogabooga »

Just to mention the other way could be useful as well; for a given Unit, a list of all contacts that it is actually detecting.
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

ORIGINAL: boogabooga

Just to mention the other way could be useful as well; for a given Unit, a list of all contacts that it is actually detecting.

Yeah that would be covered if implemented as method on Unit wrapper
Or on the Unit wrapper as a method?:
:detectionsBy('Sidename' or all if nil) --returns table of contacts this unit has detected that have not timed out.
{ [1] {guid=contactguidhere,side='SidenameOrUnknown'} ...
[XXX] {guid=contactguidhere,side='SidenameOrUnknown'} }
User avatar
blu3s
Posts: 1028
Joined: Fri Jul 08, 2022 9:45 am

Re: A way to access detecting unit data for a Contact?

Post by blu3s »

Any update on this?

Reviewing the available documentation I have found nothing in reference to the contacts of a unit or which unit has detected the contact.

It would be very useful from a scenario designer's point of view to be able to access both the contacts of a specific unit and who has detected the contact.

Thanks
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

blu3s wrote: Thu Mar 09, 2023 9:41 am Any update on this?
YES indeed there was, and I'm glad you revived this just so I can thank the devs for adding it awhile back again (I'm sure I did in release notes threads back when it was added), basically as requested.

Each contact now stores with it the last 25 or 50 so detentions just like in the gui, more or less just as I asked for in the request. It was implemented a while ago. 1147.2x I want to say but I forget. It's was a big help in doing what I was doing and I hope for others in doing other things (or making other things easier). I'll be honest I've not run that code that was using it on tiny builds yet, but far as I know it should still work the same, does in 1147.52.

So now you can see which sensor on which host made the detection, and you also know now long ago, and the range (from that sensor.. so you don't even have to calc that yourself anymore depending on what you're doing), now if you've got 100 things pinging a contact every few seconds the last 50 may not help (or whatever your doing may have to peek the data every 5 or less seconds), but in most cases it does help, a lot, without having to very low scan times on the data in most cases.

Code: Select all

local u = ScenEdit_GetContact( { side='united states', guid='Y5QK8V-0HM1KMFEQFV13'} )
print(u.lastDetections)

{
[1] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGK6H', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGK6C', age = 0, range = 81.1426696777344 },
[2] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGK6H', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGK6C', age = 0, range = 81.1426696777344 },
[3] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGJVP', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGJVK', age = 0, range = 60.0935401916504 },
..
[48] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGLD1', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGLCU', age = 1, range = 58.4287376403809 },
[49] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGLH6', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGLH2', age = 1, range = 64.2896118164063 },
[50] = { detect_sensor_guid = 'Y5QK8V-0HM1KMFEOGLH6', special_mode = None, detector_guid = 'Y5QK8V-0HM1KMFEOGLH2', age = 1, range = 64.2896118164063 }
} 
So TLDR the data is there now there to do the association, and keep longer term data yourself if you're scanning to collect it for storage in ones owns data structures. The reason for the ~50 or so limit is I think (don't want to talk for devs specifically..but..) practicality in file size and related matters since it's also storing the last 50 detentions per contact, and that adds up, and all that jazz has to be reevaluated on load too, so practically you need some limits that are also still useful.

:)

As for contacts: http://commandlua.github.io/assets/Wrap ... er_Contact
I think you should find most of what you need in:
.detectedBySide
.detectionBy (sort of the older school version of lastdetections that can still be useful)
.emissions
.firedOn
.firingAt
.lastDetections (you can work backward from this as to which unit made a detection and what sort of detection by sensor type)
.targetedBy
User avatar
blu3s
Posts: 1028
Joined: Fri Jul 08, 2022 9:45 am

Re: A way to access detecting unit data for a Contact?

Post by blu3s »

KnightHawk75 wrote: Thu Mar 16, 2023 8:26 am YES indeed there was, and I'm glad you revived this just so I can thank the devs for adding it awhile back again (I'm sure I did in release notes threads back when it was added), basically as requested.

...
Ohh thank you very much. I'm working on a nice ISR (and its subsequent strike :lol: ) scenario with ELINT and NO ELINT units and it was being a headache to collect only the logs for ELINT units to let the user analyze the collected data in by himself and make decisions based on that data.

This has opened up many possibilities!
KnightHawk75 wrote: Thu Mar 16, 2023 8:26 am .lastDetections (you can work backward from this as to which unit made a detection and what sort of detection by sensor type)
I see I overlooked this method and here was the key haha.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

Quite welcome.
blu3s wrote: Thu Mar 16, 2023 9:15 am This has opened up many possibilities!
It really has, good to hear more people are making use of the data.
User avatar
blu3s
Posts: 1028
Joined: Fri Jul 08, 2022 9:45 am

Re: A way to access detecting unit data for a Contact?

Post by blu3s »

It is a pity that there is no method to obtain contacts from a single unit. For medium/large scenarios to know if a contact has been detected by the unit you want, you have to go through the whole list of contacts on the side, and for each contact check if among its last detections, there is the one of the unit you want... This makes it very time consuming to be able to be run in a regular way

I have this script that writes the contacts of certain units to the log for later analysis. The problem is that it takes too much time (in order of 544ms) to run it every minute/every five minutes as is my intention.... And that running on a computer with an i7-9700k. I can't find a better way to optimize it, that's why, if anyone interested figure out an improvement or a different approach I'll be grateful. Thank you.
Attachments
ElintLog2.lua.txt
(2.6 KiB) Downloaded 18 times
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

blu3s,

Just some thoughts that come to mind eyeballing that...
Depending on what you may be doing I might change the code to optionally or not optionally check the type and skip the GetUnit calls and all the rest when contact type isn't related to what may be interested in (can also skip it for classification level 4 in some cases - i still wish autodetect had it's own level code instead of what seems it shares '4'). Anyway that would saves some needless processing say if you're only looking for air contacts detections for a specific unit, or surface contacts, etc etc. You could do this manually or via just pulling your contacts list using side:contactsBy("#" or "Aircraft|Facility|etc").

But yes if you're interested in everything you'll need to process all or most. Co-routine doing only x many contacts at a time per say 15 seconds would help distribute the load over time instead of taking it all at once, but may not work for specific needs.
User avatar
blu3s
Posts: 1028
Joined: Fri Jul 08, 2022 9:45 am

Re: A way to access detecting unit data for a Contact?

Post by blu3s »

KnightHawk75 wrote: Sun Mar 26, 2023 3:36 pm blu3s,

Just some thoughts that come to mind eyeballing that...
Depending on what you may be doing I might change the code to optionally or not optionally check the type and skip the GetUnit calls and all the rest when contact type isn't related to what may be interested in (can also skip it for classification level 4 in some cases - i still wish autodetect had it's own level code instead of what seems it shares '4'). Anyway that would saves some needless processing say if you're only looking for air contacts detections for a specific unit, or surface contacts, etc etc. You could do this manually or via just pulling your contacts list using side:contactsBy("#" or "Aircraft|Facility|etc").

But yes if you're interested in everything you'll need to process all or most. Co-routine doing only x many contacts at a time per say 15 seconds would help distribute the load over time instead of taking it all at once, but may not work for specific needs.
Hi KnightHawk75, thank you very much for your appreciation. Unfortunately I need all types of contacts, and I had no choice but to drastically reduce the number of units in the scenario. My idea is that the user can analyze the data collected by the ELINT platforms to know when it is best to raid enemy territory.

I had the call to GetUnit in case I needed to filter by the side of the units, now having left less units it will be the player who filters in its subsequent analysis.

Thank you very much, and I take this opportunity to thank you for the post about the 'stringify' data tables. I am using your method to keep the workspace clean and could save important info about the scen. Although later I have to consult you about some error I have when I try to save some tables but first I need to fine-tune it a bit :)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: A way to access detecting unit data for a Contact?

Post by KnightHawk75 »

blu3s wrote: Sun Mar 26, 2023 4:48 pm Thank you very much, and I take this opportunity to thank you for the post about the 'stringify' data tables. I am using your method to keep the workspace clean and could save important info about the scen. Although later I have to consult you about some error I have when I try to save some tables but first I need to fine-tune it a bit :)
Your welcome, happy to help where\when I can, hopefully we can sort through the error if it persists.
Post Reply

Return to “Lua Legion”