Skip to content

Commit

Permalink
Merge pull request #6033 from pavelbraginskiy/pretty-print-heat
Browse files Browse the repository at this point in the history
Better display of radical heat sinking in preview
  • Loading branch information
HammerGS authored Sep 26, 2024
2 parents 518ddbb + c9f257a commit 7dcbf06
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 14 deletions.
48 changes: 48 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,54 @@ public int getHeatCapacity() {

public abstract int getHeatCapacity(boolean radicalHeatSink);

/**
* Pretty-prints the heat capacity of a unit, including optional heat sinking systems.
* Typically, this is equivalent to {@link #getHeatCapacity()},
* but in the presence of Radical Heat Sinks, Coolant Pods, or the RISC Emergency Coolant System,
* produces strings like "24 [36]" or "12 [+MoS]".
* @return The formatted heat capacity
*/
public String formatHeat() {
// This method might make sense as an abstract method with overrides in Mek and Aero,
// But since the implementation would be the same in both classes, this way avoids code duplication.
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();
}

/**
* Returns the amount of heat that the entity can sink each turn, factoring
* in whether the entity is standing in water.
Expand Down
28 changes: 14 additions & 14 deletions megamek/src/megamek/common/MekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* The information is encoded in a series of classes that implement a common
* {@link ViewElement}
* interface, which can format the element either in html or in plain text.
*
*
* @author Ryan McConnell
* @since January 20, 2003
*/
Expand Down Expand Up @@ -450,9 +450,9 @@ 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.getHeatCapacity()).append("]");
.append(a.formatHeat()).append("]");
}
if (a.getHeatSinkHits() > 0) {
hsString.append(warningStart()).append(" (").append(a.getHeatSinkHits())
Expand All @@ -468,8 +468,8 @@ 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()) {
hsString.append(" [").append(aMek.getHeatCapacity()).append("]");
if (!aMek.formatHeat().equals(Integer.toString(aMek.heatSinks()))) {
hsString.append(" [").append(aMek.formatHeat()).append("]");
}
if (aMek.damagedHeatSinks() > 0) {
hsString.append(" ").append(warningStart()).append("(")
Expand Down Expand Up @@ -640,7 +640,7 @@ private String getReadout(List<ViewElement> section) {
/**
* The head section includes the title (unit name), tech level and availability,
* tonnage, bv, and cost.
*
*
* @return The data from the head section.
*/
public String getMekReadoutHead() {
Expand All @@ -651,7 +651,7 @@ public String getMekReadoutHead() {
* The basic section includes general details such as movement, system equipment
* (cockpit, gyro, etc.)
* and armor.
*
*
* @return The data from the basic section
*/
public String getMekReadoutBasic() {
Expand All @@ -660,7 +660,7 @@ public String getMekReadoutBasic() {

/**
* The invalid section includes reasons why the unit is invalid
*
*
* @return The data from the invalid section
*/
public String getMekReadoutInvalid() {
Expand All @@ -670,7 +670,7 @@ public String getMekReadoutInvalid() {
/**
* The loadout includes weapons, ammo, and other equipment broken down by
* location.
*
*
* @return The data from the loadout section.
*/
public String getMekReadoutLoadout() {
Expand All @@ -681,7 +681,7 @@ public String getMekReadoutLoadout() {
* The fluff section includes fluff details like unit history and deployment
* patterns
* as well as quirks.
*
*
* @return The data from the fluff section.
*/
public String getMekReadoutFluff() {
Expand Down Expand Up @@ -1683,7 +1683,7 @@ public String toDiscord() {
* Marks warning text; in html the text is displayed in red. In plain text it is
* preceded and followed
* by an asterisk.
*
*
* @return A String that is used to mark the beginning of a warning.
*/
private String warningStart() {
Expand All @@ -1701,7 +1701,7 @@ private String warningStart() {

/**
* Returns the end element of the warning text.
*
*
* @return A String that is used to mark the end of a warning.
*/
private String warningEnd() {
Expand All @@ -1721,7 +1721,7 @@ private String warningEnd() {
* Marks the beginning of a section of italicized text if using html output. For
* plain text
* returns an empty String.
*
*
* @return The starting element for italicized text.
*/
private String italicsStart() {
Expand All @@ -1739,7 +1739,7 @@ private String italicsStart() {

/**
* Marks the end of a section of italicized text.
*
*
* @return The ending element for italicized text.
*/
private String italicsEnd() {
Expand Down
174 changes: 174 additions & 0 deletions megamek/testresources/megamek/common/units/Sagittaire SGT-14D.mtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
generator:MegaMek Suite 0.50.1-SNAPSHOT on 2024-09-23
chassis:Sagittaire
model:SGT-14D
mul id:6835

Config:Biped
techbase:Inner Sphere
era:3134
source:Record Sheets: 3145 New Tech New Upgrades
rules level:3
role:Juggernaut

quirk:difficult_maintain
quirk:weak_head_1
quirk:imp_target_short

mass:95
engine:285 Light Engine(IS)
structure:IS Endo-Composite
myomer:Standard
cockpit:Small Cockpit
gyro:Standard Gyro

heat sinks:14 IS Double
walk mp:3
jump mp:3

armor:Standard(Inner Sphere)
LA armor:31
RA armor:31
LT armor:30
RT armor:30
CT armor:44
HD armor:9
LL armor:39
RL armor:39
RTL armor:10
RTR armor:10
RTC armor:15

Weapons:7
Large Re-engineered Laser, Left Arm
Medium VSP Laser, Left Arm
Medium VSP Laser, Left Arm
Large Re-engineered Laser, Right Arm
Medium VSP Laser, Right Arm
Medium X-Pulse Laser, Right Arm
ER Large Laser, Left Torso

Left Arm:
Shoulder
Upper Arm Actuator
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
ISMediumVSPLaser
ISMediumVSPLaser
ISMediumVSPLaser
ISMediumVSPLaser
-Empty-

Right Arm:
Shoulder
Upper Arm Actuator
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
Large Re-engineered Laser
ISMediumVSPLaser
ISMediumVSPLaser
ISMediumXPulseLaser
-Empty-
-Empty-

Left Torso:
Fusion Engine
Fusion Engine
ISDoubleHeatSink
ISDoubleHeatSink
ISDoubleHeatSink
ISERLargeLaser
ISERLargeLaser
IS Endo-Composite
IS Endo-Composite
IS Endo-Composite
-Empty-
-Empty-

Right Torso:
Fusion Engine
Fusion Engine
ISDoubleHeatSink
ISDoubleHeatSink
ISDoubleHeatSink
ISDoubleHeatSink
ISDoubleHeatSink
ISDoubleHeatSink
Radical Heat Sink System
Radical Heat Sink System
Radical Heat Sink System
IS Endo-Composite

Center Torso:
Fusion Engine
Fusion Engine
Fusion Engine
Gyro
Gyro
Gyro
Gyro
Fusion Engine
Fusion Engine
Fusion Engine
Jump Jet
IS Endo-Composite

Head:
Life Support
Sensors
Cockpit
Sensors
ISC3BoostedSystemSlaveUnit
ISC3BoostedSystemSlaveUnit
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-

Left Leg:
Hip
Upper Leg Actuator
Lower Leg Actuator
Foot Actuator
Jump Jet
IS Endo-Composite
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-

Right Leg:
Hip
Upper Leg Actuator
Lower Leg Actuator
Foot Actuator
Jump Jet
IS Endo-Composite
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-
-Empty-

overview:The Sagittaire is built to fight in the confines of an urban battlefield.
capabilities:The laser-heavy Sagittaire is powered by a Pitban extralight engine and has a top speed of 54 kph, which is comparable to 'Mechs of similar weight. The HildCo lifters fitted in the legs and midline, however, make the Sagittaire one of the few assault 'Mechs with jumping capacity, offering it a great deal of tactical versatility. That, of course, does not account for the psychological impact of witnessing a 95-ton BattleMech fly through the air on inexperienced troops. As if that weren't enough, the Sagittaire's pulse-technology lasers combined with the targeting computer enable a MechWarrior to retain a high rate of movement while still outperforming most other BattleMechs. With eighteen tons of armor, the need for such a strategy is questionable. The design is truly deadly when the Sagittaire's feet are firmly planted on the earth.
deployment:This variant uses an Endo-Composite structure and Small Cockpit. This frees enough weight to replace the weapons with two Large Re-Engineered Lasers, an ER Large Laser, three Medium Variable Speed Pulse Lasers, and a Medium X-Pulse Laser. A C3 Boosted Slave is mounted in the head. Fourteen double heat sinks are boosted by a Radical Heat Sink System. This Sagittaire can also cover 90 meters in a single jump.
history:When it was originally deployed from Robinson BattleWorks in 3063, the machine saw considerable battle against House Kurita as Duke James Sandoval dedicated heavy resources to taking and retaining a half-dozen Combine worlds. The Sagittaire was crucial in the attack on Proserpina, where one of these robots slaughtered a company of Ninth Benjamin Regulars samurai in a series of ill-fated one-on-one duels. Later, following House Kurita's successful counter-assault, the Dragon made a deliberate effort to acquire or salvage multiple Sagittaire-designed 'Mechs for its own usage. Duke Sandoval later permitted additional of these vehicles to be sold into her loyalist army as Katherine Steiner-Davion tightened her grip on the Draconis March. This was short-lived, since Tancred Sandoval removed his father as March Lord not long after. He then directed the entire Sagittaire line to reinforce his own soldiers as well as the regiments supporting Victor Steiner-Davion. As an illustration of the Sagittaire's broad appeal, an allied company and a loyalist company were stationed on New Avalon, each with a lance of Sagittaires. During the battle for the continental capital of Flensburg, only three allied robots escaped under their own power. They were all Sagittarius. They were responsible for eight "kills" out of twelve enemy 'Mechs.
manufacturer:Robinson Standard BattleWorks
primaryfactory:Robinson
systemmanufacturer:CHASSIS:Skuel Heavy TRQ EC
systemmanufacturer:ENGINE:Pitban 285 Light
systemmanufacturer:ARMOR:Starshield Special Heavy
systemmanufacturer:JUMPJET:HildCo LFT 9-X
systemmanufacturer:COMMUNICATIONS:Sony MSF-31
systemmanufacturer:TARGETING:Federated Stalker with Targeting Module

19 changes: 19 additions & 0 deletions megamek/unittests/megamek/common/EntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ void testCalculateWeight() {
}
}

@Test
void testFormatHeat() {
File f;
MekFileParser mfp;
Entity e;
String expectedHeat, computedHeat;

try {
f = new File("testresources/megamek/common/units/Sagittaire SGT-14D.mtf");
mfp = new MekFileParser(f);
e = mfp.getEntity();
expectedHeat = "28, 42 with RHS";
computedHeat = e.formatHeat();
assertEquals(expectedHeat, computedHeat);
} catch (Exception ex) {
fail(ex.getMessage());
}
}

/**
* Verify that if a unit's name appears in the list of canon unit names, it is
* canon
Expand Down

0 comments on commit 7dcbf06

Please sign in to comment.