Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Active = false
- ObjDetails = {}
- TargetHeight = -1 -- -1 results in using current Height--
- Mode = 0 --0 = Nav, 1 = Combat--
- TargetData = {}
- Friendlies = {}
- TX = 0
- TY = 0
- CX = 0
- CY = 0
- CH = 0
- MissionGiver()
- --Inputs, 1 CX, 2 CY, 3 CHeight, 4 CHeading, 5 Obj X, 6 Obj Y, 7 THeight, 8 9 10 Target/friendly updates,
- -- Bools, 1 Active, 2 Recieving Obj, 3 ,4 ,5 Receiving Target, 6 Receiving Friendly
- --outputs, 1 X, 2 Y, 3 Mission, 4 Up/Down, 6 Target X, 7 Target Y,
- --Bools, 1, 2 Return after Obj, 3 Land at Obj
- function onTick()
- Active = input.getBool(1)
- if input.getBool(5) == true then
- UpdateTargets(input.getNumber(8),input.getNumber(9))
- end
- if input.getBool(6) == true then
- UpdateFriendlies(input.getNumber(8),input.getNumber(9),input.getNumber(10))
- end
- if Active == true then
- Decision()
- end
- HeightMaintainer()
- TurretManager()
- end
- function UpdateTargets(X,Y)--checks list of targets and see if the target is a new one or is a existing one that moved
- Pass = false
- if #TargetData > 0 then
- for i = 1, #TargetData do
- Dis = math.sqrt((X-TargetData[i][2])^2 + (Y - TargetData[i][3])^2)
- if Pass == false and Dis < 20 then
- Pass = true
- TargetData[i][2] = X
- TargetData[i][3] = Y
- end
- end
- end
- if Pass == false then
- TargetData[#TargetData + 1] = {true, X, Y}
- end
- end
- function UpdateFriendlies(X,Y,ID)--updates list of friendlies received from Friend or Foe Component
- Pass = false
- if #Friendlies > 0 then
- for i = 1, #Friendlies do
- if ID == Friendlies[i][1] then
- Pass = true
- Friendlies[i][2] = X
- Friendlies[i][3] = Y
- end
- end
- end
- if Pass == false then
- Friendlies[#Friendlies + 1] = {ID, X, Y}
- end
- end
- function Decision()
- Combat = false
- Dis = 1000
- if #TargetData > 0 then
- for i = 1, #TargetData do
- for I = 1, #Friendlies do
- Dis = math.sqrt((Friendlies[I][2]-TargetData[i][2])^2 + (Friendlies[I][3] - TargetData[i][3])^2)
- end
- if Dis > 20 then
- TX = TargetData[i][2]
- TY = TargetData[i][3]
- Combat = true
- end
- end
- end
- if Combat == true then
- else
- TX = 0
- TY = 0
- end
- end
- function TurretManager()--this gives Turret script Cords to work with, the turret script converts this and given ground alt to target ground targets
- if TX == 0 and TY == 0 then
- output.setNumber(6,0)--X
- output.setNumber(7,0)--Y
- else
- output.setNumber(6,TX)
- output.setNumber(7,TY)
- end
- end
- function HeightMaintainer()
- Diff = 0
- CHeight = input.getNumber(3)
- UpDown = 0
- if TargetHeight == -1 then
- Diff = 0
- else
- Diff = TargetHeight - CHeight
- end
- if Diff == 0 then
- UpDown = 0
- elseif CHeight > TargetHeight then
- UpDown = -1
- elseif CHeight < TargetHeight then
- UpDown = 1
- end
- output.setNumber(4,UpDown)
- end
- function MissionGiver()
- MisType = property.getNumber("MissionType")
- Land = false
- RetAf = false
- if MisType == 1 then
- RetAf = true
- elseif MisType == 2 then
- RetAf = true
- Land = true
- end
- output.setBool(1,true)
- output.setNumber(3,MisType)
- output.setBool(2,RetAf)
- output.setBool(3,Land)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement