From feae9a48060b3aa3ae4108e21cb8b6e4b1c9196a Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Tue, 13 Jun 2023 17:42:18 +0200 Subject: [PATCH] Minor bugfixes --- client/public/stylesheets/olympus.css | 5 ++- client/src/map/map.ts | 4 +- client/src/units/unitsmanager.ts | 54 +++++++++++++++------------ client/views/other/dialogs.ejs | 2 +- scripts/OlympusCommand.lua | 2 +- src/core/src/aircraft.cpp | 1 + src/core/src/unit.cpp | 3 ++ 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/client/public/stylesheets/olympus.css b/client/public/stylesheets/olympus.css index d4afca30..ef86e765 100644 --- a/client/public/stylesheets/olympus.css +++ b/client/public/stylesheets/olympus.css @@ -933,10 +933,11 @@ dl.ol-data-grid dd { } .ol-dialog { - align-self: center; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); background-color: var(--background-slate-blue); color: white; - justify-self: center; position: absolute; z-index: 9999; } diff --git a/client/src/map/map.ts b/client/src/map/map.ts index 83339a7a..04b85d28 100644 --- a/client/src/map/map.ts +++ b/client/src/map/map.ts @@ -494,9 +494,9 @@ export class Map extends L.Map { #createDestinationMarkers() { this.#resetDestinationMarkers(); - if (getUnitsManager().getSelectedUnits({ excludeHumans: true }).length > 0 && getUnitsManager().getSelectedUnits({ excludeHumans: true }).length < 20) { + if (getUnitsManager().getSelectedUnits({ excludeHumans: true }).length > 0) { /* Create the unit destination preview markers */ - this.#destinationPreviewMarkers = getUnitsManager().getSelectedUnits({ excludeHumans: true }).map((unit: Unit) => { + this.#destinationPreviewMarkers = getUnitsManager().getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }).map((unit: Unit) => { var marker = new DestinationPreviewMarker(this.getMouseCoordinates(), {interactive: false}); marker.addTo(this); return marker; diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index dc3fd58b..299c2e0a 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -123,7 +123,7 @@ export class UnitsManager { } } - getSelectedUnits(options?: { excludeHumans?: boolean }) { + getSelectedUnits(options?: { excludeHumans?: boolean, onlyOnePerGroup?: boolean }) { var selectedUnits = []; for (let ID in this.#units) { if (this.#units[ID].getSelected()) { @@ -133,6 +133,14 @@ export class UnitsManager { if (options) { if (options.excludeHumans) selectedUnits = selectedUnits.filter((unit: Unit) => { return !unit.getMissionData().flags.Human }); + if (options.onlyOnePerGroup) { + var temp: Unit[] = []; + for (let unit of selectedUnits) { + if (!temp.some((otherUnit: Unit) => unit.getBaseData().groupName == otherUnit.getBaseData().groupName)) + temp.push(unit); + } + selectedUnits = temp; + } } return selectedUnits; } @@ -181,7 +189,7 @@ export class UnitsManager { /*********************** Actions on selected units ************************/ selectedUnitsAddDestination(latlng: L.LatLng, mantainRelativePosition: boolean, rotation: number) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); /* Compute the destination for each unit. If mantainRelativePosition is true, compute the destination so to hold the relative distances */ var unitDestinations: { [key: number]: LatLng } = {}; @@ -210,7 +218,7 @@ export class UnitsManager { } selectedUnitsClearDestinations() { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { const unit = selectedUnits[idx]; if (unit.getTaskData().currentState === "Follow") { @@ -226,7 +234,7 @@ export class UnitsManager { } selectedUnitsLandAt(latlng: LatLng) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].landAt(latlng); } @@ -234,21 +242,21 @@ export class UnitsManager { } selectedUnitsChangeSpeed(speedChange: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].changeSpeed(speedChange); } } selectedUnitsChangeAltitude(altitudeChange: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].changeAltitude(altitudeChange); } } selectedUnitsSetSpeed(speed: number) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setSpeed(speed); } @@ -256,7 +264,7 @@ export class UnitsManager { } selectedUnitsSetSpeedType(speedType: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setSpeedType(speedType); } @@ -264,7 +272,7 @@ export class UnitsManager { } selectedUnitsSetAltitude(altitude: number) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setAltitude(altitude); } @@ -272,7 +280,7 @@ export class UnitsManager { } selectedUnitsSetAltitudeType(altitudeType: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setAltitudeType(altitudeType); } @@ -280,7 +288,7 @@ export class UnitsManager { } selectedUnitsSetROE(ROE: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setROE(ROE); } @@ -288,7 +296,7 @@ export class UnitsManager { } selectedUnitsSetReactionToThreat(reactionToThreat: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setReactionToThreat(reactionToThreat); } @@ -296,7 +304,7 @@ export class UnitsManager { } selectedUnitsSetEmissionsCountermeasures(emissionCountermeasure: string) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setEmissionsCountermeasures(emissionCountermeasure); } @@ -304,7 +312,7 @@ export class UnitsManager { } selectedUnitsSetOnOff(onOff: boolean) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setOnOff(onOff); } @@ -312,7 +320,7 @@ export class UnitsManager { } selectedUnitsSetFollowRoads(followRoads: boolean) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].setFollowRoads(followRoads); } @@ -321,7 +329,7 @@ export class UnitsManager { selectedUnitsAttackUnit(ID: number) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].attackUnit(ID); } @@ -345,7 +353,7 @@ export class UnitsManager { } selectedUnitsRefuel() { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].refuel(); } @@ -367,7 +375,7 @@ export class UnitsManager { else if (formation === "front") { offset.x = 100; offset.y = 0; offset.z = 0; } else offset = undefined; } - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); var count = 1; var xr = 0; var yr = 1; var zr = -1; var layer = 1; @@ -410,7 +418,7 @@ export class UnitsManager { } selectedUnitsComputeGroupDestination(latlng: LatLng, rotation: number) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); /* Compute the center of the group */ var center = { x: 0, y: 0 }; selectedUnits.forEach((unit: Unit) => { @@ -441,7 +449,7 @@ export class UnitsManager { } selectedUnitsBombPoint(mouseCoordinates: LatLng) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].bombPoint(mouseCoordinates); } @@ -449,7 +457,7 @@ export class UnitsManager { } selectedUnitsCarpetBomb(mouseCoordinates: LatLng) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].carpetBomb(mouseCoordinates); } @@ -457,7 +465,7 @@ export class UnitsManager { } selectedUnitsBombBuilding(mouseCoordinates: LatLng) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].bombBuilding(mouseCoordinates); } @@ -465,7 +473,7 @@ export class UnitsManager { } selectedUnitsFireAtArea(mouseCoordinates: LatLng) { - var selectedUnits = this.getSelectedUnits({ excludeHumans: true }); + var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: true }); for (let idx in selectedUnits) { selectedUnits[idx].fireAtArea(mouseCoordinates); } diff --git a/client/views/other/dialogs.ejs b/client/views/other/dialogs.ejs index 41ba1d34..bbf5badb 100644 --- a/client/views/other/dialogs.ejs +++ b/client/views/other/dialogs.ejs @@ -3,7 +3,7 @@

DCS Olympus

Dynamic Unit Command

-
Version v0.2.1
+
Version v0.3.0
diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index 34d74cb5..81ccd4ff 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -1,6 +1,6 @@ local version = "v0.3.0-alpha" -local debug = true +local debug = false Olympus.unitCounter = 1 Olympus.payloadRegistry = {} diff --git a/src/core/src/aircraft.cpp b/src/core/src/aircraft.cpp index 14c8c005..1284f903 100644 --- a/src/core/src/aircraft.cpp +++ b/src/core/src/aircraft.cpp @@ -58,6 +58,7 @@ void Aircraft::changeAltitude(wstring change) else if (getDesiredAltitude() >= 0) setDesiredAltitude(getDesiredAltitude() + ftToM(500)); } + if (getDesiredAltitude() < 0) setDesiredAltitude(0); diff --git a/src/core/src/unit.cpp b/src/core/src/unit.cpp index 0e402933..4b18efc7 100644 --- a/src/core/src/unit.cpp +++ b/src/core/src/unit.cpp @@ -60,6 +60,9 @@ void Unit::setDefaults(bool force) /* Set the default IDLE state */ setState(State::IDLE); + /* Set desired altitude to be equal to current altitude so the unit does not climb/descend after spawn */ + setDesiredAltitude(altitude); + /* Set the default options (these are all defaults so will only affect the export data, no DCS command will be sent) */ setROE(L"Designated", force); setReactionToThreat(L"Evade", force);