use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class ClearShotCondition method check.
@Override
public boolean check(Ref ref) {
Obj obj = game.getObjectById(ref.getId(str2));
if (!(obj instanceof DC_Obj)) {
return false;
}
DC_Obj target = (DC_Obj) game.getObjectById(ref.getId(str2));
if (target == null) {
return false;
}
Coordinates c2 = target.getCoordinates();
if (c2 == null)
return false;
BattleFieldObject source = (BattleFieldObject) game.getObjectById(ref.getId(str1));
if (source == null)
return false;
if (c2.equals(source.getCoordinates()))
return true;
if (target.isOverlaying()) {
if (target instanceof BattleFieldObject) {
DIRECTION d = ((BattleFieldObject) target).getDirection();
DIRECTION d1 = DirectionMaster.getRelativeDirection(target, source);
if (d != null) {
if (d1 != d) {
if (Math.abs(d.getDegrees() - d1.getDegrees()) > 90)
return false;
}
}
}
}
wallObstruction = false;
Coordinates c1 = source.getCoordinates();
boolean toCheck = true;
boolean result = true;
if (PositionMaster.inLine(c1, c2)) {
result = PositionMaster.noObstaclesInLine(source, target, game.getBattleField().getGrid());
toCheck = false;
if (!result)
return cacheResult(source, target, result);
} else {
// TODO TRANSPARENT FOR VISION!
if (PositionMaster.inLineDiagonally(c1, c2)) {
result = PositionMaster.noObstaclesInDiagonal(c1, c2, game.getBattleField().getGrid(), source);
if (!result)
return cacheResult(source, target, result);
List<Coordinates> list = new ArrayList<>();
if (!c2.isAdjacent(source.getCoordinates())) {
DIRECTION direction = DirectionMaster.getRelativeDirection(source, target);
list = (DC_PositionMaster.getLine(false, direction, source.getCoordinates(), // PositionMaster.getDistance(source,
Math.abs(source.getX() - target.getX())));
} else {
list.add(target.getCoordinates());
}
for (Coordinates c : list) {
if (checkWallObstruction(source, target, c))
return cacheResult(source, target, false);
}
return cacheResult(source, target, true);
}
}
if (!result)
return cacheResult(source, target, result);
if (!toCheck)
return cacheResult(source, target, result);
result = checkClearShot(source, target);
return cacheResult(source, target, result);
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class FacingCondition method check.
@Override
public boolean check(Ref ref) {
if (!(ref.getSourceObj() instanceof DC_UnitModel)) {
return false;
}
BattleFieldObject obj1 = (BattleFieldObject) ref.getSourceObj();
DC_Obj obj2;
if (!(ref.getObj(KEYS.MATCH) instanceof BfObj)) {
if (!(ref.getObj(KEYS.MATCH) instanceof DC_HeroSlotItem)) {
return false;
}
obj2 = ((DC_HeroAttachedObj) ref.getObj(KEYS.MATCH)).getOwnerObj();
} else {
obj2 = (DC_Obj) ref.getObj(KEYS.MATCH);
}
boolean result = false;
if (getTemplate() != null) {
Coordinates c = obj2.getCoordinates();
if (obj2.isOverlaying())
if (obj2 instanceof BattleFieldObject) {
DIRECTION d = ((BattleFieldObject) obj2).getDirection();
if (d != null) {
c = c.getAdjacentCoordinate(d.rotate180(), 2);
}
// the coordinate to which unit must be facing in order to face the overlaying obj on the other side
}
if (obj1 == null)
return false;
if (c == null)
return false;
FACING_SINGLE facing = FacingMaster.getSingleFacing(obj1.getFacing(), obj1.getCoordinates(), c);
result = Arrays.asList(templates).contains(facing);
if (facing == UnitEnums.FACING_SINGLE.TO_THE_SIDE) {
if (result) {
if (left_right == null) {
left_right = obj1.checkBool(GenericEnums.STD_BOOLS.LEFT_RIGHT_REACH);
}
if (left_right) {
int degrees = obj1.getFacing().getDirection().getDegrees();
int degrees2 = DirectionMaster.getRelativeDirection(obj1, obj2).getDegrees();
boolean left = degrees > degrees2;
if (left) {
return left_right;
}
return !left_right;
}
}
}
}
return result;
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class Positioner method adjustCoordinate.
public static Coordinates adjustCoordinate(Entity entity, Coordinates c, FACING_DIRECTION facing, Predicate<Coordinates> filterPredicate) {
if (c == null) {
return null;
}
Loop loop = new Loop(50);
Coordinates coordinate = new Coordinates(c.x, c.y);
while (loop.continues()) {
// TODO remove from adj. list to limit
// iterations to 8!
DIRECTION direction = ArenaPositioner.getRandomSpawnAdjustDirection();
coordinate = c.getAdjacentCoordinate(direction);
if (coordinate != null) {
if (filterPredicate != null)
if (!filterPredicate.test(coordinate))
continue;
if (!DC_Game.game.isSimulation()) {
if (DC_Game.game.getBattleFieldManager().canMoveOnto(entity, coordinate)) {
break;
}
}
if (new StackingRule(DC_Game.game).canBeMovedOnto(entity, coordinate)) {
break;
}
}
}
// second layer in case first one is fully
loop = new Loop(50);
// blocked
while (!loop.continues() && !DC_Game.game.getBattleFieldManager().canMoveOnto(entity, c) || // (DC_Game.game.getBattleField().getGrid().isCoordinateObstructed(coordinate)
coordinate == null) {
Coordinates adjacentCoordinate = c.getAdjacentCoordinate(ArenaPositioner.getRandomSpawnAdjustDirection());
coordinate = adjustCoordinate(adjacentCoordinate, facing);
}
if (coordinate.isInvalid()) {
return null;
}
return coordinate;
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class Positioner method getFirstLayerCenterCoordinate.
protected Coordinates getFirstLayerCenterCoordinate(Coordinates c, ObjType objType, boolean randomPrefSide) {
if (checkCoordinateNotUsed(c)) {
if (checkCanPlaceUnitOnCoordinate(c, objType)) {
return c;
}
}
DIRECTION spawnSide = ArenaPositioner.DEFAULT_CENTER_SPAWN_SIDE;
if (randomPrefSide) {
spawnSide = DirectionMaster.getRandomDirection();
}
Coordinates adjacentCoordinate = c.getAdjacentCoordinate(spawnSide);
if (checkCanPlaceUnitOnCoordinate(adjacentCoordinate, objType)) {
getFacingAdjuster().unitPlaced(adjacentCoordinate, FacingMaster.getFacingFromDirection(ArenaPositioner.DEFAULT_CENTER_SPAWN_SIDE, false, false));
return adjacentCoordinate;
}
DIRECTION direction = spawnSide;
DirectionMaster.rotate90(spawnSide, false);
// = c.getAdjacentCoordinate(direction);
// orthogonal
Coordinates nextCoordinate;
while (true) {
direction = DirectionMaster.rotate90(direction, false);
nextCoordinate = c.getAdjacentCoordinate(direction);
if (checkCanPlaceUnitOnCoordinate(nextCoordinate, objType)) {
getFacingAdjuster().unitPlaced(nextCoordinate, FacingMaster.getFacingFromDirection(direction, true, true));
return nextCoordinate;
}
if (direction == spawnSide) {
break;
}
}
direction = DirectionMaster.rotate45(spawnSide, false);
// diagonal
nextCoordinate = adjustCoordinate(nextCoordinate, FacingMaster.getFacingFromDirection(direction));
return nextCoordinate;
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class WallMap method draw.
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(new Color(1, 1, 1, 1));
if (wallMap == null)
return;
Set<Coordinates> set = wallMap.keySet();
for (Coordinates coordinates : set) {
if (checkCoordinateIgnored(coordinates))
continue;
List<DIRECTION> list = wallMap.get(coordinates);
boolean hasVertical = false;
boolean hasHorizontal = false;
boolean hasDiagonal = false;
boolean drawCorner = true;
boolean diagonalCorner = false;
boolean round = false;
boolean diamond = false;
boolean mesh = false;
Vector2 v = GridMaster.getVectorForCoordinate(coordinates, false, false);
v.set(v.x, v.y - 128);
// obj.getVisibilityLevel() != VISIBILITY_LEVEL.CLEAR_SIGHT;
boolean darken = false;
String suffix = darken ? "dark" : null;
if (list == null) {
diamond = true;
} else {
for (DIRECTION side : list) {
TextureRegion image = getRegion(getWallImageFromSide(side, suffix), suffix);
if (side.isDiagonal()) {
if (list.size() == 1) {
round = true;
}
drawCorner = true;
if (// doens't do anything?
diagonalCorner) {
diagonalCorner = false;
} else if (hasDiagonal) {
diagonalCorner = true;
} else {
hasDiagonal = true;
}
} else {
if (list.size() > 1) {
mesh = true;
}
if (side.isVertical()) {
if (hasVertical) {
drawCorner = false;
}
hasVertical = true;
} else {
if (hasHorizontal) {
drawCorner = false;
}
hasHorizontal = true;
}
}
DOOR_STATE doorState = doorMap.get(coordinates);
if (doorState != null) {
Color color = batch.getColor();
batch.setColor(new Color(1, 1, 1, fluctuatingAlpha));
batch.draw(image, v.x, v.y);
batch.setColor(color);
} else {
batch.draw(image, v.x, v.y);
}
}
}
if (hasHorizontal && hasVertical) {
drawCorner = true;
}
if (diagonalCorner) {
drawCorner = false;
Boolean x = null;
Boolean y = null;
boolean vertical = false;
for (DIRECTION side : list) {
if (!side.isDiagonal()) {
drawCorner = true;
mesh = true;
} else {
if (y != null) {
if (y == side.growY) {
vertical = true;
break;
} else {
if (x == side.growX) {
break;
}
mesh = true;
continue;
// TODO
}
}
y = side.growY;
x = side.growX;
}
}
if (!mesh) {
TextureRegion image = getRegion(vertical ? STD_IMAGES.WALL_CORNER_ALMOND_V : STD_IMAGES.WALL_CORNER_ALMOND_H, suffix);
batch.draw(image, v.x + (128 - image.getRegionWidth()) / 2, v.y + (128 - image.getRegionHeight()) / 2);
}
}
if (drawCorner) {
TextureRegion image = getRegion(STD_IMAGES.WALL_CORNER, suffix);
if (diamond) {
image = getRegion(STD_IMAGES.WALL_CORNER_DIAMOND, suffix);
} else if (mesh && hasDiagonal) {
image = getRegion(STD_IMAGES.WALL_CORNER_MESH, suffix);
} else if (round) {
image = getRegion(STD_IMAGES.WALL_CORNER_ROUND, suffix);
}
//
batch.draw(image, v.x + (128 - image.getRegionWidth()) / 2, v.y + (128 - image.getRegionHeight()) / 2);
}
}
drawDiagonalJoints(batch, set);
super.draw(batch, parentAlpha);
}
Aggregations