Added feature: select unit payload at spawn and visibility.

This commit is contained in:
Davide Passoni
2022-12-30 17:43:20 +01:00
parent 92eab6fd41
commit 036f70db34
38 changed files with 14104 additions and 563 deletions

View File

@@ -8,7 +8,7 @@ namespace CommandPriority {
};
namespace CommandType {
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND, ATTACK_UNIT };
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND };
};
/* Base command class */
@@ -17,7 +17,7 @@ class Command
public:
int getPriority() { return priority; }
int getType() { return type; }
virtual void execute(lua_State* L) {};
virtual void execute(lua_State* L) = 0;
protected:
int priority = CommandPriority::LOW;
@@ -28,11 +28,14 @@ protected:
class MoveCommand : public Command
{
public:
MoveCommand(int ID, wstring unitName, Coords destination, int unitCategory) :
MoveCommand(int ID, wstring unitName, Coords destination, double speed, double altitude, wstring unitCategory, wstring targetName):
ID(ID),
unitName(unitName),
destination(destination),
unitCategory(unitCategory)
speed(speed),
altitude(altitude),
unitCategory(unitCategory),
targetName(targetName)
{
priority = CommandPriority::LOW;
type = CommandType::MOVE;
@@ -43,7 +46,10 @@ private:
const int ID;
const wstring unitName;
const Coords destination;
const int unitCategory;
const wstring unitCategory;
const double speed;
const double altitude;
const wstring targetName;
};
/* Smoke command */
@@ -88,10 +94,11 @@ private:
class SpawnAirCommand : public Command
{
public:
SpawnAirCommand(wstring coalition, wstring unitType, Coords location) :
SpawnAirCommand(wstring coalition, wstring unitType, Coords location, wstring payloadName) :
coalition(coalition),
unitType(unitType),
location(location)
location(location),
payloadName(payloadName)
{
priority = CommandPriority::LOW;
type = CommandType::SPAWN_AIR;
@@ -102,24 +109,5 @@ private:
const wstring coalition;
const wstring unitType;
const Coords location;
const wstring payloadName;
};
/* Attack unit command */
class AttackUnitCommand : public Command
{
public:
AttackUnitCommand(wstring unitName, wstring targetName, Coords location) :
unitName(unitName),
targetName(targetName),
location(location)
{
priority = CommandPriority::MEDIUM;
type = CommandType::ATTACK_UNIT;
};
virtual void execute(lua_State* L);
private:
const wstring unitName;
const wstring targetName;
const Coords location;
};

View File

@@ -7,10 +7,6 @@
#define GROUND_DEST_DIST_THR 100
#define AIR_DEST_DIST_THR 2000
namespace UnitCategory {
enum UnitCategories { NO_CATEGORY, AIR, GROUND, NAVY }; // Do not edit, this codes are tied to values in DCS
};
class Unit
{
public:
@@ -21,6 +17,17 @@ public:
void setPath(list<Coords> path);
void setAlive(bool newAlive) { alive = newAlive; }
void setTarget(int targetID);
wstring getTarget();
wstring getCurrentTask();
void resetActiveDestination();
virtual void changeSpeed(wstring change) {};
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
int getID() { return ID; }
wstring getName() { return name; }
@@ -34,9 +41,10 @@ public:
double getAltitude() { return altitude; }
double getHeading() { return heading; }
json::value getFlags() { return flags; }
int getCategory();
Coords getActiveDestination() { return activeDestination; }
virtual wstring getCategory() { return L"No category"; };
json::value json();
protected:
@@ -47,21 +55,131 @@ protected:
wstring unitName = L"undefined";
wstring groupName = L"undefined";
json::value type = json::value::null();
int country = 0;
int coalitionID = 0;
double latitude = 0;
double longitude = 0;
double altitude = 0;
double heading = 0;
int country = NULL;
int coalitionID = NULL;
double latitude = NULL;
double longitude = NULL;
double altitude = NULL;
double heading = NULL;
double speed = NULL;
json::value flags = json::value::null();
Coords oldPosition = Coords(0); // Used to approximate speed
int targetID = NULL;
bool holding = false;
bool looping = false;
double targetSpeed = 0;
double targetAltitude = 0;
list<Coords> activePath;
Coords activeDestination = Coords(0);
private:
virtual void AIloop();
double oldDist = 0;
private:
mutex mutexLock;
};
class AirUnit : public Unit
{
public:
AirUnit(json::value json, int ID);
virtual wstring getCategory() = 0;
protected:
virtual void AIloop();
};
class Aircraft : public AirUnit
{
public:
Aircraft(json::value json, int ID);
virtual wstring getCategory() { return L"Aircraft"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change);
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
protected:
double targetSpeed = 150;
double targetAltitude = 5000;
};
class Helicopter : public AirUnit
{
public:
Helicopter(json::value json, int ID);
virtual wstring getCategory() { return L"Helicopter"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change);
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
protected:
double targetSpeed = 50;
double targetAltitude = 1000;
};
class GroundUnit : public Unit
{
public:
GroundUnit(json::value json, int ID);
virtual void AIloop();
virtual wstring getCategory() { return L"GroundUnit"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
protected:
double targetSpeed = 10;
};
class NavyUnit : public Unit
{
public:
NavyUnit(json::value json, int ID);
virtual void AIloop();
virtual wstring getCategory() { return L"NavyUnit"; };
virtual void changeSpeed(wstring change);
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
protected:
double targetSpeed = 10;
};
class Weapon : public Unit
{
public:
Weapon(json::value json, int ID);
virtual wstring getCategory() = 0;
protected:
/* Weapons are not controllable and have no AIloop */
virtual void AIloop() {};
};
class Missile : public Weapon
{
public:
Missile(json::value json, int ID);
virtual wstring getCategory() { return L"Missile"; };
};
class Bomb : public Weapon
{
public:
Bomb(json::value json, int ID);
virtual wstring getCategory() { return L"Bomb"; };
};