Search in sources :

Example 56 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj 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 57 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class DC_MovementManager method move.

public boolean move(Unit obj, DC_Cell cell, boolean free, Path path, MOVE_MODIFIER mod, Ref ref) {
    // if (path == null) {
    // if (!free)
    // path = getPath(obj, cell); // TODO just preCheck if it's blocked
    // }
    // if (!free)
    // if (!canMove(obj, cell))
    // return false;
    Ref REF = new Ref(obj.getGame());
    REF.setTarget(cell.getId());
    REF.setSource(obj.getId());
    LogMaster.log(LogMaster.MOVEMENT_DEBUG, "Moving " + obj + " to " + cell);
    Event event = new Event(STANDARD_EVENT_TYPE.UNIT_BEING_MOVED, REF);
    if (!game.fireEvent(event)) {
        return false;
    }
    // double cost = (!free) ? path.traverse(obj) : 0;
    // int _cost = getIntegerCost(cost);
    // for AI simulation only!
    // obj.modifyParameter(PARAMS.C_N_OF_MOVES, -_cost, 0);
    // obj.modifyParameter(PARAMS.C_N_OF_ACTIONS, -_cost, 0);
    Coordinates c = cell.getCoordinates();
    if (mod != MOVE_MODIFIER.TELEPORT) {
        // TODO UPDATE!
        Unit moveObj = (Unit) getGrid().getObj(cell.getCoordinates());
        if (moveObj != null) {
            if (ref.getActive() instanceof DC_ActiveObj) {
                DC_ActiveObj activeObj = (DC_ActiveObj) ref.getActive();
                if (moveObj instanceof Unit) {
                    Unit heroObj = moveObj;
                    c = CollisionRule.collision(ref, activeObj, moveObj, heroObj, false, activeObj.getIntParam(PARAMS.FORCE));
                    if (c == null) {
                        // displaced by Collision rule?
                        return true;
                    }
                }
            }
        }
    }
    if (obj.isDead()) {
        return false;
    }
    if (!game.getRules().getStackingRule().canBeMovedOnto(obj, c)) {
        return false;
    }
    if (game.getObjectByCoordinate(c) instanceof BattleFieldObject) {
        if (((BattleFieldObject) game.getObjectByCoordinate(c)).isWall()) {
            return false;
        }
    }
    if (!game.getRules().getEngagedRule().unitMoved(obj, c.x, c.y)) {
        return false;
    }
    obj.setCoordinates(c);
    event = new Event(STANDARD_EVENT_TYPE.UNIT_FINISHED_MOVING, REF);
    return game.fireEvent(event);
}
Also used : Ref(main.entity.Ref) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) Event(main.game.logic.event.Event) Unit(eidolons.entity.obj.unit.Unit) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 58 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj 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 59 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj 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)

Example 60 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class StealthRule method actionComplete.

public void actionComplete(ActiveObj active) {
    if (!isOn())
        return;
    // perhaps only moves?
    DC_ActiveObj action = (DC_ActiveObj) active;
    Unit source = action.getOwnerObj();
    List<? extends DC_Obj> list = Analyzer.getEnemies(source, false, false, false);
    list.removeIf(unit -> {
        double d = PositionMaster.getExactDistance(source, unit);
        if ((d > getMaxDistance(source, unit))) {
            return true;
        }
        if ((d > getMaxDistance((Unit) unit, source))) {
            return true;
        }
        return false;
    });
    for (DC_Obj sub : list) {
        Unit unit = (Unit) sub;
        double d = PositionMaster.getExactDistance(source, unit);
        if ((d <= getMaxDistance(unit, source))) {
            if (isSpotRollAllowed(unit, source)) {
                rollSpotted(unit, source);
            }
        }
        if ((d <= getMaxDistance(source, unit))) {
            if (isSpotRollAllowed(source, unit)) {
                rollSpotted(source, unit);
            }
        }
    }
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Unit(eidolons.entity.obj.unit.Unit)

Aggregations

DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)73 Unit (eidolons.entity.obj.unit.Unit)22 ArrayList (java.util.ArrayList)17 Obj (main.entity.obj.Obj)15 DC_UnitAction (eidolons.entity.active.DC_UnitAction)12 DC_Obj (eidolons.entity.obj.DC_Obj)12 Ref (main.entity.Ref)9 Action (eidolons.game.battlecraft.ai.elements.actions.Action)8 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)7 ActiveObj (main.entity.obj.ActiveObj)7 Effect (main.ability.effects.Effect)5 SelectiveTargeting (main.elements.targeting.SelectiveTargeting)5 Targeting (main.elements.targeting.Targeting)5 AddBuffEffect (eidolons.ability.effects.attachment.AddBuffEffect)4 DC_SpellObj (eidolons.entity.active.DC_SpellObj)4 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)4 FixedTargeting (main.elements.targeting.FixedTargeting)4 Coordinates (main.game.bf.Coordinates)4 RollEffect (eidolons.ability.effects.oneshot.mechanic.RollEffect)3 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)3