use of megamek.common.MiscType 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.MiscType in project megameklab by MegaMek.
the class UnitUtil method removeEnhancements.
/**
* Removes all enhancements (TSM and MASC) from the mek
*
* @param unit
*/
public static void removeEnhancements(Mech unit) {
ConcurrentLinkedQueue<Mounted> equipmentList = new ConcurrentLinkedQueue<Mounted>(unit.getMisc());
for (Mounted eq : equipmentList) {
if (UnitUtil.isTSM(eq.getType()) || UnitUtil.isMASC(eq.getType()) || ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_SCM))) {
UnitUtil.removeCriticals(unit, eq);
}
}
for (Mounted eq : equipmentList) {
if (UnitUtil.isTSM(eq.getType()) || UnitUtil.isMASC(eq.getType()) || ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_SCM))) {
unit.getMisc().remove(eq);
unit.getEquipment().remove(eq);
}
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class UnitUtil method removeISorArmorMounts.
/**
* remove all Mounted on the passed unit that are internal structure or
* armor
*
* @param unit
* the Entity
* @param internalStructure
* true to remove IS, false to remove armor
*/
public static void removeISorArmorMounts(Entity unit, boolean internalStructure) {
UnitUtil.removeISorArmorCrits(unit, internalStructure);
ArrayList<String> mountList = new ArrayList<String>();
mountList.add("Standard");
List<String> names;
if (internalStructure) {
names = Arrays.asList(EquipmentType.structureNames);
} else {
names = Arrays.asList(EquipmentType.armorNames);
}
for (String name : names) {
mountList.add(String.format("Clan %1s", name));
mountList.add(String.format("IS %1s", name));
mountList.add(name);
}
for (int pos = 0; pos < unit.getEquipment().size(); ) {
Mounted mount = unit.getEquipment().get(pos);
if (mountList.contains(mount.getType().getInternalName())) {
unit.getEquipment().remove(pos);
} else {
pos++;
}
}
for (int pos = 0; pos < unit.getMisc().size(); ) {
Mounted mount = unit.getMisc().get(pos);
if ((mount.getType() instanceof MiscType) && mountList.contains(mount.getType().getInternalName())) {
unit.getMisc().remove(pos);
} else {
pos++;
}
}
if (internalStructure) {
unit.setStructureType(EquipmentType.T_STRUCTURE_STANDARD);
} else {
unit.setArmorType(EquipmentType.T_ARMOR_STANDARD);
unit.setArmorTechLevel(unit.getTechLevel());
}
}
use of megamek.common.MiscType 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.MiscType in project megameklab by MegaMek.
the class UnitUtil method createSpreadMounts.
/**
* create a Mounted and corresponding CriticalSlots for the passed in
* <code>EquipmentType</code> on the passed in <code>Mech</code>
*
* @param unit
* @param equip
* @return
*/
public static Mounted createSpreadMounts(Mech unit, EquipmentType equip) {
final String METHOD_NAME = "createSpreadMounts(Mech, EquipmentType)";
// how many non-spreadable contiguous blocks of crits?
int blocks = 0;
boolean isMisc = equip instanceof MiscType;
blocks = equip.getCriticals(unit);
List<Integer> locations = new ArrayList<Integer>();
if (isMisc) {
if ((equip.hasFlag(MiscType.F_INDUSTRIAL_TSM) || equip.hasFlag(MiscType.F_TSM))) {
// all crits user placeable
for (int i = 0; i < equip.getCriticals(unit); i++) {
locations.add(Entity.LOC_NONE);
}
} else if (equip.hasFlag(MiscType.F_ENVIRONMENTAL_SEALING)) {
// 1 crit in each location
for (int i = 0; i < unit.locations(); i++) {
locations.add(i);
}
} else if (equip.hasFlag(MiscType.F_STEALTH)) {
// 2 in arms, legs, side torsos
locations.add(Mech.LOC_LLEG);
locations.add(Mech.LOC_RLEG);
locations.add(Mech.LOC_LARM);
locations.add(Mech.LOC_RARM);
locations.add(Mech.LOC_LT);
locations.add(Mech.LOC_RT);
blocks = 6;
// Need to account for the center leg
if (unit instanceof TripodMech) {
locations.add(Mech.LOC_CLEG);
blocks++;
}
} else if (equip.hasFlag(MiscType.F_SCM)) {
// 1 in arms, legs, side torsos
locations.add(Mech.LOC_LLEG);
locations.add(Mech.LOC_RLEG);
locations.add(Mech.LOC_LARM);
locations.add(Mech.LOC_RARM);
locations.add(Mech.LOC_LT);
locations.add(Mech.LOC_RT);
blocks = 6;
} else if ((equip.hasFlag(MiscType.F_TRACKS) || equip.hasFlag(MiscType.F_TALON) || equip.hasFlag(MiscType.F_JUMP_BOOSTER))) {
// 1 block in each leg
locations.add(Mech.LOC_LLEG);
locations.add(Mech.LOC_RLEG);
if (unit instanceof QuadMech) {
locations.add(Mech.LOC_LARM);
locations.add(Mech.LOC_RARM);
}
blocks = (unit instanceof BipedMech ? 2 : 4);
// Need to account for the center leg
if (unit instanceof TripodMech) {
locations.add(Mech.LOC_CLEG);
blocks = 3;
}
} else if (equip.hasFlag(MiscType.F_PARTIAL_WING)) {
// one block in each side torso
locations.add(Mech.LOC_LT);
locations.add(Mech.LOC_RT);
blocks = 2;
} else if ((equip.hasFlag(MiscType.F_VOIDSIG) || equip.hasFlag(MiscType.F_NULLSIG) || equip.hasFlag(MiscType.F_BLUE_SHIELD))) {
// Need to account for the center leg
if (unit instanceof TripodMech) {
blocks++;
}
// 1 crit in each location, except the head
for (int i = Mech.LOC_CT; i < unit.locations(); i++) {
locations.add(i);
}
} else if (equip.hasFlag(MiscType.F_CHAMELEON_SHIELD)) {
// Need to account for the center leg
if (unit instanceof TripodMech) {
blocks++;
}
// 1 crit in each location except head and CT
for (int i = Mech.LOC_RT; i < unit.locations(); i++) {
locations.add(i);
}
}
}
boolean firstBlock = true;
Mounted mount = new Mounted(unit, equip);
for (; blocks > 0; blocks--) {
// how many crits per block?
int crits = UnitUtil.getCritsUsed(unit, equip);
for (int i = 0; i < crits; i++) {
try {
if (firstBlock || (locations.get(0) == Entity.LOC_NONE)) {
// create only one mount per equipment, for BV and stuff
addMounted(unit, mount, locations.get(0), false);
if (firstBlock) {
firstBlock = false;
}
if (locations.get(0) == Entity.LOC_NONE) {
// only user-placable spread stuff gets location
// none
// for those, we need to create a mount for each
// crit,
// otherwise we can't correctly let the user place
// them
// luckily, that only affects TSM, so BV works out
// correctly
mount = new Mounted(unit, equip);
}
} else {
CriticalSlot cs = new CriticalSlot(mount);
if (!unit.addCritical(locations.get(0), cs)) {
UnitUtil.removeCriticals(unit, mount);
JOptionPane.showMessageDialog(null, "No room for equipment", mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
unit.getMisc().remove(mount);
unit.getEquipment().remove(mount);
return null;
}
}
} catch (LocationFullException lfe) {
getLogger().log(UnitUtil.class, METHOD_NAME, lfe);
JOptionPane.showMessageDialog(null, lfe.getMessage(), mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
unit.getMisc().remove(mount);
unit.getEquipment().remove(mount);
return null;
}
}
locations.remove(0);
}
return mount;
}
Aggregations