Class Terrain

java.lang.Object
megamek.common.Terrain
All Implemented Interfaces:
Serializable

public class Terrain extends Object implements Serializable
Represents a single type of terrain or condition in a hex. The type of a terrain is immutable, once created, but the level and exits are changeable. Each type of terrain should only be represented once in a hex.
See Also:
  • Field Details

  • Constructor Details

    • Terrain

      public Terrain(int type, int level)
    • Terrain

      public Terrain(int type, int level, boolean exitsSpecified, int exits)
    • Terrain

      public Terrain(Terrain other)
    • Terrain

      public Terrain(String terrain)
      Parses a string containing terrain info into the actual terrain
  • Method Details

    • levelFor

      public static int levelFor(String string)
    • getType

      public int getType()
    • getLevel

      public int getLevel()
    • getTerrainFactor

      public int getTerrainFactor()
    • setTerrainFactor

      public void setTerrainFactor(int tf)
    • getTerrainElevation

      public int getTerrainElevation(boolean inAtmosphere)
    • getExits

      public int getExits()
    • hasExitsSpecified

      public boolean hasExitsSpecified()
    • setExits

      public void setExits(int exits)
    • setExit

      public void setExit(int direction, boolean connection)
      Sets the exit in specified direction
      Parameters:
      direction - the direction to add/remove the exit
      connection - true to add, false to remove
    • flipExits

      public void flipExits(boolean horiz, boolean vert)
      Flips the exits around the vertical axis (North-for-South) and/or the horizontal axis (East-for-West).
      Parameters:
      horiz - a boolean value that, if true, indicates that the exits are being flipped North-for-South.
      vert - a boolean value that, if true, indicates that the exits are being flipped East-for-West.
    • exitsTo

      public boolean exitsTo(Terrain other)
      Returns:
      true if the terrain in this hex exits to the terrain in the other hex.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Terrains are equal if their types and levels are equal. Does not pay attention to exits.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • applyPilotingModifier

      public void applyPilotingModifier(EntityMovementMode moveMode, PilotingRollData roll, boolean enteringRubble)
      Parameters:
      moveMode - the movement mode of the pilot
      roll - the piloting roll
      enteringRubble - if the entered terrain contains rubble
    • movementCost

      public int movementCost(Entity e)
      Returns:
      The additional movement cost for this terrain
    • ignitionModifier

      public int ignitionModifier()
      The fire ignition modifier for this terrain
    • getBogDownModifier

      public int getBogDownModifier(EntityMovementMode moveMode, boolean largeVee)
    • getUnstuckModifier

      public void getUnstuckModifier(int elev, PilotingRollData rollTarget)
    • isValid

      public boolean isValid(@Nullable List<String> errors)
      Returns true when this terrain is valid, i.e. if its level is an allowed value for its type. Exits have no limitations and are not checked. If an error is found, a line detailing the error is added to the given errors list if it not null.
      Parameters:
      errors - A list of errors to append new errors to if it is not null
      Returns:
      True when this terrain is valid, false otherwise