use of eidolons.game.battlecraft.ai.tools.path.ActionPath 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.tools.path.ActionPath in project Eidolons by IDemiurge.
the class BehaviorMaster method getAction.
private Action getAction(GOAL_TYPE type, UnitAI ai) {
String action = null;
Integer target = null;
// doesn't the group have standing orders as a whole?..
Unit unit = ai.getUnit();
Ref ref = new Ref(unit);
GroupAI group = ai.getGroup();
// checkBehaviorChange(group); where does that happen?
switch(type) {
case AMBUSH:
break;
case STALK:
break;
case STAND_GUARD:
case PATROL:
PatrolMaster.getPatrolAction(ai);
// having already turned on the Mode
case SEARCH:
case WANDER:
if (ai.isLeader()) {
Boolean change = WanderAi.checkWanderDirectionChange(group, type);
if (change == null) {
action = getIdleAction(ai, type);
change = true;
}
// maybe go meet leader if blocked... or something like it
if (change) {
group.getWanderStepCoordinateStack().push(group.getLeader().getCoordinates());
WanderAi.changeGroupMoveDirection(group, type);
}
}
boolean wait = false;
// ActionSequenceConstructor.getSequence(targetAction, task)
Coordinates targetCoordinates = WanderAi.getCoordinates(type, ai);
if (targetCoordinates == null) {
wait = true;
// if (!recursion)
// return null;
// recursion = true;
// return getAction(type, ai);
} else {
action = STD_ACTIONS.Move.name();
// if (!unit.getAction(action).canBeActivated()) {
// }
ActionPath path = getPathBuilder().init(new ListMaster<DC_ActiveObj>().getList(unit.getAction(action)), new Action(unit.getAction(action), new Ref(unit))).getPathByPriority(new ListMaster<Coordinates>().getList(targetCoordinates));
if (path == null) {
// TODO preCheck if path
ai.setPathBlocked(true);
// appropriate
} else {
ai.setPathBlocked(false);
return path.getActions().get(0);
}
}
if (wait) {
action = getIdleAction(ai, type);
} else {
// if (change) {
// targetCoordinates = WanderMaster.getCoordinates(type,
// ai);
// }
// return path.getActions().getOrCreate(0);
}
}
DC_ActiveObj active = unit.getAction(action);
ref.setTarget(target);
recursion = false;
return new Action(active, ref);
}
use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.
the class DC_MovementManager method moveTo.
public void moveTo(Coordinates coordinates) {
Unit unit = game.getManager().getActiveObj();
List<ActionPath> paths = pathCache.get(unit);
if (paths == null) {
paths = buildPath(unit, coordinates);
// Coordinates adjacentCoordinate = coordinates.getAdjacentCoordinate(DirectionMaster
// .getRelativeDirection(unit.getCoordinates(), coordinates));
// if (DialogMaster.confirm("No path could be built to " + coordinates
// + "; proceed to the closest cell? - " + adjacentCoordinate)) {
// moveTo(adjacentCoordinate);
// } else {
// return;
// }
pathCache.put(unit, paths);
}
if (paths == null) {
return;
}
Action action = null;
for (ActionPath path : paths) {
// if (DialogMaster.confirm("Path built to : " + path + "\nExecute "
// + path.getActions().get(0).toString() + "?")) {
// action = path.getActions().get(0);
// break;
// }
// just check if still passible
// if (path.getActions().get(0))
action = path.getActions().get(0);
break;
}
if (action == null) {
pathCache.remove(unit);
return;
}
// ActionAnimation anim = new ActionAnimation(action);
// anim.start();
Context context = new Context(unit.getRef());
if (action.getActive().isMove()) {
context.setTarget(game.getCellByCoordinate(coordinates).getId());
}
unit.getGame().getGameLoop().actionInput(new ActionInput(action.getActive(), context));
}
use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.
the class DC_MovementManager method promptContinuePath.
@Override
public void promptContinuePath(Obj activeUnit) {
List<ActionPath> list = pathCache.get(activeUnit);
if (list == null) {
return;
}
ActionPath path = list.get(0);
moveTo(path.getTargetCoordinates());
}
use of eidolons.game.battlecraft.ai.tools.path.ActionPath in project Eidolons by IDemiurge.
the class DC_MovementManager method buildPath.
public List<ActionPath> buildPath(Unit unit, Coordinates coordinates) {
List<DC_ActiveObj> moves = getMoves(unit);
PathBuilder builder = PathBuilder.getInstance().init(moves, new Action(unit.getAction("Move")));
List<ActionPath> paths = builder.build(new ListMaster<Coordinates>().getList(coordinates));
if (paths.isEmpty()) {
return null;
}
return paths;
}
Aggregations