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;
}
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;
}
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;
}
Aggregations