Fixed change altitude and speed for helicopters

This commit is contained in:
Pax1601 2023-12-05 09:11:36 +01:00
parent 62142ed976
commit 71cf7c67f7
5 changed files with 23 additions and 19 deletions

View File

@ -1,6 +1,8 @@
#pragma once
#include "airunit.h"
#define AIRCRAFT_DEST_DIST_THR 2000 // Meters
class Aircraft : public AirUnit
{
public:
@ -11,6 +13,8 @@ public:
virtual void changeSpeed(string change);
virtual void changeAltitude(string change);
virtual double getDestinationReachedThreshold() { return AIRCRAFT_DEST_DIST_THR; }
protected:
static json::value database;
};

View File

@ -17,6 +17,7 @@ public:
virtual void changeSpeed(string change) = 0;
virtual void changeAltitude(string change) = 0;
virtual double getDestinationReachedThreshold() { return AIR_DEST_DIST_THR; }
protected:
virtual void AIloop();

View File

@ -1,6 +1,8 @@
#pragma once
#include "airunit.h"
#define HELICOPTER_DEST_DIST_THR 500 // Meters
class Helicopter : public AirUnit
{
public:
@ -11,6 +13,8 @@ public:
virtual void changeSpeed(string change);
virtual void changeAltitude(string change);
virtual double getDestinationReachedThreshold() { return HELICOPTER_DEST_DIST_THR; }
protected:
static json::value database;
};

View File

@ -221,7 +221,7 @@ void AirUnit::AIloop()
goToDestination(enrouteTask);
}
else {
if (isDestinationReached(AIR_DEST_DIST_THR)) {
if (isDestinationReached(getDestinationReachedThreshold())) {
if (updateActivePath(looping) && setActiveDestination())
goToDestination(enrouteTask);
else

View File

@ -41,33 +41,28 @@ void Helicopter::changeSpeed(string change)
if (change.compare("stop") == 0)
setState(State::IDLE);
else if (change.compare("slow") == 0)
desiredSpeed -= knotsToMs(10);
setDesiredSpeed(getDesiredSpeed() - knotsToMs(10));
else if (change.compare("fast") == 0)
desiredSpeed += knotsToMs(10);
if (desiredSpeed < 0)
desiredSpeed = 0;
goToDestination(); /* Send the command to reach the destination */
setDesiredSpeed(getDesiredSpeed() + knotsToMs(10));
}
void Helicopter::changeAltitude(string change)
{
if (change.compare("descend") == 0)
{
if (desiredAltitude > 100)
desiredAltitude -= ftToM(100);
else if (desiredAltitude > 0)
desiredAltitude -= ftToM(10);
if (getDesiredAltitude() > 100)
setDesiredAltitude(getDesiredAltitude() - ftToM(100));
else if (getDesiredAltitude() > 0)
setDesiredAltitude(getDesiredAltitude() - ftToM(10));
}
else if (change.compare("climb") == 0)
{
if (desiredAltitude > 100)
desiredAltitude += ftToM(100);
else if (desiredAltitude >= 0)
desiredAltitude += ftToM(10);
if (getDesiredAltitude() > 100)
setDesiredAltitude(getDesiredAltitude() + ftToM(100));
else if (getDesiredAltitude() >= 0)
setDesiredAltitude(getDesiredAltitude() + ftToM(10));
}
if (desiredAltitude < 0)
desiredAltitude = 0;
goToDestination(); /* Send the command to reach the destination */
}
if (getDesiredAltitude() < 0)
setDesiredAltitude(0);
}