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:
@@ -305,7 +305,7 @@ private:
|
||||
const bool isBoolean;
|
||||
};
|
||||
|
||||
/* Set on ooff */
|
||||
/* Set on off */
|
||||
class SetOnOff : public Command
|
||||
{
|
||||
public:
|
||||
@@ -322,3 +322,21 @@ private:
|
||||
const int ID;
|
||||
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,
|
||||
REFUEL,
|
||||
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 setActivePath(list<Coords> newActivePath);
|
||||
void setTargetID(int newTargetID) { targetID = newTargetID; addMeasure(L"targetID", json::value(newTargetID));}
|
||||
void setTargetLocation(Coords newTargetLocation);
|
||||
void setIsTanker(bool newIsTanker);
|
||||
void setIsAWACS(bool newIsAWACS);
|
||||
virtual void setOnOff(bool newOnOff) { onOff = newOnOff; addMeasure(L"onOff", json::value(newOnOff));};
|
||||
@@ -137,6 +142,7 @@ public:
|
||||
Coords getActiveDestination() { return activeDestination; }
|
||||
list<Coords> getActivePath() { return activePath; }
|
||||
int getTargetID() { return targetID; }
|
||||
Coords getTargetLocation() { return targetLocation; }
|
||||
bool getIsTanker() { return isTanker; }
|
||||
bool getIsAWACS() { return isAWACS; }
|
||||
bool getOnOff() { return onOff; };
|
||||
@@ -212,8 +218,9 @@ protected:
|
||||
wstring targetSpeedType = L"GS";
|
||||
wstring targetAltitudeType = L"AGL";
|
||||
list<Coords> activePath;
|
||||
Coords activeDestination = Coords(0);
|
||||
Coords activeDestination = Coords(NULL);
|
||||
int targetID = NULL;
|
||||
Coords targetLocation = Coords(NULL);
|
||||
bool isTanker = false;
|
||||
bool isAWACS = false;
|
||||
bool onOff = true;
|
||||
|
||||
@@ -43,6 +43,12 @@ void AirUnit::setState(int newState)
|
||||
case State::REFUEL: {
|
||||
break;
|
||||
}
|
||||
case State::BOMB_POINT:
|
||||
case State::CARPET_BOMB:
|
||||
case State::BOMB_BUILDING: {
|
||||
setTargetLocation(Coords(NULL));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -90,6 +96,24 @@ void AirUnit::setState(int newState)
|
||||
addMeasure(L"currentState", json::value(L"Refuel"));
|
||||
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:
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
addMeasure(L"currentTask", json::value(currentTask));
|
||||
}
|
||||
}
|
||||
@@ -177,4 +177,16 @@ wstring SetOnOff::getString(lua_State* L)
|
||||
<< (onOff ? "true" : "false");
|
||||
|
||||
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: {
|
||||
break;
|
||||
}
|
||||
case State::FIRE_AT_AREA: {
|
||||
setTargetLocation(Coords(NULL));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -51,6 +55,12 @@ void GroundUnit::setState(int newState)
|
||||
addMeasure(L"currentState", json::value(L"Reach destination"));
|
||||
break;
|
||||
}
|
||||
case State::FIRE_AT_AREA: {
|
||||
addMeasure(L"currentState", json::value(L"Firing at area"));
|
||||
clearActivePath();
|
||||
resetActiveDestination();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -96,6 +106,17 @@ void GroundUnit::AIloop()
|
||||
}
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -316,6 +316,51 @@ void Scheduler::handleRequest(wstring key, json::value value)
|
||||
Unit* unit = unitsManager->getUnit(ID);
|
||||
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
|
||||
{
|
||||
log(L"Unknown command: " + key);
|
||||
|
||||
@@ -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"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)
|
||||
json[L"taskData"][key] = measures[key]->getValue();
|
||||
@@ -660,4 +660,12 @@ bool Unit::updateActivePath(bool looping)
|
||||
else {
|
||||
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