Search in sources :

Example 11 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class ExplorationAiMaster method getOrders.

private ActionSequence getOrders(UnitAI ai) {
    if (// TODO
    ai.getUnit().isMine())
        if (master.getPartyMaster().isFollowOn(ai.getUnit())) {
            // isFollow
            Action move = master.getPartyMaster().getFollowMove(ai.getUnit());
            if (move == null) {
                return null;
            // return getIdleOrders(ai);
            } else {
                return new ActionSequence(GOAL_TYPE.MOVE, move);
            }
        }
    // get orders?
    AiBehavior behavior = getAiBehavior(ai);
    ActionSequence orders = behavior.getOrders(ai);
    if (orders == null) {
    // orders= getIdleOrders(ai);
    }
    return orders;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) AiBehavior(eidolons.game.module.dungeoncrawl.ai.AiBehavior)

Example 12 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class PatrolMaster method getWaitAction.

private static Action getWaitAction(Patrol patrol, UnitAI ai) {
    Unit unit = ai.getUnit();
    Unit blocker = getBlockingUnit(patrol, ai);
    if (blocker == null) {
        return null;
    }
    Ref ref = new Ref(unit);
    ref.setTarget(blocker.getId());
    new Action(ai.getUnit().getAction("Wait"), ref);
    return null;
}
Also used : Ref(main.entity.Ref) Action(eidolons.game.battlecraft.ai.elements.actions.Action) Unit(eidolons.entity.obj.unit.Unit)

Example 13 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action 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 14 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action 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 15 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class PathChoiceMaster method getChoices.

List<Choice> getChoices(ActionPath path, Coordinates c_coordinate, Coordinates targetCoordinate, FACING_DIRECTION c_facing) {
    Chronos.mark("Finding choices for " + path);
    pathBuilder.adjustUnit();
    List<Choice> choices = new ArrayList<>();
    for (Coordinates c : getDefaultCoordinateTargets(path, c_coordinate)) {
        Choice stdMoveChoice = constructStdMoveChoice(c, c_coordinate, c_facing);
        if (stdMoveChoice != null) {
            choices.add(stdMoveChoice);
        }
    }
    Chronos.mark("Finding custom choices for " + path);
    List<Choice> specialChoices = new ArrayList<>();
    if (ListMaster.isNotEmpty(moveActions)) {
        for (DC_ActiveObj a : moveActions) {
            if (!a.canBeActivated()) {
                if (firstStep) {
                    if (!ReasonMaster.checkReasonCannotActivate(a, PARAMS.C_N_OF_ACTIONS.getName())) {
                        // exception for AP TODO
                        continue;
                    }
                }
            }
            if (path.hasAction(a)) {
                if (a.getIntParam(PARAMS.COOLDOWN) >= 0) {
                    continue;
                }
            }
            Targeting targeting = a.getTargeting();
            Collection<Obj> objects = null;
            if (targeting instanceof FixedTargeting) {
                Targeting t = a.getAbilities().getTargeting();
                if (t != null) {
                    objects = t.getFilter().getObjects(a.getRef());
                }
                Effect e = a.getAbilities().getEffects().getEffects().get(0);
                e.setRef(unit.getRef());
                if (e instanceof SelfMoveEffect) {
                    try {
                        Coordinates coordinates = ((SelfMoveEffect) e).getCoordinates();
                        if (coordinates != null) {
                            objects = new ArrayList<>(Arrays.asList(unit.getGame().getCellByCoordinate(coordinates)));
                        }
                    } catch (Exception ex) {
                        main.system.ExceptionMaster.printStackTrace(ex);
                    }
                }
            } else {
                pathBuilder.adjustUnit();
                objects = targeting.getFilter().getObjects(a.getRef());
            }
            if (objects != null) {
                List<Choice> choicesForAction = new ArrayList<>();
                for (Object obj : objects) {
                    if (obj instanceof DC_Cell) {
                        Coordinates coordinates = ((DC_Cell) obj).getCoordinates();
                        // if (a.getName().equals("Clumsy Leap"))
                        if (PositionMaster.getDistance(coordinates, c_coordinate) > Math.max(1, a.getIntParam(PARAMS.RANGE))) {
                            continue;
                        }
                        if (PositionMaster.getDistance(coordinates, targetCoordinate) > PositionMaster.getDistance(c_coordinate, targetCoordinate)) {
                            // TODO will this not eliminate good
                            continue;
                        }
                        // choices?
                        Ref ref = unit.getRef().getCopy();
                        ref.setTarget(((DC_Cell) obj).getId());
                        Choice choice = new Choice(coordinates, c_coordinate, new Action(a, ref));
                        choicesForAction.add(choice);
                    }
                }
                Chronos.mark("Filter custom choices for " + a);
                specialChoices.addAll(filterSpecialMoveChoices(choicesForAction, a, c_coordinate, path));
                Chronos.logTimeElapsedForMark("Filter custom choices for " + a);
            }
        // if (choices.size() > 1)
        }
    }
    Chronos.logTimeElapsedForMark("Finding custom choices for " + path);
    choices.addAll(specialChoices);
    Chronos.mark("Sort choices");
    sortChoices(choices);
    Chronos.logTimeElapsedForMark("Sort choices");
    // resetUnit();// TODO is that right?
    Chronos.logTimeElapsedForMark("Finding choices for " + path);
    // Chronos.logTimeElapsedForMark("Sorting choices for " + path);
    return choices;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) FixedTargeting(main.elements.targeting.FixedTargeting) Targeting(main.elements.targeting.Targeting) Coordinates(main.game.bf.Coordinates) Ref(main.entity.Ref) FixedTargeting(main.elements.targeting.FixedTargeting) DC_Cell(eidolons.entity.obj.DC_Cell) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) SelfMoveEffect(eidolons.ability.effects.oneshot.move.SelfMoveEffect) SelfMoveEffect(eidolons.ability.effects.oneshot.move.SelfMoveEffect) Effect(main.ability.effects.Effect) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Aggregations

Action (eidolons.game.battlecraft.ai.elements.actions.Action)32 DC_UnitAction (eidolons.entity.active.DC_UnitAction)16 Coordinates (main.game.bf.Coordinates)11 Unit (eidolons.entity.obj.unit.Unit)9 ArrayList (java.util.ArrayList)9 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)8 AiQuickItemAction (eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction)7 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)7 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)7 Ref (main.entity.Ref)6 DC_QuickItemAction (eidolons.entity.active.DC_QuickItemAction)4 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)3 GOAL_TYPE (main.content.enums.system.AiEnums.GOAL_TYPE)3 Obj (main.entity.obj.Obj)3 DC_Cell (eidolons.entity.obj.DC_Cell)2 DC_Obj (eidolons.entity.obj.DC_Obj)2 UnitAI (eidolons.game.battlecraft.ai.UnitAI)2 Task (eidolons.game.battlecraft.ai.elements.task.Task)2 Effect (main.ability.effects.Effect)2 Context (main.game.logic.action.context.Context)2