Started air fighter AI

This commit is contained in:
Pax1601
2022-12-21 19:18:20 +01:00
parent 3a46a6df21
commit de055c5a98
1766 changed files with 137925 additions and 501 deletions

View File

@@ -1,22 +1,21 @@
Olympus = {}
Olympus.unitCounter = 1
function Olympus.notify(message, displayFor)
function Olympus.notify(message, displayFor)
trigger.action.outText(message, displayFor)
end
function Olympus.move(name, lat, lng, v, category)
Olympus.notify("Olympus.move " .. name .. " (" .. lat .. ", " .. lng ..")", 10)
local unit = Unit.getByName(name)
function Olympus.move(unitName, lat, lng, v, category)
Olympus.notify("Olympus.move " .. unitName .. " (" .. lat .. ", " .. lng ..")", 10)
local unit = Unit.getByName(unitName)
if unit ~= nil then
if category == 1 then
local startPoint = mist.getLeadPos(unit:getGroup())
local endPoint = coord.LLtoLO(lat, lng, 0)
local endPoint = airbasePos
local path = {}
path[#path + 1] = mist.fixedWing.buildWP(startPoint, flyOverPoint, v, startPoint.y, 'BARO')
path[#path + 1] = mist.fixedWing.buildWP(endPoint, TurningPoint, v, startPoint.y, 'BARO')
path[#path + 1] = mist.fixedWing.buildWP(endPoint, turningPoint, v, startPoint.y, 'BARO')
mist.goRoute(unit:getGroup(), path)
Olympus.notify("Olympus.move executed succesfully on a air unit", 10)
@@ -36,7 +35,7 @@ function Olympus.move(name, lat, lng, v, category)
Olympus.notify("Olympus.move not implemented yet for navy units", 10)
end
else
Olympus.notify("Error in Olympus.move " .. name, 10)
Olympus.notify("Error in Olympus.move " .. unitName, 10)
end
end
@@ -57,7 +56,7 @@ function Olympus.smoke(color, lat, lng)
trigger.action.smoke(mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0)), colorEnum)
end
function Olympus.spawnGround(coalition, type, lat, lng)
function Olympus.spawnGround(coalition, type, lat, lng, ID)
Olympus.notify("Olympus.spawnGround " .. coalition .. " " .. type .. " (" .. lat .. ", " .. lng ..")", 10)
local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0))
local unitTable =
@@ -91,177 +90,109 @@ function Olympus.spawnGround(coalition, type, lat, lng)
Olympus.notify("Olympus.spawnGround completed succesfully", 10)
end
function Olympus.spawnAir(coalition, type, lat, lng, alt)
--https://wiki.hoggitworld.com/view/MIST_dynAdd
Olympus.notify("Olympus.spawnAir " .. coalition .. " " .. type .. " (" .. lat .. ", " .. lng ..")", 10)
local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0))
plane = {
["modulation"] = 0,
["tasks"] =
local unitTable =
{
[1] =
{
}, -- end of ["tasks"]
["radioSet"] = false,
["task"] = "CAP",
["uncontrolled"] = false,
["route"] =
{
["points"] =
["type"] = type,
["x"] = spawnLocation.x,
["y"] = spawnLocation.z,
["alt"] = alt,
["skill"] = "Excellent",
["payload"] =
{
[1] =
["pylons"] =
{
["alt"] = 2000,
["action"] = "Turning Point",
["alt_type"] = "BARO",
["speed"] = 179.86111111111,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["type"] = "Turning Point",
["ETA"] = 0,
["ETA_locked"] = true,
["x"] = spawnLocation.x,
["y"] = spawnLocation.z,
["formation_template"] = "",
["speed_locked"] = true,
}, -- end of [1]
[2] =
{
["alt"] = 2000,
["action"] = "Turning Point",
["alt_type"] = "BARO",
["speed"] = 179.86111111111,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["type"] = "Turning Point",
["ETA"] = 500.42644231043,
["ETA_locked"] = false,
["x"] = spawnLocation.x + 10000,
["y"] = spawnLocation.z,
["formation_template"] = "",
["speed_locked"] = true,
}, -- end of [2]
}, -- end of ["points"]
}, -- end of ["route"]
["groupId"] = 10,
["hidden"] = false,
["units"] =
{
[1] =
},
["fuel"] = 4900,
["flare"] = 60,
["ammo_type"] = 1,
["chaff"] = 60,
["gun"] = 100,
},
["heading"] = 0,
["callsign"] =
{
["alt"] = 2000,
["alt_type"] = "BARO",
["skill"] = "Excellent",
["speed"] = 180,
["AddPropAircraft"] =
{
}, -- end of ["AddPropAircraft"]
["type"] = type,
["unitId"] = 10,
["psi"] = 0.015782716092426,
["dataCartridge"] =
{
["GroupsPoints"] =
{
["PB"] =
{
}, -- end of ["PB"]
["Sequence 2 Red"] =
{
}, -- end of ["Sequence 2 Red"]
["Start Location"] =
{
}, -- end of ["Start Location"]
["Sequence 1 Blue"] =
{
}, -- end of ["Sequence 1 Blue"]
["Sequence 3 Yellow"] =
{
}, -- end of ["Sequence 3 Yellow"]
["A/A Waypoint"] =
{
}, -- end of ["A/A Waypoint"]
["PP"] =
{
}, -- end of ["PP"]
["Initial Point"] =
{
}, -- end of ["Initial Point"]
}, -- end of ["GroupsPoints"]
["Points"] =
{
}, -- end of ["Points"]
}, -- end of ["dataCartridge"]
["x"] = spawnLocation.x,
["y"] = spawnLocation.z,
["name"] = "Olympus-" .. Olympus.unitCounter,
["payload"] =
{
["pylons"] =
{
[7] =
{
["CLSID"] = "{7575BA0B-7294-4844-857B-031A144B2595}",
}, -- end of [7]
[3] =
{
["CLSID"] = "{7575BA0B-7294-4844-857B-031A144B2595}",
}, -- end of [3]
}, -- end of ["pylons"]
["fuel"] = 4900,
["flare"] = 60,
["ammo_type"] = 1,
["chaff"] = 60,
["gun"] = 100,
}, -- end of ["payload"]
["heading"] = 0,
["callsign"] =
{
[1] = 1,
[2] = 1,
[3] = 1,
["name"] = "Enfield11",
}, -- end of ["callsign"]
["onboard_num"] = "010",
[1] = 1,
[2] = 1,
[3] = 1,
["name"] = "Enfield11",
},
}, -- end of ["units"]
["x"] = spawnLocation.x,
["y"] = spawnLocation.z,
["name"] = "Olympus-" .. Olympus.unitCounter,
["communication"] = true,
["start_time"] = 0,
["frequency"] = 305,
},
}
--loads of other stuff you can do with this but this is probably what you need to startPoint
--you can also set a route here, and included first waypoint as spawn on airbases etc
--https://github.com/pydcs/dcs/blob/master/dcs/weapons_data.py all weapon pylon types
local countryID = nil
if coalition == 'red' then
plane.country = 'Russia'
countryID = country.id.RUSSIA
else
plane.country = 'USA'
countryID = country.id.USA
end
plane.category = 'airplane'
mist.dynAdd(plane)
local vars =
{
units = unitTable,
country = countryID,
category = 'airplane',
task = "CAP",
tasks = {},
name = "Olympus-" .. Olympus.unitCounter,
}
mist.dynAdd(vars)
Olympus.unitCounter = Olympus.unitCounter + 1
Olympus.notify("Olympus.spawnAir completed succesfully", 10)
end
function Olympus.attackUnit(unitName, targetName, lat, lng)
Olympus.notify("Olympus.attackUnit " .. unitName .. " " .. targetName, 10)
local targetID = Unit.getByName(targetName):getID()
local unit = Unit.getByName(unitName)
local category = 1
if unit ~= nil then
if category == 1 then
local startPoint = mist.getLeadPos(unit:getGroup())
local endPoint = coord.LLtoLO(lat, lng, 0)
local attackTask = {
id = 'EngageUnit',
params = {
unitId = targetID,
}
}
local path = {}
path[#path + 1] = mist.fixedWing.buildWP(startPoint, flyOverPoint, v, startPoint.y, 'BARO')
path[#path].task = attackTask
path[#path + 1] = mist.fixedWing.buildWP(endPoint, turningPoint, v, startPoint.y, 'BARO')
path[#path].task = attackTask
local missionTask = {
id = 'Mission',
params = {
route = {
points = mist.utils.deepCopy(path),
},
},
}
group = unit:getGroup()
local groupCon = group:getController()
if groupCon then
groupCon:setTask(missionTask)
end
Olympus.notify("Olympus.attackUnit completed succesfully", 10)
elseif category == 2 then
Olympus.notify("Olympus.attackUnit not implemented yet for ground units", 10)
else
Olympus.notify("Olympus.attackUnit not implemented yet for navy units", 10)
end
end
end
Olympus.notify("OlympusCommand script loaded correctly", 10)