Class LifePathXPCostCalculator

java.lang.Object
mekhq.campaign.personnel.advancedCharacterBuilder.LifePathXPCostCalculator

public class LifePathXPCostCalculator extends Object
Works out what a Life Path costs a character in XP.

The total is everything the path awards from its Fixed XP section, plus a share of its Flexible XP section, less the path's own discount. The total can be negative: a path whose drawbacks, such as negative trait awards, outweigh what it gives pays the character to take it.

How the flexible share is charged. The flexible section is a number of sets. Each set is a list of individual awards and says how many of them the player takes, and the player picks from every set. Which items they pick is up to them, so each set has to carry one price that covers any choice. That price is a weighted average of the set's item values, charged once per pick from that set, and the Life Path pays the sum of its set prices. Within a set the items are sorted by value and weighted with a bell curve centred on the middle of that order, so the middle item sets the price and an unusually cheap or unusually expensive item barely moves it. The weight of the item at position p is exp(-0.5 * ((p - middle) / 0.5) ^ 2), where middle is (itemCount - 1) / 2.

Example: set A holds Gunnery/Mek 30 XP, Piloting/Mek 30 XP and the SPA Pain Resistance at 200 XP, and the player takes one. The middle item is a 30, and the other 30 and the 200 each carry about an eighth of its weight, so the set prices at 48 XP rather than the flat average of 87. Set B holds Small Arms 20 XP and Melee 20 XP, and the player takes both, so it prices at 40 XP. The flexible section costs 88 XP, whichever items the player chooses. Pricing the two sets together, as the calculator once did, would have charged 150.

A flat average would let one expensive item drag a set's price up even for a player who never takes it, and would make the price jump every time an author added an outlier. Pricing sets separately keeps an expensive set from touching a cheap one.

Since:
0.50.11
  • Constructor Details

    • LifePathXPCostCalculator

      public LifePathXPCostCalculator()
  • Method Details

    • calculateXPCost

      public static int calculateXPCost(LifePathBuilder lifePath)
      Returns the XP a Life Path costs.
      Parameters:
      lifePath - the Life Path being priced, finished or still under construction
      Returns:
      the XP cost, which is negative when the path's drawbacks outweigh its awards
      Since:
      0.50.11
    • calculateXPCost

      public static int calculateXPCost(LifePath lifePath)
      Returns the XP a finished Life Path costs.
      Parameters:
      lifePath - the Life Path to price
      Returns:
      the XP cost, which is negative when the path's drawbacks outweigh its awards
      Since:
      0.50.11
    • calculateFlexibleXPCost

      public static int calculateFlexibleXPCost(LifePathBuilder lifePath)
      Returns the XP the whole flexible section costs: every set's price added together.
      Parameters:
      lifePath - the Life Path whose flexible sets are being priced
      Returns:
      the flexible XP cost, zero when there are no sets or none allow a pick
      Since:
      0.50.11
    • calculateFlexibleSetCost

      public static int calculateFlexibleSetCost(LifePathBuilder lifePath, int setIndex)
      Returns the XP one flexible set costs: the weighted average of its item values, multiplied by the number of items the player picks from it, rounded to the nearest XP.

      Rounded here, per set, so that the per-set prices the wizard shows add up to the total the file records. See the class documentation for why the average is weighted rather than flat.

      Parameters:
      lifePath - the Life Path the set belongs to
      setIndex - the set's index
      Returns:
      the set's price, zero when it has no items or allows no picks
      Since:
      0.50.11