use of eidolons.entity.active.DC_ActiveObj 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;
}
use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.
the class DC_MovementManager method move.
public boolean move(Unit obj, DC_Cell cell, boolean free, Path path, MOVE_MODIFIER mod, Ref ref) {
// if (path == null) {
// if (!free)
// path = getPath(obj, cell); // TODO just preCheck if it's blocked
// }
// if (!free)
// if (!canMove(obj, cell))
// return false;
Ref REF = new Ref(obj.getGame());
REF.setTarget(cell.getId());
REF.setSource(obj.getId());
LogMaster.log(LogMaster.MOVEMENT_DEBUG, "Moving " + obj + " to " + cell);
Event event = new Event(STANDARD_EVENT_TYPE.UNIT_BEING_MOVED, REF);
if (!game.fireEvent(event)) {
return false;
}
// double cost = (!free) ? path.traverse(obj) : 0;
// int _cost = getIntegerCost(cost);
// for AI simulation only!
// obj.modifyParameter(PARAMS.C_N_OF_MOVES, -_cost, 0);
// obj.modifyParameter(PARAMS.C_N_OF_ACTIONS, -_cost, 0);
Coordinates c = cell.getCoordinates();
if (mod != MOVE_MODIFIER.TELEPORT) {
// TODO UPDATE!
Unit moveObj = (Unit) getGrid().getObj(cell.getCoordinates());
if (moveObj != null) {
if (ref.getActive() instanceof DC_ActiveObj) {
DC_ActiveObj activeObj = (DC_ActiveObj) ref.getActive();
if (moveObj instanceof Unit) {
Unit heroObj = moveObj;
c = CollisionRule.collision(ref, activeObj, moveObj, heroObj, false, activeObj.getIntParam(PARAMS.FORCE));
if (c == null) {
// displaced by Collision rule?
return true;
}
}
}
}
}
if (obj.isDead()) {
return false;
}
if (!game.getRules().getStackingRule().canBeMovedOnto(obj, c)) {
return false;
}
if (game.getObjectByCoordinate(c) instanceof BattleFieldObject) {
if (((BattleFieldObject) game.getObjectByCoordinate(c)).isWall()) {
return false;
}
}
if (!game.getRules().getEngagedRule().unitMoved(obj, c.x, c.y)) {
return false;
}
obj.setCoordinates(c);
event = new Event(STANDARD_EVENT_TYPE.UNIT_FINISHED_MOVING, REF);
return game.fireEvent(event);
}
use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.
the class CellPrioritizer method getPriorityForCell.
/*
* Perhaps one could feed an action to this method!.. Or actions...
*/
public int getPriorityForCell(Unit unit, Obj cell, DC_ActiveObj targetAcsdftion) {
/*
* getOrCreate attack priority for each adjacent enemy...
*/
/*
* I could exclude paths for zone spells, let the range be the limit for
* now
*/
int priority = 0;
List<ActionPath> paths = pathMap.get(cell.getCoordinates());
if (paths == null) {
paths = getPathBuilder().init(moves, targetAction).build(new ListMaster<Coordinates>().getList(cell.getCoordinates()));
pathMap.put(cell.getCoordinates(), paths);
}
if (!ListMaster.isNotEmpty(paths)) {
return 0;
}
int path_priority = paths.get(0).getPriority();
for (Coordinates c : cell.getCoordinates().getAdjacentCoordinates()) {
Obj targetObj = unit.getGame().getObjectByCoordinate(c, false);
if (targetObj != null) {
if (targetObj.getOBJ_TYPE_ENUM() != DC_TYPE.BF_OBJ) {
if (Analyzer.isEnemy(targetObj, unit)) {
Integer cell_priority = enemyPriorityMap.get(targetObj);
if (cell_priority != null) {
priority += cell_priority;
continue;
}
Unit enemy = (Unit) targetObj;
cell_priority = DC_PriorityManager.getUnitPriority(targetObj);
// "now"?
cell_priority -= DC_PriorityManager.getMeleeThreat(enemy);
// should all AI-units *be afraid*? :) Maybe memory map
// will do nicely here?
// if ()
Action action = new Action(unit.getAction("attack"), enemy);
// if (melee )
// PriorityManager.getDamagePriority(action, targetObj,
// false);
priority += DC_PriorityManager.getAttackPriority(new ActionSequence(action));
DC_UnitAction offhand_attack = unit.getAction("offhand attack");
// use its priority?
if (offhand_attack != null) {
action = new Action(offhand_attack, enemy);
priority += DC_PriorityManager.getAttackPriority(new ActionSequence(action));
}
// do we calculate move costs before or after?
enemyPriorityMap.put(targetObj, cell_priority);
priority += cell_priority;
}
}
}
}
priority += priority * path_priority / 100;
return priority;
}
use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.
the class Choice method getTurns.
public Boolean[] getTurns() {
if (actions.size() == 1 || turns != null) {
return turns;
}
try {
List<Boolean> list = new ArrayList<>();
for (Action a : actions) {
DC_ActiveObj active = a.getActive();
if (active.getName().contains("lockwise")) {
if (!active.isConstructed()) {
active.construct();
}
for (Effect e : active.getAbilities().getEffects()) {
if (e instanceof ChangeFacingEffect) {
list.add(((ChangeFacingEffect) e).isClockwise());
}
}
}
}
turns = list.toArray(new Boolean[list.size()]);
return turns;
} catch (Exception e) {
}
return null;
}
use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.
the class StealthRule method actionComplete.
public void actionComplete(ActiveObj active) {
if (!isOn())
return;
// perhaps only moves?
DC_ActiveObj action = (DC_ActiveObj) active;
Unit source = action.getOwnerObj();
List<? extends DC_Obj> list = Analyzer.getEnemies(source, false, false, false);
list.removeIf(unit -> {
double d = PositionMaster.getExactDistance(source, unit);
if ((d > getMaxDistance(source, unit))) {
return true;
}
if ((d > getMaxDistance((Unit) unit, source))) {
return true;
}
return false;
});
for (DC_Obj sub : list) {
Unit unit = (Unit) sub;
double d = PositionMaster.getExactDistance(source, unit);
if ((d <= getMaxDistance(unit, source))) {
if (isSpotRollAllowed(unit, source)) {
rollSpotted(unit, source);
}
}
if ((d <= getMaxDistance(source, unit))) {
if (isSpotRollAllowed(source, unit)) {
rollSpotted(source, unit);
}
}
}
}
Aggregations