Skip to content

Commit

Permalink
Summary: Show crit space used by armor on fighters
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Jan 3, 2024
1 parent ee70dc5 commit c11c193
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/ui/fighterAero/ASMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void reloadTabs() {
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {

if (entityType == Entity.ETYPE_AERO) {
setEntity(new Aero());
setEntity(new AeroSpaceFighter());
getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
} else if (entityType == Entity.ETYPE_CONV_FIGHTER) {
setEntity(new ConvFighter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package megameklab.ui.generalUnit.summary;

import megamek.common.*;
import megamek.common.verifier.TestAero;
import megamek.common.verifier.TestEntity;
import megamek.common.verifier.TestSmallCraft;
import megamek.common.verifier.TestSupportVehicle;
import megameklab.util.UnitUtil;

Expand Down Expand Up @@ -58,6 +60,8 @@ public void refresh(Entity entity) {
}
} else if (entity instanceof Tank) {
critLabel.setText(formatCrits(getTankArmorCrits(entity)));
} else if (entity instanceof AeroSpaceFighter) {
critLabel.setText(getFighterCrits(entity));
}

if (entity.hasPatchworkArmor()) {
Expand Down Expand Up @@ -102,4 +106,28 @@ private int getTankArmorCrits(Entity entity) {

return usedSlots;
}

private String getFighterCrits(Entity entity) {
if (entity.hasPatchworkArmor()) {
int slots = 0;
for (int loc = 0; loc < Aero.LOC_WINGS; loc++) {
TestAero.AeroArmor aeroArmor = getArmorType(entity, loc);
if (aeroArmor == null) {
return "?";
}
slots += aeroArmor.patchworkSpace;
}
return formatCrits(slots);
} else {
TestAero.AeroArmor aeroArmor = getArmorType(entity, Aero.LOC_NOSE);
if (aeroArmor == null) {
return "?";
}
return formatCrits(aeroArmor.space);
}
}

private TestAero.AeroArmor getArmorType(Entity entity, int location) {
return TestAero.AeroArmor.getArmor(entity.getArmorType(location), entity.isClanArmor(location));
}
}

0 comments on commit c11c193

Please sign in to comment.