Added backend for altitude type, onOff, follow roads and explosion

This commit is contained in:
Pax1601 2023-06-05 21:22:22 +02:00
parent ec0b179e32
commit dca3438db0
24 changed files with 198 additions and 91 deletions

View File

@ -26,7 +26,7 @@ export class MapContextMenu extends ContextMenu {
#aircrafSpawnAltitudeSlider: Slider;
#groundUnitRoleDropdown: Dropdown;
#groundUnitTypeDropdown: Dropdown;
#spawnOptions: SpawnOptions = { role: "", type: "", latlng: new LatLng(0, 0), loadout: null, coalition: "blue", airbaseName: null, altitude: 20000 };
#spawnOptions: SpawnOptions = { role: "", type: "", latlng: new LatLng(0, 0), loadout: null, coalition: "blue", airbaseName: null, altitude: 20000 * 0.3048 };
constructor(id: string) {
super(id);
@ -37,7 +37,7 @@ export class MapContextMenu extends ContextMenu {
this.#aircraftRoleDropdown = new Dropdown("aircraft-role-options", (role: string) => this.#setAircraftRole(role));
this.#aircraftTypeDropdown = new Dropdown("aircraft-type-options", (type: string) => this.#setAircraftType(type));
this.#aircraftLoadoutDropdown = new Dropdown("loadout-options", (loadout: string) => this.#setAircraftLoadout(loadout));
this.#aircrafSpawnAltitudeSlider = new Slider("aircraft-spawn-altitude-slider", 0, 50000, "ft", (value: number) => {this.#spawnOptions.altitude = value;});
this.#aircrafSpawnAltitudeSlider = new Slider("aircraft-spawn-altitude-slider", 0, 50000, "ft", (value: number) => {this.#spawnOptions.altitude = value * 0.3048;});
this.#groundUnitRoleDropdown = new Dropdown("ground-unit-role-options", (role: string) => this.#setGroundUnitRole(role));
this.#groundUnitTypeDropdown = new Dropdown("ground-unit-type-options", (type: string) => this.#setGroundUnitType(type));

View File

@ -87,7 +87,7 @@ export class MissionHandler
}
}
if ("mission" in data)
if ("mission" in data && data.mission != null)
{
if (data.mission != null && data.mission.theatre != this.#theatre)
{

View File

@ -88,6 +88,8 @@ export class UnitControlPanel extends Panel {
this.#altitudeTypeSwitch.resetExpectedValue();
this.#onOffSwitch.resetExpectedValue();
this.#followRoadsSwitch.resetExpectedValue();
this.#altitudeSlider.resetExpectedValue();
this.#speedSlider.resetExpectedValue();
}
addButtons() {

View File

@ -211,7 +211,7 @@ export class Unit extends CustomMarker {
if (key1 in data && key2 in data[key1]) {
var value1 = this.#data[key1 as keyof(UnitData)];
var value2 = value1[key2 as keyof typeof value1];
if (typeof data[key1][key2] === typeof value2)
if (typeof data[key1][key2] === typeof value2 || typeof value2 === "undefined")
//@ts-ignore
this.#data[key1 as keyof(UnitData)][key2 as keyof typeof struct] = data[key1][key2];
}

View File

@ -22,6 +22,7 @@ export class UnitsManager {
document.addEventListener('unitDeselection', (e: CustomEvent) => this.#onUnitDeselection(e.detail));
document.addEventListener('deleteSelectedUnits', () => this.selectedUnitsDelete());
document.addEventListener('explodeSelectedUnits', () => this.selectedUnitsDelete(true));
document.addEventListener('keyup', (event) => this.#onKeyUp(event));
}
getSelectableAircraft() {
@ -457,6 +458,12 @@ export class UnitsManager {
}
/***********************************************/
#onKeyUp(event: KeyboardEvent) {
if (!keyEventWasInInput(event) && event.key === "Delete" ) {
this.selectedUnitsDelete();
}
}
#onUnitSelection(unit: Unit) {
if (this.getSelectedUnits().length > 0) {
getMap().setState(MOVE_UNIT);

View File

@ -1,6 +1,6 @@
{
"server": {
"address": "136.243.170.132",
"address": "localhost",
"port": 30000
},
"authentication": {

View File

@ -145,23 +145,27 @@ function Olympus.buildTask(options)
end
-- Move a unit. Since many tasks in DCS are Enroute tasks, this function is an important way to control the unit AI
function Olympus.move(ID, lat, lng, altitude, speed, category, taskOptions)
Olympus.debug("Olympus.move " .. ID .. " (" .. lat .. ", " .. lng ..") " .. altitude .. "m " .. speed .. "m/s " .. category, 2)
function Olympus.move(ID, lat, lng, altitude, altitudeType, speed, speedType, category, taskOptions)
Olympus.debug("Olympus.move " .. ID .. " (" .. lat .. ", " .. lng ..") " .. altitude .. "m " .. altitudeType .. " ".. speed .. "m/s " .. category .. " " .. Olympus.serializeTable(taskOptions), 2)
local unit = Olympus.getUnitByID(ID)
if unit then
if category == "Aircraft" then
local startPoint = mist.getLeadPos(unit:getGroup())
local endPoint = coord.LLtoLO(lat, lng, 0)
if altitudeType == "AGL" then
altitude = land.getHeight({x = endPoint.x, y = endPoint.z}) + altitude
end
local path = {}
if taskOptions and taskOptions['id'] == 'Land' then
path = {
[1] = mist.fixedWing.buildWP(startPoint, flyOverPoint, speed, altitude, 'BARO'),
[1] = mist.fixedWing.buildWP(startPoint, turningPoint, speed, altitude, 'BARO'),
[2] = mist.fixedWing.buildWP(endPoint, landing, speed, 0, 'AGL')
}
else
path = {
[1] = mist.fixedWing.buildWP(startPoint, flyOverPoint, speed, altitude, 'BARO'),
[1] = mist.fixedWing.buildWP(startPoint, turningPoint, speed, altitude, 'BARO'),
[2] = mist.fixedWing.buildWP(endPoint, turningPoint, speed, altitude, 'BARO')
}
end
@ -195,11 +199,17 @@ function Olympus.move(ID, lat, lng, altitude, speed, category, taskOptions)
{
group = unit:getGroup(),
point = coord.LLtoLO(lat, lng, 0),
form = "Off Road",
heading = 0,
speed = speed,
disableRoads = true
speed = speed
}
if taskOptions and taskOptions['id'] == 'FollowRoads' and taskOptions['value'] == true then
vars["disableRoads"] = false
else
vars["form"] = "Off Road"
vars["disableRoads"] = true
end
mist.groupToRandomPoint(vars)
Olympus.debug("Olympus.move executed succesfully on a ground unit", 2)
else
@ -279,12 +289,12 @@ end
-- payloadName: a string, one of the names defined in unitPayloads.lua. Must be compatible with the unitType
-- airbaseName: a string, if present the aircraft will spawn on the ground of the selected airbase
-- payload: a table, if present the unit will receive this specific payload. Overrides payloadName
function Olympus.spawnAircraft(coalition, unitType, lat, lng, spawnOptions)
function Olympus.spawnAircraft(coalition, unitType, lat, lng, alt, spawnOptions)
local payloadName = spawnOptions["payloadName"]
local airbaseName = spawnOptions["airbaseName"]
local payload = spawnOptions["payload"]
Olympus.debug("Olympus.spawnAircraft " .. coalition .. " " .. unitType .. " (" .. lat .. ", " .. lng ..")", 2)
Olympus.debug("Olympus.spawnAircraft " .. coalition .. " " .. unitType .. " (" .. lat .. ", " .. lng ..", " .. alt .. ")", 2)
local spawnLocation = mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0))
if payload == nil then
@ -304,7 +314,7 @@ function Olympus.spawnAircraft(coalition, unitType, lat, lng, spawnOptions)
["type"] = unitType,
["x"] = spawnLocation.x,
["y"] = spawnLocation.z,
["alt"] = 20000 * 0.3048,
["alt"] = alt,
["alt_type"] = "BARO",
["skill"] = "Excellent",
["payload"] =
@ -390,7 +400,7 @@ function Olympus.clone(ID, lat, lng, category)
local spawnOptions = {
payload = Olympus.payloadRegistry[unit:getName()]
}
Olympus.spawnAircraft(coalition, unit:getTypeName(), lat, lng, spawnOptions)
Olympus.spawnAircraft(coalition, unit:getTypeName(), lat, lng, unit:getPoint().y, spawnOptions)
elseif category == "GroundUnit" then
Olympus.spawnGroundUnit(coalition, unit:getTypeName(), lat, lng)
end
@ -398,11 +408,11 @@ function Olympus.clone(ID, lat, lng, category)
Olympus.debug("Olympus.clone completed successfully", 2)
end
function Olympus.delete(ID, lat, lng)
Olympus.debug("Olympus.delete " .. ID, 2)
function Olympus.delete(ID, explosion)
Olympus.debug("Olympus.delete " .. ID .. " " .. tostring(explosion), 2)
local unit = Olympus.getUnitByID(ID)
if unit then
if unit:getPlayerName() then
if unit:getPlayerName() or explosion then
trigger.action.explosion(unit:getPoint() , 250 ) --consider replacing with forcibly deslotting the player, however this will work for now
Olympus.debug("Olympus.delete completed successfully", 2)
else
@ -452,6 +462,15 @@ function Olympus.setOption(ID, optionID, optionValue)
end
end
function Olympus.setOnOff(ID, onOff)
Olympus.debug("Olympus.setOnOff " .. ID .. " " .. tostring(onOff), 2)
local unit = Olympus.getUnitByID(ID)
if unit then
unit:getGroup():getController():setOnOff(onOff)
Olympus.debug("Olympus.setOnOff completed successfully", 2)
end
end
function Olympus.serializeTable(val, name, skipnewlines, depth)
skipnewlines = skipnewlines or false
depth = depth or 0

View File

@ -10,12 +10,4 @@ public:
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change);
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
virtual void setTargetSpeed(double newTargetSpeed);
virtual void setTargetAltitude(double newTargetAltitude);
protected:
double targetSpeed = 300 / 1.94384;
double targetAltitude = 20000 * 0.3048;
};

View File

@ -15,8 +15,10 @@ public:
virtual wstring getCategory() = 0;
virtual void changeSpeed(wstring change) {};
virtual void changeAltitude(wstring change) {};
virtual void setTargetSpeed(double newTargetSpeed) {};
virtual void setTargetAltitude(double newTargetAltitude) {};
virtual void setTargetSpeed(double newTargetSpeed);
virtual void setTargetAltitude(double newTargetAltitude);
virtual void setTargetSpeedType(wstring newTargetSpeedType);
virtual void setTargetAltitudeType(wstring newTargetAltitudeType);
protected:
virtual void AIloop();

View File

@ -81,8 +81,6 @@ namespace ECMUse {
};
}
/* Base command class */
class Command
{
@ -99,11 +97,13 @@ protected:
class Move : public Command
{
public:
Move(int ID, Coords destination, double speed, double altitude, wstring taskOptions):
Move(int ID, Coords destination, double speed, wstring speedType, double altitude, wstring altitudeType, wstring taskOptions):
ID(ID),
destination(destination),
speed(speed),
speedType(speedType),
altitude(altitude),
altitudeType(altitudeType),
taskOptions(taskOptions)
{
priority = CommandPriority::HIGH;
@ -115,7 +115,9 @@ private:
const int ID;
const Coords destination;
const double speed;
const wstring speedType;
const double altitude;
const wstring altitudeType;
const wstring taskOptions;
};
@ -203,8 +205,9 @@ private:
class Delete : public Command
{
public:
Delete(int ID) :
ID(ID)
Delete(int ID, bool explosion) :
ID(ID),
explosion(explosion)
{
priority = CommandPriority::HIGH;
};
@ -213,6 +216,7 @@ public:
private:
const int ID;
const bool explosion;
};
/* Follow command */
@ -299,4 +303,22 @@ private:
const int optionValue;
const bool optionBool;
const bool isBoolean;
};
};
/* Set on ooff */
class SetOnOff : public Command
{
public:
SetOnOff(int ID, bool onOff) :
ID(ID),
onOff(onOff)
{
priority = CommandPriority::HIGH;
};
virtual wstring getString(lua_State* L);
virtual int getLoad() { return 10; }
private:
const int ID;
const bool onOff;
};

View File

@ -12,8 +12,7 @@ public:
virtual wstring getCategory() { return L"GroundUnit"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
virtual void setOnOff(bool newOnOff);
virtual void setFollowRoads(bool newFollowRoads);
protected:
double targetSpeed = 10;
};

View File

@ -10,12 +10,4 @@ public:
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change);
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
virtual void setTargetSpeed(double newTargetSpeed);
virtual void setTargetAltitude(double newTargetAltitude);
protected:
double targetSpeed = 100 / 1.94384;
double targetAltitude = 5000 * 0.3048;
};

View File

@ -10,8 +10,5 @@ public:
virtual wstring getCategory() { return L"NavyUnit"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
protected:
double targetSpeed = 10;
};

View File

@ -112,9 +112,11 @@ public:
Offset getFormationoffset() { return formationOffset; }
/********** Task data **********/
void setCurrentTask(wstring newCurrentTask) { currentTask = newCurrentTask;addMeasure(L"currentTask", json::value(newCurrentTask)); }
void setCurrentTask(wstring newCurrentTask) { currentTask = newCurrentTask; addMeasure(L"currentTask", json::value(newCurrentTask)); }
virtual void setTargetSpeed(double newTargetSpeed) { targetSpeed = newTargetSpeed; addMeasure(L"targetSpeed", json::value(newTargetSpeed));}
virtual void setTargetAltitude(double newTargetAltitude) { targetAltitude = newTargetAltitude; addMeasure(L"targetAltitude", json::value(newTargetAltitude));} //TODO fix, double definition
virtual void setTargetAltitude(double newTargetAltitude) { targetAltitude = newTargetAltitude; addMeasure(L"targetAltitude", json::value(newTargetAltitude));}
virtual void setTargetSpeedType(wstring newTargetSpeedType) { targetSpeedType = newTargetSpeedType; addMeasure(L"targetSpeedType", json::value(newTargetSpeedType)); }
virtual void setTargetAltitudeType(wstring newTargetAltitudeType) { targetAltitudeType = newTargetAltitudeType; addMeasure(L"targetAltitudeType", json::value(newTargetAltitudeType)); }
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; addMeasure(L"activeDestination", json::value("")); } // TODO fix
void setActivePath(list<Coords> newActivePath);
void clearActivePath();
@ -124,15 +126,21 @@ public:
void setTargetID(int newTargetID) { targetID = newTargetID; addMeasure(L"targetID", json::value(newTargetID));}
void setIsTanker(bool newIsTanker);
void setIsAWACS(bool newIsAWACS);
virtual void setOnOff(bool newOnOff) { onOff = newOnOff; addMeasure(L"onOff", json::value(newOnOff));};
virtual void setFollowRoads(bool newFollowRoads) { followRoads = newFollowRoads; addMeasure(L"followRoads", json::value(newFollowRoads)); };
wstring getCurrentTask() { return currentTask; }
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
virtual wstring getTargetSpeedType() { return targetSpeedType; };
virtual wstring getTargetAltitudeType() { return targetAltitudeType; };
Coords getActiveDestination() { return activeDestination; }
list<Coords> getActivePath() { return activePath; }
int getTargetID() { return targetID; }
bool getIsTanker() { return isTanker; }
bool getIsAWACS() { return isAWACS; }
bool getOnOff() { return onOff; };
bool getFollowRoads() { return followRoads; };
/********** Options data **********/
void setROE(wstring newROE);
@ -196,11 +204,15 @@ protected:
wstring currentTask = L"";
double targetSpeed = 0;
double targetAltitude = 0;
wstring targetSpeedType = L"GS";
wstring targetAltitudeType = L"AGL";
list<Coords> activePath;
Coords activeDestination = Coords(0);
int targetID = NULL;
bool isTanker = false;
bool isAWACS = false;
bool onOff = true;
bool followRoads = false;
/********** Options data **********/
wstring ROE = L"Designated";

View File

@ -14,7 +14,7 @@ public:
void updateExportData(lua_State* L);
void updateMissionData(json::value missionData);
void getData(json::value& answer, long long time);
void deleteUnit(int ID);
void deleteUnit(int ID, bool explosion);
private:
map<int, Unit*> units;

View File

@ -17,6 +17,9 @@ Aircraft::Aircraft(json::value json, int ID) : AirUnit(json, ID)
{
log("New Aircraft created with ID: " + to_string(ID));
addMeasure(L"category", json::value(getCategory()));
double targetSpeed = 300 / 1.94384;
double targetAltitude = 20000 * 0.3048;
setTargetSpeed(targetSpeed);
setTargetAltitude(targetAltitude);
};
@ -58,18 +61,4 @@ void Aircraft::changeAltitude(wstring change)
setTargetAltitude(0);
goToDestination(); /* Send the command to reach the destination */
}
void Aircraft::setTargetSpeed(double newTargetSpeed) {
targetSpeed = newTargetSpeed;
addMeasure(L"targetSpeed", json::value(targetSpeed));
if (activeDestination != NULL)
goToDestination();
}
void Aircraft::setTargetAltitude(double newTargetAltitude) {
targetAltitude = newTargetAltitude;
addMeasure(L"targetAltitude", json::value(targetAltitude));
if (activeDestination != NULL)
goToDestination();
}

View File

@ -155,12 +155,10 @@ void AirUnit::goToDestination(wstring enrouteTask)
{
if (activeDestination != NULL)
{
Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetAltitude(), enrouteTask));
Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetSpeedType(), getTargetAltitude(), getTargetAltitudeType(), enrouteTask));
scheduler->appendCommand(command);
setHasTask(true);
}
else
log(unitName + L" error, no active destination!");
}
void AirUnit::AIloop()
@ -318,3 +316,23 @@ void AirUnit::AIloop()
addMeasure(L"currentTask", json::value(currentTask));
}
void AirUnit::setTargetSpeed(double newTargetSpeed) {
Unit::setTargetSpeed(newTargetSpeed);
goToDestination();
}
void AirUnit::setTargetAltitude(double newTargetAltitude) {
Unit::setTargetAltitude(newTargetAltitude);
goToDestination();
}
void AirUnit::setTargetSpeedType(wstring newTargetSpeedType) {
Unit::setTargetSpeedType(newTargetSpeedType);
goToDestination();
}
void AirUnit::setTargetAltitudeType(wstring newTargetAltitudeType) {
Unit::setTargetAltitudeType(newTargetAltitudeType);
goToDestination();
}

View File

@ -19,7 +19,9 @@ wstring Move::getString(lua_State* L)
<< destination.lat << ", "
<< destination.lng << ", "
<< altitude << ", "
<< "\"" << altitudeType << "\"" << ", "
<< speed << ", "
<< "\"" << speedType << "\"" << ", "
<< "\"" << unit->getCategory() << "\"" << ", "
<< taskOptions;
return commandSS.str();
@ -72,6 +74,7 @@ wstring SpawnAircraft::getString(lua_State* L)
<< "\"" << unitType << "\"" << ", "
<< location.lat << ", "
<< location.lng << ", "
<< location.alt << ", "
<< optionsSS.str();
return commandSS.str();
}
@ -103,7 +106,8 @@ wstring Delete::getString(lua_State* L)
std::wostringstream commandSS;
commandSS.precision(10);
commandSS << "Olympus.delete, "
<< ID;
<< ID << ", "
<< (explosion ? "true" : "false");
return commandSS.str();
}
@ -160,4 +164,17 @@ wstring SetOption::getString(lua_State* L)
<< (optionBool? "true": "false");
}
return commandSS.str();
}
/* Set onOff command */
wstring SetOnOff::getString(lua_State* L)
{
std::wostringstream commandSS;
commandSS.precision(10);
commandSS << "Olympus.setOnOff, "
<< ID << ", "
<< (onOff ? "true" : "false");
return commandSS.str();
}

View File

@ -17,8 +17,9 @@ GroundUnit::GroundUnit(json::value json, int ID) : Unit(json, ID)
{
log("New Ground Unit created with ID: " + to_string(ID));
addMeasure(L"category", json::value(getCategory()));
double targetSpeed = 10;
setTargetSpeed(targetSpeed);
setTargetAltitude(targetAltitude);
};
void GroundUnit::AIloop()
@ -29,7 +30,11 @@ void GroundUnit::AIloop()
if (activeDestination != activePath.front())
{
activeDestination = activePath.front();
Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetAltitude(), L"nil"));
std::wostringstream taskSS;
taskSS << "{ id = 'FollowRoads', value = " << (getFollowRoads()? "true" : "false") << " }";
Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetSpeedType(), getTargetAltitude(), getTargetAltitudeType(), taskSS.str()));
scheduler->appendCommand(command);
}
}
@ -71,4 +76,17 @@ void GroundUnit::changeSpeed(wstring change)
{
}
}
void GroundUnit::setOnOff(bool newOnOff)
{
Unit::setOnOff(newOnOff);
Command* command = dynamic_cast<Command*>(new SetOnOff(ID, onOff));
scheduler->appendCommand(command);
}
void GroundUnit::setFollowRoads(bool newFollowRoads)
{
Unit::setFollowRoads(newFollowRoads);
resetActiveDestination(); /* Reset active destination to apply option*/
}

View File

@ -17,6 +17,9 @@ Helicopter::Helicopter(json::value json, int ID) : AirUnit(json, ID)
{
log("New Helicopter created with ID: " + to_string(ID));
addMeasure(L"category", json::value(getCategory()));
double targetSpeed = 100 / 1.94384;
double targetAltitude = 5000 * 0.3048;
setTargetSpeed(targetSpeed);
setTargetAltitude(targetAltitude);
};
@ -59,16 +62,3 @@ void Helicopter::changeAltitude(wstring change)
goToDestination(); /* Send the command to reach the destination */
}
void Helicopter::setTargetSpeed(double newTargetSpeed) {
targetSpeed = newTargetSpeed;
addMeasure(L"targetSpeed", json::value(targetSpeed));
goToDestination();
}
void Helicopter::setTargetAltitude(double newTargetAltitude) {
targetAltitude = newTargetAltitude;
addMeasure(L"targetAltitude", json::value(targetAltitude));
goToDestination();
}

View File

@ -17,8 +17,9 @@ NavyUnit::NavyUnit(json::value json, int ID) : Unit(json, ID)
{
log("New Navy Unit created with ID: " + to_string(ID));
addMeasure(L"category", json::value(getCategory()));
double targetSpeed = 10;
setTargetSpeed(targetSpeed);
setTargetAltitude(targetAltitude);
};
void NavyUnit::AIloop()

View File

@ -111,7 +111,8 @@ void Scheduler::handleRequest(wstring key, json::value value)
wstring type = value[L"type"].as_string();
double lat = value[L"location"][L"lat"].as_double();
double lng = value[L"location"][L"lng"].as_double();
Coords loc; loc.lat = lat; loc.lng = lng;
double altitude = value[L"altitude"].as_double();
Coords loc; loc.lat = lat; loc.lng = lng; loc.alt = altitude;
wstring payloadName = value[L"payloadName"].as_string();
wstring airbaseName = value[L"airbaseName"].as_string();
log(L"Spawning " + coalition + L" air unit of type " + type + L" with payload " + payloadName + L" at (" + to_wstring(lat) + L", " + to_wstring(lng) + L" " + airbaseName + L")");
@ -192,6 +193,13 @@ void Scheduler::handleRequest(wstring key, json::value value)
if (unit != nullptr)
unit->setTargetSpeed(value[L"speed"].as_double());
}
else if (key.compare(L"setSpeedType") == 0)
{
int ID = value[L"ID"].as_integer();
Unit* unit = unitsManager->getUnit(ID);
if (unit != nullptr)
unit->setTargetSpeedType(value[L"speedType"].as_string());
}
else if (key.compare(L"setAltitude") == 0)
{
int ID = value[L"ID"].as_integer();
@ -199,6 +207,13 @@ void Scheduler::handleRequest(wstring key, json::value value)
if (unit != nullptr)
unit->setTargetAltitude(value[L"altitude"].as_double());
}
else if (key.compare(L"setAltitudeType") == 0)
{
int ID = value[L"ID"].as_integer();
Unit* unit = unitsManager->getUnit(ID);
if (unit != nullptr)
unit->setTargetAltitudeType(value[L"altitudeType"].as_string());
}
else if (key.compare(L"cloneUnit") == 0)
{
int ID = value[L"ID"].as_integer();
@ -241,7 +256,8 @@ void Scheduler::handleRequest(wstring key, json::value value)
else if (key.compare(L"deleteUnit") == 0)
{
int ID = value[L"ID"].as_integer();
unitsManager->deleteUnit(ID);
bool explosion = value[L"explosion"].as_bool();
unitsManager->deleteUnit(ID, explosion);
}
else if (key.compare(L"refuel") == 0)
{
@ -286,6 +302,20 @@ void Scheduler::handleRequest(wstring key, json::value value)
unit->resetActiveDestination();
}
}
else if (key.compare(L"setFollowRoads") == 0)
{
int ID = value[L"ID"].as_integer();
bool followRoads = value[L"followRoads"].as_bool();
Unit* unit = unitsManager->getUnit(ID);
unit->setFollowRoads(followRoads);
}
else if (key.compare(L"setOnOff") == 0)
{
int ID = value[L"ID"].as_integer();
bool onOff = value[L"onOff"].as_bool();
Unit* unit = unitsManager->getUnit(ID);
unit->setOnOff(onOff);
}
else
{
log(L"Unknown command: " + key);

View File

@ -179,7 +179,7 @@ json::value Unit::getData(long long time)
/********** Task data **********/
json[L"taskData"] = json::value::object();
for (auto key : { L"currentState", L"currentTask", L"targetSpeed", L"targetAltitude", L"activePath", L"isTanker", L"isAWACS" })
for (auto key : { L"currentState", L"currentTask", L"targetSpeed", L"targetAltitude", L"targetSpeedType", L"targetAltitudeType", L"activePath", L"isTanker", L"isAWACS", L"onOff", L"followRoads"})
{
if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"taskData"][key] = measures[key]->getValue();

View File

@ -107,11 +107,11 @@ void UnitsManager::getData(json::value& answer, long long time)
answer[L"units"] = unitsJson;
}
void UnitsManager::deleteUnit(int ID)
void UnitsManager::deleteUnit(int ID, bool explosion)
{
if (getUnit(ID) != nullptr)
{
Command* command = dynamic_cast<Command*>(new Delete(ID));
Command* command = dynamic_cast<Command*>(new Delete(ID, explosion));
scheduler->appendCommand(command);
}
}