diff --git a/client/public/databases/aircraftdatabase.json b/client/public/databases/aircraftdatabase.json index caab8031..a6db3432 100644 --- a/client/public/databases/aircraftdatabase.json +++ b/client/public/databases/aircraftdatabase.json @@ -1230,6 +1230,7 @@ "name": "Empty Loadout" } ], + "liveryID": ["ir iriaf 43rd tfs"], "filename": "f-5.png" }, "F-86F Sabre": { diff --git a/client/src/@types/unitdatabase.d.ts b/client/src/@types/unitdatabase.d.ts index 704cf88e..f906f4b8 100644 --- a/client/src/@types/unitdatabase.d.ts +++ b/client/src/@types/unitdatabase.d.ts @@ -22,4 +22,5 @@ interface UnitBlueprint { range?: string; loadouts?: LoadoutBlueprint[]; filename?: string; + liveryID?: string; } diff --git a/client/src/controls/mapcontextmenu.ts b/client/src/controls/mapcontextmenu.ts index 5d472fc9..1d51952c 100644 --- a/client/src/controls/mapcontextmenu.ts +++ b/client/src/controls/mapcontextmenu.ts @@ -92,7 +92,8 @@ export class MapContextMenu extends ContextMenu { document.addEventListener("contextMenuDeployAircrafts", () => { this.#spawnOptions.coalition = getActiveCoalition(); if (this.#spawnOptions) { - var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, altitude: this.#spawnOptions.altitude, loadout: this.#spawnOptions.loadout}; + const liveryID = aircraftDatabase.getByName(this.#spawnOptions.name)?.liveryID; + var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, altitude: this.#spawnOptions.altitude, loadout: this.#spawnOptions.loadout, liveryID: liveryID? liveryID: ""}; var units = []; for (let i = 1; i < parseInt(this.#aircraftCountDropdown.getValue()) + 1; i++) { units.push(unitTable); @@ -107,7 +108,8 @@ export class MapContextMenu extends ContextMenu { document.addEventListener("contextMenuDeployHelicopters", () => { this.#spawnOptions.coalition = getActiveCoalition(); if (this.#spawnOptions) { - var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, altitude: this.#spawnOptions.altitude, loadout: this.#spawnOptions.loadout}; + const liveryID = aircraftDatabase.getByName(this.#spawnOptions.name)?.liveryID; + var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, altitude: this.#spawnOptions.altitude, loadout: this.#spawnOptions.loadout, liveryID: liveryID? liveryID: ""}; var units = []; for (let i = 1; i < parseInt(this.#helicopterCountDropdown.getValue()) + 1; i++) { units.push(unitTable); @@ -122,7 +124,8 @@ export class MapContextMenu extends ContextMenu { document.addEventListener("contextMenuDeployGroundUnits", () => { this.#spawnOptions.coalition = getActiveCoalition(); if (this.#spawnOptions) { - var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng}; + const liveryID = aircraftDatabase.getByName(this.#spawnOptions.name)?.liveryID; + var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, liveryID: liveryID? liveryID: ""}; var units = []; for (let i = 1; i < parseInt(this.#groundUnitCountDropdown.getValue()) + 1; i++) { units.push(JSON.parse(JSON.stringify(unitTable))); @@ -138,7 +141,8 @@ export class MapContextMenu extends ContextMenu { document.addEventListener("contextMenuDeployNavyUnits", () => { this.#spawnOptions.coalition = getActiveCoalition(); if (this.#spawnOptions) { - var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng}; + const liveryID = aircraftDatabase.getByName(this.#spawnOptions.name)?.liveryID; + var unitTable = {unitType: this.#spawnOptions.name, location: this.#spawnOptions.latlng, liveryID: liveryID? liveryID: ""}; var units = []; for (let i = 1; i < parseInt(this.#navyUnitCountDropdown.getValue()) + 1; i++) { units.push(JSON.parse(JSON.stringify(unitTable))); diff --git a/client/src/mission/missionhandler.ts b/client/src/mission/missionhandler.ts index 52436620..facf7682 100644 --- a/client/src/mission/missionhandler.ts +++ b/client/src/mission/missionhandler.ts @@ -77,7 +77,7 @@ export class MissionHandler { this.#dateAndTime = data.mission.dateAndTime; /* Set the coalition countries */ - this.#coalitions = data.mission.coalitions; + //this.#coalitions = data.mission.coalitions; /* Set the command mode options */ this.#setcommandModeOptions(data.mission.commandModeOptions); diff --git a/client/src/unit/unit.ts b/client/src/unit/unit.ts index abe147cb..39847911 100644 --- a/client/src/unit/unit.ts +++ b/client/src/unit/unit.ts @@ -311,6 +311,11 @@ export class Unit extends CustomMarker { } } + getLiveryID(): string { + const liveryID = this.getDatabase()?.getByName(this.getName())?.liveryID; + return liveryID? liveryID: ""; + } + setAlive(newAlive: boolean) { if (newAlive != this.#alive) document.dispatchEvent(new CustomEvent("unitDeath", { detail: this })); diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index 047c64ec..5356bfb3 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -555,7 +555,7 @@ export class UnitsManager { var unit = selectedUnits[idx]; coalition = unit.getCoalition(); deleteUnit(unit.ID, false, true); - units.push({unitType: unit.getName(), location: unit.getPosition()}); + units.push({unitType: unit.getName(), location: unit.getPosition(), liveryID: unit.getLiveryID()}); } const category = this.getSelectedUnitsTypes()[0]; this.spawnUnits(category, units, coalition, true); @@ -593,7 +593,8 @@ export class UnitsManager { var units = groups[groupName].map((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); - return {unitType: unit.name, location: position}; + const liveryID = unit.getDatabase()?.getByName(unit.getName())?.liveryID; + return {unitType: unit.name, location: position, liveryID: liveryID? liveryID: ""}; }); this.spawnUnits(groups[groupName][0].category, units, groups[groupName][0].coalition, true); } @@ -629,7 +630,8 @@ export class UnitsManager { if (Math.random() < IADSDensities[type]) { const unitBlueprint = randomUnitBlueprint(groundUnitDatabase, {type: type, eras: activeEras, ranges: activeRanges}); if (unitBlueprint) { - this.spawnUnits("GroundUnit", [{unitType: unitBlueprint.name, location: latlng}], coalitionArea.getCoalition(), true); + const liveryID = unitBlueprint.liveryID; + this.spawnUnits("GroundUnit", [{unitType: unitBlueprint.name, location: latlng, liveryID: liveryID? liveryID: ""}], coalitionArea.getCoalition(), true); getMap().addTemporaryMarker(latlng, unitBlueprint.name, coalitionArea.getCoalition()); } } @@ -673,7 +675,10 @@ export class UnitsManager { for (let groupName in groups) { if (groupName !== "" && groups[groupName].length > 0 && (groups[groupName].every((unit: any) => {return unit.category == "GroundUnit";}) || groups[groupName].every((unit: any) => {return unit.category == "NavyUnit";}))) { var aliveUnits = groups[groupName].filter((unit: any) => {return unit.alive}); - var units = aliveUnits.map((unit: any) => {return {unitType: unit.name, location: unit.position}}); + var units = aliveUnits.map((unit: any) => { + const liveryID = unit.getDatabase()?.getByName(unit.getName())?.liveryID; + return { unitType: unit.name, location: unit.position, liveryID: liveryID? liveryID: "" } + }); getUnitsManager().spawnUnits(groups[groupName][0].category, units, groups[groupName][0].coalition, true); } } diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index 799497e8..2fc4de58 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -447,7 +447,8 @@ function Olympus.generateAirUnitsTable(units) ["payload"] = { ["pylons"] = payload, ["fuel"] = 999999, ["flare"] = 60, ["ammo_type"] = 1, ["chaff"] = 60, ["gun"] = 100, }, ["heading"] = 0, ["callsign"] = { [1] = 1, [2] = 1, [3] = 1, ["name"] = "Olympus" .. Olympus.unitCounter.. "-" .. #unitTable + 1 }, - ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitTable + 1 + ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitTable + 1, + ["livery_id"] = unit.liveryID } end return unitTable @@ -534,7 +535,8 @@ function Olympus.generateGroundUnitsTable(units) ["y"] = spawnLocation.z, ["heading"] = 0, ["skill"] = "High", - ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitTable + 1 + ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitTable + 1, + ["livery_id"] = unit.liveryID } end end @@ -569,7 +571,8 @@ function Olympus.generateNavyUnitsTable(units) ["heading"] = 0, ["skill"] = "High", ["name"] = "Olympus-" .. Olympus.unitCounter .. "-" .. #unitTable + 1, - ["transportable"] = { ["randomTransportable"] = false } + ["transportable"] = { ["randomTransportable"] = false }, + ["livery_id"] = unit.liveryID } end end diff --git a/src/core/include/commands.h b/src/core/include/commands.h index 263de2f0..bd25435d 100644 --- a/src/core/include/commands.h +++ b/src/core/include/commands.h @@ -154,10 +154,11 @@ private: class SpawnGroundUnits : public Command { public: - SpawnGroundUnits(string coalition, vector unitTypes, vector locations, bool immediate) : + SpawnGroundUnits(string coalition, vector unitTypes, vector locations, vector liveryIDs, bool immediate) : coalition(coalition), unitTypes(unitTypes), locations(locations), + liveryIDs(liveryIDs), immediate(immediate) { priority = immediate? CommandPriority::IMMEDIATE: CommandPriority::LOW; @@ -169,6 +170,7 @@ private: const string coalition; const vector unitTypes; const vector locations; + const vector liveryIDs; const bool immediate; }; @@ -176,10 +178,11 @@ private: class SpawnNavyUnits : public Command { public: - SpawnNavyUnits(string coalition, vector unitTypes, vector locations, bool immediate) : + SpawnNavyUnits(string coalition, vector unitTypes, vector locations, vector liveryIDs, bool immediate) : coalition(coalition), unitTypes(unitTypes), locations(locations), + liveryIDs(liveryIDs), immediate(immediate) { priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; @@ -191,6 +194,7 @@ private: const string coalition; const vector unitTypes; const vector locations; + const vector liveryIDs; const bool immediate; }; @@ -198,11 +202,12 @@ private: class SpawnAircrafts : public Command { public: - SpawnAircrafts(string coalition, vector unitTypes, vector locations, vector loadouts, string airbaseName, bool immediate) : + SpawnAircrafts(string coalition, vector unitTypes, vector locations, vector loadouts, vector liveryIDs, string airbaseName, bool immediate) : coalition(coalition), unitTypes(unitTypes), locations(locations), loadouts(loadouts), + liveryIDs(liveryIDs), airbaseName(airbaseName), immediate(immediate) { @@ -216,6 +221,7 @@ private: const vector unitTypes; const vector locations; const vector loadouts; + const vector liveryIDs; const string airbaseName; const bool immediate; }; @@ -225,11 +231,12 @@ private: class SpawnHelicopters : public Command { public: - SpawnHelicopters(string coalition, vector unitTypes, vector locations, vector loadouts, string airbaseName, bool immediate) : + SpawnHelicopters(string coalition, vector unitTypes, vector locations, vector loadouts, vector liveryIDs, string airbaseName, bool immediate) : coalition(coalition), unitTypes(unitTypes), locations(locations), loadouts(loadouts), + liveryIDs(liveryIDs), airbaseName(airbaseName), immediate(immediate) { @@ -243,6 +250,7 @@ private: const vector unitTypes; const vector locations; const vector loadouts; + const vector liveryIDs; const string airbaseName; const bool immediate; }; diff --git a/src/core/src/commands.cpp b/src/core/src/commands.cpp index 511abcd4..552b6463 100644 --- a/src/core/src/commands.cpp +++ b/src/core/src/commands.cpp @@ -48,7 +48,8 @@ string SpawnGroundUnits::getString() unitsSS << "[" << i + 1 << "] = {" << "unitType = " << "\"" << unitTypes[i] << "\"" << ", " << "lat = " << locations[i].lat << ", " - << "lng = " << locations[i].lng << "},"; + << "lng = " << locations[i].lng << ", " + << "liveryID = " << "\"" << liveryIDs[i] << "\"" << " }, "; } std::ostringstream commandSS; @@ -72,7 +73,8 @@ string SpawnNavyUnits::getString() unitsSS << "[" << i + 1 << "] = {" << "unitType = " << "\"" << unitTypes[i] << "\"" << ", " << "lat = " << locations[i].lat << ", " - << "lng = " << locations[i].lng << "},"; + << "lng = " << locations[i].lng << ", " + << "liveryID = " << "\"" << liveryIDs[i] << "\"" << " }, "; } std::ostringstream commandSS; @@ -97,7 +99,8 @@ string SpawnAircrafts::getString() << "lat = " << locations[i].lat << ", " << "lng = " << locations[i].lng << ", " << "alt = " << locations[i].alt << ", " - << "loadout = \"" << loadouts[i] << "\"" << "},"; + << "loadout = \"" << loadouts[i] << "\"" << ", " + << "liveryID = " << "\"" << liveryIDs[i] << "\"" << " }, "; } std::ostringstream commandSS; @@ -124,7 +127,8 @@ string SpawnHelicopters::getString() << "lat = " << locations[i].lat << ", " << "lng = " << locations[i].lng << ", " << "alt = " << locations[i].alt << ", " - << "loadout = \"" << loadouts[i] << "\"" << "},"; + << "loadout = \"" << loadouts[i] << "\"" << ", " + << "liveryID = " << "\"" << liveryIDs[i] << "\"" << " }, "; } std::ostringstream commandSS; diff --git a/src/core/src/scheduler.cpp b/src/core/src/scheduler.cpp index d9227ddc..e975f5a0 100644 --- a/src/core/src/scheduler.cpp +++ b/src/core/src/scheduler.cpp @@ -186,6 +186,7 @@ void Scheduler::handleRequest(string key, json::value value, string username) vector unitTypes; vector locations; vector loadouts; + vector liveryIDs; for (auto unit : value[L"units"].as_array()) { string unitType = to_string(unit[L"unitType"]); double lat = unit[L"location"][L"lat"].as_double(); @@ -193,14 +194,16 @@ void Scheduler::handleRequest(string key, json::value value, string username) double alt = unit[L"altitude"].as_double(); 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"]); unitTypes.push_back(unitType); locations.push_back(location); loadouts.push_back(loadout); + liveryIDs.push_back(liveryID); log(username + " spawned a " + coalition + " " + unitType, true); } - command = dynamic_cast(new SpawnAircrafts(coalition, unitTypes, locations, loadouts, airbaseName, immediate)); + command = dynamic_cast(new SpawnAircrafts(coalition, unitTypes, locations, liveryIDs, loadouts, airbaseName, immediate)); } else if (key.compare("spawnHelicopters") == 0) { @@ -214,6 +217,7 @@ void Scheduler::handleRequest(string key, json::value value, string username) vector unitTypes; vector locations; vector loadouts; + vector liveryIDs; for (auto unit : value[L"units"].as_array()) { string unitType = to_string(unit[L"unitType"]); double lat = unit[L"location"][L"lat"].as_double(); @@ -221,14 +225,16 @@ void Scheduler::handleRequest(string key, json::value value, string username) double alt = unit[L"altitude"].as_double(); 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"]); unitTypes.push_back(unitType); locations.push_back(location); loadouts.push_back(loadout); + liveryIDs.push_back(liveryID); log(username + " spawned a " + coalition + " " + unitType, true); } - command = dynamic_cast(new SpawnHelicopters(coalition, unitTypes, locations, loadouts, airbaseName, immediate)); + command = dynamic_cast(new SpawnHelicopters(coalition, unitTypes, locations, loadouts, liveryIDs, airbaseName, immediate)); } else if (key.compare("spawnGroundUnits") == 0) { @@ -240,18 +246,21 @@ void Scheduler::handleRequest(string key, json::value value, string username) vector unitTypes; vector locations; + vector liveryIDs; for (auto unit : value[L"units"].as_array()) { string unitType = to_string(unit[L"unitType"]); double lat = unit[L"location"][L"lat"].as_double(); double lng = unit[L"location"][L"lng"].as_double(); Coords location; location.lat = lat; location.lng = lng; + string liveryID = to_string(unit[L"liveryID"]); unitTypes.push_back(unitType); locations.push_back(location); + liveryIDs.push_back(liveryID); log(username + " spawned a " + coalition + " " + unitType, true); } - command = dynamic_cast(new SpawnGroundUnits(coalition, unitTypes, locations, immediate)); + command = dynamic_cast(new SpawnGroundUnits(coalition, unitTypes, locations, liveryIDs, immediate)); } else if (key.compare("spawnNavyUnits") == 0) { @@ -263,18 +272,21 @@ void Scheduler::handleRequest(string key, json::value value, string username) vector unitTypes; vector locations; + vector liveryIDs; for (auto unit : value[L"units"].as_array()) { string unitType = to_string(unit[L"unitType"]); double lat = unit[L"location"][L"lat"].as_double(); double lng = unit[L"location"][L"lng"].as_double(); Coords location; location.lat = lat; location.lng = lng; + string liveryID = to_string(unit[L"liveryID"]); unitTypes.push_back(unitType); locations.push_back(location); + liveryIDs.push_back(liveryID); log(username + " spawned a " + coalition + " " + unitType, true); } - command = dynamic_cast(new SpawnNavyUnits(coalition, unitTypes, locations, immediate)); + command = dynamic_cast(new SpawnNavyUnits(coalition, unitTypes, locations, liveryIDs, immediate)); } else if (key.compare("attackUnit") == 0) {