From e51fc28afeb5a118c8b61d6534db2c2414439b51 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 29 Jul 2023 14:35:28 -0400 Subject: [PATCH 1/7] unit tooltip display tank crits in mini armour display --- .../i18n/megamek/client/messages.properties | 5 + .../client/ui/swing/tooltip/UnitToolTip.java | 267 ++++++++++++++---- 2 files changed, 224 insertions(+), 48 deletions(-) diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index 43742f33326..e67113ed741 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -437,6 +437,11 @@ BoardView1.Tooltip.AbbreviationHip=H BoardView1.Tooltip.AbbreviationUpperLeg=UL BoardView1.Tooltip.AbbreviationLowerLeg=LL BoardView1.Tooltip.AbbreviationLowerFoot=F +BoardView1.Tooltip.AbbreviationStabilizers=S +BoardView1.Tooltip.AbbreviationTurretLocked=L +BoardView1.Tooltip.AbbreviationMinorMovementDamage=Minor +BoardView1.Tooltip.AbbreviationModerateMovementDamage=Moderate +BoardView1.Tooltip.AbbreviationHeavyMovementDamage=Heavy BoardView1.Tooltip.ActiveTroopers=Active Troopers BoardView1.Tooltip.AeroVelAltFuel=Velocity: {0}, Altitude: {1}, Fuel: {2} BoardView1.Tooltip.AeroStartingVelAlt=Starting Velocity: {0}, Altitude: {1} diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index 0835acca5f6..3d35c3494ad 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -295,6 +295,104 @@ private static StringBuilder sysCrits(Entity entity, int type, int index, int lo return new StringBuilder().append(result); } + private static StringBuilder sysStabilizers(Tank tank, int loc, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.isStabiliserHit(loc) ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysTurretLocked(Tank tank, int loc, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.isTurretLocked(loc) ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysEngineHit(Tank tank, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.isEngineHit() ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysSensorHit(Tank tank, String locAbbr) { + String result = ""; + int total = 4; + int hits = tank.getSensorHits(); + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysMinorMovementDamage(Tank tank, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.hasMinorMovementDamage() ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysModerateMovementDamage(Tank tank, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.hasModerateMovementDamage() ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + + private static StringBuilder sysHeavyMovementDamage(Tank tank, String locAbbr) { + String result = ""; + int total = 1; + int hits = tank.hasHeavyMovementDamage() ? 1 :0; + int good = total - hits; + boolean bad = hits > 0; + + locAbbr = "  " + locAbbr + ": "; + result = guiScaledFontHTML(TT_SMALLFONT_DELTA) + locAbbr + ""; + result += systemBar(good, hits, bad); + + return new StringBuilder().append(result); + } + /** Returns the graphical Armor representation. */ private static StringBuilder addArmorMiniVisToTT(Entity entity) { if (!GUIP.getshowArmorMiniVisTT()) { @@ -312,6 +410,24 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { String row = ""; String rows = ""; + String msg_abbr_sensors = Messages.getString("BoardView1.Tooltip.AbbreviationSensors"); + String msg_abbr_lifesupport = Messages.getString("BoardView1.Tooltip.AbbreviationLifeSupport"); + String msg_abbr_engine = Messages.getString("BoardView1.Tooltip.AbbreviationEngine"); + String msg_abbr_gyro = Messages.getString("BoardView1.Tooltip.AbbreviationGyro"); + String msg_abbr_shoulder = Messages.getString("BoardView1.Tooltip.AbbreviationShoulder"); + String msg_abbr_upperarm = Messages.getString("BoardView1.Tooltip.AbbreviationUpperArm"); + String msg_abbr_lowerarm = Messages.getString("BoardView1.Tooltip.AbbreviationLowerArm"); + String msg_abbr_hand = Messages.getString("BoardView1.Tooltip.AbbreviationHand"); + String msg_abbr_hip = Messages.getString("BoardView1.Tooltip.AbbreviationHip"); + String msg_abbr_upperleg = Messages.getString("BoardView1.Tooltip.AbbreviationUpperLeg"); + String msg_abbr_lowerleg = Messages.getString("BoardView1.Tooltip.AbbreviationLowerLeg"); + String msg_abbr_foot = Messages.getString("BoardView1.Tooltip.AbbreviationLowerFoot"); + String msg_abbr_stabilizers = Messages.getString("BoardView1.Tooltip.AbbreviationStabilizers"); + String msg_abbr_turretlocked = Messages.getString("BoardView1.Tooltip.AbbreviationTurretLocked"); + String msg_abbr_minormovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationMinorMovementDamage"); + String msg_abbr_moderatemovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationModerateMovementDamage"); + String msg_abbr_heavymovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationHeavyMovementDamage"); + for (int loc = 0 ; loc < entity.locations(); loc++) { // do not show locations that do not support/have armor/internals like HULL on Aero if (hideArmorLocation(entity, loc)) { @@ -346,54 +462,80 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { col2 += intactLocBar(entity.getOArmor(loc), entity.getArmor(loc), armorChar).toString(); } - String msg_abbr_sensors = Messages.getString("BoardView1.Tooltip.AbbreviationSensors"); - String msg_abbr_lifesupport = Messages.getString("BoardView1.Tooltip.AbbreviationLifeSupport"); - String msg_abbr_engine = Messages.getString("BoardView1.Tooltip.AbbreviationEngine"); - String msg_abbr_gyro = Messages.getString("BoardView1.Tooltip.AbbreviationGyro"); - String msg_abbr_shoulder = Messages.getString("BoardView1.Tooltip.AbbreviationShoulder"); - String msg_abbr_upperarm = Messages.getString("BoardView1.Tooltip.AbbreviationUpperArm"); - String msg_abbr_lowerarm = Messages.getString("BoardView1.Tooltip.AbbreviationLowerArm"); - String msg_abbr_hand = Messages.getString("BoardView1.Tooltip.AbbreviationHand"); - String msg_abbr_hip = Messages.getString("BoardView1.Tooltip.AbbreviationHip"); - String msg_abbr_upperleg = Messages.getString("BoardView1.Tooltip.AbbreviationUpperLeg"); - String msg_abbr_lowerleg = Messages.getString("BoardView1.Tooltip.AbbreviationLowerLeg"); - String msg_abbr_foot = Messages.getString("BoardView1.Tooltip.AbbreviationLowerFoot"); - - switch (loc) { - case 0: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); - break; - case 1: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO, loc, msg_abbr_gyro).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); - break; - case 2: - case 3: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_gyro).toString(); - break; - case 4: - case 5: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_SHOULDER, loc, msg_abbr_shoulder).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_ARM, loc, msg_abbr_upperarm).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM, loc, msg_abbr_lowerarm).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND, loc, msg_abbr_hand).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HIP, loc, msg_abbr_hip).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_LEG, loc, msg_abbr_upperleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_FOOT, loc, msg_abbr_foot).toString(); - break; - case 6: - case 7: - case 8: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HIP, loc, msg_abbr_hip).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_LEG, loc, msg_abbr_upperleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_FOOT, loc, msg_abbr_foot).toString(); - break; + if (entity instanceof Mech) { + switch (loc) { + case 0: + col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); + break; + case 1: + col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO, loc, msg_abbr_gyro).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); + break; + case 2: + case 3: + col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_gyro).toString(); + break; + case 4: + case 5: + col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_SHOULDER, loc, msg_abbr_shoulder).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_ARM, loc, msg_abbr_upperarm).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM, loc, msg_abbr_lowerarm).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND, loc, msg_abbr_hand).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HIP, loc, msg_abbr_hip).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_LEG, loc, msg_abbr_upperleg).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_FOOT, loc, msg_abbr_foot).toString(); + break; + case 6: + case 7: + case 8: + col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HIP, loc, msg_abbr_hip).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_LEG, loc, msg_abbr_upperleg).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); + col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_FOOT, loc, msg_abbr_foot).toString(); + break; + default: + col3 = ""; + } + } else if (entity instanceof Tank) { + Tank tank = (Tank) entity; + boolean isSuperHeavyTank = entity instanceof SuperHeavyTank; + int tankTurrets = 0; + + if (!tank.hasNoDualTurret()) { + tankTurrets = 2; + } else if (!tank.hasNoTurret()) { + tankTurrets = 1; + } + + String turretLocked = ""; + + switch (loc) { + case 0: + case 1: + case 2: + case 3: + case 4: + col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + break; + case 5: + case 6: + col3 = isSuperHeavyTank ? sysStabilizers(tank, loc, msg_abbr_stabilizers).toString() : ""; + turretLocked = tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; + col3 += isSuperHeavyTank ? "" : turretLocked; + break; + case 7: + case 8: + turretLocked = tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; + col3 = isSuperHeavyTank ? turretLocked : ""; + break; + default: + col3 = ""; + } } col1 = "" + col1 + ""; @@ -403,6 +545,35 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { rows += row; } + if (entity instanceof GunEmplacement) { + Tank tank = (Tank) entity; + col1 = ""; + col2 = sysSensorHit(tank, msg_abbr_sensors).toString(); + col3 = ""; + + col1 = "" + col1 + ""; + col2 = "" + col2 + ""; + col3 = "" + col3 + ""; + row = "" + col1 + col2 + col3 + ""; + rows += row; + } else if (entity instanceof Tank) { + Tank tank = (Tank) entity; + Boolean isVTOL = entity instanceof VTOL; + + col1 = ""; + col2 = sysEngineHit(tank, msg_abbr_engine).toString(); + col2 += sysSensorHit(tank, msg_abbr_sensors).toString(); + col3 = isVTOL ? "" : sysMinorMovementDamage(tank, msg_abbr_minormovementdamage).toString(); + col3 += isVTOL ? "" : sysModerateMovementDamage(tank, msg_abbr_moderatemovementdamage).toString(); + col3 += isVTOL ? "" : sysHeavyMovementDamage(tank, msg_abbr_heavymovementdamage).toString(); + + col1 = "" + col1 + ""; + col2 = "" + col2 + ""; + col3 = "" + col3 + ""; + row = "" + col1 + col2 + col3 + ""; + rows += row; + } + String tbody = "" + rows + ""; String table = "" + tbody + "
"; From 677b2851a37871f5e42a0911c37ed37d5a61cb94 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 29 Jul 2023 15:23:07 -0400 Subject: [PATCH 2/7] handle SuperHeavyTank and LargeSupportTank together --- .../client/ui/swing/tooltip/UnitToolTip.java | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index 3d35c3494ad..e3469fd9f2c 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -501,9 +501,8 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { default: col3 = ""; } - } else if (entity instanceof Tank) { + } else if (entity instanceof SuperHeavyTank || entity instanceof LargeSupportTank) { Tank tank = (Tank) entity; - boolean isSuperHeavyTank = entity instanceof SuperHeavyTank; int tankTurrets = 0; if (!tank.hasNoDualTurret()) { @@ -512,26 +511,46 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { tankTurrets = 1; } - String turretLocked = ""; - switch (loc) { case 0: case 1: case 2: case 3: case 4: - col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - break; case 5: case 6: - col3 = isSuperHeavyTank ? sysStabilizers(tank, loc, msg_abbr_stabilizers).toString() : ""; - turretLocked = tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; - col3 += isSuperHeavyTank ? "" : turretLocked; + col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); break; case 7: case 8: - turretLocked = tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; - col3 = isSuperHeavyTank ? turretLocked : ""; + col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + col3 += tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; + break; + default: + col3 = ""; + } + } else if (entity instanceof Tank) { + Tank tank = (Tank) entity; + int tankTurrets = 0; + + if (!tank.hasNoDualTurret()) { + tankTurrets = 2; + } else if (!tank.hasNoTurret()) { + tankTurrets = 1; + } + + switch (loc) { + case 0: + case 1: + case 2: + case 3: + case 4: + col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + break; + case 5: + case 6: + col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + col3 += tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; break; default: col3 = ""; @@ -558,7 +577,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { rows += row; } else if (entity instanceof Tank) { Tank tank = (Tank) entity; - Boolean isVTOL = entity instanceof VTOL; + boolean isVTOL = entity instanceof VTOL; col1 = ""; col2 = sysEngineHit(tank, msg_abbr_engine).toString(); From 54985df0b0df512904f208c0c9dfcd474558af10 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 30 Jul 2023 09:21:49 -0400 Subject: [PATCH 3/7] splti out VTOL and and getTurretCount() --- .../client/ui/swing/tooltip/UnitToolTip.java | 50 +++++++++---------- .../src/megamek/common/MechSummaryCache.java | 6 +-- megamek/src/megamek/common/Tank.java | 12 +++++ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index e3469fd9f2c..fe1f18cf82d 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -298,7 +298,7 @@ private static StringBuilder sysCrits(Entity entity, int type, int index, int lo private static StringBuilder sysStabilizers(Tank tank, int loc, String locAbbr) { String result = ""; int total = 1; - int hits = tank.isStabiliserHit(loc) ? 1 :0; + int hits = tank.isStabiliserHit(loc) ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -312,7 +312,7 @@ private static StringBuilder sysStabilizers(Tank tank, int loc, String locAbbr) private static StringBuilder sysTurretLocked(Tank tank, int loc, String locAbbr) { String result = ""; int total = 1; - int hits = tank.isTurretLocked(loc) ? 1 :0; + int hits = tank.isTurretLocked(loc) ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -326,7 +326,7 @@ private static StringBuilder sysTurretLocked(Tank tank, int loc, String locAbbr) private static StringBuilder sysEngineHit(Tank tank, String locAbbr) { String result = ""; int total = 1; - int hits = tank.isEngineHit() ? 1 :0; + int hits = tank.isEngineHit() ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -354,7 +354,7 @@ private static StringBuilder sysSensorHit(Tank tank, String locAbbr) { private static StringBuilder sysMinorMovementDamage(Tank tank, String locAbbr) { String result = ""; int total = 1; - int hits = tank.hasMinorMovementDamage() ? 1 :0; + int hits = tank.hasMinorMovementDamage() ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -368,7 +368,7 @@ private static StringBuilder sysMinorMovementDamage(Tank tank, String locAbbr) { private static StringBuilder sysModerateMovementDamage(Tank tank, String locAbbr) { String result = ""; int total = 1; - int hits = tank.hasModerateMovementDamage() ? 1 :0; + int hits = tank.hasModerateMovementDamage() ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -382,7 +382,7 @@ private static StringBuilder sysModerateMovementDamage(Tank tank, String locAbbr private static StringBuilder sysHeavyMovementDamage(Tank tank, String locAbbr) { String result = ""; int total = 1; - int hits = tank.hasHeavyMovementDamage() ? 1 :0; + int hits = tank.hasHeavyMovementDamage() ? 1 : 0; int good = total - hits; boolean bad = hits > 0; @@ -503,13 +503,6 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { } } else if (entity instanceof SuperHeavyTank || entity instanceof LargeSupportTank) { Tank tank = (Tank) entity; - int tankTurrets = 0; - - if (!tank.hasNoDualTurret()) { - tankTurrets = 2; - } else if (!tank.hasNoTurret()) { - tankTurrets = 1; - } switch (loc) { case 0: @@ -524,20 +517,13 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { case 7: case 8: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - col3 += tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; + col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; break; default: col3 = ""; } } else if (entity instanceof Tank) { Tank tank = (Tank) entity; - int tankTurrets = 0; - - if (!tank.hasNoDualTurret()) { - tankTurrets = 2; - } else if (!tank.hasNoTurret()) { - tankTurrets = 1; - } switch (loc) { case 0: @@ -550,7 +536,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { case 5: case 6: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - col3 += tankTurrets > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; + col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; break; default: col3 = ""; @@ -575,16 +561,26 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { col3 = "" + col3 + ""; row = "" + col1 + col2 + col3 + ""; rows += row; - } else if (entity instanceof Tank) { + } else if (entity instanceof VTOL) { Tank tank = (Tank) entity; - boolean isVTOL = entity instanceof VTOL; + col1 = ""; + col2 = sysEngineHit(tank, msg_abbr_engine).toString(); + col2 += sysSensorHit(tank, msg_abbr_sensors).toString(); + col3 = ""; + col1 = "" + col1 + ""; + col2 = "" + col2 + ""; + col3 = "" + col3 + ""; + row = "" + col1 + col2 + col3 + ""; + rows += row; + } else if (entity instanceof Tank) { + Tank tank = (Tank) entity; col1 = ""; col2 = sysEngineHit(tank, msg_abbr_engine).toString(); col2 += sysSensorHit(tank, msg_abbr_sensors).toString(); - col3 = isVTOL ? "" : sysMinorMovementDamage(tank, msg_abbr_minormovementdamage).toString(); - col3 += isVTOL ? "" : sysModerateMovementDamage(tank, msg_abbr_moderatemovementdamage).toString(); - col3 += isVTOL ? "" : sysHeavyMovementDamage(tank, msg_abbr_heavymovementdamage).toString(); + col3 = sysMinorMovementDamage(tank, msg_abbr_minormovementdamage).toString(); + col3 += sysModerateMovementDamage(tank, msg_abbr_moderatemovementdamage).toString(); + col3 += sysHeavyMovementDamage(tank, msg_abbr_heavymovementdamage).toString(); col1 = "" + col1 + ""; col2 = "" + col2 + ""; diff --git a/megamek/src/megamek/common/MechSummaryCache.java b/megamek/src/megamek/common/MechSummaryCache.java index acff9e48e6b..15bc6a51c39 100644 --- a/megamek/src/megamek/common/MechSummaryCache.java +++ b/megamek/src/megamek/common/MechSummaryCache.java @@ -392,11 +392,7 @@ private MechSummary getSummary(Entity e, File f, String entry) { ms.setMilitary(e.isMilitary()); int tankTurrets = 0; if (e instanceof Tank) { - if (!((Tank) e).hasNoDualTurret()) { - tankTurrets = 2; - } else if (!((Tank) e).hasNoTurret()) { - tankTurrets = 1; - } + tankTurrets = ((Tank) e).getTurretCount(); } ms.setTankTurrets(tankTurrets); ms.setSourceFile(f); diff --git a/megamek/src/megamek/common/Tank.java b/megamek/src/megamek/common/Tank.java index 1dc65c24e52..6e48cc52d41 100644 --- a/megamek/src/megamek/common/Tank.java +++ b/megamek/src/megamek/common/Tank.java @@ -210,6 +210,18 @@ public boolean hasNoDualTurret() { return m_bHasNoDualTurret; } + public int getTurretCount() { + int tankTurrets = 0; + + if (!hasNoDualTurret()) { + tankTurrets = 2; + } else if (!hasNoTurret()) { + tankTurrets = 1; + } + + return tankTurrets; + } + public void setHasNoTurret(boolean b) { m_bHasNoTurret = b; } From ccc98ae2c86235ceb5063b5a387818036cba80f0 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 30 Jul 2023 09:33:35 -0400 Subject: [PATCH 4/7] use LOC constants in switches --- .../client/ui/swing/tooltip/UnitToolTip.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index fe1f18cf82d..8600f953f6e 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -464,23 +464,23 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { if (entity instanceof Mech) { switch (loc) { - case 0: + case Mech.LOC_HEAD: col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); break; - case 1: + case Mech.LOC_CT: col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO, loc, msg_abbr_gyro).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS, loc, msg_abbr_sensors).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_lifesupport).toString(); break; - case 2: - case 3: + case Mech.LOC_RT: + case Mech.LOC_LT: col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE, loc, msg_abbr_engine).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT, loc, msg_abbr_gyro).toString(); break; - case 4: - case 5: + case Mech.LOC_RARM: + case Mech.LOC_LARM: col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_SHOULDER, loc, msg_abbr_shoulder).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_ARM, loc, msg_abbr_upperarm).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM, loc, msg_abbr_lowerarm).toString(); @@ -490,9 +490,9 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_FOOT, loc, msg_abbr_foot).toString(); break; - case 6: - case 7: - case 8: + case Mech.LOC_RLEG: + case Mech.LOC_LLEG: + case Mech.LOC_CLEG: col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HIP, loc, msg_abbr_hip).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_UPPER_LEG, loc, msg_abbr_upperleg).toString(); col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_LEG, loc, msg_abbr_lowerleg).toString(); @@ -505,17 +505,17 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { Tank tank = (Tank) entity; switch (loc) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: + case SuperHeavyTank.LOC_BODY: + case SuperHeavyTank.LOC_FRONT: + case SuperHeavyTank.LOC_RIGHT: + case SuperHeavyTank.LOC_LEFT: + case SuperHeavyTank.LOC_REARRIGHT: + case SuperHeavyTank.LOC_REARLEFT: + case SuperHeavyTank.LOC_REAR: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); break; - case 7: - case 8: + case SuperHeavyTank.LOC_TURRET: + case SuperHeavyTank.LOC_TURRET_2: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; break; @@ -526,15 +526,15 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { Tank tank = (Tank) entity; switch (loc) { - case 0: - case 1: - case 2: - case 3: - case 4: + case Tank.LOC_BODY: + case Tank.LOC_FRONT: + case Tank.LOC_RIGHT: + case Tank.LOC_LEFT: + case Tank.LOC_REAR: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); break; - case 5: - case 6: + case Tank.LOC_TURRET: + case Tank.LOC_TURRET_2: col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() : ""; break; From 221d348c3e8ca52af641c334152e0b955ce3cfee Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 30 Jul 2023 10:06:16 -0400 Subject: [PATCH 5/7] add CRIT_SENSOR_MAX --- megamek/src/megamek/client/ui/swing/UnitEditorDialog.java | 4 ++-- megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java | 2 +- megamek/src/megamek/common/Tank.java | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java b/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java index f3a949ae182..5b85fd9907b 100644 --- a/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java +++ b/megamek/src/megamek/client/ui/swing/UnitEditorDialog.java @@ -642,7 +642,7 @@ private void setupTankSystemPanel() { gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("" + Messages.getString("UnitEditorDialog.sensor") + "
"), gridBagConstraints); - sensorCrit = new CheckCritPanel(4, tank.getSensorHits()); + sensorCrit = new CheckCritPanel(Tank.CRIT_SENSOR_MAX, tank.getSensorHits()); gridBagConstraints.gridx = 1; gridBagConstraints.weightx = 1.0; panSystem.add(sensorCrit, gridBagConstraints); @@ -786,7 +786,7 @@ private void setupVtolSystemPanel() { gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("" + Messages.getString("UnitEditorDialog.sensor") + "
"), gridBagConstraints); - sensorCrit = new CheckCritPanel(4, vtol.getSensorHits()); + sensorCrit = new CheckCritPanel(Tank.CRIT_SENSOR_MAX, vtol.getSensorHits()); gridBagConstraints.gridx = 1; gridBagConstraints.weightx = 1.0; panSystem.add(sensorCrit, gridBagConstraints); diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index 8600f953f6e..dcd99ffe115 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -339,7 +339,7 @@ private static StringBuilder sysEngineHit(Tank tank, String locAbbr) { private static StringBuilder sysSensorHit(Tank tank, String locAbbr) { String result = ""; - int total = 4; + int total = Tank.CRIT_SENSOR_MAX; int hits = tank.getSensorHits(); int good = total - hits; boolean bad = hits > 0; diff --git a/megamek/src/megamek/common/Tank.java b/megamek/src/megamek/common/Tank.java index 6e48cc52d41..1939156bcbf 100644 --- a/megamek/src/megamek/common/Tank.java +++ b/megamek/src/megamek/common/Tank.java @@ -83,6 +83,8 @@ public class Tank extends Entity { public static final int CRIT_TURRET_LOCK = 13; public static final int CRIT_TURRET_DESTROYED = 14; + public static final int CRIT_SENSOR_MAX = 4; + //Fortify terrain just like infantry public static final int DUG_IN_NONE = 0; public static final int DUG_IN_FORTIFYING1 = 1; @@ -1873,7 +1875,7 @@ public int getCriticalEffect(int roll, int loc, boolean damagedByFire) { } } case 9: - if (getSensorHits() < 4) { + if (getSensorHits() < CRIT_SENSOR_MAX) { return CRIT_SENSOR; } case 10: From 9c6248c388d1decc39f0181fd83194bf17b826eb Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 30 Jul 2023 10:17:08 -0400 Subject: [PATCH 6/7] more uses of CRIT_SENSOR_MAX --- megamek/src/megamek/common/VTOL.java | 4 ++-- megamek/src/megamek/common/actions/WeaponAttackAction.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/common/VTOL.java b/megamek/src/megamek/common/VTOL.java index 7cfdcdee103..9cf3106d2b9 100644 --- a/megamek/src/megamek/common/VTOL.java +++ b/megamek/src/megamek/common/VTOL.java @@ -363,7 +363,7 @@ public int getCriticalEffect(int roll, int loc, boolean damagedByFire) { } } case 9: - if (getSensorHits() < 4) { + if (getSensorHits() < Tank.CRIT_SENSOR_MAX) { return CRIT_SENSOR; } case 10: @@ -414,7 +414,7 @@ public int getCriticalEffect(int roll, int loc, boolean damagedByFire) { } } case 10: - if (getSensorHits() < 4) { + if (getSensorHits() < Tank.CRIT_SENSOR_MAX) { return CRIT_SENSOR; } case 11: diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 4226e5f4d4d..1ed9d4979d1 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -1124,7 +1124,7 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta // Vehicles Sensor Hits } else if (ae instanceof Tank) { sensorHits = ((Tank) ae).getSensorHits(); - if (sensorHits > 3) { + if (sensorHits >= Tank.CRIT_SENSOR) { return Messages.getString("WeaponAttackAction.SensorsDestroyed"); } // Industrialmechs and other unit types have destroyed sensors with 2 or more hits From 4e22f088d95ae6777bfe3ca7756bd550db1890e2 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 6 Aug 2023 13:17:15 -0400 Subject: [PATCH 7/7] check sub type before parent type, so that sub types diplay with correct name --- megamek/src/megamek/common/Entity.java | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index ed1d83b4a7a..a4384333aa0 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -14202,10 +14202,10 @@ public static String getEntityMajorTypeName(long typeId) { */ public static String getEntityTypeName(long typeId) { - if ((typeId & ETYPE_BIPED_MECH) == ETYPE_BIPED_MECH) { - return "Biped Mech"; - } else if ((typeId & ETYPE_LAND_AIR_MECH) == ETYPE_LAND_AIR_MECH) { + if ((typeId & ETYPE_LAND_AIR_MECH) == ETYPE_LAND_AIR_MECH) { return "Landair Mech"; + } else if ((typeId & ETYPE_BIPED_MECH) == ETYPE_BIPED_MECH) { + return "Biped Mech"; } else if ((typeId & ETYPE_QUAD_MECH) == ETYPE_QUAD_MECH) { return "Quad Mech"; } else if ((typeId & ETYPE_TRIPOD_MECH) == ETYPE_TRIPOD_MECH) { @@ -14214,22 +14214,22 @@ public static String getEntityTypeName(long typeId) { return "Armless Mech"; } else if ((typeId & ETYPE_MECH) == ETYPE_MECH) { return "Mech"; - } else if ((typeId & ETYPE_JUMPSHIP) == ETYPE_JUMPSHIP) { - return "JumpShip"; } else if ((typeId & ETYPE_WARSHIP) == ETYPE_WARSHIP) { return "WarShip"; } else if ((typeId & ETYPE_SPACE_STATION) == ETYPE_SPACE_STATION) { return "Space Station"; - } else if ((typeId & ETYPE_CONV_FIGHTER) == ETYPE_CONV_FIGHTER) { - return "Conventional Fighter"; + } else if ((typeId & ETYPE_JUMPSHIP) == ETYPE_JUMPSHIP) { + return "JumpShip"; } else if ((typeId & ETYPE_FIXED_WING_SUPPORT) == ETYPE_FIXED_WING_SUPPORT) { return "Fixed Wing Support"; + } else if ((typeId & ETYPE_CONV_FIGHTER) == ETYPE_CONV_FIGHTER) { + return "Conventional Fighter"; } else if ((typeId & ETYPE_FIGHTER_SQUADRON) == ETYPE_FIGHTER_SQUADRON) { return "Fighter Squadron"; - } else if ((typeId & ETYPE_SMALL_CRAFT) == ETYPE_SMALL_CRAFT) { - return "Small Craft"; } else if ((typeId & ETYPE_DROPSHIP) == ETYPE_DROPSHIP) { return "DropShip"; + } else if ((typeId & ETYPE_SMALL_CRAFT) == ETYPE_SMALL_CRAFT) { + return "Small Craft"; } else if ((typeId & ETYPE_TELEMISSILE) == ETYPE_TELEMISSILE) { return "Telemissile"; } else if ((typeId & ETYPE_AERO) == ETYPE_AERO) { @@ -14246,14 +14246,14 @@ public static String getEntityTypeName(long typeId) { return "Gun Emplacement"; } else if ((typeId & ETYPE_SUPER_HEAVY_TANK) == ETYPE_SUPER_HEAVY_TANK) { return "Superheavy Tank"; - } else if ((typeId & ETYPE_SUPPORT_TANK) == ETYPE_SUPPORT_TANK) { - return "Support Tank"; } else if ((typeId & ETYPE_LARGE_SUPPORT_TANK) == ETYPE_LARGE_SUPPORT_TANK) { return "Large Support Tank"; - } else if ((typeId & ETYPE_VTOL) == ETYPE_VTOL) { - return "VTOL"; + } else if ((typeId & ETYPE_SUPPORT_TANK) == ETYPE_SUPPORT_TANK) { + return "Support Tank"; } else if ((typeId & ETYPE_SUPPORT_VTOL) == ETYPE_SUPPORT_VTOL) { return "Support VTOL"; + } else if ((typeId & ETYPE_VTOL) == ETYPE_VTOL) { + return "VTOL"; } else if ((typeId & ETYPE_TANK) == ETYPE_TANK) { return "Tank"; } else {