use of megamek.common.weapons.bayweapons.PPCBayWeapon in project megameklab by MegaMek.
the class BayWeaponCriticalTree method canTakeEquipment.
/**
* Determines whether the equipment can be added to the bay. For a weapon this is determined
* by bay type and AV limit. For ammo this is determined by the presence of a weapon in that location
* that can use the ammo. For weapon enhancements this is determined by the presence of a weapon
* that can use the enhancement that doesn't already have one.
*
* @param bay
* @param eq
* @return
*/
private boolean canTakeEquipment(Mounted bay, Mounted eq) {
if (eq.getType() instanceof WeaponType) {
if (((WeaponType) eq.getType()).getBayType() != bay.getType()) {
return false;
}
// find current av
double av = 0;
for (Integer wNum : bay.getBayWeapons()) {
final Mounted w = eSource.getEntity().getEquipment(wNum);
// That's 1d6 for rifle and 2d6 for canon.
if (w.getType().hasFlag(WeaponType.F_PLASMA)) {
if (((WeaponType) w.getType()).getDamage() == WeaponType.DAMAGE_VARIABLE) {
av += 7;
} else {
av += 13.5;
}
} else {
av += ((WeaponType) w.getType()).getShortAV();
}
// Capacitors in bays are always considered charged.
if ((w.getLinkedBy() != null) && (w.getLinkedBy().getType().hasFlag(MiscType.F_PPC_CAPACITOR))) {
av += 5;
}
}
if (((WeaponType) eq.getType()).isCapital()) {
return av + ((WeaponType) eq.getType()).getShortAV() <= 70;
} else {
return av + ((WeaponType) eq.getType()).getShortAV() <= 700;
}
} else if (eq.getType() instanceof AmmoType) {
for (int eqNum : bay.getBayWeapons()) {
final WeaponType weapon = (WeaponType) eSource.getEntity().getEquipment(eqNum).getType();
if ((weapon.getAmmoType() == ((AmmoType) eq.getType()).getAmmoType()) && (weapon.getRackSize() == ((AmmoType) eq.getType()).getRackSize())) {
return true;
}
}
} else if ((eq.getType() instanceof MiscType) && ((eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO))) {
for (int eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
final WeaponType wtype = (WeaponType) weapon.getType();
if ((weapon.getLinkedBy() == null) && ((wtype.getAmmoType() == AmmoType.T_LRM) || (wtype.getAmmoType() == AmmoType.T_SRM) || (wtype.getAmmoType() == AmmoType.T_MML) || (wtype.getAmmoType() == AmmoType.T_NLRM))) {
return true;
}
}
} else if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_APOLLO)) {
for (int eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
final WeaponType wtype = (WeaponType) weapon.getType();
if ((weapon.getLinkedBy() == null) && (wtype.getAmmoType() == AmmoType.T_MRM)) {
return true;
}
}
} else if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR) && (bay.getType() instanceof PPCBayWeapon)) {
for (int eqNum : bay.getBayWeapons()) {
if (eSource.getEntity().getEquipment(eqNum).getLinkedBy() == null) {
return true;
}
}
}
return false;
}
use of megamek.common.weapons.bayweapons.PPCBayWeapon 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