Search in sources :

Example 6 with DIRECTION

use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.

the class DefaultActionHandler method getMoveToCellAction.

public static DC_UnitAction getMoveToCellAction(Unit source, Coordinates c) {
    DIRECTION d = DirectionMaster.getRelativeDirection(source.getCoordinates(), c);
    FACING_SINGLE f = FacingMaster.getSingleFacing(source.getFacing(), source.getCoordinates(), c);
    String name = null;
    switch(f) {
        case IN_FRONT:
            if (d.isDiagonal()) {
                // target = Eidolons.getGame().getCellByCoordinate(c);
                name = "Clumsy Leap";
                break;
            }
            name = "Move";
            break;
        case BEHIND:
            if (d.isDiagonal())
                return null;
            name = "Move Back";
            break;
        case TO_THE_SIDE:
            boolean right = !source.getFacing().isVertical() ? d.growY : d.growX;
            if (!source.getFacing().isVertical()) {
                if (source.getFacing().isCloserToZero())
                    right = !right;
            } else if (!source.getFacing().isCloserToZero())
                right = !right;
            name = right ? "Move Right" : "Move Left";
            break;
        case NONE:
            break;
    }
    if (name == null) {
        // SoundController.getCustomEventSound(SOUND_EVENT.RADIAL_CLOSED);
        return null;
    }
    return source.getAction(name);
}
Also used : DIRECTION(main.game.bf.Coordinates.DIRECTION) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Example 7 with DIRECTION

use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.

the class PatrolMaster method changeDestination.

private static void changeDestination(Patrol patrol) {
    DIRECTION d = patrol.getDirection();
    if (d == null) {
        patrol.getLeadingUnit();
    }
    if (!patrol.isBackAndForth()) {
        d = DirectionMaster.rotate90(d, patrol.isClockwise());
    } else {
        d = DirectionMaster.flip(patrol.getDirection());
    }
    Coordinates newDestination = getNewDestination(patrol, d);
    patrol.setDestination(newDestination);
}
Also used : DIRECTION(main.game.bf.Coordinates.DIRECTION) Coordinates(main.game.bf.Coordinates)

Example 8 with DIRECTION

use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.

the class PatrolMaster method getBlockingUnit.

private static Unit getBlockingUnit(Patrol patrol, UnitAI ai) {
    Unit unit = ai.getUnit();
    DIRECTION direction = DirectionMaster.getRelativeDirection(unit.getCoordinates(), patrol.getDestination());
    // paths.getOrCreate(unit);
    Coordinates coordinates = unit.getCoordinates().getAdjacentCoordinate(direction);
    // TODO more than 1 coordinate?
    // unit.getGame().getUnitByCoordinate(coordinates);
    Unit unitByCoordinate = null;
    // preCheck leader?
    Collection<Unit> units = unit.getGame().getUnitsForCoordinates(coordinates);
    for (Obj u : units) {
        // sort?
        Unit blocker = (Unit) u;
        // if (u == leader)
        if (!blocker.isOwnedBy(ai.getUnit().getOwner())) {
            continue;
        }
        if (!blocker.canMove()) {
            continue;
        }
        unitByCoordinate = blocker;
    }
    return unitByCoordinate;
}
Also used : Obj(main.entity.obj.Obj) DIRECTION(main.game.bf.Coordinates.DIRECTION) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit)

Example 9 with DIRECTION

use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.

the class PatrolMaster method getPatrolAction.

// similar to wandering but all units must be to the target point
public static Action getPatrolAction(UnitAI ai) {
    Patrol patrol = ai.getGroup().getPatrol();
    if (patrol == null) {
        initPatrol(ai.getGroup());
    }
    Action action = null;
    boolean leader = ai.getGroup().getLeader() == ai.getUnit();
    if (isArrived(patrol, ai)) {
        if (leader) {
            if (checkNewDestination(patrol)) {
                changeDestination(patrol);
            } else {
                action = getIdleAction(patrol, ai);
            }
        }
    } else {
        action = getWaitAction(patrol, ai);
    }
    if (action != null) {
        return action;
    }
    if (patrol.getReturnCoordinates() != null) {
        patrol.setDestination(patrol.getReturnCoordinates());
        patrol.setReturnCoordinates(null);
    }
    Coordinates c = patrol.getDestination();
    if (!leader) {
        Coordinates leaderCoordinates = ai.getGroup().getLeader().getCoordinates();
        DIRECTION direction = DirectionMaster.getRelativeDirection(patrol.getDestination(), leaderCoordinates);
        List<Object> list = new ArrayList<>();
        list.add(leaderCoordinates.getAdjacentCoordinate(direction));
        list.add(leaderCoordinates.getAdjacentCoordinate(DirectionMaster.rotate45(direction, true)));
        list.add(leaderCoordinates.getAdjacentCoordinate(DirectionMaster.rotate45(direction, false)));
        c = leaderCoordinates.getAdjacentCoordinate(direction);
    }
    boolean catchingUp = false;
    // make sure paths stick together! getMaxDistanceForNodes(paths)
    return action;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) ArrayList(java.util.ArrayList)

Example 10 with DIRECTION

use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.

the class WanderAi method getWanderCells.

public static List<? extends DC_Obj> getWanderCells(UnitAI ai) {
    DIRECTION d = ai.getGroup().getWanderDirection();
    // permittedCells = ai.getGroup().getWanderBlocks();
    List<DC_Obj> list = new ArrayList<>();
    for (DC_Cell cell : Analyzer.getCells(ai, false, false, true)) {
        if (d != null) {
            if (DirectionMaster.getRelativeDirection(cell, ai.getUnit()) != d) {
                continue;
            }
        }
        if (PositionMaster.getDistance(cell, ai.getUnit()) <= ai.getMaxWanderDistance()) {
            list.add(cell);
        }
    }
    if (list.isEmpty()) {
    // change direction?
    }
    return list;
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) DC_Cell(eidolons.entity.obj.DC_Cell) DIRECTION(main.game.bf.Coordinates.DIRECTION) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) ArrayList(java.util.ArrayList)

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