Skip to content

Commit

Permalink
Merge pull request #5929 from Sleet01/Fix_Ammo_AutoConfig_Artemis_Ski…
Browse files Browse the repository at this point in the history
…ps_SRMs_and_MMLs

Fix ammo auto config for Artemis skipping SRMs and MMLs
  • Loading branch information
Sleet01 authored Aug 20, 2024
2 parents 7682f16 + 680a62b commit 9897142
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
25 changes: 20 additions & 5 deletions megamek/src/megamek/client/generator/TeamLoadoutGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,22 +721,35 @@ private static boolean applyACCaselessImperative(Entity e, MunitionTree mt, Reco
return swapped;
}

// Set Artemis LRM carriers to use Artemis LRMs
private static boolean setLRMImperatives(Entity e, MunitionTree mt, ReconfigurationParameters rp) {
private static boolean insertArtemisImperatives(Entity e, MunitionTree mt, String ammoClass) {
boolean artemis = !(e.getMiscEquipment(MiscType.F_ARTEMIS).isEmpty()
&& e.getMiscEquipment(MiscType.F_ARTEMIS_V).isEmpty());

if (artemis) {
for (Mounted wpn : e.getWeaponList()) {
if (wpn.getName().toLowerCase().contains("lrm")) {
mt.insertImperative(e.getFullChassis(), e.getModel(), "any", wpn.getType().getShortName(),
for (AmmoMounted bin : e.getAmmo()) {
if (bin.getName().toUpperCase().contains(ammoClass)) {
String binType = bin.getType().getBaseName();
mt.insertImperative(e.getFullChassis(), e.getModel(), "any", binType,
"Artemis-capable");
}
}
return true;
}
return false;
}

// Set Artemis LRM carriers to use Artemis LRMs
private static boolean setLRMImperatives(Entity e, MunitionTree mt, ReconfigurationParameters rp) {
return insertArtemisImperatives(e, mt, "LRM");
}

private static boolean setSRMImperatives(Entity e, MunitionTree mt, ReconfigurationParameters rp) {
return insertArtemisImperatives(e, mt, "SRM");
}

private static boolean setMMLImperatives(Entity e, MunitionTree mt, ReconfigurationParameters rp) {
return insertArtemisImperatives(e, mt, "MML");
}
// region Imperative mutators

// region generateMunitionTree
Expand Down Expand Up @@ -945,6 +958,8 @@ public static MunitionTree generateMunitionTree(ReconfigurationParameters rp, Ar
// utility
setACImperatives(e, mt, rp);
setLRMImperatives(e, mt, rp);
setSRMImperatives(e, mt, rp);
setMMLImperatives(e, mt, rp);
}

return mt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TeamLoadoutGeneratorTest {
static AmmoType mockAC20AmmoType = (AmmoType) EquipmentType.get("ISAC20 Ammo");
static AmmoType mockAC5AmmoType = (AmmoType) EquipmentType.get("ISAC5 Ammo");
static AmmoType mockSRM6AmmoType = (AmmoType) EquipmentType.get("IS SRM 6 Ammo");
static AmmoType mockMML7LRMAmmoType = (AmmoType) EquipmentType.get("ISMML7 LRM Ammo");
static AmmoType mockMML7SRMAmmoType = (AmmoType) EquipmentType.get("ISMML7 SRM Ammo");

@BeforeAll
static void setUpAll() {
Expand Down Expand Up @@ -370,6 +372,38 @@ void testReconfigureBotTeamNoEnemyInfo() throws LocationFullException {
}
}

@Test
void testReconfigureBotTeamAllArtemis() throws LocationFullException {
TeamLoadoutGenerator tlg = new TeamLoadoutGenerator(game);
Mech mockMech = createMech("Warhammer", "WHM-6Rb", "Asgard");
mockMech.addEquipment(EquipmentType.get("IS Artemis IV FCS"), Mech.LOC_RT);
Mech mockMech2 = createMech("Valkyrie", "VLK-QW5", "Wobbles");
mockMech2.addEquipment(EquipmentType.get("Clan Artemis IV FCS"), Mech.LOC_RT);
Mech mockMech3 = createMech("Cougar", "XR", "Sarandon");
mockMech3.addEquipment(EquipmentType.get("Clan Artemis V"), Mech.LOC_RT);
mockMech.setOwner(player);
mockMech2.setOwner(player);
mockMech3.setOwner(player);
game.setEntity(0, mockMech);
game.setEntity(1, mockMech2);
game.setEntity(2, mockMech3);

// Load ammo in 'mechs; locations are for fun
Mounted bin1 = mockMech.addEquipment(mockSRM6AmmoType, Mech.LOC_CT);
Mounted bin2 = mockMech2.addEquipment(mockMML7LRMAmmoType, Mech.LOC_LT);
Mounted bin3 = mockMech2.addEquipment(mockMML7SRMAmmoType, Mech.LOC_LT);
Mounted bin4 = mockMech3.addEquipment(mockLRM15AmmoType, Mech.LOC_LT);
Mounted bin5 = mockMech3.addEquipment(mockLRM15AmmoType, Mech.LOC_LT);

// Just check that the bins are populated still
tlg.reconfigureTeam(team, "IS", "");

for (Mounted bin : List.of(bin1, bin2, bin3, bin4, bin5)) {
assertNotEquals("Standard", ((AmmoType) bin.getType()).getSubMunitionName());
assertTrue(((AmmoType) bin.getType()).getSubMunitionName().contains("Artemis"));
}
}

// Section: legalityCheck tests
@Test
void testAmmoTypeIllegalByTechLevel() {
Expand Down

0 comments on commit 9897142

Please sign in to comment.