mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Minor tweaks and fixes
This commit is contained in:
@@ -176,11 +176,11 @@ private:
|
||||
class SpawnAircrafts : public Command
|
||||
{
|
||||
public:
|
||||
SpawnAircrafts(string coalition, vector<string> unitTypes, vector<Coords> locations, vector<string> payloadNames, string airbaseName, bool immediate) :
|
||||
SpawnAircrafts(string coalition, vector<string> unitTypes, vector<Coords> locations, vector<string> loadouts, string airbaseName, bool immediate) :
|
||||
coalition(coalition),
|
||||
unitTypes(unitTypes),
|
||||
locations(locations),
|
||||
payloadNames(payloadNames),
|
||||
loadouts(loadouts),
|
||||
airbaseName(airbaseName),
|
||||
immediate(immediate)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ private:
|
||||
const string coalition;
|
||||
const vector<string> unitTypes;
|
||||
const vector<Coords> locations;
|
||||
const vector<string> payloadNames;
|
||||
const vector<string> loadouts;
|
||||
const string airbaseName;
|
||||
const bool immediate;
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ string SpawnGroundUnits::getString(lua_State* L)
|
||||
unitsSS << "[" << i + 1 << "] = {"
|
||||
<< "unitType = " << "\"" << unitTypes[i] << "\"" << ", "
|
||||
<< "lat = " << locations[i].lat << ", "
|
||||
<< "lng = " << locations[i].lng << "}";
|
||||
<< "lng = " << locations[i].lng << "},";
|
||||
}
|
||||
|
||||
std::ostringstream commandSS;
|
||||
@@ -56,14 +56,14 @@ string SpawnGroundUnits::getString(lua_State* L)
|
||||
commandSS << "Olympus.spawnUnits, {"
|
||||
<< "category = " << "\"" << "GroundUnit" << "\"" << ", "
|
||||
<< "coalition = " << "\"" << coalition << "\"" << ", "
|
||||
<< "units = " << "\"" << unitsSS.str() << "\"" << "}";
|
||||
<< "units = " << "{" << unitsSS.str() << "}" << "}";
|
||||
return commandSS.str();
|
||||
}
|
||||
|
||||
/* Spawn aircrafts command */
|
||||
string SpawnAircrafts::getString(lua_State* L)
|
||||
{
|
||||
if (unitTypes.size() != locations.size() || unitTypes.size() != payloadNames.size()) return "";
|
||||
if (unitTypes.size() != locations.size() || unitTypes.size() != loadouts.size()) return "";
|
||||
|
||||
std::ostringstream unitsSS;
|
||||
unitsSS.precision(10);
|
||||
@@ -73,7 +73,7 @@ string SpawnAircrafts::getString(lua_State* L)
|
||||
<< "lat = " << locations[i].lat << ", "
|
||||
<< "lng = " << locations[i].lng << ", "
|
||||
<< "alt = " << locations[i].alt << ", "
|
||||
<< "payloadName = \"" << payloadNames[i] << "\", " << "}";
|
||||
<< "loadout = \"" << loadouts[i] << "\"" << "},";
|
||||
}
|
||||
|
||||
std::ostringstream commandSS;
|
||||
@@ -82,7 +82,7 @@ string SpawnAircrafts::getString(lua_State* L)
|
||||
<< "category = " << "\"" << "Aircraft" << "\"" << ", "
|
||||
<< "coalition = " << "\"" << coalition << "\"" << ", "
|
||||
<< "airbaseName = \"" << airbaseName << "\", "
|
||||
<< "units = " << "\"" << unitsSS.str() << "\"" << "}";
|
||||
<< "units = " << "{" << unitsSS.str() << "}" << "}";
|
||||
return commandSS.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ void Scheduler::handleRequest(string key, json::value value)
|
||||
vector<string> unitTypes;
|
||||
vector<Coords> locations;
|
||||
for (auto unit : value[L"units"].as_array()) {
|
||||
string unitType = to_string(unit[L"type"]);
|
||||
string unitType = to_string(unit[L"unitType"]);
|
||||
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;
|
||||
@@ -119,22 +119,22 @@ void Scheduler::handleRequest(string key, json::value value)
|
||||
|
||||
vector<string> unitTypes;
|
||||
vector<Coords> locations;
|
||||
vector<string> payloadNames;
|
||||
vector<string> loadouts;
|
||||
for (auto unit : value[L"units"].as_array()) {
|
||||
string unitType = to_string(unit[L"type"]);
|
||||
string unitType = to_string(unit[L"unitType"]);
|
||||
double lat = unit[L"location"][L"lat"].as_double();
|
||||
double lng = unit[L"location"][L"lng"].as_double();
|
||||
double alt = value[L"altitude"].as_double();
|
||||
double alt = unit[L"altitude"].as_double();
|
||||
Coords location; location.lat = lat; location.lng = lng; location.alt = alt;
|
||||
string payloadName = to_string(value[L"payloadName"]);
|
||||
string loadout = to_string(unit[L"loadout"]);
|
||||
|
||||
log("Spawning " + coalition + " air unit unit of type " + unitType + " at (" + to_string(lat) + ", " + to_string(lng) + ")");
|
||||
unitTypes.push_back(unitType);
|
||||
locations.push_back(location);
|
||||
payloadNames.push_back(payloadName);
|
||||
loadouts.push_back(loadout);
|
||||
}
|
||||
|
||||
command = dynamic_cast<Command*>(new SpawnAircrafts(coalition, unitTypes, locations, payloadNames, airbaseName, immediate));
|
||||
command = dynamic_cast<Command*>(new SpawnAircrafts(coalition, unitTypes, locations, loadouts, airbaseName, immediate));
|
||||
}
|
||||
else if (key.compare("attackUnit") == 0)
|
||||
{
|
||||
|
||||
@@ -221,9 +221,9 @@ string Server::extractPassword(http_request& request) {
|
||||
return "";
|
||||
|
||||
string decoded = from_base64(authorization);
|
||||
i = authorization.find(":");
|
||||
if (i != std::string::npos)
|
||||
decoded.erase(0, i);
|
||||
i = decoded.find(":");
|
||||
if (i != string::npos && i+1 < decoded.length())
|
||||
decoded.erase(0, i+1);
|
||||
else
|
||||
return "";
|
||||
|
||||
@@ -255,12 +255,11 @@ void Server::task()
|
||||
else
|
||||
log("Error reading configuration file. Starting server on " + address);
|
||||
|
||||
if (config.is_object() && config.has_object_field(L"authentication") &&
|
||||
config[L"authentication"].has_string_field(L"password"))
|
||||
if (config.is_object() && config.has_object_field(L"authentication"))
|
||||
{
|
||||
gameMasterPassword = to_string(config[L"authentication"][L"gameMasterPassword"]);
|
||||
blueCommanderPassword = to_string(config[L"authentication"][L"blueCommanderPassword"]);
|
||||
redCommanderPassword = to_string(config[L"authentication"][L"redCommanderPassword"]);
|
||||
if (config[L"authentication"].has_string_field(L"gameMasterPassword")) gameMasterPassword = to_string(config[L"authentication"][L"gameMasterPassword"]);
|
||||
if (config[L"authentication"].has_string_field(L"blueCommanderPassword")) blueCommanderPassword = to_string(config[L"authentication"][L"blueCommanderPassword"]);
|
||||
if (config[L"authentication"].has_string_field(L"redCommanderPassword")) redCommanderPassword = to_string(config[L"authentication"][L"redCommanderPassword"]);
|
||||
}
|
||||
else
|
||||
log("Error reading configuration file. No password set.");
|
||||
|
||||
@@ -84,7 +84,7 @@ void Unit::runAILoop() {
|
||||
const bool isUnitLeaderOfAGroupWithOtherUnits = unitsManager->isUnitInGroup(this) && unitsManager->isUnitGroupLeader(this);
|
||||
if (!(isUnitAlive || isUnitLeaderOfAGroupWithOtherUnits)) return;
|
||||
|
||||
if (checkTaskFailed() && state != State::IDLE && State::LAND)
|
||||
if (checkTaskFailed() && state != State::IDLE && state != State::LAND)
|
||||
setState(State::IDLE);
|
||||
|
||||
AIloop();
|
||||
@@ -188,10 +188,10 @@ bool Unit::hasFreshData(unsigned long long time) {
|
||||
void Unit::getData(stringstream& ss, unsigned long long time)
|
||||
{
|
||||
Unit* leader = this;
|
||||
if (unitsManager->isUnitInGroup(this) && !unitsManager->isUnitGroupLeader(this))
|
||||
if (unitsManager->isUnitInGroup(this) && !unitsManager->isUnitGroupLeader(this))
|
||||
leader = unitsManager->getGroupLeader(this);
|
||||
|
||||
if (!leader->hasFreshData(time)) return;
|
||||
if (leader == nullptr || (!leader->hasFreshData(time) && !hasFreshData(time))) return;
|
||||
|
||||
const unsigned char endOfData = DataIndex::endOfData;
|
||||
ss.write((const char*)&ID, sizeof(ID));
|
||||
|
||||
@@ -39,6 +39,7 @@ bool UnitsManager::isUnitInGroup(Unit* unit)
|
||||
{
|
||||
if (unit != nullptr) {
|
||||
string groupName = unit->getGroupName();
|
||||
if (groupName.length() == 0) return false;
|
||||
for (auto const& p : units)
|
||||
{
|
||||
if (p.second->getGroupName().compare(groupName) == 0 && p.second != unit)
|
||||
@@ -50,8 +51,10 @@ bool UnitsManager::isUnitInGroup(Unit* unit)
|
||||
|
||||
bool UnitsManager::isUnitGroupLeader(Unit* unit)
|
||||
{
|
||||
if (unit != nullptr)
|
||||
return unit == getGroupLeader(unit);
|
||||
if (unit != nullptr) {
|
||||
Unit* leader = getGroupLeader(unit);
|
||||
return leader == nullptr? false: unit == getGroupLeader(unit);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -61,7 +64,7 @@ Unit* UnitsManager::getGroupLeader(Unit* unit)
|
||||
{
|
||||
if (unit != nullptr) {
|
||||
string groupName = unit->getGroupName();
|
||||
|
||||
if (groupName.length() == 0) return nullptr;
|
||||
/* Find the first unit that has the same groupName */
|
||||
for (auto const& p : units)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user