Search in sources :

Example 6 with Loop

use of main.system.auxiliary.Loop in project Eidolons by IDemiurge.

the class Positioner method adjustCoordinate.

public static Coordinates adjustCoordinate(Entity entity, Coordinates c, FACING_DIRECTION facing, Predicate<Coordinates> filterPredicate) {
    if (c == null) {
        return null;
    }
    Loop loop = new Loop(50);
    Coordinates coordinate = new Coordinates(c.x, c.y);
    while (loop.continues()) {
        // TODO remove from adj. list to limit
        // iterations to 8!
        DIRECTION direction = ArenaPositioner.getRandomSpawnAdjustDirection();
        coordinate = c.getAdjacentCoordinate(direction);
        if (coordinate != null) {
            if (filterPredicate != null)
                if (!filterPredicate.test(coordinate))
                    continue;
            if (!DC_Game.game.isSimulation()) {
                if (DC_Game.game.getBattleFieldManager().canMoveOnto(entity, coordinate)) {
                    break;
                }
            }
            if (new StackingRule(DC_Game.game).canBeMovedOnto(entity, coordinate)) {
                break;
            }
        }
    }
    // second layer in case first one is fully
    loop = new Loop(50);
    // blocked
    while (!loop.continues() && !DC_Game.game.getBattleFieldManager().canMoveOnto(entity, c) || // (DC_Game.game.getBattleField().getGrid().isCoordinateObstructed(coordinate)
    coordinate == null) {
        Coordinates adjacentCoordinate = c.getAdjacentCoordinate(ArenaPositioner.getRandomSpawnAdjustDirection());
        coordinate = adjustCoordinate(adjacentCoordinate, facing);
    }
    if (coordinate.isInvalid()) {
        return null;
    }
    return coordinate;
}
Also used : Loop(main.system.auxiliary.Loop) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) StackingRule(eidolons.game.battlecraft.rules.action.StackingRule)

Example 7 with Loop

use of main.system.auxiliary.Loop in project Eidolons by IDemiurge.

the class ImageManager method getRandomHeroPortrait.

public static String getRandomHeroPortrait() {
    Loop loop = new Loop(10);
    while (loop.continues()) {
        try {
            String bg = HeroEnums.BACKGROUND.values()[RandomWizard.getRandomIntBetween(0, HeroEnums.BACKGROUND.values().length - 1)].toString();
            List<String> portraitsForBackground = ImageManager.getPortraitsForBackground(bg);
            int index = RandomWizard.getRandomListIndex(portraitsForBackground);
            String image = portraitsForBackground.get(index);
            return image;
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    }
    return DEFAULT;
}
Also used : Loop(main.system.auxiliary.Loop)

Example 8 with Loop

use of main.system.auxiliary.Loop 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)

Aggregations

Loop (main.system.auxiliary.Loop)8 ObjType (main.entity.type.ObjType)2 Coordinates (main.game.bf.Coordinates)2 RandomWizard (main.system.auxiliary.RandomWizard)2 Unit (eidolons.entity.obj.unit.Unit)1 GroupAI (eidolons.game.battlecraft.ai.GroupAI)1 StackingRule (eidolons.game.battlecraft.rules.action.StackingRule)1 GameLoop (eidolons.game.core.GameLoop)1 DC_TYPE (main.content.DC_TYPE)1 CONTAINER_CONTENTS (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS)1 CONTAINER_CONTENT_VALUE (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENT_VALUE)1 XLinkedMap (main.data.XLinkedMap)1 DIRECTION (main.game.bf.Coordinates.DIRECTION)1 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)1 PHASE_TYPE (main.system.graphics.AnimPhase.PHASE_TYPE)1