use of megamek.common.MiscType 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));
}
}
use of megamek.common.MiscType 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.MiscType 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.MiscType in project megameklab by MegaMek.
the class EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
boolean success = false;
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getTank())) {
mount = UnitUtil.updateTC(getTank(), equip);
success = mount != null;
}
} else {
try {
mount = new Mounted(getTank(), equip);
int loc = Entity.LOC_NONE;
if (isMisc && equip.hasFlag(MiscType.F_MAST_MOUNT)) {
loc = VTOL.LOC_ROTOR;
}
getTank().addEquipment(mount, loc, false);
success = true;
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
if (success) {
equipmentList.addCrit(mount);
}
}
use of megamek.common.MiscType 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++;
}
}
}
Aggregations