use of megamek.common.Mounted in project megameklab by MegaMek.
the class CVBuildTab method resetCrits.
private void resetCrits() {
for (Mounted mount : getTank().getEquipment()) {
// Fixed shouldn't be removed
if (UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
continue;
}
UnitUtil.removeCriticals(getTank(), mount);
UnitUtil.changeMountStatus(getTank(), mount, Entity.LOC_NONE, Entity.LOC_NONE, false);
}
// Check linkings after you remove everything.
try {
MechFileParser.postLoadInit(getTank());
} catch (EntityLoadingException ele) {
// do nothing.
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
refresh.refreshAll();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class CVBuildTab method autoFillCrits.
private void autoFillCrits() {
for (Mounted mount : unallocatedView.getTableModel().getCrits()) {
for (int location = 0; location < getTank().locations(); location++) {
try {
getTank().addEquipment(mount, location, false);
UnitUtil.changeMountStatus(getTank(), mount, location, Entity.LOC_NONE, false);
break;
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
}
}
refresh.refreshAll();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class ImageHelperBattleArmor method printBattleArmorWeaponsNEquipment.
public static void printBattleArmorWeaponsNEquipment(BattleArmor ba, Graphics2D g2d, float offset) {
int typePoint = 34;
int damagePoint = 133;
int minPoint = 155;
int shtPoint = 172;
int medPoint = 188;
int longPoint = 204;
float linePoint = 150f + offset;
float maxHeight = 38.0f;
float lineFeed = 6.7f;
float stringHeight = 0f;
boolean newLineNeeded = false;
ArrayList<ArrayList<EquipmentInfo>> equipmentLocations = new ArrayList<ArrayList<EquipmentInfo>>(BattleArmor.LOC_TROOPER_6 + 1);
for (int pos = 0; pos <= BattleArmor.LOC_TROOPER_6; pos++) {
equipmentLocations.add(pos, new ArrayList<EquipmentInfo>());
}
boolean hasNarcCompact = false;
boolean hasMineLayer = false;
Mounted glove = null;
int numberOfGloves = 0;
for (Mounted eq : ba.getEquipment()) {
if ((eq.getType() instanceof AmmoType) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableBAEquipment(eq.getType())) {
continue;
}
if (!hasNarcCompact && (eq.getType() instanceof ISBACompactNarc)) {
hasNarcCompact = true;
} else if (hasNarcCompact && (eq.getType() instanceof ISBACompactNarc)) {
continue;
}
if (!hasMineLayer && eq.getType().hasFlag(MiscType.F_MINE) && eq.getType().hasFlag(MiscType.F_BA_EQUIPMENT)) {
hasMineLayer = true;
} else if (hasMineLayer && eq.getType().hasFlag(MiscType.F_MINE) && eq.getType().hasFlag(MiscType.F_BA_EQUIPMENT)) {
continue;
}
if (UnitUtil.isManipulator(eq)) {
if ((glove != null) && (glove.getName().equals(eq.getName()))) {
numberOfGloves++;
continue;
} else {
glove = eq;
numberOfGloves = 1;
}
}
equipmentLocations.get(eq.getLocation()).add(new EquipmentInfo(ba, eq));
}
if (!ba.isFireResistant() && !ba.isStealthActive() && !ba.isReactive() && !ba.isReflective()) {
maxHeight += lineFeed;
}
if (ba.hasCamoSystem()) {
maxHeight -= lineFeed;
}
if (ba.isBurdened()) {
maxHeight -= lineFeed;
}
if (ba.hasDWP()) {
maxHeight -= lineFeed;
}
if (ba.isExoskeleton() && !ba.hasWorkingMisc(MiscType.F_EXTENDED_LIFESUPPORT)) {
maxHeight -= lineFeed;
}
Font font = ImageHelperBattleArmor.getBattleArmorWeaponsNEquipmentFont(g2d, false, maxHeight, equipmentLocations, 7.0f);
g2d.setFont(font);
stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
// linePoint -= stringHeight / 2;
lineFeed = stringHeight;
for (int pos = BattleArmor.LOC_SQUAD; pos <= BattleArmor.LOC_TROOPER_6; pos++) {
ArrayList<EquipmentInfo> equipmentList = equipmentLocations.get(pos);
if (equipmentList.size() < 1) {
continue;
}
boolean indented = false;
if ((pos != BattleArmor.LOC_SQUAD) && !hasNarcCompact && !hasMineLayer) {
String loc = ba.getLocationName(pos);
g2d.setFont(UnitUtil.getNewFont(g2d, loc, false, 68, font.getSize()));
g2d.drawString(loc, typePoint, linePoint);
g2d.setFont(font);
linePoint += lineFeed;
typePoint += 5;
indented = true;
}
Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
for (EquipmentInfo eqi : equipmentList) {
newLineNeeded = false;
String name = eqi.name.trim();
if (eqi.isBACargolifter) {
float tons = (numberOfGloves * 0.5f) / 2.0f;
name += " (" + Double.toString(tons) + " ton" + ((tons % 1) == 0 ? "" : "s ") + "lifting capability)";
} else if (eqi.isManipulator && (numberOfGloves > 1)) {
if (!eqi.isBACargolifter) {
name += " (2)";
}
}
g2d.setFont(UnitUtil.getNewFont(g2d, name, false, 88, font.getSize()));
if (eqi.c3Level == EquipmentInfo.C3I) {
ImageHelper.printBC3iName(g2d, typePoint, linePoint, font, false, ba.isMixedTech() && TechConstants.isClan(ba.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3S) {
ImageHelper.printBC3Name(g2d, typePoint, linePoint, font, false, ba.isMixedTech() && TechConstants.isClan(ba.getTechLevel()));
} else {
g2d.drawString(name, typePoint, linePoint);
}
// font = UnitUtil.deriveFont(7.0f);
g2d.setFont(font);
if (eqi.isWeapon) {
if (eqi.isMML) {
ImageHelper.printCenterString(g2d, "[M,S,C]", font, damagePoint, linePoint);
linePoint += lineFeed - 1.0f;
g2d.drawString("LRM", typePoint, linePoint);
ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
g2d.drawString("6", minPoint, linePoint);
g2d.drawString("7", shtPoint, linePoint);
g2d.drawString("14", medPoint, linePoint);
g2d.drawString("21", longPoint, linePoint);
linePoint += lineFeed - 1.0f;
g2d.drawString("SRM", typePoint, linePoint);
ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
g2d.drawString("\u2014", minPoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
g2d.drawString("3", shtPoint, linePoint);
g2d.drawString("6", medPoint, linePoint);
g2d.drawString("9", longPoint, linePoint);
} else if (eqi.isATM) {
ImageHelper.printCenterString(g2d, "[M,S,C]", font, damagePoint, linePoint);
linePoint += lineFeed - 1.0f;
g2d.drawString("Standard", typePoint, linePoint);
ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
g2d.drawString("4", minPoint, linePoint);
g2d.drawString("5", shtPoint, linePoint);
g2d.drawString("10", medPoint, linePoint);
g2d.drawString("15", longPoint, linePoint);
linePoint += lineFeed - 1.0f;
g2d.drawString("Extended-Range", typePoint, linePoint);
ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
g2d.drawString("4", minPoint, linePoint);
g2d.drawString("9", shtPoint, linePoint);
g2d.drawString("18", medPoint, linePoint);
g2d.drawString("27", longPoint, linePoint);
linePoint += lineFeed - 1.0f;
g2d.drawString("High-Explosive", typePoint, linePoint);
ImageHelper.printCenterString(g2d, "3/Msl", font, damagePoint, linePoint);
g2d.drawString("\u2014", minPoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
g2d.drawString("3", shtPoint, linePoint);
g2d.drawString("6", medPoint, linePoint);
g2d.drawString("9", longPoint, linePoint);
} else {
g2d.setFont(UnitUtil.getNewFont(g2d, eqi.damage, false, 30, font.getSize()));
ImageHelper.printCenterString(g2d, eqi.damage, g2d.getFont(), damagePoint, linePoint);
g2d.setFont(font);
if (eqi.minRange > 0) {
g2d.drawString(Integer.toString(eqi.minRange), minPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", minPoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
}
if (eqi.shtRange > 0) {
g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", shtPoint, linePoint);
// g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint + 6, (int) linePoint - 2);
}
if (eqi.medRange > 0) {
g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", medPoint, linePoint);
// g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
}
if (eqi.longRange > 0) {
g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
}
}
} else {
g2d.setFont(UnitUtil.getNewFont(g2d, eqi.damage, false, 30, font.getSize()));
ImageHelper.printCenterString(g2d, eqi.damage, g2d.getFont(), damagePoint, linePoint);
g2d.setFont(font);
if (eqi.minRange > 0) {
g2d.drawString(Integer.toString(eqi.minRange), minPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", minPoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
}
if (eqi.shtRange > 0) {
g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", shtPoint, linePoint);
// g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint + 6, (int) linePoint - 2);
}
if (eqi.medRange > 0) {
g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", medPoint, linePoint);
// g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
}
if (eqi.longRange > 0) {
g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
}
}
if (eqi.hasAmmo) {
if (!newLineNeeded) {
newLineNeeded = true;
}
StringBuilder ammoString = new StringBuilder("Ammo ");
if (eqi.isCompactNarc || eqi.isBAPopUpMine) {
for (int baPos = 0; baPos < ba.getNumberActiverTroopers(); baPos++) {
for (int ammoCount = 0; ammoCount < eqi.ammoCount; ammoCount++) {
ammoString.append("O ");
}
ammoString.append("/ ");
}
ammoString.setLength(ammoString.length() - 2);
} else {
for (int ammoCount = 1; ammoCount <= eqi.ammoCount; ammoCount++) {
ammoString.append("O ");
}
}
g2d.setFont(UnitUtil.getNewFont(g2d, ammoString.toString(), false, 138, font.getSize()));
g2d.drawString(ammoString.toString(), typePoint + 5, (int) (linePoint + lineFeed));
g2d.setFont(font);
}
if (eqi.isBAMineLayer) {
StringBuilder ammoString = new StringBuilder("Ammo ");
for (int baPos = 0; baPos < ba.getNumberActiverTroopers(); baPos++) {
ammoString.append("O O / ");
}
ammoString.setLength(ammoString.length() - 2);
g2d.setFont(UnitUtil.getNewFont(g2d, ammoString.toString(), false, 138, font.getSize()));
g2d.drawString(ammoString.toString(), typePoint + 5, (int) (linePoint + lineFeed));
g2d.setFont(font);
}
linePoint += lineFeed;
if (newLineNeeded) {
linePoint += lineFeed;
}
if (indented) {
typePoint -= 5;
}
}
}
if (ba.isBurdened() && ((ba.getJumpMP(false, true, true) > 0) || UnitUtil.canLegAttack(ba) || UnitUtil.canSwarm(ba))) {
String burdenInfo = "Must detach missiles before jumping or swarm/leg attacks.";
g2d.setFont(UnitUtil.getNewFont(g2d, burdenInfo, false, 175, 7.0f));
g2d.drawString(burdenInfo, typePoint, linePoint);
linePoint += lineFeed;
g2d.setFont(font);
}
if (ba.isExoskeleton() && !ba.hasWorkingMisc(MiscType.F_EXTENDED_LIFESUPPORT)) {
String exoInfo = "unsealed Exoskeleton";
g2d.setFont(UnitUtil.getNewFont(g2d, exoInfo, false, 175, 7.0f));
g2d.drawString(exoInfo, typePoint, linePoint);
linePoint += lineFeed;
g2d.setFont(font);
}
if (ba.hasDWP()) {
String burdenInfo;
if (ba.getJumpMP(true, true, true) > 0) {
burdenInfo = "Must detach DWP before jumping or moving full ground speed.";
} else {
burdenInfo = "Must detach DWP before moving full ground speed.";
}
g2d.setFont(UnitUtil.getNewFont(g2d, burdenInfo, false, 175, 7.0f));
g2d.drawString(burdenInfo, typePoint, linePoint);
linePoint += lineFeed;
g2d.setFont(font);
}
ImageHelperBattleArmor.printBAArmor(ba, g2d, lineFeed, offset);
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class CriticalTransferHandler method importData.
/**
*/
@Override
public boolean importData(TransferSupport info) {
if (!info.isDrop() || !((getUnit() instanceof Mech) || (getUnit() instanceof Aero) || (getUnit() instanceof BattleArmor))) {
return false;
}
int trooper = 0;
if (info.getComponent() instanceof DropTargetCriticalList) {
DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
if (getUnit() instanceof BattleArmor) {
String[] split = list.getName().split(":");
if (split.length != 2) {
return false;
}
location = Integer.parseInt(split[0]);
trooper = Integer.parseInt(split[1]);
} else {
location = Integer.parseInt(list.getName());
}
Transferable t = info.getTransferable();
int slotNumber = list.getDropLocation().getIndex();
try {
Mounted eq = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
if (getUnit() instanceof BattleArmor) {
if ((location == eq.getBaMountLoc()) && (trooper == eq.getLocation())) {
return false;
}
} else {
// the criticals its mounted in
if (eq.getLocation() != Entity.LOC_NONE || eq.getSecondLocation() != Entity.LOC_NONE) {
UnitUtil.removeCriticals(getUnit(), eq);
changeMountStatus(eq, Entity.LOC_NONE, false);
} else {
eq.setOmniPodMounted(UnitUtil.canPodMount(getUnit(), eq));
}
}
if (!UnitUtil.isValidLocation(getUnit(), eq.getType(), location)) {
JOptionPane.showMessageDialog(null, eq.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
return false;
}
if (getUnit() instanceof Aero) {
return addEquipmentAero((Aero) getUnit(), eq);
} else if (getUnit() instanceof Mech) {
// superheavies can put 2 ammobins or heatsinks in one crit
if ((getUnit() instanceof Mech) && ((Mech) getUnit()).isSuperHeavy()) {
CriticalSlot cs = getUnit().getCritical(location, slotNumber);
if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && (cs.getMount2() == null)) {
EquipmentType etype = cs.getMount().getType();
EquipmentType etype2 = eq.getType();
boolean canDouble = false;
if ((etype instanceof AmmoType) && (etype2 instanceof AmmoType)) {
canDouble = (((AmmoType) etype).getAmmoType() == ((AmmoType) etype2).getAmmoType()) && (((AmmoType) etype).getRackSize() == ((AmmoType) etype2).getRackSize());
} else if (etype.equals(etype2) && UnitUtil.isHeatSink(etype)) {
canDouble = etype.getCriticals(getUnit()) == 1;
}
if (canDouble) {
cs.setMount2(eq);
changeMountStatus(eq, location, false);
return true;
}
}
}
return addEquipmentMech((Mech) getUnit(), eq, slotNumber);
} else if (getUnit() instanceof BattleArmor) {
return addEquipmentBA((BattleArmor) getUnit(), eq, trooper);
}
} catch (LocationFullException lfe) {
JOptionPane.showMessageDialog(null, lfe.getMessage(), "Location Full", JOptionPane.INFORMATION_MESSAGE);
return false;
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
return false;
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class CriticalTransferHandler method addEquipmentAero.
/**
* @param aero
* @return
*/
private boolean addEquipmentAero(Aero aero, Mounted eq) throws LocationFullException {
if (eq.getType() instanceof WeaponType) {
int[] availSpace = TestAero.availableSpace(aero);
int[] weapCount = new int[aero.locations() - 1];
for (Mounted m : aero.getWeaponList()) {
if (m.getLocation() != Entity.LOC_NONE) {
weapCount[m.getLocation()]++;
}
}
if ((weapCount[location] + 1) > availSpace[location]) {
throw new LocationFullException(eq.getName() + " does not fit in " + getUnit().getLocationAbbr(location) + " on " + getUnit().getDisplayName());
} else {
UnitUtil.addMounted(getUnit(), eq, location, false);
}
} else {
UnitUtil.addMounted(getUnit(), eq, location, false);
}
changeMountStatus(eq, location, false);
return true;
}
Aggregations