Search in sources :

Example 1 with Action

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

the class AtomicAi method getAtomicMove.

public Action getAtomicMove(Coordinates pick, Unit unit) {
    List<Action> sequence = getTurnSequenceConstructor().getTurnSequence(FACING_SINGLE.IN_FRONT, getUnit(), pick);
    Action action = null;
    if (!sequence.isEmpty()) {
        action = sequence.get(0);
    }
    if (action == null) {
        try {
            action = DC_MovementManager.getFirstAction(unit, pick);
            main.system.auxiliary.log.LogMaster.log(1, " ATOMIC ACTION " + action + "  CHOSEN TO GET TO " + pick);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        // TODO what to return???
        }
    }
    return action;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction)

Example 2 with Action

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

the class AtomicAi method getAtomicAction.

public Action getAtomicAction(UnitAI ai) {
    Action action = null;
    if (checkAtomicActionTurn(ai)) {
        action = getAtomicActionTurn(ai);
        if (action != null) {
            action.setTaskDescription("Facing Adjustment");
            return action;
        }
    }
    action = getAtomicActionPrepare(ai);
    if (action != null) {
        action.setTaskDescription(TASK_DESCRIPTION.RESTORATION.toString());
        return action;
    }
    if (checkAtomicActionApproach(ai))
        action = getAtomicActionApproach(ai);
    if (action != null)
        action.setTaskDescription("Approach");
    else {
        SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, getUnit() + " finds no atomic action!");
        return null;
    }
    String message = getUnit() + " chooses atomic action: " + action;
    SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, message);
    return action;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction)

Example 3 with Action

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

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

the class ActionSequenceConstructor method constructSingleActionSequence.

public ActionSequence constructSingleActionSequence(Action targetAction, Task task) {
    List<Action> actions = new ArrayList<>();
    UnitAI ai = task.getAI();
    targetAction.getRef().setID(KEYS.ACTIVE, targetAction.getActive().getId());
    switch(task.getType()) {
        case ATTACK:
            {
                // only facing!
                actions = constructSingleAttackSequence(targetAction, task);
                break;
            }
        case DEBUFF:
        case BUFF:
            actions.addAll(getTurnSequenceConstructor().getTurnSequence(targetAction));
            actions.add(targetAction);
            break;
        // break;
        default:
            actions.add(targetAction);
            break;
    }
    if (actions.isEmpty()) {
        return null;
    }
    // not very good
    Action action = actions.get(0);
    if (!action.canBeActivated()) {
        LogMaster.log(LOG_CHANNEL.AI_DEBUG2, "No sequence for " + actions.get(actions.size() - 1) + " - " + action.getActive().getName() + ": " + action.getActive().getCosts().getReason());
        return null;
    }
    return new ActionSequence(actions, task, ai);
}
Also used : AiQuickItemAction(eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction) Action(eidolons.game.battlecraft.ai.elements.actions.Action) UnitAI(eidolons.game.battlecraft.ai.UnitAI) ArrayList(java.util.ArrayList)

Example 5 with Action

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

the class ActionSequenceConstructor method getSequences.

private List<ActionSequence> getSequences(Task task, DC_ActiveObj active) {
    List<ActionSequence> sequences = new ArrayList<>();
    Ref ref = task.getUnit().getRef().getCopy();
    Integer arg = TaskManager.checkTaskArgReplacement(task, active);
    // if (arg == null) {
    // if (isArgNeeded(active))     return;
    // }
    ref.setTarget(arg);
    List<ActionSequence> newSequences = null;
    Action action = AiActionFactory.newAction(active, ref);
    action.setTask(task);
    try {
        newSequences = getSequencesWithPathsForAction(action, task.getArg(), task);
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    if (ListMaster.isNotEmpty(newSequences)) {
        sequences.addAll(newSequences);
    } else {
        // if no pathing is required/available [QUICK FIX]
        if (!action.canBeTargetedOnAny()) {
            return sequences;
        }
        ActionSequence sequence = constructSingleActionSequence(action, task);
        if (sequence != null) {
            if (active.isRanged()) {
                sequences.addAll(AiUnitActionMaster.splitRangedSequence(sequence));
            } else {
                sequences.add(sequence);
            }
        } else {
        // if (unit.getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_NONE)
        // TODO smarter logging?
        // main.system.auxiliary.LogMaster.log(1, "***" +
        // action.toString()
        // + " could not be constructed into an action sequence!");
        // return;
        }
    }
    return sequences;
}
Also used : Ref(main.entity.Ref) AiQuickItemAction(eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ArrayList(java.util.ArrayList)

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