use of megamek.common.Mech in project megameklab by MegaMek.
the class UnitPrintManager method printAllUnits.
public static boolean printAllUnits(Vector<Entity> loadedUnits, boolean singlePrint) {
Book book = new Book();
List<Infantry> infList = new ArrayList<>();
List<BattleArmor> baList = new ArrayList<>();
List<Protomech> protoList = new ArrayList<>();
List<Entity> unprintable = new ArrayList<>();
HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
aset.add(new MediaPrintableArea(0, 0, 8.5f, 11, MediaPrintableArea.INCH));
PrinterJob masterPrintJob = PrinterJob.getPrinterJob();
if (!masterPrintJob.printDialog(aset)) {
return true;
}
PageFormat pageFormat = new PageFormat();
pageFormat = masterPrintJob.getPageFormat(null);
Paper p = pageFormat.getPaper();
p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
pageFormat.setPaper(p);
Tank tank1 = null;
Tank wige1 = null;
Tank dualTurret1 = null;
for (Entity unit : loadedUnits) {
if (unit instanceof Mech) {
UnitUtil.removeOneShotAmmo(unit);
UnitUtil.expandUnitMounts((Mech) unit);
book.append(new PrintMech((Mech) unit, book.getNumberOfPages()), pageFormat);
} else if ((unit instanceof LargeSupportTank) || ((unit instanceof Tank) && (unit.getMovementMode() != EntityMovementMode.VTOL) && ((Tank) unit).isSuperHeavy())) {
book.append(new PrintLargeSupportVehicle((Tank) unit), pageFormat);
} else if (unit instanceof VTOL) {
book.append(new PrintVTOL((VTOL) unit), pageFormat);
} else if (unit.getMovementMode() == EntityMovementMode.WIGE) {
if (singlePrint) {
book.append(new PrintVehicle((Tank) unit, null), pageFormat);
} else if (null != wige1) {
book.append(new PrintVehicle(wige1, (Tank) unit), pageFormat);
wige1 = null;
} else {
wige1 = (Tank) unit;
}
} else if ((unit instanceof Tank) && ((unit.getMovementMode() == EntityMovementMode.NAVAL) || (unit.getMovementMode() == EntityMovementMode.SUBMARINE) || (unit.getMovementMode() == EntityMovementMode.HYDROFOIL))) {
unprintable.add(unit);
// book.append(new PrintNavalVehicle((Tank) unit), pageFormat);
} else if (unit instanceof Tank) {
if (!((Tank) unit).hasNoDualTurret()) {
if (singlePrint) {
book.append(new PrintDualTurretVehicle((Tank) unit, null), pageFormat);
} else if (null != dualTurret1) {
book.append(new PrintDualTurretVehicle(dualTurret1, (Tank) unit), pageFormat);
dualTurret1 = null;
} else {
dualTurret1 = (Tank) unit;
}
} else {
if (singlePrint) {
book.append(new PrintVehicle((Tank) unit, null), pageFormat);
} else if (null != tank1) {
book.append(new PrintVehicle(tank1, (Tank) unit), pageFormat);
tank1 = null;
} else {
tank1 = (Tank) unit;
}
}
} else if (unit.hasETypeFlag(Entity.ETYPE_AERO) && !unit.hasETypeFlag(Entity.ETYPE_JUMPSHIP)) {
if (unit instanceof Dropship) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
book.append(new PrintAerodyne((Dropship) unit), pageFormat);
} else {
book.append(new PrintSpheroid((Dropship) unit), pageFormat);
}
} else if (unit instanceof FixedWingSupport) {
book.append(new PrintFixedWingSupport((FixedWingSupport) unit), pageFormat);
} else if (unit instanceof ConvFighter) {
book.append(new PrintConventionalFighter((ConvFighter) unit), pageFormat);
} else if (unit instanceof SmallCraft) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
book.append(new PrintSmallCraftAerodyne((SmallCraft) unit), pageFormat);
} else {
book.append(new PrintSmallCraftSpheroid((SmallCraft) unit), pageFormat);
}
} else {
book.append(new PrintAero((Aero) unit), pageFormat);
}
} else if (unit instanceof BattleArmor) {
baList.add((BattleArmor) unit);
if (singlePrint || baList.size() > 4) {
book.append(new PrintBattleArmor(baList), pageFormat);
baList = new ArrayList<>();
}
} else if (unit instanceof Infantry) {
infList.add((Infantry) unit);
if (singlePrint || infList.size() > 3) {
book.append(new PrintInfantry(infList), pageFormat);
infList = new ArrayList<>();
}
} else if (unit instanceof Protomech) {
protoList.add((Protomech) unit);
if (singlePrint || protoList.size() > 4) {
book.append(new PrintProtomech(protoList), pageFormat);
protoList = new ArrayList<>();
}
} else {
// TODO: show a message dialog that lists the unprintable units
unprintable.add(unit);
}
}
if (unprintable.size() > 0) {
JOptionPane.showMessageDialog(null, "Printing is not currently supported for the following units:\n" + unprintable.stream().map(en -> en.getChassis() + " " + en.getModel()).collect(Collectors.joining("\n")));
}
if (null != wige1) {
book.append(new PrintVehicle(wige1, null), pageFormat);
}
if (null != tank1) {
book.append(new PrintVehicle(tank1, null), pageFormat);
}
if (null != dualTurret1) {
book.append(new PrintDualTurretVehicle(dualTurret1, null), pageFormat);
}
if (baList.size() > 0) {
book.append(new PrintBattleArmor(baList), pageFormat);
}
if (infList.size() > 0) {
book.append(new PrintInfantry(infList), pageFormat);
}
if (protoList.size() > 0) {
book.append(new PrintProtomech(protoList), pageFormat);
}
masterPrintJob.setPageable(book);
if (loadedUnits.size() > 1) {
masterPrintJob.setJobName(loadedUnits.get(0).getShortNameRaw() + " etc");
} else if (loadedUnits.size() > 0) {
masterPrintJob.setJobName(loadedUnits.get(0).getShortNameRaw());
}
PrintTask task = new PrintTask(masterPrintJob, aset);
task.execute();
return true;
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class UnitUtil method getEntityVerifier.
/**
* Returns a TestEntity instance for the supplied Entity.
*
* @param unit
* @return
*/
public static TestEntity getEntityVerifier(Entity unit) {
EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
TestEntity testEntity = null;
if (unit.hasETypeFlag(Entity.ETYPE_MECH)) {
testEntity = new TestMech((Mech) unit, entityVerifier.mechOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_SUPPORT_TANK)) {
testEntity = new TestSupportVehicle((Tank) unit, entityVerifier.tankOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_TANK)) {
testEntity = new TestTank((Tank) unit, entityVerifier.tankOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
testEntity = new TestSmallCraft((SmallCraft) unit, entityVerifier.aeroOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_AERO)) {
testEntity = new TestAero((Aero) unit, entityVerifier.aeroOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
testEntity = new TestBattleArmor((BattleArmor) unit, entityVerifier.baOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
testEntity = new TestInfantry((Infantry) unit, entityVerifier.infOption, null);
}
return testEntity;
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class UnitUtil method checkArmor.
public static void checkArmor(Entity unit) {
if (!(unit instanceof Mech)) {
return;
}
boolean foundError = false;
Mech mech = (Mech) unit;
// be in there.
for (int location = 0; location < mech.locations(); location++) {
// Head armor has a max of 9
if (location == Mech.LOC_HEAD) {
int armor = mech.getArmor(location);
if ((armor > 9) && !mech.isSuperHeavy()) {
foundError = true;
mech.initializeArmor(9, location);
} else if (armor > 12) {
foundError = true;
mech.initializeArmor(9, location);
}
} else {
int armor = mech.getArmor(location);
if (mech.hasRearArmor(location)) {
armor += mech.getArmor(location, true);
}
int totalArmor = mech.getInternal(location) * 2;
// Armor on the location is greater than what can be there.
if (armor > totalArmor) {
foundError = true;
int armorOverage = armor - totalArmor;
// extra armor from the rear first.
if (mech.hasRearArmor(location)) {
int rearArmor = mech.getArmor(location, true);
if (rearArmor >= armorOverage) {
mech.initializeRearArmor(rearArmor - armorOverage, location);
armorOverage = 0;
} else {
armorOverage -= rearArmor;
mech.initializeRearArmor(0, location);
}
}
// Any armor overage left remove it from the front. Min 0
// armor in the location.
armor = mech.getArmor(location);
armor = Math.max(0, armor - armorOverage);
mech.initializeArmor(armor, location);
}
}
}
if (foundError) {
JOptionPane.showMessageDialog(null, "Too much armor found on this unit.\n\rMegaMekLab has automatically corrected the problem.\n\rIt is suggested you check the armor allocation.", "Too much armor", JOptionPane.WARNING_MESSAGE);
}
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class PatchworkArmorView method setFromEntity.
public void setFromEntity(Entity en) {
List<EquipmentType> armors = TestEntity.legalArmorsFor(en.getEntityType(), (en instanceof Mech) && ((Mech) en).isIndustrial(), en.getMovementMode(), techManager);
ignoreEvents = true;
for (int loc = 0; loc < combos.size(); loc++) {
if ((loc < en.locations()) && !((en.hasETypeFlag(Entity.ETYPE_TANK) && (loc == Tank.LOC_BODY))) && !((en.hasETypeFlag(Entity.ETYPE_AERO) && (loc == Aero.LOC_WINGS)))) {
labels.get(loc).setText(en.getLocationName(loc));
combos.get(loc).removeAllItems();
for (EquipmentType eq : armors) {
combos.get(loc).addItem(eq);
}
String name = EquipmentType.getArmorTypeName(en.getArmorType(loc), TechConstants.isClan(en.getArmorTechLevel(loc)));
combos.get(loc).setSelectedItem(EquipmentType.get(name));
labels.get(loc).setVisible(true);
combos.get(loc).setVisible(true);
} else {
labels.get(loc).setVisible(false);
combos.get(loc).setVisible(false);
}
}
ignoreEvents = false;
}
Aggregations