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

Indicate variable equipment stats #499

Merged
merged 6 commits into from
Feb 25, 2020
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
6 changes: 4 additions & 2 deletions src/megameklab/com/ui/BattleArmor/tabs/EquipmentTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,9 @@ public boolean include(Entry<? extends EquipmentTableModel,
|| etype.hasFlag(MiscType.F_PARTIAL_WING)
|| etype.hasFlag(MiscType.F_JUMP_BOOSTER)
|| etype.hasFlag(MiscType.F_MECHANICAL_JUMP_BOOSTER)
|| etype.hasFlag(MiscType.F_MASC))){
|| etype.hasFlag(MiscType.F_MASC)
|| UnitUtil.isArmorOrStructure(etype)
|| UnitUtil.isJumpJet(etype))) {
return false;
}

Expand All @@ -584,7 +586,7 @@ public boolean include(Entry<? extends EquipmentTableModel,
return false;
}
BattleArmor ba = getBattleArmor();
if (((nType == T_OTHER) && UnitUtil.isBAEquipment(etype, ba))
if (((nType == T_OTHER) && UnitUtil.isBAEquipment(etype, ba) && !UnitUtil.isBattleArmorWeapon(etype, ba))
|| (((nType == T_WEAPON) && (UnitUtil.isUnitWeapon(etype, ba))))
|| ((nType == T_ENERGY) && UnitUtil.isUnitWeapon(etype, ba)
&& (wtype != null) && (wtype.hasFlag(WeaponType.F_ENERGY)
Expand Down
42 changes: 23 additions & 19 deletions src/megameklab/com/util/EquipmentTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package megameklab.com.util;

import java.awt.Color;
import java.awt.Component;
import java.text.DecimalFormat;
import java.util.ArrayList;
Expand All @@ -27,17 +26,8 @@
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;

import megamek.common.Aero;
import megamek.common.AmmoType;
import megamek.common.Entity;
import megamek.common.EquipmentType;
import megamek.common.ITechManager;
import megamek.common.MiscType;
import megamek.common.Mounted;
import megamek.common.RangeType;
import megamek.common.Tank;
import megamek.common.TechAdvancement;
import megamek.common.WeaponType;
import megamek.common.*;
import megamek.common.verifier.TestEntity;
import megamek.common.verifier.TestProtomech;
import megamek.common.weapons.autocannons.UACWeapon;
import megamek.common.weapons.gaussrifles.HAGWeapon;
Expand Down Expand Up @@ -109,7 +99,7 @@ public String getColumnName(int column) {
case COL_DAMAGE:
return "Damage";
case COL_DIVISOR:
return "Damage";
return "Divisor";
case COL_SPECIAL:
return "Special";
case COL_HEAT:
Expand Down Expand Up @@ -352,16 +342,23 @@ public Object getValueAt(int row, int col) {
return "-";
}
} else if (col == COL_TON) {
final double weight = type.getTonnage(entity);
if ((atype != null) && (entity.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)
|| entity.hasETypeFlag(Entity.ETYPE_PROTOMECH))) {
return atype.getKgPerShot() + " kg/shot";
} else if (type.getTonnage(entity) < 0.1) {
return String.format("%.2f kg", type.getTonnage(entity) * 1000);
return String.format("%.2f kg/shot", atype.getKgPerShot());
} else if (type.isVariableTonnage()) {
return "variable";
} else if (TestEntity.usesKgStandard(entity) || ((weight > 0.0) && (weight < 0.1))) {
return String.format("%.0f kg", type.getTonnage(entity) * 1000);
} else {
return String.valueOf(type.getTonnage(entity));
return formatter.format(weight);
}
} else if (col == COL_CRIT) {
if (entity.isSupportVehicle()) {
if (type.isVariableCriticals()
&& (entity.isSupportVehicle() || (entity instanceof Mech))) {
// Only Mechs and support vehicles require multiple slots for equipment
return "variable";
} else if (entity.isSupportVehicle()) {
return type.getSupportVeeSlots(entity);
} else if (entity instanceof Tank) {
return type.getTankslots(entity);
Expand All @@ -372,9 +369,15 @@ public Object getValueAt(int row, int col) {
} else if (col == COL_TRATING) {
return type.getFullRatingName(entity.isClan());
} else if (col == COL_COST) {
if (type.isVariableCost()) {
return "variable";
}
return formatter.format(type
.getCost(entity, false, Entity.LOC_NONE));
} else if (col == COL_BV) {
if (type.isVariableBV()) {
return "variable";
}
return type.getBV(entity);
} else if (col == COL_DPROTOTYPE) {
return entity.isMixedTech()? type.getTechAdvancement().getPrototypeDateName() :
Expand Down Expand Up @@ -422,9 +425,10 @@ private static String getDamageString(WeaponType wtype, boolean isAero) {
attackValue[RangeType.RANGE_LONG] = (int)wtype.getLongAV();
attackValue[RangeType.RANGE_EXTREME] = (int)wtype.getExtAV();
boolean allEq = true;
for (int i = 2; i <= wtype.maxRange && allEq; i++) {
for (int i = 2; i <= wtype.maxRange; i++) {
if (attackValue[i - 1] != attackValue[i]) {
allEq = false;
break;
}
}
StringBuilder avString = new StringBuilder();
Expand Down
17 changes: 13 additions & 4 deletions src/megameklab/com/util/UnitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
import megamek.common.weapons.autocannons.LBXACWeapon;
import megamek.common.weapons.autocannons.UACWeapon;
import megamek.common.weapons.battlearmor.CLBALBX;
import megamek.common.weapons.battlearmor.CLBALightTAG;
import megamek.common.weapons.battlearmor.ISBALightTAG;
import megamek.common.weapons.bayweapons.BayWeapon;
import megamek.common.weapons.capitalweapons.CapitalMissileWeapon;
import megamek.common.weapons.defensivepods.BPodWeapon;
Expand Down Expand Up @@ -2081,7 +2079,8 @@ public static boolean hasAmmo(Entity unit, int location) {
public static boolean isJumpJet(EquipmentType eq) {
if ((eq instanceof MiscType)
&& (eq.hasFlag(MiscType.F_JUMP_JET)
|| eq.hasFlag(MiscType.F_UMU))) {
|| eq.hasFlag(MiscType.F_UMU)
|| eq.hasFlag(MiscType.F_BA_VTOL))) {
return true;
}

Expand Down Expand Up @@ -2908,6 +2907,10 @@ public static boolean isTankWeapon(EquipmentType eq, Entity unit) {
}

public static boolean isSupportVehicleEquipment(EquipmentType eq, Entity unit) {
if ((unit.getWeightClass() == EntityWeightClass.WEIGHT_SMALL_SUPPORT)
&& (eq.getTonnage(unit) >= 5.0)) {
return false;
}
if ((eq instanceof MiscType) && !eq.hasFlag(MiscType.F_SUPPORT_TANK_EQUIPMENT)) {
return false;
} else if ((eq instanceof WeaponType)
Expand All @@ -2923,13 +2926,19 @@ public static boolean isSupportVehicleEquipment(EquipmentType eq, Entity unit) {
}
}

/**
* @param eq A {@link WeaponType} or {@link MiscType}
* @param ba The BattleArmor instance
* @return Whether the BA can use the equipment
*/
public static boolean isBAEquipment(EquipmentType eq, BattleArmor ba) {
if (eq instanceof MiscType) {
return eq.hasFlag(MiscType.F_BA_EQUIPMENT);
} else if (eq instanceof WeaponType) {
return isBattleArmorWeapon(eq, ba);
}
return true;
// This leaves ammotype, which is filtered according to having a weapon that can use it
return false;
}

public static boolean isBattleArmorAPWeapon(EquipmentType etype){
Expand Down