Skip to content

Commit

Permalink
Merge pull request #3823 from MegaMek/armor_rework
Browse files Browse the repository at this point in the history
Armor rework, part 1a
  • Loading branch information
SJuliez authored Feb 1, 2024
2 parents 08e2f2c + 2b2e22f commit 040383e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
11 changes: 5 additions & 6 deletions MekHQ/src/mekhq/campaign/market/PartsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package mekhq.campaign.market;

import megamek.common.*;
import megamek.common.equipment.ArmorType;
import megamek.common.loaders.EntityLoadingException;
import megamek.common.verifier.TestEntity;
import megamek.common.weapons.InfantryAttack;
Expand Down Expand Up @@ -425,25 +426,23 @@ private void stockVeeComponents(Campaign c) {
private void stockArmor(Campaign c) {
int amount;
for (int at = 0; at < EquipmentType.armorNames.length; at++) {
String name = EquipmentType.getArmorTypeName(at, false);
EquipmentType is = EquipmentType.get(name);
ArmorType is = ArmorType.of(at, false);
if (null != is) {
if (is.hasFlag(MiscType.F_BA_EQUIPMENT)) {
amount = (int)(5 * BaArmor.getPointsPerTon(at, false));
parts.add(new BaArmor(0, amount, at, -1, false, c));
} else {
amount = (int)(5.0 * 16.0 * EquipmentType.getArmorPointMultiplier(at, false));
amount = (int)(5.0 * is.getPointsPerTon());
parts.add(new Armor(0, at, amount, -1, false, false, c));
}
}
name = EquipmentType.getArmorTypeName(at, true);
EquipmentType clan = EquipmentType.get(name);
ArmorType clan = ArmorType.of(at, true);
if ((null != clan) && (is != clan)) {
if (clan.hasFlag(MiscType.F_BA_EQUIPMENT)) {
amount = (int)(5 * BaArmor.getPointsPerTon(at, true));
parts.add(new BaArmor(0, amount, at, -1, true, c));
} else {
amount = (int) (5.0 * 16.0 * EquipmentType.getArmorPointMultiplier(at, true));
amount = (int) (5.0 * clan.getPointsPerTon());
parts.add(new Armor(0, at, amount, -1, false, true, c));
}
}
Expand Down
12 changes: 4 additions & 8 deletions MekHQ/src/mekhq/campaign/parts/Armor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import mekhq.utilities.MHQXMLUtility;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
Expand Down Expand Up @@ -84,7 +85,7 @@ public Money getActualValue() {
}

public double getTonnageNeeded() {
double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier(type, isClanTechBase());
double armorPerTon = ArmorType.of(type, isClanTechBase()).getPointsPerTon();
if (type == EquipmentType.T_ARMOR_HARDENED) {
armorPerTon = 8.0;
}
Expand Down Expand Up @@ -247,8 +248,7 @@ public double getArmorWeight(int points) {

// this roundabout method is actually necessary to avoid rounding
// weirdness. Yeah, it's dumb.
double armorPointMultiplier = EquipmentType.getArmorPointMultiplier(getType(), isClanTechBase());
double armorPerTon = 16.0 * armorPointMultiplier;
double armorPerTon = ArmorType.of(getType(), isClan()).getPointsPerTon();
if (getType() == EquipmentType.T_ARMOR_HARDENED) {
armorPerTon = 8.0;
}
Expand Down Expand Up @@ -508,11 +508,7 @@ else if (campaign.getCampaignOptions().getIsAcquisitionPenalty() > 0) {
}

public double getArmorPointsPerTon() {
double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier(type, clan);
if (type == EquipmentType.T_ARMOR_HARDENED) {
armorPerTon = 8.0;
}
return armorPerTon;
return ArmorType.of(type, clan).getPointsPerTon();
}

public Part getNewPart() {
Expand Down
5 changes: 3 additions & 2 deletions MekHQ/src/mekhq/campaign/parts/BaArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Objects;

import megamek.common.EquipmentType;
import megamek.common.equipment.ArmorType;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
import mekhq.campaign.work.IAcquisitionWork;
Expand All @@ -43,7 +44,7 @@ public static boolean canBeIs(int type) {


public static double getPointsPerTon(int t, boolean isClan) {
return 1.0/EquipmentType.getBaArmorWeightPerPoint(t, isClan);
return 1.0 / ArmorType.of(t, isClan).getWeightPerPoint();
}

public BaArmor() {
Expand All @@ -64,7 +65,7 @@ public BaArmor clone() {

@Override
public double getTonnage() {
return EquipmentType.getBaArmorWeightPerPoint(type, clan) * amount;
return ArmorType.of(type, clan).getWeightPerPoint() * amount;
}

public Money getPointCost() {
Expand Down
11 changes: 6 additions & 5 deletions MekHQ/src/mekhq/campaign/parts/ProtomekArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import megamek.common.EquipmentType;
import megamek.common.Protomech;
import megamek.common.TechAdvancement;
import megamek.common.equipment.ArmorType;
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
import mekhq.campaign.work.IAcquisitionWork;
Expand Down Expand Up @@ -54,18 +55,18 @@ public ProtomekArmor clone() {

@Override
public double getTonnage() {
return EquipmentType.getProtomechArmorWeightPerPoint(type) * amount;
return ArmorType.of(type, true).getWeightPerPoint() * amount;
}

@Override
public Money getActualValue() {
return adjustCostsForCampaignOptions(
Money.of(amount * EquipmentType.getProtomechArmorCostPerPoint(type)));
Money.of(amount * ArmorType.of(type, true).getWeightPerPoint()));
}

@Override
public double getTonnageNeeded() {
return amountNeeded / EquipmentType.getProtomechArmorWeightPerPoint(type);
return amountNeeded / ArmorType.of(type, true).getWeightPerPoint();
}

@Override
Expand All @@ -77,7 +78,7 @@ public Money getValueNeeded() {
@Override
public Money getStickerPrice() {
// always in 5-ton increments
return Money.of(5.0 / EquipmentType.getProtomechArmorWeightPerPoint(type) * getArmorPointsPerTon()
return Money.of(5.0 / ArmorType.of(type, true).getWeightPerPoint() * getArmorPointsPerTon()
* EquipmentType.getProtomechArmorCostPerPoint(type));
}

Expand Down Expand Up @@ -117,7 +118,7 @@ public int getDifficulty() {

@Override
public double getArmorPointsPerTon() {
return 1.0 / EquipmentType.getProtomechArmorWeightPerPoint(type);
return 1.0 / ArmorType.of(type, true).getWeightPerPoint();
}

@Override
Expand Down

0 comments on commit 040383e

Please sign in to comment.