mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Converted clone function to pure lua
This commit is contained in:
@@ -248,9 +248,8 @@ private:
|
||||
class Clone : public Command
|
||||
{
|
||||
public:
|
||||
Clone(unsigned int ID, Coords location) :
|
||||
ID(ID),
|
||||
location(location)
|
||||
Clone(vector<CloneOptions> cloneOptions) :
|
||||
cloneOptions(cloneOptions)
|
||||
{
|
||||
priority = CommandPriority::LOW;
|
||||
};
|
||||
@@ -258,8 +257,7 @@ public:
|
||||
virtual unsigned int getLoad() { return 30; }
|
||||
|
||||
private:
|
||||
const unsigned int ID;
|
||||
const Coords location;
|
||||
const vector<CloneOptions> cloneOptions;
|
||||
};
|
||||
|
||||
/* Delete unit command */
|
||||
|
||||
@@ -120,4 +120,9 @@ struct SpawnOptions {
|
||||
Coords location;
|
||||
string loadout;
|
||||
string liveryID;
|
||||
};
|
||||
|
||||
struct CloneOptions {
|
||||
unsigned int ID;
|
||||
Coords location;
|
||||
};
|
||||
@@ -140,22 +140,21 @@ string SpawnHelicopters::getString()
|
||||
/* Clone unit command */
|
||||
string Clone::getString()
|
||||
{
|
||||
Unit* unit = unitsManager->getUnit(ID);
|
||||
if (unit != nullptr)
|
||||
{
|
||||
std::ostringstream commandSS;
|
||||
commandSS.precision(10);
|
||||
commandSS << "Olympus.clone, "
|
||||
<< ID << ", "
|
||||
<< location.lat << ", "
|
||||
<< location.lng << ", "
|
||||
<< "\"" << unit->getCategory() << "\"";
|
||||
return commandSS.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
std::ostringstream unitsSS;
|
||||
unitsSS.precision(10);
|
||||
for (int i = 0; i < cloneOptions.size(); i++) {
|
||||
unitsSS << "[" << i + 1 << "] = {"
|
||||
<< "ID = " << cloneOptions[i].ID << ", "
|
||||
<< "lat = " << cloneOptions[i].location.lat << ", "
|
||||
<< "lng = " << cloneOptions[i].location.lng << " }, ";
|
||||
}
|
||||
|
||||
std::ostringstream commandSS;
|
||||
commandSS.precision(10);
|
||||
commandSS << "Olympus.clone, "
|
||||
<< "{" << unitsSS.str() << "}";
|
||||
return commandSS.str();
|
||||
|
||||
}
|
||||
|
||||
/* Delete unit command */
|
||||
|
||||
@@ -376,13 +376,20 @@ void Scheduler::handleRequest(string key, json::value value, string username)
|
||||
if (unit != nullptr)
|
||||
unit->setDesiredAltitudeType(to_string(value[L"altitudeType"]));
|
||||
}
|
||||
else if (key.compare("cloneUnit") == 0)
|
||||
else if (key.compare("cloneUnits") == 0)
|
||||
{
|
||||
unsigned 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;
|
||||
command = dynamic_cast<Command*>(new Clone(ID, loc));
|
||||
vector<CloneOptions> cloneOptions;
|
||||
|
||||
for (auto unit : value[L"units"].as_array()) {
|
||||
unsigned int ID = unit[L"ID"].as_integer();
|
||||
double lat = unit[L"location"][L"lat"].as_double();
|
||||
double lng = unit[L"location"][L"lng"].as_double();
|
||||
|
||||
Coords location; location.lat = lat; location.lng = lng;
|
||||
cloneOptions.push_back({ ID, location });
|
||||
}
|
||||
|
||||
command = dynamic_cast<Command*>(new Clone(cloneOptions));
|
||||
}
|
||||
else if (key.compare("setROE") == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user