📄 movestep.java
字号:
setTurning(false); break; } // update prone state if (stepType == MovePath.STEP_GO_PRONE) { setProne(true); setHullDown(false); } else if (stepType == MovePath.STEP_GET_UP) { setProne(false); setHullDown(false); } else if (stepType == MovePath.STEP_HULL_DOWN) { setProne(false); setHullDown(true); } } public int getTotalHeat() { return totalHeat; } public int getHeat() { return heat; } /** * Amount of movement points required to move from start to dest */ protected void calcMovementCostFor(IGame game, Coords prev, int prevEl) { final int moveType = parent.getEntity().getMovementMode(); final IHex srcHex = game.getBoard().getHex(prev); final IHex destHex = game.getBoard().getHex(getPosition()); final boolean isInfantry = parent.getEntity() instanceof Infantry; final boolean isProto = parent.getEntity() instanceof Protomech; int nSrcEl = srcHex.getElevation() + prevEl; int nDestEl = destHex.getElevation() + elevation; mp = 1; // jumping always costs 1 if (parent.isJumping()) { return; } // VTOLs pay 1 for everything if (moveType == IEntityMovementMode.VTOL) { return; } // Account for terrain, unless we're moving along a road. if (!isPavementStep) { if ( (moveType != IEntityMovementMode.BIPED_SWIM) && (moveType != IEntityMovementMode.QUAD_SWIM) ) mp += destHex.movementCost(moveType); // non-hovers, non-navals and non-VTOLs check for water depth and are affected by swamp if ((moveType != IEntityMovementMode.HOVER) && (moveType != IEntityMovementMode.NAVAL) && (moveType != IEntityMovementMode.HYDROFOIL) && (moveType != IEntityMovementMode.SUBMARINE) && (moveType != IEntityMovementMode.VTOL) && (moveType != IEntityMovementMode.BIPED_SWIM) && (moveType != IEntityMovementMode.QUAD_SWIM)) { //no additional cost when moving on surface of ice. if (!destHex.containsTerrain(Terrains.ICE) || nDestEl < destHex.surface()) { if (destHex.terrainLevel(Terrains.WATER) == 1) { mp++; } else if (destHex.terrainLevel(Terrains.WATER) > 1) { mp += 3; } } } } // End not-along-road if (nSrcEl != nDestEl) { int delta_e = Math.abs(nSrcEl - nDestEl); // non-flying Infantry and ground vehicles are charged double. if ((isInfantry && !(moveType == IEntityMovementType.MOVE_VTOL_WALK || moveType == IEntityMovementType.MOVE_VTOL_RUN)) || (moveType == IEntityMovementMode.TRACKED || moveType == IEntityMovementMode.WHEELED || moveType == IEntityMovementMode.HOVER)) { delta_e *= 2; } mp += delta_e; } // If we entering a building, all non-infantry pay additional MP. if (nDestEl < destHex.terrainLevel(Terrains.BLDG_ELEV) && !(isInfantry) && !(isProto)) { Building bldg = game.getBoard().getBuildingAt(getPosition()); mp += bldg.getType(); } } /** * Is movement possible from a previous position to this one? * <p/> * This function does not comment on whether an overall movement path * is possible, just whether the <em>current</em> step is possible. */ public boolean isMovementPossible(IGame game, Coords src, int srcEl) { final IHex srcHex = game.getBoard().getHex(src); final Coords dest = this.getPosition(); final IHex destHex = game.getBoard().getHex(dest); final Entity entity = parent.getEntity(); if (null == dest) { throw new IllegalStateException( "Step has no position." ); } if (src.distance(dest) > 1) { StringBuffer buf = new StringBuffer(); buf.append( "Coordinates " ) .append( src.toString() ) .append( " and " ) .append( dest.toString() ) .append( " are not adjacent." ); throw new IllegalArgumentException( buf.toString() ); } // If we're a tank and immobile, check if we try to unjam // or eject and the crew is not unconscious if ( entity instanceof Tank && !entity.getCrew().isUnconscious() && ( type == MovePath.STEP_UNJAM_RAC || type == MovePath.STEP_EJECT || type == MovePath.STEP_SEARCHLIGHT) ) { return true; } // super-easy if (entity.isImmobile()) { return false; } // another easy check if (!game.getBoard().contains(dest)) { return false; } // can't enter impassable hex if(destHex.containsTerrain(Terrains.IMPASSABLE)) { return false; } final int srcAlt = srcEl + srcHex.getElevation(); final int destAlt = elevation + destHex.getElevation(); // Can't back up across an elevation change. if ( !(entity instanceof VTOL) && isThisStepBackwards() && ( destAlt != srcAlt ) ) { return false; } // Swarming entities can't move. if (Entity.NONE != entity.getSwarmTargetId()) { return false; } // The entity is trying to load. Check for a valid move. if (type == MovePath.STEP_LOAD) { // Transports can't load after the first step. if (!firstStep) { return false; } // Find the unit being loaded. Entity other = null; Enumeration entities = game.getEntities(src); while (entities.hasMoreElements()) { // Is the other unit friendly and not the current entity? other = (Entity) entities.nextElement(); if (!entity.getOwner().isEnemyOf(other.getOwner()) && !entity.equals(other)) { // The moving unit should be able to load the other unit. if (!entity.canLoad(other)) { return false; } // The other unit should be able to have a turn. if (!other.isLoadableThisTurn()) { return false; } // We can stop looking. break; } // Nope. Discard it. other = null; } // Check the next entity in this position. // We were supposed to find someone to load. if (other == null) { return false; } } // End STEP_LOAD-checks // mechs dumping ammo can't run boolean bDumping = false; for(Mounted mo : entity.getAmmo()) { if (mo.isDumping()) { bDumping = true; break; } } if (bDumping && (movementType == IEntityMovementType.MOVE_RUN || movementType == IEntityMovementType.MOVE_VTOL_RUN || movementType == IEntityMovementType.MOVE_JUMP)) { return false; } // check elevation difference > max int nMove = entity.getMovementMode(); // Make sure that if it's a VTOL unit with the VTOL MP listed as jump MP... // That it can't jump. if ((movementType == IEntityMovementType.MOVE_JUMP) && (nMove == IEntityMovementMode.VTOL)) { return false; } if ( movementType != IEntityMovementType.MOVE_JUMP && (nMove != IEntityMovementMode.VTOL) && ( Math.abs(srcAlt - destAlt) > entity.getMaxElevationChange() ) ) { return false; } // Units moving backwards may not change elevation levels. // (Ben thinks this rule is dumb) if ((type == MovePath.STEP_BACKWARDS || type == MovePath.STEP_LATERAL_LEFT_BACKWARDS || type == MovePath.STEP_LATERAL_RIGHT_BACKWARDS) && destAlt != srcAlt && !(entity instanceof VTOL)) { return false; } // Can't run into water unless hovering, naval, first step, using a bridge, or fly. if ((movementType == IEntityMovementType.MOVE_RUN || movementType == IEntityMovementType.MOVE_VTOL_RUN) && nMove != IEntityMovementMode.HOVER && nMove != IEntityMovementMode.NAVAL && nMove != IEntityMovementMode.HYDROFOIL && nMove != IEntityMovementMode.SUBMARINE && nMove != IEntityMovementMode.VTOL && destHex.terrainLevel(Terrains.WATER) > 0 && !(destHex.containsTerrain(Terrains.ICE) && elevation >= 0) && !dest.equals(entity.getPosition()) && !firstStep && !isPavementStep) { return false; } // ugh, stacking checks. well, maybe we're immune! if ( !parent.isJumping() && type != MovePath.STEP_CHARGE && type != MovePath.STEP_DFA ) { // can't move a mech into a hex with an enemy mech if (entity instanceof Mech && Compute.isEnemyIn(game, entity.getId(), dest, true)) { return false; } // Can't move out of a hex with an enemy unit unless we started // there, BUT we're allowed to turn, unload, or go prone. if ( Compute.isEnemyIn(game, entity.getId(), src, false, getElevation()) && !src.equals(entity.getPosition()) && type != MovePath.STEP_TURN_LEFT && type != MovePath.STEP_TURN_RIGHT && type != MovePath.STEP_UNLOAD && type != MovePath.STEP_GO_PRONE ) { return false; } } // can't jump over too-high terrain if (movementType == IEntityMovementType.MOVE_JUMP && ( destAlt > (entity.getElevation() + entity.game.getBoard().getHex(entity.getPosition()).getElevation() + entity.getJumpMPWithTerrain() + (type == MovePath.STEP_DFA?1:0)) ) ) { return false; } // Certain movement types have terrain restrictions; terrain // restrictions are lifted when moving along a road or bridge, // or when flying. Naval movement does not have the pavement // exemption. if (entity.isHexProhibited(destHex) && (!isPavementStep() || nMove == IEntityMovementMode.NAVAL || nMove == IEntityMovementMode.HYDROFOIL || nMove == IEntityMovementMode.SUBMARINE) && movementType != IEntityMovementType.MOVE_VTOL_WALK && movementType != IEntityMovementType.MOVE_VTOL_RUN) { // We're allowed to pass *over* invalid // terrain, but we can't end there. if (parent.isJumping()) { terrainInvalid = true; } else { // This is an illegal move. return false; } } //Jumping into a building hex below the roof ends the move //assume this applies also to sylph vtol movement if(!(src.equals(dest)) && src != entity.getPosition() && (parent.isJumping() || entity.getMovementMode() == IEntityMovementMode.VTOL) && srcEl < srcHex.terrainLevel(Terrains.BLDG_ELEV)) { return false; } // If we are *in* restricted terrain, we can only leave via roads. if ( movementType != IEntityMovementType.MOVE_JUMP && movementType != IEntityMovementType.MOVE_VTOL_WALK && movementType != IEntityMovementType.MOVE_VTOL_RUN && entity.isHexProhibited(srcHex) && !isPavementStep ) { return false; } if( type == MovePath.STEP_UP) { if(!(entity.canGoUp(elevation-1, getPosition()))) { return false; } } if( type == MovePath.STEP_DOWN) { if(!(entity.canGoDown(elevation+1,getPosition()))) { return false;//We can't intentionally crash. } } if (entity instanceof VTOL) { if((type == MovePath.STEP_BACKWARDS) || (type == MovePath.STEP_FORWARDS) || (type == MovePath.STEP_LATERAL_LEFT) || (type == MovePath.STEP_LATERAL_LEFT_BACKWARDS) || (type == MovePath.STEP_LATERAL_RIGHT) || (type == MovePath.STEP_LATERAL_RIGHT_BACKWARDS) || (type == MovePath.STEP_TURN_LEFT) || (type == MovePath.STEP_TURN_RIGHT)) { if(elevation==0) {//can't move on the ground. return false; } } } if ((entity instanceof VTOL) && (type == MovePath.STEP_BACKWARDS || type == MovePath.STEP_FORWARDS)) { if (elevation<=(destHex.ceiling()-destHex.surface())) { return false; //can't fly into woods or a cliff face } } //check the elevation is valid for the type of entity and hex if (type != MovePath.STEP_DFA && !entity.isElevationValid(elevation, destHex)) { if(parent.isJumping()) { terrainInvalid = true; } else { return false; } } return true; } //Used by BoardView to see if we can re-use an old movement sprite. public boolean canReuseSprite(MoveStep other) { // Assume that we *can't* reuse the sprite, and prove ourself wrong. boolean reuse = false; if (this.type == other.type && this.facing == other.facing && this.mpUsed == other.mpUsed && this.movementType == other.movementType && this.isProne == other.isProne && this.isHullDown == other.isHullDown && this.danger == other.danger && this.pastDanger == other.pastDanger && this.isUsingMASC == other.isUsingMASC && this.targetNumberMASC == other.targetNumberMASC && this.isPavementStep == other.isPavementStep && this.elevation == other.elevation && this.isLegalEndPos() && other.isLegalEndPos() ) { reuse = true; } return reuse; } public int getElevation() { return elevation; } public int getMineToLay() { return mineToLay; } public void setMineToLay(int mineId) { mineToLay = mineId; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -