use of megamek.common.AmmoType in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addToBay.
/**
* Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's
* weapon or ammo list if necessary.
*
* @param bay
* @param eq
*/
public void addToBay(@Nullable Mounted bay, Mounted eq) {
// Check that we have a bay
if ((null == bay) || !canTakeEquipment(bay, eq)) {
if (eq.getType() instanceof WeaponType) {
EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
addToNewBay(bayType, eq);
} else {
addToLocation(eq);
}
return;
} else if (eq.getType() instanceof MiscType) {
if (eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) {
for (Integer 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))) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
} else if (eq.getType().hasFlag(MiscType.F_APOLLO) || eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
if (weapon.getLinkedBy() == null) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
}
} else {
// there.
if (eq.getType() instanceof AmmoType) {
Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == eq.getType()).findFirst();
if (addMount.isPresent()) {
addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + eq.getBaseShotsLeft());
UnitUtil.removeMounted(eSource.getEntity(), eq);
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
return;
}
}
EquipmentNode bayNode = null;
for (Enumeration<?> e = ((TreeNode) model.getRoot()).children(); e.hasMoreElements(); ) {
final EquipmentNode node = (EquipmentNode) e.nextElement();
if (node.getMounted() == bay) {
bayNode = node;
break;
}
}
if (null != bayNode) {
moveToArc(eq);
EquipmentNode eqNode = new EquipmentNode(eq);
model.insertNodeInto(eqNode, bayNode, bayNode.getChildCount());
eqNode.setParent(bayNode);
if (eq.getType() instanceof WeaponType) {
bay.addWeaponToBay(eSource.getEntity().getEquipmentNum(eq));
if (eq.getLinkedBy() != null) {
moveToArc(eq.getLinkedBy());
}
} else if (eq.getType() instanceof AmmoType) {
bay.addAmmoToBay(eSource.getEntity().getEquipmentNum(eq));
}
} else {
// $NON-NLS-1$
MegaMekLab.getLogger().log(// $NON-NLS-1$
BayWeaponCriticalTree.class, // $NON-NLS-1$
"addToBay(Mounted,Mounted)", LogLevel.DEBUG, // $NON-NLS-1$
bay.getName() + "[" + eSource.getEntity().getEquipmentNum(bay) + "] not found in " + // $NON-NLS-1$
getLocationName());
}
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
use of megamek.common.AmmoType in project megameklab by MegaMek.
the class PrintMech method writeEquipment.
@Override
protected void writeEquipment(SVGRectElement svgRect) {
Map<Integer, Map<RecordSheetEquipmentLine, Integer>> eqMap = new TreeMap<>();
Map<String, Integer> ammo = new TreeMap<>();
for (Mounted m : mech.getEquipment()) {
if ((m.getType() instanceof AmmoType) && (((AmmoType) m.getType()).getAmmoType() != AmmoType.T_COOLANT_POD)) {
if (m.getLocation() != Entity.LOC_NONE) {
String shortName = m.getType().getShortName().replace("Ammo", "");
shortName = shortName.replace("(Clan)", "");
String munition = ((AmmoType) m.getType()).getSubMunitionName().replace("(Clan) ", "");
shortName = shortName.replace(munition, "");
ammo.merge(shortName.trim(), m.getBaseShotsLeft(), Integer::sum);
}
continue;
}
if ((m.getType() instanceof AmmoType) || (m.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(m.getType(), true)) {
continue;
}
if (mech.hasETypeFlag(Entity.ETYPE_QUADVEE) && (m.getType() instanceof MiscType) && m.getType().hasFlag(MiscType.F_TRACKS)) {
continue;
}
eqMap.putIfAbsent(m.getLocation(), new HashMap<>());
RecordSheetEquipmentLine line = new RecordSheetEquipmentLine(m);
eqMap.get(m.getLocation()).merge(line, 1, Integer::sum);
}
Rectangle2D bbox = getRectBBox(svgRect);
Element canvas = (Element) ((Node) svgRect).getParentNode();
int viewWidth = (int) bbox.getWidth();
int viewHeight = (int) bbox.getHeight();
int viewX = (int) bbox.getX();
int viewY = (int) bbox.getY();
int qtyX = (int) Math.round(viewX + viewWidth * 0.037);
int nameX = (int) Math.round(viewX + viewWidth * 0.08);
int locX = (int) Math.round(viewX + viewWidth * 0.41);
int heatX = (int) Math.round(viewX + viewWidth * 0.48);
int dmgX = (int) Math.round(viewX + viewWidth * 0.53);
int minX = (int) Math.round(viewX + viewWidth * 0.75);
int shortX = (int) Math.round(viewX + viewWidth * 0.82);
int medX = (int) Math.round(viewX + viewWidth * 0.89);
int longX = (int) Math.round(viewX + viewWidth * 0.96);
int indent = (int) Math.round(viewWidth * 0.02);
int currY = viewY + 10;
float fontSize = FONT_SIZE_MEDIUM;
float lineHeight = getFontHeight(fontSize) * 0.8f;
addTextElement(canvas, qtyX, currY, "Qty", fontSize, "middle", "bold");
addTextElement(canvas, nameX + indent, currY, "Type", fontSize, "start", "bold");
addTextElement(canvas, locX, currY, "Loc", fontSize, "middle", "bold");
addTextElement(canvas, heatX, currY, "Ht", fontSize, "middle", "bold");
addTextElement(canvas, dmgX, currY, "Dmg", fontSize, "start", "bold");
addTextElement(canvas, minX, currY, "Min", fontSize, "middle", "bold");
addTextElement(canvas, shortX, currY, "Sht", fontSize, "middle", "bold");
addTextElement(canvas, medX, currY, "Med", fontSize, "middle", "bold");
addTextElement(canvas, longX, currY, "Lng", fontSize, "middle", "bold");
currY += lineHeight * 1.2;
int lines = 0;
for (Integer loc : eqMap.keySet()) {
for (RecordSheetEquipmentLine line : eqMap.get(loc).keySet()) {
int rows = line.nRows();
if ((rows == 1) && (getTextLength(line.getNameField(0, mech.isMixedTech()), fontSize) > locX - nameX)) {
rows++;
}
lines += rows;
}
}
if (lines > 12) {
lineHeight = getFontHeight(fontSize) * 0.8f;
}
if (lines > 16) {
fontSize = FONT_SIZE_SMALL;
}
if (lines > 20) {
fontSize = FONT_SIZE_VSMALL;
}
for (Integer loc : eqMap.keySet()) {
for (RecordSheetEquipmentLine line : eqMap.get(loc).keySet()) {
for (int row = 0; row < line.nRows(); row++) {
if (row == 0) {
addTextElement(canvas, qtyX, currY, Integer.toString(eqMap.get(loc).get(line)), fontSize, "middle", "normal");
lines = addMultilineTextElement(canvas, nameX, currY, locX - nameX - indent, lineHeight, line.getNameField(row, mech.isMixedTech()), fontSize, "start", "normal");
} else {
lines = addMultilineTextElement(canvas, nameX + indent, currY, locX - nameX - indent, lineHeight, line.getNameField(row, mech.isMixedTech()), fontSize, "start", "normal");
}
addTextElement(canvas, locX, currY, line.getLocationField(row), fontSize, "middle", "normal");
addTextElement(canvas, heatX, currY, line.getHeatField(row), fontSize, "middle", "normal");
lines = Math.max(lines, addMultilineTextElement(canvas, dmgX, currY, minX - dmgX, lineHeight, line.getDamageField(row), fontSize, "start", "normal"));
addTextElement(canvas, minX, currY, line.getMinField(row), fontSize, "middle", "normal");
addTextElement(canvas, shortX, currY, line.getShortField(row), fontSize, "middle", "normal");
addTextElement(canvas, medX, currY, line.getMediumField(row), fontSize, "middle", "normal");
addTextElement(canvas, longX, currY, line.getLongField(row), fontSize, "middle", "normal");
currY += lineHeight * lines;
}
}
}
StringJoiner quirksList = new StringJoiner(", ");
Quirks quirks = mech.getQuirks();
for (Enumeration<IOptionGroup> optionGroups = quirks.getGroups(); optionGroups.hasMoreElements(); ) {
IOptionGroup optiongroup = optionGroups.nextElement();
if (quirks.count(optiongroup.getKey()) > 0) {
for (Enumeration<IOption> options = optiongroup.getOptions(); options.hasMoreElements(); ) {
IOption option = options.nextElement();
if (option != null && option.booleanValue()) {
quirksList.add(option.getDisplayableNameWithValue());
}
}
}
}
if ((ammo.size() > 0) || (quirksList.length() > 0)) {
Element svgGroup = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
canvas.appendChild(svgGroup);
lines = 0;
if (ammo.size() > 0) {
lines = addMultilineTextElement(svgGroup, viewX + viewWidth * 0.025, 0, viewWidth * 0.95, lineHeight, "Ammo: " + ammo.entrySet().stream().map(e -> String.format("(%s) %d", e.getKey(), e.getValue())).collect(Collectors.joining(", ")), fontSize, "start", "normal");
}
if (quirksList.length() > 0) {
lines += addMultilineTextElement(svgGroup, viewX + viewWidth * 0.025, lines * lineHeight, viewWidth * 0.95, lineHeight, "Quirks: " + quirksList.toString(), fontSize, "start", "normal");
}
svgGroup.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, String.format("translate(0,%f)", viewY + viewHeight - lines * lineHeight));
}
}
use of megamek.common.AmmoType 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.AmmoType 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.AmmoType in project megameklab by MegaMek.
the class EquipmentTableModel method getValueAt.
public Object getValueAt(int row, int col) {
EquipmentType type;
WeaponType wtype = null;
AmmoType atype = null;
MiscType mtype = null;
if (data.isEmpty()) {
return "";
} else {
type = data.get(row);
}
if (type instanceof WeaponType) {
wtype = (WeaponType) type;
}
if (type instanceof AmmoType) {
atype = (AmmoType) type;
}
if (type instanceof MiscType) {
mtype = (MiscType) type;
}
DecimalFormat formatter = new DecimalFormat();
if (col == COL_NAME) {
return UnitUtil.trimInfantryWeaponNames(type.getName());
} else if (col == COL_DAMAGE) {
if (null != wtype) {
return getDamageString(wtype, entity instanceof Aero);
} else {
return "-";
}
} else if (col == COL_DIVISOR) {
if (mtype != null && mtype.hasFlag(MiscType.F_ARMOR_KIT)) {
if ((mtype.getSubType() & MiscType.S_ENCUMBERING) == 0) {
return String.valueOf(mtype.getDamageDivisor());
} else {
return mtype.getDamageDivisor() + "E";
}
} else {
return "-";
}
} else if (col == COL_SPECIAL) {
String special = "";
if (type instanceof InfantryWeapon) {
if (type.hasFlag(WeaponType.F_INF_POINT_BLANK)) {
special += "(P)";
}
if (type.hasFlag(WeaponType.F_INF_AA)) {
special += "A";
}
if (type.hasFlag(WeaponType.F_INF_BURST)) {
special += "B";
}
if (type.hasFlag(WeaponType.F_INF_NONPENETRATING)) {
special += "N";
}
if (type.hasFlag(WeaponType.F_PLASMA) || type.hasFlag(WeaponType.F_INCENDIARY_NEEDLES) || type.hasFlag(WeaponType.F_INFERNO)) {
special += "F";
}
}
if (type.hasFlag(MiscType.F_ARMOR_KIT)) {
if ((type.getSubType() & MiscType.S_DEST) != 0) {
special += "DEST ";
}
if ((type.getSubType() & MiscType.S_SNEAK_CAMO) != 0) {
special += "Camo ";
}
if ((type.getSubType() & MiscType.S_SNEAK_IR) != 0) {
special += "IR ";
}
if ((type.getSubType() & MiscType.S_SNEAK_ECM) != 0) {
special += "ECM ";
}
if ((type.getSubType() & MiscType.S_SPACE_SUIT) != 0) {
special += "SPC ";
}
}
return special;
} else if (col == COL_CREW) {
String special = "";
if (type instanceof InfantryWeapon) {
special += Integer.toString(((InfantryWeapon) type).getCrew());
if (type.hasFlag(WeaponType.F_INF_ENCUMBER)) {
special += "E";
}
} else if (type instanceof WeaponType) {
// Field gun crew size
special += Math.max(2, (int) Math.ceil(type.getTonnage(entity)));
}
return special;
} else if (col == COL_HEAT) {
if (null != wtype) {
if (entity instanceof Aero) {
return Integer.toString(wtype.getHeat() * Mounted.getNumShots(wtype, null, true));
} else {
return Integer.toString(wtype.getHeat());
}
} else {
return "-";
}
} else if (col == COL_SHOTS) {
if (null != atype) {
return Integer.toString(atype.getShots());
} else {
return "-";
}
} else if (col == COL_RANGE) {
if (null != wtype) {
if (entity instanceof Aero) {
switch(wtype.maxRange) {
case RangeType.RANGE_SHORT:
return "Short";
case RangeType.RANGE_MEDIUM:
return "Medium";
case RangeType.RANGE_LONG:
return "Long";
case RangeType.RANGE_EXTREME:
return "Extreme";
}
;
}
if (wtype instanceof InfantryWeapon) {
return ((InfantryWeapon) wtype).getInfantryRange() + "";
}
return wtype.getShortRange() + "/" + wtype.getMediumRange() + "/" + wtype.getLongRange();
} else {
return "-";
}
} else if (col == COL_MRANGE) {
if (null != wtype) {
if (entity instanceof Aero) {
return "-";
}
int minRange = wtype.getMinimumRange();
if (minRange < 0) {
minRange = 0;
}
return Integer.toString(minRange);
} else {
return "-";
}
} else if (col == COL_TON) {
if ((entity instanceof BattleArmor) && (atype != null)) {
return (atype.getKgPerShot() * atype.getShots()) / 1000;
} else {
return type.getTonnage(entity);
}
} else if (col == COL_CRIT) {
if (entity instanceof Tank) {
return type.getTankslots(entity);
}
return type.getCriticals(entity);
} else if (col == COL_TRATING) {
return type.getFullRatingName(entity.isClan());
} else if (col == COL_COST) {
return formatter.format(type.getCost(entity, false, Entity.LOC_NONE));
} else if (col == COL_BV) {
return type.getBV(entity);
} else if (col == COL_DPROTOTYPE) {
return entity.isMixedTech() ? type.getTechAdvancement().getPrototypeDateName() : type.getTechAdvancement().getPrototypeDateName(entity.isClan());
} else if (col == COL_DPRODUCTION) {
return entity.isMixedTech() ? type.getTechAdvancement().getProductionDateName() : type.getTechAdvancement().getProductionDateName(entity.isClan());
} else if (col == COL_DCOMMON) {
return entity.isMixedTech() ? type.getTechAdvancement().getCommonDateName() : type.getTechAdvancement().getCommonDateName(entity.isClan());
} else if (col == COL_DEXTINCT) {
return entity.isMixedTech() ? type.getTechAdvancement().getExtinctionDateName() : type.getTechAdvancement().getExtinctionDateName(entity.isClan());
} else if (col == COL_DREINTRO) {
return entity.isMixedTech() ? type.getTechAdvancement().getReintroductionDateName() : type.getTechAdvancement().getReintroductionDateName(entity.isClan());
} else if (col == COL_TLEVEL) {
if ((null != techManager) && CConfig.getBooleanParam(CConfig.TECH_PROGRESSION)) {
return type.getSimpleLevel(techManager.getGameYear(), techManager.useClanTechBase(), techManager.getTechFaction()).toString();
} else {
return type.getStaticTechLevel().toString();
}
} else if (col == COL_TECH) {
switch(type.getTechBase()) {
case TechAdvancement.TECH_BASE_ALL:
return "All";
case TechAdvancement.TECH_BASE_IS:
return "IS";
case TechAdvancement.TECH_BASE_CLAN:
return "Clan";
}
} else if (col == COL_REF) {
return type.getRulesRefs();
}
return "?";
}
Aggregations