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 for spare mech locations #3766

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
40 changes: 38 additions & 2 deletions MekHQ/src/mekhq/campaign/parts/MekLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import megamek.codeUtilities.MathUtility;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.verifier.Structure;
import megamek.common.verifier.TestEntity.Ceil;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
Expand All @@ -32,6 +34,7 @@
import mekhq.campaign.personnel.SkillType;
import mekhq.campaign.unit.Unit;
import mekhq.campaign.work.WorkTime;

import org.apache.logging.log4j.LogManager;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -149,8 +152,41 @@ public MekLocation(int loc, int tonnage, int structureType, boolean clan,

@Override
public double getTonnage() {
// TODO : how much should this weigh?
return 0;
// use MegaMek's implementation of internal structure weight calculation
// assume rounding to nearest half-ton
// superheavy flag is set if weight is more than 100
// assume movement mode is biped or tripod (technically mechs can have other movement modes but
// that doesn't affect structure weight); currently impossible to tell whether a "loose" left leg is for a biped or tripod.
EntityMovementMode movementMode = (getLoc() == Mech.LOC_CLEG) ? EntityMovementMode.TRIPOD : EntityMovementMode.BIPED;

double tonnage = Structure.getWeightStructure(structureType, getUnitTonnage(), Ceil.HALFTON,
(getUnitTonnage() > 100), movementMode);

// determine the weight of the location;
// if it's a "strange" location, then the rest of this is pointless.
switch (loc) {
case Mech.LOC_HEAD:
tonnage *= 0.05;
break;
case Mech.LOC_CT:
tonnage *= 0.25;
break;
case Mech.LOC_LT:
case Mech.LOC_RT:
tonnage *= 0.15;
break;
case Mech.LOC_LARM:
case Mech.LOC_RARM:
case Mech.LOC_LLEG:
case Mech.LOC_RLEG:
case Mech.LOC_CLEG:
tonnage *= 0.1;
break;
default:
return 0;
}

return tonnage;
}

@Override
Expand Down
Loading