Skip to content

Commit

Permalink
Added check for droid distance when working on structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich authored and KJeff01 committed Dec 13, 2024
1 parent 2638082 commit 0d580d2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,14 @@ bool droidUpdateBuild(DROID *psDroid)
ASSERT_OR_RETURN(false, psStruct->type == OBJ_STRUCTURE, "target is not a structure");
ASSERT_OR_RETURN(false, psDroid->asBits[COMP_CONSTRUCT] < asConstructStats.size(), "Invalid construct pointer for unit");

// droid distance sanity check
unsigned distanceSq = droidSqDist(psDroid, psStruct);
if (distanceSq > REPAIR_MAXDIST * REPAIR_MAXDIST)
{
psDroid->action = DACTION_NONE;
return false;
}

// First check the structure hasn't been completed by another droid
if (psStruct->status == SS_BUILT)
{
Expand Down Expand Up @@ -1183,6 +1191,14 @@ bool droidUpdateDemolishing(DROID *psDroid)
STRUCTURE *psStruct = (STRUCTURE *)psDroid->order.psObj;
ASSERT_OR_RETURN(false, psStruct->type == OBJ_STRUCTURE, "target is not a structure");

// droid distance sanity check
unsigned distanceSq = droidSqDist(psDroid, psStruct);
if (distanceSq > REPAIR_MAXDIST * REPAIR_MAXDIST)
{
psDroid->action = DACTION_NONE;
return false;
}

int constructRate = 5 * constructorPoints(*psDroid->getConstructStats(), psDroid->player);
int pointsToAdd = gameTimeAdjustedAverage(constructRate);

Expand Down Expand Up @@ -1217,6 +1233,14 @@ bool droidUpdateRestore(DROID *psDroid)

ASSERT_OR_RETURN(false, psStats->weaponSubClass == WSC_ELECTRONIC, "unit's weapon is not EW");

// droid distance sanity check
unsigned distanceSq = droidSqDist(psDroid, psStruct);
if (distanceSq > REPAIR_MAXDIST * REPAIR_MAXDIST)
{
psDroid->action = DACTION_NONE;
return false;
}

unsigned restorePoints = calcDamage(weaponDamage(*psStats, psDroid->player),
psStats->weaponEffect, (BASE_OBJECT *)psStruct);

Expand Down

0 comments on commit 0d580d2

Please sign in to comment.