Class RandomNameGenerator

java.lang.Object
megamek.client.generator.RandomNameGenerator
All Implemented Interfaces:
Serializable

public class RandomNameGenerator extends Object implements Serializable
This class sets up a random name generator that can then be used to generate random pilot names. It has a couple different settings and flexible input file directory locations

Files are located in /data/names/. All files are comma spaced csv files

The historicalEthnicity.csv file shows the correspondence between the different ethnic names and their numeric code in the database. This file is used to initialize the name mapping, and must be kept current for all additions. The same numeric code MUST be used across all of the files listed below. The numeric codes MUST be listed in exact sequential order (NO skipped numbers) for the load to work correctly.

The name database is located in three files: maleGivenNames.csv, femaleGivenNames.csv, and surnames.csv.

The database is divided into three fields; an Integer Ethnic Code, a String name, and an Integer weight.

The Ethnic Code is an Integer identifying the ethnic group from the historicalEthnicity.csv file the name is from

The Name is a String containing either a male/female first name or a surname, dependent on the origin file.

The Weight is an Integer that is used to set the generation chance of the name. The higher the number, the more common the name is.

Faction files are located in /data/names/factions/ directory. The faction key is the filename without the extension. The faction files will have varying number of fields depending on how many ethnic groups exist. The faction file does two things:

First, it identifies the relative frequency of different ethnic surnames for a faction.

Second, it identifies the correspondence between first names and surnames.

This allows, for example, for more Japanese first names regardless of surname in the Draconis Combine. There MUST be a line in the Faction file for each ethnic group, although a weight of 0 can be used to prevent the generation of a grouping of names

This is divided into 3 + n fields, where n is the number of ethnic groups listed in historicalEthnicity.csv, divided into the following groupings:

The Integer Ethnic Code is the first field

The String Ethnic Name is the second field. This is included for ease of reference, and is NOT used by the generator.

The Integer Weight for generating a surname of the specified ethnicity. The higher the number, the more common the surname is for a faction.

This is followed by n fields each containing the Integer Weight for generating a given name for the ethnicity with Ethnic Code n. The higher the number for the weight, the more common that given name ethnicity is in generation for the specific ethnicity of the generated surname.

See Also:
  • Field Details

  • Constructor Details

    • RandomNameGenerator

      public RandomNameGenerator()
  • Method Details

    • generate

      public String generate(Gender gender, boolean clanPilot)
      This is used to generate a name for MegaMek only that uses the chosen faction
      Parameters:
      gender - the gender to generate the name for
      clanPilot - if the name is for a clanPilot
      Returns:
      a string containing the randomly generated name
    • generate

      public String generate(Gender gender, boolean clanPilot, String faction)
      Generate a single random name for MegaMek only
      Parameters:
      gender - the gender to generate the name for
      clanPilot - if the name is for a clanPilot
      faction - a string containing the faction key with which to generate the name from. If the faction is not a key for the factionSurnames Map, it will instead generate based on the General list
      Returns:
      a string containing the randomly generated name
    • generateWithEthnicCode

      public String generateWithEthnicCode(Gender gender, boolean clanPilot, int ethnicCode)
      Parameters:
      gender - the gender to generate the name for
      clanPilot - if the person is a clanPilot
      ethnicCode - the specified ethnic code
      Returns:
      a string containing the randomly generated name
    • generateGivenNameSurnameSplit

      public String[] generateGivenNameSurnameSplit(Gender gender, boolean clanPilot, String faction)
      Generate a single random name split between a given name and surname
      Parameters:
      gender - the gender to generate the name for
      clanPilot - if the person is a clanPilot
      faction - a string containing the faction key with which to generate the name from. If the faction is not a key for the factionSurnames Map, it will instead generate based on the General list
      Returns:
      - a String[] containing the name, with the given name at String[0] and the surname at String[1]
    • generateGivenNameSurnameSplitWithEthnicCode

      public String[] generateGivenNameSurnameSplitWithEthnicCode(Gender gender, boolean clanPilot, int ethnicCode)
      Parameters:
      gender - the gender to generate the name for
      clanPilot - if the person is a clanPilot
      ethnicCode - the specified ethnic code
      Returns:
      - a String[] containing the name, with the given name at String[0] and the surname at String[1]
    • getFactions

      public Set<String> getFactions()
      Returns:
      the set of potential keys to generate the name from - this MUST NOT be modified once it has been gotten
    • getChosenFaction

      public String getChosenFaction()
      Returns:
      the chosen faction to generate the name from
    • setChosenFaction

      public void setChosenFaction(String chosenFaction)
      Parameters:
      chosenFaction - the faction to use to generate the name
    • getHistoricalEthnicity

      public Map<Integer,String> getHistoricalEthnicity()
      Returns:
      the historical ethnicity map
    • getInstance

      public static RandomNameGenerator getInstance()
      Returns:
      the instance of the RandomNameGenerator to use