use of megamek.common.WeaponType in project megameklab by MegaMek.
the class StringUtils method getEquipmentInfo.
public static String getEquipmentInfo(Entity unit, Mounted mount) {
String info = "";
if (mount.getType() instanceof WeaponType) {
WeaponType weapon = (WeaponType) mount.getType();
if (weapon instanceof InfantryWeapon) {
info = Integer.toString(weapon.getDamage());
if (weapon.hasFlag(WeaponType.F_BALLISTIC)) {
info += " (B)";
} else if (weapon.hasFlag(WeaponType.F_ENERGY)) {
info += " (E)";
} else if (weapon.hasFlag(WeaponType.F_MISSILE)) {
info += " (M)";
} else if (weapon.hasFlag(WeaponType.F_INF_POINT_BLANK)) {
info += " (P)";
}
if (weapon.hasFlag(WeaponType.F_INF_BURST)) {
info += "B";
}
if (weapon.hasFlag(WeaponType.F_INF_AA)) {
info += "A";
}
if (weapon.hasFlag(WeaponType.F_FLAMER)) {
info += "F";
}
if (weapon.hasFlag(WeaponType.F_INF_NONPENETRATING)) {
info += "N";
}
} else if (weapon.hasFlag(WeaponType.F_MGA)) {
info = " [T]";
} else if ((weapon instanceof ISC3M) || (weapon instanceof TAGWeapon)) {
info = " [E]";
} else if (weapon instanceof ISC3RemoteSensorLauncher) {
info = " [M,E]";
} else if (weapon.getDamage() < 0) {
if (weapon instanceof StreakSRMWeapon) {
info = "2/Msl [M,C]";
} else if ((weapon instanceof SRMWeapon) || (weapon instanceof MekMortarWeapon)) {
info = "2/Msl [M,C,S]";
} else if ((weapon instanceof StreakLRMWeapon)) {
info = "1/Msl [M,C]";
} else if ((weapon instanceof LRMWeapon)) {
info = "1/Msl [M,C,S]";
} else if ((weapon instanceof MRMWeapon) || (weapon instanceof RLWeapon)) {
info = "1/Msl [M,C]";
} else if (weapon instanceof ISSnubNosePPC) {
info = "10/8/5 [DE,V]";
} else if ((weapon instanceof ISBALaserVSPSmall) || (weapon instanceof ISBALaserVSPSmall)) {
info = "5/4/3 [P,V]";
} else if ((weapon instanceof ISBALaserVSPMedium) || (weapon instanceof ISBALaserVSPMedium)) {
info = "9/7/5 [P,V]";
} else if (weapon instanceof ISVariableSpeedPulseLaserLarge) {
info = "11/9/7 [P,V]";
} else if (weapon instanceof ISHGaussRifle) {
info = "25/20/10 [DB,X]";
} else if (weapon instanceof ISPlasmaRifle) {
info = "10 [DE,H,AI]";
} else if (weapon instanceof CLPlasmaCannon) {
info = "[DE,H,AI]";
} else if (weapon instanceof HAGWeapon) {
info = Integer.toString(weapon.getRackSize());
info += " [C,F,X]";
} else if (weapon instanceof ArtilleryWeapon) {
info = Integer.toString(weapon.getRackSize());
info += "[AE,S,F]";
} else if (weapon instanceof ArtilleryCannonWeapon) {
info = Integer.toString(weapon.getRackSize());
info += "[DB,AE]";
} else if (weapon instanceof ThunderBoltWeapon) {
if (weapon instanceof ISThunderBolt5) {
info = "5";
} else if (weapon instanceof ISThunderBolt10) {
info = "10";
} else if (weapon instanceof ISThunderBolt15) {
info = "15";
} else if (weapon instanceof ISThunderBolt20) {
info = "20";
}
info += "[M]";
} else if (weapon instanceof NarcWeapon) {
info = "[M]";
} else if (weapon instanceof ISBAPopUpMineLauncher) {
info = "4";
} else {
info = Integer.toString(weapon.getRackSize());
}
} else if (weapon instanceof UACWeapon) {
info = Integer.toString(weapon.getDamage());
info += "/Sht [DB,R/C]";
} else if ((weapon instanceof ISVehicularGrenadeLauncher) || (weapon instanceof CLVehicularGrenadeLauncher)) {
info = "[AE,OS]";
} else {
if (!UnitUtil.isAMS(weapon)) {
info = Integer.toString(weapon.getDamage());
}
info += " [";
if (weapon.hasFlag(WeaponType.F_BALLISTIC) && !UnitUtil.isAMS(weapon)) {
info += "DB,";
}
if (UnitUtil.isAMS(weapon) || (weapon.hasFlag(WeaponType.F_B_POD))) {
info += "PD,";
} else if (weapon.hasFlag(WeaponType.F_PULSE)) {
info += "P,";
} else if (weapon.hasFlag(WeaponType.F_ENERGY) || weapon.hasFlag(WeaponType.F_PLASMA)) {
info += "DE,";
}
if (weapon instanceof ISBombastLaser) {
info += "V,";
}
if ((weapon instanceof LBXACWeapon) || (weapon instanceof ISSilverBulletGauss)) {
info += "C/F/";
}
if (weapon instanceof CLBALBX) {
info += "C,F,";
}
if (UnitUtil.hasSwitchableAmmo(weapon)) {
info += "S,";
}
if (weapon.hasFlag(WeaponType.F_FLAMER) || weapon.hasFlag(WeaponType.F_PLASMA)) {
info += "H,";
}
if ((weapon instanceof MGWeapon) || (weapon instanceof BPodWeapon) || (weapon instanceof CLERPulseLaserSmall) || (weapon instanceof CLBAERPulseLaserSmall) || (weapon instanceof ISXPulseLaserSmall) || (weapon instanceof ISPulseLaserSmall) || (weapon instanceof ISBALaserPulseSmall) || (weapon instanceof CLPulseLaserSmall) || (weapon instanceof CLBAPulseLaserSmall) || (weapon instanceof CLPulseLaserMicro) || (weapon instanceof CLBAPulseLaserMicro) || (weapon.hasFlag(WeaponType.F_FLAMER) || (weapon.hasFlag(WeaponType.F_BURST_FIRE)))) {
info += "AI,";
}
if (weapon.isExplosive(mount) && !(weapon instanceof ACWeapon) && (!(weapon instanceof PPCWeapon) || ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_PPC_CAPACITOR)))) {
info += "X,";
}
if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
info += "OS,";
}
info = info.substring(0, info.length() - 1) + "]";
}
} else if ((mount.getType() instanceof MiscType) && (mount.getType().hasFlag(MiscType.F_CLUB) || mount.getType().hasFlag(MiscType.F_HAND_WEAPON))) {
if (mount.getType().hasSubType(MiscType.S_VIBRO_LARGE) || mount.getType().hasSubType(MiscType.S_VIBRO_MEDIUM) || mount.getType().hasSubType(MiscType.S_VIBRO_SMALL)) {
// manually set vibros to active to get correct damage
mount.setMode(1);
}
if (mount.getType().hasSubType(MiscType.S_CLAW) || mount.getType().hasSubType(MiscType.S_CLAW_THB)) {
info = Integer.toString((int) Math.ceil(unit.getWeight() / 7.0));
} else {
info = Integer.toString(ClubAttackAction.getDamageFor(unit, mount, false));
}
} else if ((mount.getType() instanceof MiscType) && (mount.getType().hasFlag(MiscType.F_AP_POD))) {
info = "[PD,OS,AI]";
} else if ((mount.getType() instanceof MiscType) && mount.getType().hasFlag(MiscType.F_TALON)) {
info = Integer.toString(KickAttackAction.getDamageFor(unit, Mech.LOC_LLEG, false));
} else {
info = " [E]";
}
return info;
}
use of megamek.common.WeaponType in project megameklab by MegaMek.
the class UnitUtil method getToolTipInfo.
public static String getToolTipInfo(Entity unit, Mounted eq) {
DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols();
unusualSymbols.setDecimalSeparator('.');
unusualSymbols.setGroupingSeparator(',');
DecimalFormat myFormatter = new DecimalFormat("#,##0", unusualSymbols);
StringBuilder sb = new StringBuilder("<HTML>");
sb.append(eq.getName());
if ((eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || eq.getType().hasFlag(MiscType.F_AP_MOUNT)) && (eq.getLinked() != null)) {
sb.append(" (attached " + eq.getLinked().getName() + ")");
}
if (eq.isSquadSupportWeapon()) {
sb.append(" (squad support weapon)");
}
if (eq.getType() instanceof InfantryWeapon) {
sb.append("<br>Damage/Trooper: ");
double infDamage = ((InfantryWeapon) eq.getType()).getInfantryDamage();
sb.append(infDamage);
sb.append("<br>Range Class: " + ((InfantryWeapon) eq.getType()).getInfantryRange());
} else {
sb.append("<br>Crits: ");
sb.append(eq.getType().getCriticals(unit));
sb.append("<br>Tonnage: ");
if (eq.getType() instanceof MiscType) {
sb.append(((MiscType) eq.getType()).getTonnage(unit, eq.getLocation()));
} else {
sb.append(eq.getType().getTonnage(unit));
}
if (eq.getType() instanceof WeaponType) {
sb.append("<br>Heat: ");
sb.append(((WeaponType) eq.getType()).getHeat());
}
}
sb.append("<Br>Cost: ");
double cost = eq.getType().getCost(unit, false, eq.getLocation());
sb.append(myFormatter.format(cost));
sb.append(" CBills");
if (eq.isRearMounted()) {
sb.append("<br>Rear Facing");
}
if (eq.isMechTurretMounted()) {
sb.append("<br>Turret mounted");
}
if (eq.isArmored()) {
sb.append("<br>Armored");
}
if ((unit instanceof BattleArmor) && eq.getType().hasFlag(WeaponType.F_INF_SUPPORT)) {
sb.append("<br>* Infantry support weapons must be held in an " + "Armored Glove");
} else if ((unit instanceof BattleArmor) && eq.getType().hasFlag(WeaponType.F_INFANTRY)) {
sb.append("<br>* Infantry weapons must be mounted in AP Mounts");
}
sb.append("</html>");
return sb.toString();
}
use of megamek.common.WeaponType 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 "?";
}
use of megamek.common.WeaponType in project megameklab by MegaMek.
the class BuildView method jMenuLoadComponent_actionPerformed.
private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) {
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
if (eq.getType().isSpreadable() || eq.isSplitable()) {
if (!(eq.getType() instanceof MiscType) || !eq.getType().hasFlag(MiscType.F_TARGCOMP)) {
jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, 1, selectedRow);
} else {
// Targetting computer is flagged as spreadable so the slots will be added one at a time when loaded,
// since we don't have a way of indicating the number of slots until we know all the weapons. But
// it's not really splittable, so we need to put add all the slots at once.
jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getType().getCriticals(getMech()), selectedRow);
}
return;
}
try {
if ((eq.getType() instanceof WeaponType) && eq.getType().hasFlag(WeaponType.F_VGL)) {
String[] facings;
if (location == Mech.LOC_LT) {
facings = new String[4];
facings[0] = "Front";
facings[1] = "Front-Left";
facings[2] = "Rear-Left";
facings[3] = "Rear";
} else if (location == Mech.LOC_RT) {
facings = new String[4];
facings[0] = "Front";
facings[1] = "Front-Right";
facings[2] = "Rear-Right";
facings[3] = "Rear";
} else if (location == Mech.LOC_CT) {
facings = new String[2];
facings[0] = "Front";
facings[1] = "Rear";
} else {
JOptionPane.showMessageDialog(this, "VGL must be placed in torso location!", "Invalid location", JOptionPane.WARNING_MESSAGE);
return;
}
String facing = (String) JOptionPane.showInputDialog(this, "Please choose the facing of the VGL", "Choose Facing", JOptionPane.QUESTION_MESSAGE, null, facings, facings[0]);
if (facing == null) {
return;
}
UnitUtil.addMounted(getMech(), eq, location, false);
if (facing.equals("Front-Left")) {
eq.setFacing(5);
} else if (facing.equals("Front-Right")) {
eq.setFacing(1);
} else if (facing.equals("Rear-Right")) {
eq.setFacing(2);
} else if (facing.equals("Rear-Left")) {
eq.setFacing(4);
} else if (facing.equals("Rear")) {
eq.setFacing(3);
UnitUtil.changeMountStatus(getMech(), eq, location, -1, true);
}
} else {
UnitUtil.addMounted(getMech(), eq, location, false);
}
} catch (Exception ex) {
ex.printStackTrace();
}
UnitUtil.changeMountStatus(getMech(), eq, location, -1, false);
// go back up to grandparent build tab and fire a full refresh.
((BuildTab) getParent().getParent()).refreshAll();
}
use of megamek.common.WeaponType in project megameklab by MegaMek.
the class CriticalView method refresh.
public void refresh() {
leftPanel.removeAll();
rightPanel.removeAll();
nosePanel.removeAll();
aftPanel.removeAll();
int[] availSpace = TestAero.availableSpace(getAero());
if (availSpace == null) {
// Shouldn't happen, since we only allow valid armor types to be
// selected...
System.err.println("Error in CriticalView: Invalid armor type!");
return;
}
synchronized (getAero()) {
// Aeros have 5 locs, the 5th is "wings" which should be ignored
int numLocs = getAero().locations() - 1;
for (int location = 0; location < numLocs; location++) {
Vector<String> critNames = new Vector<String>(1, 1);
int numWeapons = 0;
for (int slot = 0; slot < getAero().getNumberOfCriticals(location); slot++) {
CriticalSlot cs = getAero().getCritical(location, slot);
if (cs == null) {
continue;
} else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
// Aeros shouldn't have system types
continue;
} else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
try {
Mounted m = cs.getMount();
// Critical didn't get removed. Remove it now.
if (m == null) {
m = cs.getMount();
if (m == null) {
getAero().setCritical(location, slot, null);
continue;
}
cs.setMount(m);
}
// Ignore weapon groups
if (m.isWeaponGroup()) {
continue;
}
if (m.getType() instanceof WeaponType) {
numWeapons++;
}
StringBuffer critName = new StringBuffer(m.getName());
if (critName.length() > 25) {
critName.setLength(25);
critName.append("...");
}
if (m.isRearMounted()) {
critName.append(" (R)");
}
if (m.isSponsonTurretMounted()) {
critName.append(" (ST)");
}
if (m.isPintleTurretMounted()) {
critName.append(" (PT)");
}
critName.append(":" + slot);
critNames.add(critName.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
if (critNames.size() == 0) {
critNames.add(MtfFile.EMPTY);
}
DropTargetCriticalList<String> criticalSlotList = null;
DropTargetCriticalList<String> dropTargetCriticalList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
criticalSlotList = dropTargetCriticalList;
criticalSlotList.setAlignmentX(JLabel.CENTER_ALIGNMENT);
criticalSlotList.setVisibleRowCount(critNames.size());
criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
criticalSlotList.setName(Integer.toString(location));
criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
switch(location) {
case Aero.LOC_NOSE:
nosePanel.add(criticalSlotList);
noseSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
break;
case Aero.LOC_LWING:
leftPanel.add(criticalSlotList);
leftSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
break;
case Aero.LOC_RWING:
rightPanel.add(criticalSlotList);
rightSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
break;
case Aero.LOC_AFT:
aftPanel.add(criticalSlotList);
aftSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
break;
}
}
leftPanel.add(leftSpace);
leftPanel.add(Box.createVerticalStrut(8));
rightPanel.add(rightSpace);
rightPanel.add(Box.createVerticalStrut(8));
nosePanel.add(noseSpace);
nosePanel.add(Box.createVerticalStrut(8));
aftPanel.add(aftSpace);
aftPanel.add(Box.createVerticalStrut(8));
nosePanel.repaint();
leftPanel.repaint();
rightPanel.repaint();
aftPanel.repaint();
nosePanel.invalidate();
leftPanel.invalidate();
rightPanel.invalidate();
aftPanel.invalidate();
}
}
Aggregations