Added target altitude effect to simulated fire fight

This commit is contained in:
Pax1601
2023-09-22 16:05:03 +02:00
parent 18307caab3
commit f3155e618b
9 changed files with 56 additions and 21 deletions

View File

@@ -608,8 +608,8 @@ export class Map extends L.Map {
getApp().getUnitsManager().selectedUnitsFireAtArea(this.getMouseCoordinates());
}
else if (option === "simulate-fire-fight") {
getUnitsManager().getSelectedUnits().length > 0 ? this.setState(MOVE_UNIT) : this.setState(IDLE);
getUnitsManager().selectedUnitsSimulateFireFight(this.getMouseCoordinates());
getApp().getUnitsManager().getSelectedUnits().length > 0 ? this.setState(MOVE_UNIT) : this.setState(IDLE);
getApp().getUnitsManager().selectedUnitsSimulateFireFight(this.getMouseCoordinates());
}
});
}

View File

@@ -397,4 +397,19 @@ export function getCheckboxOptions(dropdown: Dropdown) {
values[key] = value;
}
return values;
}
export function getGroundElevation(latlng: LatLng, callback: CallableFunction) {
/* Get the ground elevation from the server endpoint */
const xhr = new XMLHttpRequest();
xhr.open('GET', `api/elevation/${latlng.lat}/${latlng.lng}`, true);
xhr.timeout = 500; // ms
xhr.responseType = 'json';
xhr.onload = () => {
var status = xhr?.status;
if (status === 200) {
callback(xhr.response)
}
};
xhr.send();
}

View File

@@ -322,8 +322,8 @@ export class ServerManager {
this.POST(data, callback);
}
simulateFireFight(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) {
var command = { "ID": ID, "location": latlng }
simulateFireFight(ID: number, latlng: LatLng, altitude: number, callback: CallableFunction = () => {}) {
var command = { "ID": ID, "location": latlng, "altitude": altitude }
var data = { "simulateFireFight": command }
this.POST(data, callback);
}

View File

@@ -722,8 +722,8 @@ export class Unit extends CustomMarker {
getApp().getServerManager().fireAtArea(this.ID, latlng);
}
simulateFireFight(latlng: LatLng) {
getApp().getServerManager().simulateFireFight(this.ID, latlng);
simulateFireFight(latlng: LatLng, groundElevation: number | null) {
getApp().getServerManager().simulateFireFight(this.ID, latlng, groundElevation?? 0);
}
/***********************************************/

View File

@@ -1,7 +1,7 @@
import { LatLng, LatLngBounds } from "leaflet";
import { getApp } from "..";
import { Unit } from "./unit";
import { bearingAndDistanceToLatLng, deg2rad, getUnitDatabaseByCategory, keyEventWasInInput, latLngToMercator, mToFt, mercatorToLatLng, msToKnots, polyContains, polygonArea, randomPointInPoly, randomUnitBlueprint } from "../other/utils";
import { bearingAndDistanceToLatLng, deg2rad, getGroundElevation, getUnitDatabaseByCategory, keyEventWasInInput, latLngToMercator, mToFt, mercatorToLatLng, msToKnots, polyContains, polygonArea, randomPointInPoly, randomUnitBlueprint } from "../other/utils";
import { CoalitionArea } from "../map/coalitionarea/coalitionarea";
import { groundUnitDatabase } from "./databases/groundunitdatabase";
import { DataIndexes, GAME_MASTER, IADSDensities, IDLE, MOVE_UNIT } from "../constants/constants";
@@ -590,7 +590,7 @@ export class UnitsManager {
for (let idx in selectedUnits) {
selectedUnits[idx].carpetBomb(latlng);
}
this.#showActionMessage(selectedUnits, `unit bombing point`);
this.#showActionMessage(selectedUnits, `unit carpet bombing point`);
}
/** Instruct the selected units to fire at specific coordinates
@@ -602,7 +602,7 @@ export class UnitsManager {
for (let idx in selectedUnits) {
selectedUnits[idx].fireAtArea(latlng);
}
this.#showActionMessage(selectedUnits, `unit bombing point`);
this.#showActionMessage(selectedUnits, `unit firing at area`);
}
/** Instruct the selected units to simulate a fire fight at specific coordinates
@@ -611,9 +611,17 @@ export class UnitsManager {
*/
selectedUnitsSimulateFireFight(latlng: LatLng) {
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true });
for (let idx in selectedUnits) {
selectedUnits[idx].simulateFireFight(latlng);
}
getGroundElevation(latlng, (response: string) => {
var groundElevation: number | null = null;
try {
groundElevation = parseFloat(response);
} catch {
console.log("Simulate fire fight: could not retrieve ground elevation")
}
for (let idx in selectedUnits) {
selectedUnits[idx].simulateFireFight(latlng, groundElevation);
}
});
this.#showActionMessage(selectedUnits, `unit simulating fire fight`);
}