Search in sources :

Example 1 with ActionSequence

use of eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence 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 ActionSequence

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

the class ActionManager method getForcedAction.

public Action getForcedAction(UnitAI ai) {
    BEHAVIOR_MODE behaviorMode = ai.getBehaviorMode();
    GOAL_TYPE goal = AiEnums.GOAL_TYPE.PREPARE;
    Action action = null;
    if (behaviorMode != null) {
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.PANIC) {
            action = new Action(ai.getUnit().getAction("Cower"));
        }
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.CONFUSED) {
            action = new Action(ai.getUnit().getAction("Stumble"));
        }
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.BERSERK) {
            action = new Action(ai.getUnit().getAction("Rage"));
        }
        action.setTaskDescription("Forced Behavior");
    }
    action = getAtomicAi().getAtomicActionForced(ai);
    if (action != null)
        return action;
    try {
        action = getAtomicAi().getAtomicActionPrepare(getUnit().getAI());
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    if (action != null) {
        return action;
    }
    List<ActionSequence> actions = getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai);
    if (ai.checkMod(AI_MODIFIERS.TRUE_BRUTE)) {
        goal = AiEnums.GOAL_TYPE.ATTACK;
        actions.addAll(getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai));
    }
    if (behaviorMode == null) {
        if (ParamAnalyzer.isFatigued(getUnit())) {
            actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Rest.name())));
        }
        if (ParamAnalyzer.isHazed(getUnit())) {
            // when is that used?
            actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Concentrate.name())));
        }
    }
    if (actions.isEmpty()) {
        return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
    }
    ActionSequence sequence = getPriorityManager().chooseByPriority(actions);
    LogMaster.log(1, getUnit() + " has been Forced to choose " + "" + sequence + " with priorioty of " + sequence.getPriority());
    getMaster().getMessageBuilder().append("Forced Task: " + sequence.getTask().toShortString());
    action = sequence.nextAction();
    if (action == null) {
        return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
    }
    return action;
}
Also used : DC_UnitAction(eidolons.entity.active.DC_UnitAction) Goal(eidolons.game.battlecraft.ai.elements.goal.Goal) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) BEHAVIOR_MODE(main.content.enums.system.AiEnums.BEHAVIOR_MODE)

Example 3 with ActionSequence

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

the class ExplorationAiMaster method getOrders.

private ActionSequence getOrders(UnitAI ai) {
    if (// TODO
    ai.getUnit().isMine())
        if (master.getPartyMaster().isFollowOn(ai.getUnit())) {
            // isFollow
            Action move = master.getPartyMaster().getFollowMove(ai.getUnit());
            if (move == null) {
                return null;
            // return getIdleOrders(ai);
            } else {
                return new ActionSequence(GOAL_TYPE.MOVE, move);
            }
        }
    // get orders?
    AiBehavior behavior = getAiBehavior(ai);
    ActionSequence orders = behavior.getOrders(ai);
    if (orders == null) {
    // orders= getIdleOrders(ai);
    }
    return orders;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) AiBehavior(eidolons.game.module.dungeoncrawl.ai.AiBehavior)

Example 4 with ActionSequence

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

the class PriorityManagerImpl method setPriorities.

@Override
public void setPriorities(List<ActionSequence> actions) {
    Chronos.mark("Priority calc");
    setUnit(actions.get(0).getAi().getUnit());
    setUnitAi(actions.get(0).getAi());
    for (ActionSequence as : actions) {
        Integer mod = getUnitAi().getGoalPriorityMod(as.getTask().getType());
        if (mod == null) {
            mod = 0;
        }
        mod += getPriorityModifier().getPriorityModifier(as);
        if (getMetaGoalMaster().isOn())
            try {
                getUnitAi().setMetaGoals(getMetaGoalMaster().initMetaGoalsForUnit(getUnitAi()));
                mod += getMetaGoalMaster().getPriorityMultiplier(as);
            } catch (Exception e) {
                main.system.ExceptionMaster.printStackTrace(e);
            }
        as.setPriorityMultiplier(mod);
    }
    for (ActionSequence action : actions) {
        // debug!
        if (action == null) {
            continue;
        }
        // Chronos.mark("Calculating priority for " + action);
        int priority = -1;
        try {
            priority = getPriority(action);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
        // Chronos.logTimeElapsedForMark("Calculating priority for " +
        // action);
        action.setPriority(priority);
    }
    Chronos.logTimeElapsedForMark("Priority calc");
}
Also used : ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)

Example 5 with ActionSequence

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

the class PriorityManagerImpl method getByPriority.

public ActionSequence getByPriority(List<ActionSequence> actions) {
    Chronos.mark("Priority sorting ");
    ActionSequence sequence = new FuncMaster<ActionSequence>().getGreatest_(actions, a -> a.getPriority());
    Chronos.logTimeElapsedForMark("Priority sorting ");
    return sequence;
}
Also used : ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)

Aggregations

ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)13 Action (eidolons.game.battlecraft.ai.elements.actions.Action)7 DC_UnitAction (eidolons.entity.active.DC_UnitAction)5 Coordinates (main.game.bf.Coordinates)5 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)3 ArrayList (java.util.ArrayList)3 GOAL_TYPE (main.content.enums.system.AiEnums.GOAL_TYPE)3 Unit (eidolons.entity.obj.unit.Unit)2 UnitAI (eidolons.game.battlecraft.ai.UnitAI)2 Goal (eidolons.game.battlecraft.ai.elements.goal.Goal)2 Task (eidolons.game.battlecraft.ai.elements.task.Task)2 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)2 Obj (main.entity.obj.Obj)2 DC_QuickItemAction (eidolons.entity.active.DC_QuickItemAction)1 DC_Obj (eidolons.entity.obj.DC_Obj)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