use of megamek.common.MiscType in project megameklab by MegaMek.
the class SummaryView method runThroughEquipment.
private void runThroughEquipment(TestMech testMech) {
double weightJJ = 0.0f;
double weightEnhance = 0.0f;
double weightEquip = 0.0f;
int critJJ = 0;
int critEquip = 0;
int critEnhance = 0;
for (Mounted m : getMech().getMisc()) {
MiscType mt = (MiscType) m.getType();
if (UnitUtil.isArmorOrStructure(mt)) {
continue;
} else if (mt.hasFlag(MiscType.F_TSM) || mt.hasFlag(MiscType.F_INDUSTRIAL_TSM) || mt.hasFlag(MiscType.F_MASC)) {
weightEnhance += mt.getTonnage(getMech(), m.getLocation());
critEnhance += UnitUtil.getCritsUsed(getMech(), mt);
} else if (mt.hasFlag(MiscType.F_JUMP_JET) || mt.hasFlag(MiscType.F_JUMP_BOOSTER)) {
weightJJ += mt.getTonnage(getMech(), m.getLocation());
critJJ += mt.getCriticals(getMech());
} else if (mt.hasFlag(MiscType.F_HEAT_SINK) || mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) {
continue;
} else {
weightEquip += mt.getTonnage(getMech(), m.getLocation());
critEquip += mt.getCriticals(getMech());
}
}
for (Mounted m : getMech().getWeaponList()) {
EquipmentType et = m.getType();
weightEquip += et.getTonnage(getMech());
critEquip += et.getCriticals(getMech());
}
for (Mounted m : getMech().getAmmo()) {
EquipmentType et = m.getType();
weightEquip += et.getTonnage(getMech());
critEquip += et.getCriticals(getMech());
}
txtJumpTon.setText(Double.toString(weightJJ));
txtEnhanceTon.setText(Double.toString(weightEnhance));
txtEquipTon.setText(Double.toString(weightEquip));
txtJumpCrit.setText(Integer.toString(critJJ));
txtEnhanceCrit.setText(Integer.toString(critEnhance));
txtEquipCrit.setText(Integer.toString(critEquip));
}
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 : getTank().getMisc()) {
if (mount.getLocation() == Entity.LOC_NONE) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getTank().getWeaponList()) {
if (mount.getLocation() == Entity.LOC_NONE) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getTank().getAmmo()) {
int ammoType = ((AmmoType) mount.getType()).getAmmoType();
if ((mount.getLocation() == Entity.LOC_NONE) && (mount.getUsableShotsLeft() > 1 || ammoType == AmmoType.T_CRUISE_MISSILE)) {
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())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// structure
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && masterEquipmentList.get(pos).getType().hasFlag(MiscType.F_ENDO_STEEL)) {
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
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 EquipmentView method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ADD_COMMAND)) {
EquipmentType equip = (EquipmentType) equipmentCombo.getSelectedItem();
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getTank())) {
mount = UnitUtil.updateTC(getTank(), equip);
}
} else {
try {
mount = getTank().addEquipment(equip, Entity.LOC_NONE, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
equipmentList.addCrit(mount);
} else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
int startRow = equipmentTable.getSelectedRow();
int count = equipmentTable.getSelectedRowCount();
for (; count > 0; count--) {
if (startRow > -1) {
equipmentList.removeMounted(startRow);
equipmentList.removeCrit(startRow);
}
}
} else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
removeAllEquipment();
} else {
return;
}
fireTableRefresh();
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class SummaryView method runThroughEquipment.
private void runThroughEquipment(TestTank testTank) {
double weightJJ = 0.0f;
double weightEquip = 0.0f;
double weightSponson = 0.0f;
for (Mounted m : getTank().getMisc()) {
MiscType mt = (MiscType) m.getType();
if (UnitUtil.isArmorOrStructure(mt)) {
continue;
} else if (mt.hasFlag(MiscType.F_SPONSON_TURRET)) {
weightSponson = mt.getTonnage(getTank());
} else if (mt.hasFlag(MiscType.F_JUMP_JET)) {
weightJJ += mt.getTonnage(getTank(), m.getLocation());
} else if (mt.hasFlag(MiscType.F_HEAT_SINK) || mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) {
continue;
} else {
weightEquip += mt.getTonnage(getTank(), m.getLocation());
}
}
for (Mounted m : getTank().getWeaponList()) {
EquipmentType et = m.getType();
weightEquip += et.getTonnage(getTank());
}
for (Mounted m : getTank().getAmmo()) {
EquipmentType et = m.getType();
weightEquip += et.getTonnage(getTank());
}
txtJumpTon.setText(Double.toString(weightJJ));
txtEquipTon.setText(Double.toString(weightEquip));
txtSponsonTon.setText(Double.toString(weightSponson));
if (weightJJ > 0) {
txtJumpCrit.setText(Integer.toString(1));
} else {
txtJumpCrit.setText(Integer.toString(0));
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class BayWeaponCriticalTree method isValidDropLocation.
/**
* Determines whether the equipment can be dropped here. In the case of ammo or weapon
* enhancement, there must be a matching weapon in the bay. A weapon that doesn't fit the
* bay will be placed in a new bay.
*
* @param loc The drop location from the TransferSupport object passed to the TransferHandler
* @param eq The equipment to be dropped
* @return Whether the equipment can be dropped in the location
*/
public boolean isValidDropLocation(JTree.DropLocation loc, Mounted eq) {
if (!eSource.getEntity().usesWeaponBays()) {
return true;
}
Mounted bay = null;
TreePath path = loc.getPath();
if (null != path) {
// without a capacitor.
if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR) && (path.getLastPathComponent() instanceof EquipmentNode)) {
EquipmentNode node = (EquipmentNode) path.getLastPathComponent();
if (node.getMounted().getType() instanceof PPCWeapon) {
return node.getMounted().getLinkedBy() == null;
} else if (node.getMounted().getType() instanceof PPCBayWeapon) {
for (Integer eqNum : node.getMounted().getBayWeapons()) {
if (eSource.getEntity().getEquipment(eqNum).getLinkedBy() == null) {
return true;
}
}
return false;
}
}
bay = getBayFromPath(path);
}
// disallow dropping a bay into its current arc or a weapon or ammo into its current bay
if (null != bay) {
if ((eq == bay) || ((eq.getType() instanceof WeaponType) && (bay.getBayWeapons().contains(eSource.getEntity().getEquipmentNum(eq)))) || ((eq.getType() instanceof AmmoType) && (bay.getBayAmmo().contains(eSource.getEntity().getEquipmentNum(eq))))) {
return false;
}
}
if (eq.getType() instanceof AmmoType) {
return (null != bay) && canTakeEquipment(bay, eq);
}
if (UnitUtil.isWeaponEnhancement(eq.getType())) {
if ((null != bay) && canTakeEquipment(bay, eq)) {
for (Integer eqNum : bay.getBayWeapons()) {
if (eSource.getEntity().getEquipment(eqNum) == eq.getLinked()) {
return false;
}
}
return true;
}
return false;
}
return true;
}
Aggregations