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;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getAero())) {
mount = UnitUtil.updateTC(getAero(), equip);
if (null != mount) {
equipmentList.addCrit(mount);
}
}
} else {
int count = (Integer) spnAddCount.getValue();
if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
if (null != aMount) {
aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
return;
} else {
mount = new Mounted(getAero(), equip);
mount.setShotsLeft(((AmmoType) equip).getShots() * count);
try {
getAero().addEquipment(mount, Entity.LOC_NONE, false);
equipmentList.addCrit(mount);
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
} else {
try {
for (int i = 0; i < count; i++) {
mount = new Mounted(getAero(), equip);
getAero().addEquipment(mount, Entity.LOC_NONE, 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 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 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:
crits = 1;
break;
case EquipmentType.T_ARMOR_HEAVY_ALUM:
crits = 2;
break;
}
if (getAero().getEmptyCriticals(location) < crits) {
JOptionPane.showMessageDialog(null, armor.getName() + " does not fit in location " + getAero().getLocationName(location) + ". Resetting to Standard Armor in this 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 ex) {
}
}
}
panArmor.refresh();
panArmorAllocation.setFromEntity(getAero());
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshSummary();
refresh.refreshStatus();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class BuildView method mousePressed.
public void mousePressed(MouseEvent e) {
// locations, but only if those locations are make sense
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);
String[] locNames = getAero().getLocationNames();
// A list of the valid locations we can add the selected eq to
ArrayList<Integer> validLocs = new ArrayList<Integer>();
// The number of possible locations, Aeros' have LOC_WINGS, which we
// want ot ignore, hence -1
int numLocs = getAero().locations() - 1;
// If it's a weapon, there are restrictions
if (eq.getType() instanceof WeaponType) {
int[] availSpace = TestAero.availableSpace(getAero());
int[] numWeapons = new int[availSpace.length];
for (Mounted m : getAero().getWeaponList()) {
if (m.getLocation() != Aero.LOC_NONE) {
numWeapons[m.getLocation()]++;
}
}
for (int loc = 0; loc < numLocs; loc++) {
if ((numWeapons[loc] + 1) < availSpace[loc]) {
validLocs.add(loc);
}
}
// If it's not a weapon there are no space requirements
} else {
for (int loc = 0; loc < numLocs; loc++) {
validLocs.add(loc);
}
}
// Add a menu item for each potential location
for (Integer location : validLocs) {
if (UnitUtil.isValidLocation(getAero(), eq.getType(), location)) {
item = new JMenuItem("Add to " + locNames[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 loadEquipmentTable.
private void loadEquipmentTable() {
equipmentList.removeAllCrits();
masterEquipmentList.clear();
for (Mounted mount : getAero().getMisc()) {
if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount)) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getAero().getTotalWeaponList()) {
if (mount.getLocation() == Entity.LOC_NONE) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getAero().getAmmo()) {
if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
masterEquipmentList.add(mount);
}
}
Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
// HeatSinks first
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isHeatSink(masterEquipmentList.get(pos))) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// Jump Jets
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isJumpJet(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// weapons and ammo
Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
weaponsNAmmoList.add(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
for (Mounted mount : weaponsNAmmoList) {
equipmentList.addCrit(mount);
}
// Equipment
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && !UnitUtil.isArmor(masterEquipmentList.get(pos).getType()) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// structure
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isStructure(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// armor
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isArmor(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// everything else that is not TSM
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (!UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// TSM
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
equipmentList.addCrit(masterEquipmentList.get(pos));
}
}
Aggregations