Class SensorChoiceHandler

java.lang.Object
megamek.common.equipment.SensorChoiceHandler

public final class SensorChoiceHandler extends Object
Remembers which sensor a player wants a given chassis and model to start a battle with, in mmconf/customSensorChoice.xml.

This is the sensor counterpart of WeaponOrderHandler, and works the same way: the choice is stored against the unit's chassis and model rather than against one unit, and it is applied by MekFileParser to every unit of that design as it loads. Because that parser is shared code, a choice saved in MegaMek is also picked up by MekHQ and MegaMekLab.

Example: a player sets a Marauder MAD-3R to Infrared in the lobby and ticks the box to remember it. Every MAD-3R loaded from then on, in a MegaMek game or a MekHQ campaign, starts on infrared instead of the radar it would otherwise default to.

A SensorFamily is stored rather than a raw Sensor type, so the choice still resolves when a variant carries a different flavour of the same sensor, and a design that no longer carries anything from the saved family simply falls back to its normal default.

  • Field Details

  • Method Details

    • getSensorChoice

      @Nullable public static SensorFamily getSensorChoice(String chassis, String model)
      Returns the sensor family saved for a chassis and model.
      Parameters:
      chassis - the unit's chassis
      model - the unit's model
      Returns:
      the saved family, or null when nothing is saved for that design
    • setSensorChoice

      public static void setSensorChoice(String chassis, String model, @Nullable SensorFamily family)
      Saves a sensor family against a chassis and model. Pass null to forget a design.

      The change is held in memory until saveSensorChoiceFile() writes it out, which matches how the custom weapon order is handled.

      Parameters:
      chassis - the unit's chassis
      model - the unit's model
      family - the family to remember, or null to forget this design
    • saveSensorChoiceFile

      public static void saveSensorChoiceFile() throws IOException
      Writes the saved choices to mmconf/customSensorChoice.xml. Does nothing when nothing has changed.
      Throws:
      IOException - if the file cannot be written