use of megamek.common.Mounted in project megameklab by MegaMek.
the class PMCriticalView method refresh.
public void refresh() {
mainGunPanel.setVisible(getProtoMek().hasMainGun());
leftArmPanel.setVisible(!getProtoMek().isQuad());
rightArmPanel.setVisible(!getProtoMek().isQuad());
mainGunList.refreshContents();
torsoList.refreshContents();
leftList.refreshContents();
rightList.refreshContents();
bodyList.refreshContents();
Map<Integer, List<Mounted>> eqByLocation = getProtoMek().getEquipment().stream().collect(Collectors.groupingBy(Mounted::getLocation));
for (int location = 0; location < getProtoMek().locations(); location++) {
int slotsUsed = 0;
double weightUsed = 0.0;
if (eqByLocation.containsKey(location)) {
for (Mounted m : eqByLocation.get(location)) {
if (TestProtomech.requiresSlot(m.getType())) {
slotsUsed++;
}
weightUsed += m.getTonnage();
}
}
switch(location) {
case Protomech.LOC_TORSO:
torsoSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
torsoWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
break;
case Protomech.LOC_LARM:
leftSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
leftWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
break;
case Protomech.LOC_RARM:
rightSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
rightWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
break;
case Protomech.LOC_MAINGUN:
mainGunSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
break;
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class PMSummaryView method runThroughEquipment.
private void runThroughEquipment() {
final NumberFormat format = DecimalFormat.getInstance();
double weightJJ = 0.0f;
double weightEnhance = 0.0f;
for (Mounted m : getProtoMek().getMisc()) {
MiscType mt = (MiscType) m.getType();
if (UnitUtil.isArmorOrStructure(mt)) {
continue;
} else if (mt.hasFlag(MiscType.F_MASC)) {
weightEnhance += m.getTonnage();
} else if (mt.hasFlag(MiscType.F_JUMP_JET) || mt.hasFlag(MiscType.F_UMU)) {
weightJJ += m.getTonnage();
}
}
txtJumpKg.setText(format.format(weightJJ * 1000));
txtEnhanceKg.setText(format.format(weightEnhance * 1000));
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class PMStructureTab method jumpChanged.
@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
// Don't set jumpMP for UMU.
if (null == jumpJet) {
getProtomech().setOriginalJumpMP(0);
jumpMP = 0;
} else if (jumpJet.hasFlag(MiscType.F_JUMP_JET)) {
getProtomech().setOriginalJumpMP(jumpMP);
} else {
getProtomech().setOriginalJumpMP(0);
}
List<Mounted> jjs = getProtomech().getMisc().stream().filter(m -> jumpJet.equals(m.getType())).collect(Collectors.toList());
while (jjs.size() > jumpMP) {
UnitUtil.removeMounted(getProtomech(), jjs.remove(jjs.size() - 1));
}
while (jumpMP > jjs.size()) {
try {
UnitUtil.addMounted(getProtomech(), new Mounted(getProtomech(), jumpJet), Protomech.LOC_BODY, false);
} catch (LocationFullException e) {
// Shouldn't be able to fill location
}
jumpMP--;
}
panSummary.refresh();
refresh.refreshBuild();
refresh.refreshStatus();
refresh.refreshPreview();
panMovement.setFromEntity(getProtomech());
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class BABuildTab method autoFillCrits.
private void autoFillCrits() {
// BattleArmor doesn't track crits implicitly, so they need to be tracked explicitly
BACriticalSuit crits = new BACriticalSuit(getBattleArmor());
// Populate with equipment that is already installed
for (Mounted m : getBattleArmor().getEquipment()) {
if ((m.getLocation() == BattleArmor.LOC_SQUAD) && (m.getBaMountLoc() != BattleArmor.MOUNT_LOC_NONE)) {
crits.addMounted(m.getBaMountLoc(), m);
}
}
for (Mounted mount : buildView.getTableModel().getCrits()) {
for (int location = BattleArmor.MOUNT_LOC_BODY; location < BattleArmor.MOUNT_NUM_LOCS; location++) {
if (!UnitUtil.isValidLocation(getBattleArmor(), mount.getType(), location)) {
continue;
}
// Don't assign change equipment that's already placed
if (mount.getBaMountLoc() != BattleArmor.MOUNT_LOC_NONE) {
continue;
}
if (crits.canAddMounted(location, mount)) {
mount.setBaMountLoc(location);
// Just added for record keeping
crits.addMounted(location, mount);
break;
}
}
}
refreshAll();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class ASStructureTab method patchworkChanged.
@Override
public void patchworkChanged(int location, EquipmentType armor) {
UnitUtil.resetArmor(getAero(), location);
// TODO: move this construction data out of the ui
int crits = 0;
switch(EquipmentType.getArmorType(armor)) {
case EquipmentType.T_ARMOR_STEALTH_VEHICLE:
case EquipmentType.T_ARMOR_LIGHT_ALUM:
case EquipmentType.T_ARMOR_ALUM:
case EquipmentType.T_ARMOR_FERRO_ALUM_PROTO:
case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
case EquipmentType.T_ARMOR_REFLECTIVE:
case EquipmentType.T_ARMOR_REACTIVE:
case EquipmentType.T_ARMOR_ANTI_PENETRATIVE_ABLATION:
case EquipmentType.T_ARMOR_BALLISTIC_REINFORCED:
crits = 1;
break;
case EquipmentType.T_ARMOR_HEAVY_ALUM:
crits = 2;
break;
}
if (getAero().getEmptyCriticals(location) < crits) {
JOptionPane.showMessageDialog(null, String.format("%s does not fit in location %s. Resetting to Standard Armor in this location.", armor.getName(), getAero().getLocationName(location)), "Error", JOptionPane.INFORMATION_MESSAGE);
} else {
getAero().setArmorType(EquipmentType.getArmorType(armor), location);
getAero().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
for (; crits > 0; crits--) {
try {
getAero().addEquipment(new Mounted(getAero(), armor), location, false);
} catch (LocationFullException ignored) {
}
}
}
panArmor.refresh();
panArmorAllocation.setFromEntity(getAero());
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshSummary();
refresh.refreshStatus();
}
Aggregations