Search in sources :

Example 1 with GroupAI

use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.

the class BehaviorMaster method getAction.

private Action getAction(GOAL_TYPE type, UnitAI ai) {
    String action = null;
    Integer target = null;
    // doesn't the group have standing orders as a whole?..
    Unit unit = ai.getUnit();
    Ref ref = new Ref(unit);
    GroupAI group = ai.getGroup();
    // checkBehaviorChange(group); where does that happen?
    switch(type) {
        case AMBUSH:
            break;
        case STALK:
            break;
        case STAND_GUARD:
        case PATROL:
            PatrolMaster.getPatrolAction(ai);
        // having already turned on the Mode
        case SEARCH:
        case WANDER:
            if (ai.isLeader()) {
                Boolean change = WanderAi.checkWanderDirectionChange(group, type);
                if (change == null) {
                    action = getIdleAction(ai, type);
                    change = true;
                }
                // maybe go meet leader if blocked... or something like it
                if (change) {
                    group.getWanderStepCoordinateStack().push(group.getLeader().getCoordinates());
                    WanderAi.changeGroupMoveDirection(group, type);
                }
            }
            boolean wait = false;
            // ActionSequenceConstructor.getSequence(targetAction, task)
            Coordinates targetCoordinates = WanderAi.getCoordinates(type, ai);
            if (targetCoordinates == null) {
                wait = true;
            // if (!recursion)
            // return null;
            // recursion = true;
            // return getAction(type, ai);
            } else {
                action = STD_ACTIONS.Move.name();
                // if (!unit.getAction(action).canBeActivated()) {
                // }
                ActionPath path = getPathBuilder().init(new ListMaster<DC_ActiveObj>().getList(unit.getAction(action)), new Action(unit.getAction(action), new Ref(unit))).getPathByPriority(new ListMaster<Coordinates>().getList(targetCoordinates));
                if (path == null) {
                    // TODO preCheck if path
                    ai.setPathBlocked(true);
                // appropriate
                } else {
                    ai.setPathBlocked(false);
                    return path.getActions().get(0);
                }
            }
            if (wait) {
                action = getIdleAction(ai, type);
            } else {
            // if (change) {
            // targetCoordinates = WanderMaster.getCoordinates(type,
            // ai);
            // }
            // return path.getActions().getOrCreate(0);
            }
    }
    DC_ActiveObj active = unit.getAction(action);
    ref.setTarget(target);
    recursion = false;
    return new Action(active, ref);
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) Coordinates(main.game.bf.Coordinates) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) ListMaster(main.system.auxiliary.data.ListMaster) Unit(eidolons.entity.obj.unit.Unit) Ref(main.entity.Ref) GroupAI(eidolons.game.battlecraft.ai.GroupAI) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 2 with GroupAI

use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.

the class TestSpawner method initGroup.

private void initGroup(Wave group) {
    GroupAI groupAi = new GroupAI(group);
    groupAi.setLeader(group.getParty().getLeader());
    groupAi.setWanderDirection(FacingMaster.getRandomFacing().getDirection());
    group.setAi(groupAi);
    if (getGame().getGameMode() == GAME_MODES.DUNGEON_CRAWL) {
        XList<MapBlock> permittedBlocks = new XList<>();
        permittedBlocks.addAllUnique(group.getBlock().getConnectedBlocks().keySet());
        int wanderBlockDistance = 1;
        for (int i = 0; i < wanderBlockDistance; i++) {
            for (MapBlock b : group.getBlock().getConnectedBlocks().keySet()) {
                permittedBlocks.addAllUnique(b.getConnectedBlocks().keySet());
            }
        }
        groupAi.setPermittedBlocks(permittedBlocks);
    }
}
Also used : GroupAI(eidolons.game.battlecraft.ai.GroupAI) XList(main.data.XList) MapBlock(eidolons.game.battlecraft.logic.dungeon.location.building.MapBlock)

Example 3 with GroupAI

use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.

the class WanderAi method getCoordinates.

public static Coordinates getCoordinates(GOAL_TYPE type, UnitAI ai) {
    Coordinates targetCoordinates = WanderAi.getWanderTargetCoordinatesCell(ai, type);
    Unit unit = ai.getUnit();
    GroupAI group = ai.getGroup();
    boolean adjust = targetCoordinates == null;
    if (!adjust) {
        adjust = (!unit.getGame().getRules().getStackingRule().canBeMovedOnto(unit, targetCoordinates));
    }
    if (adjust) {
        Coordinates c = null;
        Loop loop = new Loop(50);
        while (loop.continues()) {
            c = Positioner.adjustCoordinate(targetCoordinates, null);
            if (c == null) {
                group.getWanderStepCoordinateStack().push(group.getLeader().getCoordinates());
                WanderAi.changeGroupMoveDirection(group, type);
                return null;
            }
            if (DirectionMaster.getRelativeDirection(unit.getCoordinates(), c) != group.getWanderDirection()) {
                continue;
            }
            break;
        }
        targetCoordinates = c;
    }
    return targetCoordinates;
}
Also used : Loop(main.system.auxiliary.Loop) GroupAI(eidolons.game.battlecraft.ai.GroupAI) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit)

Example 4 with GroupAI

use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.

the class WanderAi method checkUnitArrived.

private static boolean checkUnitArrived(UnitAI ai, GOAL_TYPE type) {
    GroupAI group = ai.getGroup();
    Coordinates c = group.getOriginCoordinates();
    int maxTotal = getMaxWanderTotalDistance(group, type);
    Coordinates c2 = group.getWanderStepCoordinateStack().peek();
    int maxStep = getMaxWanderStepDistance(group, type);
    if (PositionMaster.getDistance(c, ai.getUnit().getCoordinates()) > maxTotal) {
        return true;
    }
    if (c2 != null) {
        if (PositionMaster.getDistance(c2, ai.getUnit().getCoordinates()) > maxStep) {
            return true;
        }
    }
    return false;
}
Also used : GroupAI(eidolons.game.battlecraft.ai.GroupAI) Coordinates(main.game.bf.Coordinates)

Example 5 with GroupAI

use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.

the class DebugMaster method editAi.

public void editAi(Unit unit) {
    UnitAI ai = unit.getUnitAI();
    GroupAI group = ai.getGroup();
    DialogMaster.confirm("What to do with " + group);
    String TRUE = "Info";
    String FALSE = "Set Behavior";
    String NULL = "Set Parameter";
    String string = "What to do with " + group + "?";
    Boolean result = DialogMaster.askAndWait(string, TRUE, FALSE, NULL);
    LogMaster.log(1, " ");
    DIRECTION info = group.getWanderDirection();
    // TODO GLOBAL AI LOG LEVEL
    if (result == null) {
        AI_PARAM param = new EnumMaster<AI_PARAM>().retrieveEnumConst(AI_PARAM.class, ListChooser.chooseEnum(AI_PARAM.class));
        if (param != null) {
            switch(param) {
                case LOG_LEVEL:
                    ai.setLogLevel(DialogMaster.inputInt(ai.getLogLevel()));
                    break;
            }
        }
    }
    /*
         * display on BF: >> Direction >> Target coordinate for each unit or
		 * patrol >> Maybe even path... >>
		 *
		 *
		 */
    group.getPatrol();
}
Also used : GroupAI(eidolons.game.battlecraft.ai.GroupAI) UnitAI(eidolons.game.battlecraft.ai.UnitAI) DIRECTION(main.game.bf.Coordinates.DIRECTION)

Aggregations

GroupAI (eidolons.game.battlecraft.ai.GroupAI)5 Coordinates (main.game.bf.Coordinates)3 Unit (eidolons.entity.obj.unit.Unit)2 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)1 UnitAI (eidolons.game.battlecraft.ai.UnitAI)1 Action (eidolons.game.battlecraft.ai.elements.actions.Action)1 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)1 MapBlock (eidolons.game.battlecraft.logic.dungeon.location.building.MapBlock)1 XList (main.data.XList)1 Ref (main.entity.Ref)1 DIRECTION (main.game.bf.Coordinates.DIRECTION)1 Loop (main.system.auxiliary.Loop)1 ListMaster (main.system.auxiliary.data.ListMaster)1