⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testentity.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org) * *  This program is free software; you can redistribute it and/or modify it *  under the terms of the GNU General Public License as published by the Free *  Software Foundation; either version 2 of the License, or (at your option) *  any later version. * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *  for more details. *//* * Author: Reinhard Vicinus */package megamek.common.verifier;import megamek.common.Entity;import megamek.common.Mech;import megamek.common.TechConstants;import megamek.common.CriticalSlot;import megamek.common.Mounted;import megamek.common.EquipmentType;import megamek.common.WeaponType;import megamek.common.AmmoType;import megamek.common.MiscType;import megamek.common.util.StringUtil;import megamek.common.Engine;import java.util.Enumeration;import java.lang.StringBuffer;public abstract class TestEntity implements TestEntityOption {		public final static float CEIL_TON = 1.0f;	public final static float CEIL_HALFTON = 2.0f;	public final static float CEIL_QUARTERTON = 4.0f;	public final static String[] MOVEMENT_CHASSIS_NAMES = { "Building",			"Biped Mech", "Quad Mech", "Tracked Vehicle", "Wheeled Vehicle",			"Hovercraft", "VTOL", "Naval Vehicle", "Hydrofoil Vehicle",			"Submarine" };	protected Engine engine = null;	protected Armor armor = null;	protected Structure structure = null;	private TestEntityOption options = null;    public abstract Entity getEntity();	public abstract boolean isTank();	public abstract boolean isMech();	public abstract float getWeightControls();	public abstract float getWeightMisc();	public abstract int getWeightHeatSinks();	public abstract boolean hasDoubleHeatSinks();	public abstract int getCountHeatSinks();	public abstract String printWeightMisc();	public abstract String printWeightControls();	public abstract boolean correctEntity(StringBuffer buff);	public abstract boolean correctEntity(StringBuffer buff, boolean ignoreAmmo);	public abstract StringBuffer printEntity();	public abstract String getName();	public String fileString = null; // where the unit came from	public TestEntity(TestEntityOption options, Engine engine, Armor armor,			Structure structure) {		this.options = options;		this.engine = engine;		this.armor = armor;		this.structure = structure;	}	public boolean isClan() {		return getEntity().isClan();	}	public boolean isClanArmor() {		return getEntity().isClanArmor();	}	public float getWeight() {		return getEntity().getWeight();	}	public int getTotalOArmor() {		return getEntity().getTotalOArmor();	}	public String getLocationAbbr(int location) {		return getEntity().getLocationAbbr(location);	}	public float getWeightCeilingEngine() {		return options.getWeightCeilingEngine();	}	public float getWeightCeilingStructure() {		return options.getWeightCeilingStructure();	}	public float getWeightCeilingArmor() {		return options.getWeightCeilingArmor();	}	public float getWeightCeilingControls() {		return options.getWeightCeilingControls();	}	public float getWeightCeilingWeapons() {		return options.getWeightCeilingWeapons();	}	public float getWeightCeilingTargComp() {		return options.getWeightCeilingTargComp();	}	public float getWeightCeilingGyro() {		return options.getWeightCeilingGyro();	}	public float getWeightCeilingTurret() {		return options.getWeightCeilingTurret();	}	public float getWeightCeilingPowerAmp() {		return options.getWeightCeilingPowerAmp();	}	public float getMaxOverweight() {		return options.getMaxOverweight();	}	public boolean showOverweightedEntity() {		return options.showOverweightedEntity();	}	public float getMinUnderweight() {		return options.getMinUnderweight();	}	public boolean showUnderweightedEntity() {		return options.showUnderweightedEntity();	}	public boolean showCorrectArmor() {		return options.showCorrectArmor();	}	public boolean showCorrectCritical() {		return options.showCorrectCritical();	}	public boolean showFailedEquip() {		return options.showFailedEquip();	}	public boolean ignoreFailedEquip(String name) {		return options.ignoreFailedEquip(name);	}	public boolean skip() {		return options.skip();	}	public int getTargCompCrits() {		return options.getTargCompCrits();	}	public int getPrintSize() {		return options.getPrintSize();	}	protected static float ceil(float f, float type) {		return (float) Math.ceil(f * type) / type;	}	public static float ceilMaxHalf(float f, float type) {		if (type == CEIL_TON)			return ceil(f, CEIL_HALFTON);		return ceil(f, type);	}	protected static String makeWeightString(float weight) {		return (weight < 100 ? " " : "") + (weight < 10 ? " " : "")				+ Float.toString(weight)				+ ((Math.ceil(weight * 10) == weight * 10) ? "0" : "");	}	private boolean hasMASC() {		if (getEntity() instanceof Mech)			return ((Mech) getEntity()).hasMASC();		return false;	}	public String printShortMovement() {		return "Movement: "				+ Integer.toString(getEntity().getOriginalWalkMP())				+ "/"				+ Integer.toString((int) Math.ceil(getEntity()						.getOriginalWalkMP() * 1.5))				+ (hasMASC() ? "("						+ Integer.toString(getEntity().getOriginalWalkMP() * 2)						+ ")" : "")				+ (getEntity().getOriginalJumpMP() != 0 ? "/"						+ Integer.toString(getEntity().getOriginalJumpMP())						: "") + "\n";	}	public String printWeightHeatSinks() {		return StringUtil.makeLength(				"Heat Sinks: "						+ Integer.toString(getCountHeatSinks())						+ (hasDoubleHeatSinks() ? " ["								+ Integer.toString(2 * getCountHeatSinks())								+ "]" : ""), getPrintSize() - 5)				+ makeWeightString(getWeightHeatSinks()) + "\n";	}	public String printWeightEngine() {		return StringUtil.makeLength("Engine: " + engine.getEngineName(),				getPrintSize() - 5)				+ makeWeightString(getWeightEngine()) + "\n";	}	public float getWeightEngine() {		return engine.getWeightEngine(getWeightCeilingEngine());	}	public String printWeightStructure() {		return StringUtil.makeLength("Structure: "				+ Integer.toString(getEntity().getTotalOInternal()) + " "				+ structure.getShortName(), getPrintSize() - 5)				+ makeWeightString(getWeightStructure()) + "\n";	}	public float getWeightStructure() {		return structure.getWeightStructure(getWeight(),				getWeightCeilingStructure());	}	public String printWeightArmor() {		return StringUtil.makeLength("Armor: "				+ Integer.toString(getTotalOArmor()) + " "				+ armor.getShortName(), getPrintSize() - 5)				+ makeWeightString(getWeightArmor()) + "\n";	}	public float getWeightArmor() {		return armor.getWeightArmor(getTotalOArmor(), getWeightCeilingArmor());	}	public float getWeightMiscEquip(MiscType mt) {		if (mt.hasFlag(MiscType.F_HEAT_SINK)				|| mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK))			return 0f;		if (mt.hasFlag(MiscType.F_FERRO_FIBROUS))			return 0f;		if (mt.hasFlag(MiscType.F_ENDO_STEEL))			return 0f;		if (mt.hasFlag(MiscType.F_JUMP_JET)) {			return mt.getTonnage(getEntity());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& (mt.hasSubType(MiscType.S_HATCHET) || mt						.hasSubType(MiscType.S_MACE_THB))) {			return ceil(getWeight() / 15.0f, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_SWORD)) {			return ceilMaxHalf(getWeight() / 20.0f, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_MACE)) {			return ceilMaxHalf(getWeight() / 10.0f, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_PILE_DRIVER)) {			return ceilMaxHalf(10, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_CHAINSAW)) {			return ceilMaxHalf(5, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_DUAL_SAW)) {			return ceilMaxHalf(7, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_BACKHOE)) {			return ceilMaxHalf(5, getWeightCeilingWeapons());		} else if (mt.hasFlag(MiscType.F_MASC)) {			if (mt.getInternalName().equals("ISMASC"))				return Math.round(getWeight() / 20.0f);			else if (mt.getInternalName().equals("CLMASC"))				return Math.round(getWeight() / 25.0f);		} else if (mt.hasFlag(MiscType.F_TARGCOMP)) {			float fTons = 0.0f;			for (Mounted mo : getEntity().getWeaponList()) {				WeaponType wt = (WeaponType) mo.getType();				if (wt.hasFlag(WeaponType.F_DIRECT_FIRE))					fTons += wt.getTonnage(getEntity());			}			if (mt.getInternalName().equals("ISTargeting Computer"))				return ceil(fTons / 4.0f, getWeightCeilingTargComp());			else if (mt.getInternalName().equals("CLTargeting Computer"))				return ceil(fTons / 5.0f, getWeightCeilingTargComp());		} else if (mt.hasFlag(MiscType.F_VACUUM_PROTECTION)) {			return Math.round(getWeight() / 10.0f);		} else			return mt.getTonnage(getEntity());		return 0f;	}	public float getWeightMiscEquip() {		float weightSum = 0.0f;		for (Mounted m : getEntity().getMisc()) {			MiscType mt = (MiscType) m.getType();			weightSum += getWeightMiscEquip(mt);		}		return weightSum;	}	public StringBuffer printMiscEquip() {		return printMiscEquip(new StringBuffer());	}	public StringBuffer printMiscEquip(StringBuffer buff) {		return printMiscEquip(buff, 20, getPrintSize());	}	public StringBuffer printMiscEquip(StringBuffer buff, int posLoc,			int posWeight) {		for (Mounted m : getEntity().getMisc()) {			MiscType mt = (MiscType) m.getType();			if (m.getLocation() == Entity.LOC_NONE)				continue;			if (getWeightMiscEquip(mt) == 0f)				continue;			buff.append(StringUtil.makeLength(mt.getName(), 20));			buff.append(					StringUtil.makeLength(getLocationAbbr(m.getLocation()),							getPrintSize() - 5 - 20)).append(					makeWeightString(getWeightMiscEquip(mt)));			buff.append("\n");		}		return buff;	}	public float getWeightWeapon() {		float weight = 0.0f;		for (Mounted m : getEntity().getWeaponList()) {			WeaponType mt = (WeaponType) m.getType();			weight += mt.getTonnage(getEntity());		}		return weight;	}	public StringBuffer printWeapon() {		return printWeapon(new StringBuffer());	}	public StringBuffer printWeapon(StringBuffer buff) {		return printWeapon(buff, 20, getPrintSize());	}	public StringBuffer printWeapon(StringBuffer buff, int posLoc, int posWeight) {		for (Mounted m : getEntity().getWeaponList()) {			WeaponType mt = (WeaponType) m.getType();			// Don't think this can happen, but ...			if (m.getLocation() == Entity.LOC_NONE)				continue;			buff.append(StringUtil.makeLength(mt.getName(), 20));			buff.append(					StringUtil.makeLength(getLocationAbbr(m.getLocation()),							getPrintSize() - 5 - 20)).append(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -