Search in sources :

Example 6 with ActionSequence

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

the class TargetingMaster method selectTargetForAction.

public static Integer selectTargetForAction(DC_ActiveObj a) {
    /*
         * getOrCreate possible targets init goal type prioritize
		 */
    GOAL_TYPE type = GoalManager.getGoalFromAction(a);
    Obj target = null;
    int max_priority = Integer.MIN_VALUE;
    Set<Obj> objects = null;
    a.getTargeting().getFilter().setRef(a.getRef());
    try {
        objects = a.getTargeting().getFilter().getObjects();
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    for (Obj obj : objects) {
        ActionSequence sequence = new ActionSequence(type, new Action(a, obj));
        sequence.setAi(a.getOwnerObj().getUnitAI());
        sequence.setType(type);
        int priority = DC_PriorityManager.getPriority(sequence);
        if (priority > max_priority) {
            target = obj;
            max_priority = priority;
        }
    }
    if (target == null) {
        return null;
    }
    return target.getId();
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) ActiveObj(main.entity.obj.ActiveObj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE)

Example 7 with ActionSequence

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

the class PriorityManagerImpl method applyConvergingPathsPriorities.

public void applyConvergingPathsPriorities(List<ActionSequence> actions) {
    // TODO make sure that they are not pruned at path-building phase!
    // split into groups and for each group, add bonus per group member!
    Map<Action, List<ActionSequence>> asGroups = new HashMap<>();
    for (ActionSequence as : actions) {
        Action firstAction = as.get(0);
        List<ActionSequence> group = asGroups.get(firstAction);
        if (group == null) {
            group = new ArrayList<>();
            asGroups.put(firstAction, group);
        }
        group.add(as);
    }
    for (Action firstAction : asGroups.keySet()) {
        for (ActionSequence as : asGroups.get(firstAction)) {
            for (ActionSequence as2 : asGroups.get(firstAction)) {
                if (as2 == as) {
                    continue;
                }
                if (as2.getLastAction().getTarget() != null) {
                    if (as2.getLastAction().getTarget().equals(as.getLastAction().getTarget())) {
                        continue;
                    }
                }
                int bonus = MathMaster.round(as2.getPriority() / asGroups.get(firstAction).size() * (getConstInt(AiConst.CONVERGING_FACTOR)));
                LogMaster.log(getLogChannel(), bonus + " Converging Paths bonus added to " + as.getPriority() + as.getActions() + " from " + as2.getPriority() + as2.getActions());
                as.setPriority(as.getPriority() + bonus);
            }
        }
    }
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) AiQuickItemAction(eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction) DC_UnitAction(eidolons.entity.active.DC_UnitAction) DC_QuickItemAction(eidolons.entity.active.DC_QuickItemAction) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)

Example 8 with ActionSequence

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

the class CellPrioritizer method getPriorityForCell.

/*
     * Perhaps one could feed an action to this method!.. Or actions...
     */
public int getPriorityForCell(Unit unit, Obj cell, DC_ActiveObj targetAcsdftion) {
    /*
         * getOrCreate attack priority for each adjacent enemy...
		 */
    /*
         * I could exclude paths for zone spells, let the range be the limit for
		 * now
		 */
    int priority = 0;
    List<ActionPath> paths = pathMap.get(cell.getCoordinates());
    if (paths == null) {
        paths = getPathBuilder().init(moves, targetAction).build(new ListMaster<Coordinates>().getList(cell.getCoordinates()));
        pathMap.put(cell.getCoordinates(), paths);
    }
    if (!ListMaster.isNotEmpty(paths)) {
        return 0;
    }
    int path_priority = paths.get(0).getPriority();
    for (Coordinates c : cell.getCoordinates().getAdjacentCoordinates()) {
        Obj targetObj = unit.getGame().getObjectByCoordinate(c, false);
        if (targetObj != null) {
            if (targetObj.getOBJ_TYPE_ENUM() != DC_TYPE.BF_OBJ) {
                if (Analyzer.isEnemy(targetObj, unit)) {
                    Integer cell_priority = enemyPriorityMap.get(targetObj);
                    if (cell_priority != null) {
                        priority += cell_priority;
                        continue;
                    }
                    Unit enemy = (Unit) targetObj;
                    cell_priority = DC_PriorityManager.getUnitPriority(targetObj);
                    // "now"?
                    cell_priority -= DC_PriorityManager.getMeleeThreat(enemy);
                    // should all AI-units *be afraid*? :) Maybe memory map
                    // will do nicely here?
                    // if ()
                    Action action = new Action(unit.getAction("attack"), enemy);
                    // if (melee )
                    // PriorityManager.getDamagePriority(action, targetObj,
                    // false);
                    priority += DC_PriorityManager.getAttackPriority(new ActionSequence(action));
                    DC_UnitAction offhand_attack = unit.getAction("offhand attack");
                    // use its priority?
                    if (offhand_attack != null) {
                        action = new Action(offhand_attack, enemy);
                        priority += DC_PriorityManager.getAttackPriority(new ActionSequence(action));
                    }
                    // do we calculate move costs before or after?
                    enemyPriorityMap.put(targetObj, cell_priority);
                    priority += cell_priority;
                }
            }
        }
    }
    priority += priority * path_priority / 100;
    return priority;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) DC_Obj(eidolons.entity.obj.DC_Obj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit) DC_UnitAction(eidolons.entity.active.DC_UnitAction)

Example 9 with ActionSequence

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

the class AiUnitActionMaster method splitRangedSequence.

public static List<ActionSequence> splitRangedSequence(ActionSequence sequence) {
    ArrayList<ActionSequence> list = new ArrayList<>();
    for (Action a : sequence.getActions()) {
        if (a instanceof AiQuickItemAction) {
            ArrayList<Action> actions = new ArrayList<>();
            actions.add(a);
            for (Action a1 : sequence.getActions()) {
                if (!(a1 instanceof AiQuickItemAction)) {
                    actions.add(a1);
                }
            }
            ActionSequence rangedSequence = new ActionSequence(actions, sequence.getTask(), sequence.getAi());
            list.add(rangedSequence);
        }
    }
    if (list.isEmpty()) {
        list.add(sequence);
    }
    return list;
}
Also used : DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) ArrayList(java.util.ArrayList)

Example 10 with ActionSequence

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

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