Search in sources :

Example 21 with DIRECTION

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);
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) DC_Obj(eidolons.entity.obj.DC_Obj) Obj(main.entity.obj.Obj) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) ArrayList(java.util.ArrayList)

Example 22 with DIRECTION

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;
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) DC_UnitModel(eidolons.entity.obj.unit.DC_UnitModel) BfObj(main.entity.obj.BfObj) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) DC_HeroSlotItem(eidolons.entity.item.DC_HeroSlotItem) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Example 23 with DIRECTION

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;
}
Also used : Loop(main.system.auxiliary.Loop) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) StackingRule(eidolons.game.battlecraft.rules.action.StackingRule)

Example 24 with DIRECTION

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;
}
Also used : DIRECTION(main.game.bf.Coordinates.DIRECTION) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Coordinates(main.game.bf.Coordinates)

Example 25 with DIRECTION

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);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) DOOR_STATE(eidolons.game.module.dungeoncrawl.objects.DoorMaster.DOOR_STATE) Vector2(com.badlogic.gdx.math.Vector2) Color(com.badlogic.gdx.graphics.Color) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION)

Aggregations

DIRECTION (main.game.bf.Coordinates.DIRECTION)32 Coordinates (main.game.bf.Coordinates)18 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)11 DC_Obj (eidolons.entity.obj.DC_Obj)9 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)7 Unit (eidolons.entity.obj.unit.Unit)6 ArrayList (java.util.ArrayList)5 Obj (main.entity.obj.Obj)5 DC_Cell (eidolons.entity.obj.DC_Cell)2 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)2 Color (com.badlogic.gdx.graphics.Color)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 MoveEffect (eidolons.ability.effects.oneshot.move.MoveEffect)1 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)1 DC_HeroSlotItem (eidolons.entity.item.DC_HeroSlotItem)1 Structure (eidolons.entity.obj.Structure)1 DC_UnitModel (eidolons.entity.obj.unit.DC_UnitModel)1 GroupAI (eidolons.game.battlecraft.ai.GroupAI)1 UnitAI (eidolons.game.battlecraft.ai.UnitAI)1