use of eidolons.game.battlecraft.ai.GroupAI 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.GroupAI in project Eidolons by IDemiurge.
the class TestSpawner method initGroup.
private void initGroup(Wave group) {
GroupAI groupAi = new GroupAI(group);
groupAi.setLeader(group.getParty().getLeader());
groupAi.setWanderDirection(FacingMaster.getRandomFacing().getDirection());
group.setAi(groupAi);
if (getGame().getGameMode() == GAME_MODES.DUNGEON_CRAWL) {
XList<MapBlock> permittedBlocks = new XList<>();
permittedBlocks.addAllUnique(group.getBlock().getConnectedBlocks().keySet());
int wanderBlockDistance = 1;
for (int i = 0; i < wanderBlockDistance; i++) {
for (MapBlock b : group.getBlock().getConnectedBlocks().keySet()) {
permittedBlocks.addAllUnique(b.getConnectedBlocks().keySet());
}
}
groupAi.setPermittedBlocks(permittedBlocks);
}
}
use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.
the class WanderAi method getCoordinates.
public static Coordinates getCoordinates(GOAL_TYPE type, UnitAI ai) {
Coordinates targetCoordinates = WanderAi.getWanderTargetCoordinatesCell(ai, type);
Unit unit = ai.getUnit();
GroupAI group = ai.getGroup();
boolean adjust = targetCoordinates == null;
if (!adjust) {
adjust = (!unit.getGame().getRules().getStackingRule().canBeMovedOnto(unit, targetCoordinates));
}
if (adjust) {
Coordinates c = null;
Loop loop = new Loop(50);
while (loop.continues()) {
c = Positioner.adjustCoordinate(targetCoordinates, null);
if (c == null) {
group.getWanderStepCoordinateStack().push(group.getLeader().getCoordinates());
WanderAi.changeGroupMoveDirection(group, type);
return null;
}
if (DirectionMaster.getRelativeDirection(unit.getCoordinates(), c) != group.getWanderDirection()) {
continue;
}
break;
}
targetCoordinates = c;
}
return targetCoordinates;
}
use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.
the class WanderAi method checkUnitArrived.
private static boolean checkUnitArrived(UnitAI ai, GOAL_TYPE type) {
GroupAI group = ai.getGroup();
Coordinates c = group.getOriginCoordinates();
int maxTotal = getMaxWanderTotalDistance(group, type);
Coordinates c2 = group.getWanderStepCoordinateStack().peek();
int maxStep = getMaxWanderStepDistance(group, type);
if (PositionMaster.getDistance(c, ai.getUnit().getCoordinates()) > maxTotal) {
return true;
}
if (c2 != null) {
if (PositionMaster.getDistance(c2, ai.getUnit().getCoordinates()) > maxStep) {
return true;
}
}
return false;
}
use of eidolons.game.battlecraft.ai.GroupAI in project Eidolons by IDemiurge.
the class DebugMaster method editAi.
public void editAi(Unit unit) {
UnitAI ai = unit.getUnitAI();
GroupAI group = ai.getGroup();
DialogMaster.confirm("What to do with " + group);
String TRUE = "Info";
String FALSE = "Set Behavior";
String NULL = "Set Parameter";
String string = "What to do with " + group + "?";
Boolean result = DialogMaster.askAndWait(string, TRUE, FALSE, NULL);
LogMaster.log(1, " ");
DIRECTION info = group.getWanderDirection();
// TODO GLOBAL AI LOG LEVEL
if (result == null) {
AI_PARAM param = new EnumMaster<AI_PARAM>().retrieveEnumConst(AI_PARAM.class, ListChooser.chooseEnum(AI_PARAM.class));
if (param != null) {
switch(param) {
case LOG_LEVEL:
ai.setLogLevel(DialogMaster.inputInt(ai.getLogLevel()));
break;
}
}
}
/*
* display on BF: >> Direction >> Target coordinate for each unit or
* patrol >> Maybe even path... >>
*
*
*/
group.getPatrol();
}
Aggregations