/** * This is a complex exploring method which clears the old vision mask and adds * a new one. This is very computation heavy. * * @param x,y - Level coordinates. * @param sradius - The sight radius to be used. * @param m - The map object to add tile memory to. * @param l - The level being explored. */ void vision::exploreHeavy(int x, int y, int sradius, pmap& m, level& l) { //Remove previous vision. removeVision(x, y, m, l); bool last_tile_blocked; // set but unused warning //Grab the already present rastercircle or make a new one vision::rastercircle temp = (radiusmask.find(sradius) != radiusmask.end()) ? radiusmask.find(sradius)->second : initRMask(sradius); std::vector<vision::coord> mask = temp.getMask(); std::vector<std::vector<vision::coord> > lines = temp.getLines(); int size = lines.size(); for (int i = 0; i < size; ++i) { double _x = mask[i].x; double _y = mask[i].y; std::vector<vision::coord> line = lines[i]; int j = -1; last_tile_blocked = false; do { j++; int dx = line[j].x; int dy = line[j].y; if( (y+dy>-1) && (y+dy<l.getHeight()) && (x+dx>-1) && (x+dx<l.getWidth()) ) { last_tile_blocked = addVision(x+dx, y+dy, m, l); // Up down left and right optimizations if(_x == 0.0) { addVision(x+dx-1, y+dy, m, l); addVision(x+dx+1, y+dy, m, l); } else if (_y == 0.0) { addVision(x+dx, y+dy-1, m, l); addVision(x+dx, y+dy+1, m, l); } else { last_tile_blocked = !l.getTile(x+dx, y+dy).isFloor(); } } } while(!(line[j].x == _x && line[j].y == _y) && !last_tile_blocked); } }
/** * Recursively removes all vision inherently related to the actor. * * @param x - X position of the actor. * @param y - Y position of the actor. * @param m - The actor's map. * @param l - The level the actor is on. */ void vision::removeVision(int x, int y, pmap& m, level& l) { //Reset your vision if(m.isVisible(x,y)) { //get the tile on the level ncstring temp = l.getTile(x,y).toString(false); //remove output highlighting temp.rmHLight(); //add it to the map m.insert(x,y, temp); //clear the vision m.setVisible(x,y, false); //Recursively add surrounding tiles to the queue. if(x-1 > 0) removeVision(x-1, y, m, l); if(x+1 < l.getWidth()) removeVision(x+1, y, m, l); if(y-1 > 0) removeVision(x, y-1, m, l); if(y+1 < l.getHeight()) removeVision(x, y+1, m, l); } }