diff --git a/client/src/server/server.ts b/client/src/server/server.ts index 189a877a..e9c685dd 100644 --- a/client/src/server/server.ts +++ b/client/src/server/server.ts @@ -201,7 +201,7 @@ export function followUnit(ID: number, targetID: number, offset: { "x": number, export function cloneUnits(units: {ID: number, location: LatLng}[], callback: CallableFunction = () => {}) { var command = { "units": units }; - var data = { "cloneUnit": command } + var data = { "cloneUnits": command } POST(data, callback); } diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index c88e3df6..c44711a4 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -557,14 +557,18 @@ export class UnitsManager { // TODO handle from lua selectedUnitsCreateGroup() { var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false }); - var units = []; + var units: { ID: number, location: LatLng }[] = []; var coalition = "neutral"; for (let idx in selectedUnits) { var unit = selectedUnits[idx]; coalition = unit.getCoalition(); 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 */ - var units: { ID: number, location: LatLng }[] = []; for (let groupName in groups) { + var units: { ID: number, location: LatLng }[] = []; groups[groupName].forEach((unit: any) => { 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); @@ -606,7 +610,7 @@ export class UnitsManager { }); cloneUnits(units); } - getInfoPopup().setText(`${this.#copiedUnits.length - 1} units pasted`); + getInfoPopup().setText(`${this.#copiedUnits.length} units pasted`); } else { getInfoPopup().setText(`Unit cloning is disabled in ${getMissionHandler().getCommandModeOptions().commandMode} mode`); diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index ddb6aedb..44937ec3 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -1,6 +1,6 @@ local version = "v0.4.4-alpha" -local debug = false +local debug = true Olympus.OlympusDLL = nil Olympus.DLLsloaded = false @@ -410,7 +410,7 @@ function Olympus.spawnUnits(spawnTable) end -- 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) 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). function Olympus.clone(cloneTable) - Olympus.debug("Olympus.clone " .. cloneTable, 2) + Olympus.debug("Olympus.clone " .. Olympus.serializeTable(cloneTable), 2) local unitsTable = {} - local coalition = nil + local countryID = 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 unit = Olympus.getUnitByID(ID) @@ -617,26 +618,78 @@ function Olympus.clone(cloneTable) -- Update the data of the cloned unit local unitTable = Olympus.spawnDatabase[unit:getName()] + local point = coord.LLtoLO(cloneData['lat'], cloneData['lng'], 0) if unitTable then - unitTable["lat"] = lat - unitTable["lng"] = lng + unitTable["x"] = point.x + unitTable["y"] = point.z unitTable["alt"] = unit:getPoint().y unitTable["heading"] = heading + unitTable["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1 end - coalition = Olympus.getCoalitionByCoalitionID(unit:getCoalition()), - category = unit:getDesc().category, + if countryID == nil and category == nil then + 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 end end - - local spawnTable = { - coalition = coalition, + + local vars = + { + units = unitsTable, + country = countryID, 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) end