📄 gunemplacement.java
字号:
/* * MegaMek - Copyright (C) 2000-2003 Ben Mazur (bmazur@sev.org) * Copyright (C) 2005 Mike Gratton <mike@vee.net> * * 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. */package megamek.common;import java.util.Enumeration;import java.util.Vector;import java.io.Serializable;/** * A building with weapons fitted and, optionally, a turret. */public class GunEmplacement extends Entity implements Serializable { private String name = null; private int cf = 40; // default is a medium building w/ CF 40 private int height = 2; // default height is 2 private boolean turretNotExists = false; private boolean turretLocked = false; private boolean burning = false; // locations public static final int LOC_BUILDING = 0; public static final int LOC_NORTH = 1; public static final int LOC_EAST = 2; public static final int LOC_WEST = 3; public static final int LOC_TURRET = 4; public static final String[] HIT_LOCATION_NAMES = { "Building", "Turret" }; private static int[] CRITICAL_SLOTS = new int[] {0, 0, 0, 0, 0}; private static String[] LOCATION_ABBRS = { "BU", "N", "E", "W", "TU" }; private static String[] LOCATION_NAMES = { "Building", "North", "East", "West", "Turret" }; public GunEmplacement() { // set defaults as specified in BMRr initConstructionFactor(40); setHeight(2); // not actually specfied defaults, but hey, it seems reasonable setTurret(false); initTurretArmor(0); initializeInternal(IArmorState.ARMOR_NA, LOC_NORTH); initializeInternal(IArmorState.ARMOR_NA, LOC_EAST); initializeInternal(IArmorState.ARMOR_NA, LOC_WEST); } public boolean hasTurret() { return !this.turretNotExists; } public void setTurret(boolean turret) { this.turretNotExists = !turret; if (!turret) { super.setSecondaryFacing(-1); } } public boolean isTurretLocked() { return this.turretLocked; } public void setTurretLocked(boolean locked) { this.turretLocked = locked; } public int getConstructionFactor() { return this.cf; } public void setConstructionFactor(int cf) { this.cf = cf; setWeight(cf); } public void initConstructionFactor(int cf) { setConstructionFactor(cf); initializeArmor(cf, GunEmplacement.LOC_BUILDING); setArmorType(EquipmentType.T_ARMOR_STANDARD); setArmorTechLevel(TechConstants.T_IS_LEVEL_1); initializeInternal(IArmorState.ARMOR_NA, LOC_BUILDING); } public void initTurretArmor(int af) { initializeArmor(af, GunEmplacement.LOC_TURRET); initializeInternal(IArmorState.ARMOR_NA, LOC_TURRET); } public int getCurrentTurretArmor() { return getArmor(LOC_TURRET); } /////////// Building methods /////////// public String getName() { return name; } public boolean isIn(Coords coords) { return getPosition().equals(coords); } public Enumeration getCoords() { // XXX yuck! Vector coords = new Vector(1); coords.add(getPosition()); return coords.elements(); } public int getConstructionType() { if (this.cf <= 15) { return Building.LIGHT; } if (this.cf <= 40) { return Building.MEDIUM; } if (this.cf <= 90) { return Building.HEAVY; } if (this.cf <= 150) { return Building.HARDENED; } return Building.UNKNOWN; } public int getCurrentCF() { return getArmor(LOC_BUILDING); } // XXX how to handle this? public void setCurrentCF(int cf) { if (cf < 0) { throw new IllegalArgumentException ("Invalid value for Construction Factor: " + cf); } //this.currentCF = cf; } // XXX how to handle this? public int getPhaseCF() { return getArmor(LOC_BUILDING); } // XXX how to handle this? public void setPhaseCF( int cf ) { if ( cf < 0 ) { throw new IllegalArgumentException ( "Invalid value for Construction Factor: " + cf ); } //this.phaseCF = cf; } public boolean isBurning() { return this.burning; } public void setBurning(boolean burning) { this.burning = burning; } /////////// Entity methods /////////// public int height() { return this.height; } public void setHeight(int height) { this.height = height; } public boolean isImmobile() { return true; } public boolean isEligibleForMovement() { return false; } public String getMovementString(int mtype) { return "Not possible!"; } public String getMovementAbbr(int mtype) { return "!"; } public boolean isHexProhibited(IHex hex) { // can't put on top of an existing building return hex.containsTerrain(Terrains.BUILDING) ; } public int getWalkMP(boolean gravity) { return 0; } public boolean canChangeSecondaryFacing() { return hasTurret() && !turretLocked; } public boolean isValidSecondaryFacing(int n) { return hasTurret() && !turretLocked; } public int clipSecondaryFacing(int n) { return n; } public void setSecondaryFacing(int sec_facing) { if (!turretLocked) { super.setSecondaryFacing(sec_facing); } } public void setFacing(int facing) { super.setFacing(0); } public String[] getLocationAbbrs() { return LOCATION_ABBRS; } public String[] getLocationNames() { return LOCATION_NAMES; } public int locations() { return hasTurret() ? LOCATION_ABBRS.length : LOCATION_ABBRS.length - 1; } public boolean hasRearArmor(int loc) { return false; } public int getWeaponArc(int weaponId) { switch (getEquipment(weaponId).getLocation()) { case LOC_NORTH: return Compute.ARC_NORTH; case LOC_EAST: return Compute.ARC_EAST; case LOC_WEST: return Compute.ARC_WEST; case LOC_TURRET: return Compute.ARC_FORWARD; default: return Compute.ARC_360; } } public boolean isSecondaryArcWeapon(int weaponId) { if (getEquipment(weaponId).getLocation() == LOC_TURRET) { return true; } return false; } public int sideTable(Coords src) { return ToHitData.SIDE_FRONT; } public HitData rollHitLocation(int table, int side, int aimedLocation, int aimingMode) { if (aimedLocation != LOC_NONE && aimingMode == IAimingModes.AIM_MODE_IMMOBILE) { switch (Compute.d6(2)) { case 6: case 7: case 8: return new HitData((aimedLocation == LOC_BUILDING) ? LOC_BUILDING : LOC_TURRET, false, true); } } return rollHitLocation(table, side); } public HitData rollHitLocation(int table, int side) { int armorLoc = LOC_BUILDING; int effect = HitData.EFFECT_NONE; switch (Compute.d6(2)) { case 2: // ASSUMTION: damage goes to main building
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -