Fixed IADS creation, no longer clogs the server

This commit is contained in:
Pax1601 2023-12-05 15:43:48 +01:00
parent 9c2c7f45c6
commit 6afb6682ea
5 changed files with 23 additions and 23 deletions

View File

@ -68,7 +68,8 @@ export class CoalitionAreaContextMenu extends ContextMenu {
const area = this.getCoalitionArea();
if (area)
getApp().getUnitsManager().createIADS(area, getCheckboxOptions(this.#iadsTypesDropdown), getCheckboxOptions(this.#iadsErasDropdown), getCheckboxOptions(this.#iadsRangesDropdown), this.#iadsDensitySlider.getValue(), this.#iadsDistributionSlider.getValue());
})
this.hide();
});
this.hide();
}
@ -110,7 +111,7 @@ export class CoalitionAreaContextMenu extends ContextMenu {
this.getContainer()?.querySelectorAll('[data-coalition]').forEach((element: any) => {
element.setAttribute("data-coalition", this.getCoalitionArea()?.getCoalition())
});
this.#coalitionSwitch.setValue(this.getCoalitionArea()?.getCoalition() === "red");
this.#coalitionSwitch.setValue(this.getCoalitionArea()?.getCoalition() === "blue");
}
/** Get the CoalitionArea object the contextmenu is editing

View File

@ -64,7 +64,6 @@ export class ServerManager {
/* On the connection */
xmlHttp.open("GET", `${this.#demoEnabled ? this.#DEMO_ADDRESS : this.#REST_ADDRESS}/${uri}${optionsString ? `?${optionsString}` : ''}`, true);
xmlHttp.timeout = 2000;
/* If provided, set the credentials */
if (this.#username && this.#password)
@ -96,9 +95,11 @@ export class ServerManager {
this.setConnected(false);
}
};
xmlHttp.onerror = (res) => {
console.error("An error occurred during the XMLHttpRequest");
this.setConnected(false);
xmlHttp.onreadystatechange = (res) => {
if (xmlHttp.readyState == 4 && xmlHttp.status === 0) {
console.error("An error occurred during the XMLHttpRequest");
this.setConnected(false);
}
};
xmlHttp.send(null);
}
@ -600,4 +601,8 @@ export class ServerManager {
getServerIsPaused() {
return this.#serverIsPaused;
}
getRequests() {
return this.#requests;
}
}

View File

@ -46,7 +46,7 @@ export class UnitDataFileImport extends UnitDataFile {
return { unitType: unitData.name, location: unitData.position, liveryID: "" }
});
unitsManager.spawnUnits(category, unitsToSpawn, coalition, true);
unitsManager.spawnUnits(category, unitsToSpawn, coalition, false);
}
/*

View File

@ -1114,7 +1114,7 @@ export class UnitsManager {
/* Check if the city is inside the coalition area */
if (polyContains(new LatLng(airbase.getLatLng().lat, airbase.getLatLng().lng), coalitionArea)) {
/* Arbitrary formula to obtain a number of units */
var pointsNumber = 2 + 40 * density / 100;
var pointsNumber = 2 + 10 * density / 100;
for (let i = 0; i < pointsNumber; i++) {
/* Place the unit nearby the airbase, depending on the distribution parameter */
var bearing = Math.random() * 360;
@ -1127,11 +1127,8 @@ export class UnitsManager {
if (Math.random() < IADSDensities[type]) {
/* Get a random blueprint depending on the selected parameters and spawn the unit */
const unitBlueprint = randomUnitBlueprint(groundUnitDatabase, { type: type, eras: activeEras, ranges: activeRanges });
if (unitBlueprint) {
this.spawnUnits("GroundUnit", [{ unitType: unitBlueprint.name, location: latlng, liveryID: "" }], coalitionArea.getCoalition(), true, "", "", (res: any) =>{
getApp().getMap().addTemporaryMarker(latlng, unitBlueprint.name, getApp().getActiveCoalition(), res.commandHash);
});
}
if (unitBlueprint)
this.spawnUnits("GroundUnit", [{ unitType: unitBlueprint.name, location: latlng, liveryID: "" }], coalitionArea.getCoalition(), false, "", "");
}
}
}
@ -1142,7 +1139,7 @@ export class UnitsManager {
/* Check if the city is inside the coalition area */
if (polyContains(new LatLng(city.lat, city.lng), coalitionArea)) {
/* Arbitrary formula to obtain a number of units depending on the city population */
var pointsNumber = 2 + Math.pow(city.pop, 0.2) * density / 100;
var pointsNumber = 2 + Math.pow(city.pop, 0.15) * density / 100;
for (let i = 0; i < pointsNumber; i++) {
/* Place the unit nearby the city, depending on the distribution parameter */
var bearing = Math.random() * 360;
@ -1155,11 +1152,8 @@ export class UnitsManager {
if (Math.random() < IADSDensities[type]) {
/* Get a random blueprint depending on the selected parameters and spawn the unit */
const unitBlueprint = randomUnitBlueprint(groundUnitDatabase, { type: type, eras: activeEras, ranges: activeRanges });
if (unitBlueprint) {
this.spawnUnits("GroundUnit", [{ unitType: unitBlueprint.name, location: latlng, liveryID: "" }], coalitionArea.getCoalition(), true, "", "", (res: any) =>{
getApp().getMap().addTemporaryMarker(latlng, unitBlueprint.name, getApp().getActiveCoalition(), res.commandHash);
});
}
if (unitBlueprint)
this.spawnUnits("GroundUnit", [{ unitType: unitBlueprint.name, location: latlng, liveryID: "" }], coalitionArea.getCoalition(), false, "", "");
}
}
}

View File

@ -173,7 +173,7 @@ public:
priority = immediate? CommandPriority::IMMEDIATE: CommandPriority::LOW;
};
virtual string getString();
virtual unsigned int getLoad() { return immediate? 1: 30; }
virtual unsigned int getLoad() { return immediate? 5: 30; }
private:
const string coalition;
@ -196,7 +196,7 @@ public:
priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW;
};
virtual string getString();
virtual unsigned int getLoad() { return immediate ? 1 : 60; }
virtual unsigned int getLoad() { return immediate ? 5 : 60; }
private:
const string coalition;
@ -220,7 +220,7 @@ public:
priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW;
};
virtual string getString();
virtual unsigned int getLoad() { return immediate ? 1 : 45; }
virtual unsigned int getLoad() { return immediate ? 5 : 45; }
private:
const string coalition;
@ -245,7 +245,7 @@ public:
priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW;
};
virtual string getString();
virtual unsigned int getLoad() { return immediate ? 1 : 45; }
virtual unsigned int getLoad() { return immediate ? 5 : 45; }
private:
const string coalition;