Skip to content
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

Fix 5193: Weapon Bays only work at Short Range #5195

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions megamek/src/megamek/common/weapons/bayweapons/BayWeapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
*/
package megamek.common.weapons.bayweapons;

import megamek.common.Entity;
import megamek.common.Game;
import megamek.common.Mounted;
import megamek.common.SimpleTechLevel;
import megamek.common.TechAdvancement;
import megamek.common.ToHitData;
import megamek.common.WeaponType;
import megamek.common.*;
import megamek.common.actions.WeaponAttackAction;
import megamek.common.weapons.AttackHandler;
import megamek.common.weapons.BayWeaponHandler;
Expand Down Expand Up @@ -56,7 +50,7 @@ public AttackHandler fire(WeaponAttackAction waa, Game game, GameManager manager

/*
* (non-Javadoc)
*
*
* @see
* megamek.common.weapons.Weapon#getCorrectHandler(megamek.common.ToHitData,
* megamek.common.actions.WeaponAttackAction, megamek.common.Game)
Expand All @@ -66,9 +60,14 @@ protected AttackHandler getCorrectHandler(ToHitData toHit,
WeaponAttackAction waa, Game game, GameManager manager) {
return new BayWeaponHandler(toHit, waa, game, manager);
}

@Override
public int getMaxRange(Mounted weapon) {
return this.getMaxRange(weapon, null);
}

@Override
public int getMaxRange(Mounted weapon, Mounted ammo) {
int mrange = RANGE_SHORT;
Entity ae = weapon.getEntity();
if (null != ae) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public int getRoundExtAV() {

@Override
public int getMaxRange(Mounted weapon) {
return this.getMaxRange(weapon, null);
}

@Override
public int getMaxRange(Mounted weapon, Mounted ammo) {
for (int range = RangeType.RANGE_EXTREME; range >= RangeType.RANGE_SHORT; range--) {
if (infantryRange * 3 > AIRBORNE_WEAPON_RANGES[range - 1]) {
return range;
Expand Down
51 changes: 51 additions & 0 deletions megamek/unittests/megamek/common/WeaponTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,31 @@
*/
package megamek.common;

import megamek.common.weapons.Weapon;
import megamek.common.weapons.bayweapons.BayWeapon;
import megamek.common.weapons.bayweapons.PPCBayWeapon;
import megamek.common.weapons.ppc.ISERPPC;
import megamek.common.weapons.ppc.PPCWeapon;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.Enumeration;
import java.util.Vector;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class WeaponTypeTest {

private Entity mockEntity = mock(Entity.class);

@BeforeAll
static void before(){
EquipmentType.initializeTypes();
}

@Test
public void testArtemisCompatibleFlag() {
for (Enumeration<EquipmentType> e = EquipmentType.getAllTypes(); e.hasMoreElements(); ) {
Expand All @@ -45,4 +63,37 @@ public void testArtemisCompatibleFlag() {
}
}
}

private Mounted setupBayWeapon(String name){
EquipmentType etype = EquipmentType.get(name);
Mounted weapon = new Mounted(mockEntity, etype);
Mounted bWeapon = new Mounted(mockEntity, ((WeaponType) weapon.getType()).getBayType());
bWeapon.addWeaponToBay(mockEntity.getEquipmentNum(weapon));
when(mockEntity.getEquipment(anyInt())).thenReturn(weapon);

return bWeapon;
}

@Test
public void testWeaponBaysGetCorrectMaxRanges() {
Mounted ppcbay = setupBayWeapon("ISERPPC");
WeaponType wtype = (WeaponType) ppcbay.getType();
assertEquals(RangeType.RANGE_LONG, wtype.getMaxRange(ppcbay));

Mounted erplasbay = setupBayWeapon("CLERLargePulseLaser");
wtype = (WeaponType) erplasbay.getType();
assertEquals(RangeType.RANGE_LONG, wtype.getMaxRange(erplasbay ));

Mounted islplasbay = setupBayWeapon("ISLargePulseLaser");
wtype = (WeaponType) islplasbay.getType();
assertEquals(RangeType.RANGE_MEDIUM, wtype.getMaxRange(islplasbay));

Mounted ersmlasbay = setupBayWeapon("CLERSmallLaser");
wtype = (WeaponType) ersmlasbay.getType();
assertEquals(RangeType.RANGE_SHORT, wtype.getMaxRange(ersmlasbay));

Mounted islgaussbay = setupBayWeapon("ISLightGaussRifle");
wtype = (WeaponType) islgaussbay .getType();
assertEquals(RangeType.RANGE_EXTREME, wtype.getMaxRange(islgaussbay ));
}
}
Loading