use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class BuildHelper method tryPlaceCorridor.
public boolean tryPlaceCorridor(MapBlock block, Coordinates base, FACING_DIRECTION direction, boolean culdesac) {
Coordinates c = base;
FACING_DIRECTION originalDirection = direction;
List<Coordinates> coordinates = new ArrayList<>();
int max_bents = 2;
int length = 1;
int bents = 0;
Boolean turn = null;
// Boolean lastBent =null;
while (true) {
// break CUL DE SACS?!
c = c.getAdjacentCoordinate(direction.getDirection());
if (c == null) {
return false;
}
Boolean result = checkLinkOrReject(block, c, culdesac);
coordinates.add(c);
length++;
if (result == null) {
if (culdesac) {
result = checkCulDeSacEnds(originalDirection, c, length);
}
}
if (result != null) {
if (result) {
newBlock(coordinates, culdesac ? BLOCK_TYPE.CULDESAC : BLOCK_TYPE.CORRIDOR);
} else {
return false;
}
return true;
}
if (turn == null) {
if (length > 1) {
if (bents < max_bents) {
turn = checkTurn(block, length);
}
}
if (turn != null) {
direction = FacingMaster.rotate(direction, turn);
}
} else {
turn = null;
}
}
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class Spawner method spawnUnit.
public Unit spawnUnit(String typeName, String coordinates, DC_Player owner, String facing, String level) {
if (coordinates == null) {
// TODO getPositioner().getcoo
}
Coordinates c = new Coordinates(coordinates);
FACING_DIRECTION facing_direction = facing == null ? getFacingAdjuster().getFacingForEnemy(c) : FacingMaster.getFacing(facing);
ObjType type = DataManager.getType(typeName, C_OBJ_TYPE.UNITS_CHARS);
// TODO chars or units?!
if (level != null) {
int levelUps = StringMaster.getInteger(level);
if (levelUps > 0) {
type = new UnitLevelManager().getLeveledType(type, levelUps);
}
}
Unit unit = (Unit) game.getManager().getObjCreator().createUnit(type, c.x, c.y, owner, new Ref(game));
unit.setFacing(facing_direction);
if (!unit.isHero())
UnitTrainingMaster.train(unit);
if (unit.isMine())
TestMasterContent.addTestItems(unit.getType(), false);
return unit;
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class SpectrumEffect method applyThis.
public boolean applyThis() {
if (range == null)
range = new Formula(rangeFormula).getInt(ref);
Integer backwardRange = 0;
Integer sidePenalty = 0;
if (vision) {
range = new Formula(StringMaster.getValueRef(KEYS.SOURCE, PARAMS.SIGHT_RANGE)).getInt(ref);
// TODO
backwardRange = null;
// will be taken from unit
sidePenalty = null;
}
if (ref.getObj(source) instanceof BattleFieldObject)
bfObj = ((BattleFieldObject) ref.getObj(source));
else {
// TODO
}
FACING_DIRECTION facing = bfObj.getFacing();
if (circular) {
backwardRange = range;
facing = FACING_DIRECTION.NORTH;
} else {
sidePenalty = 1;
}
List<Coordinates> coordinates = new ArrayList<>(getGame().getVisionMaster().getSightMaster().getSpectrumCoordinates(range, sidePenalty, backwardRange, bfObj, vision, facing));
// boolean x-ray ++ tall/short/etc
if (effects == null) {
initEffects();
}
for (Coordinates c : coordinates) {
// TODO WHAT IF IT'S ON A DIFFERENT Z-LEVEL?
// applyThrough = true; // ?
// if (!applyThrough)
// if (!(getGame().getObjectByCoordinate(c, true) instanceof
// DC_Cell))
// continue;
DequeImpl<? extends Obj> objects = new DequeImpl<>(getGame().getObjectsOnCoordinate(getGame().getDungeon().getZ(), c, null, true, applyThrough));
if (applyThrough) {
objects.addCast(getGame().getCellByCoordinate(c));
}
for (Obj o : objects) {
ref.setMatch(o.getId());
if (filterConditions != null) {
if (!filterConditions.preCheck(ref)) {
continue;
}
}
Integer target = o.getId();
// target = getGame().getCellByCoordinate(c).getId();
if (getGame().getObjectById(target) == null) {
continue;
}
for (Effect effect : effects.getEffects()) {
Ref REF = Ref.getCopy(ref);
REF.setTarget(target);
if (reductionForDistance != null) {
// for the first time
effect.resetOriginalFormula();
// to set original
effect.resetOriginalFormula();
String reduction = reductionForDistance;
if (reductionForDistanceModifier != null)
reduction += (reductionForDistanceModifier);
Formula effectFormula = effect.getFormula();
reduction = reduction.replace(X, effectFormula.toString());
int distance = PositionMaster.getDistance(REF.getSourceObj(), REF.getTargetObj());
reduction = reduction.replace("distance", distance + "");
effectFormula.append(reduction);
// TODO
Integer amount = effectFormula.getInt(ref);
if (amount < 0) {
effect.setAmount(amount);
}
effect.setAmount(amount);
}
effect.apply(REF);
}
}
}
return true;
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class CoordinatesMaster method getClosestEdge.
public static DIRECTION getClosestEdge(Coordinates c, Integer cellsX, Integer cellsY, Boolean x_or_y_only) {
FACING_DIRECTION x_dir = null;
FACING_DIRECTION y_dir = null;
int min_x_diff = Integer.MAX_VALUE;
int min_y_diff = Integer.MAX_VALUE;
for (FACING_DIRECTION d : FACING_DIRECTION.values) {
int x_diff = Integer.MAX_VALUE;
int y_diff = Integer.MAX_VALUE;
switch(d) {
case EAST:
x_diff = cellsX - c.x;
break;
case NORTH:
y_diff = c.y;
break;
case SOUTH:
y_diff = cellsY - c.y;
break;
case WEST:
x_diff = c.x;
break;
}
if (x_diff < min_x_diff) {
x_dir = d;
min_x_diff = x_diff;
}
if (y_diff < min_y_diff) {
y_dir = d;
min_y_diff = y_diff;
}
}
if (x_dir == y_dir) {
return x_dir.getDirection();
}
if (x_or_y_only != null) {
return x_or_y_only ? x_dir.getDirection() : y_dir.getDirection();
}
return min_x_diff < min_y_diff ? x_dir.getDirection() : y_dir.getDirection();
}
use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.
the class FacingMaster method getOptimalFacing.
public static FACING_DIRECTION getOptimalFacing(Unit unit, List<Coordinates> coordinates, Function<Coordinates, Integer> function) {
HashMap<FACING_DIRECTION, Double> map = new LinkedHashMap<>();
for (FACING_DIRECTION facing : FACING_DIRECTION.values()) {
Double i = 0.0;
for (Coordinates c : coordinates) {
if (FacingMaster.getSingleFacing(facing, unit.getCoordinates(), c) != FACING_SINGLE.IN_FRONT) {
continue;
}
i += function.apply(c);
}
map.put(facing, i);
}
FACING_DIRECTION pick = null;
Double max = 0.0;
for (FACING_DIRECTION fac : map.keySet()) {
if (map.get(fac) > max) {
max = map.get(fac);
pick = fac;
}
}
return pick;
}
Aggregations