use of megamek.common.Aero in project megameklab by MegaMek.
the class MenuBarCreator method loadUnit.
private void loadUnit() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parentFrame);
unitLoadingDialog.setVisible(true);
UnitSelectorDialog viewer = new UnitSelectorDialog(parentFrame, unitLoadingDialog, true);
Entity newUnit = viewer.getChosenEntity();
viewer.setVisible(false);
viewer.dispose();
if (null == newUnit) {
return;
}
if (UnitUtil.validateUnit(newUnit).trim().length() > 0) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", UnitUtil.validateUnit(newUnit)));
}
if (newUnit.getEntityType() != parentFrame.getEntity().getEntityType()) {
MegaMekLabMainUI newUI = null;
if (newUnit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
newUI = new megameklab.com.ui.Dropship.MainUI(((Aero) newUnit).isPrimitive());
} else if (newUnit.hasETypeFlag(Entity.ETYPE_AERO) && !(newUnit.hasETypeFlag(Entity.ETYPE_JUMPSHIP) || newUnit.hasETypeFlag(Entity.ETYPE_FIXED_WING_SUPPORT))) {
newUI = new megameklab.com.ui.Aero.MainUI(((Aero) newUnit).isPrimitive());
} else if (newUnit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
newUI = new megameklab.com.ui.BattleArmor.MainUI();
} else if (newUnit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
newUI = new megameklab.com.ui.Infantry.MainUI();
} else if (newUnit.hasETypeFlag(Entity.ETYPE_MECH)) {
newUI = new megameklab.com.ui.Mek.MainUI();
} else if (newUnit.hasETypeFlag(Entity.ETYPE_TANK) && !newUnit.hasETypeFlag(Entity.ETYPE_GUN_EMPLACEMENT)) {
newUI = new megameklab.com.ui.Vehicle.MainUI();
}
if (null == newUI) {
JOptionPane.showMessageDialog(parentFrame, "Warning: Could not create new UI, aborting unit load!" + System.lineSeparator() + "Probable cause: Unsupported unit type.");
return;
}
parentFrame.dispose();
UnitUtil.updateLoadedUnit(newUnit);
newUI.setEntity(newUnit);
newUI.reloadTabs();
newUI.repaint();
newUI.refreshAll();
return;
}
CConfig.updateSaveFiles("");
UnitUtil.updateLoadedUnit(newUnit);
if (viewer.getChosenMechSummary().getSourceFile().getName().endsWith(".zip")) {
String fileName = viewer.getChosenMechSummary().getSourceFile().getAbsolutePath();
fileName = fileName.substring(0, fileName.lastIndexOf(File.separatorChar) + 1);
fileName = fileName + viewer.getChosenMechSummary().getName() + ".mtf";
CConfig.updateSaveFiles(fileName);
} else {
CConfig.updateSaveFiles(viewer.getChosenMechSummary().getSourceFile().getAbsolutePath());
}
parentFrame.setEntity(newUnit);
reload();
refresh();
parentFrame.setVisible(true);
}
use of megamek.common.Aero in project megameklab by MegaMek.
the class MenuBarCreator method jMenuResetEntity_actionPerformed.
public void jMenuResetEntity_actionPerformed(ActionEvent event) {
CConfig.updateSaveFiles("Reset Unit");
CConfig.setParam(CConfig.CONFIG_SAVE_FILE_1, "");
Entity en = parentFrame.getEntity();
if (en instanceof Tank) {
parentFrame.createNewUnit(Entity.ETYPE_TANK);
} else if (en instanceof Mech) {
parentFrame.createNewUnit(Entity.ETYPE_BIPED_MECH, ((Mech) en).isPrimitive(), ((Mech) en).isIndustrial());
} else if (en.hasETypeFlag(Entity.ETYPE_DROPSHIP)) {
parentFrame.createNewUnit(Entity.ETYPE_DROPSHIP);
} else if (en.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
parentFrame.createNewUnit(Entity.ETYPE_SMALL_CRAFT, ((Aero) en).isPrimitive());
} else if (parentFrame.getEntity() instanceof Aero) {
parentFrame.createNewUnit(Entity.ETYPE_AERO, ((Aero) en).isPrimitive());
} else if (parentFrame.getEntity() instanceof BattleArmor) {
parentFrame.createNewUnit(Entity.ETYPE_BATTLEARMOR);
} else if (parentFrame.getEntity() instanceof Infantry) {
parentFrame.createNewUnit(Entity.ETYPE_INFANTRY);
} else {
System.out.println("util.MenuBarCreatoer: " + "Received unknown entityType!");
}
setVisible(true);
reload();
refresh();
parentFrame.setVisible(true);
parentFrame.repaint();
}
use of megamek.common.Aero in project megameklab by MegaMek.
the class UnitUtil method removeMounted.
public static void removeMounted(Entity unit, Mounted mount) {
UnitUtil.removeCriticals(unit, mount);
// Some special checks for BA
if (unit instanceof BattleArmor) {
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setDWPMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the DWP
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
Mounted dwp = mount.getLinkedBy();
dwp.setLinked(null);
dwp.setLinkedBy(null);
}
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setAPMMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the AP Mount
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_AP_MOUNT)) {
Mounted apm = mount.getLinkedBy();
apm.setLinked(null);
apm.setLinkedBy(null);
}
}
// Some special checks for Aeros
if (unit instanceof Aero) {
if (mount.getType() instanceof WeaponType) {
// Aeros have additional weapon lists that need to be cleared
((Aero) unit).getTotalWeaponList().remove(mount);
((Aero) unit).getWeaponBayList().remove(mount);
((Aero) unit).getWeaponGroupList().remove(mount);
}
}
// We will need to reset the equipment numbers of the bay ammo and weapons
Map<Mounted, List<Mounted>> bayWeapons = new HashMap<>();
Map<Mounted, List<Mounted>> bayAmmo = new HashMap<>();
for (Mounted bay : unit.getWeaponBayList()) {
List<Mounted> list = bay.getBayWeapons().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayWeapons.put(bay, list);
list = bay.getBayAmmo().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayAmmo.put(bay, list);
}
unit.getEquipment().remove(mount);
if (mount.getType() instanceof MiscType) {
unit.getMisc().remove(mount);
} else if (mount.getType() instanceof AmmoType) {
unit.getAmmo().remove(mount);
} else {
unit.getWeaponList().remove(mount);
unit.getTotalWeaponList().remove(mount);
}
for (Mounted bay : bayWeapons.keySet()) {
bay.getBayWeapons().clear();
for (Mounted w : bayWeapons.get(bay)) {
if (mount != w) {
bay.getBayWeapons().add(unit.getEquipmentNum(w));
}
}
}
for (Mounted bay : bayAmmo.keySet()) {
bay.getBayAmmo().clear();
for (Mounted a : bayAmmo.get(bay)) {
if (mount != a) {
bay.getBayAmmo().add(unit.getEquipmentNum(a));
}
}
}
// An example of this would be removing a linked Artemis IV FCS
for (Mounted m : unit.getEquipment()) {
if (mount.equals(m.getLinkedBy())) {
m.setLinkedBy(null);
}
}
}
use of megamek.common.Aero in project megameklab by MegaMek.
the class ImageHelper method getRecordSheet.
public static Image getRecordSheet(Entity unit, boolean advanced) {
Image recordSheet = null;
String path = new File(recordSheetPath).getAbsolutePath() + File.separatorChar;
if (unit instanceof BipedMech) {
if (advanced) {
recordSheet = new ImageIcon(path + "tobiped.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twbiped.png").getImage();
}
} else if (unit instanceof QuadMech) {
if (advanced) {
recordSheet = new ImageIcon(path + "toquad.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twquad.png").getImage();
}
} else if (unit instanceof VTOL) {
recordSheet = new ImageIcon(path + "twvee-vtol.png").getImage();
} else if ((unit instanceof LargeSupportTank) || ((unit instanceof Tank) && ((Tank) unit).isSuperHeavy())) {
if (unit.getOInternal(LargeSupportTank.LOC_TURRET) > 0) {
recordSheet = new ImageIcon(path + "twvee-lgsupground-turret.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twvee-lgsupground.png").getImage();
}
} else if (unit instanceof Tank) {
if ((unit.getMovementMode() == EntityMovementMode.NAVAL) || (unit.getMovementMode() == EntityMovementMode.SUBMARINE) || (unit.getMovementMode() == EntityMovementMode.HYDROFOIL)) {
if (unit.getOInternal(((Tank) unit).getLocTurret()) > 0) {
recordSheet = new ImageIcon(path + "twnaval-turret.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twnaval.png").getImage();
}
} else if (advanced) {
String imageName = "twvee-" + unit.getMovementModeAsString().toLowerCase().trim() + "-dualturret.png";
recordSheet = new ImageIcon(path + imageName).getImage();
} else {
String imageName = "twvee-" + unit.getMovementModeAsString().toLowerCase().trim() + ".png";
recordSheet = new ImageIcon(path + imageName).getImage();
}
} else if (unit instanceof Aero) {
if (unit instanceof Dropship) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
recordSheet = new ImageIcon(path + "twaerodyneds.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twspheroidds.png").getImage();
}
} else if (unit instanceof ConvFighter) {
recordSheet = new ImageIcon(path + "twconventionalfighter.png").getImage();
} else if (unit instanceof SmallCraft) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
recordSheet = new ImageIcon(path + "twaero-smallcraft.png").getImage();
} else {
recordSheet = new ImageIcon(path + "twspheroid-smallcraft.png").getImage();
}
} else {
recordSheet = new ImageIcon(path + "twaero.png").getImage();
}
} else if (unit instanceof BattleArmor) {
recordSheet = new ImageIcon(path + "twba.png").getImage();
} else if (unit instanceof Protomech) {
recordSheet = new ImageIcon(path + "twproto.png").getImage();
}
return recordSheet;
}
use of megamek.common.Aero 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;
}
Aggregations