Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
702 changes: 502 additions & 200 deletions MekHQ/resources/mekhq/resources/Aggression.properties

Large diffs are not rendered by default.

754 changes: 540 additions & 214 deletions MekHQ/resources/mekhq/resources/Ambition.properties

Large diffs are not rendered by default.

732 changes: 535 additions & 197 deletions MekHQ/resources/mekhq/resources/Greed.properties

Large diffs are not rendered by default.

1,098 changes: 613 additions & 485 deletions MekHQ/resources/mekhq/resources/Intelligence.properties

Large diffs are not rendered by default.

8,567 changes: 4,730 additions & 3,837 deletions MekHQ/resources/mekhq/resources/PersonalityQuirk.properties

Large diffs are not rendered by default.

712 changes: 525 additions & 187 deletions MekHQ/resources/mekhq/resources/Social.properties

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

import static megamek.common.Compute.d6;
import static megamek.common.Compute.randomInt;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HE_SHE_THEY;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIM_HER_THEM;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIS_HER_THEIR;
import static mekhq.campaign.randomEvents.personalities.enums.Intelligence.*;

/**
Expand Down Expand Up @@ -117,7 +120,7 @@ public static void generatePersonality(Person person) {
*/
public static void generateAndApplyPersonalityQuirk(Person person) {
// This ensures we're rolling a value between 1 and the maximum index in the enum
int traitRoll = 1 + randomInt(PersonalityQuirk.values().length - 1);
int traitRoll = randomInt(PersonalityQuirk.values().length) + 1;
String traitIndex = String.valueOf(traitRoll);

person.setPersonalityQuirk(PersonalityQuirk.fromString(traitIndex));
Expand Down Expand Up @@ -166,7 +169,7 @@ private static void performPersonalityGenerationFallback(Person person) {
*/
private static String getTraitIndex(final int majorTraitsStartIndex) {
// This gives us a random number between 1 and the start of the major traits
int traitRoll = randomInt(majorTraitsStartIndex + 1);
int traitRoll = randomInt(majorTraitsStartIndex) + 1;

if (traitRoll == majorTraitsStartIndex) {
// We're deliberately not using d6() here as we want 0 to be a possibility
Expand All @@ -184,8 +187,35 @@ private static String getTraitIndex(final int majorTraitsStartIndex) {
* @param person the person whose personality description will be generated and updated
*/
public static void writePersonalityDescription(Person person) {
List<String> traitDescriptions = getTraitDescriptions(person);
Gender gender = person.getGender();
String givenName = person.getGivenName();

List<String> traitDescriptions = getTraitDescriptions(
gender, givenName, person.getAggression(), person.getAggressionDescriptionIndex(),
person.getAmbition(), person.getAmbitionDescriptionIndex(), person.getGreed(),
person.getGreedDescriptionIndex(), person.getSocial(), person.getSocialDescriptionIndex()
);

// Intelligence and personality quirk are handled differently to general personality traits.
// INTELLIGENCE
Intelligence intelligence = person.getIntelligence();
String intelligenceDescription = "";
if (!intelligence.isAverageType()) {
intelligenceDescription = intelligence.getDescription(person.getIntelligenceDescriptionIndex(),
gender, givenName);
}

// PERSONALITY QUIRK
PersonalityQuirk personalityQuirk = person.getPersonalityQuirk();
String quirkDescription = "";
if (!personalityQuirk.isNone()) {
quirkDescription = personalityQuirk.getDescription(
person.getPrimaryRole(), person.getPersonalityQuirkDescriptionIndex(), gender,
person.getOriginFaction(), givenName
);
}

// Build the description proper
StringBuilder personalityDescription = new StringBuilder();

// Append the first trait description, if exists, without wrapping in <p>
Expand All @@ -209,86 +239,92 @@ public static void writePersonalityDescription(Person person) {
}
}

if (!intelligenceDescription.isBlank()) {
if (!personalityDescription.toString().isBlank()) {
personalityDescription.append("<p>").append(intelligenceDescription).append("</p>");
} else {
personalityDescription.append(intelligenceDescription);
}
}

if (!quirkDescription.isBlank()) {
if (!personalityDescription.toString().isBlank()) {
personalityDescription.append("<p>").append(quirkDescription).append("</p>");
} else {
personalityDescription.append(quirkDescription);
}
}

person.setPersonalityDescription(personalityDescription.toString());
}

/**
* Retrieves the descriptions of all assigned personality traits for the given person. Each
* trait is processed to generate a detailed description, which is then collated into a list of
* strings.
* Retrieves the descriptions of all personality traits (other than Intelligence and Quirks) for
* the given person. This method processes various personality traits such as aggression, ambition,
* greed, and social behavior, generating descriptions based on the specified indices, gender,
* and given name of the person.
*
* <p>Descriptions for traits that are not assigned or are empty will be excluded from the
* returned list. This ensures only meaningful and applicable descriptions are included.
*
* @param person the person whose personality traits will be described
* @return a list of strings representing the descriptions of the person's traits, excluding
* default values
* @param gender the gender of the person, used for generating gender-specific pronouns in trait
* descriptions
* @param givenName the given name of the person, used to personalize the descriptions
* @param aggression the {@link Aggression} trait assigned to the person; omitted if the trait
* is set to "none"
* @param aggressionDescriptionIndex the index used to determine the specific {@link Aggression}
* description
* @param ambition the {@link Ambition} trait assigned to the person; omitted if the trait is set
* to "none"
* @param ambitionDescriptionIndex the index used to determine the specific {@link Ambition}
* description
* @param greed the {@link Greed} trait assigned to the person; omitted if the trait is set to
* "none"
* @param greedDescriptionIndex the index used to determine the specific {@link Greed} description
* @param social the {@link Social} behavior trait assigned to the person; omitted if the trait
* is set to "none"
* @param socialDescriptionIndex the index used to determine the specific {@link Social} description
* @return a list of strings, where each string represents a detailed description of a personality
* trait assigned to the given person; traits without meaningful descriptions are excluded
*/
private static List<String> getTraitDescriptions(Person person) {
private static List<String> getTraitDescriptions(Gender gender, String givenName,
Aggression aggression, int aggressionDescriptionIndex,
Ambition ambition, int ambitionDescriptionIndex,
Greed greed, int greedDescriptionIndex,
Social social, int socialDescriptionIndex) {
List<String> traitDescriptions = new ArrayList<>();

final Gender gender = person.getGender();
final String givenName = person.getGivenName();

// AGGRESSION
Aggression aggression = person.getAggression();
if (!aggression.isNone()) {
String traitDescription = aggression.getDescription(
person.getAggressionDescriptionIndex(), gender, givenName);
String traitDescription = aggression.getDescription(aggressionDescriptionIndex, gender,
givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
}
}

// AMBITION
Ambition ambition = person.getAmbition();
if (!ambition.isNone()) {
String traitDescription = ambition.getDescription(
person.getAmbitionDescriptionIndex(), gender, givenName);
String traitDescription = ambition.getDescription(ambitionDescriptionIndex, gender, givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
}
}

// GREED
Greed greed = person.getGreed();
if (!greed.isNone()) {
String traitDescription = greed.getDescription(
person.getGreedDescriptionIndex(), gender, givenName);
String traitDescription = greed.getDescription(greedDescriptionIndex, gender, givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
}
}

// SOCIAL
Social social = person.getSocial();
if (!social.isNone()) {
String traitDescription = social.getDescription(
person.getSocialDescriptionIndex(), gender, givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
}
}

// INTELLIGENCE
Intelligence intelligence = person.getIntelligence();
if (!intelligence.isAverageType()) {
String traitDescription = intelligence.getDescription(
person.getIntelligenceDescriptionIndex(), gender, givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
}
}

// PERSONALITY QUIRK
PersonalityQuirk personalityQuirk = person.getPersonalityQuirk();
if (!personalityQuirk.isNone()) {
String traitDescription = personalityQuirk.getDescription(
person.getPrimaryRole(), person.getPersonalityQuirkDescriptionIndex(), gender,
person.getOriginFaction(), givenName
);
String traitDescription = social.getDescription(socialDescriptionIndex, gender, givenName);

if (!traitDescription.isBlank()) {
traitDescriptions.add(traitDescription);
Expand Down Expand Up @@ -415,4 +451,29 @@ public static int getPersonalityValue(final boolean isUseRandomPersonalities,

return personalityValue;
}

/**
* A record to encapsulate pronoun information and associated data based on a given gender.
*/
public record PronounData(String subjectPronoun, String subjectPronounLowerCase, String objectPronoun,
String objectPronounLowerCase, String possessivePronoun, String possessivePronounLowerCase,
int pluralizer) {

/**
* Constructs a new {@code PronounData} record based on the specified gender.
*
* @param gender The gender used to determine the pronouns and pluralizer.
*/
public PronounData(Gender gender) {
this(
HE_SHE_THEY.getDescriptorCapitalized(gender),
HE_SHE_THEY.getDescriptorCapitalized(gender).toLowerCase(),
HIM_HER_THEM.getDescriptorCapitalized(gender),
HIM_HER_THEM.getDescriptorCapitalized(gender).toLowerCase(),
HIS_HER_THEIR.getDescriptorCapitalized(gender),
HIS_HER_THEIR.getDescriptorCapitalized(gender).toLowerCase(),
gender.isGenderNeutral() ? 0 : 1 // Used to determine whether to use a plural case
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import megamek.common.enums.Gender;
import megamek.logging.MMLogger;
import mekhq.campaign.randomEvents.personalities.PersonalityController.PronounData;

import static megamek.codeUtilities.MathUtility.clamp;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HE_SHE_THEY;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIM_HER_THEM;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIS_HER_THEIR;
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;

/**
Expand Down Expand Up @@ -93,7 +91,7 @@ public enum Aggression {
/**
* Defines the number of individual description variants available for each trait.
*/
public final static int MAXIMUM_VARIATIONS = 3;
public final static int MAXIMUM_VARIATIONS = 6;

/**
* The index at which major traits begin within the enumeration.
Expand Down Expand Up @@ -141,17 +139,20 @@ public String getDescription(int aggressionDescriptionIndex, final Gender gender
aggressionDescriptionIndex = clamp(aggressionDescriptionIndex, 0, MAXIMUM_VARIATIONS - 1);

final String RESOURCE_KEY = name() + ".description." + aggressionDescriptionIndex;

String subjectPronoun = HE_SHE_THEY.getDescriptorCapitalized(gender);
String subjectPronounLowerCase = HE_SHE_THEY.getDescriptor(gender);
String objectPronoun = HIM_HER_THEM.getDescriptorCapitalized(gender);
String objectPronounLowerCase = HIM_HER_THEM.getDescriptor(gender);
String possessivePronoun = HIS_HER_THEIR.getDescriptorCapitalized(gender);
String possessivePronounLowerCase = HIS_HER_THEIR.getDescriptor(gender);

return getFormattedTextAt(RESOURCE_BUNDLE, RESOURCE_KEY, givenName, subjectPronoun,
subjectPronounLowerCase, objectPronoun, objectPronounLowerCase, possessivePronoun,
possessivePronounLowerCase);
final PronounData pronounData = new PronounData(gender);

// {0} = givenName
// {1} = He/She/They
// {2} = he/she/they
// {3} = Him/Her/Them
// {4} = him/her/them
// {5} = His/Her/Their
// {6} = his/her/their
// {7} = Gender Neutral = 0, Otherwise 1 (used to determine whether to use plural case)

return getFormattedTextAt(RESOURCE_BUNDLE, RESOURCE_KEY, givenName, pronounData.subjectPronoun(),
pronounData.subjectPronounLowerCase(), pronounData.objectPronoun(), pronounData.objectPronounLowerCase(),
pronounData.possessivePronoun(), pronounData.possessivePronounLowerCase(), pronounData.pluralizer());
}

/**
Expand Down Expand Up @@ -192,7 +193,7 @@ public boolean isNone() {
*/
public static Aggression fromString(String text) {
try {
return Aggression.valueOf(text);
return Aggression.valueOf(text.toUpperCase().replace(" ", "_"));
} catch (Exception ignored) {}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import megamek.common.enums.Gender;
import megamek.logging.MMLogger;
import mekhq.campaign.randomEvents.personalities.PersonalityController.PronounData;

import static megamek.codeUtilities.MathUtility.clamp;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HE_SHE_THEY;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIM_HER_THEM;
import static mekhq.campaign.personnel.enums.GenderDescriptors.HIS_HER_THEIR;
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;

/**
Expand Down Expand Up @@ -92,7 +90,7 @@ public enum Ambition {
/**
* Defines the number of individual description variants available for each trait.
*/
public final static int MAXIMUM_VARIATIONS = 3;
public final static int MAXIMUM_VARIATIONS = 6;

/**
* The index at which major traits begin within the enumeration.
Expand Down Expand Up @@ -133,21 +131,25 @@ public String getLabel() {
* @return a formatted description string based on the enum,
* the individual's gender, name, and aggression description index.
*/
public String getDescription(int ambitionDescriptionIndex, final Gender gender, final String givenName) {
public String getDescription(int ambitionDescriptionIndex, final Gender gender,
final String givenName) {
ambitionDescriptionIndex = clamp(ambitionDescriptionIndex, 0, MAXIMUM_VARIATIONS - 1);

final String RESOURCE_KEY = name() + ".description." + ambitionDescriptionIndex;

String subjectPronoun = HE_SHE_THEY.getDescriptorCapitalized(gender);
String subjectPronounLowerCase = HE_SHE_THEY.getDescriptor(gender);
String objectPronoun = HIM_HER_THEM.getDescriptorCapitalized(gender);
String objectPronounLowerCase = HIM_HER_THEM.getDescriptor(gender);
String possessivePronoun = HIS_HER_THEIR.getDescriptorCapitalized(gender);
String possessivePronounLowerCase = HIS_HER_THEIR.getDescriptor(gender);

return getFormattedTextAt(RESOURCE_BUNDLE, RESOURCE_KEY, givenName, subjectPronoun,
subjectPronounLowerCase, objectPronoun, objectPronounLowerCase, possessivePronoun,
possessivePronounLowerCase);
final PronounData pronounData = new PronounData(gender);

// {0} = givenName
// {1} = He/She/They
// {2} = he/she/they
// {3} = Him/Her/Them
// {4} = him/her/them
// {5} = His/Her/Their
// {6} = his/her/their
// {7} = Gender Neutral = 0, Otherwise 1 (used to determine whether to use plural case)

return getFormattedTextAt(RESOURCE_BUNDLE, RESOURCE_KEY, givenName, pronounData.subjectPronoun(),
pronounData.subjectPronounLowerCase(), pronounData.objectPronoun(), pronounData.objectPronounLowerCase(),
pronounData.possessivePronoun(), pronounData.possessivePronounLowerCase(), pronounData.pluralizer());
}

/**
Expand Down Expand Up @@ -187,7 +189,7 @@ public boolean isNone() {
// region File I/O
public static Ambition fromString(String text) {
try {
return Ambition.valueOf(text);
return Ambition.valueOf(text.toUpperCase().replace(" ", "_"));
} catch (Exception ignored) {}

try {
Expand Down
Loading