From 497f718e4b3ea16d5223508e8982ef3e30acd63e Mon Sep 17 00:00:00 2001 From: Stefan Arsic Date: Fri, 12 Jan 2024 22:33:43 +0100 Subject: [PATCH] Added option for ground units to change skill --- backend/core/include/commands.h | 8 ++++++-- backend/core/src/commands.cpp | 4 ++++ backend/core/src/scheduler.cpp | 6 ++++-- client/src/controls/unitspawnmenu.ts | 6 ++++-- scripts/lua/backend/OlympusCommand.lua | 20 ++++++++++---------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/backend/core/include/commands.h b/backend/core/include/commands.h index f0071562..ac250b55 100644 --- a/backend/core/include/commands.h +++ b/backend/core/include/commands.h @@ -165,11 +165,12 @@ private: class SpawnGroundUnits : public Command { public: - SpawnGroundUnits(string coalition, vector spawnOptions, string country, bool immediate, function callback = [](){}) : + SpawnGroundUnits(string coalition, vector spawnOptions, string country, string skill, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), country(country), + skill(skill), immediate(immediate) { priority = immediate? CommandPriority::IMMEDIATE: CommandPriority::LOW; @@ -181,6 +182,7 @@ private: const string coalition; const vector spawnOptions; const string country; + const string skill; const bool immediate; }; @@ -188,11 +190,12 @@ private: class SpawnNavyUnits : public Command { public: - SpawnNavyUnits(string coalition, vector spawnOptions, string country, bool immediate, function callback = [](){}) : + SpawnNavyUnits(string coalition, vector spawnOptions, string country, string skill, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), country(country), + skill(skill), immediate(immediate) { priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; @@ -204,6 +207,7 @@ private: const string coalition; const vector spawnOptions; const string country; + const string skill; const bool immediate; }; diff --git a/backend/core/src/commands.cpp b/backend/core/src/commands.cpp index a0868ca1..1529ca84 100644 --- a/backend/core/src/commands.cpp +++ b/backend/core/src/commands.cpp @@ -46,6 +46,7 @@ string SpawnGroundUnits::getString() << "unitType = " << "\"" << spawnOptions[i].unitType << "\"" << ", " << "lat = " << spawnOptions[i].location.lat << ", " << "lng = " << spawnOptions[i].location.lng << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << ", " << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << " }, "; } @@ -55,6 +56,7 @@ string SpawnGroundUnits::getString() << "category = " << "\"" << "GroundUnit" << "\"" << ", " << "coalition = " << "\"" << coalition << "\"" << ", " << "country = \"" << country << "\", " + << "skill = \"" << skill << "\", " << "units = " << "{" << unitsSS.str() << "}" << "}"; return commandSS.str(); } @@ -70,6 +72,7 @@ string SpawnNavyUnits::getString() << "unitType = " << "\"" << spawnOptions[i].unitType << "\"" << ", " << "lat = " << spawnOptions[i].location.lat << ", " << "lng = " << spawnOptions[i].location.lng << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << ", " << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << " }, "; } @@ -79,6 +82,7 @@ string SpawnNavyUnits::getString() << "category = " << "\"" << "NavyUnit" << "\"" << ", " << "coalition = " << "\"" << coalition << "\"" << ", " << "country = \"" << country << "\", " + << "skill = \"" << skill << "\", " << "units = " << "{" << unitsSS.str() << "}" << "}"; return commandSS.str(); } diff --git a/backend/core/src/scheduler.cpp b/backend/core/src/scheduler.cpp index b36884a5..83da80cc 100644 --- a/backend/core/src/scheduler.cpp +++ b/backend/core/src/scheduler.cpp @@ -223,6 +223,7 @@ void Scheduler::handleRequest(string key, json::value value, string username, js bool immediate = value[L"immediate"].as_bool(); string coalition = to_string(value[L"coalition"]); string country = to_string(value[L"country"]); + string skill = ""; int spawnPoints = value[L"spawnPoints"].as_number().to_int32(); if (!checkSpawnPoints(spawnPoints, coalition)) return; @@ -234,15 +235,16 @@ void Scheduler::handleRequest(string key, json::value value, string username, js double lng = unit[L"location"][L"lng"].as_double(); Coords location; location.lat = lat; location.lng = lng; string liveryID = to_string(unit[L"liveryID"]); + skill = to_string(unit[L"skill"]); spawnOptions.push_back({ unitType, location, "", liveryID }); log(username + " spawned a " + coalition + " " + unitType, true); } if (key.compare("spawnGroundUnits") == 0) - command = dynamic_cast(new SpawnGroundUnits(coalition, spawnOptions, country, immediate)); + command = dynamic_cast(new SpawnGroundUnits(coalition, spawnOptions, country, skill, immediate)); else - command = dynamic_cast(new SpawnNavyUnits(coalition, spawnOptions, country, immediate)); + command = dynamic_cast(new SpawnNavyUnits(coalition, spawnOptions, country, skill, immediate)); } /************************/ else if (key.compare("attackUnit") == 0) diff --git a/client/src/controls/unitspawnmenu.ts b/client/src/controls/unitspawnmenu.ts index 830f3224..14751cf6 100644 --- a/client/src/controls/unitspawnmenu.ts +++ b/client/src/controls/unitspawnmenu.ts @@ -754,7 +754,8 @@ export class GroundUnitSpawnMenu extends UnitSpawnMenu { var unitTable: UnitSpawnTable = { unitType: spawnOptions.name, location: spawnOptions.latlng, - liveryID: spawnOptions.liveryID? spawnOptions.liveryID: "" + liveryID: spawnOptions.liveryID? spawnOptions.liveryID: "", + skill: spawnOptions.skill ? spawnOptions.skill : "High" }; var units = []; @@ -804,7 +805,8 @@ export class NavyUnitSpawnMenu extends UnitSpawnMenu { var unitTable: UnitSpawnTable = { unitType: spawnOptions.name, location: spawnOptions.latlng, - liveryID: spawnOptions.liveryID? spawnOptions.liveryID: "" + liveryID: spawnOptions.liveryID? spawnOptions.liveryID: "", + skill: spawnOptions.skill ? spawnOptions.skill : "High" }; var units = []; diff --git a/scripts/lua/backend/OlympusCommand.lua b/scripts/lua/backend/OlympusCommand.lua index fcdb37eb..295cafae 100644 --- a/scripts/lua/backend/OlympusCommand.lua +++ b/scripts/lua/backend/OlympusCommand.lua @@ -562,10 +562,10 @@ function Olympus.spawnUnits(spawnTable, skill) route = Olympus.generateAirUnitsRoute(spawnTable) category = 'helicopter' elseif spawnTable.category == 'GroundUnit' then - unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units) + unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units, skill) category = 'vehicle' elseif spawnTable.category == 'NavyUnit' then - unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units) + unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units, skill) category = 'ship' end @@ -696,7 +696,7 @@ function Olympus.generateAirUnitsRoute(spawnTable) end -- Generates ground units table, either single or from template -function Olympus.generateGroundUnitsTable(units) +function Olympus.generateGroundUnitsTable(units, skill) local unitsTable = {} for idx, unit in pairs(units) do local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(unit.lat, unit.lng, 0)) @@ -708,7 +708,7 @@ function Olympus.generateGroundUnitsTable(units) ["x"] = spawnLocation.x + value.dx, ["y"] = spawnLocation.z + value.dy, ["heading"] = 0, - ["skill"] = "High", + ["skill"] = skill, ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1 } end @@ -719,7 +719,7 @@ function Olympus.generateGroundUnitsTable(units) ["x"] = spawnLocation.x, ["y"] = spawnLocation.z, ["heading"] = unit.heading, - ["skill"] = "High", + ["skill"] = skill, ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1, ["livery_id"] = unit.liveryID } @@ -730,7 +730,7 @@ function Olympus.generateGroundUnitsTable(units) end -- Generates navy units table, either single or from template -function Olympus.generateNavyUnitsTable(units) +function Olympus.generateNavyUnitsTable(units, skill) local unitsTable = {} for idx, unit in pairs(units) do local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(unit.lat, unit.lng, 0)) @@ -742,7 +742,7 @@ function Olympus.generateNavyUnitsTable(units) ["x"] = spawnLocation.x + value.dx, ["y"] = spawnLocation.z + value.dy, ["heading"] = 0, - ["skill"] = "High", + ["skill"] = skill, ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1, ["transportable"] = { ["randomTransportable"] = false } } @@ -754,7 +754,7 @@ function Olympus.generateNavyUnitsTable(units) ["x"] = spawnLocation.x, ["y"] = spawnLocation.z, ["heading"] = unit.heading, - ["skill"] = "High", + ["skill"] = skill, ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitsTable + 1, ["transportable"] = { ["randomTransportable"] = false }, ["livery_id"] = unit.liveryID @@ -1113,9 +1113,9 @@ function Olympus.setUnitsData(arg, time) elseif table["category"] == 'Helicopter' then unitsTable = Olympus.generateAirUnitsTable(spawnTable.units, skill) elseif table["category"] == 'GroundUnit' then - unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units) + unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units, skill) elseif table["category"] == 'NavyUnit' then - unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units) + unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units, skill) end -- Save the units in the database, for cloning