public static int getFiringAngle(final Coords dest, int dest_facing, final Coords src) { int fa = dest.degree(src) - ((dest_facing % 6) * 60); if (fa < 0) { fa += 360; } else if (fa >= 360) { fa -= 360; } return fa; }
/** * The transformation encodes the y value in the top 5 decimal digits and * the x value in the bottom 5. Could more efficiently encode this by * partitioning the binary representation, but this is more human readable * and still allows for a 99999x99999 hex map. */ // encode 2 numbers into 1 public static int coordsToId(Coords c) { return c.getY() * 100000 + c.getX(); }
public static Coords idToCoords(int id) { int idNoType = id - Targetable.TYPE_BUILDING * 1000000; int y = (idNoType) / 1000; return new Coords(idNoType - (y * 1000), y); }
Coords src = getFinalCoords(); Coords currStep = src; Coords nextStep = currStep.translated(direction); while (dest.distance(nextStep) < dest.distance(currStep)) { addStep(type); currStep = nextStep; nextStep = currStep.translated(direction); if (!currStep.equals(dest)) { int dir = currStep.direction(dest); findSimplePathTo(dest, MoveStepType.FORWARDS, currStep.direction(dest), facing); break; case 1: findSimplePathTo(dest, MoveStepType.LATERAL_RIGHT, currStep.direction(dest), facing); break; case 2: findSimplePathTo(dest, MoveStepType.LATERAL_LEFT_BACKWARDS, currStep.direction(dest), facing); break; case 3: findSimplePathTo(dest, MoveStepType.BACKWARDS, currStep.direction(dest), facing); break; case 4: findSimplePathTo(dest, MoveStepType.LATERAL_RIGHT_BACKWARDS, currStep.direction(dest), facing); break; case 5: findSimplePathTo(dest, MoveStepType.LATERAL_LEFT, currStep.direction(dest), facing);
game.getBoard().getCenter() : closest.getPosition(); int desiredFacing = (toFace.direction(movingUnit.getPosition()) + 3) % 6; int currentFacing = path.getFinalFacing(); int facingDiff;
private int getFacingDiff(final MovePath first) { if (first.isJumping()) { return 0; } if (first.getFinalCoords().equals(destination)) { return 0; } int firstFacing = Math.abs(((first.getFinalCoords().direction(destination) + (backward ? 3 : 0)) % 6) - first.getFinalFacing()); if (firstFacing > 3) { firstFacing = 6 - firstFacing; } if (first.canShift()) { firstFacing = Math.max(0, firstFacing - 1); } if ((first.getFinalCoords().degree(destination) % 60) != 0) { firstFacing++; } return firstFacing; } }
if ((curHex != null) && (curHex.containsTerrain(Terrains.BUILDING))) { Coords coords = new Coords(x, y); if (!bldgByCoords.containsKey(coords)) { excep.printStackTrace(); } else { errBuff.append("Unable to create building at " + coords.toString() + "!\n"); errBuff.append(excep.getMessage() + "\n"); Coords coords = new Coords(x, y); if (!bldgByCoords.containsKey(coords)) { excep.printStackTrace(); } else { errBuff.append("Unable to create fuel tank at " + coords.toString() + "!\n"); errBuff.append(excep.getMessage() + "\n"); Coords coords = new Coords(x, y); if (!bldgByCoords.containsKey(coords)) { excep.printStackTrace(); } else { errBuff.append("Unable to create bridge at " + coords.toString() + "!\n"); errBuff.append(excep.getMessage() + "\n");
effectivePos = getPriorPosition(); if (src.equals(effectivePos)) { int fa = (effectivePos.degree(src) + ((6 - face) * 60)) % 360; LosEffects.AttackInfo ai = LosEffects.buildAttackInfo(src, getPosition(), 1, getElevation(), srcHex.floor(), curHex.floor()); ArrayList<Coords> in = Coords.intervening(ai.attackPos, ai.targetPos, true); leftBetter = LosEffects.dividedLeftBetter(in, game, ai,
/** * Find the shortest path to the destination <code>Coords</code> by hex * count. This right choice <em>only</em> when making a simple move like a * straight line or one with a single turn. * * @param dest the destination <code>Coords</code> of the move. * @param type the type of movment step required. */ private void lazyPathfinder(final Coords dest, final MoveStepType type) { MoveStepType step = MoveStepType.FORWARDS; if (type == MoveStepType.BACKWARDS) { step = MoveStepType.BACKWARDS; } Coords subDest = dest; if (!dest.equals(getFinalCoords())) { subDest = dest.translated(dest.direction(getFinalCoords())); } while (!getFinalCoords().equals(subDest)) { // adjust facing rotatePathfinder((getFinalCoords().direction(subDest) + (step == MoveStepType.BACKWARDS ? 3 : 0)) % 6, false); // step forwards addStep(step); } rotatePathfinder((getFinalCoords().direction(dest) + (step == MoveStepType.BACKWARDS ? 3 : 0)) % 6, false); if (!dest.equals(getFinalCoords())) { addStep(type); } }
public String toString() { String ownerString; String strengthString = ""; String eccmString = ""; if (owner != null) { ownerString = owner.getName(); } else { ownerString = "none"; } if (angelStrength != 0) { strengthString = ", aS: " + angelStrength; } else if (strength != 0){ if (isECMNova) { strengthString = ", nS: " + strength; } else { strengthString = ", s: " + strength; } } if (angelECCMStrength != 0) { eccmString = ", cAS: " + angelECCMStrength; } else if (eccmStrength != 0){ eccmString = ", cS: " + eccmStrength; } return "(" + pos.toString() + ", " + ownerString + ", r:" + range + strengthString + eccmString + ")"; }
public void collapseBasement(Coords coords, IBoard board, Vector<Report> vPhaseReport) { if ((basement.get(coords) == BasementType.NONE) || (basement.get(coords) == BasementType.ONE_DEEP_NORMALINFONLY)) { System.err.println("hex has no basement to collapse"); return; } if (basementCollapsed.get(coords)) { System.err.println("hex has basement that already collapsed"); return; } Report r = new Report(2112, Report.PUBLIC); r.add(getName()); r.add(coords.getBoardNum()); vPhaseReport.add(r); System.err.println("basement " + basement + "is collapsing, hex:" + coords.toString() + " set terrain!"); board.getHex(coords).addTerrain(Terrains.getTerrainFactory().createTerrain( Terrains.BLDG_BASE_COLLAPSED, 1)); basementCollapsed.put(coords, true); }
|| (overallMoveType == EntityMovementType.MOVE_SPRINT) || (overallMoveType == EntityMovementType.MOVE_VTOL_SPRINT)) && (prevFacing != curFacing) && !lastPos.equals(curPos) && !(this instanceof Infantry) && !(this instanceof Protomech)) { && prevFacing == curFacing && !lastPos.equals(curPos) && lastPos.direction(curPos) % 3 != curFacing % 3 && !(isUsingManAce() && (overallMoveType == EntityMovementType.MOVE_WALK || overallMoveType == EntityMovementType.MOVE_VTOL_WALK))) {
ArrayList<Coords> coords = Coords.intervening(a, b); boolean bDivided = ((a.degree(b) % 60) == 30); int x = 0; int prevEcmStatus = 0; for (Coords enemyECMCoords : vEnemyECMCoords) { int range = ranges.nextElement().intValue(); int nDist = c.distance(enemyECMCoords); if (nDist <= range) { ecmStatus++; for (Coords friendlyECCMCoords : vFriendlyECCMCoords) { int range = ranges.nextElement().intValue(); int nDist = c.distance(friendlyECCMCoords); if (nDist <= range) { ecmStatus--; for (Coords friendlyBAPCoords : vFriendlyBAPCoords) { int range = ranges.nextElement().intValue(); int nDist = c.distance(friendlyBAPCoords); int facing = facings.nextElement().intValue(); if (nDist <= range) {
ArrayList<Coords> in = Coords.intervening(start, end); double degree = start.degree(end); if ((degree % 60) == 30) { split = true; in = Coords.intervening(start, end, true); int dir = current.direction(c);
public boolean passedThrough(Coords c) { for (Coords crd : passedThrough) { if (crd.equals(c)) { return true; } } return false; }
/** * @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 boolean isIn8HexRadius(Coords c1, Coords c2) { // errata says we now always use 8 hex radius if (c2.distance(c1) <= 8) { return true; } return false; }