Fix completely broken effectStructureUpdates() and remove redundant variable RES_EXTRACTOR::active.

The best part of effectStructureUpdates() was using the same variable i as an inner and outer loop variable, even
though the inner loop didn't actually do anything (except changing i).
master
Cyp 2013-05-27 08:11:19 +02:00
parent 4aeeaa27f6
commit 5810fee2b2
5 changed files with 61 additions and 87 deletions

View File

@ -1504,7 +1504,7 @@ void displayStaticObjects( void )
displayAnimation( psAnimObj, false );
}
/*check the building is active*/
else if (psStructure->pFunctionality->resourceExtractor.active)
else if (psStructure->pFunctionality->resourceExtractor.psPowerGen != nullptr)
{
displayAnimation( psAnimObj, false );
if(selectedPlayer == psStructure->player)

View File

@ -238,7 +238,7 @@ static void effectSetupFire ( EFFECT *psEffect );
static void effectSetupSatLaser ( EFFECT *psEffect );
static void effectSetupFirework ( EFFECT *psEffect );
static void effectStructureUpdates(void);
static void effectStructureUpdates();
static void effectDroidUpdates(void);
static UDWORD effectGetNumFrames(EFFECT *psEffect);
@ -2429,91 +2429,74 @@ static void effectDroidUpdates(void)
/** Runs all the structure effect stuff - steam puffing out etc */
static void effectStructureUpdates(void)
static void effectStructureUpdates()
{
unsigned int i;
unsigned curPartition = frameGetFrameNumber() % EFFECT_STRUCTURE_DIVISION;
// Is it the right time?
if (graphicsTime <= lastUpdateStructures[curPartition] + STRUCTURE_UPDATE_INTERVAL)
{
return;
}
// Store away the last update time.
lastUpdateStructures[curPartition] = graphicsTime;
/* Go thru' all players */
for (i = 0; i < MAX_PLAYERS; i++)
for (unsigned player = 0; player < MAX_PLAYERS; ++player)
{
STRUCTURE *psStructure;
for (psStructure = apsStructLists[i]; psStructure; psStructure = psStructure->psNext)
for (STRUCTURE *psStructure = apsStructLists[player]; psStructure != nullptr; psStructure = psStructure->psNext)
{
/* Find it's group */
// Find its group.
unsigned int partition = psStructure->id % EFFECT_STRUCTURE_DIVISION;
/* Is it the right frame? */
if (partition == frameGetFrameNumber() % EFFECT_STRUCTURE_DIVISION)
if (partition != curPartition)
{
/* Is it the right time? */
if (graphicsTime > lastUpdateStructures[partition] + STRUCTURE_UPDATE_INTERVAL)
continue;
}
if (psStructure->status != SS_BUILT || !psStructure->visible[selectedPlayer])
{
continue;
}
/* Factories puff out smoke, power stations puff out tesla stuff */
switch (psStructure->pStructureType->type)
{
case REF_FACTORY:
case REF_CYBORG_FACTORY:
case REF_VTOL_FACTORY:
/*
We're a factory, so better puff out a bit of steam
Complete hack with the magic numbers - just for IAN demo
*/
if (psStructure->sDisplay.imd->nconnectors == 1)
{
/* Store away the last update time */
lastUpdateStructures[partition] = graphicsTime;
Vector3i eventPos = swapYZ(psStructure->pos) + Vector3i(
psStructure->sDisplay.imd->connectors->x,
psStructure->sDisplay.imd->connectors->z,
-psStructure->sDisplay.imd->connectors->y
);
/* Factories puff out smoke, power stations puff out tesla stuff */
if ( (psStructure->pStructureType->type == REF_FACTORY
|| psStructure->pStructureType->type == REF_POWER_GEN)
&& psStructure->status == SS_BUILT
&& psStructure->visible[selectedPlayer])
{
/*
We're a factory, so better puff out a bit of steam
Complete hack with the magic numbers - just for IAN demo
*/
if (psStructure->pStructureType->type == REF_FACTORY)
{
if (psStructure->sDisplay.imd->nconnectors == 1)
{
Vector3i eventPos = swapYZ(psStructure->pos) + Vector3i(
psStructure->sDisplay.imd->connectors->x,
psStructure->sDisplay.imd->connectors->z,
-psStructure->sDisplay.imd->connectors->y
);
addEffect(&eventPos, EFFECT_SMOKE, SMOKE_TYPE_STEAM, false, NULL, 0);
addEffect(&eventPos, EFFECT_SMOKE, SMOKE_TYPE_STEAM, false, NULL, 0);
if (selectedPlayer == psStructure->player)
{
audio_PlayObjStaticTrack(psStructure, ID_SOUND_STEAM);
}
}
}
else if (psStructure->pStructureType->type == REF_POWER_GEN)
{
POWER_GEN *psPowerGen = &psStructure->pFunctionality->powerGenerator;
Vector3i eventPos = swapYZ(psStructure->pos);
if (psStructure->sDisplay.imd->nconnectors > 0)
{
eventPos.y += psStructure->sDisplay.imd->connectors->z;
}
/* Add an effect over the central spire - if
connected to Res Extractor and it is active*/
for (i = 0; i < NUM_POWER_MODULES; i++)
{
if (psPowerGen->apResExtractors[i]
&& psPowerGen->apResExtractors[i]->pFunctionality->resourceExtractor.active)
{
break;
}
}
{
eventPos.y = psStructure->pos.z + 48;
addEffect(&eventPos, EFFECT_EXPLOSION, EXPLOSION_TYPE_TESLA, false, NULL, 0);
if (selectedPlayer == psStructure->player)
{
audio_PlayObjStaticTrack(psStructure, ID_SOUND_POWER_SPARK);
}
}
}
}
audio_PlayObjStaticTrack(psStructure, ID_SOUND_STEAM);
}
break;
case REF_POWER_GEN:
{
Vector3i eventPos = swapYZ(psStructure->pos);
// Add an effect over the central spire.
eventPos.y = psStructure->pos.z + 48;
addEffect(&eventPos, EFFECT_EXPLOSION, EXPLOSION_TYPE_TESLA, false, NULL, 0);
audio_PlayObjStaticTrack(psStructure, ID_SOUND_POWER_SPARK);
break;
}
default:
break;
}
}
}

View File

@ -238,7 +238,7 @@ static int64_t updateExtractedPower(STRUCTURE *psBuilding)
//only extracts points whilst its active ie associated with a power gen
//and has got some power to extract
if (pResExtractor->active)
if (pResExtractor->psPowerGen != nullptr)
{
// include modifier as a %
extractedPoints = asPower[psBuilding->player].powerModifier * EXTRACT_POINTS * FP_ONE / (100 * GAME_UPDATES_PER_SEC);

View File

@ -1924,7 +1924,6 @@ static bool setFunctionality(STRUCTURE *psBuilding, STRUCTURE_TYPE functionType)
RES_EXTRACTOR* psResExtracter = &psBuilding->pFunctionality->resourceExtractor;
// Make the structure inactive
psResExtracter->active = false;
psResExtracter->psPowerGen = NULL;
break;
}
@ -5170,11 +5169,8 @@ void checkForResExtractors(STRUCTURE *psBuilding)
for (int i = 0; i < NUM_POWER_MODULES; ++i)
{
POWER_GEN *powerGen = &psBuilding->pFunctionality->powerGenerator;
if (powerGen->apResExtractors[i] != nullptr && !powerGen->apResExtractors[i]->died)
if (powerGen->apResExtractors[i] != nullptr)
{
// Make sure the derrrick is active.
RES_EXTRACTOR *resExtractor = &powerGen->apResExtractors[i]->pFunctionality->resourceExtractor;
resExtractor->active = true;
continue; // Slot full.
}
@ -5192,7 +5188,6 @@ void checkForResExtractors(STRUCTURE *psBuilding)
}
// Assign the derrick to the power generator.
powerGen->apResExtractors[i] = derrick;
resExtractor->active = true;
resExtractor->psPowerGen = psBuilding;
++d;
@ -5207,7 +5202,7 @@ void checkForPowerGen(STRUCTURE *psBuilding)
ASSERT_OR_RETURN(, psBuilding->pStructureType->type == REF_RESOURCE_EXTRACTOR, "invalid structure type");
RES_EXTRACTOR *psRE = &psBuilding->pFunctionality->resourceExtractor;
if (psRE->active)
if (psRE->psPowerGen != nullptr)
{
return;
}
@ -5243,7 +5238,6 @@ void checkForPowerGen(STRUCTURE *psBuilding)
POWER_GEN *psPG = &bestPowerGen->pFunctionality->powerGenerator;
psPG->apResExtractors[bestSlot] = psBuilding;
psRE->psPowerGen = bestPowerGen;
psRE->active = true;
}
}
@ -5296,14 +5290,13 @@ void releaseResExtractor(STRUCTURE *psRelease)
informPowerGen(psRelease);
}
psRelease->pFunctionality->resourceExtractor.active = false;
psRelease->pFunctionality->resourceExtractor.psPowerGen = NULL;
//there may be spare resource extractors
for (psCurr = apsExtractorLists[psRelease->player]; psCurr != NULL; psCurr = psCurr->psNextFunc)
{
//check not connected and power left and built!
if (psCurr != psRelease && !psCurr->pFunctionality->resourceExtractor.active && psCurr->status == SS_BUILT)
if (psCurr != psRelease && psCurr->pFunctionality->resourceExtractor.psPowerGen == nullptr && psCurr->status == SS_BUILT)
{
checkForPowerGen(psCurr);
}
@ -5332,7 +5325,6 @@ void releasePowerGen(STRUCTURE *psRelease)
{
if (psPowerGen->apResExtractors[i])
{
psPowerGen->apResExtractors[i]->pFunctionality->resourceExtractor.active = false;
psPowerGen->apResExtractors[i]->pFunctionality->resourceExtractor.psPowerGen = NULL;
psPowerGen->apResExtractors[i] = NULL;
}

View File

@ -194,7 +194,6 @@ struct FACTORY
struct RES_EXTRACTOR
{
bool active; /*indicates when the extractor is on ie digging up oil*/
struct STRUCTURE * psPowerGen; ///< owning power generator
};