/** * Did the entity pass within a certain number of hexes of these coords? */ public boolean passedWithin(Coords c, int dist) { for (Coords crd : passedThrough) { if (crd.distance(c) <= dist) { return true; } } return false; }
public boolean isIn8HexRadius(Coords c1, Coords c2) { // errata says we now always use 8 hex radius if (c2.distance(c1) <= 8) { return true; } return false; }
public boolean illuminates(Coords c) { return ((flags & F_IGNITED) != 0 && position.distance(c) <= radius); } }
public final int distance(int distx, int disty) { return distance(new Coords(distx, disty)); }
private String validRange(Coords finalCoords, Targetable target, int startingTargetDistance, int maxRange, boolean inRange) { if (target == null) { return null; } // If I am not currently in range, discard any path that takes me further away from my target. int finalDistanceToTarget = finalCoords.distance(target.getPosition()); if (!inRange) { if (finalDistanceToTarget > startingTargetDistance) { return "INVALID: Not in range and moving further away."; } } else { // If I am in range, discard any path that takes me out of range. if (finalDistanceToTarget > maxRange) { return "INVALID: In range and moving out of range."; } } return null; }
public Enumeration<Coords> getHexesAtDistance(Coords coords, int distance) { // Initialize the one necessary variable. Vector<Coords> retVal = new Vector<Coords>(); // Handle boundary conditions. if (distance < 0) { return retVal.elements(); } if (distance == 0) { retVal.add(coords); return retVal.elements(); } // Okay, handle the "real" case. // This is a bit of a cludge. Is there a better way to do this? for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (coords.distance(x, y) == distance) { retVal.add(new Coords(x, y)); // retVal.add(getHex(x, y)); } } } return retVal.elements(); }
protected double calculateHerdingMod(Coords friendsCoords, MovePath path, StringBuilder formula) { if (friendsCoords == null) { formula.append(" - herdingMod [0 no friends]"); return 0; } double distanceToAllies = friendsCoords.distance(path.getFinalCoords()); double herding = getOwner().getBehaviorSettings() .getHerdMentalityValue(); double herdingMod = distanceToAllies * herding; formula.append(" - herdingMod [").append(LOG_DECIMAL.format(herdingMod)) .append(" = ") .append(LOG_DECIMAL.format(distanceToAllies)).append(" * ") .append(LOG_DECIMAL.format(herding)) .append("]"); return herdingMod; }
/** * Compares MovePaths based on distance from final position to * destination. If those distances are equal then spent movement points * are compared. * */ @Override public int compare(MovePath mp1, MovePath mp2) { int d1 = mp1.getFinalCoords().distance(destination); int d2 = mp2.getFinalCoords().distance(destination); if (d1 != d2) return d1 - d2; else return mp1.getMpUsed() - mp2.getMpUsed(); } }
/** * @param aPos - attacking entity * @param tPos - targeted entity * @return a vector of all the entities that are adjacent to the targeted * entity and would fall along the angle of attack */ public static ArrayList<Entity> getAdjacentEntitiesAlongAttack(Coords aPos, Coords tPos, IGame game) { ArrayList<Entity> entities = new ArrayList<Entity>(); ArrayList<Coords> coords = Coords.intervening(aPos, tPos); // loop through all intervening coords for (Coords c : coords) { // must be adjacent to the target if ((c.distance(tPos) > 1) || c.equals(tPos)) { continue; } // now lets add all the entities here for (Entity en : game.getEntitiesVector(c)) { entities.add(en); } } return entities; }
public int compare(final MovePath first, final MovePath second) { final int firstDist = first.getMpUsed() + first.getFinalCoords().distance(destination) + getFacingDiff(first); final int secondDist = second.getMpUsed() + second.getFinalCoords().distance(destination) + getFacingDiff(second); return firstDist - secondDist; }
public static int getClosestFlightPathFacing(int attackerId, Coords aPos, Entity te) { Coords finalPos = te.getPosition(); if (te.getPlayerPickedPassThrough(attackerId) != null) { finalPos = te.getPlayerPickedPassThrough(attackerId); } int distance = Integer.MAX_VALUE; if (finalPos != null) { distance = aPos.distance(finalPos); } int finalFacing = te.getFacing(); // don't return zero distance Coords, but rather the Coords immediately // before this // This is necessary to determine angle of attack and arc information // for direct fly-overs for (int i = 0; i < te.getPassedThrough().size(); i++) { Coords c = te.getPassedThrough().get(i); if (!aPos.equals(c) && (c != null) && ((aPos.distance(c) < distance) || (distance == 0))) { finalFacing = te.getPassedThroughFacing().get(i); finalPos = c; distance = aPos.distance(c); } else if (c.equals(finalPos)) { finalFacing = te.getPassedThroughFacing().get(i); } } return finalFacing; }
/** * Returns true if last step reduces distance to destination or if the * last step is a turn, get_up... . */ @Override public boolean shouldStay(MovePath movePath) { if (movePath.length() < 2) return true; MoveStep prevStep = movePath.getSecondLastStep(); Coords prevC = prevStep.getPosition(); int prevDist = dest.distance(prevC), mpDist = dest.distance(movePath.getFinalCoords()); if (prevDist > mpDist) return true; if (prevDist == mpDist) { //the distance has not changed //if we are in the same hex, then we are changing facing and it's ok. return prevC.equals(movePath.getFinalCoords()); } return false; } }
/** * Gives the distance to the closest enemy unit, or zero if none exist * * @param me Entity who has enemies * @param position Coords from which the closest enemy is found * @param game IGame that we're playing */ public double distanceToClosestEnemy(Entity me, Coords position, IGame game) { final String METHOD_NAME = "distanceToClosestEnemy(Entity, Coords, IGame)"; getOwner().methodBegin(BasicPathRanker.class, METHOD_NAME); try { Entity closest = findClosestEnemy(me, position, game); if (closest == null) { return 0; } return closest.getPosition().distance(position); } finally { getOwner().methodEnd(BasicPathRanker.class, METHOD_NAME); } }
@Override protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction waa, IGame game, Server server) { Mounted weapon = game.getEntity(waa.getEntityId()) .getEquipment(waa.getWeaponId()); Entity attacker = game.getEntity(waa.getEntityId()); int rangeToTarget = attacker.getPosition().distance(waa.getTarget(game).getPosition()); if (weapon.isInBearingsOnlyMode() && rangeToTarget >= RangeType.RANGE_BEARINGS_ONLY_MINIMUM) { return new CapitalMissileBearingsOnlyHandler(toHit, waa, game, server); } else { return new CapitalMissileBayHandler(toHit, waa, game, server); } }
/** * Assign APDS systems to the most dangerous incoming missile attacks. This * should only be called once per turn, or AMS will get extra attacks */ public WeaponAttackAction assignAPDS(List<WeaponHandler> vAttacks) { // Shouldn't have null entity, but if we do... if (getEntity() == null) { return null; } // Ensure we only target attacks in our arc & range List<WeaponAttackAction> vAttacksInArc = new Vector<>(vAttacks.size()); for (WeaponHandler wr : vAttacks) { boolean isInArc = Compute.isInArc(getEntity().getGame(), getEntity().getId(), getEntity().getEquipmentNum(this), getEntity().getGame().getEntity(wr.waa.getEntityId())); boolean isInRange = getEntity().getPosition().distance( wr.getWaa().getTarget(getEntity().getGame()).getPosition()) <= 3; if (isInArc && isInRange) { vAttacksInArc.add(wr.waa); } } // find the most dangerous salvo by expected damage WeaponAttackAction waa = Compute.getHighestExpectedDamage(getEntity() .getGame(), vAttacksInArc, true); if (waa != null) { waa.addCounterEquipment(this); return waa; } return null; }
@Override protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction waa, IGame game, Server server) { Mounted weapon = game.getEntity(waa.getEntityId()) .getEquipment(waa.getWeaponId()); Entity attacker = game.getEntity(waa.getEntityId()); int rangeToTarget = attacker.getPosition().distance(waa.getTarget(game).getPosition()); if (weapon.isInBearingsOnlyMode() && rangeToTarget >= RangeType.RANGE_BEARINGS_ONLY_MINIMUM) { return new CapitalMissileBearingsOnlyHandler(toHit, waa, game, server); } else if (weapon.curMode().equals(Weapon.Mode_CapMissile_Tele_Operated)) { return new TeleMissileHandler(toHit, waa, game, server); } else { return new CapitalMissileBayHandler(toHit, waa, game, server); } }
@Override protected AttackHandler getCorrectHandler(ToHitData toHit, WeaponAttackAction waa, IGame game, Server server) { Mounted weapon = game.getEntity(waa.getEntityId()) .getEquipment(waa.getWeaponId()); Entity attacker = game.getEntity(waa.getEntityId()); int rangeToTarget = attacker.getPosition().distance(waa.getTarget(game).getPosition()); if (weapon.isInBearingsOnlyMode() && rangeToTarget >= RangeType.RANGE_BEARINGS_ONLY_MINIMUM) { return new CapitalMissileBearingsOnlyHandler(toHit, waa, game, server); } else if (weapon.curMode().equals(Weapon.Mode_CapMissile_Tele_Operated)) { return new TeleMissileHandler(toHit, waa, game, server); } else { return new CapitalMissileBayHandler(toHit, waa, game, server); } }
int distance = enemy.getPosition().distance(path.getFinalCoords());