feat(alarm state): alarm state command is now working in DCS

This commit is contained in:
MarcoJayUsai
2025-03-21 16:21:35 +01:00
parent 2a00bab149
commit f1fcabe7f7
11 changed files with 119 additions and 45 deletions

View File

@@ -97,7 +97,7 @@ export const states: string[] = [
];
export const ROEs: string[] = ["free", "designated", "", "return", "hold"];
export const alarmStates: string[] = ["green", "auto", "red"];
export const alarmStates: string[] = ["auto", "green", "red"];
export const reactionsToThreat: string[] = ["none", "manoeuvre", "passive", "evade"];
export const emissionsCountermeasures: string[] = ["silent", "attack", "defend", "free"];
@@ -449,7 +449,7 @@ export enum DataIndexes {
startOfData = 0,
category,
alive,
radarState,
alarmState,
human,
controlled,
coalition,

View File

@@ -17,6 +17,7 @@ import {
} from "../constants/constants";
import {
AirbasesData,
AlarmState,
BullseyesData,
CommandModeOptions,
GeneralSettings,
@@ -410,6 +411,12 @@ export class ServerManager {
this.PUT(data, callback);
}
setAlarmState(ID: number, alarmState: number, callback: CallableFunction = () => {}) {
var command = { ID: ID, alarmState: alarmState };
var data = { commandAlarmState: command };
this.PUT(data, callback);
}
setReactionToThreat(ID: number, reactionToThreat: string, callback: CallableFunction = () => {}) {
var command = {
ID: ID,

View File

@@ -841,12 +841,6 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
<div className="flex flex-col gap-2">
<div>Sets the alarm state of the unit, in order:</div>
<div className="flex flex-col gap-2 px-2">
<div className="flex content-center gap-2">
{" "}
<FontAwesomeIcon icon={olButtonsRoeReturn} className={`
my-auto min-w-8 text-white
`} /> Green: The unit will not engage with its sensors in any circumstances. The unit will be able to move.
</div>
<div className="flex content-center gap-2">
{" "}
<FontAwesomeIcon icon={olButtonsRoeDesignated} className={`
@@ -857,6 +851,12 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
Auto: The unit will use its sensors to engage based on its ROE.
</div>
</div>
<div className="flex content-center gap-2">
{" "}
<FontAwesomeIcon icon={olButtonsRoeReturn} className={`
my-auto min-w-8 text-white
`} /> Green: The unit will not engage with its sensors in any circumstances. The unit will be able to move.
</div>
<div className="flex content-center gap-2">
{" "}
<FontAwesomeIcon icon={olButtonsRoeHold} className={`
@@ -876,15 +876,14 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
<OlButtonGroupItem
key={idx}
onClick={() => {
// TODO: set alarm state
// getApp()
// .getUnitsManager()
// .setROE(ROEs[convertROE(idx)], null, () =>
// setForcedUnitsData({
// ...forcedUnitsData,
// ROE: ROEs[convertROE(idx)],
// })
// );
getApp()
.getUnitsManager()
.setAlarmState(idx, null, () =>
setForcedUnitsData({
...forcedUnitsData,
alarmState: Object.values(AlarmState)[idx],
})
);
}}
active={selectedUnitsData.alarmState === alarmStates[idx]}
icon={icon}

View File

@@ -492,17 +492,17 @@ export abstract class Unit extends CustomMarker {
this.setAlive(dataExtractor.extractBool());
updateMarker = true;
break;
case DataIndexes.radarState:
case DataIndexes.alarmState:
let stringAlarmState = dataExtractor.extractString();
switch (stringAlarmState) {
case 'RED':
this.setRadarState(AlarmState.RED);
this.setAlarmState(AlarmState.RED);
break;
case 'GREEN':
this.setRadarState(AlarmState.GREEN);
this.setAlarmState(AlarmState.GREEN);
break;
case '':
this.setRadarState(AlarmState.AUTO);
this.setAlarmState(AlarmState.AUTO);
default:
break;
}
@@ -785,11 +785,10 @@ export abstract class Unit extends CustomMarker {
}
}
setRadarState(newRadarState: AlarmState) {
if (newRadarState != this.#alarmState) {
this.#alarmState = newRadarState;
// TODO: check if an event is needed -- surely yes to update the UI
console.log('----radar state updated: ', this.#alarmState);
setAlarmState(newAlarmState: AlarmState) {
if (newAlarmState != this.#alarmState) {
this.#alarmState = newAlarmState;
console.log('---- alarm state updated: ', this.#alarmState);
this.#updateMarker();
}
}
@@ -1070,9 +1069,9 @@ export abstract class Unit extends CustomMarker {
/* Radar state indicator */
if (this.#alarmState) {
var radarStateIcon = document.createElement("div");
radarStateIcon.classList.add("unit-radar-state");
el.append(radarStateIcon);
var alarmStateIcon = document.createElement("div");
alarmStateIcon.classList.add("unit-radar-state");
el.append(alarmStateIcon);
}
/* Ammo indicator */
@@ -1295,6 +1294,10 @@ export abstract class Unit extends CustomMarker {
if (!this.#human) getApp().getServerManager().setROE(this.ID, ROE);
}
commandAlarmState(alarmState: number) {
if (!this.#human) getApp().getServerManager().setAlarmState(this.ID, alarmState);
}
setReactionToThreat(reactionToThreat: string) {
if (!this.#human) getApp().getServerManager().setReactionToThreat(this.ID, reactionToThreat);
}

View File

@@ -13,11 +13,11 @@ import {
msToKnots,
} from "../other/utils";
import { CoalitionPolygon } from "../map/coalitionarea/coalitionpolygon";
import { DELETE_CYCLE_TIME, DELETE_SLOW_THRESHOLD, DataIndexes, GAME_MASTER, IADSDensities, OlympusState, UnitControlSubState } from "../constants/constants";
import { DELETE_CYCLE_TIME, DELETE_SLOW_THRESHOLD, DataIndexes, GAME_MASTER, IADSDensities, OlympusState, UnitControlSubState, alarmStates } from "../constants/constants";
import { DataExtractor } from "../server/dataextractor";
import { citiesDatabase } from "./databases/citiesdatabase";
import { TemporaryUnitMarker } from "../map/markers/temporaryunitmarker";
import { Contact, GeneralSettings, Radio, TACAN, UnitBlueprint, UnitData, UnitSpawnTable } from "../interfaces";
import { AlarmState, Contact, GeneralSettings, Radio, TACAN, UnitBlueprint, UnitData, UnitSpawnTable } from "../interfaces";
import { Group } from "./group";
import { CoalitionCircle } from "../map/coalitionarea/coalitioncircle";
import { ContextActionSet } from "./contextactionset";
@@ -719,6 +719,27 @@ export class UnitsManager {
this.#protectionCallback = callback;
} else callback(units);
}
/** Set a specific Alarm State to all the selected units
*
* @param AlarmState Value to set, see constants for acceptable values
* @param units (Optional) Array of units to apply the control to. If not provided, the operation will be completed on all selected units.
*/
setAlarmState(alarmState: number, units: Unit[] | null = null, onExecution: () => void = () => {}) {
if (units === null) units = this.getSelectedUnits();
units = units.filter((unit) => !unit.getHuman());
let callback = (units) => {
onExecution();
units.forEach((unit: Unit) => unit.commandAlarmState(alarmState));
this.#showActionMessage(units, `Alarm State set to ${alarmState.toString()}`);
};
if (getApp().getMap().getOptions().protectDCSUnits && !units.every((unit) => unit.isControlledByOlympus())) {
getApp().setState(OlympusState.UNIT_CONTROL, UnitControlSubState.PROTECTION);
this.#protectionCallback = callback;
} else callback(units);
}
/** Set a specific reaction to threat to all the selected units
*
* @param reactionToThreat Value to set, see constants for acceptable values