use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class DefaultActionHandler method getMoveToCellAction.
public static DC_UnitAction getMoveToCellAction(Unit source, Coordinates c) {
DIRECTION d = DirectionMaster.getRelativeDirection(source.getCoordinates(), c);
FACING_SINGLE f = FacingMaster.getSingleFacing(source.getFacing(), source.getCoordinates(), c);
String name = null;
switch(f) {
case IN_FRONT:
if (d.isDiagonal()) {
// target = Eidolons.getGame().getCellByCoordinate(c);
name = "Clumsy Leap";
break;
}
name = "Move";
break;
case BEHIND:
if (d.isDiagonal())
return null;
name = "Move Back";
break;
case TO_THE_SIDE:
boolean right = !source.getFacing().isVertical() ? d.growY : d.growX;
if (!source.getFacing().isVertical()) {
if (source.getFacing().isCloserToZero())
right = !right;
} else if (!source.getFacing().isCloserToZero())
right = !right;
name = right ? "Move Right" : "Move Left";
break;
case NONE:
break;
}
if (name == null) {
// SoundController.getCustomEventSound(SOUND_EVENT.RADIAL_CLOSED);
return null;
}
return source.getAction(name);
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class PatrolMaster method changeDestination.
private static void changeDestination(Patrol patrol) {
DIRECTION d = patrol.getDirection();
if (d == null) {
patrol.getLeadingUnit();
}
if (!patrol.isBackAndForth()) {
d = DirectionMaster.rotate90(d, patrol.isClockwise());
} else {
d = DirectionMaster.flip(patrol.getDirection());
}
Coordinates newDestination = getNewDestination(patrol, d);
patrol.setDestination(newDestination);
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class PatrolMaster method getBlockingUnit.
private static Unit getBlockingUnit(Patrol patrol, UnitAI ai) {
Unit unit = ai.getUnit();
DIRECTION direction = DirectionMaster.getRelativeDirection(unit.getCoordinates(), patrol.getDestination());
// paths.getOrCreate(unit);
Coordinates coordinates = unit.getCoordinates().getAdjacentCoordinate(direction);
// TODO more than 1 coordinate?
// unit.getGame().getUnitByCoordinate(coordinates);
Unit unitByCoordinate = null;
// preCheck leader?
Collection<Unit> units = unit.getGame().getUnitsForCoordinates(coordinates);
for (Obj u : units) {
// sort?
Unit blocker = (Unit) u;
// if (u == leader)
if (!blocker.isOwnedBy(ai.getUnit().getOwner())) {
continue;
}
if (!blocker.canMove()) {
continue;
}
unitByCoordinate = blocker;
}
return unitByCoordinate;
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class PatrolMaster method getPatrolAction.
// similar to wandering but all units must be to the target point
public static Action getPatrolAction(UnitAI ai) {
Patrol patrol = ai.getGroup().getPatrol();
if (patrol == null) {
initPatrol(ai.getGroup());
}
Action action = null;
boolean leader = ai.getGroup().getLeader() == ai.getUnit();
if (isArrived(patrol, ai)) {
if (leader) {
if (checkNewDestination(patrol)) {
changeDestination(patrol);
} else {
action = getIdleAction(patrol, ai);
}
}
} else {
action = getWaitAction(patrol, ai);
}
if (action != null) {
return action;
}
if (patrol.getReturnCoordinates() != null) {
patrol.setDestination(patrol.getReturnCoordinates());
patrol.setReturnCoordinates(null);
}
Coordinates c = patrol.getDestination();
if (!leader) {
Coordinates leaderCoordinates = ai.getGroup().getLeader().getCoordinates();
DIRECTION direction = DirectionMaster.getRelativeDirection(patrol.getDestination(), leaderCoordinates);
List<Object> list = new ArrayList<>();
list.add(leaderCoordinates.getAdjacentCoordinate(direction));
list.add(leaderCoordinates.getAdjacentCoordinate(DirectionMaster.rotate45(direction, true)));
list.add(leaderCoordinates.getAdjacentCoordinate(DirectionMaster.rotate45(direction, false)));
c = leaderCoordinates.getAdjacentCoordinate(direction);
}
boolean catchingUp = false;
// make sure paths stick together! getMaxDistanceForNodes(paths)
return action;
}
use of main.game.bf.Coordinates.DIRECTION in project Eidolons by IDemiurge.
the class WanderAi method getWanderCells.
public static List<? extends DC_Obj> getWanderCells(UnitAI ai) {
DIRECTION d = ai.getGroup().getWanderDirection();
// permittedCells = ai.getGroup().getWanderBlocks();
List<DC_Obj> list = new ArrayList<>();
for (DC_Cell cell : Analyzer.getCells(ai, false, false, true)) {
if (d != null) {
if (DirectionMaster.getRelativeDirection(cell, ai.getUnit()) != d) {
continue;
}
}
if (PositionMaster.getDistance(cell, ai.getUnit()) <= ai.getMaxWanderDistance()) {
list.add(cell);
}
}
if (list.isEmpty()) {
// change direction?
}
return list;
}
Aggregations