Search in sources :

Example 1 with Unit

use of eidolons.entity.obj.unit.Unit 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 Unit

use of eidolons.entity.obj.unit.Unit 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 Unit

use of eidolons.entity.obj.unit.Unit 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 Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class AiScriptExecutor method execute.

@Override
public boolean execute(COMBAT_SCRIPT_FUNCTION function, Ref ref, String... args) {
    if (args[0].equalsIgnoreCase("group")) {
    }
    int i = 0;
    Unit unit = (Unit) ref.getObj(args[0]);
    if (unit == null) {
        String name = args[i];
        if (DataManager.isTypeName(name))
            i++;
        else
            name = null;
        AI_ARG arg = new EnumMaster<AI_ARG>().retrieveEnumConst(AI_ARG.class, args[i]);
        unit = getUnit(arg);
        if (unit == null) {
            // getPower(arg);
            Boolean power = null;
            Boolean distance = getDistance(arg);
            Boolean ownership = getOwnership(arg);
            unit = getGame().getMaster().getUnitByName(name, ref, ownership, distance, power);
        }
    }
    i++;
    // group?
    // with frozen gameLoop?
    String arg = null;
    boolean free = false;
    boolean immediate = false;
    if (args.length > i) {
        String options = args[i + 1];
        i++;
        // if (StringMaster.contains(options, FREE)
        free = true;
        immediate = true;
        arg = options;
    }
    String[] additionalArgs = null;
    if (args.length > i) {
        additionalArgs = new String[args.length - i];
        for (int j = 0; j < args.length; j++) {
            additionalArgs[j] = args[i + j];
        }
    }
    executeCommand(unit, function, arg, free, immediate, additionalArgs);
    return true;
}
Also used : Unit(eidolons.entity.obj.unit.Unit)

Example 5 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class TurnSequenceConstructor method getTurnSequence.

public List<Action> getTurnSequence(Action action) {
    Conditions conditions = (action.getTargeting().getFilter().getConditions());
    FacingCondition condition = null;
    FACING_SINGLE template = null;
    DC_Obj target = action.getTarget();
    Unit source = (Unit) action.getRef().getSourceObj();
    for (Condition c : conditions) {
        if (c instanceof FacingCondition) {
            condition = (FacingCondition) c;
            break;
        }
        List<Object> list = ClassMaster.getInstances(c, FacingCondition.class);
        if (!list.isEmpty()) {
            List<Action> front_sequence = getTurnSequence(FACING_SINGLE.IN_FRONT, source, target.getCoordinates());
            List<Action> side_sequence = null;
            if (action.getSource().hasBroadReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.BROAD_REACH)) // front_sequence.remove(front_sequence.size() - 1);
            {
                side_sequence = getTurnSequence(FACING_SINGLE.TO_THE_SIDE, source, target.getCoordinates());
            }
            List<Action> hind_sequence = null;
            if (action.getSource().hasHindReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.HIND_REACH)) {
                hind_sequence = getTurnSequence(FACING_SINGLE.BEHIND, source, target.getCoordinates());
            }
            return new ListMaster<Action>().getSmallest(front_sequence, hind_sequence, side_sequence);
        }
    }
    // }
    if (condition == null) {
        return new ArrayList<>();
    }
    if (ArrayMaster.isNotEmpty(condition.getTemplate())) {
        template = condition.getTemplate()[0];
    }
    return getTurnSequence(template, source, target.getCoordinates());
}
Also used : FacingCondition(eidolons.ability.conditions.FacingCondition) Condition(main.elements.conditions.Condition) DC_Obj(eidolons.entity.obj.DC_Obj) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ArrayList(java.util.ArrayList) FacingCondition(eidolons.ability.conditions.FacingCondition) Unit(eidolons.entity.obj.unit.Unit) Conditions(main.elements.conditions.Conditions) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE)

Aggregations

Unit (eidolons.entity.obj.unit.Unit)258 Coordinates (main.game.bf.Coordinates)53 Ref (main.entity.Ref)33 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)30 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)26 DC_Obj (eidolons.entity.obj.DC_Obj)26 ArrayList (java.util.ArrayList)26 Obj (main.entity.obj.Obj)26 ObjType (main.entity.type.ObjType)23 DC_SpellObj (eidolons.entity.active.DC_SpellObj)13 DC_Cell (eidolons.entity.obj.DC_Cell)11 Event (main.game.logic.event.Event)11 DC_UnitAction (eidolons.entity.active.DC_UnitAction)10 List (java.util.List)10 DC_Game (eidolons.game.core.game.DC_Game)9 Action (eidolons.game.battlecraft.ai.elements.actions.Action)8 DequeImpl (main.system.datatypes.DequeImpl)8 OUTLINE_TYPE (main.content.enums.rules.VisionEnums.OUTLINE_TYPE)7 Entity (main.entity.Entity)7 DIRECTION (main.game.bf.Coordinates.DIRECTION)7