Merge pull request #615 from Pax1601/602-attack-mode-not-working-on-ground-and-navy-units

Added ATTACK state for ground and navy units
This commit is contained in:
Pax1601 2023-12-02 11:19:05 +01:00 committed by GitHub
commit 0b8f48b4fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 3 deletions

View File

@ -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;
}

View File

@ -46,7 +46,7 @@
</div>
</nav>
<nav class="ol-panel" oncontextmenu="return false;">
<div class="ol-panel-tab">
<div id="view-label" class="ol-panel-tab">
<img src="resources/theme/images/icons/eye-solid.svg" inject-svg />
<span>View</span>
</div>

View File

@ -148,7 +148,7 @@ public:
virtual DataTypes::Radio getRadio() { return radio; }
virtual DataTypes::GeneralSettings getGeneralSettings() { return generalSettings; }
virtual vector<DataTypes::Ammo> getAmmo() { return ammo; }
virtual vector<DataTypes::Contact> getTargets() { return contacts; }
virtual vector<DataTypes::Contact> getContacts() { return contacts; }
virtual list<Coords> getActivePath() { return activePath; }
virtual bool getIsLeader() { return isLeader; }
virtual unsigned char getOperateAs() { return operateAs; }

View File

@ -62,6 +62,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;
@ -96,6 +100,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();
@ -168,6 +179,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<Command*>(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");

View File

@ -59,6 +59,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;
@ -85,6 +89,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();
@ -142,6 +153,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<Command*>(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");