use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method removeHeatSinks.
/**
* Removes the specified number of heat sinks from the mek Heat sinks are
* removed first fwith LOC_NONE above the free crit limit then they are
* removed with a location, and lastly they are removed below the free crit
* limit
*
* @param unit
*/
public static void removeHeatSinks(Mech unit, int number) {
final String METHOD_NAME = "removeHeatSinks(Mech, int)";
Vector<Mounted> toRemove = new Vector<Mounted>();
int base = UnitUtil.getCriticalFreeHeatSinks(unit, unit.hasCompactHeatSinks());
boolean splitCompact = false;
if (unit.hasCompactHeatSinks()) {
// first check to see if there is a single compact heat sink outside
// of
// the engine and remove this first if so
Mounted mount = UnitUtil.getSingleCompactHeatSink(unit);
if ((null != mount) && (number > 0)) {
UnitUtil.removeMounted(unit, mount);
number--;
}
// compact
if ((number % 2) == 1) {
splitCompact = true;
number--;
}
}
Vector<Mounted> unassigned = new Vector<Mounted>();
Vector<Mounted> assigned = new Vector<Mounted>();
Vector<Mounted> free = new Vector<Mounted>();
for (Mounted m : unit.getMisc()) {
if (UnitUtil.isHeatSink(m)) {
if (m.getLocation() == Entity.LOC_NONE) {
if (base > 0) {
free.add(m);
base--;
} else {
unassigned.add(m);
}
} else {
assigned.add(m);
}
}
}
toRemove.addAll(unassigned);
toRemove.addAll(assigned);
toRemove.addAll(free);
if (unit.hasCompactHeatSinks()) {
// need to do some number magic here. The unassigned and assigned
// slots
// should each contain two heat sinks, but if we dip into the free
// then we
// are looking at one heat sink.
int numberDouble = Math.min(number / 2, unassigned.size() + assigned.size());
int numberSingle = Math.max(0, number - (2 * numberDouble));
number = numberDouble + numberSingle;
}
number = Math.min(number, toRemove.size());
for (int i = 0; i < number; i++) {
Mounted eq = toRemove.get(i);
UnitUtil.removeMounted(unit, eq);
}
if (splitCompact) {
Mounted eq = toRemove.get(number);
int loc = eq.getLocation();
// remove singleCompact mount and replace with a double
UnitUtil.removeMounted(unit, eq);
if (!eq.getType().hasFlag(MiscType.F_HEAT_SINK)) {
try {
UnitUtil.addMounted(unit, new Mounted(unit, EquipmentType.get("IS1 Compact Heat Sink")), loc, false);
} catch (Exception ex) {
getLogger().log(UnitUtil.class, METHOD_NAME, ex);
}
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method countUnallocatedCriticals.
public static int countUnallocatedCriticals(Mech unit) {
int nCrits = 0;
int engineHeatSinkCount = UnitUtil.getCriticalFreeHeatSinks(unit, unit.hasCompactHeatSinks());
for (Mounted mount : unit.getMisc()) {
if (UnitUtil.isHeatSink(mount) && (mount.getLocation() == Entity.LOC_NONE)) {
if (engineHeatSinkCount > 0) {
engineHeatSinkCount--;
continue;
}
}
if ((mount.getLocation() == Entity.LOC_NONE)) {
nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
}
}
for (Mounted mount : unit.getWeaponList()) {
if (mount.getLocation() == Entity.LOC_NONE) {
nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
}
}
for (Mounted mount : unit.getAmmo()) {
if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
}
}
return nCrits;
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method removeISorArmorCrits.
/**
* remove all CriticalSlots on the passed unit that are internal structure or
* armor
*
* @param unit
* the Entity
* @param internalStructure
* true to remove IS, false to remove armor
*/
public static void removeISorArmorCrits(Entity unit, boolean internalStructure) {
ArrayList<String> mountList = new ArrayList<String>();
if (internalStructure) {
for (String struc : EquipmentType.structureNames) {
mountList.add("IS " + struc);
mountList.add("Clan " + struc);
}
} else {
for (String armor : EquipmentType.armorNames) {
mountList.add("IS " + armor);
mountList.add("Clan " + armor);
}
}
for (int location = Mech.LOC_HEAD; location < unit.locations(); location++) {
for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
CriticalSlot crit = unit.getCritical(location, slot);
if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
Mounted mount = crit.getMount();
if ((mount != null) && (mount.getType() instanceof MiscType) && mountList.contains(mount.getType().getInternalName())) {
crit = null;
unit.setCritical(location, slot, crit);
}
}
}
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class UnitUtil method resetCriticalsAndMounts.
/**
* Reset all the Crits and Mounts on the Unit.
*
* @param unit
*/
public static void resetCriticalsAndMounts(Mech unit) {
for (int location = Mech.LOC_HEAD; 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_EQUIPMENT)) {
cs = null;
unit.setCritical(location, slot, cs);
}
}
}
for (Mounted mount : unit.getEquipment()) {
mount.setLocation(Entity.LOC_NONE, false);
}
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class WeaponListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean hasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
EquipmentType eq = EquipmentType.get(value.toString());
if (eq == null) {
return label;
}
label.setText(UnitUtil.getCritName(unit, eq));
label.setName(value.toString());
label.setToolTipText(UnitUtil.getToolTipInfo(unit, new Mounted(unit, eq)));
return label;
}
Aggregations