Started units spawn functions and major refactoring

This commit is contained in:
Pax1601
2022-12-07 19:46:54 +01:00
parent a10762ac0c
commit 3a46a6df21
41 changed files with 1104 additions and 1121 deletions

View File

@@ -1,13 +1,14 @@
#pragma once
#include "LUAUtils.h"
#include "Utils.h"
#include "framework.h"
#include "luatools.h"
#include "utils.h"
namespace CommandPriority {
enum CommandPriorities { LOW, MEDIUM, HIGH };
};
namespace CommandType {
enum CommandTypes { NO_TYPE, MOVE };
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND };
};
/* Base command class */
@@ -27,11 +28,78 @@ protected:
class MoveCommand : public Command
{
public:
MoveCommand(int ID, wstring unitName, Coords destination) : ID(ID), unitName(unitName), destination(destination) { priority = CommandPriority::LOW; type = CommandType::MOVE; };
MoveCommand(int ID, wstring unitName, Coords destination, int unitCategory) :
ID(ID),
unitName(unitName),
destination(destination),
unitCategory(unitCategory)
{
priority = CommandPriority::LOW;
type = CommandType::MOVE;
};
virtual void execute(lua_State* L);
private:
const int ID;
const wstring unitName;
const Coords destination;
const int unitCategory;
};
/* Smoke command */
class SmokeCommand : public Command
{
public:
SmokeCommand(wstring color, Coords location) :
color(color),
location(location)
{
priority = CommandPriority::LOW;
type = CommandType::SMOKE;
};
virtual void execute(lua_State* L);
private:
const wstring color;
const Coords location;
};
/* Spawn ground unit command */
class SpawnGroundCommand : public Command
{
public:
SpawnGroundCommand(wstring coalition, wstring unitType, Coords location) :
coalition(coalition),
unitType(unitType),
location(location)
{
priority = CommandPriority::LOW;
type = CommandType::SPAWN_GROUND;
};
virtual void execute(lua_State* L);
private:
const wstring coalition;
const wstring unitType;
const Coords location;
};
/* Spawn air unit command */
class SpawnAirCommand : public Command
{
public:
SpawnAirCommand(wstring coalition, wstring unitType, Coords location) :
coalition(coalition),
unitType(unitType),
location(location)
{
priority = CommandPriority::LOW;
type = CommandType::SPAWN_AIR;
};
virtual void execute(lua_State* L);
private:
const wstring coalition;
const wstring unitType;
const Coords location;
};

View File

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

View File

@@ -1,29 +0,0 @@
#pragma once
#include "framework.h"
#include "LUAUtils.h"
using namespace web::http;
using namespace web::http::experimental::listener;
class UnitsFactory;
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

@@ -1,7 +1,7 @@
#pragma once
#include "LUAUtils.h"
#include "framework.h"
#include "Commands.h"
#include "luatools.h"
#include "commands.h"
class Scheduler
{

View File

@@ -1,8 +1,12 @@
#pragma once
#include "Utils.h"
#include "DCSUtils.h"
#include "LUAUtils.h"
#include "framework.h"
#include "utils.h"
#include "dcstools.h"
#include "luatools.h"
namespace UnitCategory {
enum UnitCategories { NO_CATEGORY, AIR, GROUND, NAVY }; // Do not edit, this codes are tied to values in DCS
};
class Unit
{
@@ -13,28 +17,31 @@ public:
void update(json::value json);
void setPath(list<Coords> path);
void setAlive(bool newAlive) { alive = newAlive; }
int getID() { return ID; }
wstring getName() { return name; }
wstring getUnitName() { return unitName; }
wstring getGroupName() { return groupName; }
int getType() { return type; }
wstring getCountry() { return country; }
json::value getType() { return type; } // This functions returns the complete type of the object (Level1, Level2, Level3, Level4)
int getCountry() { return country; }
int getCoalitionID() { return coalitionID; }
double getLatitude() { return latitude; }
double getLongitude() { return longitude; }
double getAltitude() { return altitude; }
double getHeading() { return heading; }
int getCategory();
json::value json();
protected:
int ID;
bool alive = true;
wstring name = L"undefined";
wstring unitName = L"undefined";
wstring groupName = L"undefined";
int type = 0;
wstring country = L"undefined";
json::value type = json::value::null();
int country = 0;
int coalitionID = 0;
double latitude = 0;
double longitude = 0;

View File

@@ -1,23 +0,0 @@
#pragma once
#include "framework.h"
#include "DCSUtils.h"
class Unit;
class UnitsFactory
{
public:
UnitsFactory(lua_State* L);
~UnitsFactory();
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;
};