use of eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence 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.sequence.ActionSequence in project Eidolons by IDemiurge.
the class ActionManager method getForcedAction.
public Action getForcedAction(UnitAI ai) {
BEHAVIOR_MODE behaviorMode = ai.getBehaviorMode();
GOAL_TYPE goal = AiEnums.GOAL_TYPE.PREPARE;
Action action = null;
if (behaviorMode != null) {
if (behaviorMode == AiEnums.BEHAVIOR_MODE.PANIC) {
action = new Action(ai.getUnit().getAction("Cower"));
}
if (behaviorMode == AiEnums.BEHAVIOR_MODE.CONFUSED) {
action = new Action(ai.getUnit().getAction("Stumble"));
}
if (behaviorMode == AiEnums.BEHAVIOR_MODE.BERSERK) {
action = new Action(ai.getUnit().getAction("Rage"));
}
action.setTaskDescription("Forced Behavior");
}
action = getAtomicAi().getAtomicActionForced(ai);
if (action != null)
return action;
try {
action = getAtomicAi().getAtomicActionPrepare(getUnit().getAI());
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
if (action != null) {
return action;
}
List<ActionSequence> actions = getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai);
if (ai.checkMod(AI_MODIFIERS.TRUE_BRUTE)) {
goal = AiEnums.GOAL_TYPE.ATTACK;
actions.addAll(getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai));
}
if (behaviorMode == null) {
if (ParamAnalyzer.isFatigued(getUnit())) {
actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Rest.name())));
}
if (ParamAnalyzer.isHazed(getUnit())) {
// when is that used?
actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Concentrate.name())));
}
}
if (actions.isEmpty()) {
return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
}
ActionSequence sequence = getPriorityManager().chooseByPriority(actions);
LogMaster.log(1, getUnit() + " has been Forced to choose " + "" + sequence + " with priorioty of " + sequence.getPriority());
getMaster().getMessageBuilder().append("Forced Task: " + sequence.getTask().toShortString());
action = sequence.nextAction();
if (action == null) {
return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
}
return action;
}
use of eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence in project Eidolons by IDemiurge.
the class ExplorationAiMaster method getOrders.
private ActionSequence getOrders(UnitAI ai) {
if (// TODO
ai.getUnit().isMine())
if (master.getPartyMaster().isFollowOn(ai.getUnit())) {
// isFollow
Action move = master.getPartyMaster().getFollowMove(ai.getUnit());
if (move == null) {
return null;
// return getIdleOrders(ai);
} else {
return new ActionSequence(GOAL_TYPE.MOVE, move);
}
}
// get orders?
AiBehavior behavior = getAiBehavior(ai);
ActionSequence orders = behavior.getOrders(ai);
if (orders == null) {
// orders= getIdleOrders(ai);
}
return orders;
}
use of eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence in project Eidolons by IDemiurge.
the class PriorityManagerImpl method setPriorities.
@Override
public void setPriorities(List<ActionSequence> actions) {
Chronos.mark("Priority calc");
setUnit(actions.get(0).getAi().getUnit());
setUnitAi(actions.get(0).getAi());
for (ActionSequence as : actions) {
Integer mod = getUnitAi().getGoalPriorityMod(as.getTask().getType());
if (mod == null) {
mod = 0;
}
mod += getPriorityModifier().getPriorityModifier(as);
if (getMetaGoalMaster().isOn())
try {
getUnitAi().setMetaGoals(getMetaGoalMaster().initMetaGoalsForUnit(getUnitAi()));
mod += getMetaGoalMaster().getPriorityMultiplier(as);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
as.setPriorityMultiplier(mod);
}
for (ActionSequence action : actions) {
// debug!
if (action == null) {
continue;
}
// Chronos.mark("Calculating priority for " + action);
int priority = -1;
try {
priority = getPriority(action);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
// Chronos.logTimeElapsedForMark("Calculating priority for " +
// action);
action.setPriority(priority);
}
Chronos.logTimeElapsedForMark("Priority calc");
}
use of eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence in project Eidolons by IDemiurge.
the class PriorityManagerImpl method getByPriority.
public ActionSequence getByPriority(List<ActionSequence> actions) {
Chronos.mark("Priority sorting ");
ActionSequence sequence = new FuncMaster<ActionSequence>().getGreatest_(actions, a -> a.getPriority());
Chronos.logTimeElapsedForMark("Priority sorting ");
return sequence;
}
Aggregations