8 changes: 4 additions & 4 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3651,12 +3651,12 @@ void structureUpdate(STRUCTURE *psBuilding, bool mission)
if (psBuilding->state == SAS_OPEN && psBuilding->lastStateTime + SAS_STAY_OPEN_TIME < gameTime)
{
bool found = false;
BASE_OBJECT *psObj;

gridStartIterate(psBuilding->pos.x, psBuilding->pos.y, TILE_UNITS);
while (!found && (psObj = gridIterate()))
static GridList gridList; // static to avoid allocations.
gridList = gridStartIterate(psBuilding->pos.x, psBuilding->pos.y, TILE_UNITS);
for (GridIterator gi = gridList.begin(); !found && gi != gridList.end(); ++gi)
{
found = (psObj->type == OBJ_DROID);
found = isDroid(*gi);
}

if (!found) // no droids on our tile, safe to close
Expand Down
9 changes: 5 additions & 4 deletions src/visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,18 +538,19 @@ static void processVisibilitySelf(BASE_OBJECT *psObj)
// Calculate which objects we can see. Better to call after processVisibilitySelf, since that check is cheaper.
static void processVisibilityVision(BASE_OBJECT *psViewer)
{
BASE_OBJECT *psObj;

if (psViewer->type == OBJ_FEATURE)
{
return;
}

// get all the objects from the grid the droid is in
// Will give inconsistent results if hasSharedVision is not an equivalence relation.
gridStartIterateUnseen(psViewer->pos.x, psViewer->pos.y, psViewer->sensorRange, psViewer->player);
while (psObj = gridIterate(), psObj != NULL)
static GridList gridList; // static to avoid allocations.
gridList = gridStartIterateUnseen(psViewer->pos.x, psViewer->pos.y, psViewer->sensorRange, psViewer->player);
for (GridIterator gi = gridList.begin(); gi != gridList.end(); ++gi)
{
BASE_OBJECT *psObj = *gi;

int val = visibleObject(psViewer, psObj, false);

// If we've got ranged line of sight...
Expand Down