use of megamek.common.Mounted in project megameklab by MegaMek.
the class BuildView method jMenuLoadComponent_actionPerformed.
/**
* When the user right-clicks on the equipment table, a context menu is
* generated that his menu items for each possible location that is clicked.
* When the location is clicked, this is the method that adds the selected
* equipment to the desired location.
*
* @param location
* @param selectedRow
*/
private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) {
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
try {
getAero().addEquipment(eq, location, false);
} catch (Exception ex) {
ex.printStackTrace();
}
UnitUtil.changeMountStatus(getAero(), eq, location, -1, 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 EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
boolean multiMount = UnitUtil.isBAMultiMount(equip);
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getBattleArmor())) {
mount = UnitUtil.updateTC(getBattleArmor(), equip);
if (mount != null) {
equipmentList.addCrit(mount);
}
}
} else {
try {
if (multiMount) {
for (int t = 1; t <= getBattleArmor().getTroopers(); t++) {
mount = new Mounted(getBattleArmor(), equip);
mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
getBattleArmor().addEquipment(mount, t, false);
equipmentList.addCrit(mount);
}
} else {
mount = new Mounted(getBattleArmor(), equip);
mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
getBattleArmor().addEquipment(mount, BattleArmor.LOC_SQUAD, false);
equipmentList.addCrit(mount);
}
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class EquipmentTab method loadEquipmentTable.
private void loadEquipmentTable() {
for (Mounted mount : getBattleArmor().getWeaponList()) {
if (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType())) {
equipmentList.addCrit(mount);
}
}
for (Mounted mount : getBattleArmor().getAmmo()) {
// Ignore ammo for one-shot launchers
if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
continue;
}
equipmentList.addCrit(mount);
}
List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
for (Mounted mount : getBattleArmor().getMisc()) {
EquipmentType etype = mount.getType();
if (UnitUtil.isHeatSink(mount) || etype.hasFlag(MiscType.F_JUMP_JET) || etype.hasFlag(MiscType.F_JUMP_BOOSTER) || etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || UnitUtil.isArmorOrStructure(etype)) {
continue;
}
// if (UnitUtil.isUnitEquipment(mount.getType(), unit) || UnitUtil.isUn) {
if (UnitUtil.isFixedLocationSpreadEquipment(etype) && !spreadAlreadyAdded.contains(etype)) {
equipmentList.addCrit(mount);
// keep track of spreadable equipment here, so it doesn't
// show up multiple times in the table
spreadAlreadyAdded.add(etype);
} else {
equipmentList.addCrit(mount);
}
// }
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class EquipmentTab method removeHeatSinks.
private void removeHeatSinks() {
int location = 0;
for (; location < equipmentList.getRowCount(); ) {
Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
EquipmentType eq = mount.getType();
if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
try {
equipmentList.removeCrit(location);
} catch (ArrayIndexOutOfBoundsException aioobe) {
return;
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
location++;
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class StructureTab method enhancementChanged.
@Override
public void enhancementChanged(EquipmentType eq, boolean selected) {
if (selected) {
try {
int loc = BattleArmor.MOUNT_LOC_BODY;
if (eq.hasFlag(MiscType.F_MASC)) {
loc = BattleArmor.MOUNT_LOC_NONE;
}
int numTimesToAdd = 1;
// for each critical
if (eq.isSpreadable()) {
numTimesToAdd = eq.getCriticals(getBattleArmor());
}
for (int i = 0; i < numTimesToAdd; i++) {
Mounted newMount = new Mounted(getBattleArmor(), eq);
newMount.setBaMountLoc(loc);
getBattleArmor().addEquipment(newMount, BattleArmor.LOC_SQUAD, false);
}
} catch (LocationFullException exc) {
// Shouldn't happen with BA
exc.printStackTrace();
}
} else {
List<Mounted> mounts = getBattleArmor().getMisc().stream().filter(m -> m.getType().equals(eq)).collect(Collectors.toList());
for (Mounted mount : mounts) {
UnitUtil.removeMounted(getBattleArmor(), mount);
}
}
panMovement.setFromEntity(getBattleArmor());
refresh.refreshSummary();
refresh.refreshBuild();
refresh.refreshPreview();
}
Aggregations