-
Notifications
You must be signed in to change notification settings - Fork 376
Swarm missiles: stop at conventional infantry, and consider every unit in an adjacent hex #8958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
b532eb5
dd00dd9
9b74b03
be4c54c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6449,12 +6449,14 @@ public static Coords scatterAssaultDrop(Coords coords, int margin) { | |
| public static @Nullable Entity getSwarmMissileTarget(Game game, int aeId, Coords coords, | ||
| int weaponId) { | ||
| Entity tempEntity; | ||
| Entity attacker = game.getEntity(aeId); | ||
| // first, check the hex of the original target | ||
| Iterator<Entity> entities = game.getEntities(coords); | ||
| Vector<Entity> possibleTargets = new Vector<>(); | ||
| while (entities.hasNext()) { | ||
| tempEntity = entities.next(); | ||
| if (!tempEntity.getTargetedBySwarm(aeId, weaponId)) { | ||
| if (!tempEntity.getTargetedBySwarm(aeId, weaponId) | ||
| && canBeSwarmedFrom(game, attacker, tempEntity)) { | ||
| // we found a target | ||
| possibleTargets.add(tempEntity); | ||
| } | ||
|
|
@@ -6476,7 +6478,8 @@ public static Coords scatterAssaultDrop(Coords coords, int margin) { | |
| entities = game.getEntities(tempcoords); | ||
| if (entities.hasNext()) { | ||
| tempEntity = entities.next(); | ||
| if (!tempEntity.getTargetedBySwarm(aeId, weaponId)) { | ||
| if (!tempEntity.getTargetedBySwarm(aeId, weaponId) | ||
| && canBeSwarmedFrom(game, attacker, tempEntity)) { | ||
| // we found a target | ||
| possibleTargets.add(tempEntity); | ||
| } | ||
|
|
@@ -6490,6 +6493,36 @@ public static Coords scatterAssaultDrop(Coords coords, int margin) { | |
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Whether leftover swarm missiles may pick this unit as their secondary target. | ||
| * | ||
| * <p>Conventional infantry inside a building cannot be fired on directly from outside it; the attacker has to | ||
| * shoot the building hex instead (TW p.172). Leftover swarm missiles look for a target among the units nearby | ||
| * (TO:AUE p.183), and that search has to obey the same rule, or a volley aimed at a building ends up hitting | ||
| * the platoon sheltering in it.</p> | ||
| * | ||
| * <p>Everything else is fair game, including infantry in the open and non-infantry inside the building, which | ||
| * the building absorption rules already cover.</p> | ||
| * | ||
| * @param game the game being played | ||
| * @param attacker the unit that fired the volley, or {@code null} if it has left the board | ||
| * @param target the unit being considered as a secondary target | ||
| * | ||
| * @return {@code true} if the missiles may attack this unit | ||
| */ | ||
| private static boolean canBeSwarmedFrom(Game game, @Nullable Entity attacker, Entity target) { | ||
| boolean isShelteringInfantry = (target instanceof Infantry) && isInBuilding(game, target); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in dd00dd9 as The last one fails with the loop change reverted. The shelter case failed while the building terrain was absent, so it is genuinely reading the rule rather than passing by accident. Worth noting for anyone reusing this: the board is built in code rather than from a board string, because the test board loader fills hexes in file order rather than at the coordinates written, which put the building in the wrong hex. |
||
| if (!isShelteringInfantry) { | ||
| return true; | ||
| } | ||
| if (attacker == null) { | ||
| return false; | ||
| } | ||
| // Fire that reaches them through the building itself is legal, which is how a unit already inside shoots | ||
| // the platoon it shares the building with. | ||
| return LosEffects.calculateLOS(game, attacker, target).getThruBldg() != null; | ||
| } | ||
|
|
||
| public static @Nullable Coords getFinalPosition(Coords currentPosition, int... v) { | ||
| if ((v == null) || (v.length != 6) || (currentPosition == null)) { | ||
| return currentPosition; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, and it matters more because of this PR. The single-unit scan was already there and was mostly harmless, but this branch adds a reason to reject a unit, so a hex whose first unit is sheltering infantry now contributes nothing and hides whatever else is standing in it. Changed to walk the hex in dd00dd9, matching the original-target scan a few lines above.