feat(alarm state): refactor to separe alarm state from radar state. Kown issue: alarm state is not correctly mantained

This commit is contained in:
MarcoJayUsai
2025-03-24 18:42:04 +01:00
parent f7e9fc5cbc
commit 1622d663bb
15 changed files with 174 additions and 253 deletions

View File

@@ -132,7 +132,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
const [activeRadioSettings, setActiveRadioSettings] = useState(null as null | { radio: Radio; TACAN: TACAN });
const [activeAdvancedSettings, setActiveAdvancedSettings] = useState(null as null | GeneralSettings);
const [lastUpdateTime, setLastUpdateTime] = useState(0);
const [showScenicModes, setShowScenicModes] = useState(true);
const [showScenicModes, setShowScenicModes] = useState(false);
const [showEngagementSettings, setShowEngagementSettings] = useState(false);
const [barrelHeight, setBarrelHeight] = useState(0);
const [muzzleVelocity, setMuzzleVelocity] = useState(0);
@@ -420,9 +420,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
<td className="flex gap-2 text-lg text-gray-200">
<FontAwesomeIcon icon={entry[1][0] as IconDefinition} />{" "}
<div
className={`
text-sm text-gray-400
`}
className={`text-sm text-gray-400`}
>
{entry[1][1] as string}
</div>
@@ -802,9 +800,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsRoeHold}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Hold fire: The unit will not shoot in any circumstance
</div>
@@ -812,9 +808,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsRoeReturn}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Return fire: The unit will not fire unless fired upon
</div>
@@ -822,17 +816,13 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsRoeDesignated}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
<div>
{" "}
Fire on target: The unit will not fire unless fired upon{" "}
<p
className={`
inline font-bold
`}
className={`inline font-bold`}
>
or
</p>{" "}
@@ -843,9 +833,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsRoeFree}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Free: The unit will fire at any detected enemy in range
</div>
@@ -853,25 +841,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
<div className="flex gap-4">
<div className="my-auto">
<FaExclamationCircle
className={`
animate-bounce text-xl
`}
className={`animate-bounce text-xl`}
/>
</div>
<div>
Currently, DCS blue and red ground units do not respect{" "}
<FontAwesomeIcon
icon={olButtonsRoeReturn}
className={`
my-auto text-white
`}
className={`my-auto text-white`}
/>{" "}
and{" "}
<FontAwesomeIcon
icon={olButtonsRoeDesignated}
className={`
my-auto text-white
`}
className={`my-auto text-white`}
/>{" "}
rules of engagement, so be careful, they may start shooting when you don't want them to. Use neutral units for finer
control.
@@ -957,6 +939,18 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
tooltipRelativeToParent={true}
>
{[olButtonsRoeHold, olButtonsRoeReturn, olButtonsRoeDesignated].map((icon, idx) => {
const getAlarmStateByIdx = (idx) => {
switch (idx) {
case 0:
return AlarmState.AUTO;
case 1:
return AlarmState.GREEN;
case 2:
return AlarmState.RED;
}
}
return (
<OlButtonGroupItem
key={idx}
@@ -966,11 +960,11 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
.setAlarmState(idx, null, () =>
setForcedUnitsData({
...forcedUnitsData,
alarmState: Object.values(AlarmState)[idx],
alarmState: getAlarmStateByIdx(idx),
})
);
}}
active={selectedUnitsData.alarmState === alarmStates[idx]}
active={selectedUnitsData.alarmState === getAlarmStateByIdx(idx)}
icon={icon}
/>
);
@@ -1007,9 +1001,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsThreatNone}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
No reaction: The unit will not react in any circumstance
</div>
@@ -1017,9 +1009,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsThreatPassive}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Passive: The unit will use counter-measures, but will not alter its course
</div>
@@ -1027,9 +1017,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsThreatManoeuvre}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Manouevre: The unit will try to evade the threat using manoeuvres, but no counter-measures
</div>
@@ -1037,9 +1025,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsThreatEvade}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Full evasion: the unit will try to evade the threat both manoeuvering and using counter-measures
</div>
@@ -1094,9 +1080,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsEmissionsSilent}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Radio silence: No radar or ECM will be used
</div>
@@ -1104,9 +1088,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsEmissionsDefend}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Defensive: The unit will turn radar and ECM on only when threatened
</div>
@@ -1114,9 +1096,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsEmissionsAttack}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Attack: The unit will use radar and ECM when engaging other units
</div>
@@ -1124,9 +1104,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{" "}
<FontAwesomeIcon
icon={olButtonsEmissionsFree}
className={`
my-auto min-w-8 text-white
`}
className={`my-auto min-w-8 text-white`}
/>{" "}
Free: the unit will use the radar and ECM all the time
</div>
@@ -1347,9 +1325,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
<div className="flex gap-4">
<div className="my-auto">
<FaExclamationCircle
className={`
animate-bounce text-xl
`}
className={`animate-bounce text-xl`}
/>
</div>
<div>
@@ -1529,9 +1505,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
{/* ============== Operate as toggle START ============== */}
{selectedUnits.every((unit) => unit.getCoalition() === "neutral") && (
<div
className={`
flex content-center justify-between
`}
className={`flex content-center justify-between`}
>
<span
className={`
@@ -1573,17 +1547,13 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Barrel height:{" "}
</div>
<OlNumberInput
decimalPlaces={1}
className={`
ml-auto
`}
className={`ml-auto`}
value={barrelHeight}
min={0}
max={100}
@@ -1598,26 +1568,20 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Muzzle velocity:{" "}
</div>
<OlNumberInput
decimalPlaces={0}
className={`
ml-auto
`}
className={`ml-auto`}
value={muzzleVelocity}
min={0}
max={10000}
@@ -1632,26 +1596,20 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m/s
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Aim time:{" "}
</div>
<OlNumberInput
decimalPlaces={2}
className={`
ml-auto
`}
className={`ml-auto`}
value={aimTime}
min={0}
max={100}
@@ -1666,25 +1624,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
s
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Shots to fire:{" "}
</div>
<OlNumberInput
className={`
ml-auto
`}
className={`ml-auto`}
value={shotsToFire}
min={0}
max={100}
@@ -1701,17 +1653,13 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Shots base interval:{" "}
</div>
<OlNumberInput
decimalPlaces={2}
className={`
ml-auto
`}
className={`ml-auto`}
value={shotsBaseInterval}
min={0}
max={100}
@@ -1726,26 +1674,20 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
s
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Shots base scatter:{" "}
</div>
<OlNumberInput
decimalPlaces={2}
className={`
ml-auto
`}
className={`ml-auto`}
value={shotsBaseScatter}
min={0}
max={50}
@@ -1760,25 +1702,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
deg
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Engagement range:{" "}
</div>
<OlNumberInput
className={`
ml-auto
`}
className={`ml-auto`}
value={engagementRange}
min={0}
max={100000}
@@ -1793,25 +1729,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Targeting range:{" "}
</div>
<OlNumberInput
className={`
ml-auto
`}
className={`ml-auto`}
value={targetingRange}
min={0}
max={100000}
@@ -1826,25 +1756,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Aim method range:{" "}
</div>
<OlNumberInput
className={`
ml-auto
`}
className={`ml-auto`}
value={aimMethodRange}
min={0}
max={100000}
@@ -1859,25 +1783,19 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m
</div>
</div>
<div className="flex align-center gap-2">
<div
className={`
my-auto
`}
className={`my-auto`}
>
Acquisition range:{" "}
</div>
<OlNumberInput
className={`
ml-auto
`}
className={`ml-auto`}
value={acquisitionRange}
min={0}
max={100000}
@@ -1892,9 +1810,7 @@ export function UnitControlMenu(props: { open: boolean; onClose: () => void }) {
}}
></OlNumberInput>
<div
className={`
my-auto
`}
className={`my-auto`}
>
m
</div>