diff --git a/backend/core/include/commands.h b/backend/core/include/commands.h index c0e62d8b..9ad67c12 100644 --- a/backend/core/include/commands.h +++ b/backend/core/include/commands.h @@ -46,8 +46,8 @@ namespace ROE { }; } -namespace ALARM_STATE { - enum ALARM_STATEs { +namespace AlarmState { + enum AlarmStates { AUTO = 2, GREEN = 1, RED = 0, diff --git a/backend/core/include/unit.h b/backend/core/include/unit.h index a668efe2..b9476fdc 100644 --- a/backend/core/include/unit.h +++ b/backend/core/include/unit.h @@ -67,6 +67,7 @@ public: /********** Setters **********/ virtual void setCategory(string newValue) { updateValue(category, newValue, DataIndex::category); } virtual void setAlive(bool newValue) { updateValue(alive, newValue, DataIndex::alive); } + virtual void setAlarmState(unsigned char newValue, bool force = false); virtual void setHuman(bool newValue) { updateValue(human, newValue, DataIndex::human); } virtual void setControlled(bool newValue) { updateValue(controlled, newValue, DataIndex::controlled); } virtual void setCoalition(unsigned char newValue) { updateValue(coalition, newValue, DataIndex::coalition); } @@ -98,7 +99,6 @@ 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 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); @@ -206,7 +206,7 @@ protected: string callsign = ""; string groupName = ""; unsigned char state = State::NONE; - unsigned char alarmState = ALARM_STATE::AUTO; + unsigned char alarmState = AlarmState::AUTO; bool radarState = false; string task = ""; bool hasTask = false; diff --git a/backend/core/src/unit.cpp b/backend/core/src/unit.cpp index 5fabd410..0232c8b8 100644 --- a/backend/core/src/unit.cpp +++ b/backend/core/src/unit.cpp @@ -154,7 +154,7 @@ void Unit::update(json::value json, double dt) void Unit::setDefaults(bool force) { - setAlarmState(ALARM_STATE::AUTO, force); + setAlarmState(AlarmState::AUTO, force); } void Unit::runAILoop() { @@ -476,9 +476,13 @@ void Unit::setROE(unsigned char newROE, bool force) void Unit::setAlarmState(unsigned char newAlarmState, bool force) { + if (alarmState != newAlarmState || force) { + alarmState = newAlarmState; Command* command = dynamic_cast(new SetOption(groupName, SetCommandType::ALARM_STATE, static_cast(newAlarmState))); scheduler->appendCommand(command); - triggerUpdate(DataIndex::alarmState); + + triggerUpdate(DataIndex::alarmState); + } } void Unit::setReactionToThreat(unsigned char newReactionToThreat, bool force)