Class AvailabilityRating

java.lang.Object
megamek.client.ratgenerator.AvailabilityRating

public class AvailabilityRating extends Object
Handles availability rating values and calculations for RAT generator. Availability is rated on a base-2 logarithmic scale from 0 (non-existent) to 10 (ubiquitous), with 6 being a typical value when the source material does not give an indication of frequency. The availability rating is actually twice the exponent, which allows more precision while still storing values as integers (so it's really a base-(sqrt(2)) scale, but using 2 as the base should theoretically be faster).
These values are stored separately for chassis and models; there is one value to indicate the likelihood that a medium Mek is a Phoenix Hawk and another set of values to indicate the likelihood that a give Phoenix Hawk is a 1D or 1K, etc.
  • Field Details

    • LOG_BASE

      public static final double LOG_BASE
  • Constructor Details

    • AvailabilityRating

      public AvailabilityRating(String unit, int era, String code)
      Parameters:
      unit - The chassis or model key
      era - The era that this availability code applies to.
      code - A string with the format FKEY[!RATING]:AV[+/-][:YEAR]
      examples: LA:7, FS:3+:3024, DC!A:8!B:7
      FKEY: the faction key
      !RATING: provides direct control over each equipment level. Not compatible with +/- or year values.
      AV: an integer that indicates how common this unit is relative to others (chassis or model of same chassis)
      +: the indicated av rating applies to the highest equipment rating for the faction (usually A or Keshik) and decreases for each step the rating is reduced.
      -: as +, but applies to the lowest equipment rating (F or PGC) and decreases as rating increases.
      YEAR: when the unit becomes available to the faction, if later than the beginning of the era. Any year before this within the era will be treated as having no availability.
  • Method Details

    • getFaction

      public String getFaction()
    • setFaction

      public void setFaction(String faction)
    • getAvailability

      public int getAvailability()
    • getAvailability

      public int getAvailability(String equipmentLevel)
      Returns the availability value, using the provided equipment rating if multiple levels are present or the raw value if not
      Parameters:
      equipmentLevel - name of equipment level, typically one of A/B/C/D/F
      Returns:
      availability value for the specified equipment rating string
    • getAvailability

      public int getAvailability(int equipmentLevelIndex)
      Returns the availability value, using the provided equipment level if multiple levels are present or the raw value if not
      Parameters:
      equipmentLevelIndex - index number of equipment level, typically 0 (F), 1 (D), 2 (C), 3 (B), 4 (A)
      Returns:
      availability value for the specified equipment rating value
    • adjustForRating

      public int adjustForRating(int equipRating, int numLevels)
      Adjust availability rating for the dynamic +/- value, which is based on equipment quality rating. The (+) will reduce availability for commands with a lower rating, while the (-) will reduce availability for commands with a higher rating.
      Parameters:
      equipRating - zero-based index based on numLevels of rating to check
      numLevels - number of equipment levels available, typically 5 (A/B/C/D/F)
      Returns:
      integer, may be negative
    • setAvailability

      public void setAvailability(int availability)
    • getRatings

      public String getRatings()
    • setRatings

      public void setRatings(String ratings)
    • setRatingByNumericLevel

      public void setRatingByNumericLevel(FactionRecord fRec)
      Converts letter-based equipment level to index-based for working with systems that use it
      Parameters:
      fRec - faction-specific record, for equipment levels (typically A/B/C/D/F)
    • getRatingAdjustment

      @Deprecated(since="0.51.0", forRemoval=true) public int getRatingAdjustment()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setRatingAdjustment

      @Deprecated(since="0.51.0", forRemoval=true) public void setRatingAdjustment(int ratingAdjustment)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • hasMultipleRatings

      public boolean hasMultipleRatings()
      Indicates this availability rating object has different ratings for multiple levels.
      Returns:
      true if ratings for multiple levels are set
    • getEra

      public int getEra()
    • setEra

      public void setEra(int era)
    • getStartYear

      public int getStartYear()
    • setStartYear

      public void setStartYear(int year)
    • getUnitName

      public String getUnitName()
    • setUnitName

      public void setUnitName(String unitName)
    • getFactionCode

      public String getFactionCode()
    • getAvailabilityCode

      public String getAvailabilityCode()
      Get the string equivalent of the ratings values. Multiple ratings requires compiling them back into a !RATING:VALUE!RATING:VALUE format
      Returns:
      string with properly formatted availability values, without the leading faction code
    • formatAvailability

      public String formatAvailability(FactionRecord factionRecord)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • makeCopy

      public AvailabilityRating makeCopy(String newFaction)
      Creates a copy of this rating for another faction.

      The copy is rebuilt from getAvailabilityCode(), which does not carry the start year, so the year has to be reapplied by hand. Without this the copy would silently revert to the start of the era, and a unit gated to a later year would become available early.

      Note the copy does not carry ratingByNumericLevel. Those indexes are resolved against a specific faction's equipment rating system, so a caller copying to a different faction must call setRatingByNumericLevel(FactionRecord) with the new faction.

      Parameters:
      newFaction - the faction code the copy is for
      Returns:
      the copy
    • getWeight

      public double getWeight()