Class HexEditHandler

java.lang.Object
megamek.server.totalWarfare.HexEditHandler

public class HexEditHandler extends Object
Applies a gamemaster's edits to a single hex: adding a terrain, changing its level, or clearing the hex.

The change is tried on a copy of the hex first and only kept if the result is a hex the game considers valid, so an edit can never leave the board in a state the rest of the engine does not expect - rapids outside water, for instance, or a woods level that does not exist.

Changing the depth of water in a hex that units are standing in is refused. There is no rule for what happens to a unit when the ground beneath it floods, and inventing one here would be a house rule; that is being decided separately.

Status and known limits

Note for anyone picking this up: the gamemaster terrain tools are a first, deliberately simple pass. They work, but they have had little testing and the validation is thin - see HexEditValidator for what is and is not checked, and for the TODO that goes with it. Both modifying terrain and changing it want more testing than they have had.

  • Field Details

    • REMOVE_TERRAIN_LEVEL

      public static final int REMOVE_TERRAIN_LEVEL
      Passed as the terrain level to remove a terrain rather than add it.
      See Also:
  • Method Details

    • setTerrain

      public String setTerrain(Coords coords, int boardId, int terrainType, int terrainLevel, String gamemasterName)
      Sets one terrain in one hex to the given level, removing that terrain when the level is REMOVE_TERRAIN_LEVEL.
      Parameters:
      coords - The hex to change
      boardId - The board the hex is on
      terrainType - The terrain to set, from Terrains
      terrainLevel - The level to set it to, or REMOVE_TERRAIN_LEVEL to remove it
      gamemasterName - The name of the gamemaster making the change, for the report
      Returns:
      A description of why the edit was refused, or null when it was applied
    • applyHexEdit

      public String applyHexEdit(HexEditSpec spec, String gamemasterName)
      Applies a gamemaster's edit to every hex it names, or to none of them.

      Each hex is checked first and the whole edit is refused if any one of them would end up invalid. A gamemaster flooding a valley wants the valley flooded or a reason why not; half a valley flooded, with the hexes that failed left dry among the ones that worked, is the worst of both.

      Parameters:
      spec - The hexes to change and the terrain they should end up holding
      gamemasterName - The name of the gamemaster making the change, for the report
      Returns:
      A description of why the edit was refused, or null when it was applied
    • setTerrainFactor

      public String setTerrainFactor(Coords coords, int boardId, int terrainType, int terrainFactor, String gamemasterName)
      Sets how much punishment a terrain in one hex can still take, leaving what the terrain is alone. Woods that have been shelled but not yet flattened are the usual case: the hex is still light woods, but there is less of it left to burn or blast away.
      Parameters:
      coords - The hex holding the terrain
      boardId - The board the hex is on
      terrainType - The terrain to weaken or restore, from Terrains
      terrainFactor - The terrain factor to leave it at
      gamemasterName - The name of the gamemaster making the change, for the report
      Returns:
      A description of why the edit was refused, or null when it was applied
    • clearHex

      public String clearHex(Coords coords, int boardId, String gamemasterName)
      Clears every terrain from one hex, leaving bare ground at the hex's own level.
      Parameters:
      coords - The hex to clear
      boardId - The board the hex is on
      gamemasterName - The name of the gamemaster making the change, for the report
      Returns:
      A description of why the edit was refused, or null when it was applied