From c3c84b211578528715379324dfe1ab0bd8bff1bf Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Wed, 19 Apr 2023 16:30:14 +0200 Subject: [PATCH] Follow, tankers and AWACS completed --- client/src/controls/dropdown.ts | 16 ++++++++-- client/src/missionhandler/missionhandler.ts | 8 +++-- client/src/panels/unitcontrolpanel.ts | 33 ++++++++++++++++++--- src/core/include/unit.h | 7 +++-- src/core/src/airunit.cpp | 25 +++++++++++----- 5 files changed, 68 insertions(+), 21 deletions(-) diff --git a/client/src/controls/dropdown.ts b/client/src/controls/dropdown.ts index 7e59d00b..c675d1dd 100644 --- a/client/src/controls/dropdown.ts +++ b/client/src/controls/dropdown.ts @@ -24,9 +24,10 @@ export class Dropdown { this.#clip(); }); - this.#element.addEventListener("mouseleave", ev => { - this.#close(); - }); + // Commented out since it is a bit frustrating, particularly when the dropdown opens towards the top and not to the bottom + //this.#element.addEventListener("mouseleave", ev => { + // this.#close(); + //}); } setOptions(optionsList: string[]) @@ -61,7 +62,10 @@ export class Dropdown { this.#index = idx; this.#close(); this.#callback(option); + return true; } + else + return false; } reset() { @@ -73,6 +77,12 @@ export class Dropdown { return this.#value.innerText; } + setValue(value: string) { + var index = this.#optionsList.findIndex((option) => {return option === value}); + if (index > -1) + this.selectValue(index); + } + getIndex() { return this.#index; } diff --git a/client/src/missionhandler/missionhandler.ts b/client/src/missionhandler/missionhandler.ts index 98dae71a..e225eb1c 100644 --- a/client/src/missionhandler/missionhandler.ts +++ b/client/src/missionhandler/missionhandler.ts @@ -1,5 +1,5 @@ import { Marker, LatLng, Icon } from "leaflet"; -import { getMap, getUnitsManager } from ".."; +import { getInfoPopup, getMap, getUnitsManager } from ".."; import { Airbase } from "./airbase"; var bullseyeIcons = [ @@ -58,6 +58,8 @@ export class MissionHandler getMap().setView(new LatLng(-50.6, -42.7), 7); else if (this.#theatre == "Caucasus") getMap().setView(new LatLng(42.1, 42.3), 8); + + getInfoPopup().setText("Map set to " + this.#theatre); } } } @@ -93,8 +95,8 @@ export class MissionHandler { this.#airbasesMarkers[idx].setLatLng(new LatLng(airbase.latitude, airbase.longitude)); this.#airbasesMarkers[idx].setCoalition(airbase.coalition); - this.#airbasesMarkers[idx].setProperties(["Runway 1: 31L / 13R", "Runway 2: 31R / 13L", "TCN: 17X", "ILS: ---" ]); - this.#airbasesMarkers[idx].setParkings(["2x big", "5x small"]); + //this.#airbasesMarkers[idx].setProperties(["Runway 1: 31L / 13R", "Runway 2: 31R / 13L", "TCN: 17X", "ILS: ---" ]); + //this.#airbasesMarkers[idx].setParkings(["2x big", "5x small"]); } } } diff --git a/client/src/panels/unitcontrolpanel.ts b/client/src/panels/unitcontrolpanel.ts index 1880eba9..1af37976 100644 --- a/client/src/panels/unitcontrolpanel.ts +++ b/client/src/panels/unitcontrolpanel.ts @@ -210,13 +210,37 @@ export class UnitControlPanel extends Panel { if (getUnitsManager().getSelectedUnits().length == 1) { + var radioMHz = Math.floor(unit.getTaskData().radioFrequency / 1000000); + var radioDecimals = (unit.getTaskData().radioFrequency / 1000000 - radioMHz) * 1000; + + // Default values for "normal" units this.#radioCallsignDropdown.setOptions(["Enfield", "Springfield", "Uzi", "Colt", "Dodge", "Ford", "Chevy", "Pontiac"]); this.#radioCallsignDropdown.selectValue(unit.getTaskData().radioCallsign); - var tankerCheckbox = this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.querySelector("input") - if (tankerCheckbox) tankerCheckbox.checked = unit.getTaskData().isTanker; - var AWACSCheckbox = this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input") - if (AWACSCheckbox) AWACSCheckbox.checked = unit.getTaskData().isAWACS; + // Input values + var tankerCheckbox = this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.querySelector("input") + var AWACSCheckbox = this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input") + + var TACANChannelInput = this.#advancedSettingsDialog.querySelector("#TACAN-channel")?.querySelector("input"); + var TACANCallsignInput = this.#advancedSettingsDialog.querySelector("#tacan-callsign")?.querySelector("input"); + var radioMhzInput = this.#advancedSettingsDialog.querySelector("#radio-mhz")?.querySelector("input"); + var radioCallsignNumberInput = this.#advancedSettingsDialog.querySelector("#radio-callsign-number")?.querySelector("input"); + + if (tankerCheckbox) tankerCheckbox.checked = unit.getTaskData().isTanker; + if (AWACSCheckbox) AWACSCheckbox.checked = unit.getTaskData().isAWACS; + if (TACANChannelInput) TACANChannelInput.value = String(unit.getTaskData().TACANChannel); + if (TACANCallsignInput) TACANCallsignInput.value = String(unit.getTaskData().TACANCallsign); + if (radioMhzInput) radioMhzInput.value = String(radioMHz); + if (radioCallsignNumberInput) radioCallsignNumberInput.value = String(unit.getTaskData().radioCallsignNumber); + + this.#TACANXYDropdown.setValue(unit.getTaskData().TACANXY); + this.#radioDecimalsDropdown.setValue("." + radioDecimals); + + // Make sure its in the valid range + if (!this.#radioCallsignDropdown.selectValue(unit.getTaskData().radioCallsign)) + this.#radioCallsignDropdown.selectValue(0); + + // Set options for tankers var roles = aircraftDatabase.getByName(unit.getBaseData().name)?.loadouts.map((loadout) => {return loadout.roles}) if (roles != undefined && Array.prototype.concat.apply([], roles)?.includes("Tanker")){ this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.classList.remove("hide"); @@ -227,6 +251,7 @@ export class UnitControlPanel extends Panel { this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.classList.add("hide"); } + // Set options for AWACS if (roles != undefined && Array.prototype.concat.apply([], roles)?.includes("AWACS")){ this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.classList.remove("hide"); this.#radioCallsignDropdown.setOptions(["Overlord", "Magic", "Wizard", "Focus", "Darkstar"]); diff --git a/src/core/include/unit.h b/src/core/include/unit.h index 92b50083..441c3e75 100644 --- a/src/core/include/unit.h +++ b/src/core/include/unit.h @@ -169,6 +169,7 @@ protected: /********** Mission data **********/ double fuel = 0; + double initialFuel = 0; // Used internally to detect refueling completed json::value ammo = json::value::null(); json::value targets = json::value::null(); bool hasTask = false; @@ -193,12 +194,12 @@ protected: bool isTanker = false; bool isAWACS = false; bool TACANOn = false; - int TACANChannel = 0; + int TACANChannel = 40; wstring TACANXY = L"X"; wstring TACANCallsign = L"TKR"; bool radioOn = false; - int radioFrequency = 0; - int radioCallsign = 0; + int radioFrequency = 260000000; // MHz + int radioCallsign = 1; int radioCallsignNumber = 1; /********** Options data **********/ diff --git a/src/core/src/airunit.cpp b/src/core/src/airunit.cpp index 5d580b65..cf3d2369 100644 --- a/src/core/src/airunit.cpp +++ b/src/core/src/airunit.cpp @@ -83,6 +83,7 @@ void AirUnit::setState(int newState) break; } case State::REFUEL: { + initialFuel = fuel; clearActivePath(); resetActiveDestination(); addMeasure(L"currentState", json::value(L"Refuel")); @@ -192,6 +193,9 @@ void AirUnit::AIloop() if (isTanker) { taskSS << "{ [1] = { id = 'Tanker' }, [2] = { id = 'Orbit', pattern = 'Race-Track' } }"; } + else if (isAWACS) { + taskSS << "{ [1] = { id = 'AWACS' }, [2] = { id = 'Orbit', pattern = 'Circle' } }"; + } else { taskSS << "{ id = 'Orbit', pattern = 'Circle' }"; } @@ -239,7 +243,7 @@ void AirUnit::AIloop() break; } case State::LAND: { - wstring enrouteTask = L"{" "id = 'land' }"; + wstring enrouteTask = L"{ id = 'Land' }"; currentTask = L"Landing"; if (activeDestination == NULL) @@ -311,13 +315,18 @@ void AirUnit::AIloop() currentTask = L"Refueling"; if (!hasTask) { - std::wostringstream taskSS; - taskSS << "{" - << "id = 'Refuel'" - << "}"; - Command* command = dynamic_cast(new SetTask(ID, taskSS.str())); - scheduler->appendCommand(command); - hasTask = true; + if (fuel <= initialFuel) { + std::wostringstream taskSS; + taskSS << "{" + << "id = 'Refuel'" + << "}"; + Command* command = dynamic_cast(new SetTask(ID, taskSS.str())); + scheduler->appendCommand(command); + hasTask = true; + } + else { + setState(State::IDLE); + } } } default: