Started air fighter AI

This commit is contained in:
Pax1601
2022-12-21 19:18:20 +01:00
parent 3a46a6df21
commit de055c5a98
1766 changed files with 137925 additions and 501 deletions

View File

@@ -8,7 +8,7 @@ namespace CommandPriority {
};
namespace CommandType {
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND };
enum CommandTypes { NO_TYPE, MOVE, SMOKE, LASE, EXPLODE, SPAWN_AIR, SPAWN_GROUND, ATTACK_UNIT };
};
/* Base command class */
@@ -102,4 +102,24 @@ private:
const wstring coalition;
const wstring unitType;
const Coords location;
};
/* 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

@@ -15,6 +15,6 @@ public:
private:
list<Command*> commands;
mutex lock;
mutex mutexLock;
};

View File

@@ -4,6 +4,9 @@
#include "dcstools.h"
#include "luatools.h"
#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
};
@@ -30,12 +33,15 @@ public:
double getLongitude() { return longitude; }
double getAltitude() { return altitude; }
double getHeading() { return heading; }
json::value getFlags() { return flags; }
int getCategory();
Coords getActiveDestination() { return activeDestination; }
json::value json();
protected:
int ID;
bool AI = false;
bool alive = true;
wstring name = L"undefined";
wstring unitName = L"undefined";
@@ -47,11 +53,15 @@ protected:
double longitude = 0;
double altitude = 0;
double heading = 0;
json::value flags = json::value::null();
list<Coords> activePath;
Coords activeDestination;
Coords activeDestination = Coords(0);
private:
virtual void AIloop();
double oldDist = 0;
mutex mutexLock;
};

View File

@@ -0,0 +1,4 @@
#pragma once
#include "framework.h"
void registerLuaFunctions(lua_State* L);

29
src/core/include/server.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include "framework.h"
#include "luatools.h"
using namespace web::http;
using namespace web::http::experimental::listener;
class UnitsFactory;
class Scheduler;
class Server
{
public:
Server(lua_State* L);
~Server();
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,23 @@
#pragma once
#include "framework.h"
#include "dcstools.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;
};