Search in sources :

Example 1 with UnitAI

use of eidolons.game.battlecraft.ai.UnitAI 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 UnitAI

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

use of eidolons.game.battlecraft.ai.UnitAI in project Eidolons by IDemiurge.

the class ExplorationAiMaster method checkAiActs.

public void checkAiActs() {
    // master.getGame().getAiManager().getBehaviorMaster().
    activeUnitAIs.forEach(ai -> ai.setExplorationTimePassed(master.getTimeMaster().getTime() - ai.getExplorationTimeOfLastAction()));
    // if (isAiActs())
    // return;
    boolean isAiActs = false;
    for (UnitAI ai : activeUnitAIs) {
        if (!ExplorationMaster.isExplorationOn())
            return;
        if (ai.getExplorationTimePassed() <= ExplorationTimeMaster.secondsPerAP)
            continue;
        double distance = PositionMaster.getExactDistance(ai.getUnit().getCoordinates(), Eidolons.getMainHero().getCoordinates());
        if (distance > getMaxDistance(ai))
            continue;
        try {
            if (tryMoveAi(ai))
                isAiActs = true;
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    }
    if (isAiActs) {
        aiActs = true;
        if (ExplorationMaster.isExplorationOn())
            master.getLoop().signal();
    }
}
Also used : UnitAI(eidolons.game.battlecraft.ai.UnitAI)

Example 4 with UnitAI

use of eidolons.game.battlecraft.ai.UnitAI in project Eidolons by IDemiurge.

the class AtomicAi method checkAtomicActionApproach.

public boolean checkAtomicActionApproach(UnitAI ai) {
    if (ai.getCurrentOrder() != null)
        if (ai.getCurrentOrder().getStrictPriority() != ORDER_PRIORITY_MODS.ATTACK && ai.getCurrentOrder().getStrictPriority() != ORDER_PRIORITY_MODS.APPROACH)
            return false;
    double maxDistance = getDistanceForAtomicApproach(ai);
    double minDistance = -1;
    for (Unit sub : Analyzer.getVisibleEnemies(ai)) {
        if (game.getVisionMaster().getSightMaster().getClearShotCondition().check(getUnit(), sub)) {
            double distance = PositionMaster.getExactDistance(getUnit(), sub);
            if (distance < minDistance)
                minDistance = distance;
        }
    }
    if (minDistance < 0) {
        return false;
    }
    minDistance -= Analyzer.getVisibleEnemies(ai).size();
    minDistance += ai.getGroup().getMembers().size();
    Double average = ai.getGroup().getMembers().stream().collect(Collectors.averagingInt((t) -> t.getIntParam(PARAMS.POWER)));
    Integer p = ai.getUnit().getIntParam(PARAMS.POWER);
    minDistance -= p / average;
    minDistance += average / p;
    return minDistance > maxDistance;
}
Also used : DUNGEON_OBJ_TYPE(eidolons.game.module.dungeoncrawl.objects.DungeonObj.DUNGEON_OBJ_TYPE) BooleanMaster(main.system.auxiliary.secondary.BooleanMaster) STD_SPEC_ACTIONS(eidolons.entity.active.DC_ActionManager.STD_SPEC_ACTIONS) Analyzer(eidolons.game.battlecraft.ai.tools.Analyzer) DC_QuickItemObj(eidolons.entity.item.DC_QuickItemObj) PARAMS(eidolons.content.PARAMS) AiHandler(eidolons.game.battlecraft.ai.elements.generic.AiHandler) DC_MovementManager(eidolons.game.battlecraft.logic.battlefield.DC_MovementManager) DOOR_ACTION(eidolons.game.module.dungeoncrawl.objects.DoorMaster.DOOR_ACTION) STD_MODE_ACTIONS(eidolons.entity.active.DC_ActionManager.STD_MODE_ACTIONS) AiMaster(eidolons.game.battlecraft.ai.elements.generic.AiMaster) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE) AI_TYPE(main.content.enums.system.AiEnums.AI_TYPE) Positioner(eidolons.game.battlecraft.logic.dungeon.universal.Positioner) Ref(main.entity.Ref) FacingMaster(eidolons.game.battlecraft.logic.battlefield.FacingMaster) SPECIAL_LOG(main.system.auxiliary.log.FileLogger.SPECIAL_LOG) PositionMaster(main.system.math.PositionMaster) AiConst(eidolons.game.battlecraft.ai.advanced.machine.AiConst) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ListMaster(main.system.auxiliary.data.ListMaster) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ORDER_PRIORITY_MODS(main.content.enums.system.AiEnums.ORDER_PRIORITY_MODS) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) TASK_DESCRIPTION(eidolons.game.battlecraft.ai.elements.task.Task.TASK_DESCRIPTION) Collection(java.util.Collection) STANDARD_PASSIVES(main.content.enums.entity.UnitEnums.STANDARD_PASSIVES) FuncMaster(main.system.math.FuncMaster) Collectors(java.util.stream.Collectors) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) RandomWizard(main.system.auxiliary.RandomWizard) ParamAnalyzer(eidolons.game.battlecraft.ai.tools.ParamAnalyzer) SpecialLogger(main.system.auxiliary.log.SpecialLogger) List(java.util.List) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Door(eidolons.game.module.dungeoncrawl.objects.Door) AiActionFactory(eidolons.game.battlecraft.ai.elements.actions.AiActionFactory) AI_MODIFIERS(main.content.CONTENT_CONSTS2.AI_MODIFIERS) Coordinates(main.game.bf.Coordinates) DC_PriorityManager(eidolons.game.battlecraft.ai.tools.priority.DC_PriorityManager) Unit(eidolons.entity.obj.unit.Unit) DOOR_STATE(eidolons.game.module.dungeoncrawl.objects.DoorMaster.DOOR_STATE) Unit(eidolons.entity.obj.unit.Unit)

Example 5 with UnitAI

use of eidolons.game.battlecraft.ai.UnitAI in project Eidolons by IDemiurge.

the class ActionManager method chooseAction.

public Action chooseAction() {
    UnitAI ai = getMaster().getUnitAI();
    if (ai.checkStandingOrders()) {
        return ai.getStandingOrders().get(0);
    }
    // TODO try not to? :)
    getPathSequenceConstructor().clearCache();
    if (getUnit() != ai.getUnit()) {
        getCellPrioritizer().reset();
    } else {
    }
    checkDeactivate();
    if (ListMaster.isNotEmpty(ai.getForcedActions())) {
        Action action = ai.getForcedActions().get(0);
        ai.getForcedActions().remove(0);
        return action;
    }
    // if (!ai.isEngaged()) {
    // TODO      return behaviorMaster.getBehaviorAction(ai);
    // }
    FACING_DIRECTION originalFacing = getUnit().getFacing();
    Coordinates originalCoordinates = getUnit().getCoordinates();
    Action action = null;
    ActionSequence chosenSequence = null;
    boolean atomic = false;
    if (isAtomicAiOn())
        try {
            atomic = getAtomicAi().checkAtomicActionRequired(ai);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    if (atomic)
        if (isAtomicAiOn())
            try {
                action = getAtomicAi().getAtomicAction(ai);
            } catch (Exception e) {
                main.system.ExceptionMaster.printStackTrace(e);
                action = getAtomicAi().getAtomicWait(ai.getUnit());
            }
    if (action == null) {
        List<ActionSequence> actions = new ArrayList<>();
        try {
            List<ActionSequence> sequences = getActionSequenceConstructor().createActionSequences(ai);
            for (ActionSequence a : sequences) {
                if (a.get(0).canBeActivated()) {
                    // if (a.getOrCreate(0).canBeTargeted())
                    actions.add(a);
                }
            }
            if (ListMaster.isNotEmpty(actions)) {
                chosenSequence = DC_PriorityManager.chooseByPriority(actions);
            }
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        } finally {
            getUnit().setCoordinates(originalCoordinates);
            getUnit().setFacing(originalFacing);
        }
    }
    if (chosenSequence == null) {
        if (action == null) {
            action = getForcedAction(ai);
        }
        return action;
    } else {
        if (chosenSequence.getType() == GOAL_TYPE.DEFEND)
            return chosenSequence.nextAction();
    }
    if (getUnit().getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_NONE) {
        if (Launcher.DEV_MODE)
            game.getLogManager().log(LOG.GAME_INFO, ai.getUnit().getName() + " chooses task: " + chosenSequence.getTask().toShortString());
        String message = getUnit() + " has chosen: " + chosenSequence + " with priority of " + StringMaster.wrapInParenthesis(chosenSequence.getPriority() + "");
        LogMaster.log(LOG_CHANNEL.AI_DEBUG, message);
        SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, message);
    }
    // TODO for behaviors? ai-issued-orders?
    ai.checkSetOrders(chosenSequence);
    return chosenSequence.nextAction();
}
Also used : DC_UnitAction(eidolons.entity.active.DC_UnitAction) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList)

Aggregations

UnitAI (eidolons.game.battlecraft.ai.UnitAI)8 Unit (eidolons.entity.obj.unit.Unit)3 Action (eidolons.game.battlecraft.ai.elements.actions.Action)3 ArrayList (java.util.ArrayList)3 Coordinates (main.game.bf.Coordinates)3 DC_UnitAction (eidolons.entity.active.DC_UnitAction)2 AiActionFactory (eidolons.game.battlecraft.ai.elements.actions.AiActionFactory)2 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)2 AiHandler (eidolons.game.battlecraft.ai.elements.generic.AiHandler)2 AiMaster (eidolons.game.battlecraft.ai.elements.generic.AiMaster)2 Task (eidolons.game.battlecraft.ai.elements.task.Task)2 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)2 Ref (main.entity.Ref)2 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)2 PARAMS (eidolons.content.PARAMS)1 STD_MODE_ACTIONS (eidolons.entity.active.DC_ActionManager.STD_MODE_ACTIONS)1 STD_SPEC_ACTIONS (eidolons.entity.active.DC_ActionManager.STD_SPEC_ACTIONS)1 DC_QuickItemObj (eidolons.entity.item.DC_QuickItemObj)1 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)1 GroupAI (eidolons.game.battlecraft.ai.GroupAI)1