Record Class RatTableContent

java.lang.Object
java.lang.Record
megamek.utilities.ratdata.RatTableContent
Record Components:
salvagePct - the whole-number chance, 0 to 100, that a drawn unit is replaced by salvage
units - the faction's own units, each an index into the export's unit list with its table weight
salvage - the salvage factions, each an index into the export's faction list with its share of all salvage in units of 1/10000; salvage is rolled after each unit is drawn, so these weights are not in the same pool as the unit weights

public record RatTableContent(int salvagePct, List<RatTableContent.WeightedEntry> units, List<RatTableContent.WeightedEntry> salvage) extends Record
One random assignment table as the RAT data export stores it: the faction's own units with their weights, the salvage factions with their weights, and the chance a roll goes to salvage.

The encoding is canonical: entries are sorted by index, so two tables with the same contents always encode to the same bytes. That is what lets RatDataShard store each distinct table once.

Encoded layout, little-endian:

 uint8  salvagePct
 uint16 unitCount
 uint16 salvageCount
 unitCount    x (uint16 unitIndex,    uint16 weight)
 salvageCount x (uint16 factionIndex, uint16 weight)
 
  • Field Details

    • SALVAGE_WEIGHT_SCALE

      public static final int SALVAGE_WEIGHT_SCALE
      A salvage faction's weight is its share of all salvage, out of this total.
      See Also:
  • Constructor Details

  • Method Details

    • salvagePct

      public static int salvagePct(SalvageChance salvageChance)
      Parameters:
      salvageChance - the table's salvage chance
      Returns:
      the chance that a drawn unit is salvage, rounded to a whole percentage; 0 when there are no salvage sources
    • salvageWeight

      public static int salvageWeight(SalvageChance salvageChance, FactionRecord faction)
      Parameters:
      salvageChance - the table's salvage chance
      faction - one of its salvage sources
      Returns:
      the faction's share of all salvage, in units of 1/10000
    • encode

      public byte[] encode()
      Returns:
      the canonical byte encoding of this table
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • salvagePct

      public int salvagePct()
      Returns the value of the salvagePct record component.
      Returns:
      the value of the salvagePct record component
    • units

      Returns the value of the units record component.
      Returns:
      the value of the units record component
    • salvage

      Returns the value of the salvage record component.
      Returns:
      the value of the salvage record component