Search in sources :

Example 1 with Task

use of eidolons.game.battlecraft.ai.elements.task.Task 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 Task

use of eidolons.game.battlecraft.ai.elements.task.Task in project Eidolons by IDemiurge.

the class ActionSequenceConstructor method createActionSequencesForGoal.

public List<ActionSequence> createActionSequencesForGoal(Goal goal, UnitAI ai) {
    List<ActionSequence> actionSequences = new ArrayList<>();
    List<DC_ActiveObj> actions = AiUnitActionMaster.getFullActionList(goal.getTYPE(), ai.getUnit());
    actions.addAll(addSubactions(actions));
    for (DC_ActiveObj action : actions) {
        if (!TimeLimitMaster.checkTimeLimitForAi(getUnitAI()))
            break;
        Chronos.mark(getChronosPrefix() + action);
        List<Task> tasks = getTaskManager().getTasks(goal.getTYPE(), ai, goal.isForced(), action);
        for (Task task : tasks) {
            if (task.isBlocked()) {
                continue;
            }
            if (actionSequences.size() > 0) {
                long time = TimeLimitMaster.getTimeLimitForAction();
                if (Chronos.getTimeElapsedForMark(getChronosPrefix() + action) > time) {
                    LogMaster.log(1, "*********** TIME ELAPSED FOR  " + action + StringMaster.wrapInParenthesis(time + ""));
                    break;
                }
            }
            String string = task.toString();
            Obj obj = action.getGame().getObjectById((Integer) task.getArg());
            if (obj != null) {
                string = obj.getName();
            }
            try {
                // Chronos.mark(getChronosPrefix() + string);
                actionSequences.addAll(getSequences(task, action));
            // Chronos.logTimeElapsedForMark(getChronosPrefix() + string);
            } catch (Exception e) {
                main.system.ExceptionMaster.printStackTrace(e);
            }
        }
        Chronos.logTimeElapsedForMark(getChronosPrefix() + action);
    }
    return actionSequences;
}
Also used : Task(eidolons.game.battlecraft.ai.elements.task.Task) DC_WeaponObj(eidolons.entity.item.DC_WeaponObj) DC_QuickItemObj(eidolons.entity.item.DC_QuickItemObj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) ArrayList(java.util.ArrayList) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 3 with Task

use of eidolons.game.battlecraft.ai.elements.task.Task in project Eidolons by IDemiurge.

the class OrderMaster method checkOrderCompleted.

public static boolean checkOrderCompleted(Action action) {
    UnitAI ai = action.getSource().getAI();
    Order order = ai.getCurrentOrder();
    Task task = action.getTask();
    return false;
}
Also used : Task(eidolons.game.battlecraft.ai.elements.task.Task) UnitAI(eidolons.game.battlecraft.ai.UnitAI)

Example 4 with Task

use of eidolons.game.battlecraft.ai.elements.task.Task 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

Task (eidolons.game.battlecraft.ai.elements.task.Task)4 UnitAI (eidolons.game.battlecraft.ai.UnitAI)2 Action (eidolons.game.battlecraft.ai.elements.actions.Action)2 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)2 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)2 ArrayList (java.util.ArrayList)2 Coordinates (main.game.bf.Coordinates)2 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)1 DC_QuickItemObj (eidolons.entity.item.DC_QuickItemObj)1 DC_WeaponObj (eidolons.entity.item.DC_WeaponObj)1 Unit (eidolons.entity.obj.unit.Unit)1 Order (eidolons.game.battlecraft.ai.advanced.companion.Order)1 AiActionFactory (eidolons.game.battlecraft.ai.elements.actions.AiActionFactory)1 AiHandler (eidolons.game.battlecraft.ai.elements.generic.AiHandler)1 AiMaster (eidolons.game.battlecraft.ai.elements.generic.AiMaster)1 COMBAT_SCRIPT_FUNCTION (eidolons.game.battlecraft.logic.battle.mission.CombatScriptExecutor.COMBAT_SCRIPT_FUNCTION)1 ScriptExecutor (eidolons.game.battlecraft.logic.meta.scenario.script.ScriptExecutor)1 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)1 GOAL_TYPE (main.content.enums.system.AiEnums.GOAL_TYPE)1 DataManager (main.data.DataManager)1