mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
feat(alarm state): refactor to separe alarm state from radar state. Kown issue: alarm state is not correctly mantained
This commit is contained in:
@@ -48,9 +48,9 @@ namespace ROE {
|
||||
|
||||
namespace ALARM_STATE {
|
||||
enum ALARM_STATEs {
|
||||
AUTO = 0,
|
||||
AUTO = 2,
|
||||
GREEN = 1,
|
||||
RED = 2,
|
||||
RED = 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace DataIndex {
|
||||
category,
|
||||
alive,
|
||||
alarmState,
|
||||
radarState,
|
||||
human,
|
||||
controlled,
|
||||
coalition,
|
||||
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
virtual void setTargetID(unsigned int newValue) { updateValue(targetID, newValue, DataIndex::targetID); }
|
||||
virtual void setTargetPosition(Coords newValue) { updateValue(targetPosition, newValue, DataIndex::targetPosition); }
|
||||
virtual void setROE(unsigned char newValue, bool force = false);
|
||||
virtual void commandAlarmState(unsigned char newValue, bool force = false);
|
||||
virtual void setAlarmState(unsigned char newValue, bool force = false);
|
||||
virtual void setReactionToThreat(unsigned char newValue, bool force = false);
|
||||
virtual void setEmissionsCountermeasures(unsigned char newValue, bool force = false);
|
||||
virtual void setTACAN(DataTypes::TACAN newValue, bool force = false);
|
||||
@@ -126,12 +126,12 @@ public:
|
||||
virtual void setTargetingRange(double newValue) { updateValue(targetingRange, newValue, DataIndex::targetingRange); }
|
||||
virtual void setAimMethodRange(double newValue) { updateValue(aimMethodRange, newValue, DataIndex::aimMethodRange); }
|
||||
virtual void setAcquisitionRange(double newValue) { updateValue(acquisitionRange, newValue, DataIndex::acquisitionRange); }
|
||||
virtual void setAlarmState(string newValue) { updateValue(alarmState, newValue, DataIndex::alarmState); }
|
||||
virtual void setRadarState(bool newValue) { updateValue(radarState, newValue, DataIndex::radarState); }
|
||||
|
||||
/********** Getters **********/
|
||||
virtual string getCategory() { return category; };
|
||||
virtual bool getAlive() { return alive; }
|
||||
virtual string getAlarmState() { return alarmState; }
|
||||
virtual unsigned char getAlarmState() { return alarmState; }
|
||||
virtual bool getHuman() { return human; }
|
||||
virtual bool getControlled() { return controlled; }
|
||||
virtual unsigned char getCoalition() { return coalition; }
|
||||
@@ -190,6 +190,7 @@ public:
|
||||
virtual double getTargetingRange() { return targetingRange; }
|
||||
virtual double getAimMethodRange() { return aimMethodRange; }
|
||||
virtual double getAcquisitionRange() { return acquisitionRange; }
|
||||
virtual bool getRadarState() { return radarState; }
|
||||
|
||||
protected:
|
||||
unsigned int ID;
|
||||
@@ -205,7 +206,8 @@ protected:
|
||||
string callsign = "";
|
||||
string groupName = "";
|
||||
unsigned char state = State::NONE;
|
||||
string alarmState = "";
|
||||
unsigned char alarmState = ALARM_STATE::AUTO;
|
||||
bool radarState = false;
|
||||
string task = "";
|
||||
bool hasTask = false;
|
||||
Coords position = Coords(NULL);
|
||||
|
||||
@@ -609,7 +609,7 @@ string GroundUnit::aimAtPoint(Coords aimTarget) {
|
||||
Geodesic::WGS84().Direct(position.lat, position.lng, bearing1, r, lat, lng);
|
||||
|
||||
taskString = +"Barrel elevation: " + to_string((int) round(barrelElevation)) + "m, bearing: " + to_string((int) round(bearing1)) + "deg";
|
||||
log(unitName + "(" + name + ")" + " shooting with aim at point method. Barrel elevation: " + to_string(barrelElevation) + "m, bearing: " + to_string(bearing1) + "°");
|
||||
log(unitName + "(" + name + ")" + " shooting with aim at point method. Barrel elevation: " + to_string(barrelElevation) + "m, bearing: " + to_string(bearing1) + "<EFBFBD>");
|
||||
|
||||
std::ostringstream taskSS;
|
||||
taskSS.precision(10);
|
||||
|
||||
@@ -406,17 +406,17 @@ void Scheduler::handleRequest(string key, json::value value, string username, js
|
||||
log(username + " set unit " + unit->getUnitName() + "(" + unit->getName() + ") ROE to " + to_string(ROE), true);
|
||||
}
|
||||
}
|
||||
else if (key.compare("commandAlarmState") == 0)
|
||||
else if (key.compare("setAlarmState") == 0)
|
||||
{
|
||||
unsigned int ID = value[L"ID"].as_integer();
|
||||
unitsManager->acquireControl(ID);
|
||||
Unit* unit = unitsManager->getGroupLeader(ID);
|
||||
if (unit != nullptr) {
|
||||
unsigned char alarmState = value[L"alarmState"].as_integer();
|
||||
unit->commandAlarmState(alarmState);
|
||||
unit->setAlarmState(alarmState);
|
||||
log(username + " set unit " + unit->getUnitName() + "(" + unit->getName() + ") alarm state to " + to_string(alarmState), true);
|
||||
} else {
|
||||
log("Error while setting commandAlarmState. Unit does not exist.");
|
||||
log("Error while setting setAlarmState. Unit does not exist.");
|
||||
}
|
||||
}
|
||||
/************************/
|
||||
|
||||
@@ -18,7 +18,7 @@ extern UnitsManager* unitsManager;
|
||||
Unit::Unit(json::value json, unsigned int ID) :
|
||||
ID(ID)
|
||||
{
|
||||
log("Creating unit with ID: " + to_string(ID));
|
||||
// log("Creating unit with ID: " + to_string(ID));
|
||||
}
|
||||
|
||||
Unit::~Unit()
|
||||
@@ -83,8 +83,8 @@ void Unit::update(json::value json, double dt)
|
||||
if (json.has_boolean_field(L"isAlive"))
|
||||
setAlive(json[L"isAlive"].as_bool());
|
||||
|
||||
if (json.has_string_field(L"alarmState")) {
|
||||
setAlarmState(to_string(json[L"alarmState"]));
|
||||
if (json.has_boolean_field(L"radarState")) {
|
||||
setRadarState(json[L"radarState"].as_bool());
|
||||
}
|
||||
|
||||
if (json.has_boolean_field(L"isHuman"))
|
||||
@@ -154,7 +154,7 @@ void Unit::update(json::value json, double dt)
|
||||
|
||||
void Unit::setDefaults(bool force)
|
||||
{
|
||||
|
||||
setAlarmState(ALARM_STATE::AUTO, force);
|
||||
}
|
||||
|
||||
void Unit::runAILoop() {
|
||||
@@ -256,7 +256,8 @@ void Unit::getData(stringstream& ss, unsigned long long time)
|
||||
switch (datumIndex) {
|
||||
case DataIndex::category: appendString(ss, datumIndex, category); break;
|
||||
case DataIndex::alive: appendNumeric(ss, datumIndex, alive); break;
|
||||
case DataIndex::alarmState: appendString(ss, datumIndex, alarmState); break;
|
||||
case DataIndex::alarmState: appendNumeric(ss, datumIndex, alarmState); break;
|
||||
case DataIndex::radarState: appendNumeric(ss, datumIndex, radarState); break;
|
||||
case DataIndex::human: appendNumeric(ss, datumIndex, human); break;
|
||||
case DataIndex::controlled: appendNumeric(ss, datumIndex, controlled); break;
|
||||
case DataIndex::coalition: appendNumeric(ss, datumIndex, coalition); break;
|
||||
@@ -473,7 +474,7 @@ void Unit::setROE(unsigned char newROE, bool force)
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::commandAlarmState(unsigned char newAlarmState, bool force)
|
||||
void Unit::setAlarmState(unsigned char newAlarmState, bool force)
|
||||
{
|
||||
Command* command = dynamic_cast<Command*>(new SetOption(groupName, SetCommandType::ALARM_STATE, static_cast<unsigned int>(newAlarmState)));
|
||||
scheduler->appendCommand(command);
|
||||
|
||||
Reference in New Issue
Block a user