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

Mounted rework #4025

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
import megamek.common.equipment.BombMounted;
import megamek.common.icons.Camouflage;
import megamek.common.icons.Portrait;
import megamek.common.loaders.BLKFile;
Expand Down Expand Up @@ -5750,15 +5751,12 @@ public void clearGameData(Entity entity) {

if (entity instanceof IBomber) {
IBomber bomber = (IBomber) entity;
List<Mounted> mountedBombs = bomber.getBombs();
List<BombMounted> mountedBombs = bomber.getBombs();
if (!mountedBombs.isEmpty()) {
// These should return an int[] filled with 0's
int[] intBombChoices = bomber.getIntBombChoices();
int[] extBombChoices = bomber.getExtBombChoices();
for (Mounted m : mountedBombs) {
if (!(m.getType() instanceof BombType)) {
continue;
}
for (BombMounted m : mountedBombs) {
if (m.getBaseShotsLeft() == 1) {
if (m.isInternalBomb()) {
intBombChoices[BombType.getBombTypeFromInternalName(m.getType().getInternalName())] += 1;
Expand Down
7 changes: 4 additions & 3 deletions MekHQ/src/mekhq/campaign/mission/CrewSkillUpgrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import megamek.codeUtilities.ObjectUtility;
import megamek.common.*;
import megamek.common.equipment.WeaponMounted;
import megamek.common.options.OptionsConstants;
import mekhq.campaign.personnel.SpecialAbility;
import mekhq.campaign.personnel.enums.PersonnelRole;
Expand Down Expand Up @@ -240,10 +241,10 @@ private boolean extraEligibilityCheck(SpecialAbility spa, Entity entity) {
* @return Weapon name
*/
private String pickRandomWeapon(Entity entity, boolean clusterOnly) {
List<Mounted> weapons = entity.getIndividualWeaponList();
List<Mounted> eligibleWeapons = new ArrayList<>();
List<WeaponMounted> weapons = entity.getIndividualWeaponList();
List<WeaponMounted> eligibleWeapons = new ArrayList<>();

for (Mounted weapon : weapons) {
for (WeaponMounted weapon : weapons) {
if (SpecialAbility.isWeaponEligibleForSPA(weapon.getType(), PersonnelRole.NONE, clusterOnly)) {
eligibleWeapons.add(weapon);
}
Expand Down
3 changes: 2 additions & 1 deletion MekHQ/src/mekhq/campaign/parts/Refit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.Version;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.MiscMounted;
import megamek.common.loaders.BLKFile;
import megamek.common.loaders.EntityLoadingException;
import megamek.common.verifier.EntityVerifier;
Expand Down Expand Up @@ -2458,7 +2459,7 @@ private Part heatSinkPart(Entity entity) {
}
return new AeroHeatSink(0, ((Aero) entity).getHeatType(), false, campaign);
} else if (entity instanceof Mech) {
Optional<Mounted> mount = entity.getMisc().stream()
Optional<MiscMounted> mount = entity.getMisc().stream()
.filter(m -> m.getType().hasFlag(MiscType.F_HEAT_SINK)
|| m.getType().hasFlag(MiscType.F_DOUBLE_HEAT_SINK))
.findAny();
Expand Down
3 changes: 2 additions & 1 deletion MekHQ/src/mekhq/campaign/parts/equipment/AmmoBin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.AmmoMounted;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
Expand Down Expand Up @@ -260,7 +261,7 @@ public void fix() {
}

public void loadBin() {
Mounted mounted = getMounted();
AmmoMounted mounted = (AmmoMounted) getMounted();
if (mounted == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.AmmoMounted;
import mekhq.campaign.Campaign;
import mekhq.campaign.parts.AmmoStorage;
import mekhq.campaign.parts.PartInventory;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void updateConditionFromPart() {

@Override
public void loadBin() {
Mounted mounted = getMounted();
AmmoMounted mounted = (AmmoMounted) getMounted();
if (mounted != null) {
// Calculate the actual shots needed
int shotsPerTrooper = shotsNeeded / getNumTroopers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ private static void checkWeaponBay(Unit unit, EquipmentType type, int equipmentN
return;
}

Mounted weaponBay = null;
Mounted<?> weaponBay = null;
for (Mounted m : unit.getEntity().getWeaponBayList()) {
if (m.getLocation() != weapon.getLocation()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import megamek.common.CriticalSlot;
import megamek.common.Mounted;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.AmmoMounted;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
Expand Down Expand Up @@ -307,7 +308,7 @@ public int getBaseTime() {

@Override
public void updateConditionFromPart() {
Mounted mounted = getMounted();
AmmoMounted mounted = (AmmoMounted) getMounted();
if (mounted != null) {
mounted.setHit(false);
mounted.setDestroyed(false);
Expand Down
59 changes: 30 additions & 29 deletions MekHQ/unittests/mekhq/campaign/parts/equipment/AmmoBinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.common.Entity;
import megamek.common.Mounted;
import megamek.common.Protomech;
import megamek.common.equipment.AmmoMounted;
import mekhq.campaign.Campaign;
import mekhq.campaign.CampaignOptions;
import mekhq.campaign.Quartermaster;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void setShotsNeeded() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
doAnswer(invocation -> {
Expand Down Expand Up @@ -318,12 +319,12 @@ public void getFullShotsUsesOriginalShotsFromMounted() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
int originalShots = 32;
when(mockMounted.getOriginalShots()).thenReturn(originalShots);

when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and ensure it reports the shots from the mounted and not the ammo type
Expand Down Expand Up @@ -593,10 +594,10 @@ public void changeMunitionTest() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(isSRM2Ammo);
when(mockMounted.getBaseShotsLeft()).thenReturn(isSRM2Ammo.getShots());
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
doAnswer(invocation -> {
// Update the ammo type returned by mounted
AmmoType newAmmoType = invocation.getArgument(0);
Expand Down Expand Up @@ -881,10 +882,10 @@ public void loadBinWithoutSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and try to load it when the warehouse is empty.
Expand Down Expand Up @@ -916,10 +917,10 @@ public void loadBinWithOnlySpareAmmoOfWrongType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add ammo of the wrong type to the warehouse ...
Expand Down Expand Up @@ -958,10 +959,10 @@ public void loadBinWithJustEnoughSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of the right type to the warehouse ...
Expand Down Expand Up @@ -999,10 +1000,10 @@ public void loadBinWithMoreThanEnoughSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add more than enough ammo of the right type to the warehouse ...
Expand Down Expand Up @@ -1042,7 +1043,7 @@ public void loadEmptyBinAfterChangingAmmoType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
doAnswer(invocation -> {
Expand All @@ -1058,7 +1059,7 @@ public void loadEmptyBinAfterChangingAmmoType() {
return null;
}).when(mockMounted).setShotsLeft(anyInt());

when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of both types to the warehouse ...
Expand Down Expand Up @@ -1105,7 +1106,7 @@ public void loadFullBinAfterChangingAmmoType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(ammoType.getShots());
doAnswer(invocation -> {
Expand All @@ -1121,7 +1122,7 @@ public void loadFullBinAfterChangingAmmoType() {
return null;
}).when(mockMounted).setShotsLeft(anyInt());

when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of the new type to the warehouse ...
Expand Down Expand Up @@ -1187,10 +1188,10 @@ public void fixBinWithoutSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and try to load it when the warehouse is empty.
Expand Down Expand Up @@ -1222,10 +1223,10 @@ public void fixBinWithOnlySpareAmmoOfWrongType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add ammo of the wrong type to the warehouse ...
Expand Down Expand Up @@ -1264,10 +1265,10 @@ public void fixBinWithJustEnoughSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of the right type to the warehouse ...
Expand Down Expand Up @@ -1305,10 +1306,10 @@ public void fixBinWithMoreThanEnoughSpareAmmo() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add more than enough ammo of the right type to the warehouse ...
Expand Down Expand Up @@ -1348,7 +1349,7 @@ public void fixEmptyBinAfterChangingAmmoType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(0);
doAnswer(invocation -> {
Expand All @@ -1364,7 +1365,7 @@ public void fixEmptyBinAfterChangingAmmoType() {
return null;
}).when(mockMounted).setShotsLeft(anyInt());

when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of both types to the warehouse ...
Expand Down Expand Up @@ -1411,7 +1412,7 @@ public void fixFullBinAfterChangingAmmoType() {
Unit mockUnit = mock(Unit.class);
Entity mockEntity = mock(Entity.class);
when(mockUnit.getEntity()).thenReturn(mockEntity);
Mounted mockMounted = mock(Mounted.class);
AmmoMounted mockMounted = mock(AmmoMounted.class);
when(mockMounted.getType()).thenReturn(ammoType);
when(mockMounted.getBaseShotsLeft()).thenReturn(ammoType.getShots());
doAnswer(invocation -> {
Expand All @@ -1427,7 +1428,7 @@ public void fixFullBinAfterChangingAmmoType() {
return null;
}).when(mockMounted).setShotsLeft(anyInt());

when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn(mockMounted);
when(mockEntity.getEquipment(eq(equipmentNum))).thenReturn((Mounted) mockMounted);
ammoBin.setUnit(mockUnit);

// ... and add just enough ammo of the new type to the warehouse ...
Expand Down
Loading
Loading