mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Minor cleanup
This commit is contained in:
@@ -10,7 +10,7 @@ import { AIC } from "./aic/aic";
|
|||||||
import { ATC } from "./atc/ATC";
|
import { ATC } from "./atc/ATC";
|
||||||
import { FeatureSwitches } from "./FeatureSwitches";
|
import { FeatureSwitches } from "./FeatureSwitches";
|
||||||
import { LogPanel } from "./panels/logpanel";
|
import { LogPanel } from "./panels/logpanel";
|
||||||
import { getAirbases, getBulllseye, getUnits } from "./server/server";
|
import { getAirbases, getBulllseye as getBulllseyes, getUnits } from "./server/server";
|
||||||
|
|
||||||
var map: Map;
|
var map: Map;
|
||||||
var contextMenu: ContextMenu;
|
var contextMenu: ContextMenu;
|
||||||
@@ -138,7 +138,7 @@ function setup() {
|
|||||||
|
|
||||||
/* On the first connection, force request of full data */
|
/* On the first connection, force request of full data */
|
||||||
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
|
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
|
||||||
getBulllseye((data: BullseyesData) => getMissionData()?.update(data));
|
getBulllseyes((data: BullseyesData) => getMissionData()?.update(data));
|
||||||
getUnits((data: UnitsData) => getUnitsManager()?.update(data), true /* Does a full refresh */);
|
getUnits((data: UnitsData) => getUnitsManager()?.update(data), true /* Does a full refresh */);
|
||||||
|
|
||||||
/* Start periodically requesting updates */
|
/* Start periodically requesting updates */
|
||||||
@@ -165,9 +165,8 @@ function requestUpdate() {
|
|||||||
function requestRefresh() {
|
function requestRefresh() {
|
||||||
/* Main refresh rate = 5000ms. */
|
/* Main refresh rate = 5000ms. */
|
||||||
getUnits((data: UnitsData) => {
|
getUnits((data: UnitsData) => {
|
||||||
getUnitsManager()?.update(data);
|
|
||||||
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
|
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
|
||||||
getBulllseye((data: BullseyesData) => getMissionData()?.update(data));
|
getBulllseyes((data: BullseyesData) => getMissionData()?.update(data));
|
||||||
checkSessionHash(data.sessionHash);
|
checkSessionHash(data.sessionHash);
|
||||||
}, true);
|
}, true);
|
||||||
setTimeout(() => requestRefresh(), 5000);
|
setTimeout(() => requestRefresh(), 5000);
|
||||||
|
|||||||
@@ -60,12 +60,6 @@ export class UnitsManager {
|
|||||||
.forEach((ID: string) => this.#units[parseInt(ID)]?.setData(data.units[ID]));
|
.forEach((ID: string) => this.#units[parseInt(ID)]?.setData(data.units[ID]));
|
||||||
}
|
}
|
||||||
|
|
||||||
forceUpdate() {
|
|
||||||
for (let ID in this.#units) {
|
|
||||||
this.#units[ID].forceUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selectUnit(ID: number, deselectAllUnits: boolean = true)
|
selectUnit(ID: number, deselectAllUnits: boolean = true)
|
||||||
{
|
{
|
||||||
if (deselectAllUnits)
|
if (deselectAllUnits)
|
||||||
|
|||||||
@@ -4,8 +4,22 @@
|
|||||||
#include "dcstools.h"
|
#include "dcstools.h"
|
||||||
#include "luatools.h"
|
#include "luatools.h"
|
||||||
|
|
||||||
namespace State {
|
namespace State
|
||||||
enum States { IDLE, REACH_DESTINATION, ATTACK, WINGMAN, FOLLOW, LAND, REFUEL, AWACS, EWR, TANKER, RUN_AWAY };
|
{
|
||||||
|
enum States
|
||||||
|
{
|
||||||
|
IDLE,
|
||||||
|
REACH_DESTINATION,
|
||||||
|
ATTACK,
|
||||||
|
WINGMAN,
|
||||||
|
FOLLOW,
|
||||||
|
LAND,
|
||||||
|
REFUEL,
|
||||||
|
AWACS,
|
||||||
|
EWR,
|
||||||
|
TANKER,
|
||||||
|
RUN_AWAY
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Unit
|
class Unit
|
||||||
@@ -14,109 +28,159 @@ public:
|
|||||||
Unit(json::value json, int ID);
|
Unit(json::value json, int ID);
|
||||||
~Unit();
|
~Unit();
|
||||||
|
|
||||||
|
int getID() { return ID; }
|
||||||
|
|
||||||
void updateExportData(json::value json);
|
void updateExportData(json::value json);
|
||||||
void updateMissionData(json::value json);
|
void updateMissionData(json::value json);
|
||||||
json::value json(bool fullRefresh);
|
json::value json(bool fullRefresh);
|
||||||
|
|
||||||
|
/********** Base data **********/
|
||||||
|
void setAI(bool newAI) { AI = newAI; }
|
||||||
|
bool getAI() { return AI; }
|
||||||
|
void setName(wstring newName){name = newName};
|
||||||
|
wstring getName() { return name; }
|
||||||
|
void setUnitName(wstring newName){name = newName};
|
||||||
|
wstring getUnitName() { return unitName; }
|
||||||
|
void setGroupName(wstring newName){name = newName};
|
||||||
|
wstring getGroupName() { return groupName; }
|
||||||
|
void setAlive(bool newAlive) { alive = newAlive; }
|
||||||
|
bool getAlive() { return alive; }
|
||||||
|
void setType(json::value newType) { type = newType; }
|
||||||
|
json::value getType() { return type; }
|
||||||
|
void setCountry(int newCountry) { country = newCountry; }
|
||||||
|
int getCountry() { return country; }
|
||||||
|
|
||||||
|
/********** Flight data **********/
|
||||||
|
void setLatitude(double newLatitude) {latitude = newLatitude;}
|
||||||
|
double getLatitude() { return latitude; }
|
||||||
|
void setLongitude(double newLatitude) {longitude = newLongitude;}
|
||||||
|
double getLongitude() { return longitude; }
|
||||||
|
void setAltitude(double newAltitude) {altitude = newAltitude;}
|
||||||
|
double getAltitude() { return altitude; }
|
||||||
|
void setHeading(double newHeading) {heading = newHeading;}
|
||||||
|
double getHeading() { return heading; }
|
||||||
|
void setSpeed(double newSpeed) {speed = newSpeed;}
|
||||||
|
double getSpeed() {return speed; }
|
||||||
|
|
||||||
|
/********** Mission data **********/
|
||||||
|
void setFuel(double newFuel) { fuel = newFuel;}
|
||||||
|
double getFuel() {return fuel;}
|
||||||
|
void setAmmo(json::value newAmmo) { ammo = newAmmo; }
|
||||||
|
json::value getAmmo { return ammo; }
|
||||||
|
void setTargets(json::value newTargets) {targets = newTargets;}
|
||||||
|
json::value getTargets() { return targets; }
|
||||||
|
void setHasTask(bool newHasTask) { hasTask = newHasTask;}
|
||||||
|
bool getHasTask() { return hasTask; }
|
||||||
|
void setCoalitionID(int newCoalitionID) { coalitionID = newCoalitionID; }
|
||||||
|
int getCoalitionID() { return coalitionID; }
|
||||||
|
void setFlags(json::value newFlags) { flags = newFlags; }
|
||||||
|
json::value getFlags() { return flags; }
|
||||||
|
|
||||||
|
/********** Formation data **********/
|
||||||
|
void setIsLeader(bool newIsLeader);
|
||||||
|
bool getIsLeader() { return isLeader; }
|
||||||
|
void setIsWingman(bool newIsWingman);
|
||||||
|
bool getIsWingman() { return isWingman; }
|
||||||
|
void setLeader(Unit *newLeader) { leader = newLeader; }
|
||||||
|
Unit* getLeader() {return leader;}
|
||||||
|
void setWingmen(vector<Unit *> newWingmen) { wingmen = newWingmen; }
|
||||||
|
vector<Unit*> getWingmen() {return wingmen;}
|
||||||
|
void setFormation(wstring newFormation) { formation = newFormation; }
|
||||||
|
wstring getFormation() { return formation; }
|
||||||
|
void setFormationOffset(Offset formationOffset);
|
||||||
|
Offset getFormationoffset() {return formationOffset;}
|
||||||
|
|
||||||
|
/********** Task data **********/
|
||||||
|
void setCurrentTask(wstring newCurrentTask) { currentTask = newCurrentTask; }
|
||||||
|
wstring getCurrentTask() { return currentTask; }
|
||||||
|
virtual void setTargetSpeed(double newSpeed) { targetSpeed = newSpeed; }
|
||||||
|
virtual double getTargetSpeed() { return targetSpeed; };
|
||||||
|
virtual void setTargetAltitude(double newAltitude) { targetAltitude = newAltitude; }
|
||||||
|
virtual double getTargetAltitude() { return targetAltitude; };
|
||||||
|
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; }
|
||||||
|
Coords getActiveDestination() { return activeDestination; }
|
||||||
|
void setActivePath(list<Coords> newActivePath);
|
||||||
|
list<Coords> getPath() {return activePath}
|
||||||
|
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; }
|
||||||
|
Coords getActiveDestination() { return activeDestination; }
|
||||||
|
void setTarget(int targetID);
|
||||||
|
wstring getTarget();
|
||||||
|
|
||||||
|
/********** Options data **********/
|
||||||
|
void setROE(wstring newROE);
|
||||||
|
wstring getROE() {return ROE;}
|
||||||
|
void setReactionToThreat(wstring newReactionToThreat);
|
||||||
|
wstring getReactionToThreat() {return reactionToThreat;}
|
||||||
|
|
||||||
|
/********** Control functions **********/
|
||||||
|
void landAt(Coords loc);
|
||||||
|
virtual void changeSpeed(wstring change){};
|
||||||
|
virtual void changeAltitude(wstring change){};
|
||||||
|
void resetActiveDestination();
|
||||||
virtual void setState(int newState) { state = newState; };
|
virtual void setState(int newState) { state = newState; };
|
||||||
void resetTask();
|
void resetTask();
|
||||||
|
|
||||||
void setPath(list<Coords> path);
|
/********** Other functions **********/
|
||||||
void setActiveDestination(Coords newActiveDestination) { activeDestination = newActiveDestination; }
|
|
||||||
void setAlive(bool newAlive) { alive = newAlive; }
|
|
||||||
void setTarget(int targetID);
|
|
||||||
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; }
|
|
||||||
void setFormationOffset(Offset formationOffset);
|
|
||||||
void setROE(wstring newROE);
|
|
||||||
void setReactionToThreat(wstring newReactionToThreat);
|
|
||||||
void landAt(Coords loc);
|
|
||||||
void setHasNewData(bool newHasNewData) { hasNewData = newHasNewData; }
|
void setHasNewData(bool newHasNewData) { hasNewData = newHasNewData; }
|
||||||
|
|
||||||
int getID() { return ID; }
|
|
||||||
wstring getName() { return name; }
|
|
||||||
wstring getUnitName() { return unitName; }
|
|
||||||
wstring getGroupName() { return groupName; }
|
|
||||||
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; }
|
|
||||||
double getLongitude() { return longitude; }
|
|
||||||
double getAltitude() { return altitude; }
|
|
||||||
double getHeading() { return heading; }
|
|
||||||
json::value getFlags() { return flags; }
|
|
||||||
Coords getActiveDestination() { return activeDestination; }
|
|
||||||
virtual wstring getCategory() { return L"No category"; };
|
virtual wstring getCategory() { return L"No category"; };
|
||||||
wstring getTarget();
|
bool isTargetAlive();
|
||||||
bool isTargetAlive();
|
|
||||||
wstring getCurrentTask() { return currentTask; }
|
|
||||||
bool getAlive() { return alive; }
|
|
||||||
bool getIsLeader() { return isLeader; }
|
|
||||||
bool getIsWingman() { return isWingman; }
|
|
||||||
wstring getFormation() { return formation; }
|
|
||||||
bool getHasNewData() { return hasNewData; }
|
bool getHasNewData() { return hasNewData; }
|
||||||
|
|
||||||
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:
|
protected:
|
||||||
int ID;
|
int ID;
|
||||||
bool hasNewData = false;
|
|
||||||
int newDataCounter = 0;
|
|
||||||
int state = State::IDLE;
|
|
||||||
bool hasTask = false;
|
|
||||||
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();
|
|
||||||
int targetID = NULL;
|
|
||||||
wstring currentTask = L"";
|
|
||||||
bool isLeader = false;
|
|
||||||
bool isWingman = false;
|
|
||||||
Offset formationOffset = Offset(NULL);
|
|
||||||
wstring formation = L"";
|
|
||||||
Unit* leader = nullptr;
|
|
||||||
wstring ROE = L"";
|
|
||||||
wstring reactionToThreat = L"";
|
|
||||||
vector<Unit*> wingmen;
|
|
||||||
double targetSpeed = 0;
|
|
||||||
double targetAltitude = 0;
|
|
||||||
double fuel = 0;
|
|
||||||
json::value ammo;
|
|
||||||
json::value targets;
|
|
||||||
|
|
||||||
|
/********** Base data **********/
|
||||||
|
bool AI = false;
|
||||||
|
wstring name = L"undefined";
|
||||||
|
wstring unitName = L"undefined";
|
||||||
|
wstring groupName = L"undefined";
|
||||||
|
bool alive = true;
|
||||||
|
json::value type = json::value::null();
|
||||||
|
int country = NULL;
|
||||||
|
|
||||||
|
/********** Flight data **********/
|
||||||
|
double latitude = NULL;
|
||||||
|
double longitude = NULL;
|
||||||
|
double altitude = NULL;
|
||||||
|
double speed = NULL;
|
||||||
|
double heading = NULL;
|
||||||
|
|
||||||
|
/********** Mission data **********/
|
||||||
|
double fuel = 0;
|
||||||
|
json::value ammo = json::value::null();
|
||||||
|
json::value targets = json::value::null();
|
||||||
|
bool hasTask = false;
|
||||||
|
int coalitionID = NULL; // TODO: save coalition directly
|
||||||
|
json::value flags = json::value::null();
|
||||||
|
|
||||||
|
/********** Formation data **********/
|
||||||
|
bool isLeader = false;
|
||||||
|
bool isWingman = false;
|
||||||
|
wstring formation = L"";
|
||||||
|
Unit *leader = nullptr;
|
||||||
|
vector<Unit *> wingmen;
|
||||||
|
Offset formationOffset = Offset(NULL);
|
||||||
|
|
||||||
|
/********** Task data **********/
|
||||||
|
wstring currentTask = L"";
|
||||||
|
double targetSpeed = 0;
|
||||||
|
double targetAltitude = 0;
|
||||||
list<Coords> activePath;
|
list<Coords> activePath;
|
||||||
Coords activeDestination = Coords(0);
|
Coords activeDestination = Coords(0);
|
||||||
|
int targetID = NULL;
|
||||||
|
|
||||||
|
/********** Options data **********/
|
||||||
|
wstring ROE = L"";
|
||||||
|
wstring reactionToThreat = L"";
|
||||||
|
|
||||||
|
/********** State machine **********/
|
||||||
|
int state = State::IDLE;
|
||||||
|
|
||||||
|
/********** Other **********/
|
||||||
Coords oldPosition = Coords(0); // Used to approximate speed
|
Coords oldPosition = Coords(0); // Used to approximate speed
|
||||||
|
bool hasNewData = false;
|
||||||
|
int newDataCounter = 0;
|
||||||
|
|
||||||
list<pair<int, std::function<void(void)>>> schedule;
|
/********** Functions **********/
|
||||||
|
|
||||||
virtual void AIloop() = 0;
|
virtual void AIloop() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void Scheduler::handleRequest(wstring key, json::value value)
|
|||||||
Unit* unit = unitsManager->getUnit(ID);
|
Unit* unit = unitsManager->getUnit(ID);
|
||||||
if (unit != nullptr)
|
if (unit != nullptr)
|
||||||
{
|
{
|
||||||
unit->setPath(newPath);
|
unit->setActivePath(newPath);
|
||||||
unit->setState(State::REACH_DESTINATION);
|
unit->setState(State::REACH_DESTINATION);
|
||||||
log(unitName + L" new path set successfully");
|
log(unitName + L" new path set successfully");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,12 +90,13 @@ json::value Unit::json(bool fullRefresh)
|
|||||||
auto json = json::value::object();
|
auto json = json::value::object();
|
||||||
|
|
||||||
/********** Base data **********/
|
/********** Base data **********/
|
||||||
json[L"AI"] = AI;
|
json[L"baseData"] = json::value::object();
|
||||||
json[L"name"] = json::value::string(name);
|
json[L"baseData"][L"AI"] = AI;
|
||||||
json[L"unitName"] = json::value::string(unitName);
|
json[L"baseData"][L"name"] = json::value::string(name);
|
||||||
json[L"groupName"] = json::value::string(groupName);
|
json[L"baseData"][L"unitName"] = json::value::string(unitName);
|
||||||
json[L"alive"] = alive;
|
json[L"baseData"][L"groupName"] = json::value::string(groupName);
|
||||||
json[L"category"] = json::value::string(getCategory());
|
json[L"baseData"][L"alive"] = alive;
|
||||||
|
json[L"baseData"][L"category"] = json::value::string(getCategory());
|
||||||
|
|
||||||
/********** Flight data **********/
|
/********** Flight data **********/
|
||||||
json[L"flightData"] = json::value::object();
|
json[L"flightData"] = json::value::object();
|
||||||
@@ -162,7 +163,7 @@ json::value Unit::json(bool fullRefresh)
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setPath(list<Coords> path)
|
void Unit::setActivePath(list<Coords> path)
|
||||||
{
|
{
|
||||||
if (state != State::WINGMAN && state != State::FOLLOW)
|
if (state != State::WINGMAN && state != State::FOLLOW)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user