use of eidolons.game.battlecraft.ai.elements.task.Task 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 eidolons.game.battlecraft.ai.elements.task.Task in project Eidolons by IDemiurge.
the class ActionSequenceConstructor method createActionSequencesForGoal.
public List<ActionSequence> createActionSequencesForGoal(Goal goal, UnitAI ai) {
List<ActionSequence> actionSequences = new ArrayList<>();
List<DC_ActiveObj> actions = AiUnitActionMaster.getFullActionList(goal.getTYPE(), ai.getUnit());
actions.addAll(addSubactions(actions));
for (DC_ActiveObj action : actions) {
if (!TimeLimitMaster.checkTimeLimitForAi(getUnitAI()))
break;
Chronos.mark(getChronosPrefix() + action);
List<Task> tasks = getTaskManager().getTasks(goal.getTYPE(), ai, goal.isForced(), action);
for (Task task : tasks) {
if (task.isBlocked()) {
continue;
}
if (actionSequences.size() > 0) {
long time = TimeLimitMaster.getTimeLimitForAction();
if (Chronos.getTimeElapsedForMark(getChronosPrefix() + action) > time) {
LogMaster.log(1, "*********** TIME ELAPSED FOR " + action + StringMaster.wrapInParenthesis(time + ""));
break;
}
}
String string = task.toString();
Obj obj = action.getGame().getObjectById((Integer) task.getArg());
if (obj != null) {
string = obj.getName();
}
try {
// Chronos.mark(getChronosPrefix() + string);
actionSequences.addAll(getSequences(task, action));
// Chronos.logTimeElapsedForMark(getChronosPrefix() + string);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
}
Chronos.logTimeElapsedForMark(getChronosPrefix() + action);
}
return actionSequences;
}
use of eidolons.game.battlecraft.ai.elements.task.Task in project Eidolons by IDemiurge.
the class OrderMaster method checkOrderCompleted.
public static boolean checkOrderCompleted(Action action) {
UnitAI ai = action.getSource().getAI();
Order order = ai.getCurrentOrder();
Task task = action.getTask();
return false;
}
use of eidolons.game.battlecraft.ai.elements.task.Task in project Eidolons by IDemiurge.
the class WanderAi method getOrders.
@Override
public ActionSequence getOrders(UnitAI ai) {
Coordinates c1 = null;
try {
WanderAi.checkWanderDirectionChange(ai.getGroup(), GOAL_TYPE.WANDER);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
try {
c1 = (getWanderTargetCoordinatesCell(ai, GOAL_TYPE.WANDER));
} catch (Exception e) {
c1 = (CoordinatesMaster.getRandomAdjacentCoordinate(ai.getUnit().getCoordinates()));
main.system.ExceptionMaster.printStackTrace(e);
}
c1 = Positioner.adjustCoordinate(ai.getUnit(), c1, ai.getUnit().getFacing(), getWanderPredicate(ai.getUnit(), ai.getUnit().getFacing(), c1));
Task task = new Task(ai, GOAL_TYPE.WANDER, null);
List<Action> turnSequence = getMaster(ai).getTurnSequenceConstructor().getTurnSequence(ai.getUnit(), c1);
if (ListMaster.isNotEmpty(turnSequence)) {
return new ActionSequence(turnSequence, task, ai);
}
List<Coordinates> c = new ArrayList<>();
c.add(c1);
getMaster(ai).setUnit(ai.getUnit());
// getMaster(ai).getPathBuilder().init(null, null);
// TimeLimitMaster.markTimeForAI(ai);
List<ActionPath> paths = new ArrayList<>();
// getMaster(ai).getPathBuilder().build(c);
Action action = null;
if (paths.isEmpty()) {
if (c.get(0) != null)
action = getMaster(ai).getAtomicAi().getAtomicMove(c.get(0), ai.getUnit());
else
action = getMaster(ai).getAtomicAi().getAtomicActionApproach(ai);
if (action != null)
return new ActionSequence(GOAL_TYPE.WANDER, action);
} else
action = paths.get(0).getActions().get(0);
if (action == null)
return null;
List<ActionSequence> sequences = getMaster(ai).getActionSequenceConstructor().getSequencesFromPaths(paths, task, action);
if (sequences.isEmpty())
return null;
return sequences.get(0);
}
Aggregations