diff --git a/rts/Sim/Units/CommandAI/BuilderCAI.cpp b/rts/Sim/Units/CommandAI/BuilderCAI.cpp index cfc1574cb60..42cdcd8254f 100644 --- a/rts/Sim/Units/CommandAI/BuilderCAI.cpp +++ b/rts/Sim/Units/CommandAI/BuilderCAI.cpp @@ -1639,8 +1639,13 @@ bool CBuilderCAI::FindRepairTargetAndRepair( bool stationary = false; for (const CUnit* unit: *qfQuery.units) { + if (teamHandler.Ally(owner->allyteam, unit->allyteam)) { if (!haveEnemy && (unit->health < unit->maxHealth)) { + // Don't auto pick for repair or build if within 900 frames of last reclaim + if (!unit->AllowUnitAutoRepair()) + continue; + // don't help allies build unless set on roam if (unit->beingBuilt && owner->team != unit->team && (owner->moveState != MOVESTATE_ROAM)) continue; diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 5728e5730b0..e1e93865bfe 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -1973,6 +1973,25 @@ void CUnit::TurnIntoNanoframe() eventHandler.UnitReverseBuilt(this); } +bool CUnit::AllowUnitAutoRepair() +const { + if (this->lastOwnerReclaim == 0) return true; + + if ((gs->frameNum) >= (this->lastOwnerReclaim + 900)) + { + return true; + } + else + { + if ((this->lastOwnerReclaim) <= (this->lastOwnerBuildRepair)) + { + return true; + } + } + return false; +} + + bool CUnit::AddBuildPower(CUnit* builder, float amount) { RECOIL_DETAILED_TRACY_ZONE; @@ -1981,10 +2000,14 @@ bool CUnit::AddBuildPower(CUnit* builder, float amount) // stop decaying on building AND reclaim lastNanoAdd = gs->frameNum; - + CTeam* builderTeam = teamHandler.Team(builder->team); if (amount >= 0.0f) { + // Register attempt to build/repair by owner + if ((builder->team)==(this->team)) + lastOwnerBuildRepair = gs->frameNum; + // build or repair if (!beingBuilt && (health >= maxHealth)) return false; @@ -2012,7 +2035,6 @@ bool CUnit::AddBuildPower(CUnit* builder, float amount) if (buildProgress >= 1.0f) FinishedBuilding(false); } - return true; } else if (health < maxHealth) { @@ -2042,6 +2064,8 @@ bool CUnit::AddBuildPower(CUnit* builder, float amount) } } else { // reclaim + if ((builder->team)==(this->team)) + lastOwnerReclaim = gs->frameNum; if (!AllowedReclaim(builder)) { builder->DependentDied(this); return false; diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index ea36dd60b3c..c2c3b58ff09 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -105,6 +105,9 @@ class CUnit : public CSolidObject // negative amount=reclaim, return= true -> build power was successfully applied bool AddBuildPower(CUnit* builder, float amount); + + // FindRepairTarget/FindRepairTargetAndRepair functions will ignore units that return false here + bool AllowUnitAutoRepair() const; virtual void Activate(); virtual void Deactivate(); @@ -370,6 +373,8 @@ class CUnit : public CSolidObject // if we arent built on for a while start decaying int lastNanoAdd = 0; + int lastOwnerReclaim = 0; + int lastOwnerBuildRepair = 0; int lastFlareDrop = 0; // id of transport that the unit is about to be {un}loaded by