Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rts/Sim/Units/CommandAI/BuilderCAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 26 additions & 2 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -2012,7 +2035,6 @@ bool CUnit::AddBuildPower(CUnit* builder, float amount)
if (buildProgress >= 1.0f)
FinishedBuilding(false);
}

return true;
}
else if (health < maxHealth) {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down