use of megamek.common.WeaponType in project megameklab by MegaMek.
the class StatusBar method calculateTotalHeat.
public double calculateTotalHeat() {
double heat = 0;
if (getMech().getOriginalJumpMP() > 0) {
if (getMech().getJumpType() == Mech.JUMP_IMPROVED) {
heat += Math.max(3, Math.ceil(getMech().getOriginalJumpMP() / 2.0f));
} else if (getMech().getJumpType() != Mech.JUMP_BOOSTER) {
heat += Math.max(3, getMech().getOriginalJumpMP());
}
if (getMech().getEngine().getEngineType() == Engine.XXL_ENGINE) {
heat *= 2;
}
} else if (getMech().getEngine().getEngineType() == Engine.XXL_ENGINE) {
heat += 6;
} else {
heat += 2;
}
if (getMech().hasNullSig()) {
heat += 10;
}
if (getMech().hasChameleonShield()) {
heat += 6;
}
for (Mounted mounted : getMech().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;
}
use of megamek.common.WeaponType 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;
}
use of megamek.common.WeaponType 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.WeaponType in project megameklab by MegaMek.
the class WeaponView method loadAmmo.
private void loadAmmo(Component o) {
if (o instanceof JList) {
JList<?> list = (JList<?>) o;
if (list.equals(laserWeaponCombo)) {
subLaserAmmoList.removeAllElements();
WeaponType weapon = (WeaponType) subLaserWeaponList.elementAt(list.getSelectedIndex());
if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
return;
}
Vector<String> equipmentList = new Vector<String>();
if (weapon.getAmmoType() != AmmoType.T_NA) {
for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
subLaserAmmoList.add(ammo);
equipmentList.add(ammo.getInternalName());
}
}
}
laserAmmoCombo.setListData(equipmentList);
} else if (list.equals(missileWeaponCombo)) {
subMissileAmmoList.removeAllElements();
WeaponType weapon = (WeaponType) subMissileWeaponList.elementAt(list.getSelectedIndex());
if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
return;
}
Vector<String> equipmentList = new Vector<String>();
for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR) && !weapon.hasFlag(WeaponType.F_ONESHOT)) {
subMissileAmmoList.add(ammo);
equipmentList.add(ammo.getInternalName());
}
}
missileAmmoCombo.setListData(equipmentList);
} else if (list.equals(ballisticWeaponCombo)) {
subBallisticAmmoList.removeAllElements();
WeaponType weapon = (WeaponType) subBallisticWeaponList.elementAt(list.getSelectedIndex());
if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
return;
}
Vector<String> equipmentList = new Vector<String>();
for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
subBallisticAmmoList.add(ammo);
equipmentList.add(ammo.getInternalName());
}
}
ballisticAmmoCombo.setListData(equipmentList);
} else if (list.equals(artilleryWeaponCombo)) {
subArtilleryAmmoList.removeAllElements();
WeaponType weapon = (WeaponType) subArtilleryWeaponList.elementAt(list.getSelectedIndex());
if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
return;
}
Vector<String> equipmentList = new Vector<String>();
for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
subArtilleryAmmoList.add(ammo);
equipmentList.add(ammo.getInternalName());
}
}
artilleryAmmoCombo.setListData(equipmentList);
}
}
}
use of megamek.common.WeaponType in project megameklab by MegaMek.
the class AeroBayTransferHandler method importData.
@Override
public boolean importData(TransferSupport support) {
if (!support.isDrop()) {
return false;
}
// Fields are equipmentNum, node child index, bay child index
String[] source = null;
List<Mounted> eqList = new ArrayList<>();
try {
source = ((String) support.getTransferable().getTransferData(DataFlavor.stringFlavor)).split(":");
for (String field : source[0].split(",")) {
int eqNum = Integer.parseInt(field);
Mounted m = eSource.getEntity().getEquipment(eqNum);
if (null != m) {
eqList.add(m);
}
}
} catch (Exception ex) {
MegaMekLab.getLogger().log(AeroBayTransferHandler.class, // $NON-NLS-1$
"importData(TransferSupport)", ex);
return false;
}
if (eqList.isEmpty()) {
return false;
}
if ((support.getComponent() instanceof BayWeaponCriticalTree)) {
final BayWeaponCriticalTree tree = (BayWeaponCriticalTree) support.getComponent();
if (eSource.getEntity().usesWeaponBays() && (eqList.size() == 1)) {
// If it's a bay we move it and its entire contents. Otherwise we find the bay that was
// dropped on and add it there. A weapon dropped on an illegal bay will create a new one
// and non-bay equipment will be added at the top level regardless of the drop location.
// Non-weapon bay equipment cannot be dropped on an illegal bay.
final Mounted mount = eqList.get(0);
if (mount.getType() instanceof BayWeapon) {
tree.addBay(mount);
} else if ((mount.getType() instanceof AmmoType) && (support.getUserDropAction() == AMMO_SINGLE)) {
// Default action for ammo is to move a single slot. Holding the ctrl key when dropping
// will create a AMMO_ALL command, which adds all the ammo of the type.
tree.addAmmo(mount, ((AmmoType) mount.getType()).getShots(), ((JTree.DropLocation) support.getDropLocation()).getPath());
} else {
tree.addToArc(mount, ((JTree.DropLocation) support.getDropLocation()).getPath());
}
} else {
// Small craft don't use bays.
tree.addToLocation(eqList);
}
} else {
// Target is unallocated bay table.
for (Mounted mount : eqList) {
if (mount.getType() instanceof AmmoType) {
AmmoType at = (AmmoType) mount.getType();
// Check whether we are moving one of multiple slots.
if ((support.getUserDropAction() == AMMO_SINGLE) && (mount.getUsableShotsLeft() > at.getShots())) {
mount.setShotsLeft(mount.getUsableShotsLeft() - at.getShots());
}
Mounted addMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), at);
if (null != addMount) {
if (support.getUserDropAction() == AMMO_SINGLE) {
addMount.setShotsLeft(addMount.getUsableShotsLeft() + at.getShots());
} else {
addMount.setShotsLeft(addMount.getUsableShotsLeft() + mount.getUsableShotsLeft());
}
} else {
try {
Mounted m = eSource.getEntity().addEquipment(at, Entity.LOC_NONE);
if (support.getUserDropAction() == AMMO_ALL) {
m.setShotsLeft(mount.getUsableShotsLeft());
}
} catch (LocationFullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
List<Mounted> toRemove;
if (mount.getType() instanceof BayWeapon) {
toRemove = new ArrayList<>();
for (Integer num : mount.getBayWeapons()) {
toRemove.add(eSource.getEntity().getEquipment(num));
}
for (Integer num : mount.getBayAmmo()) {
toRemove.add(eSource.getEntity().getEquipment(num));
}
} else {
toRemove = Collections.singletonList(mount);
}
for (Mounted m : toRemove) {
if (m.getType() instanceof AmmoType) {
Mounted aMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), m.getType());
if (null != aMount) {
aMount.setShotsLeft(aMount.getUsableShotsLeft() + m.getUsableShotsLeft());
m.setShotsLeft(0);
continue;
}
}
UnitUtil.removeCriticals(eSource.getEntity(), m);
UnitUtil.changeMountStatus(eSource.getEntity(), m, Entity.LOC_NONE, Entity.LOC_NONE, false);
if ((mount.getType() instanceof WeaponType) && (m.getLinkedBy() != null)) {
UnitUtil.removeCriticals(eSource.getEntity(), m.getLinkedBy());
UnitUtil.changeMountStatus(eSource.getEntity(), m.getLinkedBy(), Entity.LOC_NONE, Entity.LOC_NONE, false);
m.getLinkedBy().setLinked(null);
m.setLinkedBy(null);
}
}
UnitUtil.compactCriticals(eSource.getEntity());
}
if (mount.getType() instanceof BayWeapon) {
mount.getBayWeapons().clear();
mount.getBayAmmo().clear();
UnitUtil.removeMounted(eSource.getEntity(), mount);
}
}
}
return true;
}
Aggregations