Search in sources :

Example 21 with Action

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

the class PathBuilder method checkAddFaceTurn.

private void checkAddFaceTurn() {
    unit.setFacing(c_facing);
    unit.setCoordinates(c_coordinate);
    if (ReasonMaster.checkReasonCannotTarget(FILTER_REASON.FACING, targetAction)) {
        List<Action> sequence = getTurnSequenceConstructor().getTurnSequence(targetAction);
        for (Action a : sequence) {
            path.add(new Choice(c_coordinate, a));
        }
    }
    unit.setFacing(originalFacing);
    unit.setCoordinates(originalCoordinate);
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action)

Example 22 with Action

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

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

the class DC_MovementManager method buildPath.

public List<ActionPath> buildPath(Unit unit, Coordinates coordinates) {
    List<DC_ActiveObj> moves = getMoves(unit);
    PathBuilder builder = PathBuilder.getInstance().init(moves, new Action(unit.getAction("Move")));
    List<ActionPath> paths = builder.build(new ListMaster<Coordinates>().getList(coordinates));
    if (paths.isEmpty()) {
        return null;
    }
    return paths;
}
Also used : PathBuilder(eidolons.game.battlecraft.ai.tools.path.PathBuilder) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) ListMaster(main.system.auxiliary.data.ListMaster) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 24 with Action

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

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

the class Choice method getTurns.

public Boolean[] getTurns() {
    if (actions.size() == 1 || turns != null) {
        return turns;
    }
    try {
        List<Boolean> list = new ArrayList<>();
        for (Action a : actions) {
            DC_ActiveObj active = a.getActive();
            if (active.getName().contains("lockwise")) {
                if (!active.isConstructed()) {
                    active.construct();
                }
                for (Effect e : active.getAbilities().getEffects()) {
                    if (e instanceof ChangeFacingEffect) {
                        list.add(((ChangeFacingEffect) e).isClockwise());
                    }
                }
            }
        }
        turns = list.toArray(new Boolean[list.size()]);
        return turns;
    } catch (Exception e) {
    }
    return null;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) ChangeFacingEffect(eidolons.ability.effects.oneshot.mechanic.ChangeFacingEffect) ArrayList(java.util.ArrayList) ChangeFacingEffect(eidolons.ability.effects.oneshot.mechanic.ChangeFacingEffect) Effect(main.ability.effects.Effect) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

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