Skip to content

Commit

Permalink
Ignore right-click attack commands if AttackClass doesn't match
Browse files Browse the repository at this point in the history
When right clicking without attack mode selected the
COMMAND_ID_OBJECT is created and AttackClass isn't
checked which can cause Squad to get stuck with the
order that can't fire at due to target UnitClass

This makes check the AttackClass and UnitClass of target
upon receiving the COMMAND_ID_OBJECT
  • Loading branch information
IonAgorria committed Apr 27, 2024
1 parent 1fabdb3 commit cb611bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
43 changes: 29 additions & 14 deletions Source/Units/Squad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,42 @@ void terUnitSquad::executeCommand(const UnitCommand& command)
terUnitBase::executeCommand(command);

switch(command.commandID()){
case COMMAND_ID_OBJECT:
if ((command.selectionMode() & COMMAND_SELECTED_MODE_NEGATIVE) == 0) {
case COMMAND_ID_OBJECT: {
if ((command.selectionMode() & COMMAND_SELECTED_MODE_NEGATIVE) == 0) {
clearOrders();
}
if(command.unit()) {
if (isEnemy(command.unit())) {
addTarget(command.unit());
if ((command.selectionMode() & COMMAND_SELECTED_MODE_NEGATIVE) == 0) {
soundEvent(SOUND_VOICE_SQUAD_ATTACKS);
terUnitBase* pUnit = command.unit();
if (pUnit) {
int attackClass = UNIT_CLASS_IGNORE;
if (!Empty()) {
if (!isBase()) {
attackClass = pUnit->Player->unitAttribute(currentMutation_)->AttackClass;
} else {
attackClass = attackEnemyClass();
}
}
if (isEnemy(pUnit)) {
if (pUnit->unitClass() & attackClass) {
addTarget(pUnit);
if ((command.selectionMode() & COMMAND_SELECTED_MODE_NEGATIVE) == 0) {
soundEvent(SOUND_VOICE_SQUAD_ATTACKS);
}
}
} else {
if (dynamic_cast<terUnitLegionary*>(command.unit())) {
setSquadToFollow(command.unit());
} else if(command.unit()->Player->isWorld()) {
addTarget(command.unit());
} else {
if (dynamic_cast<terUnitLegionary*>(pUnit)) {
setSquadToFollow(pUnit);
} else if (pUnit->Player->isWorld()) {
if (pUnit->unitClass() & attackClass) {
addTarget(pUnit);
}
} else {
addWayPoint(command.unit()->position(), command.selectionMode() & COMMAND_SELECTED_MODE_OVERRIDE);
bool bypassPathfinder = command.selectionMode() & COMMAND_SELECTED_MODE_OVERRIDE;
addWayPoint(pUnit->position(), bypassPathfinder);
}
}
}
break;
break;
}

case COMMAND_ID_PATROL:
if (patrolPoints_.empty() || (patrolIndex_ == 1 && patrolPoints_.empty())) {
Expand Down
19 changes: 12 additions & 7 deletions Source/Units/WarBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ void terBuildingMilitary::executeCommand(const UnitCommand& command)

switch(command.commandID()){
case COMMAND_ID_POINT:
setAttackTarget(NULL,true);
setAttackTarget(nullptr, true);
xassert(!wayPoints().empty());
break;
case COMMAND_ID_OBJECT:
if(!command.unit() || command.unit()->Player->clan() != Player->clan())
setAttackTarget(safe_cast<terUnitReal*>(command.unit()),true);
break;
case COMMAND_ID_STOP:
setAttackTarget(NULL,true);
case COMMAND_ID_OBJECT: {
terUnitReal* pUnit = dynamic_cast<terUnitReal*>(command.unit());
if (pUnit && isEnemy(pUnit) && pUnit->unitClass() & attr()->AttackClass) {
setAttackTarget(pUnit, true);
} else {
setAttackTarget(nullptr, true);
}
break;
}
case COMMAND_ID_STOP:
setAttackTarget(nullptr, true);
break;
default:
break;
Expand Down

0 comments on commit cb611bb

Please sign in to comment.