Ejemplo n.º 1
0
Vector2d findBestPositionToAttack(const model::World& w, const model::Trooper& trooper, const model::Trooper& enemy){
	Vector2d res(-1,-1);
	PathFinder pf;
	int bestDist = 1 << 20;
	const std::vector<std::vector<model::CellType> >& cells = w.getCells();
	for (int i = 0; i < w.getWidth(); i++){
		for (int j = 0; j < w.getHeight(); j++){
//			if (enemy.getDistanceTo(i,j) > 8 || cells[i][j] != model::FREE || PathFinder::isTropperInCell(w,Vector2d(i,j))) //dist to check. Too much???
			if (trooper.getDistanceTo(i,j) > 5 || cells[i][j] != model::FREE || PathFinder::isTropperInCell(w,Vector2d(i,j))) //dist to check. Too much???
				continue;
			
			if (!w.isVisible(trooper.getShootingRange(), i, j, model::STANDING, enemy.getX(), enemy.getY(), enemy.getStance()))
				continue;

			std::list<Vector2d> path = pf.calcOptimalPath(w, Vector2d(trooper.getX(), trooper.getY()), Vector2d(i, j));
			
			if(path.empty())
				continue;

			std::list<Vector2d> pathWithoutPlayers = pf.calcOptimalPath(w, Vector2d(trooper.getX(), trooper.getY()), Vector2d(i, j), true);

			if (pathWithoutPlayers.size() + 3 < path.size())
				continue;

			int dist = path.size();
			if (dist < bestDist){
				bestDist = dist;
				res = Vector2d(i,j);
			}
		}
	}

	return res;
}
Ejemplo n.º 2
0
Vector2d processApproximate(const model::World& w, const Vector2d& appr){
	Vector2d res;
	const std::vector<std::vector<model::CellType> >& cells = w.getCells();
	float min = 1 << 20;
	for (int i = 0; i < w.getWidth(); i++)
	for (int j = 0; j < w.getHeight(); j++){
		float d = dist(appr, Vector2d(i, j));
		if (cells[i][j] == model::FREE && min > d){
			min = d;
			res = Vector2d (i, j);
		}
	}
	return res;
}
Ejemplo n.º 3
0
Map::Map(const model::Game& game, const model::World& world)
	: m_tiles(world.getTilesXY())
	, m_game(&game)
	, m_world(&world)

	, m_tileSize((int)m_game->getTrackTileSize())
	, m_tileCenter((int)m_game->getTrackTileSize() / 2, (int)m_game->getTrackTileSize() / 2)
	, m_worldWidthTiles(world.getWidth())
	, m_worldHeightTiles(world.getHeight())
{

	m_tileNodes.resize(m_worldWidthTiles * m_worldHeightTiles);
	updateNodes();
}
Ejemplo n.º 4
0
std::vector<Vector2d> getDstsWithDir(const model::World& w, const Vector2d susanin_v, const Vector2d dir){
	std::vector<Vector2d> res;
	const std::vector<std::vector<model::CellType> >& cells = w.getCells();
	for (int i = 0; i < w.getWidth(); i++)
	for (int j = 0; j < w.getHeight(); j++){
		float d = dist(susanin_v, Vector2d(i, j));

		if (d > kMinDist && d < kMaxDist &&
			cells[i][j] == model::FREE &&
			!PathFinder::isTropperInCell(w, Vector2d(i, j)) &&
			isFeetDirection(susanin_v, i, j, dir))
			res.push_back(Vector2d(i, j));
	}
	return res;
}