mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Fixed errors in lua clone units
This commit is contained in:
@@ -201,7 +201,7 @@ export function followUnit(ID: number, targetID: number, offset: { "x": number,
|
|||||||
|
|
||||||
export function cloneUnits(units: {ID: number, location: LatLng}[], callback: CallableFunction = () => {}) {
|
export function cloneUnits(units: {ID: number, location: LatLng}[], callback: CallableFunction = () => {}) {
|
||||||
var command = { "units": units };
|
var command = { "units": units };
|
||||||
var data = { "cloneUnit": command }
|
var data = { "cloneUnits": command }
|
||||||
POST(data, callback);
|
POST(data, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -557,14 +557,18 @@ export class UnitsManager {
|
|||||||
// TODO handle from lua
|
// TODO handle from lua
|
||||||
selectedUnitsCreateGroup() {
|
selectedUnitsCreateGroup() {
|
||||||
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
|
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
|
||||||
var units = [];
|
var units: { ID: number, location: LatLng }[] = [];
|
||||||
var coalition = "neutral";
|
var coalition = "neutral";
|
||||||
for (let idx in selectedUnits) {
|
for (let idx in selectedUnits) {
|
||||||
var unit = selectedUnits[idx];
|
var unit = selectedUnits[idx];
|
||||||
coalition = unit.getCoalition();
|
coalition = unit.getCoalition();
|
||||||
units.push({ ID: unit.ID, location: unit.getPosition() });
|
units.push({ ID: unit.ID, location: unit.getPosition() });
|
||||||
}
|
}
|
||||||
cloneUnits(units);
|
cloneUnits(units, () => {
|
||||||
|
units.forEach((unit: any) => {
|
||||||
|
deleteUnit(unit.ID, false, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -597,8 +601,8 @@ export class UnitsManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* Clone the units in groups */
|
/* Clone the units in groups */
|
||||||
var units: { ID: number, location: LatLng }[] = [];
|
|
||||||
for (let groupName in groups) {
|
for (let groupName in groups) {
|
||||||
|
var units: { ID: number, location: LatLng }[] = [];
|
||||||
groups[groupName].forEach((unit: any) => {
|
groups[groupName].forEach((unit: any) => {
|
||||||
var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng);
|
var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng);
|
||||||
getMap().addTemporaryMarker(position, unit.name, unit.coalition);
|
getMap().addTemporaryMarker(position, unit.name, unit.coalition);
|
||||||
@@ -606,7 +610,7 @@ export class UnitsManager {
|
|||||||
});
|
});
|
||||||
cloneUnits(units);
|
cloneUnits(units);
|
||||||
}
|
}
|
||||||
getInfoPopup().setText(`${this.#copiedUnits.length - 1} units pasted`);
|
getInfoPopup().setText(`${this.#copiedUnits.length} units pasted`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getInfoPopup().setText(`Unit cloning is disabled in ${getMissionHandler().getCommandModeOptions().commandMode} mode`);
|
getInfoPopup().setText(`Unit cloning is disabled in ${getMissionHandler().getCommandModeOptions().commandMode} mode`);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local version = "v0.4.4-alpha"
|
local version = "v0.4.4-alpha"
|
||||||
|
|
||||||
local debug = false
|
local debug = true
|
||||||
|
|
||||||
Olympus.OlympusDLL = nil
|
Olympus.OlympusDLL = nil
|
||||||
Olympus.DLLsloaded = false
|
Olympus.DLLsloaded = false
|
||||||
@@ -410,7 +410,7 @@ function Olympus.spawnUnits(spawnTable)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Save the units in the database, for cloning
|
-- Save the units in the database, for cloning
|
||||||
for idx, unitTable in pairs(unitTable) do
|
for idx, unitTable in pairs(unitsTable) do
|
||||||
Olympus.addToDatabase(unitTable)
|
Olympus.addToDatabase(unitTable)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -600,13 +600,14 @@ end
|
|||||||
|
|
||||||
-- Clones a unit by ID. Will clone the unit with the same original payload as the source unit. TODO: only works on Olympus unit not ME units (TO BE VERIFIED).
|
-- Clones a unit by ID. Will clone the unit with the same original payload as the source unit. TODO: only works on Olympus unit not ME units (TO BE VERIFIED).
|
||||||
function Olympus.clone(cloneTable)
|
function Olympus.clone(cloneTable)
|
||||||
Olympus.debug("Olympus.clone " .. cloneTable, 2)
|
Olympus.debug("Olympus.clone " .. Olympus.serializeTable(cloneTable), 2)
|
||||||
|
|
||||||
local unitsTable = {}
|
local unitsTable = {}
|
||||||
local coalition = nil
|
local countryID = nil
|
||||||
local category = nil
|
local category = nil
|
||||||
|
local route = {}
|
||||||
|
|
||||||
for cloneData, idx in pairs(cloneTable) do
|
for idx, cloneData in pairs(cloneTable) do
|
||||||
local ID = cloneData.ID
|
local ID = cloneData.ID
|
||||||
local unit = Olympus.getUnitByID(ID)
|
local unit = Olympus.getUnitByID(ID)
|
||||||
|
|
||||||
@@ -617,26 +618,78 @@ function Olympus.clone(cloneTable)
|
|||||||
-- Update the data of the cloned unit
|
-- Update the data of the cloned unit
|
||||||
local unitTable = Olympus.spawnDatabase[unit:getName()]
|
local unitTable = Olympus.spawnDatabase[unit:getName()]
|
||||||
|
|
||||||
|
local point = coord.LLtoLO(cloneData['lat'], cloneData['lng'], 0)
|
||||||
if unitTable then
|
if unitTable then
|
||||||
unitTable["lat"] = lat
|
unitTable["x"] = point.x
|
||||||
unitTable["lng"] = lng
|
unitTable["y"] = point.z
|
||||||
unitTable["alt"] = unit:getPoint().y
|
unitTable["alt"] = unit:getPoint().y
|
||||||
unitTable["heading"] = heading
|
unitTable["heading"] = heading
|
||||||
|
unitTable["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
coalition = Olympus.getCoalitionByCoalitionID(unit:getCoalition()),
|
if countryID == nil and category == nil then
|
||||||
category = unit:getDesc().category,
|
countryID = unit:getCountry()
|
||||||
|
if unit:getDesc().category == Unit.Category.AIRPLANE then
|
||||||
|
category = 'plane'
|
||||||
|
route = {
|
||||||
|
["points"] =
|
||||||
|
{
|
||||||
|
[1] =
|
||||||
|
{
|
||||||
|
["alt"] = alt,
|
||||||
|
["alt_type"] = "BARO",
|
||||||
|
["tasks"] = {
|
||||||
|
[1] = {["number"] = 1, ["auto"] = true, ["id"] = "WrappedAction", ["enabled"] = true, ["params"] = {["action"] = {["id"] = "EPLRS", ["params"] = {["value"] = true}, }, }, },
|
||||||
|
[2] = {["number"] = 2, ["auto"] = false, ["id"] = "Orbit", ["enabled"] = true, ["params"] = {["pattern"] = "Circle"}, },
|
||||||
|
},
|
||||||
|
["type"] = "Turning Point",
|
||||||
|
["x"] = point.x,
|
||||||
|
["y"] = point.z,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
elseif unit:getDesc().category == Unit.Category.HELICOPTER then
|
||||||
|
category = 'helicopter'
|
||||||
|
route = {
|
||||||
|
["points"] =
|
||||||
|
{
|
||||||
|
[1] =
|
||||||
|
{
|
||||||
|
["alt"] = alt,
|
||||||
|
["alt_type"] = "BARO",
|
||||||
|
["tasks"] = {
|
||||||
|
[1] = {["number"] = 1, ["auto"] = true, ["id"] = "WrappedAction", ["enabled"] = true, ["params"] = {["action"] = {["id"] = "EPLRS", ["params"] = {["value"] = true}, }, }, },
|
||||||
|
[2] = {["number"] = 2, ["auto"] = false, ["id"] = "Orbit", ["enabled"] = true, ["params"] = {["pattern"] = "Circle"}, },
|
||||||
|
},
|
||||||
|
["type"] = "Turning Point",
|
||||||
|
["x"] = point.x,
|
||||||
|
["y"] = point.z,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
elseif unit:getDesc().category == Unit.Category.GROUND_UNIT then
|
||||||
|
category = 'vehicle'
|
||||||
|
elseif unit:getDesc().category == Unit.Category.SHIP then
|
||||||
|
category = 'ship'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
unitsTable[#unitsTable + 1] = unitTable
|
unitsTable[#unitsTable + 1] = unitTable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local spawnTable = {
|
local vars =
|
||||||
coalition = coalition,
|
{
|
||||||
|
units = unitsTable,
|
||||||
|
country = countryID,
|
||||||
category = category,
|
category = category,
|
||||||
units = unitsTable
|
route = route,
|
||||||
|
name = "Olympus-" .. Olympus.unitCounter,
|
||||||
|
task = 'CAP'
|
||||||
}
|
}
|
||||||
Olympus.spawnUnits(spawnTable)
|
|
||||||
|
mist.dynAdd(vars)
|
||||||
|
Olympus.unitCounter = Olympus.unitCounter + 1
|
||||||
|
|
||||||
Olympus.debug("Olympus.clone completed successfully", 2)
|
Olympus.debug("Olympus.clone completed successfully", 2)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user