mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
feat(alarm state): alarm state command is now working in DCS
This commit is contained in:
@@ -18,6 +18,7 @@ namespace SetCommandType {
|
||||
FORMATION = 5,
|
||||
RTB_ON_BINGO = 6,
|
||||
SILENCE = 7,
|
||||
ALARM_STATE = 9,
|
||||
RTB_ON_OUT_OF_AMMO = 10,
|
||||
ECM_USING = 13,
|
||||
PROHIBIT_AA = 14,
|
||||
@@ -45,6 +46,14 @@ namespace ROE {
|
||||
};
|
||||
}
|
||||
|
||||
namespace ALARM_STATE {
|
||||
enum ALARM_STATEs {
|
||||
AUTO = 0,
|
||||
GREEN = 1,
|
||||
RED = 2,
|
||||
};
|
||||
}
|
||||
|
||||
namespace ReactionToThreat {
|
||||
enum ReactionsToThreat {
|
||||
NO_REACTION = 0,
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace DataIndex {
|
||||
startOfData = 0,
|
||||
category,
|
||||
alive,
|
||||
radarState,
|
||||
alarmState,
|
||||
human,
|
||||
controlled,
|
||||
coalition,
|
||||
|
||||
@@ -96,6 +96,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 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);
|
||||
@@ -112,12 +113,12 @@ public:
|
||||
virtual void setRacetrackLength(double newValue) { updateValue(racetrackLength, newValue, DataIndex::racetrackLength); }
|
||||
virtual void setRacetrackAnchor(Coords newValue) { updateValue(racetrackAnchor, newValue, DataIndex::racetrackAnchor); }
|
||||
virtual void setRacetrackBearing(double newValue) { updateValue(racetrackBearing, newValue, DataIndex::racetrackBearing); }
|
||||
virtual void setRadarState(string newValue) { updateValue(radarState, newValue, DataIndex::radarState); }
|
||||
virtual void setAlarmState(string newValue) { updateValue(alarmState, newValue, DataIndex::alarmState); }
|
||||
|
||||
/********** Getters **********/
|
||||
virtual string getCategory() { return category; };
|
||||
virtual bool getAlive() { return alive; }
|
||||
virtual string getRadarState() { return radarState; }
|
||||
virtual string getAlarmState() { return alarmState; }
|
||||
virtual bool getHuman() { return human; }
|
||||
virtual bool getControlled() { return controlled; }
|
||||
virtual unsigned char getCoalition() { return coalition; }
|
||||
@@ -180,7 +181,7 @@ protected:
|
||||
string callsign = "";
|
||||
string groupName = "";
|
||||
unsigned char state = State::NONE;
|
||||
string radarState = "";
|
||||
string alarmState = "";
|
||||
string task = "";
|
||||
bool hasTask = false;
|
||||
Coords position = Coords(NULL);
|
||||
|
||||
@@ -114,6 +114,19 @@ json::value Scheduler::getCommandModeOptions() {
|
||||
return json;
|
||||
}
|
||||
|
||||
/* Convert from string to alarm state enum value */
|
||||
ALARM_STATE::ALARM_STATEs stringToAlarmState(const std::wstring& state) {
|
||||
if (state == L"red") {
|
||||
return ALARM_STATE::RED;
|
||||
} else if (state == L"green") {
|
||||
return ALARM_STATE::GREEN;
|
||||
} else if (state == L"auto") {
|
||||
return ALARM_STATE::AUTO;
|
||||
} else {
|
||||
throw invalid_argument("Stato non valido: " + std::string(state.begin(), state.end()));
|
||||
}
|
||||
}
|
||||
|
||||
bool Scheduler::checkSpawnPoints(int spawnPoints, string coalition)
|
||||
{
|
||||
if (!getRestrictSpawns()) return true;
|
||||
@@ -402,6 +415,20 @@ 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)
|
||||
{
|
||||
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();
|
||||
log(username + " is trying to set unit " + unit->getUnitName() + "(" + unit->getName() + ") alarm state to " + to_string(alarmState), true);
|
||||
unit->commandAlarmState(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.");
|
||||
}
|
||||
}
|
||||
/************************/
|
||||
else if (key.compare("setReactionToThreat") == 0)
|
||||
{
|
||||
|
||||
@@ -83,9 +83,9 @@ 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"radarState")) {
|
||||
log("Unit " + to_string(json[L"unitName"]) + " has radarState: " + to_string(json[L"radarState"]));
|
||||
setRadarState(to_string(json[L"radarState"]));
|
||||
if (json.has_string_field(L"alarmState")) {
|
||||
// log("Unit " + to_string(json[L"unitName"]) + " has alarmState: " + to_string(json[L"alarmState"]));
|
||||
setAlarmState(to_string(json[L"alarmState"]));
|
||||
}
|
||||
|
||||
if (json.has_boolean_field(L"isHuman"))
|
||||
@@ -213,7 +213,7 @@ void Unit::refreshLeaderData(unsigned long long time) {
|
||||
case DataIndex::operateAs: updateValue(operateAs, leader->operateAs, datumIndex); break;
|
||||
case DataIndex::shotsScatter: updateValue(shotsScatter, leader->shotsScatter, datumIndex); break;
|
||||
case DataIndex::shotsIntensity: updateValue(shotsIntensity, leader->shotsIntensity, datumIndex); break;
|
||||
case DataIndex::radarState: updateValue(radarState, leader->radarState, datumIndex); break;
|
||||
case DataIndex::alarmState: updateValue(alarmState, leader->alarmState, datumIndex); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ 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::radarState: appendString(ss, datumIndex, radarState); break;
|
||||
case DataIndex::alarmState: appendString(ss, datumIndex, alarmState); 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;
|
||||
@@ -463,6 +463,13 @@ void Unit::setROE(unsigned char newROE, bool force)
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::commandAlarmState(unsigned char newAlarmState, bool force)
|
||||
{
|
||||
Command* command = dynamic_cast<Command*>(new SetOption(groupName, SetCommandType::ALARM_STATE, static_cast<unsigned int>(newAlarmState)));
|
||||
scheduler->appendCommand(command);
|
||||
triggerUpdate(DataIndex::alarmState);
|
||||
}
|
||||
|
||||
void Unit::setReactionToThreat(unsigned char newReactionToThreat, bool force)
|
||||
{
|
||||
if (reactionToThreat != newReactionToThreat || force) {
|
||||
|
||||
Reference in New Issue
Block a user