diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index fc4c18bf..94fdb7f3 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -914,7 +914,7 @@ function Olympus.setTask(groupName, taskOptions) end end --- Reset the dask of a group +-- Reset the task of a group function Olympus.resetTask(groupName) Olympus.debug("Olympus.resetTask " .. groupName, 2) local group = Group.getByName(groupName) diff --git a/src/core/include/commands.h b/src/core/include/commands.h index 02707ad0..fc86944e 100644 --- a/src/core/include/commands.h +++ b/src/core/include/commands.h @@ -124,10 +124,10 @@ public: taskOptions(taskOptions), category(category) { - priority = CommandPriority::HIGH; + priority = CommandPriority::MEDIUM; }; virtual string getString(); - virtual unsigned int getLoad() { return 2; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -196,7 +196,7 @@ public: priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; }; virtual string getString(); - virtual unsigned int getLoad() { return immediate ? 1 : 30; } + virtual unsigned int getLoad() { return immediate ? 1 : 60; } private: const string coalition; @@ -220,7 +220,7 @@ public: priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; }; virtual string getString(); - virtual unsigned int getLoad() { return immediate ? 1 : 30; } + virtual unsigned int getLoad() { return immediate ? 1 : 45; } private: const string coalition; @@ -245,7 +245,7 @@ public: priority = immediate ? CommandPriority::IMMEDIATE : CommandPriority::LOW; }; virtual string getString(); - virtual unsigned int getLoad() { return immediate ? 1 : 30; } + virtual unsigned int getLoad() { return immediate ? 1 : 45; } private: const string coalition; @@ -289,7 +289,7 @@ public: immediate = immediate; }; virtual string getString(); - virtual unsigned int getLoad() { return immediate? 1: 5; } + virtual unsigned int getLoad() { return immediate? 1: 30; } private: const unsigned int ID; @@ -310,7 +310,7 @@ public: priority = CommandPriority::MEDIUM; }; virtual string getString(); - virtual unsigned int getLoad() { return 1; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -328,7 +328,7 @@ public: priority = CommandPriority::HIGH; }; virtual string getString(); - virtual unsigned int getLoad() { return 1; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -346,7 +346,7 @@ public: priority = CommandPriority::HIGH; }; virtual string getString(); - virtual unsigned int getLoad() { return 1; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -379,7 +379,7 @@ public: priority = CommandPriority::HIGH; }; virtual string getString(); - virtual unsigned int getLoad() { return 1; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -401,7 +401,7 @@ public: priority = CommandPriority::HIGH; }; virtual string getString(); - virtual unsigned int getLoad() { return 1; } + virtual unsigned int getLoad() { return 5; } private: const string groupName; @@ -421,7 +421,7 @@ public: priority = CommandPriority::MEDIUM; }; virtual string getString(); - virtual unsigned int getLoad() { return 4; } + virtual unsigned int getLoad() { return 5; } private: const Coords location; diff --git a/src/core/src/aircraft.cpp b/src/core/src/aircraft.cpp index eb716c01..4c91f938 100644 --- a/src/core/src/aircraft.cpp +++ b/src/core/src/aircraft.cpp @@ -34,7 +34,6 @@ Aircraft::Aircraft(json::value json, unsigned int ID) : AirUnit(json, ID) setCategory("Aircraft"); setDesiredSpeed(knotsToMs(300)); setDesiredAltitude(ftToM(20000)); - }; void Aircraft::changeSpeed(string change) @@ -48,11 +47,6 @@ void Aircraft::changeSpeed(string change) if (getDesiredSpeed() < knotsToMs(50)) setDesiredSpeed(knotsToMs(50)); - - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ } void Aircraft::changeAltitude(string change) @@ -69,14 +63,9 @@ void Aircraft::changeAltitude(string change) if (getDesiredAltitude() > 5000) setDesiredAltitude(getDesiredAltitude() + ftToM(2500)); else if (getDesiredAltitude() >= 0) - setDesiredAltitude(getDesiredAltitude() + ftToM(500)); + setDesiredAltitude(getDesiredAltitude() + ftToM(500)); } if (getDesiredAltitude() < 0) setDesiredAltitude(0); - - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ } \ No newline at end of file diff --git a/src/core/src/airunit.cpp b/src/core/src/airunit.cpp index f5f95f20..24080da5 100644 --- a/src/core/src/airunit.cpp +++ b/src/core/src/airunit.cpp @@ -146,12 +146,15 @@ void AirUnit::setState(unsigned char newState) break; } - resetTask(); + setHasTask(false); + resetTaskFailedCounter(); log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); state = newState; triggerUpdate(DataIndex::state); + + AIloop(); } void AirUnit::AIloop() diff --git a/src/core/src/groundunit.cpp b/src/core/src/groundunit.cpp index f40e73b7..b8405bee 100644 --- a/src/core/src/groundunit.cpp +++ b/src/core/src/groundunit.cpp @@ -104,7 +104,6 @@ void GroundUnit::setState(unsigned char newState) setEnableTaskCheckFailed(true); clearActivePath(); resetActiveDestination(); - resetTask(); break; } case State::FIRE_AT_AREA: { @@ -135,12 +134,15 @@ void GroundUnit::setState(unsigned char newState) break; } - resetTask(); + setHasTask(false); + resetTaskFailedCounter(); log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); state = newState; triggerUpdate(DataIndex::state); + + AIloop(); } void GroundUnit::AIloop() @@ -217,7 +219,7 @@ void GroundUnit::AIloop() case State::SIMULATE_FIRE_FIGHT: { setTask("Simulating fire fight"); - if (internalCounter == 0 && targetPosition != Coords(NULL)) { + if (internalCounter == 0 && targetPosition != Coords(NULL) && scheduler->getLoad() == 0) { /* Get the distance and bearing to the target */ Coords scatteredTargetPosition = targetPosition; double distance; diff --git a/src/core/src/navyunit.cpp b/src/core/src/navyunit.cpp index 317178e1..a9e2194f 100644 --- a/src/core/src/navyunit.cpp +++ b/src/core/src/navyunit.cpp @@ -93,34 +93,33 @@ void NavyUnit::setState(unsigned char newState) setEnableTaskCheckFailed(true); clearActivePath(); resetActiveDestination(); - resetTask(); break; } case State::FIRE_AT_AREA: { setEnableTaskCheckFailed(true); clearActivePath(); resetActiveDestination(); - resetTask(); break; } case State::SIMULATE_FIRE_FIGHT: { setEnableTaskCheckFailed(true); clearActivePath(); resetActiveDestination(); - resetTask(); break; } default: break; } - if (newState != state) - resetTask(); + setHasTask(false); + resetTaskFailedCounter(); log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); state = newState; triggerUpdate(DataIndex::state); + + AIloop(); } void NavyUnit::AIloop() @@ -188,15 +187,9 @@ void NavyUnit::AIloop() case State::SIMULATE_FIRE_FIGHT: { setTask("Simulating fire fight"); - if (!getHasTask()) { - std::ostringstream taskSS; - taskSS.precision(10); + // TODO - taskSS << "{id = 'FireAtPoint', lat = " << targetPosition.lat << ", lng = " << targetPosition.lng << ", radius = 1}"; - Command* command = dynamic_cast(new SetTask(groupName, taskSS.str(), [this]() { this->setHasTaskAssigned(true); })); - scheduler->appendCommand(command); - setHasTask(true); - } + setState(State::IDLE); } default: break; diff --git a/src/core/src/scheduler.cpp b/src/core/src/scheduler.cpp index a5289b5b..28af3520 100644 --- a/src/core/src/scheduler.cpp +++ b/src/core/src/scheduler.cpp @@ -56,7 +56,13 @@ void Scheduler::execute(lua_State* L) log("Error executing command " + commandString); else log("Command '" + commandString + "' executed correctly, current load " + to_string(getLoad())); - load = command->getLoad(); + + /* Adjust the load depending on the fps */ + double fpsMultiplier = 1; + if (getFrameRate() + 5 > 0) + fpsMultiplier = static_cast(max(1, 60 / (getFrameRate() + 5))); + + load = command->getLoad() * fpsMultiplier; commands.remove(command); executedCommandsHashes.push_back(command->getHash()); command->executeCallback(); /* Execute the command callback (this is a lambda function that can be used to execute a function when the command is run) */ diff --git a/src/core/src/unit.cpp b/src/core/src/unit.cpp index 11e3a4f1..6e6959a0 100644 --- a/src/core/src/unit.cpp +++ b/src/core/src/unit.cpp @@ -430,7 +430,11 @@ void Unit::resetTask() void Unit::setFormationOffset(Offset newFormationOffset) { formationOffset = newFormationOffset; - resetTask(); + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::formationOffset); } @@ -519,7 +523,11 @@ void Unit::setIsActiveTanker(bool newIsActiveTanker) { if (isActiveTanker != newIsActiveTanker) { isActiveTanker = newIsActiveTanker; - resetTask(); + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::isActiveTanker); } @@ -529,7 +537,11 @@ void Unit::setIsActiveAWACS(bool newIsActiveAWACS) { if (isActiveAWACS != newIsActiveAWACS) { isActiveAWACS = newIsActiveAWACS; - resetTask(); + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::isActiveAWACS); } @@ -644,10 +656,11 @@ void Unit::setDesiredSpeed(double newDesiredSpeed) { if (desiredSpeed != newDesiredSpeed) { desiredSpeed = newDesiredSpeed; - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::desiredSpeed); } @@ -657,10 +670,11 @@ void Unit::setDesiredAltitude(double newDesiredAltitude) { if (desiredAltitude != newDesiredAltitude) { desiredAltitude = newDesiredAltitude; - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::desiredAltitude); } @@ -670,10 +684,11 @@ void Unit::setDesiredSpeedType(string newDesiredSpeedType) { if (desiredSpeedType != (newDesiredSpeedType.compare("GS") == 0)) { desiredSpeedType = newDesiredSpeedType.compare("GS") == 0; - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::desiredSpeedType); } @@ -683,10 +698,11 @@ void Unit::setDesiredAltitudeType(string newDesiredAltitudeType) { if (desiredAltitudeType != (newDesiredAltitudeType.compare("AGL") == 0)) { desiredAltitudeType = newDesiredAltitudeType.compare("AGL") == 0; - if (state == State::IDLE) - resetTask(); - else - goToDestination(); /* Send the command to reach the destination */ + + /* Apply the change */ + setHasTask(false); + resetTaskFailedCounter(); + AIloop(); triggerUpdate(DataIndex::desiredAltitudeType); }