diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index fa40dabd88d..91d75edb033 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -899,6 +899,7 @@ public enum InvalidSourceBuildReason { private boolean hasFleeZone = false; private HexArea fleeZone = HexArea.EMPTY_AREA; + private transient Boolean cacheHasNoModularArmor = null; /** * Generates a new, blank, entity. @@ -6447,6 +6448,7 @@ public void newRound(int roundNumber) { isJumpingNow = false; convertingNow = false; damageThisRound = 0; + cacheHasNoModularArmor = null; if (assaultDropInProgress == 2) { assaultDropInProgress = 0; } @@ -12131,7 +12133,10 @@ public boolean isAeroSensorDestroyed() { } public boolean hasModularArmor() { - return hasModularArmor(-1); + if (cacheHasNoModularArmor == null || cacheHasNoModularArmor) { + cacheHasNoModularArmor = hasModularArmor(-1); + } + return cacheHasNoModularArmor; } public boolean hasModularArmor(int loc) { diff --git a/megamek/src/megamek/common/Mek.java b/megamek/src/megamek/common/Mek.java index 9eb4ee92477..a9e70a711be 100644 --- a/megamek/src/megamek/common/Mek.java +++ b/megamek/src/megamek/common/Mek.java @@ -318,6 +318,8 @@ public abstract class Mek extends Entity { // Cooling System Flaws quirk private boolean coolingFlawActive = false; + private transient Boolean cacheHasNoIndustrialTSM = null; + // QuadVees, LAMs, and tracked 'Meks can change movement mode. protected EntityMovementMode originalMovementMode = EntityMovementMode.BIPED; @@ -610,6 +612,7 @@ public void newRound(int roundNumber) { m.setMode("Off"); } } // Check the next piece of equipment. + cacheHasNoIndustrialTSM = null; super.newRound(roundNumber); incrementMASCAndSuperchargerLevels(); @@ -885,13 +888,19 @@ public boolean hasActiveTSM(boolean includeIndustrial) { * @return */ public boolean hasIndustrialTSM() { - for (Mounted m : getEquipment()) { - if ((m.getType() instanceof MiscType) + // This is a special cache that returns immediatelly if the value is false + // but checks for the real value if it is not (because it may lose the state, but cannot gain during normal gameplay) + if (cacheHasNoIndustrialTSM == null || cacheHasNoIndustrialTSM) { + for (Mounted m : getEquipment()) { + if ((m.getType() instanceof MiscType) && m.getType().hasFlag(MiscType.F_INDUSTRIAL_TSM)) { - return true; + cacheHasNoIndustrialTSM = true; + return true; + } } + cacheHasNoIndustrialTSM = false; } - return false; + return cacheHasNoIndustrialTSM; } /**