use of megamek.common.Mounted in project megameklab by MegaMek.
the class StructureTab method clearCrit.
/**
* Removes equipment placed in the given critical slot to clear the space for a system critical
*/
private void clearCrit(int loc, int slotNum) {
final CriticalSlot crit = getMech().getCritical(loc, slotNum);
Mounted mounted = null;
if (crit != null && crit.getType() == CriticalSlot.TYPE_EQUIPMENT) {
mounted = crit.getMount();
}
if (mounted == null) {
return;
}
UnitUtil.removeCriticals(getMech(), mounted);
if (crit.getMount2() != null) {
UnitUtil.removeCriticals(getMech(), crit.getMount2());
}
// Check linkings after you remove everything.
try {
MechFileParser.postLoadInit(getMech());
} catch (EntityLoadingException ele) {
// do nothing.
} catch (Exception ex) {
ex.printStackTrace();
}
if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
UnitUtil.changeMountStatus(getMech(), mounted, Entity.LOC_NONE, Entity.LOC_NONE, false);
if (crit.getMount2() != null) {
UnitUtil.changeMountStatus(getMech(), crit.getMount2(), Entity.LOC_NONE, Entity.LOC_NONE, false);
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class StructureTab method jumpChanged.
@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
// Don't set jumpMP for UMU.
if (null == jumpJet) {
getMech().setOriginalJumpMP(0);
jumpMP = 0;
} else if (jumpJet.hasFlag(MiscType.F_JUMP_JET) || jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
getMech().setOriginalJumpMP(jumpMP);
} else {
getMech().setOriginalJumpMP(0);
}
List<Mounted> jjs = getMech().getMisc().stream().filter(m -> m.getType() == jumpJet).collect(Collectors.toList());
if (jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
if (!getMech().hasWorkingMisc(MiscType.F_JUMP_BOOSTER)) {
UnitUtil.createSpreadMounts(getMech(), jumpJet);
}
} else {
while (jjs.size() > jumpMP) {
UnitUtil.removeMounted(getMech(), jjs.remove(jjs.size() - 1));
}
while (jumpMP > jjs.size()) {
try {
UnitUtil.addMounted(getMech(), new Mounted(getMech(), jumpJet), Entity.LOC_NONE, false);
} catch (LocationFullException e) {
// Adding to LOC_NONE
}
jumpMP--;
}
}
panSummary.refresh();
refresh.refreshBuild();
refresh.refreshStatus();
refresh.refreshPreview();
panMovement.setFromEntity(getMech());
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class BuildView method mousePressed.
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu popup = new JPopupMenu();
JMenuItem item;
final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
final int totalCrits = UnitUtil.getCritsUsed(getMech(), eq.getType());
String[] locations = getMech().getLocationNames();
String[] abbrLocations = getMech().getLocationAbbrs();
if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getMech() instanceof LandAirMech)) {
int[] critSpace = UnitUtil.getHighestContinuousNumberOfCritsArray(getMech());
if ((critSpace[Mech.LOC_RT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RT)) {
JMenu rtMenu = new JMenu(locations[Mech.LOC_RT]);
if (critSpace[Mech.LOC_RT] >= totalCrits) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RT]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(Mech.LOC_RT, selectedRow);
}
});
rtMenu.add(item);
}
int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_RARM, Mech.LOC_RLEG };
for (int location = 0; location < 3; location++) {
JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_RT], abbrLocations[splitLocations[location]]));
int subCrits = critSpace[splitLocations[location]];
for (int slots = 1; slots <= subCrits; slots++) {
final int primarySlots = totalCrits - slots;
item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_RT], primarySlots, abbrLocations[splitLocations[location]], slots));
final int secondaryLocation = splitLocations[location];
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RT, secondaryLocation, primarySlots, selectedRow);
}
});
subMenu.add(item);
}
rtMenu.add(subMenu);
}
popup.add(rtMenu);
}
if ((critSpace[Mech.LOC_RARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RARM)) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RARM]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RARM, Mech.LOC_RARM, totalCrits, selectedRow);
}
});
popup.add(item);
}
if ((critSpace[Mech.LOC_LT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LT)) {
JMenu ltMenu = new JMenu(locations[Mech.LOC_LT]);
if (critSpace[Mech.LOC_LT] >= totalCrits) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LT]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(Mech.LOC_LT, selectedRow);
}
});
ltMenu.add(item);
}
int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_LARM, Mech.LOC_LLEG };
for (int location = 0; location < 3; location++) {
JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_LT], abbrLocations[splitLocations[location]]));
int subCrits = critSpace[splitLocations[location]];
for (int slots = 1; slots <= subCrits; slots++) {
final int primarySlots = totalCrits - slots;
item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_LT], primarySlots, abbrLocations[splitLocations[location]], slots));
final int secondaryLocation = splitLocations[location];
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LT, secondaryLocation, primarySlots, selectedRow);
}
});
subMenu.add(item);
}
ltMenu.add(subMenu);
}
popup.add(ltMenu);
}
if ((critSpace[Mech.LOC_LARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LARM)) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LARM]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LARM, Mech.LOC_LARM, totalCrits, selectedRow);
}
});
popup.add(item);
}
} else {
for (int location = 0; location < getMech().locations(); location++) {
if ((UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location) >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), location)) {
item = new JMenuItem("Add to " + locations[location]);
final int loc = location;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(loc, selectedRow);
}
});
popup.add(item);
}
}
}
popup.show(this, e.getX(), e.getY());
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class BuildView method jMenuLoadSplitComponent_actionPerformed.
private void jMenuLoadSplitComponent_actionPerformed(int location, int secondaryLocation, int primarySlots, int selectedRow) {
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
int crits = UnitUtil.getCritsUsed(getMech(), eq.getType());
int openSlots = Math.min(primarySlots, UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location));
eq.setSecondLocation(secondaryLocation);
for (int slot = 0; slot < openSlots; slot++) {
try {
UnitUtil.addMounted(getMech(), eq, location, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
crits -= openSlots;
for (int slot = 0; slot < crits; slot++) {
try {
UnitUtil.addMounted(getMech(), eq, secondaryLocation, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
UnitUtil.changeMountStatus(getMech(), eq, location, secondaryLocation, false);
// go back up to grandparent build tab and fire a full refresh.
((BuildTab) getParent().getParent()).refreshAll();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class StatusBar method calculateTotalHeat.
public double calculateTotalHeat() {
double heat = 0;
for (Mounted mounted : getAero().getWeaponList()) {
WeaponType wtype = (WeaponType) mounted.getType();
double weaponHeat = wtype.getHeat();
// only count non-damaged equipment
if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() || mounted.isBreached()) {
continue;
}
// one shot weapons count 1/4
if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) || wtype.hasFlag(WeaponType.F_ONESHOT)) {
weaponHeat *= 0.25;
}
// double heat for ultras
if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) {
weaponHeat *= 2;
}
// Six times heat for RAC
if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) {
weaponHeat *= 6;
}
// half heat for streaks
if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_MRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) {
weaponHeat *= 0.5;
}
heat += weaponHeat;
}
return heat;
}
Aggregations