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

📄 testentity.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					makeWeightString(mt.getTonnage(getEntity()))).append("\n");		}		return buff;	}	public float getWeightAmmo() {		float weight = 0.0f;		for (Mounted m : getEntity().getAmmo()) {			// One Shot Ammo			if (m.getLocation() == Entity.LOC_NONE)				continue;			AmmoType mt = (AmmoType) m.getType();			weight += mt.getTonnage(getEntity());		}		return weight;	}	public StringBuffer printAmmo() {		return printAmmo(new StringBuffer());	}	public StringBuffer printAmmo(StringBuffer buff) {		return printAmmo(buff, 20, getPrintSize());	}	public StringBuffer printAmmo(StringBuffer buff, int posLoc, int posWeight) {		for (Mounted m : getEntity().getAmmo()) {			AmmoType mt = (AmmoType) 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(					makeWeightString(mt.getTonnage(getEntity()))).append("\n");		}		return buff;	}	public String printLocations() {		StringBuffer buff = new StringBuffer();		for (int i = 0; i < getEntity().locations(); i++) {			String locationName = getEntity().getLocationName(i);			buff.append(locationName + ":");			buff.append("\n");			for (int j = 0; j < getEntity().getNumberOfCriticals(i); j++) {				CriticalSlot slot = getEntity().getCritical(i, j);				if (slot == null) {					buff.append(Integer.toString(j) + ". -Emtpy-");					buff.append("\n");				} else if (slot.getType() == CriticalSlot.TYPE_SYSTEM) {					if (isMech()) {						buff.append(Integer.toString(j));						buff.append(". ");						buff.append(((Mech) getEntity()).getSystemName(slot								.getIndex()));						buff.append("\n");					} else {						buff.append(Integer.toString(j)								+ ". UNKNOWN SYSTEM NAME");						buff.append("\n");					}				} else if (slot.getType() == CriticalSlot.TYPE_EQUIPMENT) {					Mounted m = getEntity().getEquipment(slot.getIndex());					buff.append(Integer.toString(j) + ". "							+ m.getType().getInternalName());					buff.append("\n");				}			}		}		return buff.toString();	}	public int calcMiscCrits(MiscType mt) {		if (mt.hasFlag(MiscType.F_CLUB)				&& (mt.hasSubType(MiscType.S_HATCHET)						|| mt.hasSubType(MiscType.S_SWORD) || mt						.hasSubType(MiscType.S_MACE_THB))) {			return (int) Math.ceil(getWeight() / 15.0);		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_MACE)) {			return (int) Math.ceil(getWeight() / 10.0);		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_PILE_DRIVER)) {			return 8;		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_CHAINSAW)) {			return 5;		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_DUAL_SAW)) {			return 7;		} else if (mt.hasFlag(MiscType.F_CLUB)				&& mt.hasSubType(MiscType.S_BACKHOE)) {			return 6;		} 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());			}			float weight = 0.0f;			if (mt.getInternalName().equals("ISTargeting Computer"))				weight = ceil(fTons / 4.0f, getWeightCeilingTargComp());			else if (mt.getInternalName().equals("CLTargeting Computer"))				weight = ceil(fTons / 5.0f, getWeightCeilingTargComp());			switch (getTargCompCrits()) {			case CEIL_TARGCOMP_CRITS:				return (int) Math.ceil(weight);			case ROUND_TARGCOMP_CRITS:				return Math.round(weight);			case FLOOR_TARGCOMP_CRITS:				return (int) Math.floor(weight);			}		} else if (EquipmentType.getArmorTypeName(				EquipmentType.T_ARMOR_FERRO_FIBROUS).equals(				mt.getInternalName())) {			if (isClanArmor())				return 7;			return 14;		} else if (EquipmentType.getArmorTypeName(				EquipmentType.T_ARMOR_FERRO_FIBROUS_PROTO).equals(				mt.getInternalName())) {			return 16;		} else if (EquipmentType.getArmorTypeName(				EquipmentType.T_ARMOR_LIGHT_FERRO).equals(mt.getInternalName())) {			return 7;		} else if (EquipmentType.getArmorTypeName(				EquipmentType.T_ARMOR_HEAVY_FERRO).equals(mt.getInternalName())) {			return 21;		} else if (EquipmentType.getStructureTypeName(				EquipmentType.T_STRUCTURE_ENDO_STEEL).equals(				mt.getInternalName())) {			if (isClan())				return 7;			return 14;		} else if (EquipmentType.getStructureTypeName(				EquipmentType.T_STRUCTURE_ENDO_PROTOTYPE).equals(				mt.getInternalName())) {			return 16;		}		return mt.getCriticals(getEntity());	}	public float calculateWeight() {		float weight = 0;		weight += getWeightEngine();		weight += getWeightStructure();		weight += getWeightControls();		weight += getWeightHeatSinks();		weight += getWeightArmor();		weight += getWeightMisc();		weight += getWeightMiscEquip();		weight += getWeightWeapon();		weight += getWeightAmmo();		weight += getWeightCarryingSpace();		return weight;	}	public String printWeightCalculation() {		return printWeightEngine() + printWeightStructure()				+ printWeightControls() + printWeightHeatSinks()				+ printWeightArmor() + printWeightMisc()				+ printWeightCarryingSpace() + "Equipment:\n"				+ printMiscEquip() + printWeapon() + printAmmo();	}	public boolean correctWeight(StringBuffer buff) {		return correctWeight(buff, showOverweightedEntity(),				showUnderweightedEntity());	}	public boolean correctWeight(StringBuffer buff, boolean showO, boolean showU) {		float weightSum = calculateWeight();		float weight = getWeight();		if (showO && weight + getMaxOverweight() < weightSum) {			buff.append("Weight: ").append(calculateWeight()).append(					" is greater then ").append(getWeight()).append("\n");			// buff.append(printWeightCalculation()).append("\n");			return false;		}		if (showU && weight - getMinUnderweight() > weightSum) {			buff.append("Weight: ").append(calculateWeight()).append(					" is lesser then ").append(getWeight()).append("\n");			// buff.append(printWeightCalculation()).append("\n");			return false;		}		return true;	}	public boolean hasIllegalTechLevels(StringBuffer buff) {		return hasIllegalTechLevels(buff, true);	}	public boolean hasIllegalTechLevels(StringBuffer buff, boolean ignoreAmmo) {		boolean retVal = false;		int eTechLevel = getEntity().getTechLevel();		for (Mounted mounted : getEntity().getEquipment()) {			EquipmentType nextE = mounted.getType();			if ((ignoreAmmo) && (nextE instanceof AmmoType)) {				continue;			} else if (!(TechConstants.isLegal(eTechLevel,					nextE.getTechLevel(), true))) {				if (!retVal)					buff.append("Equipment illegal at unit's tech level:\n");				retVal = true;				buff.append(nextE.getName()).append("\n");			}		}		return retVal;	}	public boolean hasFailedEquipment(StringBuffer buff) {		boolean hasFailedEquipment = false;		for (Enumeration e = getEntity().getFailedEquipment(); e				.hasMoreElements();) {			String name = (String) e.nextElement();			if (!ignoreFailedEquip(name)) {				if (!hasFailedEquipment)					buff.append("Equipment that Failed to Load:\n");				buff.append(name).append("\n");				hasFailedEquipment = true;			}		}		return hasFailedEquipment;	}	public StringBuffer printFailedEquipment(StringBuffer buff) {		if (getEntity().getFailedEquipment().hasMoreElements())			buff.append("Equipment that Failed to Load:\n");		for (Enumeration e = getEntity().getFailedEquipment(); e				.hasMoreElements();)			buff.append(e.nextElement()).append("\n");		return buff;	}	public int getWeightCarryingSpace() {		return getEntity().getTroopCarryingSpace();	}	public String printWeightCarryingSpace() {		if (getEntity().getTroopCarryingSpace() != 0)			return StringUtil.makeLength("Carrying Capacity:",					getPrintSize() - 5)					+ makeWeightString(getEntity().getTroopCarryingSpace())					+ "\n";		return "";	}	public String printArmorLocation(int loc) {		if (getEntity().hasRearArmor(loc))			return StringUtil.makeLength(					getEntity().getLocationAbbr(loc) + ":", 5)					+ StringUtil.makeLength(getEntity().getOInternal(loc), 4)					+ StringUtil.makeLength(getEntity().getOArmor(loc), 3)					+ " / "					+ StringUtil							.makeLength(getEntity().getOArmor(loc, true), 2);		return StringUtil.makeLength(				getEntity().getLocationAbbr(loc) + ":", 5)				+ StringUtil.makeLength(getEntity().getOInternal(loc), 4)				+ StringUtil.makeLength(getEntity().getOArmor(loc), 6)				+ "  ";	}	public String printArmorPlacement() {		StringBuffer buff = new StringBuffer();		buff.append("Armor Placement:\n");		for (int loc = 0; loc < getEntity().locations(); loc++) {			buff.append(printArmorLocation(loc)).append("\n");		}		return buff.toString();	}	public String printTechLevel() {		return "Chassis: "				+ MOVEMENT_CHASSIS_NAMES[getEntity().getMovementMode()] + " - "				+ TechConstants.getLevelName(getEntity().getTechLevel()) + " ("				+ Integer.toString(getEntity().getYear()) + ")\n";	}} // End class TestEntityclass Armor {	public final static int CLAN_ARMOR = 0x01;	private int armorType;	private int armorFlags;	public Armor(int armorType, int armorFlags) {		this.armorType = armorType;		this.armorFlags = armorFlags;	}	public float getWeightArmor(int totalOArmor, float roundWeight) {		return getWeightArmor(armorType, armorFlags, totalOArmor, roundWeight);	}	public static float getWeightArmor(int armorType, int armorFlags,			int totalOArmor, float roundWeight) {		float points = totalOArmor;		if (armorType == EquipmentType.T_ARMOR_FERRO_FIBROUS				|| armorType == EquipmentType.T_ARMOR_FERRO_FIBROUS_PROTO) {			if ((armorFlags & CLAN_ARMOR) != 0)				points /= 1.2f;			else				points /= 1.12f;		} else if (armorType == EquipmentType.T_ARMOR_LIGHT_FERRO) {			points /= 1.06f;		} else if (armorType == EquipmentType.T_ARMOR_HEAVY_FERRO) {			points /= 1.24f;		}		float pointsPerTon = 16.0f;		if (armorType == EquipmentType.T_ARMOR_HARDENED)			pointsPerTon = 8.0f;		float armorWeight = Math.round(points) / pointsPerTon;		return TestEntity.ceilMaxHalf(armorWeight, roundWeight);	}	public String getShortName() {		return "(" + EquipmentType.getArmorTypeName(armorType) + ")";	}} // end class Armorclass Structure {	public final static int CLAN_STRUCTURE = 0x01;	private int structureType;	private int structureFlags;	public Structure(int structureType, int structureFlags) {		this.structureType = structureType;		this.structureFlags = structureFlags;	}	public float getWeightStructure(float weight, float roundWeight) {		return getWeightStructure(structureType, weight, roundWeight);	}	public static float getWeightStructure(int structureType, float weight,			float roundWeight) {		if (structureType == EquipmentType.T_STRUCTURE_ENDO_STEEL) {			return TestEntity.ceilMaxHalf(weight / 20.0f, roundWeight);		} else if (structureType == EquipmentType.T_STRUCTURE_ENDO_PROTOTYPE) {			return TestEntity.ceilMaxHalf(weight / 20.0f, roundWeight);		} else if (structureType == EquipmentType.T_STRUCTURE_REINFORCED) {			return TestEntity.ceilMaxHalf(weight / 5.0f, roundWeight);		} else if (structureType == EquipmentType.T_STRUCTURE_COMPOSITE) {			return TestEntity.ceilMaxHalf(weight / 20.0f, roundWeight);		}		return weight / 10.0f;	}	public String getShortName() {		return "(" + EquipmentType.getStructureTypeName(structureType) + ")";	}} // End class Structure

⌨️ 快捷键说明

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