Skip to content

Commit

Permalink
Make auto-repair work all the time, not just when droids are stopped.
Browse files Browse the repository at this point in the history
Droids no longer start to retreat and then stop in the middle of the battlefield doing nothing, while getting shot
at.
  • Loading branch information
Cyp committed Sep 24, 2012
1 parent 2402562 commit 8c83693
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 48 deletions.
6 changes: 0 additions & 6 deletions src/action.cpp
Expand Up @@ -868,12 +868,6 @@ void actionUpdateDroid(DROID *psDroid)
}
}
}
// Still not doing anything? See if we need to self repair.
if ((psDroid->action == DACTION_NONE || psDroid->action == DACTION_WAITFORREPAIR)
&& selfRepairEnabled(psDroid->player))
{
droidSelfRepair(psDroid);
}
break;
case DACTION_WAITDURINGREPAIR:
// Check that repair facility still exists
Expand Down
6 changes: 0 additions & 6 deletions src/ai.cpp
Expand Up @@ -1054,12 +1054,6 @@ void aiUpdateDroid(DROID *psDroid)
{
lookForTarget = false;
}
// except when self-repairing
if (psDroid->action == DACTION_DROIDREPAIR &&
psDroid->psActionTarget[0] == (BASE_OBJECT *)psDroid)
{
lookForTarget = true;
}
// don't look for a target if sulking
if (psDroid->action == DACTION_SULK)
{
Expand Down
61 changes: 28 additions & 33 deletions src/droid.cpp
Expand Up @@ -104,9 +104,11 @@ extern DROID_TEMPLATE sDefaultDesignTemplate;
DROID *psLastDroidHit;

//determines the best IMD to draw for the droid - A TEMP MEASURE!
void groupConsoleInformOfSelection( UDWORD groupNumber );
void groupConsoleInformOfCreation( UDWORD groupNumber );
void groupConsoleInformOfCentering( UDWORD groupNumber );
static void groupConsoleInformOfSelection(UDWORD groupNumber);
static void groupConsoleInformOfCreation(UDWORD groupNumber);
static void groupConsoleInformOfCentering(UDWORD groupNumber);

static void droidUpdateDroidSelfRepair(DROID *psRepairDroid);

void cancelBuild(DROID *psDroid)
{
Expand Down Expand Up @@ -826,6 +828,12 @@ void droidUpdate(DROID *psDroid)
}
// -----------------

// See if we can and need to self repair.
if (!isVtolDroid(psDroid) && psDroid->body < psDroid->originalBody && psDroid->asBits[COMP_REPAIRUNIT].nStat != 0 && selfRepairEnabled(psDroid->player))
{
droidUpdateDroidSelfRepair(psDroid);
}

/* Update the fire damage data */
if (psDroid->burnStart != 0 && psDroid->burnStart != gameTime - deltaGameTime) // -deltaGameTime, since projectiles are updated after droids.
{
Expand Down Expand Up @@ -1176,29 +1184,6 @@ bool droidStartDroidRepair( DROID *psDroid )
return true;
}

/*checks a droids current body points to see if need to self repair*/
void droidSelfRepair(DROID *psDroid)
{
CHECK_DROID(psDroid);

if (!isVtolDroid(psDroid))
{
if (psDroid->body < psDroid->originalBody)
{
if (psDroid->asBits[COMP_REPAIRUNIT].nStat != 0)
{
psDroid->action = DACTION_DROIDREPAIR;
setDroidActionTarget(psDroid, (BASE_OBJECT *)psDroid, 0);
psDroid->actionStarted = gameTime;
psDroid->actionPoints = 0;
}
}
}

CHECK_DROID(psDroid);
}


/*Start a EW weapon droid working on a low resistance structure*/
bool droidStartRestore( DROID *psDroid )
{
Expand Down Expand Up @@ -1314,16 +1299,10 @@ bool droidUpdateRepair( DROID *psDroid )
}

/*Updates a Repair Droid working on a damaged droid*/
bool droidUpdateDroidRepair(DROID *psRepairDroid)
static bool droidUpdateDroidRepairBase(DROID *psRepairDroid, DROID *psDroidToRepair)
{
CHECK_DROID(psRepairDroid);

ASSERT_OR_RETURN(false, psRepairDroid->action == DACTION_DROIDREPAIR, "Unit does not have unit repair order");
ASSERT_OR_RETURN(false, psRepairDroid->asBits[COMP_REPAIRUNIT].nStat != 0, "Unit does not have a repair turret");

DROID *psDroidToRepair = (DROID *)psRepairDroid->psActionTarget[0];
ASSERT_OR_RETURN(false, psDroidToRepair->type == OBJ_DROID, "Target is not a unit");

int iRepairRateNumerator = repairPoints(asRepairStats + psRepairDroid->asBits[COMP_REPAIRUNIT].nStat, psRepairDroid->player);
int iRepairRateDenominator = 1;

Expand Down Expand Up @@ -1353,6 +1332,22 @@ bool droidUpdateDroidRepair(DROID *psRepairDroid)
return psDroidToRepair->body < psDroidToRepair->originalBody;
}

bool droidUpdateDroidRepair(DROID *psRepairDroid)
{
ASSERT_OR_RETURN(false, psRepairDroid->action == DACTION_DROIDREPAIR, "Unit does not have unit repair order");
ASSERT_OR_RETURN(false, psRepairDroid->asBits[COMP_REPAIRUNIT].nStat != 0, "Unit does not have a repair turret");

DROID *psDroidToRepair = (DROID *)psRepairDroid->psActionTarget[0];
ASSERT_OR_RETURN(false, psDroidToRepair->type == OBJ_DROID, "Target is not a unit");

return droidUpdateDroidRepairBase(psRepairDroid, psDroidToRepair);
}

static void droidUpdateDroidSelfRepair(DROID *psRepairDroid)
{
droidUpdateDroidRepairBase(psRepairDroid, psRepairDroid);
}

// return whether a droid is IDF
bool idfDroid(DROID *psDroid)
{
Expand Down
3 changes: 0 additions & 3 deletions src/droid.h
Expand Up @@ -157,9 +157,6 @@ extern bool droidStartDroidRepair( DROID *psDroid );
/*Updates a Repair Droid working on a damaged droid - returns true whilst repairing*/
extern bool droidUpdateDroidRepair(DROID *psRepairDroid);

/*checks a droids current body points to see if need to self repair*/
extern void droidSelfRepair(DROID *psDroid);

/* Update a construction droid while it is building
returns true while building continues */
extern bool droidUpdateBuild(DROID *psDroid);
Expand Down

1 comment on commit 8c83693

@dak180
Copy link
Contributor

@dak180 dak180 commented on 8c83693 Sep 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cyp as I answered when you asked on irc there are two reasons why droids only repair when stopped: the story reason and the balance one, which I will enumerate here.

The balance one is of course that they become much harder to kill (I have not done tests to be able to say how much harder though); I would be most worried some especially high HP combos becoming more or less unkillable.

The story explanation is rather simple, since these are military vehicles there is the smallest possible margins for everything, including on-board power budget; this means that any later upgrades need to fit that budget; which in this case means that while they are repairing they cannot move or fire (or in some cases, produce more rounds to reload with), the two other most energy intensive operations they can perform.

All that said, I would not object to a droid still keeping a radar watch and continuing it's retreat when threatened; in fact I think that would cover most, if not all of the issues that people have with the current behavior.

Please sign in to comment.