use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method expandUnitMounts.
/**
* Expands crits that are a single mount by have multiple spreadable crits
* Such as TSM, Endo Steel, Reactive armor.
*
* @param unit
*/
public static void expandUnitMounts(Mech unit) {
for (int location = 0; location <= Mech.LOC_LLEG; location++) {
for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
CriticalSlot cs = unit.getCritical(location, slot);
if ((cs == null) || (cs.getType() == CriticalSlot.TYPE_SYSTEM)) {
continue;
}
Mounted mount = cs.getMount();
if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType()) && (UnitUtil.isTSM(mount.getType()) || UnitUtil.isArmorOrStructure(mount.getType()))) {
Mounted newMount = new Mounted(unit, mount.getType());
newMount.setLocation(location, mount.isRearMounted());
newMount.setArmored(mount.isArmored());
cs.setMount(newMount);
cs.setArmored(mount.isArmored());
unit.getEquipment().remove(mount);
unit.getMisc().remove(mount);
unit.getEquipment().add(newMount);
unit.getMisc().add(newMount);
}
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method updateJumpJets.
/**
* updates the Jump Jets.
*
* @param unit
* @param jjAmount
* @param jjType
*/
public static void updateJumpJets(Mech unit, int jjAmount, int jjType) {
final String METHOD_NAME = "updateJumpJets(Mech, int, int)";
unit.setOriginalJumpMP(jjAmount);
int ctype = unit.getJumpType();
if (jjType == ctype) {
int currentJJ = (int) unit.getMisc().stream().filter(m -> m.getType().hasFlag(MiscType.F_JUMP_JET)).count();
if (jjAmount < currentJJ) {
UnitUtil.removeJumpJets(unit, currentJJ - jjAmount);
return;
} else if (jjAmount > currentJJ) {
jjAmount = jjAmount - currentJJ;
} else {
// No change, get the fuck outta here!
return;
}
} else {
UnitUtil.removeJumpJets(unit, unit.getJumpMP());
}
// and add if too low
if (jjType == Mech.JUMP_BOOSTER) {
UnitUtil.removeJumpJets(unit, unit.getJumpMP());
createSpreadMounts(unit, EquipmentType.get(UnitUtil.getJumpJetType(jjType, unit.isClan())));
} else {
while (jjAmount > 0) {
try {
unit.addEquipment(new Mounted(unit, EquipmentType.get(UnitUtil.getJumpJetType(jjType, unit.isClan()))), Entity.LOC_NONE, false);
} catch (Exception ex) {
getLogger().log(UnitUtil.class, METHOD_NAME, ex);
}
jjAmount--;
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method removeMounted.
public static void removeMounted(Entity unit, Mounted mount) {
UnitUtil.removeCriticals(unit, mount);
// Some special checks for BA
if (unit instanceof BattleArmor) {
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setDWPMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the DWP
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
Mounted dwp = mount.getLinkedBy();
dwp.setLinked(null);
dwp.setLinkedBy(null);
}
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setAPMMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the AP Mount
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_AP_MOUNT)) {
Mounted apm = mount.getLinkedBy();
apm.setLinked(null);
apm.setLinkedBy(null);
}
}
// Some special checks for Aeros
if (unit instanceof Aero) {
if (mount.getType() instanceof WeaponType) {
// Aeros have additional weapon lists that need to be cleared
((Aero) unit).getTotalWeaponList().remove(mount);
((Aero) unit).getWeaponBayList().remove(mount);
((Aero) unit).getWeaponGroupList().remove(mount);
}
}
// We will need to reset the equipment numbers of the bay ammo and weapons
Map<Mounted, List<Mounted>> bayWeapons = new HashMap<>();
Map<Mounted, List<Mounted>> bayAmmo = new HashMap<>();
for (Mounted bay : unit.getWeaponBayList()) {
List<Mounted> list = bay.getBayWeapons().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayWeapons.put(bay, list);
list = bay.getBayAmmo().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayAmmo.put(bay, list);
}
unit.getEquipment().remove(mount);
if (mount.getType() instanceof MiscType) {
unit.getMisc().remove(mount);
} else if (mount.getType() instanceof AmmoType) {
unit.getAmmo().remove(mount);
} else {
unit.getWeaponList().remove(mount);
unit.getTotalWeaponList().remove(mount);
}
for (Mounted bay : bayWeapons.keySet()) {
bay.getBayWeapons().clear();
for (Mounted w : bayWeapons.get(bay)) {
if (mount != w) {
bay.getBayWeapons().add(unit.getEquipmentNum(w));
}
}
}
for (Mounted bay : bayAmmo.keySet()) {
bay.getBayAmmo().clear();
for (Mounted a : bayAmmo.get(bay)) {
if (mount != a) {
bay.getBayAmmo().add(unit.getEquipmentNum(a));
}
}
}
// An example of this would be removing a linked Artemis IV FCS
for (Mounted m : unit.getEquipment()) {
if (mount.equals(m.getLinkedBy())) {
m.setLinkedBy(null);
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method replaceMainWeapon.
public static void replaceMainWeapon(Infantry unit, InfantryWeapon weapon, boolean secondary) {
Mounted existingInfantryMount = null;
for (Mounted m : unit.getWeaponList()) {
if ((m.getType() instanceof InfantryWeapon) && (m.getLocation() == Infantry.LOC_INFANTRY)) {
existingInfantryMount = m;
break;
}
}
if (null != existingInfantryMount) {
UnitUtil.removeMounted(unit, existingInfantryMount);
}
if (secondary) {
unit.setSecondaryWeapon(weapon);
} else {
unit.setPrimaryWeapon(weapon);
}
// is TAG, in which case both are added.
if (unit.getSecondaryWeapon() != null && unit.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
try {
unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
} else if ((unit.getSecondaryN() < 2) || (null == unit.getSecondaryWeapon())) {
try {
unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
} else {
try {
unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class MovementView method setMovementModToolTips.
private void setMovementModToolTips(Entity en) {
StringJoiner walkTooltip = new StringJoiner(", ");
StringJoiner runTooltip = new StringJoiner(", ");
StringJoiner jumpTooltip = new StringJoiner(", ");
if (en.hasModularArmor()) {
walkTooltip.add("-1 (Modular armor)");
jumpTooltip.add("-1 (Modular armor)");
}
if (en instanceof Mech) {
if (((Mech) en).hasMPReducingHardenedArmor()) {
runTooltip.add("-1 (Hardened armor)");
}
if (((Mech) en).hasArmedMASC()) {
runTooltip.add("MASC/Supercharger");
}
int medShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_MEDIUM);
int lgShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_LARGE);
if (lgShields + medShields > 0) {
walkTooltip.add(String.format("-%d (Shield)", lgShields + medShields));
}
if (lgShields > 0) {
jumpTooltip.add("No Jump (Large Shield)");
}
} else if (en.hasWorkingMisc(MiscType.F_MASC)) {
runTooltip.add("Supercharger");
} else if (en.hasWorkingMisc(MiscType.F_JET_BOOSTER)) {
runTooltip.add("Jet Booster");
}
Optional<Mounted> partialWing = en.getMisc().stream().filter(m -> m.getType().hasFlag(MiscType.F_PARTIAL_WING)).findAny();
if (partialWing.isPresent()) {
int bonus = 2;
if (en instanceof Mech) {
bonus = ((Mech) en).getPartialWingJumpBonus(partialWing.get());
}
jumpTooltip.add(String.format("+%d (Partial wing)", bonus));
}
txtWalkFinal.setToolTipText(walkTooltip.length() > 0 ? walkTooltip.toString() : null);
txtRunFinal.setToolTipText(runTooltip.length() > 0 ? runTooltip.toString() : null);
txtJumpFinal.setToolTipText(jumpTooltip.length() > 0 && en.getOriginalJumpMP(true) > 0 ? jumpTooltip.toString() : null);
}
Aggregations