Reworked unit as as state machine, added formations, added measuring on map, added copy-paste

This commit is contained in:
Pax1601
2023-02-01 21:38:36 +01:00
parent bb7259d908
commit 3c1db67733
74 changed files with 4838 additions and 907 deletions

View File

@@ -37,10 +37,10 @@ function Olympus.getCoalitionByCoalitionID(coalitionID)
end
-- Builds a valid task depending on the provided options
function Olympus.buildTask(options)
function Olympus.buildEnrouteTask(options)
local task = nil
-- Engage specific target by ID. Checks if target exists.
if options['id'] == 'EngageUnit' and options['targetID'] ~= nil then
if options['id'] == 'EngageUnit' and options['targetID'] then
local target = Olympus.getUnitByID(options['targetID'])
if target and target:isExist() then
task = {
@@ -54,7 +54,28 @@ function Olympus.buildTask(options)
return task
end
-- Move a unit. Since most tasks in DCS are Enroute tasks, this function is the main way to control the unit AI
-- Builds a valid task depending on the provided options
function Olympus.buildTask(options)
local task = nil
-- Engage specific target by ID. Checks if target exists.
if options['id'] == 'FollowUnit' and options['leaderID'] and options['offset'] then
local leader = Olympus.getUnitByID(options['leaderID'])
if leader and leader:isExist() then
task = {
id = 'Follow',
params = {
groupId = leader:getGroup():getID(),
pos = options['offset'],
lastWptIndexFlag = false,
lastWptIndex = 1
}
}
end
end
return task
end
-- Move a unit. Since many tasks in DCS are Enroute tasks, this function is an important way to control the unit AI
function Olympus.move(ID, lat, lng, altitude, speed, category, taskOptions)
Olympus.notify("Olympus.move " .. ID .. " (" .. lat .. ", " .. lng ..") " .. altitude .. "m " .. speed .. "m/s " .. category, 2)
local unit = Olympus.getUnitByID(ID)
@@ -69,10 +90,12 @@ function Olympus.move(ID, lat, lng, altitude, speed, category, taskOptions)
}
-- If a task exists assign it to the controller
local task = Olympus.buildTask(taskOptions)
if task then
path[1].task = task
path[2].task = task
if taskOptions then
local task = Olympus.buildEnrouteTask(taskOptions)
if task then
path[1].task = task
path[2].task = task
end
end
-- Assign the mission task to the controller
@@ -171,7 +194,7 @@ function Olympus.spawnAircraft(coalition, unitType, lat, lng, spawnOptions)
local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0))
if payload == nil then
if payloadName and payloadName ~= "" and Olympus.unitPayloads[unitType][payloadName] ~= nil then
if payloadName and payloadName ~= "" and Olympus.unitPayloads[unitType][payloadName] then
payload = Olympus.unitPayloads[unitType][payloadName]
else
payload = {}
@@ -275,24 +298,77 @@ function Olympus.clone(ID)
Olympus.notify("Olympus.clone completed successfully", 2)
end
function Olympus.follow(leaderID, ID)
Olympus.notify("Olympus.follow " .. ID .. " " .. leaderID, 2)
local leader = Olympus.getUnitByID(leaderID)
function Olympus.setTask(ID, taskOptions)
Olympus.notify("Olympus.setTask " .. ID .. " " .. Olympus.serializeTable(taskOptions), 2)
local unit = Olympus.getUnitByID(ID)
local followTask = {
id = 'Follow',
params = {
groupId = leader:getGroup():getID(),
pos = {x = 0 , y = 0, z = 20} ,
lastWptIndexFlag = false,
lastWptIndex = 1
}
}
Olympus.notify("Olympus.follow group ID" .. unit:getGroup():getID(), 2)
unit:getGroup():getController():pushTask(followTask)
Olympus.notify("Olympus.follow completed successfully", 2)
if unit then
local task = Olympus.buildTask(taskOptions);
if task then
unit:getGroup():getController():setTask(task)
Olympus.notify("Olympus.setTask completed successfully", 2)
end
end
end
function Olympus.resetTask(ID)
Olympus.notify("Olympus.resetTask " .. ID, 2)
local unit = Olympus.getUnitByID(ID)
if unit then
unit:getGroup():getController():resetTask()
Olympus.notify("Olympus.resetTask completed successfully", 2)
end
end
function Olympus.setCommand(ID, command)
Olympus.notify("Olympus.setCommand " .. ID .. " " .. Olympus.serializeTable(command), 2)
local unit = Olympus.getUnitByID(ID)
if unit then
unit:getGroup():getController():setCommand(command)
Olympus.notify("Olympus.setCommand completed successfully", 2)
end
end
function Olympus.setOption(ID, optionID, optionValue)
Olympus.notify("Olympus.setCommand " .. ID .. " " .. optionID .. " " .. optionValue, 2)
local unit = Olympus.getUnitByID(ID)
if unit then
unit:getGroup():getController():setOption(optionID, optionValue)
Olympus.notify("Olympus.setOption completed successfully", 2)
end
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
Olympus.notify("OlympusCommand script loaded successfully", 2)

View File

@@ -8,11 +8,14 @@ function Olympus.setMissionData(arg, time)
local missionData = {}
-- Bullseye data
local bullseyeVec3 = coalition.getMainRefPoint(0)
local bullseyeLatitude, bullseyeLongitude, bullseyeAltitude = coord.LOtoLL(bullseyeVec3)
local bullseye = {}
bullseye["lat"] = bullseyeLatitude
bullseye["lng"] = bullseyeLongitude
for i = 0, 2 do
local bullseyeVec3 = coalition.getMainRefPoint(i)
local bullseyeLatitude, bullseyeLongitude, bullseyeAltitude = coord.LOtoLL(bullseyeVec3)
bullseye[i] = {}
bullseye[i]["lat"] = bullseyeLatitude
bullseye[i]["lng"] = bullseyeLongitude
end
-- Units tactical data
-- TODO find some way to spread the load of getting this data (split)
@@ -29,6 +32,8 @@ function Olympus.setMissionData(arg, time)
table["targets"]["radar"] = controller:getDetectedTargets(4)
table["targets"]["rwr"] = controller:getDetectedTargets(16)
table["targets"]["other"] = controller:getDetectedTargets(2, 8, 32)
table["hasTask"] = controller:hasTask()
table["ammo"] = unit:getAmmo()
table["fuel"] = unit:getFuel()

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +0,0 @@
try:
# Python 2
from SimpleHTTPServer import test, SimpleHTTPRequestHandler
except ImportError:
# Python 3
from http.server import test, SimpleHTTPRequestHandler
test(SimpleHTTPRequestHandler)

View File

@@ -1,44 +0,0 @@
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(
['server.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='server',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)