MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / structureUpdate

Function structureUpdate

src/structure.cpp:3776–4015  ·  view source on GitHub ↗

The main update routine for all Structures */

Source from the content-addressed store, hash-verified

3774
3775/* The main update routine for all Structures */
3776void structureUpdate(STRUCTURE *psBuilding, bool bMission)
3777{
3778 UDWORD widthScatter, breadthScatter;
3779 UDWORD emissionInterval, iPointsToAdd, iPointsRequired;
3780 Vector3i dv;
3781 int i;
3782
3783 syncDebugStructure(psBuilding, '<');
3784
3785 if (psBuilding->flags.test(OBJECT_FLAG_DIRTY) && !bMission)
3786 {
3787 visTilesUpdate(psBuilding);
3788 psBuilding->flags.set(OBJECT_FLAG_DIRTY, false);
3789 }
3790
3791 if (psBuilding->pStructureType->type == REF_GATE)
3792 {
3793 if (psBuilding->state == SAS_OPEN && psBuilding->lastStateTime + SAS_STAY_OPEN_TIME < gameTime)
3794 {
3795 bool found = false;
3796
3797 static GridList gridList; // static to avoid allocations.
3798 gridList = gridStartIterate(psBuilding->pos.x, psBuilding->pos.y, TILE_UNITS);
3799 for (GridIterator gi = gridList.begin(); !found && gi != gridList.end(); ++gi)
3800 {
3801 found = isDroid(*gi);
3802 }
3803
3804 if (!found) // no droids on our tile, safe to close
3805 {
3806 psBuilding->state = SAS_CLOSING;
3807 auxStructureClosedGate(psBuilding); // closed
3808 psBuilding->lastStateTime = gameTime; // reset timer
3809 }
3810 }
3811 else if (psBuilding->state == SAS_OPENING && psBuilding->lastStateTime + SAS_OPEN_SPEED < gameTime)
3812 {
3813 psBuilding->state = SAS_OPEN;
3814 auxStructureOpenGate(psBuilding); // opened
3815 psBuilding->lastStateTime = gameTime; // reset timer
3816 }
3817 else if (psBuilding->state == SAS_CLOSING && psBuilding->lastStateTime + SAS_OPEN_SPEED < gameTime)
3818 {
3819 psBuilding->state = SAS_NORMAL;
3820 psBuilding->lastStateTime = gameTime; // reset timer
3821 }
3822 }
3823 else if (psBuilding->pStructureType->type == REF_RESOURCE_EXTRACTOR)
3824 {
3825 if (!psBuilding->pFunctionality->resourceExtractor.psPowerGen
3826 && psBuilding->animationEvent == ANIM_EVENT_ACTIVE) // no power generator connected
3827 {
3828 resetObjectAnimationState(psBuilding);
3829 }
3830 else if (psBuilding->pFunctionality->resourceExtractor.psPowerGen
3831 && psBuilding->animationEvent == ANIM_EVENT_NONE // we have a power generator, but no animation
3832 && psBuilding->sDisplay.imd != nullptr)
3833 {

Callers 1

gameStateUpdateFunction · 0.85

Calls 15

visTilesUpdateFunction · 0.85
isDroidFunction · 0.85
auxStructureClosedGateFunction · 0.85
auxStructureOpenGateFunction · 0.85
aiUpdateStructureFunction · 0.85
structureHasModulesFunction · 0.85
gameTimeAdjustedAverageFunction · 0.85
removeStructFunction · 0.85
canSmokeFunction · 0.85
getStructureDamageFunction · 0.85

Tested by

no test coverage detected