Updated databases

This commit is contained in:
Pax1601
2023-10-11 18:01:27 +02:00
parent 4cdf82cb14
commit 2264faabfc
13 changed files with 47484 additions and 46630 deletions

View File

@@ -93,7 +93,7 @@ export class CoalitionAreaContextMenu extends ContextMenu {
}));
/* Create the checkboxes to select the unit ranges */
this.#iadsRangesDropdown.setOptionsElements(groundUnitDatabase.getRanges().map((range: string) => {
this.#iadsRangesDropdown.setOptionsElements(["Short range", "Medium range", "Long range"].map((range: string) => {
return createCheckboxOption(range, `Add ${range} units to the IADS`);
}));

View File

@@ -161,12 +161,16 @@ export class MapContextMenu extends ContextMenu {
this.#aircraftSpawnMenu.reset();
this.#aircraftSpawnMenu.setCountries();
this.#aircraftSpawnMenu.clearCirclesPreviews();
this.#helicopterSpawnMenu.reset();
this.#helicopterSpawnMenu.setCountries();
this.#helicopterSpawnMenu.clearCirclesPreviews();
this.#groundUnitSpawnMenu.reset();
this.#groundUnitSpawnMenu.setCountries();
this.#groundUnitSpawnMenu.clearCirclesPreviews();
this.#navyUnitSpawnMenu.reset();
this.#navyUnitSpawnMenu.setCountries();
this.#navyUnitSpawnMenu.clearCirclesPreviews();
this.setVisibleSubMenu(type);
this.clip();

View File

@@ -202,7 +202,6 @@ export interface UnitBlueprint {
label: string;
shortLabel: string;
type?: string;
rangeType?: string;
loadouts?: LoadoutBlueprint[];
filename?: string;
liveries?: { [key: string]: { name: string, countries: string[] } };
@@ -215,8 +214,8 @@ export interface UnitBlueprint {
abilities?: string;
acquisitionRange?: number;
engagementRange?: number;
refuelsFrom?: string;
refuellingType?: string;
canTargetPoint?: boolean;
canRearm?: boolean;
}
export interface UnitSpawnOptions {

View File

@@ -611,7 +611,7 @@ export class Map extends L.Map {
options["land-at-point"] = { text: "Land here", tooltip: "Land at this precise location" };
}
if (selectedUnits.every((unit: Unit) => { return unit.canFulfillRole(["CAS", "Strike"]) })) {
if (selectedUnits.every((unit: Unit) => { return unit.canTargetPoint()})) {
options["bomb"] = { text: "Precision bombing", tooltip: "Precision bombing of a specific point" };
options["carpet-bomb"] = { text: "Carpet bombing", tooltip: "Carpet bombing close to a point" };
} else {
@@ -619,7 +619,7 @@ export class Map extends L.Map {
}
}
else if (selectedUnitTypes.length === 1 && ["GroundUnit", "NavyUnit"].includes(selectedUnitTypes[0])) {
if (selectedUnits.every((unit: Unit) => { return ["AAA", "APC", "Gun Artillery", "Rocket Artillery", "Infantry", "IFV", "Tank", "Cruiser", "Destroyer", "Frigate"].includes(unit.getType()) })) {
if (selectedUnits.every((unit: Unit) => { return unit.canTargetPoint() })) {
options["fire-at-area"] = { text: "Fire at area", tooltip: "Fire at a large area" };
options["simulate-fire-fight"] = { text: "Simulate fire fight", tooltip: "Simulate a fire fight by shooting randomly in a certain large area" };
}

View File

@@ -308,16 +308,24 @@ export function randomUnitBlueprint(unitDatabase: UnitDatabase, options: {type?:
/* Keep only the units that have a range included in the requested values */
if (options.ranges) {
unitBlueprints = unitBlueprints.filter((unitBlueprint: UnitBlueprint) => {
//@ts-ignore
return unitBlueprint.rangeType? options.ranges.includes(unitBlueprint.rangeType): true;
var rangeType = "";
var range = unitBlueprint.acquisitionRange ;
if (range !== undefined) {
if (range >= 0 && range < 10000)
rangeType = "Short range";
else if (range >= 10000 && range < 100000)
rangeType = "Medium range";
else if (range >= 100000 && range < 999999)
rangeType = "Long range";
}
return options.ranges?.includes(rangeType);
});
}
/* Keep only the units that have an era included in the requested values */
if (options.eras) {
unitBlueprints = unitBlueprints.filter((unitBlueprint: UnitBlueprint) => {
//@ts-ignore
return unitBlueprint.era? options.eras.includes(unitBlueprint.era): true;
return unitBlueprint.era? options.eras?.includes(unitBlueprint.era): true;
});
}

View File

@@ -117,25 +117,32 @@ export class UnitDatabase {
return eras;
}
/* Returns a list of all possible ranges in a database */
getRanges() {
var filteredBlueprints = this.getBlueprints();
var ranges: string[] = [];
for (let unit in filteredBlueprints) {
var range = filteredBlueprints[unit].rangeType;
if (range && range !== "" && !ranges.includes(range))
ranges.push(range);
}
return ranges;
}
/* Get all blueprints by range */
getByRange(range: string) {
var filteredBlueprints = this.getBlueprints();
var unitswithrange = [];
var minRange = 0;
var maxRange = 0;
if (range === "Short range") {
minRange = 0;
maxRange = 10000;
}
else if (range === "Medium range") {
minRange = 10000;
maxRange = 100000;
}
else {
minRange = 100000;
maxRange = 999999;
}
for (let unit in filteredBlueprints) {
if (filteredBlueprints[unit].rangeType === range) {
unitswithrange.push(filteredBlueprints[unit]);
var engagementRange = filteredBlueprints[unit].engagementRange;
if (engagementRange !== undefined) {
if (engagementRange >= minRange && engagementRange < maxRange) {
unitswithrange.push(filteredBlueprints[unit]);
}
}
}
return unitswithrange;

View File

@@ -616,6 +616,14 @@ export class Unit extends CustomMarker {
return getApp().getMap().getBounds().contains(this.getPosition());
}
canTargetPoint() {
return this.getDatabase()?.getByName(this.#name)?.canTargetPoint === true;
}
canRearm() {
return this.getDatabase()?.getByName(this.#name)?.canRearm === true;
}
/********************** Unit commands *************************/
addDestination(latlng: L.LatLng) {
if (!this.#human) {