use of main.game.bf.Coordinates 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;
}
use of main.game.bf.Coordinates 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());
}
use of main.game.bf.Coordinates 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));
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class PathSequenceConstructor method getTargetCells.
private List<Coordinates> getTargetCells(Action targetAction) {
if (targetAction.isDummy()) {
return new ListMaster<Coordinates>().getList(targetAction.getTarget().getCoordinates());
}
if (targetAction.getActive().getName().equalsIgnoreCase(StringMaster.getWellFormattedString(STD_SPEC_ACTIONS.Guard_Mode.toString()))) {
return new ListMaster<Coordinates>().toList_(targetAction.getTask().getObjArg().getCoordinates());
}
Boolean fastPickClosestToTargetOrSelf = null;
if (TimeLimitMaster.isFastPickCell()) {
if (targetAction.getActive().isRanged()) {
fastPickClosestToTargetOrSelf = false;
}
if (targetAction.getActive().isMelee()) {
// if (targetAction.getSource().getAiType()!= AI_TYPE.SNEAK) TODO just behind!
fastPickClosestToTargetOrSelf = true;
}
}
Coordinates originalCoordinate = getUnit().getCoordinates();
List<Coordinates> list = cellsCache.get(targetAction.getTargeting());
if (list != null) {
return list;
}
list = new ArrayList<>();
try {
if (fastPickClosestToTargetOrSelf != null) {
double min = Integer.MAX_VALUE;
DC_Obj center = fastPickClosestToTargetOrSelf ? targetAction.getTarget() : targetAction.getSource();
for (Coordinates c : center.getCoordinates().getAdjacentCoordinates()) {
if (// TODO
!TargetingMaster.isValidTargetingCell(targetAction, c, getUnit())) {
continue;
}
double distance = PositionMaster.getExactDistance(c, originalCoordinate);
if (distance <= min) {
list = new ListMaster<Coordinates>().getList(c);
min = distance;
}
}
}
if (list.isEmpty()) {
// TODO prioritizedCells;
List<Coordinates> coordinatesList = null;
if (!ListMaster.isNotEmpty(coordinatesList)) {
coordinatesList = getUnit().getGame().getBattleField().getGrid().getCoordinatesList();
}
// prune by distance/direction from target?
for (Coordinates c : coordinatesList) {
if (!TargetingMaster.isValidTargetingCell(targetAction, c, getUnit())) {
continue;
}
// TODO causes visuals!
getUnit().setCoordinates(c);
if (TargetingMaster.canBeTargeted(targetAction, true, true)) {
list.add(c);
}
}
}
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
} finally {
getUnit().setCoordinates(originalCoordinate);
}
if (list.size() > 1) {
list = getPruneMaster().pruneTargetCells(targetAction, list);
}
if (getUnit().getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_BASIC) {
LogMaster.log(LOG_CHANNEL.AI_DEBUG, "***" + targetAction + " has target cells for PB: " + list);
}
cellsCache.put(targetAction.getTargeting(), list);
return list;
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class AI_Manager method getAction.
public Action getAction(Unit unit) {
if (unit.isMine()) {
unit.getQuickItemActives();
}
messageBuilder = new StringBuffer();
Action action = null;
running = true;
setUnit(unit);
Coordinates bufferedCoordinates = unit.getCoordinates();
try {
action = actionManager.chooseAction();
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
} finally {
running = false;
}
if (action == null) {
running = true;
try {
action = actionManager.getForcedAction(getAI(unit));
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
} finally {
running = false;
SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, getUnit() + " opts for Forced Action: " + action);
}
} else {
try {
getMessageBuilder().append("Task: " + action.getTaskDescription());
if (!CoreEngine.isGraphicsOff()) {
if (game.isDebugMode() || Launcher.DEV_MODE)
FloatingTextMaster.getInstance().createFloatingText(TEXT_CASES.BATTLE_COMMENT, getMessageBuilder().toString(), getUnit());
}
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
}
if (!bufferedCoordinates.equals(unit.getCoordinates())) {
unit.setCoordinates(bufferedCoordinates);
}
return action;
}
Aggregations