Search in sources :

Example 6 with Action

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

the class TurnSequenceConstructor method getTurnSequence.

public List<Action> getTurnSequence(FACING_SINGLE template, Unit source, Coordinates target) {
    FACING_DIRECTION original_facing = source.getFacing();
    FACING_DIRECTION facing = original_facing;
    boolean clockwise = true;
    int i = 0;
    List<Action> clockwise_list = new ArrayList<>();
    if (template == FacingMaster.getSingleFacing(FacingMaster.rotate180(facing), source.getCoordinates(), target)) {
        DC_UnitAction specAction = source.getAction("Turn About " + (RandomWizard.random() ? "anti" : "") + "clockwise");
        if (specAction != null) {
            clockwise_list.add(new Action(specAction));
            return clockwise_list;
        }
    }
    while (true) {
        if (template == FacingMaster.getSingleFacing(facing, source.getCoordinates(), target)) {
            break;
        }
        facing = FacingMaster.rotate(facing, clockwise);
        clockwise_list.add(getTurnAction(clockwise, source));
        i++;
        if (i > 2) {
            break;
        }
    }
    clockwise = false;
    i = 0;
    List<Action> anticlockwise_list = new ArrayList<>();
    facing = original_facing;
    while (true) {
        if (template == FacingMaster.getSingleFacing(facing, source.getCoordinates(), target)) {
            break;
        }
        facing = FacingMaster.rotate(facing, clockwise);
        anticlockwise_list.add(getTurnAction(clockwise, source));
        i++;
        if (i > 2) {
            break;
        }
    }
    return (anticlockwise_list.size() > clockwise_list.size()) ? clockwise_list : anticlockwise_list;
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ArrayList(java.util.ArrayList) DC_UnitAction(eidolons.entity.active.DC_UnitAction)

Example 7 with Action

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

the class TurnSequenceConstructor method getTurnSequence.

public List<Action> getTurnSequence(Action action) {
    Conditions conditions = (action.getTargeting().getFilter().getConditions());
    FacingCondition condition = null;
    FACING_SINGLE template = null;
    DC_Obj target = action.getTarget();
    Unit source = (Unit) action.getRef().getSourceObj();
    for (Condition c : conditions) {
        if (c instanceof FacingCondition) {
            condition = (FacingCondition) c;
            break;
        }
        List<Object> list = ClassMaster.getInstances(c, FacingCondition.class);
        if (!list.isEmpty()) {
            List<Action> front_sequence = getTurnSequence(FACING_SINGLE.IN_FRONT, source, target.getCoordinates());
            List<Action> side_sequence = null;
            if (action.getSource().hasBroadReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.BROAD_REACH)) // front_sequence.remove(front_sequence.size() - 1);
            {
                side_sequence = getTurnSequence(FACING_SINGLE.TO_THE_SIDE, source, target.getCoordinates());
            }
            List<Action> hind_sequence = null;
            if (action.getSource().hasHindReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.HIND_REACH)) {
                hind_sequence = getTurnSequence(FACING_SINGLE.BEHIND, source, target.getCoordinates());
            }
            return new ListMaster<Action>().getSmallest(front_sequence, hind_sequence, side_sequence);
        }
    }
    // }
    if (condition == null) {
        return new ArrayList<>();
    }
    if (ArrayMaster.isNotEmpty(condition.getTemplate())) {
        template = condition.getTemplate()[0];
    }
    return getTurnSequence(template, source, target.getCoordinates());
}
Also used : FacingCondition(eidolons.ability.conditions.FacingCondition) Condition(main.elements.conditions.Condition) DC_Obj(eidolons.entity.obj.DC_Obj) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ArrayList(java.util.ArrayList) FacingCondition(eidolons.ability.conditions.FacingCondition) Unit(eidolons.entity.obj.unit.Unit) Conditions(main.elements.conditions.Conditions) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Example 8 with Action

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

the class AI_Manager method getAction.

public Action getAction(Unit unit) {
    if (unit.isMine()) {
        unit.getQuickItemActives();
    }
    messageBuilder = new StringBuffer();
    Action action = null;
    running = true;
    setUnit(unit);
    Coordinates bufferedCoordinates = unit.getCoordinates();
    try {
        action = actionManager.chooseAction();
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    } finally {
        running = false;
    }
    if (action == null) {
        running = true;
        try {
            action = actionManager.getForcedAction(getAI(unit));
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        } finally {
            running = false;
            SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, getUnit() + " opts for Forced Action: " + action);
        }
    } else {
        try {
            getMessageBuilder().append("Task: " + action.getTaskDescription());
            if (!CoreEngine.isGraphicsOff()) {
                if (game.isDebugMode() || Launcher.DEV_MODE)
                    FloatingTextMaster.getInstance().createFloatingText(TEXT_CASES.BATTLE_COMMENT, getMessageBuilder().toString(), getUnit());
            }
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    }
    if (!bufferedCoordinates.equals(unit.getCoordinates())) {
        unit.setCoordinates(bufferedCoordinates);
    }
    return action;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates)

Example 9 with Action

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

the class BehaviorMaster method getAction.

private Action getAction(GOAL_TYPE type, UnitAI ai) {
    String action = null;
    Integer target = null;
    // doesn't the group have standing orders as a whole?..
    Unit unit = ai.getUnit();
    Ref ref = new Ref(unit);
    GroupAI group = ai.getGroup();
    // checkBehaviorChange(group); where does that happen?
    switch(type) {
        case AMBUSH:
            break;
        case STALK:
            break;
        case STAND_GUARD:
        case PATROL:
            PatrolMaster.getPatrolAction(ai);
        // having already turned on the Mode
        case SEARCH:
        case WANDER:
            if (ai.isLeader()) {
                Boolean change = WanderAi.checkWanderDirectionChange(group, type);
                if (change == null) {
                    action = getIdleAction(ai, type);
                    change = true;
                }
                // maybe go meet leader if blocked... or something like it
                if (change) {
                    group.getWanderStepCoordinateStack().push(group.getLeader().getCoordinates());
                    WanderAi.changeGroupMoveDirection(group, type);
                }
            }
            boolean wait = false;
            // ActionSequenceConstructor.getSequence(targetAction, task)
            Coordinates targetCoordinates = WanderAi.getCoordinates(type, ai);
            if (targetCoordinates == null) {
                wait = true;
            // if (!recursion)
            // return null;
            // recursion = true;
            // return getAction(type, ai);
            } else {
                action = STD_ACTIONS.Move.name();
                // if (!unit.getAction(action).canBeActivated()) {
                // }
                ActionPath path = getPathBuilder().init(new ListMaster<DC_ActiveObj>().getList(unit.getAction(action)), new Action(unit.getAction(action), new Ref(unit))).getPathByPriority(new ListMaster<Coordinates>().getList(targetCoordinates));
                if (path == null) {
                    // TODO preCheck if path
                    ai.setPathBlocked(true);
                // appropriate
                } else {
                    ai.setPathBlocked(false);
                    return path.getActions().get(0);
                }
            }
            if (wait) {
                action = getIdleAction(ai, type);
            } else {
            // if (change) {
            // targetCoordinates = WanderMaster.getCoordinates(type,
            // ai);
            // }
            // return path.getActions().getOrCreate(0);
            }
    }
    DC_ActiveObj active = unit.getAction(action);
    ref.setTarget(target);
    recursion = false;
    return new Action(active, ref);
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) ListMaster(main.system.auxiliary.data.ListMaster) Unit(eidolons.entity.obj.unit.Unit) Ref(main.entity.Ref) GroupAI(eidolons.game.battlecraft.ai.GroupAI) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 10 with Action

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

the class ForcedActionEffect method applyThis.

@Override
public boolean applyThis() {
    Unit unit = (Unit) ref.getTargetObj();
    Ref REF = unit.getRef();
    if (key != null) {
        REF.setTarget(ref.getId(key));
    }
    Action action = new Action(unit.getAction(actionName), REF);
    unit.getGame().getAiManager().getAI(unit).getForcedActions().add(action);
    return true;
}
Also used : Ref(main.entity.Ref) Action(eidolons.game.battlecraft.ai.elements.actions.Action) Unit(eidolons.entity.obj.unit.Unit)

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