Record Class ForceGeneratorAvailability

java.lang.Object
java.lang.Record
megamek.common.units.ForceGeneratorAvailability
Record Components:
startYear - first year this entry applies, or UNSPECIFIED_YEAR to start at the unit's introduction year
endYear - last year this entry applies, or UNSPECIFIED_YEAR for no end
availabilityCodes - comma-separated availability codes, e.g. "FS:5,LA:3"
All Implemented Interfaces:
Serializable

public record ForceGeneratorAvailability(int startYear, int endYear, String availabilityCodes) extends Record implements Serializable
Force Generator availability declared inside a unit file (.mtf or .blk). This lets a custom unit tell the Force Generator which factions field it and how often, without editing the canon era files in data/forcegenerator.

Note this is NOT the tech availability rating (see AvailabilityValue and ITechnology), which rates how hard equipment is to obtain on an A-F/X scale.

A single line holds an optional year range followed by a comma-separated list of availability codes:

 availability:FS:5,LA:3                 intro year to extinction
 availability:3067-3085 FS:7,LA:6       explicit year range
 availability:3067- FS:7                open-ended range
 

The codes use the same FKEY:AV[+/-][:YEAR] format as the era XML files, so they are handed to AvailabilityRating unchanged. AV runs 0 (none) to 10 (ubiquitous) on a base-2 log scale, where 6 is typical and every +2 doubles how often the unit appears.

See Also:
  • Field Details

    • UNSPECIFIED_YEAR

      public static final int UNSPECIFIED_YEAR
      Marks a year that the unit file did not specify, so the unit's own introduction/extinction dates are used.
      See Also:
  • Constructor Details

    • ForceGeneratorAvailability

      public ForceGeneratorAvailability(int startYear, int endYear, String availabilityCodes)
      Creates an instance of a ForceGeneratorAvailability record class.
      Parameters:
      startYear - the value for the startYear record component
      endYear - the value for the endYear record component
      availabilityCodes - the value for the availabilityCodes record component
  • Method Details

    • parse

      public static ForceGeneratorAvailability parse(String line)
      Parses a single availability line from a unit file. The line must not include the availability: prefix.
      Parameters:
      line - the line contents, e.g. "FS:5,LA:3" or "3067-3085 FS:7"
      Returns:
      the parsed entry
      Throws:
      IllegalArgumentException - if the line is blank or the year range is malformed
    • parseAll

      public static List<ForceGeneratorAvailability> parseAll(Collection<String> lines, String unitName)
      Parses every availability line from a unit file, skipping any that are malformed. A bad line is logged and dropped rather than failing the load, so a typo cannot make the unit unusable.
      Parameters:
      lines - the line contents, without the availability: prefix
      unitName - the unit these lines came from, used for logging
      Returns:
      the parsed entries, in file order; empty if there are none
    • effectiveStartYear

      public int effectiveStartYear(int introductionYear)
      Resolves the first year this entry applies, falling back to the unit's introduction year when the file did not specify one.
      Parameters:
      introductionYear - the unit's introduction year
      Returns:
      the effective start year
    • effectiveEndYear

      public int effectiveEndYear()
      Resolves the last year this entry applies. An unspecified end year means the unit never drops out.
      Returns:
      the effective end year
    • appliesToEra

      public boolean appliesToEra(int eraStartYear, int eraEndYear, int introductionYear)
      Tests whether this entry overlaps an era bucket. Era buckets run from their own year up to the year before the next era begins.
      Parameters:
      eraStartYear - first year of the era bucket
      eraEndYear - last year of the era bucket, or Integer.MAX_VALUE for the final era
      introductionYear - the unit's introduction year, used when the file gave no start year
      Returns:
      true if any part of this entry falls inside the era
    • toFileFormat

      public String toFileFormat()
      Renders this entry the way it appears in a unit file, without the availability: prefix.
      Returns:
      the file representation of this entry
    • 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.
    • startYear

      public int startYear()
      Returns the value of the startYear record component.
      Returns:
      the value of the startYear record component
    • endYear

      public int endYear()
      Returns the value of the endYear record component.
      Returns:
      the value of the endYear record component
    • availabilityCodes

      public String availabilityCodes()
      Returns the value of the availabilityCodes record component.
      Returns:
      the value of the availabilityCodes record component