diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp
index f52e9c361..73103dad2 100644
--- a/src/unit/unit.cpp
+++ b/src/unit/unit.cpp
@@ -3338,8 +3338,9 @@ global void HitUnit(Unit* attacker,Unit* target,int damage)
     // Only worker types can capture.
     // Still possible to destroy building if not careful (too many attackers)
     if( EnableBuildingCapture && attacker
-	    && type->Building && target->HP<=damage*3 &&
-	    (attacker->Type==UnitTypeOrcWorker
+	    && type->Building && target->HP<=damage*3
+	    && IsEnemy(attacker->Player,target)
+	    && (attacker->Type==UnitTypeOrcWorker
 		|| attacker->Type==UnitTypeHumanWorker) ) {
 	ChangeUnitOwner(target, target->Player, attacker->Player);
 	CommandStopUnit(attacker);	// Attacker shouldn't continue attack!