Search in sources :

Example 6 with FACING_SINGLE

use of main.content.enums.entity.UnitEnums.FACING_SINGLE 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 FACING_SINGLE

use of main.content.enums.entity.UnitEnums.FACING_SINGLE in project Eidolons by IDemiurge.

the class PathChoiceMaster method constructStdMoveChoice.

private Choice constructStdMoveChoice(Coordinates targetCoordinate, Coordinates c_coordinate, FACING_DIRECTION c_facing) {
    FACING_SINGLE facing = FacingMaster.getSingleFacing(c_facing, c_coordinate, targetCoordinate);
    Action moveAction = getMoveAction();
    if (facing == UnitEnums.FACING_SINGLE.IN_FRONT) {
        if (firstStep) {
            if (!moveAction.canBeActivated()) {
                return null;
            }
        }
        return new Choice(targetCoordinate, c_coordinate, moveAction);
    }
    pathBuilder.adjustUnit();
    Collection<Action> actions = pathBuilder.getTurnSequenceConstructor().getTurnSequence(UnitEnums.FACING_SINGLE.IN_FRONT, unit, targetCoordinate);
    actions.add(moveAction);
    // resetUnit();// TODO is that right?
    Choice choice = new Choice(targetCoordinate, c_coordinate, actions.toArray(new Action[actions.size()]));
    return choice;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Example 8 with FACING_SINGLE

use of main.content.enums.entity.UnitEnums.FACING_SINGLE in project Eidolons by IDemiurge.

the class DC_MovementManager method getFirstAction.

public static Action getFirstAction(Unit unit, Coordinates coordinates) {
    FACING_SINGLE relative = FacingMaster.getSingleFacing(unit.getFacing(), unit.getCoordinates(), coordinates);
    if (relative == FACING_SINGLE.IN_FRONT) {
        if (new CellCondition(UNIT_DIRECTION.AHEAD).check(unit))
            return AiActionFactory.newAction("Move", unit.getAI());
    }
    boolean left = (unit.getFacing().isVertical()) ? PositionMaster.isToTheLeft(unit.getCoordinates(), coordinates) : PositionMaster.isAbove(unit.getCoordinates(), coordinates);
    if (unit.getFacing().isMirrored()) {
        left = !left;
    }
    if (!new CellCondition(left ? UNIT_DIRECTION.LEFT : UNIT_DIRECTION.RIGHT).check(unit))
        return null;
    return AiActionFactory.newAction("Move " + (left ? "Left" : "Right"), unit.getAI());
// List<ActionPath> paths = instance.buildPath(unit, coordinates);
// if (!ListMaster.isNotEmpty(paths)) {
// return  null ;
// }
// ActionPath path =paths.get(0);
// for (ActionPath portrait : paths){
// if (portrait.getActions().get(0).getActive().isTurn())
// {
// path = portrait;
// break;
// }
// }
// return path.getActions().get(0);
}
Also used : CellCondition(eidolons.ability.conditions.req.CellCondition) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Example 9 with FACING_SINGLE

use of main.content.enums.entity.UnitEnums.FACING_SINGLE 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 10 with FACING_SINGLE

use of main.content.enums.entity.UnitEnums.FACING_SINGLE in project Eidolons by IDemiurge.

the class PruneMaster method pruneTargetCells.

public List<Coordinates> pruneTargetCells(Action targetAction, List<Coordinates> list) {
    TreeMap<Integer, Coordinates> map = new TreeMap<>(SortMaster.getNaturalIntegerComparator(false));
    Coordinates coordinates = targetAction.getSource().getCoordinates();
    for (Coordinates c : list) {
        int distance = 10 * PositionMaster.getDistance(coordinates, c);
        if (!PositionMaster.inLine(c, coordinates)) {
            distance += 5;
        }
        if (PositionMaster.inLineDiagonally(c, coordinates)) {
            distance += 2;
        }
        FACING_SINGLE facing = FacingMaster.getSingleFacing(targetAction.getSource().getFacing(), c, coordinates);
        switch(facing) {
            case BEHIND:
                distance += 12;
                break;
            case IN_FRONT:
                break;
            case TO_THE_SIDE:
                distance += 6;
                break;
        }
        // TODO KEYS WILL OVERLAP!
        map.put(distance, c);
    }
    for (int i = map.size() - getConstInt(AiConst.DEFAULT_PRUNE_SIZE); i > 0; i--) {
        map.remove(map.lastKey());
    }
    // }
    return new ArrayList<>(map.values());
}
Also used : Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Aggregations

FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)11 ArrayList (java.util.ArrayList)3 Coordinates (main.game.bf.Coordinates)3 FacingCondition (eidolons.ability.conditions.FacingCondition)2 CellCondition (eidolons.ability.conditions.req.CellCondition)2 DC_UnitAction (eidolons.entity.active.DC_UnitAction)2 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)2 DC_Obj (eidolons.entity.obj.DC_Obj)2 Action (eidolons.game.battlecraft.ai.elements.actions.Action)2 DIRECTION (main.game.bf.Coordinates.DIRECTION)2 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)2 RotateByAction (com.badlogic.gdx.scenes.scene2d.actions.RotateByAction)1 StatusCheckCondition (eidolons.ability.conditions.StatusCheckCondition)1 VisibilityCondition (eidolons.ability.conditions.VisibilityCondition)1 StdPassiveCondition (eidolons.ability.conditions.shortcut.StdPassiveCondition)1 DC_HeroSlotItem (eidolons.entity.item.DC_HeroSlotItem)1 DC_UnitModel (eidolons.entity.obj.unit.DC_UnitModel)1 Unit (eidolons.entity.obj.unit.Unit)1 TreeMap (java.util.TreeMap)1 Condition (main.elements.conditions.Condition)1