Exemplo n.º 1
0
/**
 * Adds vision to the specified tile in the actor's map
 *
 * @param x - X position of the tile.
 * @param y - Y position of the tile.
 * @param m - The actor's map.
 * @param l - The level the tile is on.
 */
bool vision::addVision(int x, int y, pmap& m, level& l) {
	m.setVisible(x, y, true);
	ncstring t = l.getTile(x, y).toString(true);
	t.setHLight();//set highlight for output
	m.insert(x, y, t);//add to the given map
	return !l.getTile(x, y).isFloor();
}
Exemplo n.º 2
0
/**
 * This is a simple exploring method which clears the old vision mask and adds
 * a new one which is unhindered by terrain.
 *
 * @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::exploreXRay(int x, int y, int sradius, pmap& m, level& l) {
	//Remove previous vision.
	removeVision(x, y, m, l);
	//rudimentary sight radius LoS
	for(int j = y-sradius; (j <= y+sradius); ++j) {
		for(int i = x-sradius; (i <= x+sradius); ++i) {
			if((i>-1)&&(i<m.getX())&&(j>-1)&&(j<m.getY())) {
				if(pow (sradius,2) > (pow (x-abs(i),2) + pow (y-abs(j),2))) {
					m.setVisible(i,j, true);//add vision
					ncstring temp = l.getTile(i,j).toString(true);
					temp.setHLight();//set highlight for output
					m.insert(i,j, temp);//add to the given map
				}
			}
		}
	}
}
Exemplo n.º 3
0
/**
 * 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);

	}
}
Exemplo n.º 4
0
/**
 * 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);
	}
}