Jump to content

Create a table of the current active WP of a group


Recommended Posts

Posted (edited)

Hi guys 🙂

 

I'm still working on my big FrenchPack script. I implemented an AI capability for ground units : Any armored vehicle will try either to face its main threat to maximize armor or will engage in random maneuvers. It works and would be a basis for a more complex system. Thing is as it works by assigning a new WP to the group, it will erase the already scheduled route.

 

I therefore would like to create a table which would include:

- The WP of the unit

- Which is the active WP

- Being able to get it to resume its route once the "maneuver" is finished. 

For now the function looks like this and will only work with the condition that the vehicle is not moving to do not mess with mission editor planned routes 

 

local function FfaceR() --------------- IA FAIT FACE RED
timer.scheduleFunction(FfaceR, {}, timer.getTime() + 15) 

local FFACEV  = 				trigger.misc.getUserFlag("FFACEV")
local FFACEF  = 				trigger.misc.getUserFlag("FFACEF")


if FFACEV == 0 and FFACEF == 0 or FFACEV == 1 then 
local group_arrayR = coalition.getGroups(coalition.side.RED, Group.Category.GROUND)

for k, group in pairs(group_arrayR) do 
if group then 
local units = group:getUnits()

		local leader = units[1]
		local nonleader = units[2]
		
											
											
		
		if leader and Unit.isExist(leader) and leader:getName() ~= "XLBis" and not nonleader  then	
		if Unit.hasAttribute(leader, "Tanks") or
		Unit.hasAttribute(leader, "IFV") 
		
		then
			
		local logi = leader:getController()
		local list = logi:getDetectedTargets(Controller.Detection.VISUAL)
			
					for _,DetectedTarget in pairs(list) do
						if DetectedTarget ~= nil then
					obj = DetectedTarget.object 
					tgt = obj:getTypeName()	   
					tgtpos = obj:getPosition().p
					
					
					
											
		
					local leader_pt3d = leader:getPoint()
					local orientation = leader:getPosition()			
					local heading = leader:getDrawArgumentValue(0)
					
					
												if heading < 0 then
													heading =  -heading*180 
												else
													heading = 360 -  heading * 180
												end
											
												local chassis_heading = GetHeading(orientation)
												heading = heading + ((chassis_heading*180)/math.pi)
												
												if heading > 359 then
												heading = heading - 360
												end
												
					local Fheading = math.floor(heading+0)						
					local Azimut_tourelle =  math.sqrt(math.pow(leader:getDrawArgumentValue(0), 2))
					
					local leaderPos = leader:getPosition().p
					local LG = leader:getGroup()
					local LGSP = leader:getVelocity()
					
					
					local Vecc = {x = leaderPos.x - tgtpos.x, y = leaderPos.y - tgtpos.y,z = leaderPos.z - tgtpos.z}
					local North = {x = 1, y = 0, z = 0}
					local Distx	= math.pow(leaderPos.x - tgtpos.x, 2)
					local Distz = math.pow(leaderPos.z - tgtpos.z, 2)
					local Dist1 = math.sqrt(Distx+ Distz)
					local Dist2 = math.floor(Dist1+0)	
					local Ang1 =  math.deg(getDir(Vecc))
					local Ang2 = math.floor(Ang1+0)
									
				
				if Ang2 > 180 then Ang2 = Ang2 - 180 elseif Ang2 < 179 then Ang2 = Ang2 + 180 end
					
					local speed = leader:getVelocity()
					local Angle_match = math.sqrt(math.pow(Ang2 - Fheading, 2))
					
				
					local A =      {
           group =  LG, 
           point = {y = tgtpos.y,  x = tgtpos.x, z = tgtpos.z},
           radius = 0,
		   form = "diamond",
		   heading = Fheading,
		   speed = 0.5,
		   disableRoads = true
               } 
				local B =      {
           group =  LG, 
           point = {y = leaderPos.y,  x = leaderPos.x, z = leaderPos.z},
           radius = 250,
		   form = "diamond",
		   heading = Fheading,
		   speed = 30,
		   disableRoads = true
               } 
			
				local rand = math.random(1,100)
			   if Azimut_tourelle > 0.2  and math.sqrt( math.pow(speed.z + speed.x + speed.y, 2)) < 2
					
					
					then 
					
						groupToRandomPoint(A)
														end
				if Azimut_tourelle < 0.2 and math.sqrt( math.pow(speed.z + speed.x + speed.y, 2)) < 2  then
				
				trigger.action.groupStopMoving(LG)
												end
				if Azimut_tourelle > 0 and rand < 10 and math.sqrt( math.pow(speed.z + speed.x + speed.y, 2)) < 2  then 
				groupToRandomPoint(B)
				end				
		end
		end
end		
	end
	end
	end
	end
end

I'm really bad at tables. If you have a way to do it efficiently, it would be appreciated 🙂

Grimes save me 🥲

Nicolas

Edited by dimitriov
Posted
1 hour ago, dimitriov said:

...I therefore would like to create a table which would include:

- The WP of the unit

- Which is the active WP

- Being able to get it to resume its route once the "maneuver" is finished...

 

Hi Nicolas, the only way I actually found to handle that is :

- get route/WP using mist function

- get trace of WP already reached using a flag (value +1 when a new WP is reached)

- and resume route, updated by removing already reached WP using this little function :

function GoUDRoute()
GroupRoute = mist.getGroupRoute(GroupName, true)
for i = 1, trigger.misc.getUserFlag(FlagName) do
table.remove(GroupRoute, 1)
end
mist.goRoute(GroupName, GroupRoute)
end

Have a nice day

Pierre

Posted

@dimitriov if you want to see a working example using it (in the example - replacement of an aircraft by same aircraft but from enemy coalition to act as defection, that continues the route of previous aircraft from the point where it is spawned -  I use mist.getCurrentGroupData and mist.getGroupData instead of mist.getGroupRoute, but works the same) you can download this .miz :

 

 

Posted

Problem is that I would like to avoid using MIST... Usually if needed I copy paste one of its functions on my side but here the function getgrouproute simply uses too many subfunctions to do it in a clean way... :s

Posted (edited)

@dimitriov I wrote the script with env.mission datas and used setTask Mission to resume route and put it in this example. (so without using mist)

The vehicle enters a zone ("debut tir") that activates a triggered task (fire on point) using AI SET TASK (so this task deletes the route, and without action when the task is complete the vehicle just stands on place without resuming). 45 seconds after "debut tir" task, the function ResumeRoute is used with groupname and flagname as parameters and the vehicle resumes its route toward remaining waypoints.

Only requirement, apart using the function when needed to resume, is to set flag value for waypoints > 0 (value = 1 for wpt 1 etc...) by script in advanced wpt action.

 

Edited by toutenglisse
removed miz
  • Like 1
Posted

@dimitriov there is a flaw in my script. It works if used once by each vehicle groups, but issue raise if function is used multiple times by a group (due to flags values being manually set and to the way env.mission updates points when setTask Mission is used).

Here is the updated miz example (script is updated and instead of manually set flag values for wpts > 0, each wpt need to set flag value = flag value +1).

test-GroundVeh-resume-route-after-setTask.miz

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...