mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Reworked unit as as state machine, added formations, added measuring on map, added copy-paste
This commit is contained in:
@@ -8,7 +8,7 @@ namespace CommandPriority {
|
||||
};
|
||||
|
||||
namespace CommandType {
|
||||
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND, CLONE, LAND, REFUEL, FOLLOW };
|
||||
enum CommandTypes { NO_TYPE, MOVE, SMOKE, SPAWN_AIR, SPAWN_GROUND, CLONE, FOLLOW, RESET_TASK, SET_OPTION, SET_COMMAND, SET_TASK };
|
||||
};
|
||||
|
||||
/* Base command class */
|
||||
@@ -25,10 +25,10 @@ protected:
|
||||
};
|
||||
|
||||
/* Simple low priority move command (from user click) */
|
||||
class MoveCommand : public Command
|
||||
class Move : public Command
|
||||
{
|
||||
public:
|
||||
MoveCommand(int ID, Coords destination, double speed, double altitude, wstring unitCategory, wstring taskOptions):
|
||||
Move(int ID, Coords destination, double speed, double altitude, wstring unitCategory, wstring taskOptions):
|
||||
ID(ID),
|
||||
destination(destination),
|
||||
speed(speed),
|
||||
@@ -51,10 +51,10 @@ private:
|
||||
};
|
||||
|
||||
/* Smoke command */
|
||||
class SmokeCommand : public Command
|
||||
class Smoke : public Command
|
||||
{
|
||||
public:
|
||||
SmokeCommand(wstring color, Coords location) :
|
||||
Smoke(wstring color, Coords location) :
|
||||
color(color),
|
||||
location(location)
|
||||
{
|
||||
@@ -69,10 +69,10 @@ private:
|
||||
};
|
||||
|
||||
/* Spawn ground unit command */
|
||||
class SpawnGroundUnitCommand : public Command
|
||||
class SpawnGroundUnit : public Command
|
||||
{
|
||||
public:
|
||||
SpawnGroundUnitCommand(wstring coalition, wstring unitType, Coords location) :
|
||||
SpawnGroundUnit(wstring coalition, wstring unitType, Coords location) :
|
||||
coalition(coalition),
|
||||
unitType(unitType),
|
||||
location(location)
|
||||
@@ -89,10 +89,10 @@ private:
|
||||
};
|
||||
|
||||
/* Spawn air unit command */
|
||||
class SpawnAircraftCommand : public Command
|
||||
class SpawnAircraft : public Command
|
||||
{
|
||||
public:
|
||||
SpawnAircraftCommand(wstring coalition, wstring unitType, Coords location, wstring payloadName, wstring airbaseName) :
|
||||
SpawnAircraft(wstring coalition, wstring unitType, Coords location, wstring payloadName, wstring airbaseName) :
|
||||
coalition(coalition),
|
||||
unitType(unitType),
|
||||
location(location),
|
||||
@@ -114,10 +114,10 @@ private:
|
||||
};
|
||||
|
||||
/* Clone unit command */
|
||||
class CloneCommand : public Command
|
||||
class Clone : public Command
|
||||
{
|
||||
public:
|
||||
CloneCommand(int ID) :
|
||||
Clone(int ID) :
|
||||
ID(ID)
|
||||
{
|
||||
priority = CommandPriority::LOW;
|
||||
@@ -130,19 +130,73 @@ private:
|
||||
};
|
||||
|
||||
/* Follow command */
|
||||
class FollowCommand : public Command
|
||||
class SetTask : public Command
|
||||
{
|
||||
public:
|
||||
FollowCommand(int leaderID, int ID) :
|
||||
leaderID(leaderID),
|
||||
ID(ID)
|
||||
SetTask(int ID, wstring task) :
|
||||
ID(ID),
|
||||
task(task)
|
||||
{
|
||||
priority = CommandPriority::LOW;
|
||||
priority = CommandPriority::MEDIUM;
|
||||
type = CommandType::FOLLOW;
|
||||
};
|
||||
virtual wstring getString(lua_State* L);
|
||||
|
||||
private:
|
||||
const int leaderID;
|
||||
const int ID;
|
||||
const wstring task;
|
||||
};
|
||||
|
||||
/* Reset task command */
|
||||
class ResetTask : public Command
|
||||
{
|
||||
public:
|
||||
ResetTask(int ID) :
|
||||
ID(ID)
|
||||
{
|
||||
priority = CommandPriority::HIGH;
|
||||
type = CommandType::RESET_TASK;
|
||||
};
|
||||
virtual wstring getString(lua_State* L);
|
||||
|
||||
private:
|
||||
const int ID;
|
||||
};
|
||||
|
||||
/* Set command */
|
||||
class SetCommand : public Command
|
||||
{
|
||||
public:
|
||||
SetCommand(int ID, wstring command) :
|
||||
ID(ID),
|
||||
command(command)
|
||||
{
|
||||
priority = CommandPriority::HIGH;
|
||||
type = CommandType::RESET_TASK;
|
||||
};
|
||||
virtual wstring getString(lua_State* L);
|
||||
|
||||
private:
|
||||
const int ID;
|
||||
const wstring command;
|
||||
};
|
||||
|
||||
/* Set option command */
|
||||
class SetOption : public Command
|
||||
{
|
||||
public:
|
||||
SetOption(int ID, int optionID, int optionValue) :
|
||||
ID(ID),
|
||||
optionID(optionID),
|
||||
optionValue(optionValue)
|
||||
{
|
||||
priority = CommandPriority::HIGH;
|
||||
type = CommandType::RESET_TASK;
|
||||
};
|
||||
virtual wstring getString(lua_State* L);
|
||||
|
||||
private:
|
||||
const int ID;
|
||||
const int optionID;
|
||||
const int optionValue;
|
||||
};
|
||||
@@ -4,8 +4,9 @@
|
||||
#include "dcstools.h"
|
||||
#include "luatools.h"
|
||||
|
||||
#define GROUND_DEST_DIST_THR 100
|
||||
#define AIR_DEST_DIST_THR 2000
|
||||
namespace State {
|
||||
enum States { IDLE, REACH_DESTINATION, ATTACK, WINGMAN, FOLLOW, RTB, REFUEL, AWACS, EWR, TANKER, RUN_AWAY };
|
||||
};
|
||||
|
||||
class Unit
|
||||
{
|
||||
@@ -17,19 +18,19 @@ public:
|
||||
void updateMissionData(json::value json);
|
||||
json::value json();
|
||||
|
||||
virtual void setState(int newState) { state = newState; };
|
||||
void resetTask();
|
||||
|
||||
void setPath(list<Coords> path);
|
||||
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; }
|
||||
void setAlive(bool newAlive) { alive = newAlive; }
|
||||
void setTarget(int targetID);
|
||||
void setLeader(bool newLeader) { leader = newLeader; }
|
||||
void setWingman(bool newWingman) { wingman = newWingman; }
|
||||
void setIsLeader(bool newIsLeader);
|
||||
void setIsWingman(bool newIsWingman);
|
||||
void setLeader(Unit* newLeader) { leader = newLeader; }
|
||||
void setWingmen(vector<Unit*> newWingmen) { wingmen = newWingmen; }
|
||||
void setFormation(wstring newFormation) { formation = newFormation; }
|
||||
|
||||
virtual void changeSpeed(wstring change) {};
|
||||
virtual void changeAltitude(wstring change) {};
|
||||
|
||||
void resetActiveDestination();
|
||||
void setFormationOffset(Offset formationOffset);
|
||||
|
||||
int getID() { return ID; }
|
||||
wstring getName() { return name; }
|
||||
@@ -46,12 +47,26 @@ public:
|
||||
Coords getActiveDestination() { return activeDestination; }
|
||||
virtual wstring getCategory() { return L"No category"; };
|
||||
wstring getTarget();
|
||||
bool isTargetAlive();
|
||||
wstring getCurrentTask() { return currentTask; }
|
||||
bool getAlive() { return alive; }
|
||||
bool getIsLeader() { return isLeader; }
|
||||
bool getIsWingman() { return isWingman; }
|
||||
wstring getFormation() { return formation; }
|
||||
|
||||
virtual double getTargetSpeed() { return targetSpeed; };
|
||||
virtual double getTargetAltitude() { return targetAltitude; };
|
||||
virtual void setTargetSpeed(double newSpeed) { targetSpeed = newSpeed; }
|
||||
virtual void setTargetAltitude(double newAltitude) { targetAltitude = newAltitude; }
|
||||
virtual void changeSpeed(wstring change) {};
|
||||
virtual void changeAltitude(wstring change) {};
|
||||
|
||||
void resetActiveDestination();
|
||||
|
||||
protected:
|
||||
int ID;
|
||||
int state = State::IDLE;
|
||||
bool hasTask = false;
|
||||
bool AI = false;
|
||||
bool alive = true;
|
||||
wstring name = L"undefined";
|
||||
@@ -67,13 +82,12 @@ protected:
|
||||
double speed = NULL;
|
||||
json::value flags = json::value::null();
|
||||
int targetID = NULL;
|
||||
bool holding = false;
|
||||
bool looping = false;
|
||||
wstring taskOptions = L"{}";
|
||||
wstring currentTask = L"";
|
||||
bool leader = false;
|
||||
bool wingman = false;
|
||||
bool isLeader = false;
|
||||
bool isWingman = false;
|
||||
Offset formationOffset = Offset(NULL);
|
||||
wstring formation = L"";
|
||||
Unit* leader = nullptr;
|
||||
vector<Unit*> wingmen;
|
||||
double targetSpeed = 0;
|
||||
double targetAltitude = 0;
|
||||
@@ -85,112 +99,16 @@ protected:
|
||||
Coords activeDestination = Coords(0);
|
||||
Coords oldPosition = Coords(0); // Used to approximate speed
|
||||
|
||||
virtual void AIloop();
|
||||
virtual void AIloop() = 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"; };
|
||||
};
|
||||
|
||||
|
||||
19
src/core/include/aircraft.h
Normal file
19
src/core/include/aircraft.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "airunit.h"
|
||||
|
||||
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;
|
||||
};
|
||||
30
src/core/include/airunit.h
Normal file
30
src/core/include/airunit.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "framework.h"
|
||||
#include "utils.h"
|
||||
#include "dcstools.h"
|
||||
#include "luatools.h"
|
||||
#include "Unit.h"
|
||||
|
||||
#define AIR_DEST_DIST_THR 2000
|
||||
|
||||
class AirUnit : public Unit
|
||||
{
|
||||
public:
|
||||
AirUnit(json::value json, int ID);
|
||||
|
||||
virtual wstring getCategory() = 0;
|
||||
virtual void changeSpeed(wstring change) {};
|
||||
virtual void changeAltitude(wstring change) {};
|
||||
virtual void setTargetSpeed(double newTargetSpeed);
|
||||
virtual void setTargetAltitude(double newTargetAltitude);
|
||||
|
||||
protected:
|
||||
virtual void AIloop();
|
||||
virtual void setState(int newState);
|
||||
bool isDestinationReached();
|
||||
bool setActiveDestination();
|
||||
void createHoldingPattern();
|
||||
bool updateActivePath(bool looping);
|
||||
void goToDestination(wstring enrouteTask = L"nil");
|
||||
void taskWingmen();
|
||||
};
|
||||
19
src/core/include/groundunit.h
Normal file
19
src/core/include/groundunit.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "unit.h"
|
||||
|
||||
#define GROUND_DEST_DIST_THR 100
|
||||
|
||||
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;
|
||||
};
|
||||
19
src/core/include/helicopter.h
Normal file
19
src/core/include/helicopter.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "airunit.h"
|
||||
|
||||
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;
|
||||
};
|
||||
17
src/core/include/navyunit.h
Normal file
17
src/core/include/navyunit.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "unit.h"
|
||||
|
||||
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;
|
||||
};
|
||||
30
src/core/include/weapon.h
Normal file
30
src/core/include/weapon.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "unit.h"
|
||||
|
||||
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"; };
|
||||
};
|
||||
Reference in New Issue
Block a user