mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added backend for advanced commands
This commit is contained in:
@@ -97,7 +97,7 @@ export class MouseInfoPanel extends Panel {
|
|||||||
|
|
||||||
let bng = zeroAppend(Math.floor(bear), 3);
|
let bng = zeroAppend(Math.floor(bear), 3);
|
||||||
|
|
||||||
if (bng === "000")
|
if (bng === "000")
|
||||||
bng = "360";
|
bng = "360";
|
||||||
|
|
||||||
var [str, unit] = this.#computeDistanceString(dist)
|
var [str, unit] = this.#computeDistanceString(dist)
|
||||||
@@ -112,7 +112,7 @@ export class MouseInfoPanel extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#onMouseMove(e: any) {
|
#onMouseMove(e: any) {
|
||||||
|
|
||||||
this.#update();
|
this.#update();
|
||||||
this.#drawMeasureLine();
|
this.#drawMeasureLine();
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ export class MouseInfoPanel extends Panel {
|
|||||||
|
|
||||||
#computeDistanceString(dist: number) {
|
#computeDistanceString(dist: number) {
|
||||||
var val = mToNm(dist);
|
var val = mToNm(dist);
|
||||||
var strVal = 0;
|
var strVal = 0;
|
||||||
var decimal = false;
|
var decimal = false;
|
||||||
var unit = "NM";
|
var unit = "NM";
|
||||||
if (val > 10)
|
if (val > 10)
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ export function fireAtArea(ID: number, latlng: LatLng) {
|
|||||||
var data = { "fireAtArea": command }
|
var data = { "fireAtArea": command }
|
||||||
POST(data, () => { });
|
POST(data, () => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACAN: TACAN, radio: Radio, generalSettings: GeneralSettings) {
|
export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACAN: TACAN, radio: Radio, generalSettings: GeneralSettings) {
|
||||||
var command = {
|
var command = {
|
||||||
"ID": ID,
|
"ID": ID,
|
||||||
|
|||||||
@@ -139,8 +139,41 @@ function Olympus.buildTask(options)
|
|||||||
pattern = options['pattern'] or "Circle"
|
pattern = options['pattern'] or "Circle"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif options['id'] == 'Bombing' and options['lat'] and options['lng'] then
|
||||||
|
task = {
|
||||||
|
id = 'Bombing',
|
||||||
|
params = {
|
||||||
|
point = coord.LLtoLO(options['lat'], options['lng'], 0),
|
||||||
|
attackQty = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif options['id'] == 'CarpetBombing' and options['lat'] and options['lng'] then
|
||||||
|
task = {
|
||||||
|
id = 'CarpetBombing',
|
||||||
|
params = {
|
||||||
|
point = coord.LLtoLO(options['lat'], options['lng'], 0),
|
||||||
|
attackQty = 1,
|
||||||
|
carpetLength = 1000,
|
||||||
|
attackType = 'Carpet'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif options['id'] == 'AttackMapObject' and options['lat'] and options['lng'] then
|
||||||
|
task = {
|
||||||
|
id = 'AttackMapObject',
|
||||||
|
params = {
|
||||||
|
point = coord.LLtoLO(options['lat'], options['lng'], 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elseif options['id'] == 'FireAtPoint' and options['lat'] and options['lng'] and options['radius'] then
|
||||||
|
task = {
|
||||||
|
id = 'AttackMapObject',
|
||||||
|
params = {
|
||||||
|
point = coord.LLtoLO(options['lat'], options['lng'], 0),
|
||||||
|
radius = options['radius']
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return task
|
return task
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -238,6 +271,12 @@ function Olympus.smoke(color, lat, lng)
|
|||||||
trigger.action.smoke(mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0)), colorEnum)
|
trigger.action.smoke(mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0)), colorEnum)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Creates an explosion on the ground
|
||||||
|
function Olympus.explosion(intensity, lat, lng)
|
||||||
|
Olympus.debug("Olympus.explosion " .. intensity .. " (" .. lat .. ", " .. lng ..")", 2)
|
||||||
|
trigger.action.explosion(mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0)), intensity)
|
||||||
|
end
|
||||||
|
|
||||||
-- Spawns a single ground unit
|
-- Spawns a single ground unit
|
||||||
function Olympus.spawnGroundUnit(coalition, unitType, lat, lng)
|
function Olympus.spawnGroundUnit(coalition, unitType, lat, lng)
|
||||||
Olympus.debug("Olympus.spawnGroundUnit " .. coalition .. " " .. unitType .. " (" .. lat .. ", " .. lng ..")", 2)
|
Olympus.debug("Olympus.spawnGroundUnit " .. coalition .. " " .. unitType .. " (" .. lat .. ", " .. lng ..")", 2)
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ private:
|
|||||||
const bool isBoolean;
|
const bool isBoolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Set on ooff */
|
/* Set on off */
|
||||||
class SetOnOff : public Command
|
class SetOnOff : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -322,3 +322,21 @@ private:
|
|||||||
const int ID;
|
const int ID;
|
||||||
const bool onOff;
|
const bool onOff;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Make a ground explosion */
|
||||||
|
class Explosion : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Explosion(int intensity, Coords location) :
|
||||||
|
location(location),
|
||||||
|
intensity(intensity)
|
||||||
|
{
|
||||||
|
priority = CommandPriority::MEDIUM;
|
||||||
|
};
|
||||||
|
virtual wstring getString(lua_State* L);
|
||||||
|
virtual int getLoad() { return 10; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Coords location;
|
||||||
|
const int intensity;
|
||||||
|
};
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ namespace State
|
|||||||
LAND,
|
LAND,
|
||||||
REFUEL,
|
REFUEL,
|
||||||
AWACS,
|
AWACS,
|
||||||
TANKER
|
TANKER,
|
||||||
|
BOMB_POINT,
|
||||||
|
CARPET_BOMB,
|
||||||
|
BOMB_BUILDING,
|
||||||
|
FIRE_AT_AREA
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,6 +128,7 @@ public:
|
|||||||
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; addMeasure(L"activeDestination", json::value("")); } // TODO fix
|
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; addMeasure(L"activeDestination", json::value("")); } // TODO fix
|
||||||
void setActivePath(list<Coords> newActivePath);
|
void setActivePath(list<Coords> newActivePath);
|
||||||
void setTargetID(int newTargetID) { targetID = newTargetID; addMeasure(L"targetID", json::value(newTargetID));}
|
void setTargetID(int newTargetID) { targetID = newTargetID; addMeasure(L"targetID", json::value(newTargetID));}
|
||||||
|
void setTargetLocation(Coords newTargetLocation);
|
||||||
void setIsTanker(bool newIsTanker);
|
void setIsTanker(bool newIsTanker);
|
||||||
void setIsAWACS(bool newIsAWACS);
|
void setIsAWACS(bool newIsAWACS);
|
||||||
virtual void setOnOff(bool newOnOff) { onOff = newOnOff; addMeasure(L"onOff", json::value(newOnOff));};
|
virtual void setOnOff(bool newOnOff) { onOff = newOnOff; addMeasure(L"onOff", json::value(newOnOff));};
|
||||||
@@ -137,6 +142,7 @@ public:
|
|||||||
Coords getActiveDestination() { return activeDestination; }
|
Coords getActiveDestination() { return activeDestination; }
|
||||||
list<Coords> getActivePath() { return activePath; }
|
list<Coords> getActivePath() { return activePath; }
|
||||||
int getTargetID() { return targetID; }
|
int getTargetID() { return targetID; }
|
||||||
|
Coords getTargetLocation() { return targetLocation; }
|
||||||
bool getIsTanker() { return isTanker; }
|
bool getIsTanker() { return isTanker; }
|
||||||
bool getIsAWACS() { return isAWACS; }
|
bool getIsAWACS() { return isAWACS; }
|
||||||
bool getOnOff() { return onOff; };
|
bool getOnOff() { return onOff; };
|
||||||
@@ -212,8 +218,9 @@ protected:
|
|||||||
wstring targetSpeedType = L"GS";
|
wstring targetSpeedType = L"GS";
|
||||||
wstring targetAltitudeType = L"AGL";
|
wstring targetAltitudeType = L"AGL";
|
||||||
list<Coords> activePath;
|
list<Coords> activePath;
|
||||||
Coords activeDestination = Coords(0);
|
Coords activeDestination = Coords(NULL);
|
||||||
int targetID = NULL;
|
int targetID = NULL;
|
||||||
|
Coords targetLocation = Coords(NULL);
|
||||||
bool isTanker = false;
|
bool isTanker = false;
|
||||||
bool isAWACS = false;
|
bool isAWACS = false;
|
||||||
bool onOff = true;
|
bool onOff = true;
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ void AirUnit::setState(int newState)
|
|||||||
case State::REFUEL: {
|
case State::REFUEL: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case State::BOMB_POINT:
|
||||||
|
case State::CARPET_BOMB:
|
||||||
|
case State::BOMB_BUILDING: {
|
||||||
|
setTargetLocation(Coords(NULL));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -90,6 +96,24 @@ void AirUnit::setState(int newState)
|
|||||||
addMeasure(L"currentState", json::value(L"Refuel"));
|
addMeasure(L"currentState", json::value(L"Refuel"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case State::BOMB_POINT: {
|
||||||
|
addMeasure(L"currentState", json::value(L"Bombing point"));
|
||||||
|
clearActivePath();
|
||||||
|
resetActiveDestination();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State::CARPET_BOMB: {
|
||||||
|
addMeasure(L"currentState", json::value(L"Carpet bombing"));
|
||||||
|
clearActivePath();
|
||||||
|
resetActiveDestination();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State::BOMB_BUILDING: {
|
||||||
|
addMeasure(L"currentState", json::value(L"Bombing building"));
|
||||||
|
clearActivePath();
|
||||||
|
resetActiveDestination();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -249,9 +273,42 @@ void AirUnit::AIloop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case State::BOMB_POINT: {
|
||||||
|
currentTask = L"Bombing point";
|
||||||
|
|
||||||
|
if (!getHasTask()) {
|
||||||
|
std::wostringstream taskSS;
|
||||||
|
taskSS << "{id = 'Bombing', lat = " << targetLocation.lat << ", lng = " << targetLocation.lng << "}";
|
||||||
|
Command* command = dynamic_cast<Command*>(new SetTask(ID, taskSS.str()));
|
||||||
|
scheduler->appendCommand(command);
|
||||||
|
setHasTask(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case State::CARPET_BOMB: {
|
||||||
|
currentTask = L"Carpet bombing";
|
||||||
|
|
||||||
|
if (!getHasTask()) {
|
||||||
|
std::wostringstream taskSS;
|
||||||
|
taskSS << "{id = 'CarpetBombing', lat = " << targetLocation.lat << ", lng = " << targetLocation.lng << "}";
|
||||||
|
Command* command = dynamic_cast<Command*>(new SetTask(ID, taskSS.str()));
|
||||||
|
scheduler->appendCommand(command);
|
||||||
|
setHasTask(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case State::BOMB_BUILDING: {
|
||||||
|
currentTask = L"Bombing building";
|
||||||
|
|
||||||
|
if (!getHasTask()) {
|
||||||
|
std::wostringstream taskSS;
|
||||||
|
taskSS << "{id = 'AttackMapObject', lat = " << targetLocation.lat << ", lng = " << targetLocation.lng << "}";
|
||||||
|
Command* command = dynamic_cast<Command*>(new SetTask(ID, taskSS.str()));
|
||||||
|
scheduler->appendCommand(command);
|
||||||
|
setHasTask(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addMeasure(L"currentTask", json::value(currentTask));
|
addMeasure(L"currentTask", json::value(currentTask));
|
||||||
}
|
}
|
||||||
@@ -177,4 +177,16 @@ wstring SetOnOff::getString(lua_State* L)
|
|||||||
<< (onOff ? "true" : "false");
|
<< (onOff ? "true" : "false");
|
||||||
|
|
||||||
return commandSS.str();
|
return commandSS.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Explosion command */
|
||||||
|
wstring Explosion::getString(lua_State* L)
|
||||||
|
{
|
||||||
|
std::wostringstream commandSS;
|
||||||
|
commandSS.precision(10);
|
||||||
|
commandSS << "Olympus.explosion, "
|
||||||
|
<< intensity << ", "
|
||||||
|
<< location.lat << ", "
|
||||||
|
<< location.lng;
|
||||||
|
return commandSS.str();
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,10 @@ void GroundUnit::setState(int newState)
|
|||||||
case State::REACH_DESTINATION: {
|
case State::REACH_DESTINATION: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case State::FIRE_AT_AREA: {
|
||||||
|
setTargetLocation(Coords(NULL));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -51,6 +55,12 @@ void GroundUnit::setState(int newState)
|
|||||||
addMeasure(L"currentState", json::value(L"Reach destination"));
|
addMeasure(L"currentState", json::value(L"Reach destination"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case State::FIRE_AT_AREA: {
|
||||||
|
addMeasure(L"currentState", json::value(L"Firing at area"));
|
||||||
|
clearActivePath();
|
||||||
|
resetActiveDestination();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -96,6 +106,17 @@ void GroundUnit::AIloop()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case State::FIRE_AT_AREA: {
|
||||||
|
currentTask = L"Firing at area";
|
||||||
|
|
||||||
|
if (!getHasTask()) {
|
||||||
|
std::wostringstream taskSS;
|
||||||
|
taskSS << "{id = 'FireAtPoint', lat = " << targetLocation.lat << ", lng = " << targetLocation.lng << ", radius = 1000}";
|
||||||
|
Command* command = dynamic_cast<Command*>(new SetTask(ID, taskSS.str()));
|
||||||
|
scheduler->appendCommand(command);
|
||||||
|
setHasTask(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,6 +316,51 @@ void Scheduler::handleRequest(wstring key, json::value value)
|
|||||||
Unit* unit = unitsManager->getUnit(ID);
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
unit->setOnOff(onOff);
|
unit->setOnOff(onOff);
|
||||||
}
|
}
|
||||||
|
else if (key.compare(L"explosion") == 0)
|
||||||
|
{
|
||||||
|
int intensity = value[L"intensity"].as_integer();
|
||||||
|
double lat = value[L"location"][L"lat"].as_double();
|
||||||
|
double lng = value[L"location"][L"lng"].as_double();
|
||||||
|
log(L"Adding " + to_wstring(intensity) + L" explosion at (" + to_wstring(lat) + L", " + to_wstring(lng) + L")");
|
||||||
|
Coords loc; loc.lat = lat; loc.lng = lng;
|
||||||
|
command = dynamic_cast<Command*>(new Explosion(intensity, loc));
|
||||||
|
}
|
||||||
|
else if (key.compare(L"bombPoint") == 0)
|
||||||
|
{
|
||||||
|
int ID = value[L"ID"].as_integer();
|
||||||
|
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;
|
||||||
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
|
unit->setState(State::BOMB_POINT);
|
||||||
|
}
|
||||||
|
else if (key.compare(L"carpetBomb") == 0)
|
||||||
|
{
|
||||||
|
int ID = value[L"ID"].as_integer();
|
||||||
|
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;
|
||||||
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
|
unit->setState(State::CARPET_BOMB);
|
||||||
|
}
|
||||||
|
else if (key.compare(L"bombBuilding") == 0)
|
||||||
|
{
|
||||||
|
int ID = value[L"ID"].as_integer();
|
||||||
|
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;
|
||||||
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
|
unit->setState(State::BOMB_BUILDING);
|
||||||
|
}
|
||||||
|
else if (key.compare(L"fireAtArea") == 0)
|
||||||
|
{
|
||||||
|
int ID = value[L"ID"].as_integer();
|
||||||
|
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;
|
||||||
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
|
unit->setState(State::FIRE_AT_AREA);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log(L"Unknown command: " + key);
|
log(L"Unknown command: " + key);
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ json::value Unit::getData(long long time)
|
|||||||
|
|
||||||
/********** Task data **********/
|
/********** Task data **********/
|
||||||
json[L"taskData"] = json::value::object();
|
json[L"taskData"] = json::value::object();
|
||||||
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"})
|
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", L"targetID", L"targetLocation"})
|
||||||
{
|
{
|
||||||
if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
|
if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
|
||||||
json[L"taskData"][key] = measures[key]->getValue();
|
json[L"taskData"][key] = measures[key]->getValue();
|
||||||
@@ -660,4 +660,12 @@ bool Unit::updateActivePath(bool looping)
|
|||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unit::setTargetLocation(Coords newTargetLocation) {
|
||||||
|
targetLocation = newTargetLocation;
|
||||||
|
auto json = json::value();
|
||||||
|
json[L"latitude"] = json::value(newTargetLocation.lat);
|
||||||
|
json[L"longitude"] = json::value(newTargetLocation.lng);
|
||||||
|
addMeasure(L"targetLocation", json::value(json));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user