From 2124e9cd42ecd257848f3e95545b5d6606b67728 Mon Sep 17 00:00:00 2001 From: Stefan Arsic Date: Sat, 3 Feb 2024 22:29:26 +0100 Subject: [PATCH] Fixed setting skill level --- backend/core/include/commands.h | 16 ++++------------ backend/core/src/commands.cpp | 21 +++++++++------------ backend/core/src/scheduler.cpp | 20 +++++++++----------- client/src/controls/unitspawnmenu.ts | 2 +- scripts/lua/backend/OlympusCommand.lua | 26 +++++++++++++------------- 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/backend/core/include/commands.h b/backend/core/include/commands.h index ac250b55..2badd091 100644 --- a/backend/core/include/commands.h +++ b/backend/core/include/commands.h @@ -165,12 +165,11 @@ private: class SpawnGroundUnits : public Command { public: - SpawnGroundUnits(string coalition, vector spawnOptions, string country, string skill, bool immediate, function callback = [](){}) : + SpawnGroundUnits(string coalition, vector spawnOptions, string country, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), country(country), - skill(skill), immediate(immediate) { priority = immediate? CommandPriority::IMMEDIATE: CommandPriority::LOW; @@ -182,7 +181,6 @@ private: const string coalition; const vector spawnOptions; const string country; - const string skill; const bool immediate; }; @@ -190,12 +188,11 @@ private: class SpawnNavyUnits : public Command { public: - SpawnNavyUnits(string coalition, vector spawnOptions, string country, string skill, bool immediate, function callback = [](){}) : + SpawnNavyUnits(string coalition, vector spawnOptions, string country, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), country(country), - skill(skill), immediate(immediate) { priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; @@ -207,7 +204,6 @@ private: const string coalition; const vector spawnOptions; const string country; - const string skill; const bool immediate; }; @@ -215,13 +211,12 @@ private: class SpawnAircrafts : public Command { public: - SpawnAircrafts(string coalition, vector spawnOptions, string airbaseName, string country, string skill, bool immediate, function callback = [](){}) : + SpawnAircrafts(string coalition, vector spawnOptions, string airbaseName, string country, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), airbaseName(airbaseName), country(country), - skill(skill), immediate(immediate) { priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; @@ -234,7 +229,6 @@ private: const vector spawnOptions; const string airbaseName; const string country; - const string skill; const bool immediate; }; @@ -242,13 +236,12 @@ private: class SpawnHelicopters : public Command { public: - SpawnHelicopters(string coalition, vector spawnOptions, string airbaseName, string country, string skill, bool immediate, function callback = [](){}) : + SpawnHelicopters(string coalition, vector spawnOptions, string airbaseName, string country, bool immediate, function callback = [](){}) : Command(callback), coalition(coalition), spawnOptions(spawnOptions), airbaseName(airbaseName), country(country), - skill(skill), immediate(immediate) { priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; @@ -261,7 +254,6 @@ private: const vector spawnOptions; const string airbaseName; const string country; - const string skill; const bool immediate; }; diff --git a/backend/core/src/commands.cpp b/backend/core/src/commands.cpp index 1529ca84..604580cb 100644 --- a/backend/core/src/commands.cpp +++ b/backend/core/src/commands.cpp @@ -46,8 +46,9 @@ 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 << "\"" << " }, "; + << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << "}, "; + } std::ostringstream commandSS; @@ -56,7 +57,6 @@ string SpawnGroundUnits::getString() << "category = " << "\"" << "GroundUnit" << "\"" << ", " << "coalition = " << "\"" << coalition << "\"" << ", " << "country = \"" << country << "\", " - << "skill = \"" << skill << "\", " << "units = " << "{" << unitsSS.str() << "}" << "}"; return commandSS.str(); } @@ -72,8 +72,8 @@ 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 << "\"" << " }, "; + << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << "}, "; } std::ostringstream commandSS; @@ -82,7 +82,6 @@ string SpawnNavyUnits::getString() << "category = " << "\"" << "NavyUnit" << "\"" << ", " << "coalition = " << "\"" << coalition << "\"" << ", " << "country = \"" << country << "\", " - << "skill = \"" << skill << "\", " << "units = " << "{" << unitsSS.str() << "}" << "}"; return commandSS.str(); } @@ -99,8 +98,8 @@ string SpawnAircrafts::getString() << "lng = " << spawnOptions[i].location.lng << ", " << "alt = " << spawnOptions[i].location.alt << ", " << "loadout = \"" << spawnOptions[i].loadout << "\"" << ", " - << "skill = \"" << spawnOptions[i].skill << "\"" << ", " - << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << " }, "; + << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << "}, "; } std::ostringstream commandSS; @@ -110,7 +109,6 @@ string SpawnAircrafts::getString() << "coalition = " << "\"" << coalition << "\"" << ", " << "airbaseName = \"" << airbaseName << "\", " << "country = \"" << country << "\", " - << "skill = \"" << skill << "\", " << "units = " << "{" << unitsSS.str() << "}" << "}"; return commandSS.str(); } @@ -128,8 +126,8 @@ string SpawnHelicopters::getString() << "lng = " << spawnOptions[i].location.lng << ", " << "alt = " << spawnOptions[i].location.alt << ", " << "loadout = \"" << spawnOptions[i].loadout << "\"" << ", " - << "skill = \"" << spawnOptions[i].skill << "\"" << ", " - << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << " }, "; + << "liveryID = " << "\"" << spawnOptions[i].liveryID << "\"" << ", " + << "skill = \"" << spawnOptions[i].skill << "\"" << "}, "; } std::ostringstream commandSS; @@ -139,7 +137,6 @@ string SpawnHelicopters::getString() << "coalition = " << "\"" << coalition << "\"" << ", " << "airbaseName = \"" << airbaseName << "\", " << "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 83da80cc..23947274 100644 --- a/backend/core/src/scheduler.cpp +++ b/backend/core/src/scheduler.cpp @@ -191,7 +191,6 @@ void Scheduler::handleRequest(string key, json::value value, string username, js string coalition = to_string(value[L"coalition"]); string airbaseName = to_string(value[L"airbaseName"]); string country = to_string(value[L"country"]); - string skill = ""; int spawnPoints = value[L"spawnPoints"].as_number().to_int32(); @@ -206,16 +205,16 @@ void Scheduler::handleRequest(string key, json::value value, string username, js Coords location; location.lat = lat; location.lng = lng; location.alt = alt; string loadout = to_string(unit[L"loadout"]); string liveryID = to_string(unit[L"liveryID"]); - skill = to_string(unit[L"skill"]); + string skill = to_string(unit[L"skill"]); - spawnOptions.push_back({unitType, location, loadout, liveryID}); - log(username + " spawned a " + coalition + " " + unitType, true); + spawnOptions.push_back({unitType, location, loadout, skill, liveryID}); + log(username + " spawned a " + coalition + " " + unitType , true); } if (key.compare("spawnAircrafts") == 0) - command = dynamic_cast(new SpawnAircrafts(coalition, spawnOptions, airbaseName, country, skill, immediate)); + command = dynamic_cast(new SpawnAircrafts(coalition, spawnOptions, airbaseName, country, immediate)); else - command = dynamic_cast(new SpawnHelicopters(coalition, spawnOptions, airbaseName, country, skill, immediate)); + command = dynamic_cast(new SpawnHelicopters(coalition, spawnOptions, airbaseName, country, immediate)); } /************************/ else if (key.compare("spawnGroundUnits") == 0 || key.compare("spawnNavyUnits") == 0) @@ -223,7 +222,6 @@ 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; @@ -235,16 +233,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"]); + string skill = to_string(unit[L"skill"]); - spawnOptions.push_back({ unitType, location, "", liveryID }); + spawnOptions.push_back({ unitType, location, "", skill, liveryID}); log(username + " spawned a " + coalition + " " + unitType, true); } if (key.compare("spawnGroundUnits") == 0) - command = dynamic_cast(new SpawnGroundUnits(coalition, spawnOptions, country, skill, immediate)); + command = dynamic_cast(new SpawnGroundUnits(coalition, spawnOptions, country, immediate)); else - command = dynamic_cast(new SpawnNavyUnits(coalition, spawnOptions, country, skill, immediate)); + command = dynamic_cast(new SpawnNavyUnits(coalition, spawnOptions, country, immediate)); } /************************/ else if (key.compare("attackUnit") == 0) diff --git a/client/src/controls/unitspawnmenu.ts b/client/src/controls/unitspawnmenu.ts index 14751cf6..e237afd8 100644 --- a/client/src/controls/unitspawnmenu.ts +++ b/client/src/controls/unitspawnmenu.ts @@ -273,7 +273,7 @@ export abstract class UnitSpawnMenu { if (!this.#unitSkillDropdown.isHidden()) { this.#unitSkillDropdown.setOptions(["Average", "Good", "High", "Excellent"]) - this.#unitSkillDropdown.selectValue(3); + this.#unitSkillDropdown.selectValue(4); } /* Get the unit data from the db */ diff --git a/scripts/lua/backend/OlympusCommand.lua b/scripts/lua/backend/OlympusCommand.lua index 295cafae..a80c205f 100644 --- a/scripts/lua/backend/OlympusCommand.lua +++ b/scripts/lua/backend/OlympusCommand.lua @@ -545,7 +545,7 @@ end -- loadout: (string, optional) only for air units, must be one of the loadouts defined in unitPayloads.lua -- payload: (table, optional) overrides loadout, specifies directly the loadout of the unit -- liveryID: (string, optional) -function Olympus.spawnUnits(spawnTable, skill) +function Olympus.spawnUnits(spawnTable) Olympus.debug("Olympus.spawnUnits " .. Olympus.serializeTable(spawnTable), 2) local unitsTable = nil @@ -554,18 +554,18 @@ function Olympus.spawnUnits(spawnTable, skill) -- Generate the units table and route as per DCS requirements if spawnTable.category == 'Aircraft' then - unitsTable = Olympus.generateAirUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateAirUnitsTable(spawnTable.units) route = Olympus.generateAirUnitsRoute(spawnTable) category = 'plane' elseif spawnTable.category == 'Helicopter' then - unitsTable = Olympus.generateAirUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateAirUnitsTable(spawnTable.units) route = Olympus.generateAirUnitsRoute(spawnTable) category = 'helicopter' elseif spawnTable.category == 'GroundUnit' then - unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units) category = 'vehicle' elseif spawnTable.category == 'NavyUnit' then - unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units) category = 'ship' end @@ -600,7 +600,7 @@ function Olympus.spawnUnits(spawnTable, skill) end -- Generates unit table for air units -function Olympus.generateAirUnitsTable(units, skill) +function Olympus.generateAirUnitsTable(units) local unitsTable = {} for idx, unit in pairs(units) do local loadout = unit.loadout -- loadout: a string, one of the names defined in unitPayloads.lua. Must be compatible with the unitType @@ -628,7 +628,7 @@ function Olympus.generateAirUnitsTable(units, skill) ["y"] = spawnLocation.z, ["alt"] = unit.alt, ["alt_type"] = "BARO", - ["skill"] = skill, + ["skill"] = unit.skill, ["payload"] = payload, ["heading"] = unit.heading, ["callsign"] = { [1] = 1, [2] = 1, [3] = 1, ["name"] = "Olympus" .. Olympus.unitCounter.. "-" .. #unitsTable + 1 }, @@ -696,7 +696,7 @@ function Olympus.generateAirUnitsRoute(spawnTable) end -- Generates ground units table, either single or from template -function Olympus.generateGroundUnitsTable(units, skill) +function Olympus.generateGroundUnitsTable(units) local unitsTable = {} for idx, unit in pairs(units) do local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(unit.lat, unit.lng, 0)) @@ -730,7 +730,7 @@ function Olympus.generateGroundUnitsTable(units, skill) end -- Generates navy units table, either single or from template -function Olympus.generateNavyUnitsTable(units, skill) +function Olympus.generateNavyUnitsTable(units) local unitsTable = {} for idx, unit in pairs(units) do local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(unit.lat, unit.lng, 0)) @@ -1109,13 +1109,13 @@ function Olympus.setUnitsData(arg, time) -- Generate the units table as per DCS requirements if table["category"] == 'Aircraft' then - unitsTable = Olympus.generateAirUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateAirUnitsTable(spawnTable.units) elseif table["category"] == 'Helicopter' then - unitsTable = Olympus.generateAirUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateAirUnitsTable(spawnTable.units) elseif table["category"] == 'GroundUnit' then - unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateGroundUnitsTable(spawnTable.units) elseif table["category"] == 'NavyUnit' then - unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units, skill) + unitsTable = Olympus.generateNavyUnitsTable(spawnTable.units) end -- Save the units in the database, for cloning