/** * Initialize an entity state from a movement path */ EntityState(MovePath path) { position = path.getFinalCoords(); facing = path.getFinalFacing(); hexesMoved = path.getHexesMoved(); heat = path.getEntity().heat; if (path.getLastStepMovementType() == EntityMovementType.MOVE_WALK) { heat = getHeat() + 1; } else if (path.getLastStepMovementType() == EntityMovementType.MOVE_RUN) { heat = getHeat() + 2; } else if ((path.getLastStepMovementType() == EntityMovementType.MOVE_JUMP) && (getHexesMoved() <= 3)) { heat = getHeat() + 3; } else if ((path.getLastStepMovementType() == EntityMovementType.MOVE_JUMP) && (getHexesMoved() > 3)) { heat = getHeat() + getHexesMoved(); } prone = path.getFinalProne() || path.getFinalHullDown(); immobile = path.getEntity().isImmobile(); jumping = path.isJumping(); movementType = path.getLastStepMovementType(); naturalAptGun = path.getEntity().hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY); naturalAptPilot = path.getEntity().hasAbility(OptionsConstants.PILOT_APTITUDE_PILOTING); setSecondaryFacing(getFacing()); }
protected void setDamageDirection(EntityState targetState, Coords shooterCoords) { int fromDirection = targetState.getPosition().direction(shooterCoords); setDamageDirection(((fromDirection - targetState.getFacing()) + 6) % 6); }
private EntityState getTargetState() { if (null == targetState) { targetState = new EntityState(target); } return targetState; }
shooterState = new EntityState(shooter); targetState = new EntityState(target); if ((null == shooterState.getPosition()) || (null == targetState.getPosition())) { return new ToHitData(TH_NULL_POSITION); toHitData.append(getAttackerMovementModifier(game, shooter.getId(), shooterState.getMovementType())); if (!shooterState.isAero() && targetState.isAirborneAero()) { final IAero targetAero = (IAero) target; if (((Entity)targetAero).isNOE()) { final Coords closestInFlightPath = getNearestPointInFlightPath(shooterState.getPosition(), targetAero); final int aeroDistance = closestInFlightPath.distance(shooterState.getPosition()); if (1 >= aeroDistance) { toHitData.addModifier(TH_TAR_AERO_NOE_ADJ); toHitData.append(getTargetMovementModifier(targetState.getHexesMoved(), targetState.isJumping(), target instanceof VTOL, game)); if (shooterState.isProne()) { toHitData.addModifier(TH_ATT_PRONE); if (targetState.isImmobile() && !target.isHexBeingBombed()) { toHitData.addModifier(TH_TAR_IMMOBILE); && (EntityMovementType.MOVE_NONE == targetState.getMovementType()) && !targetState.isImmobile() && !((target instanceof Infantry) || (target instanceof VTOL) ||
Mockito.when(mockGameOptions.booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE)).thenReturn(false); Mockito.when(mockTarget.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_POS_LOW_PROFILE))).thenReturn(false); Mockito.when(mockShooterState.getFacing()).thenReturn(1); Mockito.doReturn(true).when(testFireControl).isInArc(Mockito.any(Coords.class), Mockito.anyInt(), Mockito.any(Coords.class), Mockito.anyInt()); Mockito.when(mockTargetState.getPosition()).thenReturn(new Coords(0, 15)); Mockito.when(mockShooter.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_POS_IMP_TARG_L))).thenReturn(true); expected = new ToHitData(mockShooter.getCrew().getGunnery(), FireControl.TH_GUNNERY); mockWeapon, mockGame)); Mockito.when(mockShooter.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_NEG_POOR_TARG_L))).thenReturn(false); Mockito.when(mockTargetState.getPosition()).thenReturn(mockTargetCoords); Mockito.when(mockTargetState.getPosition()).thenReturn(new Coords(0, 5)); Mockito.when(mockShooter.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_POS_IMP_TARG_S))).thenReturn(true); expected = new ToHitData(mockShooter.getCrew().getGunnery(), FireControl.TH_GUNNERY); mockWeapon, mockGame)); Mockito.when(mockShooter.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_NEG_POOR_TARG_S))).thenReturn(false); Mockito.when(mockTargetState.getPosition()).thenReturn(mockTargetCoords); Mockito.when(mockFighter.getTargetId()).thenReturn(2); final EntityState mockFighterState = Mockito.mock(EntityState.class); Mockito.when(mockFighterState.isAirborneAero()).thenReturn(true); Mockito.when(mockFighterState.isBuilding()).thenReturn(false); Mockito.when(mockFighterState.getHeat()).thenReturn(0); Mockito.when(mockFighterState.getPosition()).thenReturn(mockTargetCoords); expected = new ToHitData(mockShooter.getCrew().getGunnery(), FireControl.TH_GUNNERY);
shooterState = new EntityState(shooter); targetState = new EntityState(target); if (shooterState.isProne()) { int shooterFacing = shooterState.getFacing(); if (shooter.isSecondaryArcWeapon(shooter.getEquipmentNum(weapon))) { shooterFacing = shooterState.getSecondaryFacing(); final boolean inArc = isInArc(shooterState.getPosition(), shooterFacing, targetState.getPosition(), shooter.getWeaponArc(shooter.getEquipmentNum(weapon))); if (!inArc) { int distance = shooterState.getPosition().distance(targetState.getPosition()); if (targetState.isAirborneAero() && !shooterState.isAero()) { if (RangeType.RANGE_OUT == range) { return new ToHitData(TH_OUT_OF_RANGE); } else if ((RangeType.RANGE_MINIMUM == range) && targetState.isAirborneAero()) { range = RangeType.RANGE_SHORT; !targetState.isAirborneAero()) { return new ToHitData(TH_INF_ZERO_RNG); final LosEffects losEffects = getLosEffects(game, shooter.getId(), target, shooterState.getPosition(), targetState.getPosition(), false);
Mockito.when(mockShooterState.isProne()).thenReturn(false); Mockito.when(mockShooter.hasQuirk(Mockito.eq(OptionsConstants.QUIRK_POS_ANTI_AIR))).thenReturn(false); Mockito.when(mockTargetState.isImmobile()).thenReturn(false); Mockito.when(mockTargetState.getMovementType()).thenReturn(EntityMovementType.MOVE_NONE); Mockito.when(mockTargetState.getPosition()).thenReturn(new Coords(10, 0)); Mockito.when(mockTargetState.isProne()).thenReturn(false); Mockito.when(mockTarget.isAirborne()).thenReturn(false); Mockito.when(mockTarget.isAirborneVTOLorWIGE()).thenReturn(false); Mockito.when(mockFighter.isNOE()).thenReturn(true); final EntityState mockFighterState = Mockito.mock(EntityState.class); Mockito.when(mockFighterState.isAirborneAero()).thenReturn(true); Mockito.when(mockFighterState.isImmobile()).thenReturn(false); Mockito.when(mockFighterState.getMovementType()).thenReturn(EntityMovementType.MOVE_SAFE_THRUST); Mockito.when(mockFighterState.getPosition()).thenReturn(new Coords(10, 0)); Mockito.when(mockFighterState.isProne()).thenReturn(false); Mockito.doReturn(new Coords(0, 2)).when(testFireControl).getNearestPointInFlightPath(Mockito.any(Coords.class), Mockito.any(Aero.class)); Mockito.when(mockShooterState.getPosition()).thenReturn(null); expected = new ToHitData(FireControl.TH_NULL_POSITION); assertToHitDataEquals(expected, testFireControl.guessToHitModifierHelperForAnyAttack(mockShooter, 10, mockGame)); Mockito.when(mockShooterState.getPosition()).thenReturn(new Coords(0, 0)); Mockito.when(mockTargetState.getPosition()).thenReturn(null); expected = new ToHitData(FireControl.TH_NULL_POSITION);
mockShooterState = Mockito.mock(EntityState.class); mockShooterCoords = new Coords(0, 0); Mockito.when(mockShooterState.getPosition()).thenReturn(mockShooterCoords); mockShooterMoveMod = new ToHitData(); Mockito.when(mockTargetState.isBuilding()).thenReturn(false); Mockito.when(mockTargetState.getHeat()).thenReturn(0); mockTargetMoveMod = new ToHitData(); mockTargetCoords = new Coords(10, 0); Mockito.when(mockTargetState.getPosition()).thenReturn(mockTargetCoords);
shooterState = new EntityState(shooter); targetState = new EntityState(target); final int distance = shooterState.getPosition().distance(targetState.getPosition()); if (1 < distance) { return new ToHitData(TH_PHY_TOO_FAR); if (!isInArc(shooterState.getPosition(), shooterState.getSecondaryFacing(), targetState.getPosition(), arc)) { return new ToHitData(TH_PHY_NOT_IN_ARC); final IHex attackerHex = game.getBoard().getHex(shooterState.getPosition()); final IHex targetHex = game.getBoard().getHex(targetState.getPosition()); final int attackerElevation = shooter.getElevation() + attackerHex.getLevel(); final int attackerHeight = shooter.relHeight() + attackerHex.getLevel(); if (shooterState.isProne()) { return new ToHitData(TH_PHY_P_TAR_PRONE); if (shooterState.isProne()) { return new ToHitData(TH_PHY_K_PRONE);
&& ((9 <= target.getHeat()) || target.isBuilding()) && !fireResistant) { returnAmmo = infernoAmmo;
shooterState = new EntityState(shooter); targetState = new EntityState(target); && !(EntityMovementType.MOVE_NONE == shooterState.getMovementType())) { continue; && !(EntityMovementType.MOVE_NONE == shooterState.getMovementType()) && (Infantry.LOC_FIELD_GUNS == shoot.getWeapon().getLocation())) { continue; calculateUtility(myPlan, calcHeatTolerance(shooter, null), shooterState.isAero());
shooterState = new EntityState(getShooter()); targetState = new EntityState(getTarget()); setDamageDirection(targetState, shooterState.getPosition()); if (shooterState.hasNaturalAptPiloting()) { msg.append("\n\tAttacker has Natural Aptitude Piloting"); setProbabilityToHit(Compute.oddsAbove(getHitData().getValue(), shooterState.hasNaturalAptPiloting()) / 100.0);
Mockito.anyInt(), Mockito.any(IGame.class)); mockTargetCoords = new Coords(0, 1); Mockito.when(mockTargetState.getPosition()).thenReturn(mockTargetCoords); Mockito.doReturn(true).when(testFireControl).isInArc(Mockito.any(Coords.class), Mockito.anyInt(), Mockito.any(Coords.class), Mockito.anyInt()); final IHex mockShooterHex = Mockito.mock(IHex.class); Mockito.when(mockShooterHex.getLevel()).thenReturn(0); Mockito.when(mockBoard.getHex(Mockito.eq(mockShooterState.getPosition()))).thenReturn(mockShooterHex); Mockito.when(mockShooter.getElevation()).thenReturn(0); Mockito.when(mockShooter.relHeight()).thenReturn(2); Mockito.when(mockBoard.getHex(Mockito.eq(mockTargetState.getPosition()))).thenReturn(mockTargetHex); Mockito.when(mockTarget.getElevation()).thenReturn(0); Mockito.when(mockTarget.getHeight()).thenReturn(2); PhysicalAttackType.LEFT_KICK, mockGame)); Mockito.when(mockTargetState.getPosition()).thenReturn(new Coords(0, 0)); // Move them into my hex. expected = new ToHitData(); expected.addModifier(mockCrew.getPiloting() - 2, FireControl.TH_PHY_BASE); PhysicalAttackType.LEFT_KICK, mockGame)); Mockito.when(mockTargetState.getPosition()).thenReturn(new Coords(0, 1)); Mockito.when(mockShooterState.isProne()).thenReturn(true); assertToHitDataEquals(expected, testFireControl.guessToHitModifierPhysical(mockShooter, mockShooterState, mockTarget, mockTargetState, PhysicalAttackType.LEFT_KICK,
LosEffects.calculateLos(game, enemy.getId(), path.getEntity(), shooterState.getPosition(), targetState.getPosition(), false); actualTarget = new BuildingTarget(targetState.getPosition(), game.getBoard(), false); targetState = new EntityState(actualTarget);
private int calcAttackDirection() { return getTargetState().getPosition().direction(getShooterState().getPosition()); }
private int calcDamageDirection() { return ((calcAttackDirection() - getTargetState().getFacing()) + 6) % 6; }
Mockito.when(mockTargetState.isBuilding()).thenReturn(true); testAmmoList.add(mockAmmoAtm5He); testAmmoList.add(mockAmmoAtm5Er); Assert.assertEquals(mockAmmoAtm5Inferno, testFireControl.getAtmAmmo(testAmmoList, 8, mockTargetState, false)); Assert.assertEquals(mockAmmoAtm5St, testFireControl.getAtmAmmo(testAmmoList, 8, mockTargetState, true)); Mockito.when(mockTargetState.isBuilding()).thenReturn(false); Mockito.when(mockTargetState.getHeat()).thenReturn(9); Assert.assertEquals(mockAmmoAtm5Inferno, testFireControl.getAtmAmmo(testAmmoList, 8, mockTargetState, false)); Assert.assertEquals(mockAmmoAtm5St, testFireControl.getAtmAmmo(testAmmoList, 8, mockTargetState, true)); Mockito.when(mockTargetState.getHeat()).thenReturn(0);
/** * Checks if a target lies under a move path, to see if an aero unit can attack it. * * @param flightPath move path to check * @param targetState used for targets position * @return TRUE if the target is under the path. */ boolean isTargetUnderFlightPath(final MovePath flightPath, final EntityState targetState) { final Coords targetCoords = targetState.getPosition(); for (final Enumeration<MoveStep> step = flightPath.getSteps(); step.hasMoreElements(); ) { final Coords stepCoords = step.nextElement().getPosition(); if (targetCoords.equals(stepCoords)) { return true; } } return false; }
Mockito.when(mockShooterState.getPosition()).thenReturn(SHOOTER_COORDS); Mockito.when(mockTargetState.getFacing()).thenReturn(TARGET_FACING); Mockito.when(mockTargetState.getPosition()).thenReturn(TARGET_COORDS_9);
private EntityState getShooterState() { if (null == shooterState) { shooterState = new EntityState(getShooter()); } return shooterState; }