use of megamek.common.weapons.infantry.InfantryWeapon 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.weapons.infantry.InfantryWeapon 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.weapons.infantry.InfantryWeapon in project megameklab by MegaMek.
the class WeaponView method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ADDP_COMMAND) || e.getActionCommand().equals(ADDS_COMMAND)) {
boolean isSecondary = e.getActionCommand().equals(ADDS_COMMAND);
int view = masterEquipmentTable.getSelectedRow();
if (view < 0) {
// selection got filtered away
return;
}
int selected = masterEquipmentTable.convertRowIndexToModel(view);
EquipmentType equip = masterEquipmentList.getType(selected);
if (equip instanceof InfantryWeapon) {
UnitUtil.replaceMainWeapon(getInfantry(), (InfantryWeapon) equip, isSecondary);
if (equip.hasFlag(WeaponType.F_TAG)) {
getInfantry().setSpecializations(getInfantry().getSpecializations() | Infantry.TAG_TROOPS);
getInfantry().setSecondaryN(2);
} else if (getInfantry().getSecondaryN() == 0) {
getInfantry().setSecondaryN(1);
}
}
} else {
return;
}
refresh.refreshAll();
}
use of megamek.common.weapons.infantry.InfantryWeapon in project megameklab by MegaMek.
the class BuildView 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;
final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
final Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
final String[] locNames = BattleArmor.MOUNT_LOC_NAMES;
// A list of the valid locations we can add the selected eq to
ArrayList<Integer> validLocs = new ArrayList<Integer>();
int numLocs = BattleArmor.MOUNT_NUM_LOCS;
for (int loc = 0; loc < numLocs; loc++) {
if (TestBattleArmor.isMountLegal(getBattleArmor(), eq, loc)) {
validLocs.add(loc);
}
}
if (eq.getLocation() == BattleArmor.LOC_SQUAD && !(eq.getType() instanceof InfantryWeapon)) {
// Add a menu item for each potential location
for (Integer location : validLocs) {
if (UnitUtil.isValidLocation(getBattleArmor(), eq.getType(), location)) {
item = new JMenuItem("Add to " + locNames[location]);
final int loc = location;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mountEquipmentInLocation(loc, selectedRow);
}
});
popup.add(item);
}
}
if (!UnitUtil.isArmor(eq.getType()) && !eq.isSquadSupportWeapon()) {
item = new JMenuItem("Make individual weapon");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setLocation(BattleArmor.LOC_TROOPER_1);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
} else {
if (!UnitUtil.isArmor(eq.getType()) && !(eq.getType() instanceof InfantryWeapon) && !((eq.getType() instanceof WeaponType) && (eq.getType().hasFlag(WeaponType.F_TASER) || ((WeaponType) eq.getType()).getAmmoType() == AmmoType.T_NARC))) {
item = new JMenuItem("Make squad weapon");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setLocation(BattleArmor.LOC_SQUAD);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
}
// Allow number of shots selection
if ((getBattleArmor() instanceof BattleArmor) && eq.getType() instanceof AmmoType) {
AmmoType at = (AmmoType) eq.getType();
int maxNumShots = 4;
int stepSize = 1;
if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
maxNumShots = 8;
stepSize = 2;
}
for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
if (i == eq.getBaseShotsLeft()) {
continue;
}
item = new JMenuItem("Set Shots: " + i);
final int shots = i;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setShotsLeft(shots);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
}
// Allow making this a squad support weapon
if ((eq.getType() instanceof WeaponType) && !eq.isSquadSupportWeapon() && !eq.getType().hasFlag(WeaponType.F_INFANTRY) && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
item = new JMenuItem("Mount as squad support weapon");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setSquadSupportWeapon(true);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
// Adding ammo as a squad support mount is slightly different
if ((eq.getType() instanceof AmmoType) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !eq.isSquadSupportWeapon() && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
boolean enabled = false;
for (Mounted weapon : getBattleArmor().getWeaponList()) {
WeaponType wtype = (WeaponType) weapon.getType();
if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(eq, wtype)) {
enabled = true;
}
}
item = new JMenuItem("Mount as squad support weapon");
item.setEnabled(enabled);
item.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setSquadSupportWeapon(true);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
// Allow removing squad support weapon
if (eq.isSquadSupportWeapon()) {
item = new JMenuItem("Remove squad support weapon mount");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setSquadSupportWeapon(false);
// squad support weapon
for (Mounted ammo : getBattleArmor().getAmmo()) {
ammo.setSquadSupportWeapon(false);
}
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
// See if we should allow linking this to a DWP
if (getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !(eq.getType() instanceof AmmoType) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
for (Mounted m : getBattleArmor().getMisc()) {
// If this isn't a DWP or it's a full DWP, skip
if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || m.getLinked() != null) {
continue;
}
String locName;
if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
locName = "None";
} else {
locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
}
item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
final Mounted dwp = m;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setLinked(dwp);
dwp.setLinked(eq);
eq.setDWPMounted(true);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
}
// Should we allow mounting Ammo in a DWP?
if ((eq.getType() instanceof AmmoType) && getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
for (final Mounted m : getBattleArmor().getMisc()) {
// If this isn't a DWP, skip
if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
continue;
}
// We only want to enable the menu item if the DWP has a
// mounted weapon and we clicked on a valid ammo type
boolean enabled = false;
if (m.getLinked() != null) {
EquipmentType etype = m.getLinked().getType();
if (etype instanceof WeaponType) {
WeaponType wtype = (WeaponType) etype;
if (AmmoType.isAmmoValid(eq, wtype)) {
enabled = true;
}
}
}
String locName;
if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
locName = "None";
} else {
locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
}
item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
item.setToolTipText("Ammo can only be mounted in a DWP " + "with a valid weapon.");
item.setEnabled(enabled);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
m.getLinked().setLinked(eq);
eq.setDWPMounted(true);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
}
// Right-clicked on a DWP that has an attached weapon
if (eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && eq.getLinked() != null) {
item = new JMenuItem("Remove attached weapon");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Mounted attached = eq.getLinked();
attached.setDWPMounted(false);
eq.setLinked(null);
eq.setLinkedBy(null);
attached.setLinked(null);
attached.setLinkedBy(null);
// Remove any attached ammo
for (Mounted ammo : getBattleArmor().getAmmo()) {
if (attached.equals(ammo.getLinkedBy())) {
ammo.setDWPMounted(false);
ammo.setLinked(null);
ammo.setLinkedBy(null);
}
}
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
// See if we should allow linking this to an AP Mount
if (getBattleArmor().hasWorkingMisc(MiscType.F_AP_MOUNT) && eq.getType().hasFlag(WeaponType.F_INFANTRY) && !eq.isAPMMounted()) {
for (Mounted m : getBattleArmor().getMisc()) {
// If this isn't an AP Mount or it's a full AP Mount, skip
if (!m.getType().hasFlag(MiscType.F_AP_MOUNT) || m.getLinked() != null) {
continue;
}
// regardless of the number of gloves
if (m.getType().hasFlag(MiscType.F_ARMORED_GLOVE)) {
boolean hasUsedGlove = false;
for (Mounted m2 : getBattleArmor().getMisc()) {
if (m2.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && (m2.getLinked() != null)) {
hasUsedGlove = true;
}
}
if (hasUsedGlove) {
continue;
}
}
// Only armored gloves can carry infantry support weapons
if (!m.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && eq.getType().hasFlag(WeaponType.F_INF_SUPPORT)) {
continue;
}
String locName;
if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
locName = "None";
} else {
locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
}
item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
final Mounted apm = m;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eq.setLinked(apm);
apm.setLinked(eq);
eq.setAPMMounted(true);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
}
// Right-clicked on a AP Mount that has an attached weapon
if (eq.getType().hasFlag(MiscType.F_AP_MOUNT) && eq.getLinked() != null) {
item = new JMenuItem("Remove attached weapon");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Mounted attached = eq.getLinked();
attached.setAPMMounted(false);
eq.setLinked(null);
eq.setLinkedBy(null);
attached.setLinked(null);
attached.setLinkedBy(null);
((BuildTab) getParent().getParent()).refreshAll();
}
});
popup.add(item);
}
popup.show(this, e.getX(), e.getY());
}
}
Aggregations