Class FortifyState

java.lang.Object
megamek.common.units.FortifyState
All Implemented Interfaces:
Serializable

public class FortifyState extends Object implements Serializable
Tracks whether a unit performing multi-turn fieldwork - digging in (TO:AR p.106) or raising a fortified hex as Trench/Fieldworks Engineers (TO:AUE p.153) - has been damaged between turns. Per those rules, taking damage during a turn spent fortifying extends the effort by one turn (regardless of how many attacks were made), so the unit's dug-in progress counter must not advance on any turn in which it was attacked.

This class is intentionally agnostic about the unit type. Callers supply a "health signature": any integer that only decreases when the unit takes damage (for example, total armor plus internal structure). A decrease in that signature between two consecutive turns means the unit was damaged and the effort is set back by one turn.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    begin(int healthSignature)
    Records the health signature at the moment fieldwork begins, establishing the baseline that the next turn's checkpoint compares against.
    boolean
    checkpointWasDamaged(int healthSignature)
    Compares the current health signature against the previous checkpoint and stores the new value for next turn.
    void
    Clears the in-progress baseline; call when the unit stops fortifying.
    boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FortifyState

      public FortifyState()
  • Method Details

    • begin

      public void begin(int healthSignature)
      Records the health signature at the moment fieldwork begins, establishing the baseline that the next turn's checkpoint compares against.
      Parameters:
      healthSignature - the unit's current health signature (for example, total armor + internal)
    • checkpointWasDamaged

      public boolean checkpointWasDamaged(int healthSignature)
      Compares the current health signature against the previous checkpoint and stores the new value for next turn. A decrease since the last checkpoint means the unit was damaged.
      Parameters:
      healthSignature - the unit's current health signature (for example, total armor + internal)
      Returns:
      true if the unit has taken damage since the last checkpoint (so the effort should be extended by one turn); false on the first checkpoint or when no damage was taken
    • wasExtendedAtLastCheckpoint

      public boolean wasExtendedAtLastCheckpoint()
      Returns:
      true if the most recent checkpointWasDamaged(int) detected damage (i.e. the effort was extended). Used to report/notify the delay after the checkpoint has run.
    • reset

      public void reset()
      Clears the in-progress baseline; call when the unit stops fortifying.