Class WoodsClearingTracker

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

public class WoodsClearingTracker extends Object implements Serializable
Tracks ongoing woods-clearing operations using chainsaws and dual saws.

Per TM pp.241-243, a chainsaw or dual saw can clear a path through wooded hexes. Instead of using the Terrain Factor damage system, a saw takes 2 turns to reduce a wooded hex one level (heavy to light, light to rough). Two units clearing the same hex can reduce this to 1 turn.

Work accumulates per-hex and persists even if no entity works the hex for a round (a partially cut tree stays partially cut). Work only progresses when at least one entity actively declares clearing in a given round.

See Also:
  • Field Details

    • TURNS_REQUIRED_SINGLE

      public static final int TURNS_REQUIRED_SINGLE
      Number of work turns needed to clear a hex with a single saw.
      See Also:
    • TURNS_REQUIRED_MULTI

      public static final int TURNS_REQUIRED_MULTI
      Number of work turns needed when 2+ saws are working the same hex.
      See Also:
  • Constructor Details

    • WoodsClearingTracker

      public WoodsClearingTracker()
  • Method Details

    • declareClearing

      public void declareClearing(int entityId, BoardLocation targetHex)
      Registers an entity as clearing a specific hex this round.
      Parameters:
      entityId - the ID of the entity performing clearing
      targetHex - the hex being cleared
    • processNewRound

      public List<BoardLocation> processNewRound()
      Processes the round transition for all clearing operations.

      For each hex that had contributors this round, increments accumulated work. A hex completes when accumulated work reaches the required threshold (2 turns for single unit, 1 turn for 2+ units). Hexes with no contributors this round retain their accumulated work (a partially cut tree stays partially cut) but do not progress.

      Returns:
      list of hex locations that have completed clearing (ready for terrain reduction)
    • wasClearingLastRound

      public boolean wasClearingLastRound(int entityId)
      Checks if an entity declared clearing in the previous round (used for firing penalty).
      Parameters:
      entityId - the entity ID to check
      Returns:
      true if the entity was clearing last round and should have the running/flank penalty
    • hasAccumulatedWork

      public boolean hasAccumulatedWork(BoardLocation hex)
      Checks if a hex already has accumulated clearing work (partially cut).
      Parameters:
      hex - the hex to check
      Returns:
      true if the hex has any accumulated work from prior turns
    • isClearingThisRound

      public boolean isClearingThisRound(int entityId)
      Checks if an entity is currently declared as clearing this round.
      Parameters:
      entityId - the entity ID to check
      Returns:
      true if the entity declared clearing this round
    • getClearingTarget

      public BoardLocation getClearingTarget(int entityId)
      Returns the hex that a given entity is clearing this round, or null if not clearing.
      Parameters:
      entityId - the entity ID to check
      Returns:
      the BoardLocation being cleared, or null
    • getAllClearingEntities

      public Set<Integer> getAllClearingEntities()
      Returns all entity IDs currently involved in clearing operations (this round or last round).
      Returns:
      set of entity IDs involved in clearing
    • getTurnsRemainingPerHex

      public Map<BoardLocation,Integer> getTurnsRemainingPerHex()
      Returns a map of hex locations to the number of turns remaining to complete clearing. Accounts for the number of contributors this round when calculating remaining turns.
      Returns:
      map of hex locations to turns remaining (1 or 2 typically)
    • removeStaleEntries

      public void removeStaleEntries(Function<BoardLocation,Hex> hexLookup)
      Removes tracker entries for hexes that no longer contain woods or jungle. This handles cases where fire or other effects removed the woods before the saw clearing completed.
      Parameters:
      hexLookup - a function that returns the Hex at a given BoardLocation, or null
    • clear

      public void clear()
      Removes all clearing operations. Used when resetting the game state.