use of main.swing.XLine in project Eidolons by IDemiurge.
the class ClearShotCondition method checkWallObstruction.
private boolean checkWallObstruction(DC_Obj source, DC_Obj target, Coordinates coordinates) {
if (isUnitTestBreakMode()) {
return false;
}
Boolean result = source.getGame().getVisionMaster().getVisionController().getWallObstructionMapper().get(source.getCoordinates(), source.getGame().getCellByCoordinate(target.getCoordinates()));
if (result != null) {
return result;
}
DIRECTION direction = DirectionMaster.getRelativeDirection(source, target);
// target.setBlockingCoordinate(coordinates);
float angle = getAngle(source.getCoordinates(), target.getCoordinates());
for (Coordinates c : coordinates.getAdjacent()) {
// c
DIRECTION relativeDirection = c.isAdjacent(source.getCoordinates()) ? DirectionMaster.getRelativeDirection(c, coordinates) : DirectionMaster.getRelativeDirection(coordinates, c);
if (BooleanMaster.areOpposite(relativeDirection.growX, direction.growX)) {
continue;
}
if (BooleanMaster.areOpposite(relativeDirection.growY, direction.growY)) {
continue;
}
double distance = PositionMaster.getDistanceToLine(new XLine(source.getCoordinates(), target.getCoordinates()), c);
if (distance > 1) {
continue;
}
if (coordinates.equals(target.getCoordinates()) || !target.getCoordinates().isAdjacent(source.getCoordinates(), false)) // && !coordinates.equals(target.getCoordinates())
// && target.getCoordinates().isAdjacent(source.getCoordinates())
{
double d = PositionMaster.getExactDistance(source.getCoordinates(), target.getCoordinates()) - PositionMaster.getExactDistance(c, source.getCoordinates());
if ((d) <= 0.0) {
// must not be beyond target
continue;
}
d = PositionMaster.getExactDistance(source.getCoordinates(), target.getCoordinates()) - PositionMaster.getExactDistance(coordinates, target.getCoordinates());
if ((d) <= 0.0) {
// must not be behind source
continue;
}
}
// DIRECTION d1 = DirectionMaster.getRelativeDirection(source.getCoordinates(), c);
// DIRECTION d2 = DirectionMaster.getRelativeDirection(target.getCoordinates(), c);
boolean left = false;
if (source.getY() != c.y) {
left = (float) Math.abs(source.getX() - c.x) / Math.abs(source.getY() - c.y) < angle;
}
List<DIRECTION> list = source.getGame().getBattleFieldManager().getWallMap().get(c);
if (list == null) {
continue;
}
for (DIRECTION d : list) {
// TODO does direction matter???
if (d != null) {
if (!d.isDiagonal()) {
continue;
}
}
if (left) {
if (BooleanMaster.areOpposite(d.growX, direction.growX)) {
continue;
}
if (!BooleanMaster.areOpposite(d.growY, direction.growY)) {
continue;
}
}
if (!left) {
if (BooleanMaster.areOpposite(d.growY, direction.growY)) {
// TODO does X/Y interchange?
continue;
}
if (!BooleanMaster.areOpposite(d.growX, direction.growX)) {
// TODO does X/Y interchange?
continue;
}
}
if (target.getOBJ_TYPE_ENUM() == DC_TYPE.BF_OBJ) {
if (target.isInfoSelected()) {
LogMaster.log(1, target + " vs " + coordinates + " distance: " + distance);
}
if (target.isInfoSelected()) {
LogMaster.log(1, angle + " vs " + (float) Math.abs(source.getX() - c.x) / Math.abs(source.getX() - c.y));
}
}
wallObstruction = true;
return true;
}
}
return false;
}
use of main.swing.XLine in project Eidolons by IDemiurge.
the class HC_Tree method drawLinks.
protected void drawLinks(Graphics g) {
for (XLine line : linkMap.keySet()) {
g.setColor(linkMap.get(line).getColor());
g.drawLine(line.getX1(), line.getX2(), line.getY1(), line.getY2());
}
}
Aggregations