package dev.llan.model.board.generation;
import dev.llan.model.board.Point;
import dev.llan.model.board.Tile;
import dev.llan.model.board.Tile.TileType;
import java.util.ArrayList;
import java.util.List;
import static dev.llan.model.board.generation.Constants.BASE_CLEARANCE_RADIUS;
import static dev.llan.model.board.generation.Constants.CLEARANCE_MULTIPLIER;
public class Room {
public enum RoomType {
START,
END,
ENEMY
}
private int rowRadius;
private int colRadius;
private Point center;
private RoomType type;
private double clearanceRadius;
public Room(int rowRadius, int colRadius, Point position) {
this.rowRadius = rowRadius;
this.colRadius = colRadius;
this.center = position;
clearanceRadius = calculateRadius();
type = RoomType.ENEMY;
}
public void setType(RoomType type) {
this.type = type;
}
public RoomType getType() {
return type;
}
public Point getCenter() {
return center;
}
private double calculateRadius() {
double diagonal = Math.sqrt(rowRadius * rowRadius + colRadius * colRadius) * CLEARANCE_MULTIPLIER;
return diagonal / 2 + BASE_CLEARANCE_RADIUS;
}
public void removePointsWithinRadius(List<Point> points) {
points.removeIf(point -> Point.getDistance(point, center) <= clearanceRadius);
}
public void placeTiles(Tile[][] map) {
for (int row = -rowRadius; row <= rowRadius; row++) {
for (int col = -colRadius; col <= colRadius; col++) {
int mapRow = center.getRow() + row;
int mapCol = center.getCol() + col;
if (Math.abs(row) == rowRadius || Math.abs(col) == colRadius) {
map[mapRow][mapCol] = new Tile(new Point(mapRow, mapCol), TileType.UNMOVABLE);
} else {
map[mapRow][mapCol] = new Tile(new Point(mapRow, mapCol), TileType.VACANT);
}
}
}
}
public List<DirectedPoint> getConnectionPoints() {
List<DirectedPoint> connectionPoints = new ArrayList<>();
connectionPoints.add(new DirectedPoint(center.translate(-rowRadius, 0), Direction.UP));
connectionPoints.add(new DirectedPoint(center.translate(rowRadius, 0), Direction.DOWN));
connectionPoints.add(new DirectedPoint(center.translate(0, -colRadius), Direction.LEFT));
connectionPoints.add(new DirectedPoint(center.translate(0, colRadius), Direction.RIGHT));
return connectionPoints;
}
}