Search in sources :

Example 6 with ActionPath

use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.

the class ActionSequenceConstructor method getSequencesFromPaths.

public List<ActionSequence> getSequencesFromPaths(List<ActionPath> paths, Task task, Action action) {
    List<ActionSequence> list = new ArrayList<>();
    for (ActionPath path : paths) {
        if (!TimeLimitMaster.checkTimeLimitForAi(getUnitAI()))
            break;
        ActionSequence sequence = new ActionSequence(path.getActions(), task, task.getAI());
        if (action.getActive().isRanged()) {
            List<Action> rangedAttackSequence = constructSingleAttackSequence(action, task);
            if (rangedAttackSequence.isEmpty()) {
                return list;
            }
            // TODO
            sequence.getActions().addAll(rangedAttackSequence);
        } else {
            sequence.getActions().add(action);
        }
        list.add(sequence);
    }
    return list;
}
Also used : AiQuickItemAction(eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ArrayList(java.util.ArrayList) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath)

Example 7 with ActionPath

use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.

the class ActionSequenceConstructor method getSequencesWithPathsForAction.

private List<ActionSequence> getSequencesWithPathsForAction(Action action, Object arg, Task task) {
    List<ActionSequence> list = new ArrayList<>();
    game = action.getRef().getGame();
    unit = action.getSource();
    if (task.getAI().getBehaviorMode() == AiEnums.BEHAVIOR_MODE.PANIC) {
    // target action = FLEE;
    }
    if (task.getType() == AiEnums.GOAL_TYPE.RETREAT) {
        {
            List<ActionSequence> sequencesFromPaths = getSequencesFromPaths(getPathSequenceConstructor().getRetreatPaths(arg), task, action);
            return sequencesFromPaths;
        }
    // TODO
    }
    boolean singleAction = action.isSingle();
    if (task.getType() == GOAL_TYPE.PROTECT) {
        singleAction = action.getSource().getCoordinates().equals(action.getTarget().getCoordinates());
    } else if (!singleAction) {
        if (arg != null) {
            singleAction = // .toString()));
            TargetingMaster.canBeTargeted(action, true);
        } else {
            singleAction = (action).canBeActivated();
        }
    }
    // if (ReasonMaster.getReasons(action).getOrCreate(0)==FILTER_REASON.FACING)
    if (singleAction) {
        ActionSequence sequence = constructSingleActionSequence(action, task);
        if (sequence == null) {
            return null;
        }
        list.add(sequence);
        return list;
    }
    if (!task.isForced()) {
        // TODO REFACTOR
        if (task.getType() != GOAL_TYPE.PROTECT && task.getType() != AiEnums.GOAL_TYPE.ATTACK && task.getType() != AiEnums.GOAL_TYPE.RETREAT && task.getType() != AiEnums.GOAL_TYPE.SEARCH && task.getType() != AiEnums.GOAL_TYPE.MOVE && !task.getType().isBehavior()) {
            return null;
        }
    }
    if (task.getType() == AiEnums.GOAL_TYPE.SUMMONING) {
        return null;
    }
    if (task.getType() == AiEnums.GOAL_TYPE.ZONE_DAMAGE) {
        // TODO until pathing/cell-pr. is fixed
        return null;
    }
    if (!task.isForced()) {
        if (task.getAI().checkMod(AI_MODIFIERS.TRUE_BRUTE)) {
            return null;
        }
        if (task.getAI().getBehaviorMode() == AiEnums.BEHAVIOR_MODE.BERSERK) {
            return null;
        }
    // if (getAnalyzer().isRanged(task.getAI())) return null ;
    // TODO   if ((!action.getActive().isRanged() && task.getAI().getType() == AiEnums.AI_TYPE.ARCHER)
    // || (task.getAI().getType() == AiEnums.AI_TYPE.CASTER && !unit.getSpells().isEmpty())) {
    // return null;
    // }
    }
    Unit unit = (Unit) action.getRef().getSourceObj();
    List<DC_ActiveObj> moveActions = getMoveActions(action);
    if (!ListMaster.isNotEmpty(moveActions)) {
        // [QUICK FIX]
        if (!unit.getAction(DC_ActionManager.STD_ACTIONS.Turn_Anticlockwise.name()).canBeActivated(action.getRef(), true) && !unit.getAction(DC_ActionManager.STD_ACTIONS.Move.name()).canBeActivated(action.getRef(), true)) {
            return null;
        }
    } else {
    // if (prioritizedCells == null)
    // prioritizedCells = CellPrioritizer
    // .getMeleePriorityCellsForUnit(unit.getUnitAI(),
    // moveActions, action);
    }
    List<ActionPath> paths = getPathSequenceConstructor().getPathSequences(moveActions, action);
    list = getSequencesFromPaths(paths, task, action);
    // }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) Unit(eidolons.entity.obj.unit.Unit) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 8 with ActionPath

use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.

the class PathSequenceConstructor method getOptimalPathSequence.

public ActionPath getOptimalPathSequence(UnitAI ai, Coordinates targetCell) {
    List<DC_ActiveObj> moves = AiUnitActionMaster.getMoveActions(ai.getUnit());
    Action action = AiActionFactory.newAction("Move", ai);
    List<Coordinates> coordinates = new ArrayList<>();
    coordinates.add(targetCell);
    List<ActionPath> paths = getPathSequences(moves, action, coordinates);
    // });
    return paths.get(0);
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 9 with ActionPath

use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.

the class WanderAi method getOrders.

@Override
public ActionSequence getOrders(UnitAI ai) {
    Coordinates c1 = null;
    try {
        WanderAi.checkWanderDirectionChange(ai.getGroup(), GOAL_TYPE.WANDER);
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    try {
        c1 = (getWanderTargetCoordinatesCell(ai, GOAL_TYPE.WANDER));
    } catch (Exception e) {
        c1 = (CoordinatesMaster.getRandomAdjacentCoordinate(ai.getUnit().getCoordinates()));
        main.system.ExceptionMaster.printStackTrace(e);
    }
    c1 = Positioner.adjustCoordinate(ai.getUnit(), c1, ai.getUnit().getFacing(), getWanderPredicate(ai.getUnit(), ai.getUnit().getFacing(), c1));
    Task task = new Task(ai, GOAL_TYPE.WANDER, null);
    List<Action> turnSequence = getMaster(ai).getTurnSequenceConstructor().getTurnSequence(ai.getUnit(), c1);
    if (ListMaster.isNotEmpty(turnSequence)) {
        return new ActionSequence(turnSequence, task, ai);
    }
    List<Coordinates> c = new ArrayList<>();
    c.add(c1);
    getMaster(ai).setUnit(ai.getUnit());
    // getMaster(ai).getPathBuilder().init(null, null);
    // TimeLimitMaster.markTimeForAI(ai);
    List<ActionPath> paths = new ArrayList<>();
    // getMaster(ai).getPathBuilder().build(c);
    Action action = null;
    if (paths.isEmpty()) {
        if (c.get(0) != null)
            action = getMaster(ai).getAtomicAi().getAtomicMove(c.get(0), ai.getUnit());
        else
            action = getMaster(ai).getAtomicAi().getAtomicActionApproach(ai);
        if (action != null)
            return new ActionSequence(GOAL_TYPE.WANDER, action);
    } else
        action = paths.get(0).getActions().get(0);
    if (action == null)
        return null;
    List<ActionSequence> sequences = getMaster(ai).getActionSequenceConstructor().getSequencesFromPaths(paths, task, action);
    if (sequences.isEmpty())
        return null;
    return sequences.get(0);
}
Also used : Task(eidolons.game.battlecraft.ai.elements.task.Task) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath)

Aggregations

ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)9 Action (eidolons.game.battlecraft.ai.elements.actions.Action)7 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)4 Unit (eidolons.entity.obj.unit.Unit)4 ArrayList (java.util.ArrayList)4 Coordinates (main.game.bf.Coordinates)4 DC_UnitAction (eidolons.entity.active.DC_UnitAction)2 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)2 Task (eidolons.game.battlecraft.ai.elements.task.Task)2 Ref (main.entity.Ref)2 ListMaster (main.system.auxiliary.data.ListMaster)2 GroupAI (eidolons.game.battlecraft.ai.GroupAI)1 UnitAI (eidolons.game.battlecraft.ai.UnitAI)1 Order (eidolons.game.battlecraft.ai.advanced.companion.Order)1 AiActionFactory (eidolons.game.battlecraft.ai.elements.actions.AiActionFactory)1 AiQuickItemAction (eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction)1 AiHandler (eidolons.game.battlecraft.ai.elements.generic.AiHandler)1 AiMaster (eidolons.game.battlecraft.ai.elements.generic.AiMaster)1 PathBuilder (eidolons.game.battlecraft.ai.tools.path.PathBuilder)1 COMBAT_SCRIPT_FUNCTION (eidolons.game.battlecraft.logic.battle.mission.CombatScriptExecutor.COMBAT_SCRIPT_FUNCTION)1