Search in sources :

Example 1 with Coordinates

use of main.game.bf.Coordinates in project Eidolons by IDemiurge.

the class AtomicAi method getHotZoneCell.

private Coordinates getHotZoneCell(UnitAI ai, Boolean approach_retreat_search) {
    ATOMIC_LOGIC logic = getAtomicLogic(ai);
    List<Unit> enemies = Analyzer.getVisibleEnemies(ai);
    List<Unit> allies = Analyzer.getAllies(ai);
    float greatest = 0;
    Coordinates pick = null;
    for (Coordinates c : ai.getUnit().getCoordinates().getAdjacentCoordinates()) {
        float i = 0;
        i += getCellPriority(c, ai);
        if (BooleanMaster.isFalse(approach_retreat_search)) {
            for (Unit a : allies) {
                i += getAllyPriority(c, a, ai, logic) + RandomWizard.getRandomInt(10);
            }
        }
        for (Unit e : enemies) {
            i = i + ((approach_retreat_search ? 1 : -1) * getEnemyPriority(c, e, ai, logic)) + RandomWizard.getRandomInt(10);
        }
        i = i * getCellPriorityMod(c, ai) / 100;
        if (i > greatest) {
            greatest = i;
            pick = c;
        }
    }
    return pick;
}
Also used : Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit)

Example 2 with Coordinates

use of main.game.bf.Coordinates in project Eidolons by IDemiurge.

the class AtomicAi method getApproachCoordinate.

private Coordinates getApproachCoordinate(UnitAI ai) {
    Collection<Unit> units = getAnalyzer().getVisibleEnemies(ai);
    if (units.isEmpty())
        return null;
    FACING_DIRECTION facing = FacingMaster.getOptimalFacingTowardsUnits(getUnit().getCoordinates(), units, t -> getThreatAnalyzer().getThreat(ai, (Unit) t));
    if (facing == null)
        return null;
    Coordinates c = getUnit().getCoordinates().getAdjacentCoordinate(facing.getDirection());
    return Positioner.adjustCoordinate(ai.getUnit(), c, ai.getUnit().getFacing());
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit)

Example 3 with Coordinates

use of main.game.bf.Coordinates 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 4 with Coordinates

use of main.game.bf.Coordinates in project Eidolons by IDemiurge.

the class PathSequenceConstructor method getTargetCells.

private List<Coordinates> getTargetCells(Action targetAction) {
    if (targetAction.isDummy()) {
        return new ListMaster<Coordinates>().getList(targetAction.getTarget().getCoordinates());
    }
    if (targetAction.getActive().getName().equalsIgnoreCase(StringMaster.getWellFormattedString(STD_SPEC_ACTIONS.Guard_Mode.toString()))) {
        return new ListMaster<Coordinates>().toList_(targetAction.getTask().getObjArg().getCoordinates());
    }
    Boolean fastPickClosestToTargetOrSelf = null;
    if (TimeLimitMaster.isFastPickCell()) {
        if (targetAction.getActive().isRanged()) {
            fastPickClosestToTargetOrSelf = false;
        }
        if (targetAction.getActive().isMelee()) {
            // if (targetAction.getSource().getAiType()!= AI_TYPE.SNEAK) TODO just behind!
            fastPickClosestToTargetOrSelf = true;
        }
    }
    Coordinates originalCoordinate = getUnit().getCoordinates();
    List<Coordinates> list = cellsCache.get(targetAction.getTargeting());
    if (list != null) {
        return list;
    }
    list = new ArrayList<>();
    try {
        if (fastPickClosestToTargetOrSelf != null) {
            double min = Integer.MAX_VALUE;
            DC_Obj center = fastPickClosestToTargetOrSelf ? targetAction.getTarget() : targetAction.getSource();
            for (Coordinates c : center.getCoordinates().getAdjacentCoordinates()) {
                if (// TODO
                !TargetingMaster.isValidTargetingCell(targetAction, c, getUnit())) {
                    continue;
                }
                double distance = PositionMaster.getExactDistance(c, originalCoordinate);
                if (distance <= min) {
                    list = new ListMaster<Coordinates>().getList(c);
                    min = distance;
                }
            }
        }
        if (list.isEmpty()) {
            // TODO prioritizedCells;
            List<Coordinates> coordinatesList = null;
            if (!ListMaster.isNotEmpty(coordinatesList)) {
                coordinatesList = getUnit().getGame().getBattleField().getGrid().getCoordinatesList();
            }
            // prune by distance/direction from target?
            for (Coordinates c : coordinatesList) {
                if (!TargetingMaster.isValidTargetingCell(targetAction, c, getUnit())) {
                    continue;
                }
                // TODO causes visuals!
                getUnit().setCoordinates(c);
                if (TargetingMaster.canBeTargeted(targetAction, true, true)) {
                    list.add(c);
                }
            }
        }
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    } finally {
        getUnit().setCoordinates(originalCoordinate);
    }
    if (list.size() > 1) {
        list = getPruneMaster().pruneTargetCells(targetAction, list);
    }
    if (getUnit().getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_BASIC) {
        LogMaster.log(LOG_CHANNEL.AI_DEBUG, "***" + targetAction + " has target cells for PB: " + list);
    }
    cellsCache.put(targetAction.getTargeting(), list);
    return list;
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) Coordinates(main.game.bf.Coordinates) ListMaster(main.system.auxiliary.data.ListMaster)

Example 5 with Coordinates

use of main.game.bf.Coordinates in project Eidolons by IDemiurge.

the class AI_Manager method getAction.

public Action getAction(Unit unit) {
    if (unit.isMine()) {
        unit.getQuickItemActives();
    }
    messageBuilder = new StringBuffer();
    Action action = null;
    running = true;
    setUnit(unit);
    Coordinates bufferedCoordinates = unit.getCoordinates();
    try {
        action = actionManager.chooseAction();
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    } finally {
        running = false;
    }
    if (action == null) {
        running = true;
        try {
            action = actionManager.getForcedAction(getAI(unit));
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        } finally {
            running = false;
            SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, getUnit() + " opts for Forced Action: " + action);
        }
    } else {
        try {
            getMessageBuilder().append("Task: " + action.getTaskDescription());
            if (!CoreEngine.isGraphicsOff()) {
                if (game.isDebugMode() || Launcher.DEV_MODE)
                    FloatingTextMaster.getInstance().createFloatingText(TEXT_CASES.BATTLE_COMMENT, getMessageBuilder().toString(), getUnit());
            }
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    }
    if (!bufferedCoordinates.equals(unit.getCoordinates())) {
        unit.setCoordinates(bufferedCoordinates);
    }
    return action;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates)

Aggregations

Coordinates (main.game.bf.Coordinates)226 Unit (eidolons.entity.obj.unit.Unit)49 ObjType (main.entity.type.ObjType)30 ArrayList (java.util.ArrayList)29 Obj (main.entity.obj.Obj)28 DC_Obj (eidolons.entity.obj.DC_Obj)22 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)21 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)21 DIRECTION (main.game.bf.Coordinates.DIRECTION)20 Ref (main.entity.Ref)15 MapBlock (eidolons.game.battlecraft.logic.dungeon.location.building.MapBlock)13 DC_Cell (eidolons.entity.obj.DC_Cell)12 Action (eidolons.game.battlecraft.ai.elements.actions.Action)11 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)9 BufferedImage (java.awt.image.BufferedImage)8 DequeImpl (main.system.datatypes.DequeImpl)8 Vector2 (com.badlogic.gdx.math.Vector2)7 DC_UnitAction (eidolons.entity.active.DC_UnitAction)7 ZCoordinates (main.game.bf.ZCoordinates)6 ObjAtCoordinate (main.entity.type.ObjAtCoordinate)5