mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added feature: select unit payload at spawn and visibility.
This commit is contained in:
@@ -5,34 +5,63 @@ function Olympus.notify(message, displayFor)
|
||||
trigger.action.outText(message, displayFor)
|
||||
end
|
||||
|
||||
function Olympus.move(unitName, lat, lng, v, category)
|
||||
Olympus.notify("Olympus.move " .. unitName .. " (" .. lat .. ", " .. lng ..")", 10)
|
||||
function Olympus.move(unitName, lat, lng, altitude, speed, category, targetName)
|
||||
Olympus.notify("Olympus.move " .. unitName .. " (" .. lat .. ", " .. lng ..") " .. altitude .. "m " .. speed .. "m/s " .. category .. " target " .. targetName, 10)
|
||||
local unit = Unit.getByName(unitName)
|
||||
if unit ~= nil then
|
||||
if category == 1 then
|
||||
local startPoint = mist.getLeadPos(unit:getGroup())
|
||||
if category == "Aircraft" then
|
||||
local startPoint = mist.getLeadPos(unit:getGroup())
|
||||
local endPoint = coord.LLtoLO(lat, lng, 0)
|
||||
|
||||
local task = nil
|
||||
if targetName ~= "" then
|
||||
targetID = Unit.getByName(targetName):getID()
|
||||
task = {
|
||||
id = 'EngageUnit',
|
||||
params = {
|
||||
unitId = targetID,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
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(startPoint, flyOverPoint, speed, altitude, 'BARO')
|
||||
if task ~= nil then
|
||||
path[#path].task = task
|
||||
end
|
||||
path[#path + 1] = mist.fixedWing.buildWP(endPoint, turningPoint, speed, altitude, 'BARO')
|
||||
if task ~= nil then
|
||||
path[#path].task = task
|
||||
end
|
||||
|
||||
mist.goRoute(unit:getGroup(), path)
|
||||
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.move executed succesfully on a air unit", 10)
|
||||
elseif category == 2 then
|
||||
elseif category == "GroundUnit" then
|
||||
vars =
|
||||
{
|
||||
group = unit:getGroup(),
|
||||
point = coord.LLtoLO(lat, lng, 0),
|
||||
form = "Off Road",
|
||||
heading = 0,
|
||||
speed = v,
|
||||
speed = speed,
|
||||
disableRoads = true
|
||||
}
|
||||
mist.groupToRandomPoint(vars)
|
||||
Olympus.notify("Olympus.move executed succesfully on a ground unit", 10)
|
||||
else
|
||||
Olympus.notify("Olympus.move not implemented yet for navy units", 10)
|
||||
Olympus.notify("Olympus.move not implemented yet for " .. category, 10)
|
||||
end
|
||||
else
|
||||
Olympus.notify("Error in Olympus.move " .. unitName, 10)
|
||||
@@ -90,23 +119,26 @@ function Olympus.spawnGround(coalition, type, lat, lng, ID)
|
||||
Olympus.notify("Olympus.spawnGround completed succesfully", 10)
|
||||
end
|
||||
|
||||
function Olympus.spawnAir(coalition, type, lat, lng, alt)
|
||||
Olympus.notify("Olympus.spawnAir " .. coalition .. " " .. type .. " (" .. lat .. ", " .. lng ..")", 10)
|
||||
function Olympus.spawnAir(coalition, unitType, lat, lng, payloadName)
|
||||
local alt = 5000
|
||||
Olympus.notify("Olympus.spawnAir " .. coalition .. " " .. unitType .. " (" .. lat .. ", " .. lng ..") " .. payloadName, 10)
|
||||
local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0))
|
||||
local payload = {}
|
||||
if Olympus.unitPayloads[unitType][payloadName] ~= nil then
|
||||
payload = Olympus.unitPayloads[unitType][payloadName]
|
||||
end
|
||||
local unitTable =
|
||||
{
|
||||
[1] =
|
||||
{
|
||||
["type"] = type,
|
||||
["type"] = unitType,
|
||||
["x"] = spawnLocation.x,
|
||||
["y"] = spawnLocation.z,
|
||||
["alt"] = alt,
|
||||
["skill"] = "Excellent",
|
||||
["payload"] =
|
||||
{
|
||||
["pylons"] =
|
||||
{
|
||||
},
|
||||
["pylons"] = payload,
|
||||
["fuel"] = 4900,
|
||||
["flare"] = 60,
|
||||
["ammo_type"] = 1,
|
||||
@@ -146,53 +178,4 @@ function Olympus.spawnAir(coalition, type, lat, lng, alt)
|
||||
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)
|
||||
@@ -5,29 +5,86 @@ function Olympus.notify(message, displayFor)
|
||||
end
|
||||
|
||||
function Olympus.setMissionData(arg, time)
|
||||
local missionData = {}
|
||||
|
||||
-- Bullseye data
|
||||
local bullseyeVec3 = coalition.getMainRefPoint(0)
|
||||
local bullseyeLatitude, bullseyeLongitude, bullseyeAltitude = coord.LOtoLL(bullseyeVec3)
|
||||
local command = "Olympus.missionData = " ..
|
||||
"{" ..
|
||||
"bullseye = {" ..
|
||||
"x = " .. bullseyeVec3.x .. "," ..
|
||||
"y = " .. bullseyeVec3.z .. "," ..
|
||||
"lat = " .. bullseyeLatitude .. "," ..
|
||||
"lng = " .. bullseyeLongitude .. "," ..
|
||||
"}," ..
|
||||
"}\n" ..
|
||||
"Olympus.OlympusDLL.setMissionData()"
|
||||
local bullseye = {}
|
||||
bullseye["x"] = bullseyeVec3.x
|
||||
bullseye["y"] = bullseyeVec3.z
|
||||
bullseye["lat"] = bullseyeLatitude
|
||||
bullseye["lng"] = bullseyeLongitude
|
||||
|
||||
for groupName, group in pairs(mist.DBs.groupsByName) do
|
||||
if groupName and group then
|
||||
local hasTask = Group.getByName(groupName):getController():hasTask()
|
||||
Olympus.notify(groupName .. ": " .. tostring(hasTask), 2)
|
||||
-- Units tactical data
|
||||
-- TODO find some way to spread the load of getting this data (split)
|
||||
local unitsData = {}
|
||||
for groupName, gp in pairs(mist.DBs.groupsByName) do
|
||||
if groupName ~= nil then
|
||||
local group = Group.getByName(groupName)
|
||||
if group ~= nil then
|
||||
local controller = group:getController()
|
||||
for index, unit in pairs(group:getUnits()) do
|
||||
local table = {}
|
||||
table["targets"] = {}
|
||||
table["targets"]["visual"] = controller:getDetectedTargets(1)
|
||||
table["targets"]["radar"] = controller:getDetectedTargets(4)
|
||||
table["targets"]["rwr"] = controller:getDetectedTargets(16)
|
||||
table["targets"]["other"] = controller:getDetectedTargets(2, 8, 32)
|
||||
|
||||
table["ammo"] = unit:getAmmo()
|
||||
table["fuel"] = unit:getFuel()
|
||||
table["life"] = unit:getLife() / unit:getLife0()
|
||||
unitsData[unit:getObjectID()] = table
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Assemble missionData table
|
||||
missionData["bullseye"] = bullseye
|
||||
missionData["unitsData"] = unitsData
|
||||
|
||||
local command = "Olympus.missionData = " .. Olympus.serializeTable(missionData) .. "\n" .. "Olympus.OlympusDLL.setMissionData()"
|
||||
net.dostring_in("export", command)
|
||||
return time + 5
|
||||
end
|
||||
|
||||
function Olympus.serializeTable(val, name, skipnewlines, depth)
|
||||
skipnewlines = skipnewlines or false
|
||||
depth = depth or 0
|
||||
|
||||
local tmp = string.rep(" ", depth)
|
||||
|
||||
|
||||
if name then
|
||||
if type(name) == "number" then
|
||||
tmp = tmp .. "[" .. name .. "]" .. " = "
|
||||
else
|
||||
tmp = tmp .. name .. " = "
|
||||
end
|
||||
end
|
||||
|
||||
if type(val) == "table" then
|
||||
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
|
||||
|
||||
for k, v in pairs(val) do
|
||||
tmp = tmp .. Olympus.serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
|
||||
end
|
||||
|
||||
tmp = tmp .. string.rep(" ", depth) .. "}"
|
||||
elseif type(val) == "number" then
|
||||
tmp = tmp .. tostring(val)
|
||||
elseif type(val) == "string" then
|
||||
tmp = tmp .. string.format("%q", val)
|
||||
elseif type(val) == "boolean" then
|
||||
tmp = tmp .. (val and "true" or "false")
|
||||
else
|
||||
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
|
||||
end
|
||||
|
||||
return tmp
|
||||
end
|
||||
|
||||
timer.scheduleFunction(Olympus.setMissionData, {}, timer.getTime() + 1)
|
||||
Olympus.notify("OlympusMission script loaded correctly", 10)
|
||||
|
||||
75
scripts/generatePayloadTables.py
Normal file
75
scripts/generatePayloadTables.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from slpp import slpp as lua
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
SEARCH_FOLDER = "D:\\Eagle Dynamics\\DCS World OpenBeta"
|
||||
|
||||
def dump_lua(data):
|
||||
if type(data) is str:
|
||||
return f'"{data}"'
|
||||
if type(data) in (int, float):
|
||||
return f'{data}'
|
||||
if type(data) is bool:
|
||||
return data and "true" or "false"
|
||||
if type(data) is list:
|
||||
l = "{"
|
||||
l += ",\n ".join([dump_lua(item) for item in data])
|
||||
l += "}"
|
||||
return l
|
||||
if type(data) is dict:
|
||||
t = "{"
|
||||
t += ",\n ".join([f'[{k}] = {dump_lua(v)}' if type(k) == int else f'["{k}"]={dump_lua(v)}' for k,v in data.items()])
|
||||
t += "}"
|
||||
return t
|
||||
|
||||
logging.error(f"Unknown type {type(data)}")
|
||||
|
||||
filenames = [os.path.join(dp, f) for dp, dn, filenames in os.walk(SEARCH_FOLDER) for f in filenames if os.path.splitext(f)[1] == '.lua']
|
||||
|
||||
for filename in list(filenames):
|
||||
with open(filename, 'r') as f:
|
||||
try:
|
||||
if f.read().find("unitPayloads") == -1:
|
||||
filenames.remove(filename)
|
||||
except:
|
||||
filenames.remove(filename)
|
||||
logging.warning(f"{filename} skipped...")
|
||||
pass
|
||||
|
||||
names = {}
|
||||
payloads = {}
|
||||
for filename in filenames:
|
||||
with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
|
||||
try:
|
||||
lines = f.read()
|
||||
searchString = "local unitPayloads = {"
|
||||
start = lines.find(searchString)
|
||||
end = lines.rfind("}")
|
||||
tmp = lua.decode(lines[start + len(searchString) - 1: end + 1])
|
||||
if type(tmp['payloads']) == dict:
|
||||
src = tmp['payloads'].values()
|
||||
else:
|
||||
src = tmp['payloads']
|
||||
|
||||
names[tmp['unitType']] = []
|
||||
payloads[tmp['unitType']] = {}
|
||||
for payload in src:
|
||||
names[tmp['unitType']].append(payload['name'])
|
||||
if type(payload['pylons']) == dict:
|
||||
payloads[tmp['unitType']][payload['name']] = {payload['pylons'][key]['num']: {"CLSID" : payload['pylons'][key]['CLSID']} for key in payload['pylons']}
|
||||
else:
|
||||
payloads[tmp['unitType']][payload['name']] = {payload['pylons'][key]['num']: {"CLSID" : payload['pylons'][key]['CLSID']} for key in range(len(payload['pylons']))}
|
||||
except:
|
||||
pass
|
||||
|
||||
with open('payloadNames.js', 'w') as f:
|
||||
f.write("payloadNames = ")
|
||||
json.dump(names, f, ensure_ascii = False)
|
||||
|
||||
with open('unitPayloads.lua', 'w') as f:
|
||||
f.write("Olympus.unitPayloads = " + dump_lua(payloads))
|
||||
|
||||
|
||||
|
||||
|
||||
1
scripts/payloadNames.js
Normal file
1
scripts/payloadNames.js
Normal file
File diff suppressed because one or more lines are too long
12586
scripts/unitPayloads.lua
Normal file
12586
scripts/unitPayloads.lua
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user