Completed unit nation selection and new spawn menu

This commit is contained in:
Pax1601 2023-09-03 15:15:11 +02:00
parent 695adc8acb
commit 6898d1df6d
17 changed files with 13414 additions and 5159 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ export class Dropdown {
#defaultValue: string;
#optionsList: string[] = [];
#index: number = 0;
#hidden: boolean = false;
constructor(ID: string | null, callback: CallableFunction, options: string[] | null = null, defaultText?: string) {
if (ID === null)
@ -139,11 +140,17 @@ export class Dropdown {
}
show() {
this.#container.classList.add("show");
this.#container.classList.remove("hide");
this.#hidden = false;
}
hide() {
this.#container.classList.add("hide");
this.#hidden = true;
}
isHidden() {
return this.#hidden;
}
#toggle() {

View File

@ -63,7 +63,12 @@ export class Slider extends Control {
setValue(newValue: number, ignoreExpectedValue: boolean = true) {
if (!this.getDragged() && (ignoreExpectedValue || this.checkExpectedValue(newValue))) {
this.#value = newValue;
if (this.#value !== newValue) {
this.#value = newValue;
if (this.#callback)
this.#callback(this.getValue());
}
if (this.#slider != null)
this.#slider.value = String((newValue - this.#minValue) / (this.#maxValue - this.#minValue) * parseFloat(this.#slider.max));
this.#update();

View File

@ -84,7 +84,10 @@ export class UnitSpawnMenu {
advancedOptionsText.innerText = "Advanced options";
var advancedOptionsHr = document.createElement("hr");
advancedOptionsToggle.append(advancedOptionsText, advancedOptionsHr);
advancedOptionsToggle.addEventListener("click", () => { advancedOptionsDiv.classList.toggle("hide") });
advancedOptionsToggle.addEventListener("click", () => {
advancedOptionsDiv.classList.toggle("hide");
this.#container.dispatchEvent(new Event("resize"));
});
advancedOptionsDiv.append(this.#unitCountryDropdown.getContainer(), this.#unitLiveryDropdown.getContainer(),
this.#unitLoadoutPreviewEl, this.#unitSpawnAltitudeSlider.getContainer() as HTMLElement);
@ -94,7 +97,9 @@ export class UnitSpawnMenu {
this.#deployUnitButtonEl.disabled = true;
this.#deployUnitButtonEl.innerText = "Deploy unit";
this.#deployUnitButtonEl.setAttribute("data-coalition", "blue");
this.#deployUnitButtonEl.addEventListener("click", () => { this.#deployUnits(); });
this.#deployUnitButtonEl.addEventListener("click", () => {
this.deployUnits(this.#spawnOptions, parseInt(this.#unitCountDropdown.getValue()));
});
/* Assemble all components */
this.#container.append(this.#unitRoleTypeDropdown.getContainer(), unitLabelCountContainerEl, this.#unitLoadoutDropdown.getContainer(),
@ -115,13 +120,11 @@ export class UnitSpawnMenu {
/* Event listeners */
this.#container.addEventListener("unitRoleTypeChanged", () => {
this.#deployUnitButtonEl.disabled = true;
this.#unitLabelDropdown.reset();
if (this.#unitLoadoutListEl !== null)
this.#unitLoadoutListEl.replaceChildren();
if (this.#unitLoadoutDropdown !== null)
this.#unitLoadoutDropdown.reset();
if (this.#unitImageEl !== null)
this.#unitImageEl.classList.toggle("hide", true);
this.#unitLoadoutListEl.replaceChildren();
this.#unitLoadoutDropdown.reset();
this.#unitImageEl.classList.toggle("hide", true);
this.#unitLiveryDropdown.reset();
if (this.#orderByRole)
@ -129,18 +132,24 @@ export class UnitSpawnMenu {
else
this.#unitLabelDropdown.setOptions(this.#unitDatabase.getByType(this.#spawnOptions.roleType).map((blueprint) => { return blueprint.label }));
this.#container.dispatchEvent(new Event("resize"));
this.#spawnOptions.name = "";
this.#spawnOptions.loadout = undefined;
this.#spawnOptions.liveryID = undefined;
this.#computeSpawnPoints();
})
this.#container.addEventListener("unitLabelChanged", () => {
if (this.#unitLoadoutDropdown !== null) {
this.#deployUnitButtonEl.disabled = false;
if (!this.#unitLoadoutDropdown.isHidden()) {
this.#unitLoadoutDropdown.setOptions(this.#unitDatabase.getLoadoutNamesByRole(this.#spawnOptions.name, this.#spawnOptions.roleType));
this.#unitLoadoutDropdown.selectValue(0);
}
if (this.#unitImageEl !== null) {
this.#unitImageEl.src = `images/units/${this.#unitDatabase.getByName(this.#spawnOptions.name)?.filename}`;
this.#unitImageEl.classList.toggle("hide", false);
}
this.#unitImageEl.src = `images/units/${this.#unitDatabase.getByName(this.#spawnOptions.name)?.filename}`;
this.#unitImageEl.classList.toggle("hide", false);
this.#setUnitLiveryOptions();
this.#container.dispatchEvent(new Event("resize"));
@ -148,9 +157,8 @@ export class UnitSpawnMenu {
})
this.#container.addEventListener("unitLoadoutChanged", () => {
this.#deployUnitButtonEl.disabled = false;
var items = this.#spawnOptions.loadout?.items.map((item: any) => { return `${item.quantity}x ${item.name}`; });
if (items != undefined && this.#unitLoadoutListEl !== null) {
if (items != undefined) {
items.length == 0 ? items.push("Empty loadout") : "";
this.#unitLoadoutListEl.replaceChildren(
...items.map((item: any) => {
@ -191,12 +199,9 @@ export class UnitSpawnMenu {
else
this.#unitRoleTypeDropdown.setOptions(this.#unitDatabase.getTypes());
if (this.#unitLoadoutListEl !== null)
this.#unitLoadoutListEl.replaceChildren();
if (this.#unitLoadoutDropdown !== null)
this.#unitLoadoutDropdown.reset();
if (this.#unitImageEl !== null)
this.#unitImageEl.classList.toggle("hide", true);
this.#unitLoadoutListEl.replaceChildren();
this.#unitLoadoutDropdown.reset();
this.#unitImageEl.classList.toggle("hide", true);
this.setCountries();
this.#container.dispatchEvent(new Event("resize"));
@ -208,7 +213,7 @@ export class UnitSpawnMenu {
this.#unitCountryDropdown.setOptionsElements(this.#createCountryButtons(this.#unitCountryDropdown, countries, (country: string) => { this.#setUnitCountry(country) }));
if (countries.length > 0 && !countries.includes(this.#spawnOptions.country)) {
this.#unitCountryDropdown.forceValue(countries[0]);
this.#unitCountryDropdown.forceValue(this.#getFormattedCountry(countries[0]));
this.#setUnitCountry(countries[0]);
}
}
@ -300,10 +305,15 @@ export class UnitSpawnMenu {
#setUnitLivery(liveryName: string) {
var liveries = this.#unitDatabase.getByName(this.#spawnOptions.name)?.liveries;
if (liveries !== undefined) {
for (let liveryID in liveries)
if (liveries[liveryID].name === liveryName)
this.#spawnOptions.liveryID = liveryID;
if (liveryName === "Default") {
this.#spawnOptions.liveryID = "";
}
else {
if (liveries !== undefined) {
for (let liveryID in liveries)
if (liveries[liveryID].name === liveryName)
this.#spawnOptions.liveryID = liveryID;
}
}
this.#container.dispatchEvent(new Event("unitLiveryChanged"));
}
@ -314,7 +324,7 @@ export class UnitSpawnMenu {
var countryLiveries: string[] = ["Default"];
liveries.forEach((livery: any) => {
var nationLiveryCodes = this.#countryCodes[this.#spawnOptions.country].liveryCodes;
if (livery.countries.some((country: string) => { return nationLiveryCodes.includes(country) }))
if (livery.countries === "All" || livery.countries.some((country: string) => { return nationLiveryCodes.includes(country) }))
countryLiveries.push(livery.name);
});
this.#unitLiveryDropdown.setOptions(countryLiveries);
@ -322,43 +332,20 @@ export class UnitSpawnMenu {
}
}
#deployUnits() {
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,
liveryID: this.#spawnOptions.liveryID
};
var units = [];
for (let i = 1; i < parseInt(this.#unitCountDropdown.getValue()) + 1; i++) {
units.push(unitTable);
}
if (getUnitsManager().spawnUnits("Unit", units, getActiveCoalition(), false, this.#spawnOptions.airbase ? this.#spawnOptions.airbase.getName() : "", this.#spawnOptions.country)) {
getMap().addTemporaryMarker(this.#spawnOptions.latlng, this.#spawnOptions.name, getActiveCoalition());
getMap().getMapContextMenu().hide();
}
}
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number) {
/* Virtual function must be overloaded by inheriting classes */
}
#createCountryButtons(parent: Dropdown, countries: string[], callback: CallableFunction) {
return Object.values(countries).map((country: string) => {
var el = document.createElement("div");
var formattedCountry = "";
if (this.#countryCodes[country] !== undefined && this.#countryCodes[country].displayName !== undefined)
formattedCountry = this.#countryCodes[country].displayName;
else
formattedCountry = country.charAt(0).toUpperCase() + country.slice(1).toLowerCase();
var button = document.createElement("button");
button.classList.add("country-dropdown-element");
el.appendChild(button);
button.addEventListener("click", () => {
callback(country);
parent.forceValue(formattedCountry);
parent.forceValue(this.#getFormattedCountry(country));
parent.close();
});
if (this.#countryCodes[country] !== undefined) {
@ -373,12 +360,21 @@ export class UnitSpawnMenu {
console.log("Unknown country " + country);
}
var text = document.createElement("div");
text.innerText = formattedCountry;
text.innerText = this.#getFormattedCountry(country);
button.appendChild(text);
return el;
});
}
#getFormattedCountry(country: string) {
var formattedCountry = "";
if (this.#countryCodes[country] !== undefined && this.#countryCodes[country].displayName !== undefined)
formattedCountry = this.#countryCodes[country].displayName;
else
formattedCountry = country.charAt(0).toUpperCase() + country.slice(1).toLowerCase();
return formattedCountry;
}
#computeSpawnPoints() {
if (getMissionHandler() && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
var unitCount = parseInt(this.#unitCountDropdown.getValue());
@ -401,6 +397,27 @@ export class AircraftSpawnMenu extends UnitSpawnMenu {
this.getAltitudeSlider().setIncrement(500);
this.getAltitudeSlider().setValue(20000);
}
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number) {
spawnOptions.coalition = getActiveCoalition();
if (spawnOptions) {
var unitTable = {
unitType: spawnOptions.name,
location: spawnOptions.latlng,
altitude: spawnOptions.altitude? spawnOptions.altitude: 0,
loadout: spawnOptions.loadout? spawnOptions.loadout.name: "",
liveryID: spawnOptions.liveryID? spawnOptions.liveryID: ""
};
var units = [];
for (let i = 1; i < unitsCount + 1; i++) {
units.push(unitTable);
}
if (getUnitsManager().spawnUnits("Aircraft", units, getActiveCoalition(), false, spawnOptions.airbase ? spawnOptions.airbase.getName() : "", spawnOptions.country)) {
getMap().addTemporaryMarker(spawnOptions.latlng, spawnOptions.name, getActiveCoalition());
getMap().getMapContextMenu().hide();
}
}
}
}
export class HelicopterSpawnMenu extends UnitSpawnMenu {
@ -415,6 +432,27 @@ export class HelicopterSpawnMenu extends UnitSpawnMenu {
this.getAltitudeSlider().setIncrement(100);
this.getAltitudeSlider().setValue(5000);
}
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number) {
spawnOptions.coalition = getActiveCoalition();
if (spawnOptions) {
var unitTable = {
unitType: spawnOptions.name,
location: spawnOptions.latlng,
altitude: spawnOptions.altitude? spawnOptions.altitude: 0,
loadout: spawnOptions.loadout? spawnOptions.loadout.name: "",
liveryID: spawnOptions.liveryID? spawnOptions.liveryID: ""
};
var units = [];
for (let i = 1; i < unitsCount + 1; i++) {
units.push(unitTable);
}
if (getUnitsManager().spawnUnits("Helicopter", units, getActiveCoalition(), false, spawnOptions.airbase ? spawnOptions.airbase.getName() : "", spawnOptions.country)) {
getMap().addTemporaryMarker(spawnOptions.latlng, spawnOptions.name, getActiveCoalition());
getMap().getMapContextMenu().hide();
}
}
}
}
export class GroundUnitSpawnMenu extends UnitSpawnMenu {
@ -429,6 +467,26 @@ export class GroundUnitSpawnMenu extends UnitSpawnMenu {
this.getLoadoutDropdown().hide();
this.getLoadoutPreview().classList.add("hide");
}
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number) {
spawnOptions.coalition = getActiveCoalition();
if (spawnOptions) {
var unitTable = {
unitType: spawnOptions.name,
location: spawnOptions.latlng,
liveryID: spawnOptions.liveryID? spawnOptions.liveryID: ""
};
var units = [];
for (let i = 1; i < unitsCount + 1; i++) {
units.push(JSON.parse(JSON.stringify(unitTable)));
unitTable.location.lat += 0.0001;
}
if (getUnitsManager().spawnUnits("GroundUnit", units, getActiveCoalition(), false, spawnOptions.airbase ? spawnOptions.airbase.getName() : "", spawnOptions.country)) {
getMap().addTemporaryMarker(spawnOptions.latlng, spawnOptions.name, getActiveCoalition());
getMap().getMapContextMenu().hide();
}
}
}
}
export class NavyUnitSpawnMenu extends UnitSpawnMenu {
@ -443,4 +501,24 @@ export class NavyUnitSpawnMenu extends UnitSpawnMenu {
this.getLoadoutDropdown().hide();
this.getLoadoutPreview().classList.add("hide");
}
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number) {
spawnOptions.coalition = getActiveCoalition();
if (spawnOptions) {
var unitTable = {
unitType: spawnOptions.name,
location: spawnOptions.latlng,
liveryID: spawnOptions.liveryID? spawnOptions.liveryID: ""
};
var units = [];
for (let i = 1; i < unitsCount + 1; i++) {
units.push(JSON.parse(JSON.stringify(unitTable)));
unitTable.location.lat += 0.0001;
}
if (getUnitsManager().spawnUnits("NavyUnit", units, getActiveCoalition(), false, spawnOptions.airbase ? spawnOptions.airbase.getName() : "", spawnOptions.country)) {
getMap().addTemporaryMarker(spawnOptions.latlng, spawnOptions.name, getActiveCoalition());
getMap().getMapContextMenu().hide();
}
}
}
}

View File

@ -1,6 +1,6 @@
import { LatLng } from "leaflet";
import { getInfoPopup, getMap } from "..";
import { Airbase, AirbaseChartData } from "./airbase";
import { Airbase } from "./airbase";
import { Bullseye } from "./bullseye";
import { BLUE_COMMANDER, GAME_MASTER, NONE, RED_COMMANDER } from "../constants/constants";
import { refreshAll, setCommandModeOptions } from "../server/server";

View File

@ -170,14 +170,14 @@ export function spawnHelicopters(units: any, coalition: string, airbaseName: str
POST(data, () => { });
}
export function spawnGroundUnits(units: any, coalition: string, immediate: boolean, spawnPoints: number) {
var command = { "units": units, "coalition": coalition, "immediate": immediate, "spawnPoints": spawnPoints };;
export function spawnGroundUnits(units: any, coalition: string, country: string, immediate: boolean, spawnPoints: number) {
var command = { "units": units, "coalition": coalition, "country": country, "immediate": immediate, "spawnPoints": spawnPoints };;
var data = { "spawnGroundUnits": command }
POST(data, () => { });
}
export function spawnNavyUnits(units: any, coalition: string, immediate: boolean, spawnPoints: number) {
var command = { "units": units, "coalition": coalition, "immediate": immediate, "spawnPoints": spawnPoints };
export function spawnNavyUnits(units: any, coalition: string, country: string, immediate: boolean, spawnPoints: number) {
var command = { "units": units, "coalition": coalition, "country": country, "immediate": immediate, "spawnPoints": spawnPoints };
var data = { "spawnNavyUnits": command }
POST(data, () => { });
}

View File

@ -722,14 +722,14 @@ export class UnitsManager {
return false;
}
spawnPoints = units.reduce((points: number, unit: any) => {return points + groundUnitDatabase.getSpawnPointsByName(unit.unitType)}, 0);
spawnGroundUnits(units, coalition, immediate, spawnPoints);
spawnGroundUnits(units, coalition, country, immediate, spawnPoints);
} else if (category === "NavyUnit") {
if (getMissionHandler().getCommandModeOptions().restrictSpawns && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
getInfoPopup().setText("Navy units can be spawned during the SETUP phase only");
return false;
}
spawnPoints = units.reduce((points: number, unit: any) => {return points + navyUnitDatabase.getSpawnPointsByName(unit.unitType)}, 0);
spawnNavyUnits(units, coalition, immediate, spawnPoints);
spawnNavyUnits(units, coalition, country, immediate, spawnPoints);
}
if (spawnPoints <= getMissionHandler().getAvailableSpawnPoints()) {

View File

@ -461,8 +461,6 @@ function Olympus.generateAirUnitsTable(units)
["livery_id"] = unit.liveryID
}
Olympus.debug(unit.liveryID, 5)
-- Add the payload to the registry, used for unit cloning
Olympus.payloadRegistry[unitTable[#unitTable].name] = payload
end

View File

@ -11,7 +11,7 @@
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["C:\\Users\\dpass\\Documents\\DCSOlympus\\client\\public\\databases\\units\\aircraftdatabase.json"]
"args": ["groundunit"]
}
]
}

View File

@ -0,0 +1,94 @@
import sys
import json
import inspect
import difflib
from slpp import slpp as lua
SEARCH_FOLDER = "D:\\Eagle Dynamics\\DCS World OpenBeta"
sys.path.append("..\\..\\..\\dcs-master\\dcs-master")
from dcs.weapons_data import Weapons
from dcs.planes import *
from dcs.helicopters import *
from dcs.vehicles import *
from dcs.ships import *
from dcs.liveries.liveryscanner import LiveryScanner
livery_scanner = LiveryScanner()
livery_scanner.scan_dcs_installation(SEARCH_FOLDER)
# Known id mismatches (because reasons, ask ED)
mismatched_ids = {
"A-10CII": "A-10C_2"
}
# The database file on which to operate is the first standard argument of the call
if len(sys.argv) > 1:
if (sys.argv[1] == "aircraft"):
filename = '..\\..\\client\\public\\databases\\units\\aircraftdatabase.json'
elif (sys.argv[1] == "helicopter"):
filename = '..\\..\\client\\public\\databases\\units\\helicopterdatabase.json'
elif (sys.argv[1] == "groundunit"):
filename = '..\\..\\client\\public\\databases\\units\\groundunitdatabase.json'
elif (sys.argv[1] == "navyunit"):
filename = '..\\..\\client\\public\\databases\\units\\navyunitdatabase.json'
# Loads the database
with open(filename) as f:
database = json.load(f)
for unit_name in database:
database[unit_name]["enabled"] = True
# Loop on all the units in the database
for unit_name in database:
try:
# Get the pydcs Python class for the unit
if (sys.argv[1] == "aircraft"):
unitmap = plane_map
elif (sys.argv[1] == "helicopter"):
unitmap = helicopter_map
elif (sys.argv[1] == "groundunit"):
unitmap = vehicle_map
elif (sys.argv[1] == "navyunit"):
unitmap = ship_map
lowercase_keys = [key.lower() for key in unitmap.keys()]
res = difflib.get_close_matches(unit_name.lower(), lowercase_keys)
if len(res) > 0:
found_name = list(unitmap.keys())[lowercase_keys.index(res[0])]
cls = unitmap[found_name]
else:
print(f"Warning, could not find {unit_name} in classes list. Skipping...")
continue
# Add the liveries
liveries = []
if unit_name in livery_scanner.map:
liveries = livery_scanner.map[unit_name]
else:
if (unit_name in mismatched_ids):
found_name = mismatched_ids[unit_name]
else:
lowercase_keys = [key.lower() for key in livery_scanner.map.keys()]
res = difflib.get_close_matches(unit_name.lower(), lowercase_keys)
found_name = list(livery_scanner.map.keys())[lowercase_keys.index(res[0])]
print(f"Warning, could not find {unit_name} in liveries list. Best match is {found_name}. Manual check required!")
liveries = livery_scanner.map[found_name]
database[unit_name]["liveries"] = {}
for livery in liveries:
database[unit_name]["liveries"][livery.id] = {
"name": livery.name,
"countries": [country for country in livery.countries] if livery.countries != None else "All"
}
except Exception as e:
print(f"Could not find data for aircraft of type {unit_name}: {e}, skipping...")
# Dump everything in the database
with open(filename, "w") as f:
json.dump(database, f, indent=2)
# Done!
print("Done!")

View File

@ -11,10 +11,6 @@ sys.path.append("..\..\..\dcs-master\dcs-master")
from dcs.weapons_data import Weapons
from dcs.planes import *
from dcs.helicopters import *
from dcs.liveries.liveryscanner import LiveryScanner
livery_scanner = LiveryScanner()
livery_scanner.scan_dcs_installation(SEARCH_FOLDER)
# Known id mismatches (because reasons, ask ED)
mismatched_ids = {
@ -29,11 +25,20 @@ def find_weapon_name(clsid):
for weapon_id in weapon_ids:
if getattr(Weapons, weapon_id)["clsid"] == clsid:
return getattr(Weapons, weapon_id)["name"]
# The database file on which to operate is the first standard argument of the call
if len(sys.argv) > 1:
if (sys.argv[1] == "aircraft"):
filename = '..\\..\\client\\public\\databases\\units\\aircraftdatabase.json'
elif (sys.argv[1] == "helicopter"):
filename = '..\\..\\client\\public\\databases\\units\\helicopterdatabase.json'
elif (sys.argv[1] == "groundunit"):
filename = '..\\..\\client\\public\\databases\\units\\groundunitdatabase.json'
elif (sys.argv[1] == "navyunit"):
filename = '..\\..\\client\\public\\databases\\units\\navyunitdatabase.json'
# Loads the database
with open(sys.argv[1]) as f:
with open(filename) as f:
database = json.load(f)
for unit_name in database:
database[unit_name]["enabled"] = True
@ -51,28 +56,22 @@ if len(sys.argv) > 1:
for unit_name in database:
try:
# Get the pydcs Python class for the unit
cls = getattr(sys.modules[__name__], unit_name.replace("-", "_").replace(" ", "_"))
# Add the liveries
liveries = []
if unit_name in livery_scanner.map:
liveries = livery_scanner.map[unit_name]
if (sys.argv[1] == "aircraft"):
unitmap = plane_map
elif (sys.argv[1] == "helicopter"):
unitmap = helicopter_map
elif (sys.argv[1] == "groundunit"):
unitmap = vehicle_map
elif (sys.argv[1] == "navyunit"):
unitmap = ship_map
lowercase_keys = [key.lower() for key in unitmap.keys()]
res = difflib.get_close_matches(unit_name.lower(), lowercase_keys)
if len(res) > 0:
found_name = list(unitmap.keys())[lowercase_keys.index(res[0])]
cls = unitmap[found_name]
else:
if (unit_name in mismatched_ids):
found_name = mismatched_ids[unit_name]
else:
lowercase_keys = [key.lower() for key in livery_scanner.map.keys()]
res = difflib.get_close_matches(unit_name.lower(), lowercase_keys)
found_name = list(livery_scanner.map.keys())[lowercase_keys.index(res[0])]
print(f"Warning, could not find {unit_name} in liveries list. Best match is {found_name}. Manual check required!")
liveries = livery_scanner.map[found_name]
database[unit_name]["liveries"] = {}
for livery in liveries:
database[unit_name]["liveries"][livery.id] = {
"name": livery.name,
"countries": [country for country in livery.countries]
}
print(f"Warning, could not find {unit_name} in classes list. Skipping...")
continue
# Create the loadouts table and add the empty loadout for the default task
database[unit_name]["loadouts"] = []
@ -124,7 +123,7 @@ if len(sys.argv) > 1:
print(f"Could not find data for aircraft of type {unit_name}: {e}, skipping...")
# Dump everything in the database
with open(sys.argv[1], "w") as f:
with open(filename, "w") as f:
json.dump(database, f, indent=2)
# Done!

View File

@ -155,9 +155,10 @@ private:
class SpawnGroundUnits : public Command
{
public:
SpawnGroundUnits(string coalition, vector<SpawnOptions> spawnOptions, bool immediate) :
SpawnGroundUnits(string coalition, vector<SpawnOptions> spawnOptions, string country, bool immediate) :
coalition(coalition),
spawnOptions(spawnOptions),
country(country),
immediate(immediate)
{
priority = immediate? CommandPriority::IMMEDIATE: CommandPriority::LOW;
@ -168,6 +169,7 @@ public:
private:
const string coalition;
const vector<SpawnOptions> spawnOptions;
const string country;
const bool immediate;
};
@ -175,9 +177,10 @@ private:
class SpawnNavyUnits : public Command
{
public:
SpawnNavyUnits(string coalition, vector<SpawnOptions> spawnOptions, bool immediate) :
SpawnNavyUnits(string coalition, vector<SpawnOptions> spawnOptions, string country, bool immediate) :
coalition(coalition),
spawnOptions(spawnOptions),
country(country),
immediate(immediate)
{
priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW;
@ -188,6 +191,7 @@ public:
private:
const string coalition;
const vector<SpawnOptions> spawnOptions;
const string country;
const bool immediate;
};

View File

@ -55,6 +55,7 @@ string SpawnGroundUnits::getString()
commandSS << "Olympus.spawnUnits, {"
<< "category = " << "\"" << "GroundUnit" << "\"" << ", "
<< "coalition = " << "\"" << coalition << "\"" << ", "
<< "country = \"" << country << "\", "
<< "units = " << "{" << unitsSS.str() << "}" << "}";
return commandSS.str();
}
@ -78,6 +79,7 @@ string SpawnNavyUnits::getString()
commandSS << "Olympus.spawnUnits, {"
<< "category = " << "\"" << "NavyUnit" << "\"" << ", "
<< "coalition = " << "\"" << coalition << "\"" << ", "
<< "country = \"" << country << "\", "
<< "units = " << "{" << unitsSS.str() << "}" << "}";
return commandSS.str();
}

View File

@ -230,6 +230,7 @@ void Scheduler::handleRequest(string key, json::value value, string username)
{
bool immediate = value[L"immediate"].as_bool();
string coalition = to_string(value[L"coalition"]);
string country = to_string(value[L"country"]);
int spawnPoints = value[L"spawnPoints"].as_number().to_int32();
if (!checkSpawnPoints(spawnPoints, coalition)) return;
@ -242,16 +243,17 @@ void Scheduler::handleRequest(string key, json::value value, string username)
Coords location; location.lat = lat; location.lng = lng;
string liveryID = to_string(unit[L"liveryID"]);
spawnOptions.push_back({ unitType, location, "", liveryID});
spawnOptions.push_back({ unitType, location, "", liveryID });
log(username + " spawned a " + coalition + " " + unitType, true);
}
command = dynamic_cast<Command*>(new SpawnGroundUnits(coalition, spawnOptions, immediate));
command = dynamic_cast<Command*>(new SpawnGroundUnits(coalition, spawnOptions, country, immediate));
}
else if (key.compare("spawnNavyUnits") == 0)
{
bool immediate = value[L"immediate"].as_bool();
string coalition = to_string(value[L"coalition"]);
string country = to_string(value[L"country"]);
int spawnPoints = value[L"spawnPoints"].as_number().to_int32();
if (!checkSpawnPoints(spawnPoints, coalition)) return;
@ -264,11 +266,11 @@ void Scheduler::handleRequest(string key, json::value value, string username)
Coords location; location.lat = lat; location.lng = lng;
string liveryID = to_string(unit[L"liveryID"]);
spawnOptions.push_back({ unitType, location, "", liveryID });
spawnOptions.push_back({ unitType, location, "", liveryID});
log(username + " spawned a " + coalition + " " + unitType, true);
}
command = dynamic_cast<Command*>(new SpawnNavyUnits(coalition, spawnOptions, immediate));
command = dynamic_cast<Command*>(new SpawnNavyUnits(coalition, spawnOptions, country, immediate));
}
else if (key.compare("attackUnit") == 0)
{