Package megamek.common.units
Record Class ForceGeneratorAvailability
java.lang.Object
java.lang.Record
megamek.common.units.ForceGeneratorAvailability
- Record Components:
startYear- first year this entry applies, orUNSPECIFIED_YEARto start at the unit's introduction yearendYear- last year this entry applies, orUNSPECIFIED_YEARfor no endavailabilityCodes- 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intMarks a year that the unit file did not specify, so the unit's own introduction/extinction dates are used. -
Constructor Summary
ConstructorsConstructorDescriptionForceGeneratorAvailability(int startYear, int endYear, String availabilityCodes) Creates an instance of aForceGeneratorAvailabilityrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanappliesToEra(int eraStartYear, int eraEndYear, int introductionYear) Tests whether this entry overlaps an era bucket.Returns the value of theavailabilityCodesrecord component.intResolves the last year this entry applies.inteffectiveStartYear(int introductionYear) Resolves the first year this entry applies, falling back to the unit's introduction year when the file did not specify one.intendYear()Returns the value of theendYearrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static ForceGeneratorAvailabilityParses a single availability line from a unit file.static List<ForceGeneratorAvailability> parseAll(Collection<String> lines, String unitName) Parses every availability line from a unit file, skipping any that are malformed.intReturns the value of thestartYearrecord component.Renders this entry the way it appears in a unit file, without theavailability:prefix.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
UNSPECIFIED_YEAR
public static final int UNSPECIFIED_YEARMarks a year that the unit file did not specify, so the unit's own introduction/extinction dates are used.- See Also:
-
-
Constructor Details
-
ForceGeneratorAvailability
Creates an instance of aForceGeneratorAvailabilityrecord class.- Parameters:
startYear- the value for thestartYearrecord componentendYear- the value for theendYearrecord componentavailabilityCodes- the value for theavailabilityCodesrecord component
-
-
Method Details
-
parse
Parses a single availability line from a unit file. The line must not include theavailability: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
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 theavailability:prefixunitName- 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 bucketeraEndYear- last year of the era bucket, orInteger.MAX_VALUEfor the final eraintroductionYear- the unit's introduction year, used when the file gave no start year- Returns:
trueif any part of this entry falls inside the era
-
toFileFormat
Renders this entry the way it appears in a unit file, without theavailability:prefix.- Returns:
- the file representation of this entry
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
startYear
public int startYear()Returns the value of thestartYearrecord component.- Returns:
- the value of the
startYearrecord component
-
endYear
public int endYear()Returns the value of theendYearrecord component.- Returns:
- the value of the
endYearrecord component
-
availabilityCodes
Returns the value of theavailabilityCodesrecord component.- Returns:
- the value of the
availabilityCodesrecord component
-