aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/Creature.cpp2
-rw-r--r--src/game/Unit.cpp9
-rw-r--r--src/game/Unit.h2
3 files changed, 9 insertions, 4 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 623b13f9dd2..94aa3c2151c 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1576,7 +1576,7 @@ bool Creature::canStartAttack(Unit const* who) const
|| !IsWithinDistInMap(who, GetAttackDistance(who)))
return false;
- if(!canAttack(who))
+ if(!canAttack(who, false))
return false;
return IsWithinLOSInMap(who);
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 0ff6aacb5ef..571ff991147 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -8557,11 +8557,16 @@ bool Unit::isTargetableForAttack() const
return isAttackableByAOE() && !hasUnitState(UNIT_STAT_DIED);
}
-bool Unit::canAttack(Unit const* target) const
+bool Unit::canAttack(Unit const* target, bool force) const
{
assert(target);
- if(!IsHostileTo(target))
+ if(force)
+ {
+ if(IsFriendlyTo(target))
+ return false;
+ }
+ else if(!IsHostileTo(target))
return false;
if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED))
diff --git a/src/game/Unit.h b/src/game/Unit.h
index a8a60fa5ec9..24122368e61 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -928,7 +928,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool isTargetableForAttack() const;
bool isAttackableByAOE() const;
- bool canAttack(Unit const* target) const;
+ bool canAttack(Unit const* target, bool force = true) const;
virtual bool IsInWater() const;
virtual bool IsUnderWater() const;
bool isInAccessiblePlaceFor(Creature const* c) const;