📄 entity.java
字号:
minAlt = hex.floor(); break; default: return false; } return (altitude > minAlt); } /** * is it possible to go up, or are we at maximum altitude? * assuming passed elevation. */ public boolean canGoUp(int assumedElevation,Coords assumedPos) { IHex hex = getGame().getBoard().getHex(assumedPos); int altitude = assumedElevation + hex.surface(); int maxAlt = hex.surface(); switch(getMovementMode()) { case IEntityMovementMode.INF_JUMP: case IEntityMovementMode.INF_LEG: case IEntityMovementMode.INF_MOTORIZED: maxAlt += Math.max(0, hex.terrainLevel(Terrains.BLDG_ELEV)); break; case IEntityMovementMode.VTOL: maxAlt = hex.surface() + 50; break; case IEntityMovementMode.SUBMARINE: case IEntityMovementMode.BIPED_SWIM: case IEntityMovementMode.QUAD_SWIM: maxAlt = hex.surface(); break; default: return false; } return (altitude < maxAlt); } /** * Check if this entity can legally occupy the requested elevation. * Does not check stacking, only terrain limitations */ public boolean isElevationValid(int assumedElevation, IHex hex) { int altitude = assumedElevation + hex.surface(); if(getMovementMode() == IEntityMovementMode.VTOL) { if(this instanceof Infantry && (hex.containsTerrain(Terrains.BUILDING) || hex.containsTerrain(Terrains.WOODS) || hex.containsTerrain(Terrains.JUNGLE))) { //VTOL BA (sylph) can move as ground unit as well return (assumedElevation <=50 && altitude >= hex.floor()); } else if(hex.containsTerrain(Terrains.WOODS) || hex.containsTerrain(Terrains.WATER) || hex.containsTerrain(Terrains.JUNGLE)) { return (assumedElevation <=50 && altitude > hex.ceiling()); } return (assumedElevation <=50 && altitude >= hex.ceiling()); } else if (getMovementMode() == IEntityMovementMode.SUBMARINE || (getMovementMode() == IEntityMovementMode.QUAD_SWIM&& hasUMU()) || (getMovementMode() == IEntityMovementMode.BIPED_SWIM&& hasUMU())) { return (altitude >= hex.floor() && altitude <= hex.surface()); } else if (getMovementMode() == IEntityMovementMode.HYDROFOIL || getMovementMode() == IEntityMovementMode.NAVAL){ return altitude == hex.surface(); } else { //regular ground units if(hex.containsTerrain(Terrains.ICE) || (getMovementMode() == IEntityMovementMode.HOVER && hex.containsTerrain(Terrains.WATER))) { //surface of ice is OK, surface of water is OK for hovers if(altitude == hex.surface()) return true; } //only mechs can move underwater if(hex.containsTerrain(Terrains.WATER) && altitude < hex.surface() && !(this instanceof Mech) && !(this instanceof Protomech)) return false; // can move on the ground unless its underwater if(altitude == hex.floor()) return true; if(hex.containsTerrain(Terrains.BRIDGE)) { //can move on top of a bridge if(assumedElevation == hex.terrainLevel(Terrains.BRIDGE_ELEV)) return true; } if(hex.containsTerrain(Terrains.BUILDING)) { //Mechs, protos and infantry can occupy any floor in the building if(this instanceof Mech || this instanceof Protomech || this instanceof Infantry) { if(altitude >= hex.floor() && altitude <= hex.ceiling()) return true; } } } return false; } /** * Returns the height of the unit, that is, how many levels above * it's elevation is it for LOS purposes. * * Default is 0. */ public int height() { return 0; } /** * Returns the absolute height of the entity */ public int absHeight() { return getElevation() + height(); } /** * Returns the display name for this entity. */ public String getDisplayName() { if (displayName == null) { generateDisplayName(); } return displayName; } /** * Generates the display name for this entity. * <p/> * Sub-classes are allowed to override this method. * * The display name is in the format [Chassis] [Model] ([Player Name]). */ public void generateDisplayName() { StringBuffer nbuf = new StringBuffer(); nbuf.append(chassis); if (model != null && model.length() > 0) { nbuf.append(" ").append(model); } // if show unit id is on, append the id if (PreferenceManager.getClientPreferences().getShowUnitId()) { nbuf.append(" ID:").append(this.getId()); } else if (duplicateMarker > 1) { //if not, and a player has more than one unit with the same name, // append "#N" after the model to differentiate. nbuf.append(" #" + duplicateMarker); } if (getOwner() != null) { nbuf.append(" (").append(getOwner().getName()).append(")"); } if (PreferenceManager.getClientPreferences().getShowUnitId()) { nbuf.append(" ID:").append(this.getId()); } this.displayName = nbuf.toString(); } /** * A short name, suitable for displaying above a unit icon. The short name * is basically the same as the display name, minus the player name. */ public String getShortName() { if (shortName == null) { generateShortName(); } return shortName; } /** * Generate the short name for a unit * <p/> * Sub-classes are allowed to override this method. * * The display name is in the format [Chassis] [Model]. */ public void generateShortName() { StringBuffer nbuf = new StringBuffer(); nbuf.append(chassis); if (model != null && model.length() > 0) { nbuf.append(" ").append(model); } // if show unit id is on, append the id if (PreferenceManager.getClientPreferences().getShowUnitId()) { nbuf.append(" ID:").append(this.getId()); } else if (duplicateMarker > 1) { // if not, and a player has more than one unit with the same name, // append "#N" after the model to differentiate. nbuf.append(" #" + duplicateMarker); } this.shortName = nbuf.toString(); } public String getShortNameRaw() { StringBuffer nbuf = new StringBuffer(); nbuf.append(chassis); if (model != null && model.length() > 0) { nbuf.append(" ").append(model); } return nbuf.toString(); } /** * Returns the primary facing, or -1 if n/a */ public int getFacing() { return facing; } /** * Sets the primary facing. */ public void setFacing(int facing) { this.facing = facing; if (game != null) game.processGameEvent(new GameEntityChangeEvent(this, this)); } /** * Returns the secondary facing, or -1 if n/a */ public int getSecondaryFacing() { return sec_facing; } /** * Sets the secondary facing. */ public void setSecondaryFacing(int sec_facing) { this.sec_facing = sec_facing; if (game != null) game.processGameEvent(new GameEntityChangeEvent(this, this)); } /** * Can this entity change secondary facing at all? */ public abstract boolean canChangeSecondaryFacing(); /** * Can this entity torso/turret twist the given direction? */ public abstract boolean isValidSecondaryFacing(int dir); /** * Returns the closest valid secondary facing to the given direction. * * @return the the closest valid secondary facing. */ public abstract int clipSecondaryFacing(int dir); /** * Returns true if the entity has an RAC */ public boolean hasRAC() { for(Mounted mounted : getWeaponList()) { WeaponType wtype = (WeaponType)mounted.getType(); if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { return true; } } return false; } /** * Returns true if the entity has an RAC which is jammed and not destroyed */ public boolean canUnjamRAC() { for (Mounted mounted : getWeaponList()) { WeaponType wtype = (WeaponType)mounted.getType(); if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY && mounted.isJammed() && !mounted.isDestroyed()) { return true; } } return false; } /** * Returns true if the entity can flip its arms */ public boolean canFlipArms() { return false; } /** * Returns this entity's original walking movement points */ public int getOriginalWalkMP() { return walkMP; } /** * Sets this entity's original walking movement points */ public void setOriginalWalkMP(int walkMP) { this.walkMP = walkMP; } /** * Returns this entity's walking/cruising mp, factored * for heat and gravity. */ public int getWalkMP() { return getWalkMP(true); } /** * Returns this entity's walking/cruising mp, factored * for heat and possibly gravity. * * @param gravity: Should the movement be factored for gravity */ public int getWalkMP( boolean gravity ) { int mp = this.walkMP; int minus=0; if (game != null && game.getOptions().booleanOption("maxtech_heat")) { if (heat<30) { minus = (heat / 5); } else if (heat>=49) { minus = 9; } else if (heat>=43) { minus = 8; } else if (heat>=37) { minus = 7; } else if (heat>=31) { minus = 6; } mp = Math.max(mp-minus,0); } else { mp = Math.max(mp - (heat / 5), 0); } mp = applyGravityEffectsOnMP(mp); return mp; } /** * For non-'Mechs, this is really boring, but... */ public int getStandingHeat() { return 0; } /** * For non-'Mechs, this is really boring, but... */ public int getWalkHeat() { return 0; } /** * Returns this entity's unmodified running/flank mp. */ protected int getOriginalRunMP() { return (int)Math.ceil(getOriginalWalkMP() * 1.5); } /** * Returns this entity's running/flank mp modified for heat. */ public int getRunMP() { return getRunMP(true); } public int getRunMP(boolean gravity) { return (int)Math.ceil(getWalkMP(gravity) * 1.5); } public int getRunMPwithoutMASC() { return getRunMPwithoutMASC(true); } public abstract int getRunMPwithoutMASC(boolean gravity); /** * Returns this entity's running/flank mp as a string. */ public String getRunMPasString() { return Integer.toString(getRunMP()); } /** * For non-'Mechs, this is really boring, but... */ public int getRunHeat() { return 0; } /** * Returns this entity's original jumping mp. */ public int getOriginalJumpMP() { return jumpMP; } /** * Sets this entity's original jump movement points */ public void setOriginalJumpMP(int jumpMP) { this.jumpMP = jumpMP; } /** * Returns this entity's current jumping MP, not effected by terrain, * factored for gravity. */ public int getJumpMP() { return applyGravityEffectsOnMP(jumpMP); } public int getJumpType() { return 0; } /** * For non-'Mechs, this is really boring, but... */ public int getJumpHeat(int movedMP) { return 0; } /** * Returns this entity's current jumping MP, effected by terrain (like * water.) */ public int getJumpMPWithTerrain() { return getJumpMP(); } /** * Returns the elevation that this entity would be on if it were placed * into the specified hex. * Hovercraft, naval vessels, and hydrofoils move on the surface of the water */ public int elevationOccupied(IHex hex) { if (hex == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -