Skip to content

Commit

Permalink
More detailed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbraginskiy committed Sep 24, 2024
1 parent fca90f5 commit ce80e92
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 45 deletions.
12 changes: 1 addition & 11 deletions megamek/src/megamek/common/Aero.java
Original file line number Diff line number Diff line change
Expand Up @@ -1566,16 +1566,6 @@ public int getHeatCapacity(boolean includeRadicalHeatSink) {
return capacity;
}

@Override
public String formatHeat() {
int capacity = (getHeatSinks() * (getHeatType() + 1));
if (hasWorkingMisc(MiscType.F_RADICAL_HEATSINK)) {
return "%d [%d]".formatted(capacity, capacity + getHeatSinks());
} else {
return Integer.toString(capacity);
}
}

// If the aero is in the water, it is dead so no worries
@Override
public int getHeatCapacityWithWater() {
Expand Down Expand Up @@ -1814,7 +1804,7 @@ public int getCriticalEffect(int roll, int target) {
}

/**
*/
@Override
public void setOmni(boolean omni) {
Expand Down
37 changes: 36 additions & 1 deletion megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4834,7 +4834,42 @@ public int getHeatCapacity() {
* @return The formatted heat capacity
*/
public String formatHeat() {
return Integer.toString(getHeatCapacity(true));
int sinks;
if (this instanceof Mek m) {
sinks = m.getActiveSinks();
} else if (this instanceof Aero a) {
sinks = a.getHeatSinks();
} else {
return "(none)";
}

StringBuilder sb = new StringBuilder();
int capacity = getHeatCapacity(false);
sb.append(capacity);

// Radical Heat Sinks
if (hasWorkingMisc(MiscType.F_RADICAL_HEATSINK)) {
capacity += sinks;
sb.append(", ").append(capacity).append(" with RHS");
}

// Coolant Pod
for (AmmoMounted m : getAmmo()) {
if (m.getType().ammoType == AmmoType.T_COOLANT_POD) {
capacity += sinks;
sb.append(", ").append(capacity).append(" with Coolant Pod");
break;
}
}

// RISC ECS
for (MiscMounted m : getMisc()) {
if (m.getType().hasFlag(MiscType.F_EMERGENCY_COOLANT_SYSTEM)) {
sb.append(", +MoS with RISC ECS");
}
}

return sb.toString();
}

/**
Expand Down
31 changes: 0 additions & 31 deletions megamek/src/megamek/common/Mek.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import megamek.common.cost.MekCostCalculator;
import megamek.common.enums.AimingMode;
import megamek.common.enums.MPBoosters;
import megamek.common.equipment.AmmoMounted;
import megamek.common.equipment.MiscMounted;
import megamek.common.loaders.MtfFile;
import megamek.common.options.IBasicOption;
Expand Down Expand Up @@ -1638,36 +1637,6 @@ && hasWorkingMisc(MiscType.F_RADICAL_HEATSINK)) {
return Math.max(capacity, 0);
}

@Override
public String formatHeat() {
StringBuilder sb = new StringBuilder();
int capacity = getHeatCapacity(true, false);
sb.append(capacity);

// Radical Heatsinks
if (hasWorkingMisc(MiscType.F_RADICAL_HEATSINK)) {
capacity += getActiveSinks();
sb.append(" [").append(capacity).append("]");
}

// Coolant Pod
for (AmmoMounted m : getAmmo()) {
if (m.getType().ammoType == AmmoType.T_COOLANT_POD) {
capacity += getActiveSinks();
sb.append(" [").append(capacity).append("]");
break;
}
}

for (MiscMounted m : getMisc()) {
if (m.getType().hasFlag(MiscType.F_EMERGENCY_COOLANT_SYSTEM)) {
sb.append(" [+MoS]");
}
}

return sb.toString();
}

/**
* Returns the about of heat that the entity can sink each turn, factoring
* for water.
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/common/MekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public MekView(final Entity entity, final boolean showDetail, final boolean useA
hsString.append(" (").append(a.getPodHeatSinks()).append(" ")
.append(Messages.getString("MekView.Pod")).append(")");
}
if (a.getHeatCapacity() > a.getHeatSinks()) {
if (!a.formatHeat().equals(Integer.toString(a.getHeatSinks()))) {
hsString.append(" [")
.append(a.formatHeat()).append("]");
}
Expand All @@ -468,7 +468,7 @@ public MekView(final Entity entity, final boolean showDetail, final boolean useA
Mek aMek = (Mek) entity;
StringBuilder hsString = new StringBuilder();
hsString.append(aMek.heatSinks());
if (aMek.getHeatCapacity() > aMek.heatSinks()) {
if (!aMek.formatHeat().equals(Integer.toString(aMek.heatSinks()))) {
hsString.append(" [").append(aMek.formatHeat()).append("]");
}
if (aMek.damagedHeatSinks() > 0) {
Expand Down

0 comments on commit ce80e92

Please sign in to comment.