From 0d580d2c68fe6ce5192fae2c03f33434c3d96d3f Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Wed, 11 Dec 2024 04:06:52 +0200 Subject: [PATCH] Added check for droid distance when working on structure --- src/droid.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/droid.cpp b/src/droid.cpp index e3e0ed75179..8d49baf58b0 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -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) { @@ -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); @@ -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);