Skip to content

Commit

Permalink
Cleanup: Remove unused mendVtol() function and fix excess indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed Jun 21, 2012
1 parent e1dcb24 commit adc13fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 65 deletions.
24 changes: 0 additions & 24 deletions src/droid.cpp
Expand Up @@ -3208,30 +3208,6 @@ void updateVtolAttackRun(DROID *psDroid , int weapon_slot)
}
}

/*this mends the VTOL when it has been returned to home base whilst on an
offworld mission*/
void mendVtol(DROID *psDroid)
{
UBYTE i;
ASSERT_OR_RETURN( , vtolEmpty(psDroid), "droid is not an empty weapon VTOL!");

CHECK_DROID(psDroid);

/* set rearm value to no runs made */
for (i = 0;i < psDroid->numWeaps;i++)
{
psDroid->sMove.iAttackRuns[i] = 0;
//reset ammo and lastTimeFired
psDroid->asWeaps[i].ammo = asWeaponStats[psDroid->
asWeaps[i].nStat].numRounds;
psDroid->asWeaps[i].lastFired = 0;
}
/* set droid points to max */
psDroid->body = psDroid->originalBody;

CHECK_DROID(psDroid);
}

//assign rearmPad to the VTOL
void assignVTOLPad(DROID *psNewDroid, STRUCTURE *psReArmPad)
{
Expand Down
3 changes: 0 additions & 3 deletions src/droid.h
Expand Up @@ -286,9 +286,6 @@ extern bool vtolFull(DROID *psDroid);
/*Checks a vtol for being fully armed and fully repaired to see if ready to
leave reArm pad */
extern bool vtolHappy(const DROID* psDroid);
/*this mends the VTOL when it has been returned to home base whilst on an
offworld mission*/
extern void mendVtol(DROID *psDroid);
/*checks if the droid is a VTOL droid and updates the attack runs as required*/
extern void updateVtolAttackRun(DROID *psDroid, int weapon_slot);
/*returns a count of the base number of attack runs for the weapon attached to the droid*/
Expand Down
74 changes: 36 additions & 38 deletions src/structure.cpp
Expand Up @@ -3424,51 +3424,49 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psReArmPad->timeLastUpdated = gameTime;
}

/* do rearming */
UDWORD pointsRequired;

//amount required is a factor of the droids' weight
pointsRequired = psDroid->weight / REARM_FACTOR;
//take numWeaps into consideration
pointsToAdd = psReArmPad->reArmPoints * (gameTime - psReArmPad->timeStarted) /
GAME_TICKS_PER_SEC;
pointsAlreadyAdded = psReArmPad->reArmPoints * (psReArmPad->timeLastUpdated - psReArmPad->timeStarted) /
GAME_TICKS_PER_SEC;
if (pointsToAdd >= pointsRequired)
/* do rearming */
UDWORD pointsRequired;

//amount required is a factor of the droids' weight
pointsRequired = psDroid->weight / REARM_FACTOR;
//take numWeaps into consideration
pointsToAdd = psReArmPad->reArmPoints * (gameTime - psReArmPad->timeStarted) / GAME_TICKS_PER_SEC;
pointsAlreadyAdded = psReArmPad->reArmPoints * (psReArmPad->timeLastUpdated - psReArmPad->timeStarted) / GAME_TICKS_PER_SEC;
if (pointsToAdd >= pointsRequired)
{
// We should be fully loaded by now.
for (i = 0; i < psDroid->numWeaps; i++)
{
// set rearm value to no runs made
psDroid->asWeaps[i].usedAmmo = 0;
// reset ammo and lastFired
psDroid->asWeaps[i].ammo = asWeaponStats[psDroid->asWeaps[i].nStat].numRounds;
psDroid->asWeaps[i].lastFired = 0;
}
}
else
{
for (i = 0; i < psDroid->numWeaps; i++)
{
// Make sure it's a rearmable weapon (and so we don't divide by zero)
if (psDroid->asWeaps[i].usedAmmo > 0 && asWeaponStats[psDroid->asWeaps[i].nStat].numRounds > 0)
{
// We should be fully loaded by now.
for (i = 0; i < psDroid->numWeaps; i++)
// Do not "simplify" this formula.
// It is written this way to prevent rounding errors.
int ammoToAddThisTime =
pointsToAdd*getNumAttackRuns(psDroid,i)/pointsRequired -
pointsAlreadyAdded*getNumAttackRuns(psDroid,i)/pointsRequired;
psDroid->asWeaps[i].usedAmmo -= std::min<unsigned>(ammoToAddThisTime, psDroid->asWeaps[i].usedAmmo);
if (ammoToAddThisTime)
{
// set rearm value to no runs made
psDroid->asWeaps[i].usedAmmo = 0;
// reset ammo and lastFired
psDroid->asWeaps[i].ammo = asWeaponStats[psDroid->asWeaps[i].nStat].numRounds;
psDroid->asWeaps[i].lastFired = 0;
break;
}
}
else
{
for (i = 0; i < psDroid->numWeaps; i++)
{
// Make sure it's a rearmable weapon (and so we don't divide by zero)
if (psDroid->asWeaps[i].usedAmmo > 0 && asWeaponStats[psDroid->asWeaps[i].nStat].numRounds > 0)
{
// Do not "simplify" this formula.
// It is written this way to prevent rounding errors.
int ammoToAddThisTime =
pointsToAdd*getNumAttackRuns(psDroid,i)/pointsRequired -
pointsAlreadyAdded*getNumAttackRuns(psDroid,i)/pointsRequired;
psDroid->asWeaps[i].usedAmmo -= std::min<unsigned>(ammoToAddThisTime, psDroid->asWeaps[i].usedAmmo);
if (ammoToAddThisTime)
{
// reset ammo and lastFired
psDroid->asWeaps[i].ammo = asWeaponStats[psDroid->asWeaps[i].nStat].numRounds;
psDroid->asWeaps[i].lastFired = 0;
break;
}
}
}
}
}
}
/* do repairing */
if (psDroid->body < psDroid->originalBody)
{
Expand Down

0 comments on commit adc13fe

Please sign in to comment.