use of megamek.common.AmmoType in project megameklab by MegaMek.
the class ImageHelper method printMechWeaponsNEquipment.
public static void printMechWeaponsNEquipment(Mech mech, Graphics2D g2d, int leftMargin, int topMargin) {
int qtyPoint = 26 + leftMargin;
int typePoint = 38 + leftMargin;
int locPoint = 105 + leftMargin;
int heatPoint = 118 + leftMargin;
int damagePoint = 145 + leftMargin;
int minPoint = 167 + leftMargin;
int shtPoint = 183 + leftMargin;
int medPoint = 199 + leftMargin;
int longPoint = 215 + leftMargin;
float linePoint = 202f + topMargin;
float lineFeed = 6.7f;
boolean newLineNeeded = false;
ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(Mech.LOC_LLEG + 1);
for (int pos = 0; pos <= Mech.LOC_LLEG; pos++) {
equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
}
for (Mounted eq : mech.getEquipment()) {
if ((eq.getType() instanceof AmmoType) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType(), true)) {
continue;
}
Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
String equipmentName = eq.getName();
if (eq.isRearMounted()) {
equipmentName += " (R)";
}
if (eq.isMechTurretMounted()) {
equipmentName += " (T)";
}
if (eqHash.containsKey(equipmentName)) {
EquipmentInfo eqi = eqHash.get(equipmentName);
if (eq.getType().getTechLevel(mech.getTechLevelYear()) != eqi.techLevel) {
eqi = new EquipmentInfo(mech, eq);
} else {
eqi.count++;
}
eqHash.put(equipmentName, eqi);
} else {
EquipmentInfo eqi = new EquipmentInfo(mech, eq);
eqHash.put(equipmentName, eqi);
}
}
Font font = UnitUtil.deriveFont(true, 10.0f);
g2d.setFont(font);
HashMap<TextAttribute, Object> strikeThroughAttr = new HashMap<TextAttribute, Object>();
strikeThroughAttr.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
for (int pos = Mech.LOC_HEAD; pos <= Mech.LOC_LLEG; pos++) {
Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
if (eqHash.size() < 1) {
continue;
}
int count = 0;
ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
for (EquipmentInfo eqi : eqHash.values()) {
equipmentList.add(eqi);
}
Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
for (EquipmentInfo eqi : equipmentList) {
newLineNeeded = false;
if (count >= 12) {
break;
}
font = UnitUtil.deriveFont(7.0f);
g2d.setFont(font);
g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
String name = eqi.name.trim();
Font nameFont = UnitUtil.getNewFont(g2d, name, false, 60, 7.0f);
if (eqi.isDestroyed) {
nameFont = nameFont.deriveFont(strikeThroughAttr);
}
g2d.setFont(nameFont);
if (eqi.c3Level == EquipmentInfo.C3I) {
ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3EM) {
ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3S) {
ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3M) {
ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3SB) {
ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3MB) {
ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
} else {
g2d.drawString(name, typePoint, linePoint);
}
Font locFont = UnitUtil.getNewFont(g2d, eqi.loc, false, 15, 7.0f);
g2d.setFont(locFont);
ImageHelper.printCenterString(g2d, eqi.loc, font, locPoint, linePoint);
g2d.setFont(UnitUtil.deriveFont(7));
if (eqi.isWeapon) {
g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
if (eqi.isMML) {
ImageHelper.printCenterString(g2d, "[M,C,S]", 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,C,S]", 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 if (eqi.isAMS) {
ImageHelper.printCenterString(g2d, "\u2014 [PD]", font, damagePoint, linePoint);
// g2d.drawLine(damagePoint - 9, (int) linePoint - 2,
// damagePoint - 3, (int) linePoint - 2);
// ImageHelper.printCenterString(g2d, "[PD]", font,
// damagePoint+4, linePoint);
g2d.drawString("\u2014", minPoint, linePoint);
g2d.drawString("\u2014", shtPoint, linePoint);
g2d.drawString("\u2014", medPoint, linePoint);
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
// + 6, (int) linePoint - 2);
// g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint
// + 6, (int) linePoint - 2);
// g2d.drawLine(medPoint, (int) linePoint - 2, medPoint
// + 6, (int) linePoint - 2);
// g2d.drawLine(longPoint, (int) linePoint - 2,
// longPoint + 6, (int) linePoint - 2);
} else if (eqi.isCenturion) {
ImageHelper.printCenterString(g2d, "0", font, damagePoint, linePoint);
// g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
// + 6, (int) linePoint - 2);
g2d.drawString("\u2014", minPoint, linePoint);
g2d.drawString("6(1)", shtPoint - 1, linePoint);
g2d.drawString("12(2)", medPoint - 6, linePoint);
g2d.drawString("18(3)", longPoint - 4, linePoint);
} else {
if (ImageHelper.getStringWidth(g2d, eqi.damage.trim(), font) > 22) {
font = UnitUtil.deriveFont(6.0f);
g2d.setFont(font);
ImageHelper.printCenterString(g2d, eqi.damage.substring(0, eqi.damage.indexOf('[')), font, damagePoint, linePoint);
font = UnitUtil.deriveFont(7.0f);
g2d.setFont(font);
ImageHelper.printCenterString(g2d, eqi.damage.substring(eqi.damage.indexOf('[')), font, damagePoint, (linePoint + lineFeed) - 1.0f);
newLineNeeded = true;
} else {
ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint, linePoint);
}
if (eqi.minRange > 0) {
g2d.drawString(Integer.toString(eqi.minRange), minPoint, 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, 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, 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, linePoint);
} else {
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(longPoint, (int) linePoint - 2,
// longPoint + 6, (int) linePoint - 2);
}
}
} else {
if (eqi.heat > 0) {
g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
} else {
g2d.drawString("\u2014", heatPoint, linePoint);
// g2d.drawLine(heatPoint, (int) linePoint - 2,
// heatPoint + 6, (int) linePoint - 2);
}
ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint - 2, linePoint);
g2d.drawString("\u2014", minPoint, linePoint);
g2d.drawString("\u2014", shtPoint, linePoint);
g2d.drawString("\u2014", medPoint, linePoint);
// (int) linePoint - 2);
if (eqi.longRange > 0) {
g2d.drawString(Integer.toString(eqi.longRange), longPoint, linePoint);
} else {
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(longPoint, (int) linePoint - 2,
// longPoint + 6, (int) linePoint - 2);
}
}
if (eqi.hasArtemis) {
g2d.drawString("w/Artemis IV FCS", typePoint, linePoint + lineFeed);
newLineNeeded = true;
} else if (eqi.hasArtemisV) {
g2d.drawString("w/Artemis V FCS", typePoint, linePoint + lineFeed);
newLineNeeded = true;
} else if (eqi.hasApollo) {
g2d.drawString("w/Apollo FCS", typePoint, linePoint + lineFeed);
newLineNeeded = true;
}
linePoint += lineFeed;
if (newLineNeeded) {
linePoint += lineFeed;
}
count++;
}
}
if (mech instanceof LandAirMech) {
ImageHelper.printLAMFuel((LandAirMech) mech, g2d, qtyPoint);
}
}
use of megamek.common.AmmoType in project megameklab by MegaMek.
the class BuildView method loadEquipmentTable.
private void loadEquipmentTable() {
equipmentList.removeAllCrits();
masterEquipmentList.clear();
for (Mounted mount : getBattleArmor().getMisc()) {
if ((mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE && !mount.getType().hasFlag(MiscType.F_BA_MANIPULATOR) && !mount.getName().contains("BA Standard"))) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getBattleArmor().getWeaponList()) {
// Don't display weapons mounted in a detachable weapon pack
if (mount.isDWPMounted() || mount.isAPMMounted()) {
continue;
}
if ((mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) && (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType()))) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getBattleArmor().getAmmo()) {
// Ignore ammo for one-shot launchers
if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
continue;
}
// Ignore DWP-mounted ammo
if (mount.isDWPMounted()) {
continue;
}
if (mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
masterEquipmentList.add(mount);
}
}
Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
// Jump Jets
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isJumpJet(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// weapons and ammo
Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
weaponsNAmmoList.add(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
for (Mounted mount : weaponsNAmmoList) {
equipmentList.addCrit(mount);
}
// Equipment
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// armor
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (UnitUtil.isArmor(masterEquipmentList.get(pos).getType())) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// everything else
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
equipmentList.addCrit(masterEquipmentList.get(pos));
}
}
use of megamek.common.AmmoType in project megameklab by MegaMek.
the class AerospaceBuildView method loadEquipmentTable.
private void loadEquipmentTable() {
equipmentList.removeAllCrits();
masterEquipmentList.clear();
for (Mounted mount : getAero().getMisc()) {
if (mount.getLocation() == Entity.LOC_NONE) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getAero().getTotalWeaponList()) {
if (mount.getLocation() == Entity.LOC_NONE) {
masterEquipmentList.add(mount);
}
}
for (Mounted mount : getAero().getAmmo()) {
if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
masterEquipmentList.add(mount);
}
}
Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
// weapons and ammo
Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
weaponsNAmmoList.add(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
for (Mounted mount : weaponsNAmmoList) {
equipmentList.addCrit(mount);
}
// Equipment
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
if (masterEquipmentList.get(pos).getType() instanceof MiscType) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
// everything else
for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
equipmentList.addCrit(masterEquipmentList.get(pos));
masterEquipmentList.remove(pos);
pos--;
}
}
use of megamek.common.AmmoType in project megameklab by MegaMek.
the class AerospaceBuildView method mousePressed.
public void mousePressed(MouseEvent e) {
// locations, but only if those locations are make sense
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu popup = new JPopupMenu();
JMenuItem item = null;
if (equipmentTable.getSelectedRowCount() > 1) {
List<Mounted> list = new ArrayList<>();
for (int row : equipmentTable.getSelectedRows()) {
list.add((Mounted) equipmentTable.getModel().getValueAt(row, CriticalTableModel.EQUIPMENT));
}
for (BayWeaponCriticalTree l : arcViews) {
// Aerodyne small craft and dropships skip the aft side arcs
if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
continue;
}
if (list.stream().anyMatch(eq -> l.canAdd(eq))) {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(list));
popup.add(item);
}
}
} else {
final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
for (BayWeaponCriticalTree l : arcViews) {
// Aerodyne small craft and dropships skip the aft side arcs
if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
continue;
}
if (getAero().usesWeaponBays()) {
JMenu menu = new JMenu(l.getLocationName());
for (Mounted bay : l.baysFor(eq)) {
if (eq.getType() instanceof AmmoType) {
final int shotCount = ((AmmoType) eq.getType()).getShots();
JMenu locMenu = new JMenu(bay.getName());
for (int shots = shotCount; shots <= eq.getUsableShotsLeft(); shots += shotCount) {
item = new JMenuItem("Add " + shots + ((shots > 1) ? " shots" : " shot"));
final int addShots = shots;
item.addActionListener(ev -> l.addAmmoToBay(bay, eq, addShots));
locMenu.add(item);
}
menu.add(locMenu);
} else {
item = new JMenuItem(bay.getName());
item.addActionListener(ev -> l.addToBay(bay, eq));
menu.add(item);
}
}
if (eq.getType() instanceof WeaponType) {
final EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
item = new JMenuItem("New " + bayType.getName());
item.addActionListener(ev -> l.addToNewBay(bayType, eq));
menu.add(item);
}
if (menu.getItemCount() > 0) {
popup.add(menu);
} else if ((eq.getType() instanceof MiscType) && l.canAdd(eq)) {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(eq));
popup.add(item);
}
} else {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(eq));
popup.add(item);
}
}
}
popup.show(this, e.getX(), e.getY());
}
}
use of megamek.common.AmmoType in project megameklab by MegaMek.
the class PrintInfantry method printImage.
public void printImage(Graphics2D g2d, PageFormat pageFormat) {
if ((null == g2d) || (null == infantry)) {
return;
}
SVGDiagram diagram;
int stop = Math.min(4, infantryList.size() - currentPosition);
if (stop > 3) {
diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_no_tables.svg"));
} else {
diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_tables.svg"));
}
try {
Tspan tspan = (Tspan) diagram.getElement("text_copyright");
tspan.setText(String.format(tspan.getText(), Calendar.getInstance().get(Calendar.YEAR)));
((Text) tspan.getParent()).rebuild();
diagram.render(g2d);
for (int pos = 0; pos < stop; pos++) {
diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_platoon_" + (pos + 1) + ".svg"));
infantry = infantryList.get(pos + currentPosition);
tspan = (Tspan) diagram.getElement(ID_PLATOON_NAME);
String name = infantry.getChassis();
if (infantry.getModel().length() > 0) {
name += " " + infantry.getModel();
}
if (name.length() > 48) {
tspan.setText(infantry.getChassis());
} else {
tspan.setText(name);
}
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_ARMOR_KIT);
EquipmentType armor = infantry.getArmorKit();
if (armor != null) {
tspan.setText(armor.getName());
((Text) tspan.getParent()).rebuild();
} else if (infantry.hasDEST()) {
tspan.setText("DEST");
((Text) tspan.getParent()).rebuild();
} else {
StringJoiner sj = new StringJoiner("/");
if (infantry.hasSneakCamo()) {
sj.add("Camo");
}
if (infantry.hasSneakIR()) {
sj.add("IR");
}
if (infantry.hasSneakECM()) {
sj.add("ECM");
}
if (sj.length() > 0) {
tspan.setText("Sneak(" + sj.toString() + ")");
((Text) tspan.getParent()).rebuild();
}
}
tspan = (Tspan) diagram.getElement(ID_ARMOR_DIVISOR);
tspan.setText(String.valueOf(infantry.getDamageDivisor() + (infantry.isArmorEncumbering() ? "E" : "")));
((Text) tspan.getParent()).rebuild();
for (int j = 1; j <= 30; j++) {
if (j > infantry.getShootingStrength()) {
diagram.getElement(ID_SOLDIER + j).addAttribute("display", AnimationElement.AT_XML, "none");
diagram.getElement(ID_NO_SOLDIER + j).removeAttribute("display", AnimationElement.AT_XML);
} else {
tspan = (Tspan) diagram.getElement(ID_DAMAGE + j);
tspan.setText(String.valueOf((int) Math.round(infantry.getDamagePerTrooper() * j)));
((Text) tspan.getParent()).rebuild();
}
}
diagram.updateTime(0);
InfantryWeapon rangeWeapon = infantry.getPrimaryWeapon();
if (infantry.getSecondaryWeapon() != null && infantry.getSecondaryN() > 1 && !infantry.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
rangeWeapon = infantry.getSecondaryWeapon();
}
boolean scuba = infantry.getMovementMode() == EntityMovementMode.INF_UMU || infantry.getMovementMode() == EntityMovementMode.SUBMARINE;
if (scuba) {
diagram.getElement(ID_UW_LABEL).removeAttribute("display", AnimationElement.AT_XML);
}
InfantryWeapon singleSecondary = (infantry.getSecondaryN() == 1) ? infantry.getSecondaryWeapon() : null;
for (int j = 0; j <= 21; j++) {
tspan = (Tspan) diagram.getElement(ID_RANGE_MOD + j);
tspan.setText(rangeMod(j, rangeWeapon, singleSecondary, false));
if (scuba) {
tspan = (Tspan) diagram.getElement(ID_UW_RANGE_MOD + j);
tspan.setText(rangeMod(j, rangeWeapon, singleSecondary, true));
}
((Text) tspan.getParent()).rebuild();
}
int numGuns = 0;
int numShots = 0;
WeaponType gun = null;
for (Mounted m : infantry.getEquipment()) {
if (m.getLocation() == Infantry.LOC_FIELD_GUNS) {
if (m.getType() instanceof WeaponType) {
gun = (WeaponType) m.getType();
numGuns++;
} else if (m.getType() instanceof AmmoType) {
numShots += ((AmmoType) m.getType()).getShots();
}
}
}
if (gun == null) {
diagram.getElement(ID_FIELD_GUN_COLUMNS).addAttribute("display", AnimationElement.AT_XML, "none");
} else {
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_QTY);
tspan.setText(Integer.toString(numGuns));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_TYPE);
tspan.setText(gun.getName());
((Text) tspan.getParent()).rebuild();
/* We don't use StringUnits.getEquipmentInfo() to format the damage
* string because gauss explosion flags do not apply, and switchable
* only applies for non-LBX.
*/
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_DMG);
if (gun instanceof ArtilleryWeapon) {
tspan.setText(gun.getRackSize() + " [AE,S,F]");
} else {
StringBuilder sb = new StringBuilder(Integer.toString(gun.getDamage()));
switch(gun.getAmmoType()) {
case AmmoType.T_AC_ULTRA:
case AmmoType.T_AC_ULTRA_THB:
sb.append("/Sht, R2 [DB,R/S/C]");
break;
case AmmoType.T_AC_ROTARY:
sb.append("/Sht, R6 [DB,R/S/C]");
break;
case AmmoType.T_AC:
case AmmoType.T_AC_PRIMITIVE:
case AmmoType.T_LAC:
sb.append(" [DB,C/S/F]");
break;
case AmmoType.T_AC_LBX:
case AmmoType.T_AC_LBX_THB:
sb.append(" [DB,C/F]");
break;
default:
sb.append(" [DB]");
}
tspan.setText(sb.toString());
}
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_MIN_RANGE);
if (gun.getMinimumRange() > 0) {
tspan.setText(Integer.toString(gun.getMinimumRange()));
} else {
tspan.setText("—");
}
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_SHORT);
tspan.setText(Integer.toString(gun.getShortRange()));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_MED);
tspan.setText(Integer.toString(gun.getMediumRange()));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_LONG);
tspan.setText(Integer.toString(gun.getLongRange()));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_AMMO);
tspan.setText(Integer.toString(numShots));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_CREW);
tspan.setText(Integer.toString((int) Math.ceil(gun.getTonnage(infantry))));
((Text) tspan.getParent()).rebuild();
}
if (infantry.hasDEST()) {
diagram.getElement(ID_DEST_MODS).removeAttribute("display", AnimationElement.AT_XML);
diagram.getElement(ID_SNEAK_IR_MODS).removeAttribute("display", AnimationElement.AT_XML);
} else if (infantry.hasSneakCamo()) {
diagram.getElement(ID_SNEAK_CAMO_MODS).removeAttribute("display", AnimationElement.AT_XML);
}
if (infantry.hasSneakIR()) {
diagram.getElement(ID_SNEAK_IR_MODS).removeAttribute("display", AnimationElement.AT_XML);
}
tspan = (Tspan) diagram.getElement(ID_BV);
tspan.setText(Integer.toString(infantry.calculateBattleValue()));
((Text) tspan.getParent()).rebuild();
tspan = (Tspan) diagram.getElement(ID_TRANSPORT_WT);
tspan.setText(String.format("%.1f tons", infantry.getWeight()));
((Text) tspan.getParent()).rebuild();
Tspan mp1 = (Tspan) diagram.getElement(ID_MP_1);
Tspan mode1 = (Tspan) diagram.getElement(ID_MODE_1);
Tspan mp2 = (Tspan) diagram.getElement(ID_MP_2);
Tspan mode2 = (Tspan) diagram.getElement(ID_MODE_2);
switch(infantry.getMovementMode()) {
case INF_JUMP:
mp1.setText(Integer.toString(infantry.getJumpMP(false)));
mode1.setText("Jump");
mp2.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode2.setText("Ground");
((Text) mp2.getParent()).rebuild();
((Text) mode2.getParent()).rebuild();
break;
case INF_UMU:
mp1.setText(Integer.toString(infantry.getActiveUMUCount()));
if (infantry.getOriginalJumpMP() > 1) {
mode1.setText("SCUBA (Motorized)");
} else {
mode1.setText("SCUBA");
}
mp2.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode2.setText("Ground");
((Text) mp2.getParent()).rebuild();
((Text) mode2.getParent()).rebuild();
break;
case HOVER:
mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode1.setText("Mechanized Hover");
break;
case TRACKED:
mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode1.setText("Mechanized Tracked");
break;
case WHEELED:
mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode1.setText("Mechanized Wheeled");
break;
case VTOL:
mp1.setText(Integer.toString(infantry.getJumpMP(false)));
if (infantry.hasMicrolite()) {
mode1.setText("VTOL (Microlite)");
} else {
mode1.setText("VTOL (Micro-copter)");
}
break;
case SUBMARINE:
mp1.setText(Integer.toString(infantry.getActiveUMUCount()));
mode1.setText("Mechanized SCUBA");
break;
case INF_MOTORIZED:
mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode1.setText("Motorized");
break;
case INF_LEG:
default:
mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
mode1.setText("Ground");
break;
}
if (mp1.getText().equals("0")) {
mp1.setText("0*");
}
((Text) mp1.getParent()).rebuild();
((Text) mode1.getParent()).rebuild();
List<String> notes = new ArrayList<>();
if (infantry.isMechanized() || infantry.isArmorEncumbering()) {
notes.add("Cannot make anti-'Mech attacks.");
}
if (infantry.hasSpaceSuit()) {
notes.add("Can operate in vacuum.");
}
if (rangeWeapon.hasFlag(WeaponType.F_INF_BURST)) {
notes.add("+1D6 damage vs. conventional infantry.");
}
if (rangeWeapon.hasFlag(WeaponType.F_INF_NONPENETRATING)) {
notes.add("Can only damage conventional infantry.");
}
if (infantry.getPrimaryWeapon().hasFlag(WeaponType.F_INFERNO) || (infantry.getSecondaryWeapon() != null && infantry.getSecondaryWeapon().hasFlag(WeaponType.F_INFERNO))) {
notes.add("Flame-based weapon.");
} else {
for (int i = 0; i < infantry.getPrimaryWeapon().getModesCount(); i++) {
if (infantry.getPrimaryWeapon().getMode(i).equals("Heat")) {
notes.add("Flame-based weapon.");
break;
}
}
if (infantry.getSecondaryWeapon() != null) {
for (int i = 0; i < infantry.getSecondaryWeapon().getModesCount(); i++) {
if (infantry.getSecondaryWeapon().getMode(i).equals("Heat")) {
notes.add("Flame-based weapon.");
}
}
}
}
if (infantry.getPrimaryWeapon().hasFlag(WeaponType.F_INF_AA) || (infantry.getSecondaryWeapon() != null && infantry.getSecondaryWeapon().hasFlag(WeaponType.F_INF_AA))) {
notes.add("Can attack airborn units.");
}
if (infantry.hasSpecialization(Infantry.BRIDGE_ENGINEERS)) {
notes.add("Bridge-building equipment");
}
if (infantry.hasSpecialization(Infantry.DEMO_ENGINEERS)) {
notes.add("Equipped with demolition gear");
}
if (infantry.hasSpecialization(Infantry.FIRE_ENGINEERS)) {
notes.add("Firefighting equipment");
}
if (infantry.hasSpecialization(Infantry.MINE_ENGINEERS)) {
notes.add("Minesweeper equipment");
}
if (infantry.hasSpecialization(Infantry.TRENCH_ENGINEERS)) {
notes.add("Trench/Fieldwork equipment");
}
if (infantry.hasSpecialization(Infantry.MARINES)) {
notes.add("No penalties for vacuum or zero-G");
}
if (infantry.hasSpecialization(Infantry.MOUNTAIN_TROOPS)) {
notes.add("Mountain climbing equipment");
}
if (infantry.hasSpecialization(Infantry.PARAMEDICS)) {
notes.add("Paramedic equipment.");
}
if (infantry.hasSpecialization(Infantry.PARATROOPS)) {
notes.add("Can make atmospheric drops.");
}
if (infantry.hasSpecialization(Infantry.SENSOR_ENGINEERS)) {
notes.add("Surveillance and communication equipment");
}
if (infantry.hasSpecialization(Infantry.TAG_TROOPS)) {
notes.add("Equipped with TAG (Range 3/6/9)");
}
if (infantry.hasSneakECM()) {
notes.add("Invisible to standard/light active probes.");
}
for (int i = 0; i < Math.min(8, notes.size()); i++) {
tspan = (Tspan) diagram.getElement(ID_NOTE_LINE + i);
tspan.setText(notes.get(i));
}
((Text) diagram.getElement(ID_NOTES)).rebuild();
diagram.updateTime(0);
diagram.render(g2d);
}
} catch (SVGException ex) {
ex.printStackTrace();
}
g2d.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
}
Aggregations