From 125d5396b9035a305568b3c40e008d6398b61374 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Thu, 30 Nov 2023 15:36:31 +0100 Subject: [PATCH 1/2] Fixed IADS creation It now also considers airbases when creating the IADS. Fixed styling and unit types. Currently SAM Sites ranges are incorrect but will be fixed when database is updated --- client/demo.js | 2 +- .../public/stylesheets/other/contextmenus.css | 2 + client/src/constants/constants.ts | 4 +- client/src/map/map.ts | 6 +-- client/src/unit/unitsmanager.ts | 37 ++++++++++++++++++- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/client/demo.js b/client/demo.js index e27687aa..2a8ba5c7 100644 --- a/client/demo.js +++ b/client/demo.js @@ -55,7 +55,7 @@ class DemoDataGenerator { // UNCOMMENT TO TEST ALL UNITS **************** - + /* var databases = Object.assign({}, aircraftDatabase, helicopterDatabase, groundUnitDatabase, navyUnitDatabase); var t = Object.keys(databases).length; var l = Math.floor(Math.sqrt(t)); diff --git a/client/public/stylesheets/other/contextmenus.css b/client/public/stylesheets/other/contextmenus.css index a35d3624..c4d369f3 100644 --- a/client/public/stylesheets/other/contextmenus.css +++ b/client/public/stylesheets/other/contextmenus.css @@ -580,6 +580,7 @@ #iads-menu { row-gap: 10px; + padding: 10px; } #coalition-area-contextmenu>div:nth-child(2) { @@ -596,6 +597,7 @@ flex-direction: column; justify-content: space-between; row-gap: 5px; + padding: 20px; } .create-iads-button { diff --git a/client/src/constants/constants.ts b/client/src/constants/constants.ts index 07fba370..d3961b1f 100644 --- a/client/src/constants/constants.ts +++ b/client/src/constants/constants.ts @@ -220,8 +220,8 @@ export const MAP_MARKER_CONTROLS: MapMarkerVisibilityControl[] = [{ "tooltip": "Toggle airbase' visibility" }]; -export const IADSTypes = ["AAA", "MANPADS", "SAM Site", "Radar"]; -export const IADSDensities: { [key: string]: number } = { "AAA": 0.8, "MANPADS": 0.3, "SAM Site": 0.1, "Radar": 0.05 }; +export const IADSTypes = ["AAA", "SAM Site", "Radar (EWR)"]; +export const IADSDensities: { [key: string]: number } = { "AAA": 0.8, "SAM Site": 0.1, "Radar (EWR)": 0.05 }; export const GROUND_UNIT_AIR_DEFENCE_REGEX:RegExp = /(\b(AAA|SAM|MANPADS?|[mM]anpads?)|[sS]tinger\b)/; export const HIDE_GROUP_MEMBERS = "Hide group members when zoomed out"; export const SHOW_UNIT_LABELS = "Show unit labels (L)"; diff --git a/client/src/map/map.ts b/client/src/map/map.ts index d9145a70..f6694b71 100644 --- a/client/src/map/map.ts +++ b/client/src/map/map.ts @@ -7,7 +7,7 @@ import { AirbaseContextMenu } from "../contextmenus/airbasecontextmenu"; import { Dropdown } from "../controls/dropdown"; import { Airbase } from "../mission/airbase"; import { Unit } from "../unit/unit"; -import { bearing, createCheckboxOption } from "../other/utils"; +import { bearing, createCheckboxOption, polyContains } from "../other/utils"; import { DestinationPreviewMarker } from "./markers/destinationpreviewmarker"; import { TemporaryUnitMarker } from "./markers/temporaryunitmarker"; import { ClickableMiniMap } from "./clickableminimap"; @@ -559,7 +559,7 @@ export class Map extends L.Map { /* Coalition areas are ordered in the #coalitionAreas array according to their zindex. Select the upper one */ for (let coalitionArea of this.#coalitionAreas) { - if (coalitionArea.getBounds().contains(e.latlng)) { + if (polyContains(e.latlng, coalitionArea)) { if (coalitionArea.getSelected()) clickedCoalitionArea = coalitionArea; else @@ -662,7 +662,7 @@ export class Map extends L.Map { this.#destinationGroupRotation = -bearing(this.#destinationRotationCenter.lat, this.#destinationRotationCenter.lng, this.getMouseCoordinates().lat, this.getMouseCoordinates().lng); this.#updateDestinationCursors(); } - else if (this.#state === COALITIONAREA_DRAW_POLYGON) { + else if (this.#state === COALITIONAREA_DRAW_POLYGON && e.latlng !== undefined) { this.#drawingCursor.setLatLng(e.latlng); /* Update the polygon being drawn with the current position of the mouse cursor */ this.getSelectedCoalitionArea()?.moveActiveVertex(e.latlng); diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index 4372bf16..5e8471de 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -1108,6 +1108,36 @@ export class UnitsManager { const activeEras = Object.keys(eras).filter((key: string) => { return eras[key]; }); const activeRanges = Object.keys(ranges).filter((key: string) => { return ranges[key]; }); + var airbases = getApp().getMissionManager().getAirbases(); + Object.keys(airbases).forEach((airbaseName: string) => { + var airbase = airbases[airbaseName]; + /* 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 depending on the city population */ + var pointsNumber = 2 + 40 * 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; + var distance = Math.random() * distribution * 100; + const latlng = bearingAndDistanceToLatLng(airbase.getLatLng().lat, airbase.getLatLng().lng, bearing, distance); + + /* Make sure the unit is still inside the coalition area */ + if (polyContains(latlng, coalitionArea)) { + const type = activeTypes[Math.floor(Math.random() * activeTypes.length)]; + 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); + }); + } + } + } + } + } + }) + citiesDatabase.forEach((city: { lat: number, lng: number, pop: number }) => { /* Check if the city is inside the coalition area */ if (polyContains(new LatLng(city.lat, city.lng), coalitionArea)) { @@ -1125,8 +1155,11 @@ 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); + 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); + }); + } } } } From b044d9a6c06dee45330af9847afaf231c00a3234 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Thu, 30 Nov 2023 15:46:48 +0100 Subject: [PATCH 2/2] Minor comments --- client/src/unit/unitsmanager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index 5e8471de..1eedccbc 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -1113,10 +1113,10 @@ export class UnitsManager { var airbase = airbases[airbaseName]; /* 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 depending on the city population */ + /* Arbitrary formula to obtain a number of units */ var pointsNumber = 2 + 40 * density / 100; for (let i = 0; i < pointsNumber; i++) { - /* Place the unit nearby the city, depending on the distribution parameter */ + /* Place the unit nearby the airbase, depending on the distribution parameter */ var bearing = Math.random() * 360; var distance = Math.random() * distribution * 100; const latlng = bearingAndDistanceToLatLng(airbase.getLatLng().lat, airbase.getLatLng().lng, bearing, distance);