use of megamek.common.verifier.EntityVerifier in project megameklab by MegaMek.
the class CriticalView method refresh.
public void refresh() {
critSuit = new CriticalSuit(getBattleArmor());
leftPanel.removeAll();
rightPanel.removeAll();
bodyPanel.removeAll();
turretPanel.removeAll();
int[] numAPWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
int[] numAMWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
for (Mounted m : getBattleArmor().getEquipment()) {
if (m.getLocation() == BattleArmor.LOC_SQUAD || m.getLocation() == trooper) {
critSuit.addMounted(m.getBaMountLoc(), m);
// Weapons mounted in a quad turret count against the body limits
int useLoc = m.getBaMountLoc();
if (useLoc == BattleArmor.MOUNT_LOC_TURRET) {
useLoc = BattleArmor.MOUNT_LOC_BODY;
}
if (useLoc != BattleArmor.MOUNT_LOC_NONE) {
if ((m.getType() instanceof WeaponType) && !(m.getType() instanceof InfantryWeapon)) {
numAMWeapons[useLoc]++;
}
if (m.getType().hasFlag(MiscType.F_AP_MOUNT)) {
numAPWeapons[useLoc]++;
}
}
}
}
synchronized (getBattleArmor()) {
for (int location = 0; location < critSuit.locations(); location++) {
Vector<String> critNames = new Vector<String>(1, 1);
for (int slot = 0; slot < critSuit.getNumCriticals(location); slot++) {
CriticalSlot cs = critSuit.getCritical(location, slot);
if (cs == null) {
if (showEmpty) {
critNames.add(MtfFile.EMPTY);
}
continue;
} else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
// BattleArmor shouldn't have system type crits
continue;
} else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
try {
Mounted m = cs.getMount();
// Critical didn't get removed. Remove it now.
if (m == null) {
if (showEmpty) {
critNames.add(MtfFile.EMPTY);
}
continue;
}
StringBuffer critName = new StringBuffer(m.getName());
critName.append(":" + slot + ":" + getBattleArmor().getEquipmentNum(m));
critNames.add(critName.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
DropTargetCriticalList<String> criticalSlotList = null;
criticalSlotList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
criticalSlotList.setAlignmentX(JLabel.CENTER_ALIGNMENT);
criticalSlotList.setVisibleRowCount(critNames.size());
criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
criticalSlotList.setName(location + ":" + trooper);
criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
switch(location) {
case BattleArmor.MOUNT_LOC_LARM:
leftPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_RARM:
rightPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_BODY:
bodyPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_TURRET:
turretPanel.add(criticalSlotList);
break;
}
}
String[] amTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
String[] apTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
for (int loc = 0; loc < BattleArmor.MOUNT_NUM_LOCS; loc++) {
amTxt[loc] = "AM Wpn: " + numAMWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiMechWeapons(loc);
apTxt[loc] = "AP Wpn: " + numAPWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiPersonnelWeapons(loc, trooper);
if (numAMWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
amTxt[loc] = "<html><font color='C00000'>" + amTxt[loc] + "</font></html>";
}
if (numAPWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
apTxt[loc] = "<html><font color='C00000'>" + apTxt[loc] + "</font></html>";
}
}
leftPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
leftPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
rightPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
rightPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
bodyPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
bodyPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
// Hide the arm panels if we are a quad
if (getBattleArmor().getChassisType() == BattleArmor.CHASSIS_TYPE_QUAD) {
leftPanel.setVisible(false);
rightPanel.setVisible(false);
turretPanel.setVisible(getBattleArmor().getTurretCapacity() > 0);
} else {
leftPanel.setVisible(true);
rightPanel.setVisible(true);
turretPanel.setVisible(false);
}
EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
TestBattleArmor testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
String weightTxt = "Weight: " + String.format("%1$.3f", testBA.calculateWeight(trooper)) + "/" + getBattleArmor().getTrooperWeight();
if (testBA.calculateWeight(trooper) > getBattleArmor().getTrooperWeight()) {
weightTxt = "<html><font color='C00000'>" + weightTxt + "</font></html>";
}
weightLabel.setText(weightTxt);
leftPanel.add(Box.createVerticalStrut(8));
rightPanel.add(Box.createVerticalStrut(8));
bodyPanel.add(Box.createVerticalStrut(8));
turretPanel.add(Box.createVerticalStrut(8));
leftPanel.invalidate();
leftPanel.invalidate();
rightPanel.invalidate();
turretPanel.invalidate();
bodyPanel.repaint();
leftPanel.repaint();
rightPanel.repaint();
turretPanel.repaint();
}
}
use of megamek.common.verifier.EntityVerifier 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.verifier.EntityVerifier in project megameklab by MegaMek.
the class BACriticalView method refresh.
public void refresh() {
critSuit = new BACriticalSuit(getBattleArmor());
leftArmPanel.removeAll();
rightArmPanel.removeAll();
bodyPanel.removeAll();
turretPanel.removeAll();
int[] numAPWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
int[] numAMWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
for (Mounted m : getBattleArmor().getEquipment()) {
if ((m.getLocation() == BattleArmor.LOC_SQUAD) || (m.getLocation() == trooper)) {
critSuit.addMounted(m.getBaMountLoc(), m);
// Weapons mounted in a quad turret count against the body limits
int useLoc = m.getBaMountLoc();
if (useLoc == BattleArmor.MOUNT_LOC_TURRET) {
useLoc = BattleArmor.MOUNT_LOC_BODY;
}
if (useLoc != BattleArmor.MOUNT_LOC_NONE) {
if ((m.getType() instanceof WeaponType) && !(m.getType() instanceof InfantryWeapon)) {
numAMWeapons[useLoc]++;
}
if (m.getType().hasFlag(MiscType.F_AP_MOUNT)) {
numAPWeapons[useLoc]++;
}
}
}
}
synchronized (getBattleArmor()) {
for (int location = 0; location < critSuit.locations(); location++) {
Vector<String> critNames = new Vector<>(1, 1);
for (int slot = 0; slot < critSuit.getNumCriticals(location); slot++) {
CriticalSlot cs = critSuit.getCritical(location, slot);
if (cs == null) {
if (showEmpty) {
critNames.add(CritCellUtil.EMPTY_CRITCELL_TEXT);
}
} else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
Mounted m = cs.getMount();
if (m == null) {
if (showEmpty) {
critNames.add(CritCellUtil.EMPTY_CRITCELL_TEXT);
}
} else {
critNames.add(m.getName() + ":" + slot + ":" + getBattleArmor().getEquipmentNum(m));
}
}
}
BAASBMDropTargetCriticalList<String> criticalSlotList = new BAASBMDropTargetCriticalList<>(critNames, eSource, refresh, showEmpty, this);
criticalSlotList.setVisibleRowCount(critNames.size());
criticalSlotList.setAlignmentX(JComponent.CENTER_ALIGNMENT);
criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
criticalSlotList.setName(location + ":" + trooper);
criticalSlotList.setBorder(BorderFactory.createLineBorder(CritCellUtil.CRITCELL_BORDER_COLOR));
switch(location) {
case BattleArmor.MOUNT_LOC_LARM:
leftArmPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_RARM:
rightArmPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_BODY:
bodyPanel.add(criticalSlotList);
break;
case BattleArmor.MOUNT_LOC_TURRET:
turretPanel.add(criticalSlotList);
break;
}
}
String[] amTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
String[] apTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
for (int loc = 0; loc < BattleArmor.MOUNT_NUM_LOCS; loc++) {
amTxt[loc] = "Anti-Mech Weapons: " + numAMWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiMechWeapons(loc);
apTxt[loc] = "Anti-Personnel Weapons: " + numAPWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiPersonnelWeapons(loc, trooper);
if (numAMWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
amTxt[loc] = "<html><font color='C00000'>" + amTxt[loc] + "</font></html>";
}
if (numAPWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
apTxt[loc] = "<html><font color='C00000'>" + apTxt[loc] + "</font></html>";
}
}
leftArmPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_LARM]));
leftArmPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_LARM]));
rightArmPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_RARM]));
rightArmPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_RARM]));
bodyPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_BODY]));
bodyPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_BODY]));
// Hide the arm panels if we are a quad
boolean isQuad = getBattleArmor().getChassisType() == BattleArmor.CHASSIS_TYPE_QUAD;
leftArmPanel.setVisible(!isQuad);
rightArmPanel.setVisible(!isQuad);
turretPanel.setVisible(isQuad && (getBattleArmor().getTurretCapacity() > 0));
EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
TestBattleArmor testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
String weightTxt = "Weight: " + String.format("%1$.3f", testBA.calculateWeight(trooper)) + "/" + getBattleArmor().getTrooperWeight();
if (testBA.calculateWeight(trooper) > getBattleArmor().getTrooperWeight()) {
weightTxt = "<html><font color='C00000'>" + weightTxt + "</font></html>";
}
weightLabel.setText(weightTxt);
validate();
}
}
Aggregations