feat: started implementing infrared and laser

This commit is contained in:
Pax1601
2025-01-29 08:03:32 +01:00
parent 79f9905413
commit 5a4a202805
10 changed files with 231 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import {
faClone,
faExplosion,
faHand,
faLightbulb,
faLocationCrosshairs,
faLocationDot,
faMapLocation,
@@ -887,6 +888,32 @@ export namespace ContextActions {
{ type: ContextActionType.ENGAGE, code: "KeyV", ctrlKey: false, shiftKey: false }
);
export const FIRE_LASER = new ContextAction(
"fire-laser",
"Shine laser at point",
"Click on a point to shine a laser with the given code from the unit to the ground.",
faLightbulb,
ContextActionTarget.POINT,
(units: Unit[], _, targetPosition: LatLng | null) => {
if (targetPosition)
getApp().getUnitsManager().fireLaser(targetPosition, getApp().getMap().getKeepRelativePositions(), getApp().getMap().getDestinationRotation(), units);
},
{ type: ContextActionType.ENGAGE, code: "KeyL", ctrlKey: true, shiftKey: false }
);
export const FIRE_INFRARED = new ContextAction(
"fire-infrared",
"Shine infrared at point",
"Click on a point to shine a infrared beam from the unit to the ground.",
faLightbulb,
ContextActionTarget.POINT,
(units: Unit[], _, targetPosition: LatLng | null) => {
if (targetPosition)
getApp().getUnitsManager().fireInfrared(targetPosition, getApp().getMap().getKeepRelativePositions(), getApp().getMap().getDestinationRotation(), units);
},
{ type: ContextActionType.ENGAGE, code: "KeyL", ctrlKey: true, shiftKey: false }
);
export const SIMULATE_FIRE_FIGHT = new ContextAction(
"simulate-fire-fight",
"Simulate fire fight",

View File

@@ -67,8 +67,9 @@ export class TemporaryUnitMarker extends CustomMarker {
el.append(unitIcon);
// Short label
let shortLabel: null | HTMLDivElement = null;
if (blueprint.category == "aircraft" || blueprint.category == "helicopter") {
var shortLabel = document.createElement("div");
shortLabel = document.createElement("div");
shortLabel.classList.add("unit-short-label");
shortLabel.innerText = blueprint?.shortLabel || "";
el.append(shortLabel);
@@ -88,7 +89,8 @@ export class TemporaryUnitMarker extends CustomMarker {
const rotateHandle = (heading) => {
el.style.transform = `rotate(${heading}deg)`;
unitIcon.style.transform = `rotate(-${heading}deg)`;
shortLabel.style.transform = `rotate(-${heading}deg)`;
if (shortLabel)
shortLabel.style.transform = `rotate(-${heading}deg)`;
};
SpawnHeadingChangedEvent.on((heading) => rotateHandle(heading));

View File

@@ -192,6 +192,9 @@ export class OlympusApp {
this.getServerManager().setActiveCommandMode(GAME_MASTER);
}
else if (this.getState() !== OlympusState.LOGIN) {
this.setState(OlympusState.LOGIN, LoginSubState.CREDENTIALS);
}
} else if (this.getState() !== OlympusState.LOGIN) {
this.setState(OlympusState.LOGIN, LoginSubState.CREDENTIALS);
}

View File

@@ -450,6 +450,18 @@ export class ServerManager {
this.PUT(data, callback);
}
fireLaser(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) {
var command = { ID: ID, location: latlng, code: 1688 };
var data = { fireLaser: command };
this.PUT(data, callback);
}
fireInfrared(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) {
var command = { ID: ID, location: latlng };
var data = { fireInfrared: command };
this.PUT(data, callback);
}
simulateFireFight(ID: number, latlng: LatLng, altitude: number, callback: CallableFunction = () => {}) {
var command = { ID: ID, location: latlng, altitude: altitude };
var data = { simulateFireFight: command };

View File

@@ -915,6 +915,8 @@ export abstract class Unit extends CustomMarker {
contextActionSet.addContextAction(this, ContextActions.CENTER_MAP);
contextActionSet.addContextAction(this, ContextActions.CLONE);
contextActionSet.addContextAction(this, ContextActions.ATTACK);
contextActionSet.addContextAction(this, ContextActions.FIRE_LASER);
contextActionSet.addContextAction(this, ContextActions.FIRE_INFRARED);
contextActionSet.addDefaultContextAction(this, ContextActions.MOVE);
}
@@ -1325,6 +1327,14 @@ export abstract class Unit extends CustomMarker {
getApp().getServerManager().fireAtArea(this.ID, latlng);
}
fireLaser(latlng: LatLng) {
getApp().getServerManager().fireLaser(this.ID, latlng);
}
fireInfrared(latlng: LatLng) {
getApp().getServerManager().fireInfrared(this.ID, latlng);
}
simulateFireFight(latlng: LatLng, targetGroundElevation: number | null) {
getGroundElevation(this.getPosition(), (response: string) => {
var unitGroundElevation: number | null = null;

View File

@@ -895,6 +895,61 @@ export class UnitsManager {
this.#protectionCallback = callback;
} else callback(units);
}
/** Instruct the selected units to fire at specific coordinates
*
* @param latlng Location to fire at
* @param units (Optional) Array of units to apply the control to. If not provided, the operation will be completed on all selected units.
*/
fireLaser(latlng: LatLng, mantainRelativePosition: boolean, rotation: number = 0, units: Unit[] | null = null) {
if (units === null) units = this.getSelectedUnits();
units = units.filter((unit) => !unit.getHuman());
let callback = (units) => {
/* Compute the target for each unit. If mantainRelativePosition is true, compute the target so to hold the relative positions */
var unitTargets: { [key: number]: LatLng } = {};
if (mantainRelativePosition) unitTargets = this.computeGroupDestination(latlng, rotation);
else
units.forEach((unit: Unit) => {
unitTargets[unit.ID] = latlng;
});
units.forEach((unit: Unit) => unit.fireLaser(unitTargets[unit.ID]));
this.#showActionMessage(units, `unit shining laser at point`);
};
if (getApp().getMap().getOptions().protectDCSUnits && !units.every((unit) => unit.isControlledByOlympus())) {
getApp().setState(OlympusState.UNIT_CONTROL, UnitControlSubState.PROTECTION);
this.#protectionCallback = callback;
} else callback(units);
}
/** Instruct the selected units to fire at specific coordinates
*
* @param latlng Location to fire at
* @param units (Optional) Array of units to apply the control to. If not provided, the operation will be completed on all selected units.
*/
fireInfrared(latlng: LatLng, mantainRelativePosition: boolean, rotation: number = 0, units: Unit[] | null = null) {
if (units === null) units = this.getSelectedUnits();
units = units.filter((unit) => !unit.getHuman());
let callback = (units) => {
/* Compute the target for each unit. If mantainRelativePosition is true, compute the target so to hold the relative positions */
var unitTargets: { [key: number]: LatLng } = {};
if (mantainRelativePosition) unitTargets = this.computeGroupDestination(latlng, rotation);
else
units.forEach((unit: Unit) => {
unitTargets[unit.ID] = latlng;
});
units.forEach((unit: Unit) => unit.fireInfrared(unitTargets[unit.ID]));
this.#showActionMessage(units, `unit shining infrared at point`);
};
if (getApp().getMap().getOptions().protectDCSUnits && !units.every((unit) => unit.isControlledByOlympus())) {
getApp().setState(OlympusState.UNIT_CONTROL, UnitControlSubState.PROTECTION);
this.#protectionCallback = callback;
} else callback(units);
}
/** Instruct the selected units to simulate a fire fight at specific coordinates
*
* @param latlng Location to fire at