From 17b8b35a433f2bf90c358ae31c1fd0683bc0ec19 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Thu, 30 Nov 2023 13:08:43 +0100 Subject: [PATCH 1/2] Added ATTACK state for ground and navy units --- src/core/include/unit.h | 2 +- src/core/src/groundunit.cpp | 32 ++++++++++++++++++++++++++++++++ src/core/src/navyunit.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/core/include/unit.h b/src/core/include/unit.h index d60f6c36..73d8ca0b 100644 --- a/src/core/include/unit.h +++ b/src/core/include/unit.h @@ -148,7 +148,7 @@ public: virtual DataTypes::Radio getRadio() { return radio; } virtual DataTypes::GeneralSettings getGeneralSettings() { return generalSettings; } virtual vector getAmmo() { return ammo; } - virtual vector getTargets() { return contacts; } + virtual vector getContacts() { return contacts; } virtual list getActivePath() { return activePath; } virtual bool getIsLeader() { return isLeader; } virtual unsigned char getOperateAs() { return operateAs; } diff --git a/src/core/src/groundunit.cpp b/src/core/src/groundunit.cpp index 56ba31d9..8462a5bd 100644 --- a/src/core/src/groundunit.cpp +++ b/src/core/src/groundunit.cpp @@ -68,6 +68,10 @@ void GroundUnit::setState(unsigned char newState) case State::REACH_DESTINATION: { break; } + case State::ATTACK: { + setTargetID(NULL); + break; + } case State::FIRE_AT_AREA: { setTargetPosition(Coords(NULL)); break; @@ -102,6 +106,13 @@ void GroundUnit::setState(unsigned char newState) resetActiveDestination(); break; } + case State::ATTACK: { + setEnableTaskCheckFailed(true); + clearActivePath(); + resetActiveDestination(); + resetTask(); + break; + } case State::FIRE_AT_AREA: { setEnableTaskCheckFailed(true); clearActivePath(); @@ -174,6 +185,27 @@ void GroundUnit::AIloop() } break; } + case State::ATTACK: { + Unit* target = unitsManager->getUnit(getTargetID()); + if (target != nullptr) { + setTask("Attacking " + target->getUnitName()); + + if (!getHasTask()) { + /* Send the command */ + std::ostringstream taskSS; + taskSS.precision(10); + taskSS << "{id = 'AttackUnit', unitID = " << target->getID() << " }"; + Command* command = dynamic_cast(new SetTask(groupName, taskSS.str(), [this]() { this->setHasTaskAssigned(true); })); + scheduler->appendCommand(command); + setHasTask(true); + } + } + else { + setState(State::IDLE); + } + + break; + } case State::FIRE_AT_AREA: { setTask("Firing at area"); diff --git a/src/core/src/navyunit.cpp b/src/core/src/navyunit.cpp index b965d423..a8cc7d87 100644 --- a/src/core/src/navyunit.cpp +++ b/src/core/src/navyunit.cpp @@ -65,6 +65,10 @@ void NavyUnit::setState(unsigned char newState) case State::REACH_DESTINATION: { break; } + case State::ATTACK: { + setTargetID(NULL); + break; + } case State::FIRE_AT_AREA: { setTargetPosition(Coords(NULL)); break; @@ -91,6 +95,13 @@ void NavyUnit::setState(unsigned char newState) resetActiveDestination(); break; } + case State::ATTACK: { + setEnableTaskCheckFailed(true); + clearActivePath(); + resetActiveDestination(); + resetTask(); + break; + } case State::FIRE_AT_AREA: { setEnableTaskCheckFailed(true); clearActivePath(); @@ -148,6 +159,25 @@ void NavyUnit::AIloop() } break; } + case State::ATTACK: { + Unit* target = unitsManager->getUnit(getTargetID()); + if (target != nullptr) { + setTask("Attacking " + target->getUnitName()); + + if (!getHasTask()) { + /* Send the command */ + std::ostringstream taskSS; + taskSS.precision(10); + taskSS << "{id = 'AttackUnit', unitID = " << target->getID() << " }"; + Command* command = dynamic_cast(new SetTask(groupName, taskSS.str(), [this]() { this->setHasTaskAssigned(true); })); + scheduler->appendCommand(command); + setHasTask(true); + } + } + else { + setState(State::IDLE); + } + } case State::FIRE_AT_AREA: { setTask("Firing at area"); From d2fa94a6cb6ec68d4c94e8613cf0a48b15f8dd0f Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Sat, 2 Dec 2023 11:17:30 +0100 Subject: [PATCH 2/2] Minor graphical tweak --- client/public/stylesheets/other/toolbar.css | 11 ++++++++++- client/views/toolbars/primary.ejs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/public/stylesheets/other/toolbar.css b/client/public/stylesheets/other/toolbar.css index 27550908..4754fa83 100644 --- a/client/public/stylesheets/other/toolbar.css +++ b/client/public/stylesheets/other/toolbar.css @@ -55,13 +55,22 @@ padding:0 6px; } +#view-label { + margin-left: 5px; +} + +#view-label svg { + height: 20px; + width: 20px; +} + #toolbar-container>*:nth-child(3)>svg { display: none; } #unit-visibility-control > div:nth-child(3), #coalition-visibility-control { - border-left: 4px solid white; + border-left: 2px solid white; padding-left: 12px; } diff --git a/client/views/toolbars/primary.ejs b/client/views/toolbars/primary.ejs index fc9f7d75..01afc8c7 100644 --- a/client/views/toolbars/primary.ejs +++ b/client/views/toolbars/primary.ejs @@ -46,7 +46,7 @@