private void drawHeat(Graphics graph, Entity entity, int x, int y) { if (!((entity instanceof Mech) || (entity instanceof Aero))) { return; } boolean mtHeat = false; int mHeat = 30; if ((entity.getGame() != null) && entity.getGame().getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_HEAT)) { mHeat = 50; mtHeat = true; } int heat = Math.min(mHeat, entity.heat); graph.setColor(Color.darkGray); graph.fillRect(x + 52, y + 4, 2, 30); graph.setColor(Color.lightGray); graph.fillRect(x + 51, y + 3, 2, 30); graph.setColor(Color.red); if (mtHeat) { graph.fillRect(x + 51, y + 3 + (30 - (int) (heat * 0.6)), 2, (int) (heat * 0.6)); } else { graph.fillRect(x + 51, y + 3 + (30 - heat), 2, heat); } }
public boolean isOnAtmosphericGroundMap() { return ((getGame().getPlanetaryConditions().getAtmosphere() != PlanetaryConditions.ATMO_VACUUM) || (getGame().getPlanetaryConditions().getAtmosphere() != PlanetaryConditions.ATMO_TRACE)) && (getGame().getBoard().onGround() || // doesn't make sense in english, but "atmospheric" map actually // covers maps that are within a planet's gravity well getGame().getBoard().inAtmosphere()); }
public IGame getGame() { if (getEntity() != null) { return getEntity().getGame(); } else { return null; } }
public boolean canLoad(Entity unit) { if (unit.getWeight() > currentSpace) { return false; } // We can carry two dropships or one JS/WS/SS. if (unit.hasETypeFlag(Entity.ETYPE_DROPSHIP)) { return troops.isEmpty() || ((troops.size() == 1) && (null != unit.getGame().getEntity(troops.get(0))) && (unit.getGame().getEntity(troops.get(0)).hasETypeFlag(Entity.ETYPE_DROPSHIP))); } else if (unit.hasETypeFlag(Entity.ETYPE_JUMPSHIP)) { return troops.isEmpty(); } else { return false; } }
default void liftOff(int altitude) { if (isSpheroid()) { ((Entity) this).setMovementMode(EntityMovementMode.SPHEROID); } else { ((Entity) this).setMovementMode(EntityMovementMode.AERODYNE); } ((Entity) this).setAltitude(altitude); HashSet<Coords> positions = ((Entity) this).getOccupiedCoords(); ((Entity) this).getSecondaryPositions().clear(); if (((Entity) this).getGame() != null) { ((Entity) this).getGame().updateEntityPositionLookup((Entity) this, positions); } }
/** * Convenience method to determine whether this entity should be treated as an airborne aero on a ground map. * @return True if this is an airborne aircraft on a ground map. */ public boolean isAirborneAeroOnGroundMap() { return isAero() && isAirborne() && getGame().getBoard().onGround(); }
/** * Used to determine if this entity is only detected by an enemies * sensors and hence should only be a sensor return. * * @return */ public static boolean onlyDetectedBySensors(IPlayer localPlayer, Entity entity) { boolean sensors = (entity.getGame().getOptions().booleanOption( OptionsConstants.ADVANCED_TACOPS_SENSORS) || entity.getGame().getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADVANCED_SENSORS)); boolean sensorsDetectAll = entity.getGame().getOptions().booleanOption( OptionsConstants.ADVANCED_SENSORS_DETECT_ALL); boolean doubleBlind = entity.getGame().getOptions().booleanOption( OptionsConstants.ADVANCED_DOUBLE_BLIND); boolean hasVisual = entity.hasSeenEntity(localPlayer); boolean hasDetected = entity.hasDetectedEntity(localPlayer); if (sensors && doubleBlind && !sensorsDetectAll && !EntityVisibilityUtils.trackThisEntitiesVisibilityInfo(localPlayer, entity) && hasDetected && !hasVisual) { return true; } else { return false; } }
default String hasRoomForVerticalLanding() { Coords pos = ((Entity) this).getPosition(); IHex hex = ((Entity) this).getGame().getBoard().getHex(((Entity) this).getPosition()); if (((Entity) this).getGame().getBoard().getBuildingAt(pos) != null) { return "Buildings in the way"; } // no units in the way for (Entity en : ((Entity) this).getGame().getEntitiesVector(pos)) { if (!en.isAirborne()) { return "Ground units in the way"; } } hex = ((Entity) this).getGame().getBoard().getHex(pos); // if the hex is null, then we are offboard. Don't let units // land offboard. if (null == hex) { return "landing area not on the map"; } // landing must contain only acceptable terrain if (!hex.isClearForLanding()) { return "Unacceptable terrain for landing"; } return null; }
/** * This function returns an html-coded list that says what * quirks are enabled for this unit * @return */ public String getQuirksList() { String quirkString = ""; boolean first = true; if(null != getEntity().getGame() && getEntity().getGame().getOptions().booleanOption("stratops_quirks")) { for (Enumeration<IOptionGroup> i = getEntity().getQuirks().getGroups(); i.hasMoreElements();) { IOptionGroup group = i.nextElement(); for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements();) { IOption quirk = j.nextElement(); if (quirk.booleanValue()) { if(first) { first = false; } else { quirkString += "\n"; } quirkString += quirk.getDisplayableNameWithValue(); } } } } if(quirkString.equals("")) { return null; } return quirkString; }
/** * Generates a mock game object. * Sets up some values for the passed-in entities as well (game IDs, and the game object itself) * @param entities * @return */ private IGame generateMockGame(List<Entity> entities, IBoard mockBoard) { final IGame mockGame = Mockito.mock(IGame.class); Mockito.when(mockGame.getBoard()).thenReturn(mockBoard); final GameOptions mockGameOptions = Mockito.mock(GameOptions.class); Mockito.when(mockGame.getOptions()).thenReturn(mockGameOptions); Mockito.when(mockGameOptions.booleanOption(Mockito.anyString())).thenReturn(false); for(int x = 0; x < entities.size(); x++) { Mockito.when(mockGame.getEntity(x + 1)).thenReturn(entities.get(x)); Mockito.when(entities.get(x).getGame()).thenReturn(mockGame); Mockito.when(entities.get(x).getId()).thenReturn(x + 1); } return mockGame; }
/** * In hexes with buildings, returns the elevation relative to the roof. Otherwise returns the elevation * relative to the surface. */ public int getClearance() { IHex hex = entity.getGame().getBoard().getHex(getPosition()); if (hex.containsTerrain(Terrains.BLDG_ELEV)) { return elevation - hex.terrainLevel(Terrains.BLDG_ELEV); } return elevation; }
/** * Figures out the "opposite" edge for the given entity on the entity's game board * @param entity Entity to evaluate * @return the Board.START_ constant representing the "opposite" edge */ public static CardinalEdge getClosestEdge(Entity entity) { int distanceToWest = entity.getPosition().getX(); int distanceToEast = entity.getGame().getBoard().getWidth() - entity.getPosition().getX(); int distanceToNorth = entity.getPosition().getY(); int distanceToSouth = entity.getGame().getBoard().getHeight() - entity.getPosition().getY(); boolean closerWestThanEast = distanceToWest < distanceToEast; boolean closerNorthThanSouth = distanceToNorth < distanceToSouth; int horizontalDistance = Math.min(distanceToWest, distanceToEast); int verticalDistance = Math.min(distanceToNorth, distanceToSouth); if(horizontalDistance < verticalDistance) { return closerWestThanEast ? CardinalEdge.WEST : CardinalEdge.EAST; } else { return closerNorthThanSouth ? CardinalEdge.NORTH : CardinalEdge.SOUTH; } }
/** * We only want to show double-blind visibility indicators on our own * mechs and teammates mechs (assuming team vision option). */ public static boolean trackThisEntitiesVisibilityInfo(IPlayer localPlayer, Entity e) { if (localPlayer == null) { return false; } if (e.getGame().getOptions().booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND) //$NON-NLS-1$ && ((e.getOwner().getId() == localPlayer.getId()) || (e.getGame().getOptions().booleanOption(OptionsConstants.ADVANCED_TEAM_VISION) //$NON-NLS-1$ && (e.getOwner().getTeam() == localPlayer.getTeam())))) { return true; } return false; } }
default PilotingRollData checkVelocityDouble(int velocity, EntityMovementType overallMoveType) { PilotingRollData roll = ((Entity) this).getBasePilotingRoll(overallMoveType); if ((velocity > (2 * ((Entity) this).getWalkMP())) && !((Entity) this).getGame().getBoard().inSpace()) { // append the reason modifier roll.append(new PilotingRollData(((Entity) this).getId(), 0, "Velocity greater than 2x safe thrust")); } else { roll.addModifier(TargetRoll.CHECK_FALSE, "Check false: Entity is not exceeding 2x safe thrust"); } return roll; }
public Refit(Unit oUnit, Entity newEn, boolean custom, boolean refurbish) { this(); isRefurbishing = refurbish; customJob = custom; oldUnit = oUnit; newEntity = newEn; newEntity.setOwner(oldUnit.getEntity().getOwner()); newEntity.setGame(oldUnit.getEntity().getGame()); failedCheck = false; timeSpent = 0; fixableString = null; kitFound = false; campaign = oldUnit.campaign; calculate(); if(customJob) { suggestNewName(); } }
/** * Worker function that determines the direction in which the given entity will go off board * if it starts at the given coordinates with the given vectors. * @param entity Entity to examine * @param startingCoords Starting coordinates * @param vectors Starting velocity vector * @return Flight direction. OffBoardDirection.NONE if the given entity will be able to remain on board. */ private static OffBoardDirection calculateOffBoardDirection(Entity entity, Coords startingCoords, int[] vectors) { Coords nextCoords = Compute.getFinalPosition(startingCoords, vectors); int availableThrust = entity.getRunMP(); IBoard board = entity.getGame().getBoard(); OffBoardDirection offBoardDirection = OffBoardDirection.NONE; // step one: check if the position is out of bounds by more than the unit has available thrust if(nextCoords.getX() < -availableThrust) { offBoardDirection = OffBoardDirection.WEST; } else if (nextCoords.getX() > board.getWidth() + availableThrust) { offBoardDirection = OffBoardDirection.EAST; } else if (nextCoords.getY() < -availableThrust) { offBoardDirection = OffBoardDirection.NORTH; } else if(nextCoords.getY() > board.getHeight() + availableThrust) { offBoardDirection = OffBoardDirection.SOUTH; } return offBoardDirection; }
/** * get final elevation relative to the tops of any buildings in the hex * @return */ public int getFinalClearance() { if (getLastStep() != null) { return getLastStep().getClearance(); } IHex hex = entity.getGame().getBoard().getHex(getEntity().getPosition()); if (hex.containsTerrain(Terrains.BLDG_ELEV)) { return getEntity().getElevation() - hex.terrainLevel(Terrains.BLDG_ELEV); } return getEntity().getElevation(); }
default PilotingRollData checkStall(MovePath md) { PilotingRollData roll = ((Entity) this).getBasePilotingRoll(md.getLastStepMovementType()); // if the entity has already moved, its movement got interrupted (probably by a hidden unit, not much else can interrupt an aero unit) // in which case, the movement is complete. We just need to allow the user to hit 'done'. if(((Entity) this).delta_distance > 0) { roll.addModifier(TargetRoll.CHECK_FALSE, "Check false: aero has already moved"); // an airborne, aerodyne aero is considered to "stall" if it's not moving anywhere, // hovering, landing, or going off board } else if ((md.getFinalVelocity() == 0) && !md.contains(MoveStepType.HOVER) && isAirborne() && !isSpheroid() && !((Entity) this).getGame().getBoard().inSpace() && !md.contains(MoveStepType.LAND) && !md.contains(MoveStepType.VLAND) && !md.contains(MoveStepType.RETURN) && !md.contains(MoveStepType.OFF) && !md.contains(MoveStepType.FLEE)) { roll.append(new PilotingRollData(((Entity) this).getId(), 0, "stalled out")); } else { roll.addModifier(TargetRoll.CHECK_FALSE, "Check false: entity not stalled out"); } return roll; }
@Override public void hexSelected(BoardViewEvent b) { // Are we ignoring events? if (isIgnoringEvents()) { return; } final Client client = clientgui.getClient(); if (client.isMyTurn() && (b.getCoords() != null) && (ce() != null) && !b.getCoords().equals(ce().getPosition())) { if (shiftheld) { updateFlipArms(false); torsoTwist(b.getCoords()); } else if (phase == IGame.Phase.PHASE_TARGETING) { target(new HexTarget(b.getCoords(), ce().getGame().getBoard(), Targetable.TYPE_HEX_ARTILLERY)); } else { target(chooseTarget(b.getCoords())); } } }