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

Weight calculation #4973

Merged
merged 2 commits into from
Dec 26, 2023
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
5 changes: 5 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11073,6 +11073,11 @@ public Engine getEngine() {
return engine;
}

/** @return The type of engine if it has an engine, or Engine.NONE, if it has no engine. */
public int getEngineType() {
return hasEngine() ? getEngine().getEngineType() : Engine.NONE;
}

public boolean hasEngine() {
return (null != engine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ public StringBuffer printEntity() {
}

@Override
public double calculateWeight() {
public double calculateWeightExact() {
double weight = 0;
weight += getWeightStructure();
weight += getWeightEngine();
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/verifier/TestAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ public StringBuffer printEntity() {
}

@Override
public double calculateWeight() {
public double calculateWeightExact() {
double weight = 0;
weight += getWeightEngine();
weight += getWeightControls();
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/verifier/TestBattleArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ public double calculateWeight(int trooper) {
}

@Override
public double calculateWeight() {
public double calculateWeightExact() {
double totalWeight = 0.0;
for (int i = 0; i < ba.getTroopers(); i++) {
totalWeight += calculateWeight(i);
Expand Down
42 changes: 34 additions & 8 deletions megamek/src/megamek/common/verifier/TestEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,32 @@ public static int calcHeatNeutralHSRequirement(Entity entity) {
return heat;
}

/**
* According to TM, unit weights are to be rounded up to the nearest half ton or kilo. This method
* returns the rounded weight.
*
* @return The weight of the unit, rounded up according to TM, p.22.
*/
public double calculateWeight() {
double weight = calculateWeightExact();
// If the unit used kg standard, we just need to get rid of floating-point math anomalies.
// Otherwise accumulated kg-scale equipment needs to be rounded up to the nearest half-ton.
weight = round(weight, Ceil.KILO);
if (usesKgStandard()) {
return weight;
} else {
return ceil(weight, Ceil.HALFTON);
}
}

/**
* According to TM p.22, unit weights are to be rounded up to the nearest half ton or kilo, but in MML
* for construction at least we should be able to show the exact weight. This method returns the unrounded
* weight.
*
* @return The unrounded weight of the unit.
*/
public double calculateWeightExact() {
double weight = 0;
weight += getWeightEngine();
weight += getWeightStructure();
Expand All @@ -877,14 +902,7 @@ public double calculateWeight() {
weight += getWeightCarryingSpace();

weight += getArmoredComponentWeight();
// If the unit used kg standard, we just need to get rid of floating-point math anomalies.
// Otherwise accumulated kg-scale equipment needs to be rounded up to the nearest half-ton.
weight = round(weight, Ceil.KILO);
if (usesKgStandard()) {
return weight;
} else {
return ceil(weight, Ceil.HALFTON);
}
return weight;
}

public String printWeightCalculation() {
Expand Down Expand Up @@ -1671,6 +1689,14 @@ boolean usesKgStandard() {
return usesKgStandard(getEntity());
}


public int totalCritSlotCount() {
int slotCount = 0;
for (int i = 0; i < getEntity().locations(); i++) {
slotCount += getEntity().getNumberOfCriticals(i);
}
return slotCount;
}
} // End class TestEntity

class Armor {
Expand Down
5 changes: 2 additions & 3 deletions megamek/src/megamek/common/verifier/TestInfantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@ public String getName() {
public double getWeightPowerAmp() {
return 0;
}

@Override
public double calculateWeight() {
public double calculateWeightExact() {
return infantry.getWeight();
}

}
4 changes: 2 additions & 2 deletions megamek/src/megamek/common/verifier/TestProtomech.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public int getCountHeatSinks() {
@Override
public double calculateWeight() {
// Deal with some floating point precision issues
return round(super.calculateWeight(), Ceil.KILO);
return round(super.calculateWeightExact(), Ceil.KILO);
}

@Override
public double getWeightAllocatedArmor() {
ProtomechArmor armor = ProtomechArmor.getArmor(proto);
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/verifier/TestSmallCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ public StringBuffer printEntity() {
}

@Override
public double calculateWeight() {
public double calculateWeightExact() {
double weight = 0;
weight += getWeightStructure();
weight += getWeightEngine();
Expand Down
7 changes: 6 additions & 1 deletion megamek/src/megamek/common/verifier/TestSupportVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,12 @@ private double ceilWeight(double val) {

@Override
public double calculateWeight() {
return ceilWeight(super.calculateWeight() + getFuelTonnage());
return ceilWeight(calculateWeightExact());
}

@Override
public double calculateWeightExact() {
return super.calculateWeightExact() + getFuelTonnage();
}

@Override
Expand Down