use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.
the class AtomicAi method getAtomicMove.
public Action getAtomicMove(Coordinates pick, Unit unit) {
List<Action> sequence = getTurnSequenceConstructor().getTurnSequence(FACING_SINGLE.IN_FRONT, getUnit(), pick);
Action action = null;
if (!sequence.isEmpty()) {
action = sequence.get(0);
}
if (action == null) {
try {
action = DC_MovementManager.getFirstAction(unit, pick);
main.system.auxiliary.log.LogMaster.log(1, " ATOMIC ACTION " + action + " CHOSEN TO GET TO " + pick);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
// TODO what to return???
}
}
return action;
}
use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.
the class AtomicAi method getAtomicAction.
public Action getAtomicAction(UnitAI ai) {
Action action = null;
if (checkAtomicActionTurn(ai)) {
action = getAtomicActionTurn(ai);
if (action != null) {
action.setTaskDescription("Facing Adjustment");
return action;
}
}
action = getAtomicActionPrepare(ai);
if (action != null) {
action.setTaskDescription(TASK_DESCRIPTION.RESTORATION.toString());
return action;
}
if (checkAtomicActionApproach(ai))
action = getAtomicActionApproach(ai);
if (action != null)
action.setTaskDescription("Approach");
else {
SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, getUnit() + " finds no atomic action!");
return null;
}
String message = getUnit() + " chooses atomic action: " + action;
SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, message);
return action;
}
use of eidolons.game.battlecraft.ai.elements.actions.Action 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.actions.Action in project Eidolons by IDemiurge.
the class ActionSequenceConstructor method constructSingleActionSequence.
public ActionSequence constructSingleActionSequence(Action targetAction, Task task) {
List<Action> actions = new ArrayList<>();
UnitAI ai = task.getAI();
targetAction.getRef().setID(KEYS.ACTIVE, targetAction.getActive().getId());
switch(task.getType()) {
case ATTACK:
{
// only facing!
actions = constructSingleAttackSequence(targetAction, task);
break;
}
case DEBUFF:
case BUFF:
actions.addAll(getTurnSequenceConstructor().getTurnSequence(targetAction));
actions.add(targetAction);
break;
// break;
default:
actions.add(targetAction);
break;
}
if (actions.isEmpty()) {
return null;
}
// not very good
Action action = actions.get(0);
if (!action.canBeActivated()) {
LogMaster.log(LOG_CHANNEL.AI_DEBUG2, "No sequence for " + actions.get(actions.size() - 1) + " - " + action.getActive().getName() + ": " + action.getActive().getCosts().getReason());
return null;
}
return new ActionSequence(actions, task, ai);
}
use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.
the class ActionSequenceConstructor method getSequences.
private List<ActionSequence> getSequences(Task task, DC_ActiveObj active) {
List<ActionSequence> sequences = new ArrayList<>();
Ref ref = task.getUnit().getRef().getCopy();
Integer arg = TaskManager.checkTaskArgReplacement(task, active);
// if (arg == null) {
// if (isArgNeeded(active)) return;
// }
ref.setTarget(arg);
List<ActionSequence> newSequences = null;
Action action = AiActionFactory.newAction(active, ref);
action.setTask(task);
try {
newSequences = getSequencesWithPathsForAction(action, task.getArg(), task);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
if (ListMaster.isNotEmpty(newSequences)) {
sequences.addAll(newSequences);
} else {
// if no pathing is required/available [QUICK FIX]
if (!action.canBeTargetedOnAny()) {
return sequences;
}
ActionSequence sequence = constructSingleActionSequence(action, task);
if (sequence != null) {
if (active.isRanged()) {
sequences.addAll(AiUnitActionMaster.splitRangedSequence(sequence));
} else {
sequences.add(sequence);
}
} else {
// if (unit.getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_NONE)
// TODO smarter logging?
// main.system.auxiliary.LogMaster.log(1, "***" +
// action.toString()
// + " could not be constructed into an action sequence!");
// return;
}
}
return sequences;
}
Aggregations