Search in sources :

Example 1 with ActionPath

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

the class AiScriptExecutor method executeCommand.

private void executeCommand(Unit unit, COMBAT_SCRIPT_FUNCTION function, String arg, boolean free, boolean immediate, String... args) {
    ActionSequence sequence = null;
    GOAL_TYPE goal = getGoalType(function);
    Task task = new Task(true, unit.getAI(), goal, arg);
    UnitAI ai = unit.getAI();
    switch(function) {
        case MOVE_TO:
            // via a path!
            ActionPath path = getPathSequenceConstructor().getOptimalPathSequence(unit.getAI(), new Coordinates(arg.toString()));
            sequence = new ActionSequence(path.getActions(), task, unit.getAI());
            break;
        case TURN_TO:
            // cell id
            sequence = new ActionSequence(getTurnSequenceConstructor().getTurnSequence(FACING_SINGLE.IN_FRONT, unit, new Coordinates(arg.toString())), task, unit.getAI());
            break;
        case ACTION:
            Action action = AiActionFactory.newAction(arg.toString(), ai);
            // new ActionSequence();
            sequence = getActionSequenceConstructor().constructSingleActionSequence(action, new Task(ai, goal, args[0]));
            break;
        case ATTACK:
            break;
        case FREEZE:
            break;
        case UNFREEZE:
            break;
        case ORDER:
            // OrderFactory.getOrder();
            Order a = new Order(arg.toString());
            unit.getAI().setCurrentOrder(a);
            return;
    }
    if (immediate) {
        unit.getAI().setStandingOrders(sequence);
        unit.getAI().setFree(free);
    } else
        sequence.getActions().forEach(// TODO wait?
        action -> getExecutor().execute(action, free));
}
Also used : Order(eidolons.game.battlecraft.ai.advanced.companion.Order) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ScriptExecutor(eidolons.game.battlecraft.logic.meta.scenario.script.ScriptExecutor) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) AiHandler(eidolons.game.battlecraft.ai.elements.generic.AiHandler) AiMaster(eidolons.game.battlecraft.ai.elements.generic.AiMaster) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE) Order(eidolons.game.battlecraft.ai.advanced.companion.Order) COMBAT_SCRIPT_FUNCTION(eidolons.game.battlecraft.logic.battle.mission.CombatScriptExecutor.COMBAT_SCRIPT_FUNCTION) Ref(main.entity.Ref) UnitAI(eidolons.game.battlecraft.ai.UnitAI) DataManager(main.data.DataManager) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) AiActionFactory(eidolons.game.battlecraft.ai.elements.actions.AiActionFactory) Task(eidolons.game.battlecraft.ai.elements.task.Task) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) EnumMaster(main.system.auxiliary.EnumMaster) 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) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Coordinates(main.game.bf.Coordinates) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath)

Example 2 with ActionPath

use of eidolons.game.battlecraft.ai.tools.path.ActionPath 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 3 with ActionPath

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

the class DC_MovementManager method moveTo.

public void moveTo(Coordinates coordinates) {
    Unit unit = game.getManager().getActiveObj();
    List<ActionPath> paths = pathCache.get(unit);
    if (paths == null) {
        paths = buildPath(unit, coordinates);
        // Coordinates adjacentCoordinate = coordinates.getAdjacentCoordinate(DirectionMaster
        // .getRelativeDirection(unit.getCoordinates(), coordinates));
        // if (DialogMaster.confirm("No path could be built to " + coordinates
        // + "; proceed to the closest cell? - " + adjacentCoordinate)) {
        // moveTo(adjacentCoordinate);
        // } else {
        // return;
        // }
        pathCache.put(unit, paths);
    }
    if (paths == null) {
        return;
    }
    Action action = null;
    for (ActionPath path : paths) {
        // if (DialogMaster.confirm("Path built to : " + path + "\nExecute "
        // + path.getActions().get(0).toString() + "?")) {
        // action = path.getActions().get(0);
        // break;
        // }
        // just check if still passible
        // if (path.getActions().get(0))
        action = path.getActions().get(0);
        break;
    }
    if (action == null) {
        pathCache.remove(unit);
        return;
    }
    // ActionAnimation anim = new ActionAnimation(action);
    // anim.start();
    Context context = new Context(unit.getRef());
    if (action.getActive().isMove()) {
        context.setTarget(game.getCellByCoordinate(coordinates).getId());
    }
    unit.getGame().getGameLoop().actionInput(new ActionInput(action.getActive(), context));
}
Also used : Context(main.game.logic.action.context.Context) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionInput(eidolons.game.core.ActionInput) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) Unit(eidolons.entity.obj.unit.Unit)

Example 4 with ActionPath

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

the class DC_MovementManager method promptContinuePath.

@Override
public void promptContinuePath(Obj activeUnit) {
    List<ActionPath> list = pathCache.get(activeUnit);
    if (list == null) {
        return;
    }
    ActionPath path = list.get(0);
    moveTo(path.getTargetCoordinates());
}
Also used : ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath)

Example 5 with ActionPath

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

the class DC_MovementManager method buildPath.

public List<ActionPath> buildPath(Unit unit, Coordinates coordinates) {
    List<DC_ActiveObj> moves = getMoves(unit);
    PathBuilder builder = PathBuilder.getInstance().init(moves, new Action(unit.getAction("Move")));
    List<ActionPath> paths = builder.build(new ListMaster<Coordinates>().getList(coordinates));
    if (paths.isEmpty()) {
        return null;
    }
    return paths;
}
Also used : PathBuilder(eidolons.game.battlecraft.ai.tools.path.PathBuilder) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) ListMaster(main.system.auxiliary.data.ListMaster) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

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