First commit

This commit is contained in:
Pax1601
2022-11-20 12:05:38 +01:00
commit 3aa1cfe104
162 changed files with 4318 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#pragma once
#include "LUAUtils.h"
#include "Utils.h"
namespace CommandPriority {
enum CommandPriorities { LOW, MEDIUM, HIGH };
};
namespace CommandType {
enum CommandTypes { NO_TYPE, MOVE };
};
/* Base command class */
class Command
{
public:
int getPriority() { return priority; }
int getType() { return type; }
virtual void execute(lua_State* L) {};
protected:
int priority = CommandPriority::LOW;
int type = CommandType::NO_TYPE;
};
/* Simple low priority move command (from user click) */
class MoveCommand : public Command
{
public:
MoveCommand(int ID, wstring unitName, Coords destination) : ID(ID), unitName(unitName), destination(destination) { priority = CommandPriority::LOW; type = CommandType::MOVE; };
virtual void execute(lua_State* L);
private:
const int ID;
const wstring unitName;
const Coords destination;
};

View File

@@ -0,0 +1,7 @@
#pragma once
#include "framework.h"
namespace LUAFunctions
{
void registerLuaFunctions(lua_State* L);
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include "framework.h"
#include "LUAUtils.h"
using namespace web::http;
using namespace web::http::experimental::listener;
class UnitsHandler;
class Scheduler;
class RESTServer
{
public:
RESTServer(lua_State* L);
~RESTServer();
private:
std::thread* serverThread;
void handle_options(http_request request);
void handle_get(http_request request);
void handle_request(http_request request, function<void(json::value const&, json::value&)> action);
void handle_put(http_request request);
void task();
atomic<bool> runListener;
};

View File

@@ -0,0 +1,20 @@
#pragma once
#include "LUAUtils.h"
#include "framework.h"
#include "Commands.h"
class Scheduler
{
public:
Scheduler(lua_State* L);
~Scheduler();
void appendCommand(Command* command);
void execute(lua_State* L);
void handleRequest(wstring key, json::value value);
private:
list<Command*> commands;
mutex lock;
};

50
src/core/include/Unit.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
#include "Utils.h"
#include "DCSUtils.h"
#include "LUAUtils.h"
#include "framework.h"
class Unit
{
public:
Unit(json::value json, int ID);
~Unit();
void update(json::value json);
void setPath(list<Coords> path);
int getID() { return ID; }
wstring getName() { return name; }
wstring getUnitName() { return unitName; }
wstring getGroupName() { return groupName; }
int getType() { return type; }
wstring getCountry() { return country; }
int getCoalitionID() { return coalitionID; }
double getLatitude() { return latitude; }
double getLongitude() { return longitude; }
double getAltitude() { return altitude; }
double getHeading() { return heading; }
json::value json();
protected:
int ID;
wstring name = L"undefined";
wstring unitName = L"undefined";
wstring groupName = L"undefined";
int type = 0;
wstring country = L"undefined";
int coalitionID = 0;
double latitude = 0;
double longitude = 0;
double altitude = 0;
double heading = 0;
list<Coords> activePath;
Coords activeDestination;
private:
virtual void AIloop();
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include "framework.h"
#include "DCSUtils.h"
class Unit;
class UnitsHandler
{
public:
UnitsHandler(lua_State* L);
~UnitsHandler();
Unit* getUnit(int ID);
void getMissionDB(lua_State* L);
void update(lua_State* L);
void updateAnswer(json::value& answer);
private:
map<int, Unit*> units;
json::value missionDB;
};