use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class ActionManager method chooseAction.
public Action chooseAction() {
UnitAI ai = getMaster().getUnitAI();
if (ai.checkStandingOrders()) {
return ai.getStandingOrders().get(0);
}
// TODO try not to? :)
getPathSequenceConstructor().clearCache();
if (getUnit() != ai.getUnit()) {
getCellPrioritizer().reset();
} else {
}
checkDeactivate();
if (ListMaster.isNotEmpty(ai.getForcedActions())) {
Action action = ai.getForcedActions().get(0);
ai.getForcedActions().remove(0);
return action;
}
// if (!ai.isEngaged()) {
// TODO return behaviorMaster.getBehaviorAction(ai);
// }
FACING_DIRECTION originalFacing = getUnit().getFacing();
Coordinates originalCoordinates = getUnit().getCoordinates();
Action action = null;
ActionSequence chosenSequence = null;
boolean atomic = false;
if (isAtomicAiOn())
try {
atomic = getAtomicAi().checkAtomicActionRequired(ai);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
if (atomic)
if (isAtomicAiOn())
try {
action = getAtomicAi().getAtomicAction(ai);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
action = getAtomicAi().getAtomicWait(ai.getUnit());
}
if (action == null) {
List<ActionSequence> actions = new ArrayList<>();
try {
List<ActionSequence> sequences = getActionSequenceConstructor().createActionSequences(ai);
for (ActionSequence a : sequences) {
if (a.get(0).canBeActivated()) {
// if (a.getOrCreate(0).canBeTargeted())
actions.add(a);
}
}
if (ListMaster.isNotEmpty(actions)) {
chosenSequence = DC_PriorityManager.chooseByPriority(actions);
}
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
} finally {
getUnit().setCoordinates(originalCoordinates);
getUnit().setFacing(originalFacing);
}
}
if (chosenSequence == null) {
if (action == null) {
action = getForcedAction(ai);
}
return action;
} else {
if (chosenSequence.getType() == GOAL_TYPE.DEFEND)
return chosenSequence.nextAction();
}
if (getUnit().getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_NONE) {
if (Launcher.DEV_MODE)
game.getLogManager().log(LOG.GAME_INFO, ai.getUnit().getName() + " chooses task: " + chosenSequence.getTask().toShortString());
String message = getUnit() + " has chosen: " + chosenSequence + " with priority of " + StringMaster.wrapInParenthesis(chosenSequence.getPriority() + "");
LogMaster.log(LOG_CHANNEL.AI_DEBUG, message);
SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, message);
}
// TODO for behaviors? ai-issued-orders?
ai.checkSetOrders(chosenSequence);
return chosenSequence.nextAction();
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class StructureResetter method resetFacing.
public void resetFacing() {
FACING_DIRECTION facing = null;
if (facing != null) {
setProperty(PROPS.FACING_DIRECTION, facing.getName());
} else {
String name = getProperty(PROPS.FACING_DIRECTION);
facing = (new EnumMaster<FACING_DIRECTION>().retrieveEnumConst(FACING_DIRECTION.class, name));
if (facing == null) {
if (getEntity().getDirection() != null) {
FacingMaster.getFacingFromDirection(getEntity().getDirection());
} else if (getRef().getObj(KEYS.SUMMONER) != null) {
facing = ((DC_UnitModel) getRef().getObj(KEYS.SUMMONER)).getFacing();
} else {
facing = FacingMaster.getRandomFacing();
}
}
}
getEntity().setFacing(facing);
// getEntity().setFacing(facing);
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class UnitResetter method resetFacing.
public void resetFacing() {
FACING_DIRECTION facing = null;
if (facing != null) {
setProperty(PROPS.FACING_DIRECTION, facing.getName());
} else {
String name = getProperty(PROPS.FACING_DIRECTION);
facing = (new EnumMaster<FACING_DIRECTION>().retrieveEnumConst(FACING_DIRECTION.class, name));
if (facing == null) {
if (getEntity().getDirection() != null) {
FacingMaster.getFacingFromDirection(getEntity().getDirection());
} else if (getRef().getObj(KEYS.SUMMONER) != null) {
facing = ((DC_UnitModel) getRef().getObj(KEYS.SUMMONER)).getFacing();
} else {
facing = FacingMaster.getRandomFacing();
}
}
}
getEntity().setFacing(facing);
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class Targeter method canTargetAny.
public boolean canTargetAny() {
Targeting targeting = getTargeting();
if (!(targeting instanceof SelectiveTargeting)) {
return true;
}
Map<FACING_DIRECTION, Boolean> map = getTargetingAnyCache().get(getOwnerObj().getCoordinates());
if (map == null) {
map = new HashMap<>();
targetingAnyCache.put(getOwnerObj().getCoordinates(), map);
}
Boolean canTargetAny = map.get(getOwnerObj().getFacing());
if (canTargetAny == null) {
canTargetAny = !targeting.getFilter().getObjects(getRef()).isEmpty();
}
map.put(getOwnerObj().getFacing(), canTargetAny);
return canTargetAny;
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class Targeter method canBeTargeted.
public boolean canBeTargeted(Integer id, boolean caching) {
Targeting targeting = getTargeting();
Map<FACING_DIRECTION, Map<Integer, Boolean>> map = getTargetingCache().get(getOwnerObj().getCoordinates());
if (map == null) {
map = new HashMap<>();
getTargetingCache().put(getOwnerObj().getCoordinates(), map);
}
Map<Integer, Boolean> map2 = map.get(getOwnerObj().getFacing());
if (map2 == null) {
map2 = new HashMap<>();
map.put(getOwnerObj().getFacing(), map2);
}
// TODO for ai?
Boolean result = map2.get(id);
if (caching) {
if (result != null)
return result;
}
if (targeting == null) {
// TODO ??
if (getEntity().getActives().size() > 1) {
return true;
}
if (!getEntity().getActives().isEmpty()) {
if (getEntity().getActives().get(0).getAbilities().getAbils().size() > 1) {
return true;
}
}
return false;
}
Ref REF = getEntity().getRef().getCopy();
REF.setMatch(id);
if (targeting instanceof MultiTargeting) {
// TODO ??
}
Conditions conditions = targeting.getFilter().getConditions();
if (result != null) {
if (result) {
if (!conditions.preCheck(REF)) {
return false;
}
}
if (!result) {
if (conditions.preCheck(REF)) {
return true;
}
}
}
if (conditions.isEmpty())
if (targeting instanceof TemplateSelectiveTargeting)
((TemplateSelectiveTargeting) targeting).initTargeting();
getEntity().getRef().getSourceObj().getRef().setInfoEntity(getEntity());
result = conditions.preCheck(REF);
map2.put(id, result);
return result;
}
Aggregations