diff --git a/backend/core/src/scheduler.cpp b/backend/core/src/scheduler.cpp index 663600d6..fdbac585 100644 --- a/backend/core/src/scheduler.cpp +++ b/backend/core/src/scheduler.cpp @@ -377,6 +377,10 @@ void Scheduler::handleRequest(string key, json::value value, string username, js { vector cloneOptions; bool deleteOriginal = value[L"deleteOriginal"].as_bool(); + string coalition = to_string(value[L"coalition"]); + + int spawnPoints = value[L"spawnPoints"].as_number().to_int32(); + if (!checkSpawnPoints(spawnPoints, coalition)) return; for (auto unit : value[L"units"].as_array()) { unsigned int ID = unit[L"ID"].as_integer(); diff --git a/frontend/react/src/server/servermanager.ts b/frontend/react/src/server/servermanager.ts index 0f5307f9..7c624384 100644 --- a/frontend/react/src/server/servermanager.ts +++ b/frontend/react/src/server/servermanager.ts @@ -28,6 +28,7 @@ import { TACAN, } from "../interfaces"; import { MapOptionsChangedEvent, ServerStatusUpdatedEvent, WrongCredentialsEvent } from "../events"; +import { Coalition } from "../types/types"; export class ServerManager { #connected: boolean = false; @@ -341,9 +342,10 @@ export class ServerManager { this.PUT(data, callback); } - cloneUnits(units: { ID: number; location: LatLng }[], deleteOriginal: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { + cloneUnits(units: { ID: number; location: LatLng }[], deleteOriginal: boolean, spawnPoints: number, coalition: Coalition, callback: CallableFunction = () => {}) { var command = { units: units, + coalition: coalition, deleteOriginal: deleteOriginal, spawnPoints: spawnPoints, }; diff --git a/frontend/react/src/ui/contextmenus/spawncontextmenu.tsx b/frontend/react/src/ui/contextmenus/spawncontextmenu.tsx index 05245da0..f5e02fbe 100644 --- a/frontend/react/src/ui/contextmenus/spawncontextmenu.tsx +++ b/frontend/react/src/ui/contextmenus/spawncontextmenu.tsx @@ -122,8 +122,8 @@ export function SpawnContextMenu(props: {}) { setXPosition(xPosition - 60); setYPosition(yPosition - 40); } - }, [blueprint, translated]) - useEffect(translateMenu, [blueprint, translated]) + }, [blueprint, translated]); + useEffect(translateMenu, [blueprint, translated]); /* Filter the blueprints according to the label */ const filteredBlueprints: UnitBlueprint[] = []; @@ -306,6 +306,9 @@ export function SpawnContextMenu(props: {}) { /> ); })} + {blueprints.length === 0 && No aircraft available} )} @@ -353,6 +356,9 @@ export function SpawnContextMenu(props: {}) { /> ); })} + {blueprints.length === 0 && No helicopter available} )} @@ -403,6 +409,9 @@ export function SpawnContextMenu(props: {}) { /> ); })} + {blueprints.length === 0 && No air defence unit available} )} @@ -453,6 +462,9 @@ export function SpawnContextMenu(props: {}) { /> ); })} + {blueprints.length === 0 && No ground unit available} )} @@ -500,10 +512,13 @@ export function SpawnContextMenu(props: {}) { /> ); })} + {blueprints.length === 0 && No navy unit available} )} - {openAccordion === CategoryGroup.EFFECT && ( + {openAccordion === CategoryGroup.EFFECT && commandModeOptions.commandMode === GAME_MASTER && ( <>
)} + {openAccordion === CategoryGroup.EFFECT && commandModeOptions.commandMode !== GAME_MASTER && ( +
+ Not available in this mode +
+ )} {openAccordion === CategoryGroup.SEARCH && (
setFilterString(value)} text={filterString} /> diff --git a/frontend/react/src/ui/panels/airbasemenu.tsx b/frontend/react/src/ui/panels/airbasemenu.tsx index 5c046cb1..5637a7fa 100644 --- a/frontend/react/src/ui/panels/airbasemenu.tsx +++ b/frontend/react/src/ui/panels/airbasemenu.tsx @@ -117,10 +117,9 @@ export function AirbaseMenu(props: { open: boolean; onClose: () => void; childre
{Object.keys(runway.headings[0]).map((runwayName) => { return ( -
+
{" "} RWY {runwayName} @@ -213,6 +212,9 @@ export function AirbaseMenu(props: { open: boolean; onClose: () => void; childre /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "aircraft").length === 0 && ( + No aircraft available + )}
void; childre /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "helicopter").length === 0 && ( + No helicopter available + )}
diff --git a/frontend/react/src/ui/panels/spawnmenu.tsx b/frontend/react/src/ui/panels/spawnmenu.tsx index 3437c8f5..fd9a390b 100644 --- a/frontend/react/src/ui/panels/spawnmenu.tsx +++ b/frontend/react/src/ui/panels/spawnmenu.tsx @@ -124,12 +124,19 @@ export function SpawnMenu(props: { open: boolean; onClose: () => void; children?

Spawn menu

The spawn menu allows you to spawn new units in the current mission.

Moreover, it allows you to spawn effects like smokes and explosions.

-

You can use the search bar to quickly find a specific unit. Otherwise, open the category you are interested in, and use the filters to refine your selection.

- -
Click on a unit to enter the spawn properties menu. The menu is divided into multiple sections: +

+ You can use the search bar to quickly find a specific unit. Otherwise, open the category you are interested in, and use the filters to refine your + selection.{" "} +

+ +
+ Click on a unit to enter the spawn properties menu. The menu is divided into multiple sections:
  • Unit name and short description
  • Quick access name
  • @@ -139,11 +146,18 @@ export function SpawnMenu(props: { open: boolean; onClose: () => void; children?

To get more info on each control, hover your cursor on it.

Quick access

-

If you plan on reusing the same spawn multiple times during the mission, you can "star" the spawn properties. This will allow you to reuse them quickly multiple times. The starred spawn will save all settings, so you can create starred spawn with multiple variations, e.g. loadouts, or skill levels.

- +

+ If you plan on reusing the same spawn multiple times during the mission, you can "star" the spawn properties. This will allow you to reuse them + quickly multiple times. The starred spawn will save all settings, so you can create starred spawn with multiple variations, e.g. loadouts, or + skill levels. +

+
); }} @@ -202,6 +216,9 @@ export function SpawnMenu(props: { open: boolean; onClose: () => void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "aircraft").length === 0 && ( + No aircraft available + )}
void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "helicopter").length === 0 && ( + No helicopter available + )}
void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "groundunit" && blueprint.type === "SAM Site").length === 0 && ( + No SAM sites available + )} void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.canAAA).length === 0 && No AAA unit available} void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "groundunit" && blueprint.type !== "SAM Site").length === 0 && ( + No ground unit available + )} void; children? /> ); })} + {filteredBlueprints.filter((blueprint) => blueprint.category === "navyunit").length === 0 && ( + No navy unit available + )} - { - setOpenAccordion(openAccordion === CategoryAccordion.EFFECT ? CategoryAccordion.NONE : CategoryAccordion.EFFECT); - setSelectedRole(null); - setSelectedType(null); - }} - > -
{ + setOpenAccordion(openAccordion === CategoryAccordion.EFFECT ? CategoryAccordion.NONE : CategoryAccordion.EFFECT); + setSelectedRole(null); + setSelectedType(null); + }} > - { - setEffect("explosion"); - }} - /> - { - setEffect("smoke"); - }} - /> -
-
+
+ { + setEffect("explosion"); + }} + /> + { + setEffect("smoke"); + }} + /> +
+ + )} )} diff --git a/frontend/react/src/unit/unitsmanager.ts b/frontend/react/src/unit/unitsmanager.ts index 39003f66..99ce1c2c 100644 --- a/frontend/react/src/unit/unitsmanager.ts +++ b/frontend/react/src/unit/unitsmanager.ts @@ -13,7 +13,7 @@ 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 { BLUE_COMMANDER, DELETE_CYCLE_TIME, DELETE_SLOW_THRESHOLD, DataIndexes, GAME_MASTER, IADSDensities, OlympusState, RED_COMMANDER, UnitControlSubState } from "../constants/constants"; import { DataExtractor } from "../server/dataextractor"; import { citiesDatabase } from "./databases/citiesdatabase"; import { TemporaryUnitMarker } from "../map/markers/temporaryunitmarker"; @@ -39,6 +39,7 @@ import { import { UnitDatabase } from "./databases/unitdatabase"; import * as turf from "@turf/turf"; import { PathMarker } from "../map/markers/pathmarker"; +import { Coalition } from "../types/types"; /** The UnitsManager handles the creation, update, and control of units. Data is strictly updated by the server ONLY. This means that any interaction from the user will always and only * result in a command to the server, executed by means of a REST PUT request. Any subsequent change in data will be reflected only when the new data is sent back by the server. This strategy allows @@ -1257,12 +1258,20 @@ export class UnitsManager { if (units === null) units = this.getSelectedUnits(); units = units.filter((unit) => !unit.getHuman()); + // TODO: maybe check units are all of same coalition? + let callback = (units) => { onExecution(); if (this.getUnitsCategories(units).length == 1) { var unitsData: { ID: number; location: LatLng }[] = []; units.forEach((unit: Unit) => unitsData.push({ ID: unit.ID, location: unit.getPosition() })); - getApp().getServerManager().cloneUnits(unitsData, true, 0 /* No spawn points, we delete the original units */); + + /* Determine the coalition */ + let coalition = "all"; + if (getApp().getMissionManager().getCommandModeOptions().commandMode === BLUE_COMMANDER) coalition = "blue"; + else if (getApp().getMissionManager().getCommandModeOptions().commandMode === RED_COMMANDER) coalition = "red"; + + getApp().getServerManager().cloneUnits(unitsData, true, 0 /* No spawn points, we delete the original units */, coalition as Coalition); this.#showActionMessage(units, `created a group`); } else { getApp().addInfoMessage(`Groups can only be created from units of the same category`); @@ -1469,9 +1478,13 @@ export class UnitsManager { units.push({ ID: unit.ID, location: position }); }); + let coalition = "all"; + if (getApp().getMissionManager().getCommandModeOptions().commandMode === BLUE_COMMANDER) coalition = "blue"; + else if (getApp().getMissionManager().getCommandModeOptions().commandMode === RED_COMMANDER) coalition = "red"; + getApp() .getServerManager() - .cloneUnits(units, false, spawnPoints, (res: any) => { + .cloneUnits(units, false, getApp().getMissionManager().getCommandModeOptions().commandMode === GAME_MASTER? 0: spawnPoints, coalition as Coalition, (res: any) => { if (res !== undefined) { markers.forEach((marker: TemporaryUnitMarker) => { marker.setCommandHash(res); @@ -1655,7 +1668,7 @@ export class UnitsManager { getApp().addInfoMessage("Aircrafts can be air spawned during the SETUP phase only"); return false; } - spawnPoints = units.reduce((points: number, unit: UnitSpawnTable) => { + spawnPoints = getApp().getMissionManager().getCommandModeOptions().commandMode === GAME_MASTER? 0: units.reduce((points: number, unit: UnitSpawnTable) => { return points + this.getDatabase().getSpawnPointsByName(unit.unitType); }, 0); spawnFunction = () => getApp().getServerManager().spawnAircrafts(units, coalition, airbase, country, immediate, spawnPoints, callback); @@ -1664,7 +1677,7 @@ export class UnitsManager { getApp().addInfoMessage("Helicopters can be air spawned during the SETUP phase only"); return false; } - spawnPoints = units.reduce((points: number, unit: UnitSpawnTable) => { + spawnPoints = getApp().getMissionManager().getCommandModeOptions().commandMode === GAME_MASTER? 0: units.reduce((points: number, unit: UnitSpawnTable) => { return points + this.getDatabase().getSpawnPointsByName(unit.unitType); }, 0); spawnFunction = () => getApp().getServerManager().spawnHelicopters(units, coalition, airbase, country, immediate, spawnPoints, callback); @@ -1673,7 +1686,7 @@ export class UnitsManager { getApp().addInfoMessage("Ground units can be spawned during the SETUP phase only"); return false; } - spawnPoints = units.reduce((points: number, unit: UnitSpawnTable) => { + spawnPoints = getApp().getMissionManager().getCommandModeOptions().commandMode === GAME_MASTER? 0: units.reduce((points: number, unit: UnitSpawnTable) => { return points + this.getDatabase().getSpawnPointsByName(unit.unitType); }, 0); spawnFunction = () => getApp().getServerManager().spawnGroundUnits(units, coalition, country, immediate, spawnPoints, callback); @@ -1682,7 +1695,7 @@ export class UnitsManager { getApp().addInfoMessage("Navy units can be spawned during the SETUP phase only"); return false; } - spawnPoints = units.reduce((points: number, unit: UnitSpawnTable) => { + spawnPoints = getApp().getMissionManager().getCommandModeOptions().commandMode === GAME_MASTER? 0: units.reduce((points: number, unit: UnitSpawnTable) => { return points + this.getDatabase().getSpawnPointsByName(unit.unitType); }, 0); spawnFunction = () => getApp().getServerManager().spawnNavyUnits(units, coalition, country, immediate, spawnPoints, callback);