-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathAbstractProcreation.java
725 lines (616 loc) · 28.9 KB
/
AbstractProcreation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/*
* Copyright (C) 2021-2025 The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPL),
* version 3 or (at your option) any later version,
* as published by the Free Software Foundation.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* A copy of the GPL should have been included with this project;
* if not, see <https://www.gnu.org/licenses/>.
*
* NOTICE: The MegaMek organization is a non-profit group of volunteers
* creating free software for the BattleTech community.
*
* MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks
* of The Topps Company, Inc. All Rights Reserved.
*
* Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of
* InMediaRes Productions, LLC.
*/
package mekhq.campaign.personnel.procreation;
import static mekhq.campaign.mod.am.InjuryTypes.POSTPARTUM_RECOVERY;
import static mekhq.campaign.personnel.BodyLocation.INTERNAL;
import static mekhq.campaign.personnel.education.EducationController.setInitialEducationLevel;
import static mekhq.campaign.personnel.enums.BloodGroup.getInheritedBloodGroup;
import static mekhq.campaign.personnel.enums.BloodGroup.getRandomBloodGroup;
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.UUID;
import megamek.codeUtilities.MathUtility;
import megamek.common.Compute;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
import megamek.common.options.IOption;
import mekhq.MHQConstants;
import mekhq.campaign.Campaign;
import mekhq.campaign.CampaignOptions;
import mekhq.campaign.ExtraData.IntKey;
import mekhq.campaign.ExtraData.StringKey;
import mekhq.campaign.log.MedicalLogger;
import mekhq.campaign.log.PersonalLogger;
import mekhq.campaign.personnel.Injury;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.PersonnelOptions;
import mekhq.campaign.personnel.enums.FamilialRelationshipType;
import mekhq.campaign.personnel.enums.GenderDescriptors;
import mekhq.campaign.personnel.enums.PersonnelStatus;
import mekhq.campaign.personnel.enums.RandomProcreationMethod;
import mekhq.campaign.personnel.enums.education.EducationLevel;
import mekhq.campaign.personnel.lifeEvents.BirthAnnouncement;
import mekhq.campaign.randomEvents.prisoners.enums.PrisonerStatus;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Planet;
/**
* AbstractProcreation is the baseline class for procreation and birth in MekHQ. It holds all the common logic for
* procreation, and is implemented by classes defining how to determine if a female person will randomly procreate on a
* given day.
*/
public abstract class AbstractProcreation {
//region Variable Declarations
private final RandomProcreationMethod method;
private boolean useClanPersonnelProcreation;
private boolean usePrisonerProcreation;
private boolean useRelationshiplessProcreation;
private boolean useRandomClanPersonnelProcreation;
private boolean useRandomPrisonerProcreation;
public static final IntKey PREGNANCY_CHILDREN_DATA = new IntKey("procreation:children");
public static final StringKey PREGNANCY_FATHER_DATA = new StringKey("procreation:father");
private static final String RESOURCE_BUNDLE = "mekhq.resources." + AbstractProcreation.class.getSimpleName();
//endregion Variable Declarations
//region Constructors
protected AbstractProcreation(final RandomProcreationMethod method, final CampaignOptions options) {
this.method = method;
setUseClanPersonnelProcreation(options.isUseClanPersonnelProcreation());
setUsePrisonerProcreation(options.isUsePrisonerProcreation());
setUseRelationshiplessProcreation(options.isUseRelationshiplessRandomProcreation());
setUseRandomClanPersonnelProcreation(options.isUseRandomClanPersonnelProcreation());
setUseRandomPrisonerProcreation(options.isUseRandomPrisonerProcreation());
}
//endregion Constructors
//region Getters/Setters
public RandomProcreationMethod getMethod() {
return method;
}
public boolean isUseClanPersonnelProcreation() {
return useClanPersonnelProcreation;
}
public void setUseClanPersonnelProcreation(final boolean useClanPersonnelProcreation) {
this.useClanPersonnelProcreation = useClanPersonnelProcreation;
}
public boolean isUsePrisonerProcreation() {
return usePrisonerProcreation;
}
public void setUsePrisonerProcreation(final boolean usePrisonerProcreation) {
this.usePrisonerProcreation = usePrisonerProcreation;
}
public boolean isUseRelationshiplessProcreation() {
return useRelationshiplessProcreation;
}
public void setUseRelationshiplessProcreation(final boolean useRelationshiplessProcreation) {
this.useRelationshiplessProcreation = useRelationshiplessProcreation;
}
public boolean isUseRandomClanPersonnelProcreation() {
return useRandomClanPersonnelProcreation;
}
public void setUseRandomClanPersonnelProcreation(final boolean useRandomClanPersonnelProcreation) {
this.useRandomClanPersonnelProcreation = useRandomClanPersonnelProcreation;
}
public boolean isUseRandomPrisonerProcreation() {
return useRandomPrisonerProcreation;
}
public void setUseRandomPrisonerProcreation(final boolean useRandomPrisonerProcreation) {
this.useRandomPrisonerProcreation = useRandomPrisonerProcreation;
}
//endregion Getters/Setters
//region Determination Methods
/**
* This method determines the number of babies a person will give birth to.
*
* @param multiplePregnancyOccurrences the X occurrences for there to be a single multiple child occurrence (i.e., 1
* in X)
*
* @return the number of babies the person will give birth to, limited to decuplets
*/
protected int determineNumberOfBabies(final int multiplePregnancyOccurrences) {
int children = 1;
while ((Compute.randomInt(multiplePregnancyOccurrences) == 0) && (children < 10)) {
children++;
}
return children;
}
/**
* This method determines the duration for a pregnancy, with a variance determined through a Gaussian distribution
* with a maximum spread of approximately six weeks.
* <p>
* TODO : Swap me to instead use a distribution function that generates an overall length,
* TODO : Including pre-term and post-term births
*
* @return the pregnancy duration
*/
private int determinePregnancyDuration() {
// This creates a random range of approximately six weeks with which to modify the standard
// pregnancy duration to create a randomized pregnancy duration
final double gaussian = Math.sqrt(-2.0 * Math.log(Math.random())) * Math.cos(2.0 * Math.PI * Math.random());
// To not get unusual results, we limit the variance to +/- 4.0 (almost 6 weeks).
// A base length of 268 creates a solid enough duration for now.
return 268 + (int) Math.round(MathUtility.clamp(gaussian, -4d, 4d) * 10.0);
}
/**
* This determines the current week of the pregnancy
*
* @param today the current date
* @param person the pregnant person
*
* @return the current week of their pregnancy
*/
public int determinePregnancyWeek(final LocalDate today, final Person person) {
return (int) Math.max(Math.ceil(ChronoUnit.DAYS.between(person.getExpectedDueDate()
.minusDays(MHQConstants.PREGNANCY_STANDARD_DURATION),
today) / 7f), 1);
}
/**
* This determines the father of the baby.
*
* @param campaign the campaign the baby is part of
* @param mother the mother of the baby
*/
protected @Nullable Person determineFather(final Campaign campaign, final Person mother) {
return (campaign.getCampaignOptions().isDetermineFatherAtBirth() && mother.getGenealogy().hasSpouse()) ?
mother.getGenealogy().getSpouse() :
((mother.getExtraData().get(PREGNANCY_FATHER_DATA) != null) ?
campaign.getPerson(UUID.fromString(mother.getExtraData().get(PREGNANCY_FATHER_DATA))) :
null);
}
//endregion Determination Methods
/**
* This is used to determine if a person can procreate
*
* @param today the current date
* @param person the person to determine for
* @param randomProcreation if this is for random procreation or manual procreation
*
* @return null if they can, otherwise the reason why they cannot
*/
public @Nullable String canProcreate(final LocalDate today, final Person person, final boolean randomProcreation) {
if (person.getGender().isMale()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.Gender.text");
}
if (!person.isTryingToConceive()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.NotTryingForABaby.text");
}
if (person.isPregnant()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.AlreadyPregnant.text");
}
if (!person.getStatus().isActive()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.Inactive.text");
}
if (person.isDeployed()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.Deployed.text");
}
// Not allowing under-18s to procreate is project policy
if (person.isChild(today, true)) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.Child.text");
}
if (person.getAge(today) >= 51) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.TooOld.text");
}
if (!isUseClanPersonnelProcreation() && person.isClanPersonnel()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.ClanPersonnel.text");
}
if (!isUsePrisonerProcreation() && person.getPrisonerStatus().isCurrentPrisoner()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.Prisoner.text");
}
if (randomProcreation) {
if (!isUseRelationshiplessProcreation() && !person.getGenealogy().hasSpouse()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.NoSpouse.text");
}
if (!isUseRandomClanPersonnelProcreation() && person.isClanPersonnel()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.RandomClanPersonnel.text");
}
if (!isUseRandomPrisonerProcreation() && person.getPrisonerStatus().isCurrentPrisoner()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.RandomPrisoner.text");
}
if (person.getGenealogy().hasSpouse()) {
if (person.getGenealogy().getSpouse().getGender().isFemale()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.FemaleSpouse.text");
}
if (!person.getGenealogy().getSpouse().isTryingToConceive()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.SpouseNotTryingForABaby.text");
}
if (!person.getGenealogy().getSpouse().getStatus().isActive()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.InactiveSpouse.text");
}
if (person.getGenealogy().getSpouse().isDeployed()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.DeployedSpouse.text");
}
// Not allowing under-18s to procreate is project policy
// This conditional shouldn't be relevant in 2025, due to changes made in 2024.
// However, we're keeping it as we don't want campaigns from pre-policy
// implementation being able to circumnavigate project policy.
if (person.getGenealogy().getSpouse().isChild(today, true)) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.ChildSpouse.text");
}
if (!isUseRandomClanPersonnelProcreation() && person.getGenealogy().getSpouse().isClanPersonnel()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.ClanPersonnelSpouse.text");
}
if (!isUseRandomPrisonerProcreation() &&
person.getGenealogy().getSpouse().getPrisonerStatus().isCurrentPrisoner()) {
return getFormattedTextAt(RESOURCE_BUNDLE, "cannotProcreate.PrisonerSpouse.text");
}
}
}
return null;
}
/**
* This method is how a person becomes pregnant.
*
* @param campaign the campaign the person is a part of
* @param today the current date
* @param mother the newly pregnant mother
* @param isNoReport true if no message should be posted to the daily report
*/
public void addPregnancy(final Campaign campaign, final LocalDate today, final Person mother, boolean isNoReport) {
addPregnancy(campaign,
today,
mother,
determineNumberOfBabies(campaign.getCampaignOptions().getMultiplePregnancyOccurrences()),
isNoReport);
}
/**
* This method is how a person becomes pregnant with the specified number of children. They have their due date set,
* and the parentage of the pregnancy is determined.
*
* @param campaign the campaign the person is a part of
* @param today the current date
* @param mother the newly pregnant mother
* @param size the number of children the mother is having
* @param isNoReport true if no message should be posted to the daily report
*/
public void addPregnancy(final Campaign campaign, final LocalDate today, final Person mother, final int size,
boolean isNoReport) {
if (size < 1) {
return;
}
mother.setExpectedDueDate(today.plusDays(MHQConstants.PREGNANCY_STANDARD_DURATION));
mother.setDueDate(today.plusDays(determinePregnancyDuration()));
mother.getExtraData().set(PREGNANCY_CHILDREN_DATA, size);
mother.getExtraData()
.set(PREGNANCY_FATHER_DATA,
mother.getGenealogy().hasSpouse() ? mother.getGenealogy().getSpouse().getId().toString() : null);
final String babyAmount = getFormattedTextAt(RESOURCE_BUNDLE, "babyAmount.text").split(",")[size - 1];
if (!isNoReport) {
campaign.addReport(getFormattedTextAt(RESOURCE_BUNDLE,
"babyConceived.report",
mother.getHyperlinkedName(),
babyAmount).trim());
}
if (campaign.getCampaignOptions().isLogProcreation()) {
MedicalLogger.hasConceived(mother, today, babyAmount);
if (mother.getGenealogy().hasSpouse()) {
PersonalLogger.spouseConceived(mother.getGenealogy().getSpouse(),
mother.getFullName(),
today,
babyAmount);
}
}
}
/**
* Removes a pregnancy and clears all related data from the provided person
*
* @param person the person to clear the pregnancy data for
*/
public void removePregnancy(final Person person) {
person.setDueDate(null);
person.setExpectedDueDate(null);
person.getExtraData().set(PREGNANCY_CHILDREN_DATA, null);
person.getExtraData().set(PREGNANCY_FATHER_DATA, null);
}
/**
* This method is how a mother gives birth to a number of babies and has them added to the campaign.
*
* @param campaign the campaign to add the baby in question to
* @param today today's date
* @param mother the mother giving birth
*/
public void birth(final Campaign campaign, final LocalDate today, final Person mother) {
CampaignOptions campaignOptions = campaign.getCampaignOptions();
// Determine the number of children
final int size = mother.getExtraData().get(PREGNANCY_CHILDREN_DATA, 1);
// Determine father information
final Person father = determineFather(campaign, mother);
// Determine Prisoner Status
final PrisonerStatus prisonerStatus = PrisonerStatus.FREE;
// Output a specific report to the campaign if they are giving birth to multiple children
if (size > 1) {
campaign.addReport(getFormattedTextAt(RESOURCE_BUNDLE,
"multipleBabiesBorn.report",
mother.getHyperlinkedName(),
getFormattedTextAt(RESOURCE_BUNDLE, "babyAmount.text").split(",")[size - 1]));
}
// Create Babies
for (int i = 0; i < size; i++) {
// Create a baby
final Person baby = campaign.newDependent(Gender.RANDOMIZE,
mother.getOriginFaction(),
campaign.getLocation().getPlanet());
baby.setSurname(campaignOptions.getBabySurnameStyle()
.generateBabySurname(mother, father, baby.getGender()));
baby.setDateOfBirth(today);
baby.removeAllSkills();// Limit skills by age for children and adolescents
// re-roll SPAs to include in any age and skill adjustments
Enumeration<IOption> options = new PersonnelOptions().getOptions(PersonnelOptions.LVL3_ADVANTAGES);
for (IOption option : Collections.list(options)) {
baby.getOptions().getOption(option.getName()).clearValue();
}
baby.setBloodGroup(getInheritedBloodGroup(mother.getBloodGroup(),
father == null ? getRandomBloodGroup() : father.getBloodGroup()));
// Create reports and log the birth
campaign.addReport(getFormattedTextAt(RESOURCE_BUNDLE,
"babyBorn.report",
mother.getHyperlinkedName(),
baby.getHyperlinkedName(),
GenderDescriptors.BOY_GIRL.getDescriptor(baby.getGender())));
logAndUpdateFamily(campaign, today, mother, baby, father);
// Founder Tag Assignment
if (campaignOptions.isAssignNonPrisonerBabiesFounderTag() && !prisonerStatus.isCurrentPrisoner()) {
baby.setFounder(true);
} else if (campaignOptions.isAssignChildrenOfFoundersFounderTag()) {
baby.setFounder(baby.getGenealogy().getParents().stream().anyMatch(Person::isFounder));
}
// set education
baby.setEduHighestEducation(EducationLevel.EARLY_CHILDHOOD);
// set loyalty
baby.setLoyalty(Compute.d6(4, 3));
// Recruit the baby
campaign.recruitPerson(baby, prisonerStatus, true, true);
// if the mother is at school, add the baby to the list of tag alongs
if (mother.getStatus().isStudent()) {
mother.addEduTagAlong(baby.getId());
baby.changeStatus(campaign, today, PersonnelStatus.ON_LEAVE);
}
// Apply postpartum effects
if (campaignOptions.isUseAdvancedMedical()) {
Injury injury = POSTPARTUM_RECOVERY.newInjury(campaign, mother, INTERNAL, 1);
mother.addInjury(injury);
} else {
int currentHits = mother.getHits();
mother.setHits(currentHits + 1);
}
// Alert the player
if (campaignOptions.isShowLifeEventDialogBirths()) {
new BirthAnnouncement(campaign, mother, baby.getGender(), size);
}
}
// adjust parents' loyalty
if (father != null) {
father.performRandomizedLoyaltyChange(campaign, false, true);
}
mother.performRandomizedLoyaltyChange(campaign, false, true);
// check desire for children
if (Compute.d6(1) <= 2) {
mother.setTryingToConceive(false);
}
// Cleanup Data
removePregnancy(mother);
// Return from Maternity leave
if (mother.getStatus().isOnMaternityLeave()) {
mother.changeStatus(campaign, today, PersonnelStatus.ACTIVE);
}
}
/**
* Logs the birth of a baby and updates the genealogy information of the family.
*
* @param campaign the ongoing campaign
* @param today the current date
* @param mother the mother of the baby
* @param baby the newborn baby
* @param father the father of the baby, null if unknown
*/
private static void logAndUpdateFamily(Campaign campaign, LocalDate today, Person mother, Person baby,
Person father) {
if (campaign.getCampaignOptions().isLogProcreation()) {
MedicalLogger.deliveredBaby(mother, baby, today);
if (father != null) {
PersonalLogger.ourChildBorn(father, baby, mother.getFullName(), today);
}
}
// Create genealogy information
baby.getGenealogy().addFamilyMember(FamilialRelationshipType.PARENT, mother);
mother.getGenealogy().addFamilyMember(FamilialRelationshipType.CHILD, baby);
if (father != null) {
baby.getGenealogy().addFamilyMember(FamilialRelationshipType.PARENT, father);
father.getGenealogy().addFamilyMember(FamilialRelationshipType.CHILD, baby);
}
}
/**
* Creates baby/babies and performs any necessary operations such as setting birthdate, creating reports, updating
* genealogy, setting education, loyalty, personality, and recruiting the baby. This version is for historic births
* that occur as part of a character's background.
*
* @param campaign the campaign object
* @param today the current date
* @param mother the mother person object
* @param father the father person object, can be null if the father is unknown
*
* @return the babies
*/
public List<Person> birthHistoric(final Campaign campaign, final LocalDate today, final Person mother,
@Nullable final Person father) {
List<Person> babies = new ArrayList<>();
// Determine the number of children
final int size = mother.getExtraData().get(PREGNANCY_CHILDREN_DATA, 1);
// Create Babies
for (int i = 0; i < size; i++) {
// Create the babies
Faction originFaction = mother.getOriginFaction();
Planet originPlanet = mother.getOriginPlanet();
if (father != null && Compute.randomInt(1) == 0) {
originFaction = father.getOriginFaction();
originPlanet = father.getOriginPlanet();
}
final Person baby = campaign.newDependent(Gender.RANDOMIZE, originFaction, originPlanet);
baby.setSurname(campaign.getCampaignOptions()
.getBabySurnameStyle()
.generateBabySurname(mother, father, baby.getGender()));
baby.setDateOfBirth(mother.getDueDate());
baby.removeAllSkills();// Limit skills by age for children and adolescents
// re-roll SPAs to include in any age and skill adjustments
Enumeration<IOption> options = new PersonnelOptions().getOptions(PersonnelOptions.LVL3_ADVANTAGES);
for (IOption option : Collections.list(options)) {
baby.getOptions().getOption(option.getName()).clearValue();
}
baby.setLoyalty(Compute.d6(3) + 2);
// set education based on age
setInitialEducationLevel(campaign, baby);
// Create reports and log the birth
logAndUpdateFamily(campaign, today, mother, baby, father);
// add to the list of babies
babies.add(baby);
}
if (Compute.d6(1) <= 2) {
mother.setTryingToConceive(false);
}
// Cleanup Data
removePregnancy(mother);
return babies;
}
/**
* This is used to process procreation when a person dies with the Pregnancy Complications status
*
* @param campaign the campaign to add the baby to
* @param today the current date
* @param person the person to process
*/
public void processPregnancyComplications(final Campaign campaign, final LocalDate today, final Person person) {
// The child might be able to be born, albeit into a world without their mother.
// The status, however, can be manually set for males and for those who are not pregnant.
// This is purposeful to allow for player customization, and thus we first check if they
// are pregnant before checking if the birth occurs
if (!person.isPregnant()) {
return;
}
final int pregnancyWeek = determinePregnancyWeek(today, person);
final double babyBornChance = getBabyBornChance(pregnancyWeek);
if (Compute.randomFloat() < babyBornChance) {
birth(campaign, today, person);
}
}
/**
* Calculates the chance of a baby being born based on the pregnancy week.
*
* @param pregnancyWeek the week of the pregnancy
*
* @return the chance of a baby being born, ranging from 0.0 to 1.0
*/
private static double getBabyBornChance(int pregnancyWeek) {
int range = switch (pregnancyWeek) {
case 23 -> 1;
case 24 -> 2;
case 25 -> 3;
default -> (pregnancyWeek > 25 && pregnancyWeek <= 29) ?
4 :
(pregnancyWeek > 29 && pregnancyWeek <= 35) ? 5 : (pregnancyWeek > 35) ? 6 : 0;
};
return switch (range) {
case 1 -> 0.25;
case 2 -> 0.5;
case 3 -> 0.8;
case 4 -> 0.9;
case 5 -> 0.95;
case 6 -> 0.99;
default -> 0.0;
};
}
//region New Day
/**
* Process new day procreation for an individual
*
* @param campaign the campaign to process
* @param today the current day
* @param person the person to process
*/
public void processNewWeek(final Campaign campaign, final LocalDate today, final Person person) {
// Instantly return for male personnel
if (person.getGender().isMale()) {
return;
}
// Check if they are already pregnant
if (person.isPregnant()) {
// They give birth if the due date has passed
if ((today.isAfter(person.getDueDate())) || (today.isEqual(person.getDueDate()))) {
birth(campaign, today, person);
return;
}
if (campaign.getCampaignOptions().isUseMaternityLeave()) {
if (!person.isBusy() && (person.getDueDate().minusWeeks(20).isBefore(today))) {
person.changeStatus(campaign, today, PersonnelStatus.ON_MATERNITY_LEAVE);
}
}
return;
}
// Make the required checks for random procreation
processRandomProcreationCheck(campaign, today, person, false);
}
/**
* Checks if a person randomly procreates on the given day in the campaign. If the person does procreate, add a
* pregnancy to the campaign for the person.
*
* @param campaign The campaign to check procreation for.
* @param today The current date.
* @param person The person to check for procreation.
* @param isNoReport true, if the player shouldn't be informed, otherwise false
*/
public void processRandomProcreationCheck(final Campaign campaign, final LocalDate today, final Person person,
boolean isNoReport) {
if (randomlyProcreates(today, person)) {
addPregnancy(campaign, today, person, isNoReport);
}
}
//region Random Procreation
/**
* Determines if a non-pregnant woman procreates on a given day
*
* @param today the current day
* @param person the person in question
*
* @return true if they do, otherwise false
*/
protected boolean randomlyProcreates(final LocalDate today, final Person person) {
if (canProcreate(today, person, true) != null) {
return false;
} else {
return procreation(person);
}
}
/**
* Determines if a person with an eligible partner procreates
*
* @param person the person to determine for
*
* @return true if they do, otherwise false
*/
protected abstract boolean procreation(Person person);
}