Started migration to TypeScript

This commit is contained in:
Pax1601
2023-01-08 10:05:10 +01:00
parent 036f70db34
commit ca6b66eb33
55 changed files with 1429 additions and 662 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, CLONE, LAND, REFUEL, FOLLOW };
};
/* Base command class */
@@ -17,7 +17,7 @@ class Command
public:
int getPriority() { return priority; }
int getType() { return type; }
virtual void execute(lua_State* L) = 0;
virtual wstring getString(lua_State* L) = 0;
protected:
int priority = CommandPriority::LOW;
@@ -28,28 +28,26 @@ protected:
class MoveCommand : public Command
{
public:
MoveCommand(int ID, wstring unitName, Coords destination, double speed, double altitude, wstring unitCategory, wstring targetName):
ID(ID),
unitName(unitName),
MoveCommand(int ID, Coords destination, double speed, double altitude, wstring unitCategory, wstring taskOptions):
ID(ID),
destination(destination),
speed(speed),
altitude(altitude),
unitCategory(unitCategory),
targetName(targetName)
taskOptions(taskOptions)
{
priority = CommandPriority::LOW;
priority = CommandPriority::HIGH;
type = CommandType::MOVE;
};
virtual void execute(lua_State* L);
virtual wstring getString(lua_State* L);
private:
const int ID;
const wstring unitName;
const Coords destination;
const wstring unitCategory;
const double speed;
const double altitude;
const wstring targetName;
const wstring taskOptions;
};
/* Smoke command */
@@ -63,7 +61,7 @@ public:
priority = CommandPriority::LOW;
type = CommandType::SMOKE;
};
virtual void execute(lua_State* L);
virtual wstring getString(lua_State* L);
private:
const wstring color;
@@ -71,10 +69,10 @@ private:
};
/* Spawn ground unit command */
class SpawnGroundCommand : public Command
class SpawnGroundUnitCommand : public Command
{
public:
SpawnGroundCommand(wstring coalition, wstring unitType, Coords location) :
SpawnGroundUnitCommand(wstring coalition, wstring unitType, Coords location) :
coalition(coalition),
unitType(unitType),
location(location)
@@ -82,7 +80,7 @@ public:
priority = CommandPriority::LOW;
type = CommandType::SPAWN_GROUND;
};
virtual void execute(lua_State* L);
virtual wstring getString(lua_State* L);
private:
const wstring coalition;
@@ -91,23 +89,60 @@ private:
};
/* Spawn air unit command */
class SpawnAirCommand : public Command
class SpawnAircraftCommand : public Command
{
public:
SpawnAirCommand(wstring coalition, wstring unitType, Coords location, wstring payloadName) :
SpawnAircraftCommand(wstring coalition, wstring unitType, Coords location, wstring payloadName, wstring airbaseName) :
coalition(coalition),
unitType(unitType),
location(location),
payloadName(payloadName)
payloadName(payloadName),
airbaseName(airbaseName)
{
priority = CommandPriority::LOW;
type = CommandType::SPAWN_AIR;
};
virtual void execute(lua_State* L);
virtual wstring getString(lua_State* L);
private:
const wstring coalition;
const wstring unitType;
const Coords location;
const wstring payloadName;
const wstring airbaseName;
};
/* Clone unit command */
class CloneCommand : public Command
{
public:
CloneCommand(int ID) :
ID(ID)
{
priority = CommandPriority::LOW;
type = CommandType::CLONE;
};
virtual wstring getString(lua_State* L);
private:
const int ID;
};
/* Follow command */
class FollowCommand : public Command
{
public:
FollowCommand(int leaderID, int ID) :
leaderID(leaderID),
ID(ID)
{
priority = CommandPriority::LOW;
type = CommandType::FOLLOW;
};
virtual wstring getString(lua_State* L);
private:
const int leaderID;
const int ID;
};

View File

@@ -14,26 +14,27 @@ public:
~Unit();
void update(json::value json);
json::value json();
void setPath(list<Coords> path);
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; }
void setAlive(bool newAlive) { alive = newAlive; }
void setTarget(int targetID);
wstring getTarget();
wstring getCurrentTask();
void resetActiveDestination();
void setLeader(bool newLeader) { leader = newLeader; }
void setWingman(bool newWingman) { wingman = newWingman; }
void setWingmen(vector<Unit*> newWingmen) { wingmen = newWingmen; }
void setFormation(wstring newFormation) { formation = newFormation; }
virtual void changeSpeed(wstring change) {};
virtual void changeAltitude(wstring change) {};
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
void resetActiveDestination();
int getID() { return ID; }
wstring getName() { return name; }
wstring getUnitName() { return unitName; }
wstring getGroupName() { return groupName; }
json::value getType() { return type; } // This functions returns the complete type of the object (Level1, Level2, Level3, Level4)
json::value getType() { return type; } // This function returns the complete type of the object (Level1, Level2, Level3, Level4)
int getCountry() { return country; }
int getCoalitionID() { return coalitionID; }
double getLatitude() { return latitude; }
@@ -42,34 +43,40 @@ public:
double getHeading() { return heading; }
json::value getFlags() { return flags; }
Coords getActiveDestination() { return activeDestination; }
virtual wstring getCategory() { return L"No category"; };
json::value json();
wstring getTarget();
wstring getCurrentTask() { return currentTask; }
virtual double getTargetSpeed() { return targetSpeed; };
virtual double getTargetAltitude() { return targetAltitude; };
protected:
int ID;
bool AI = false;
bool alive = true;
wstring name = L"undefined";
wstring unitName = L"undefined";
wstring groupName = L"undefined";
json::value type = json::value::null();
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;
bool AI = false;
bool alive = true;
wstring name = L"undefined";
wstring unitName = L"undefined";
wstring groupName = L"undefined";
json::value type = json::value::null();
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;
wstring taskOptions = L"{}";
wstring currentTask = L"";
bool leader = false;
bool wingman = false;
wstring formation = L"";
vector<Unit*> wingmen;
double targetSpeed = 0;
double targetAltitude = 0;
list<Coords> activePath;
Coords activeDestination = Coords(0);

View File

@@ -1,4 +1,13 @@
#pragma once
#include "framework.h"
#define PROTECTED_CALL "Olympus = {}\n \
function Olympus.protectedCall(...)\n\n \
local status, retval = pcall(...)\n \
if not status then\n \
trigger.action.outText(\"ERROR: \" ..retval, 20)\n \
end\n \
end\n \
trigger.action.outText(\"Olympus.protectedCall registered successfully\", 10)\n"
void registerLuaFunctions(lua_State* L);