use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.
the class TurnSequenceConstructor method getTurnSequence.
public List<Action> getTurnSequence(FACING_SINGLE template, Unit source, Coordinates target) {
FACING_DIRECTION original_facing = source.getFacing();
FACING_DIRECTION facing = original_facing;
boolean clockwise = true;
int i = 0;
List<Action> clockwise_list = new ArrayList<>();
if (template == FacingMaster.getSingleFacing(FacingMaster.rotate180(facing), source.getCoordinates(), target)) {
DC_UnitAction specAction = source.getAction("Turn About " + (RandomWizard.random() ? "anti" : "") + "clockwise");
if (specAction != null) {
clockwise_list.add(new Action(specAction));
return clockwise_list;
}
}
while (true) {
if (template == FacingMaster.getSingleFacing(facing, source.getCoordinates(), target)) {
break;
}
facing = FacingMaster.rotate(facing, clockwise);
clockwise_list.add(getTurnAction(clockwise, source));
i++;
if (i > 2) {
break;
}
}
clockwise = false;
i = 0;
List<Action> anticlockwise_list = new ArrayList<>();
facing = original_facing;
while (true) {
if (template == FacingMaster.getSingleFacing(facing, source.getCoordinates(), target)) {
break;
}
facing = FacingMaster.rotate(facing, clockwise);
anticlockwise_list.add(getTurnAction(clockwise, source));
i++;
if (i > 2) {
break;
}
}
return (anticlockwise_list.size() > clockwise_list.size()) ? clockwise_list : anticlockwise_list;
}
use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.
the class TurnSequenceConstructor method getTurnSequence.
public List<Action> getTurnSequence(Action action) {
Conditions conditions = (action.getTargeting().getFilter().getConditions());
FacingCondition condition = null;
FACING_SINGLE template = null;
DC_Obj target = action.getTarget();
Unit source = (Unit) action.getRef().getSourceObj();
for (Condition c : conditions) {
if (c instanceof FacingCondition) {
condition = (FacingCondition) c;
break;
}
List<Object> list = ClassMaster.getInstances(c, FacingCondition.class);
if (!list.isEmpty()) {
List<Action> front_sequence = getTurnSequence(FACING_SINGLE.IN_FRONT, source, target.getCoordinates());
List<Action> side_sequence = null;
if (action.getSource().hasBroadReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.BROAD_REACH)) // front_sequence.remove(front_sequence.size() - 1);
{
side_sequence = getTurnSequence(FACING_SINGLE.TO_THE_SIDE, source, target.getCoordinates());
}
List<Action> hind_sequence = null;
if (action.getSource().hasHindReach() || action.getActive().checkPassive(UnitEnums.STANDARD_PASSIVES.HIND_REACH)) {
hind_sequence = getTurnSequence(FACING_SINGLE.BEHIND, source, target.getCoordinates());
}
return new ListMaster<Action>().getSmallest(front_sequence, hind_sequence, side_sequence);
}
}
// }
if (condition == null) {
return new ArrayList<>();
}
if (ArrayMaster.isNotEmpty(condition.getTemplate())) {
template = condition.getTemplate()[0];
}
return getTurnSequence(template, source, target.getCoordinates());
}
use of eidolons.game.battlecraft.ai.elements.actions.Action 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;
}
use of eidolons.game.battlecraft.ai.elements.actions.Action 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.elements.actions.Action in project Eidolons by IDemiurge.
the class ForcedActionEffect method applyThis.
@Override
public boolean applyThis() {
Unit unit = (Unit) ref.getTargetObj();
Ref REF = unit.getRef();
if (key != null) {
REF.setTarget(ref.getId(key));
}
Action action = new Action(unit.getAction(actionName), REF);
unit.getGame().getAiManager().getAI(unit).getForcedActions().add(action);
return true;
}
Aggregations