All pastes #607798 Raw Edit

MarkR

public cpp v1 · immutable
·published 2007-07-07 22:07 UTC
rendered paste body
typedef std::vector<MapPoint> MapPointList;typedef MapPointList::iterator MapPointListIterator;/*  * This is a sort of flood fill. It stops when it reaches walls / doors etc. * * When the player opens a door, the area on all sides of it becomes visible. */void Map::makeTileVisible(int x,int y, int z){        MapPointList points;        MapPointList newpoints;        points.push_back(MapPoint(x+1,y));        points.push_back(MapPoint(x-1,y));        points.push_back(MapPoint(x,y+1));        points.push_back(MapPoint(x,y-1));        while (points.size() > 0) {                for (MapPointListIterator i = points.begin(); i != points.end(); i++) {                        MapPoint point = *i;                        MapBlock & block = blockAt(point.x, point.y, z);                        if (! block.visible) {                                block.visible = true;                                // If it's passable, do the adjacent ones too.                                if (block.wallType == WallTypeNone) {                                        newpoints.push_back(MapPoint(point.x + 1, point.y));                                        newpoints.push_back(MapPoint(point.x - 1, point.y));                                        newpoints.push_back(MapPoint(point.x, point.y + 1));                                        newpoints.push_back(MapPoint(point.x, point.y - 1));                                        // Diagonals.                                        newpoints.push_back(MapPoint(point.x + 1, point.y +1));                                        newpoints.push_back(MapPoint(point.x - 1, point.y -1));                                        newpoints.push_back(MapPoint(point.x + 1, point.y - 1));                                        newpoints.push_back(MapPoint(point.x - 1, point.y + 1));                                }                        }                }                points = newpoints;                newpoints.clear();        }}