Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for droid distance when working on structure #4148

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
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
Loading