Skip to content

Commit

Permalink
Merge pull request #5754 from IllianiCBT/birthdayBug
Browse files Browse the repository at this point in the history
Corrected Birthday Generation for Personnel
  • Loading branch information
HammerGS authored Jan 15, 2025
2 parents 5a064ba + 6aab372 commit 7badb32
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,32 @@ protected void generatePhenotype(Campaign campaign, Person person) {
}

/**
* Generates the birthday for a {@link Person}.
* @param campaign The {@link Campaign} which tracks the person.
* @param person The {@link Person} being generated.
* @param expLvl The experience level of {@code person}.
* @param isClanPersonnel A value indicating if {@code person} is from the Clans.
* Generates the birthday for a {@link Person} based on their experience level and affiliation.
* <p>
* The method calculates the person's age using {@link Utilities#getAgeByExpLevel(int, boolean)}
* and subtracts it from the current campaign date to determine their year of birth.
* A random day within that year is then selected, ensuring the generated birthday is
* always on or before the current campaign date, so the person's age is accurate.
* </p>
*
* @param campaign The {@link Campaign} containing metadata such as the current local date.
* @param person The {@link Person} whose birthday is being generated.
* @param expLvl The experience level of the {@code person}, which determines their age.
* @param isClanPersonnel Indicates whether the {@code person} belongs to the Clans,
* which affects the calculated age.
*/
protected void generateBirthday(Campaign campaign, Person person, int expLvl, boolean isClanPersonnel) {
LocalDate birthday = campaign.getLocalDate();
birthday = birthday.minusYears(Utilities.getAgeByExpLevel(expLvl, isClanPersonnel));
LocalDate currentDate = campaign.getLocalDate();
int age = Utilities.getAgeByExpLevel(expLvl, isClanPersonnel);

// Subtract age to get the target year
LocalDate birthday = currentDate.minusYears(age);

// choose a random day and month
int nDays = birthday.isLeapYear() ? 366 : 365;
// Constrain the random day to ensure the birthday is on or before the current date
int daysInYear = birthday.isLeapYear() ? 366 : 365;
int maxDay = Math.min(currentDate.getDayOfYear(), daysInYear);
int randomDay = Compute.randomInt(maxDay) + 1;

int randomDay = Compute.randomInt(nDays) + 1;
person.setDateOfBirth(birthday.withDayOfYear(randomDay));
}
}

0 comments on commit 7badb32

Please sign in to comment.