forked from MegaMek/mekhq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.java
5805 lines (5022 loc) · 231 KB
/
Person.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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2009 - Jay Lawson (jaylawson39 at yahoo.com). All Rights Reserved.
* Copyright (C) 2020-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;
import static java.lang.Math.abs;
import static java.lang.Math.floor;
import static java.lang.Math.min;
import static java.lang.Math.round;
import static megamek.codeUtilities.MathUtility.clamp;
import static megamek.common.Compute.randomInt;
import static megamek.common.enums.SkillLevel.REGULAR;
import static mekhq.campaign.personnel.PersonnelOptions.*;
import static mekhq.campaign.personnel.enums.BloodGroup.getRandomBloodGroup;
import static mekhq.campaign.personnel.skills.Attributes.MAXIMUM_ATTRIBUTE_SCORE;
import static mekhq.campaign.personnel.skills.Attributes.MINIMUM_ATTRIBUTE_SCORE;
import static mekhq.campaign.personnel.skills.Aging.getReputationAgeModifier;
import static mekhq.campaign.personnel.skills.SkillType.S_ADMIN;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import megamek.Version;
import megamek.client.generator.RandomNameGenerator;
import megamek.codeUtilities.MathUtility;
import megamek.codeUtilities.StringUtility;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
import megamek.common.enums.SkillLevel;
import megamek.common.icons.Portrait;
import megamek.common.options.IOption;
import megamek.common.options.IOptionGroup;
import megamek.common.options.OptionsConstants;
import megamek.common.options.PilotOptions;
import megamek.logging.MMLogger;
import mekhq.MekHQ;
import mekhq.Utilities;
import mekhq.campaign.Campaign;
import mekhq.campaign.CampaignOptions;
import mekhq.campaign.ExtraData;
import mekhq.campaign.event.PersonChangedEvent;
import mekhq.campaign.event.PersonStatusChangedEvent;
import mekhq.campaign.finances.Money;
import mekhq.campaign.force.Force;
import mekhq.campaign.log.LogEntry;
import mekhq.campaign.log.LogEntryFactory;
import mekhq.campaign.log.PersonalLogger;
import mekhq.campaign.log.ServiceLogger;
import mekhq.campaign.mod.am.InjuryUtil;
import mekhq.campaign.parts.Part;
import mekhq.campaign.personnel.enums.BloodGroup;
import mekhq.campaign.personnel.enums.ManeiDominiClass;
import mekhq.campaign.personnel.enums.ManeiDominiRank;
import mekhq.campaign.personnel.enums.ModifierValue;
import mekhq.campaign.personnel.enums.PersonnelRole;
import mekhq.campaign.personnel.enums.PersonnelStatus;
import mekhq.campaign.personnel.enums.Phenotype;
import mekhq.campaign.personnel.enums.Profession;
import mekhq.campaign.personnel.enums.ROMDesignation;
import mekhq.campaign.personnel.enums.education.EducationLevel;
import mekhq.campaign.personnel.enums.education.EducationStage;
import mekhq.campaign.personnel.familyTree.Genealogy;
import mekhq.campaign.personnel.ranks.Rank;
import mekhq.campaign.personnel.ranks.RankSystem;
import mekhq.campaign.personnel.ranks.RankValidator;
import mekhq.campaign.personnel.ranks.Ranks;
import mekhq.campaign.personnel.skills.Attributes;
import mekhq.campaign.personnel.skills.Skill;
import mekhq.campaign.personnel.skills.SkillType;
import mekhq.campaign.personnel.skills.Skills;
import mekhq.campaign.personnel.skills.enums.SkillAttribute;
import mekhq.campaign.randomEvents.personalities.enums.Aggression;
import mekhq.campaign.randomEvents.personalities.enums.Ambition;
import mekhq.campaign.randomEvents.personalities.enums.Greed;
import mekhq.campaign.randomEvents.personalities.enums.PersonalityQuirk;
import mekhq.campaign.randomEvents.personalities.enums.Reasoning;
import mekhq.campaign.randomEvents.personalities.enums.Social;
import mekhq.campaign.randomEvents.prisoners.enums.PrisonerStatus;
import mekhq.campaign.unit.Unit;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Factions;
import mekhq.campaign.universe.Planet;
import mekhq.campaign.universe.PlanetarySystem;
import mekhq.campaign.work.IPartWork;
import mekhq.utilities.MHQXMLUtility;
import mekhq.utilities.ReportingUtilities;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* @author Jay Lawson (jaylawson39 at yahoo.com)
* @author Justin "Windchild" Bowen
*/
public class Person {
// region Variable Declarations
public static final Map<Integer, Money> MEKWARRIOR_AERO_RANSOM_VALUES;
public static final Map<Integer, Money> OTHER_RANSOM_VALUES;
// Traits
public static final int TRAIT_MODIFICATION_COST = 100;
public static final String CONNECTIONS_LABEL = "CONNECTIONS";
public static final int MINIMUM_CONNECTIONS = 0;
public static final int MAXIMUM_CONNECTIONS = 10;
public static final String REPUTATION_LABEL = "REPUTATION";
public static final int MINIMUM_REPUTATION = -5;
public static final int MAXIMUM_REPUTATION = 5;
public static final String WEALTH_LABEL = "WEALTH";
public static final int MINIMUM_WEALTH = -1;
public static final int MAXIMUM_WEALTH = 10;
public static final String UNLUCKY_LABEL = "UNLUCKY";
public static final int MINIMUM_UNLUCKY = 0;
public static final int MAXIMUM_UNLUCKY = 5;
private PersonAwardController awardController;
// region Family Variables
// Lineage
private final Genealogy genealogy;
// region Procreation
private LocalDate dueDate;
private LocalDate expectedDueDate;
// endregion Procreation
// endregion Family Variables
private UUID id;
// region Name
private transient String fullName; // this is a runtime variable, and shouldn't be saved
private String preNominal;
private String givenName;
private String surname;
private String postNominal;
private String maidenName;
private String callsign;
// endregion Name
private Gender gender;
private BloodGroup bloodGroup;
private Portrait portrait;
private PersonnelRole primaryRole;
private PersonnelRole secondaryRole;
private ROMDesignation primaryDesignator;
private ROMDesignation secondaryDesignator;
private String biography;
private LocalDate birthday;
private LocalDate joinedCampaign;
private LocalDate recruitment;
private LocalDate lastRankChangeDate;
private LocalDate dateOfDeath;
private List<LogEntry> personnelLog;
private List<LogEntry> scenarioLog;
// this is used by autoAwards to abstract the support person of the year award
private int autoAwardSupportPoints;
private LocalDate retirement;
private int loyalty;
private int fatigue;
private Boolean isRecoveringFromFatigue;
private Skills skills;
private PersonnelOptions options;
private int toughness;
private int connections;
private int wealth;
private boolean hasPerformedExtremeExpenditure;
private int reputation;
private int unlucky;
private Attributes atowAttributes;
private PersonnelStatus status;
private int xp;
private int totalXPEarnings;
private int acquisitions;
private Money salary;
private Money totalEarnings;
private int hits;
private int hitsPrior;
private PrisonerStatus prisonerStatus;
// Supports edge usage by a ship's engineer composite crewman
private int edgeUsedThisRound;
// To track how many edge points personnel have left until next refresh
private int currentEdge;
// phenotype and background
private Phenotype phenotype;
private String bloodname;
private Faction originFaction;
private Planet originPlanet;
private LocalDate becomingBondsmanEndDate;
// assignments
private Unit unit;
private UUID doctorId;
private List<Unit> techUnits;
private int vocationalXPTimer;
// days of rest
private int daysToWaitForHealing;
// Our rank
private RankSystem rankSystem;
private int rank;
private int rankLevel;
private ManeiDominiClass maneiDominiClass;
private ManeiDominiRank maneiDominiRank;
// stuff to track for support teams
private int minutesLeft;
private int overtimeLeft;
private int nTasks;
private boolean engineer;
public static final int PRIMARY_ROLE_SUPPORT_TIME = 480;
public static final int PRIMARY_ROLE_OVERTIME_SUPPORT_TIME = 240;
public static final int SECONDARY_ROLE_SUPPORT_TIME = 240;
public static final int SECONDARY_ROLE_OVERTIME_SUPPORT_TIME = 120;
// region Advanced Medical
private List<Injury> injuries;
// endregion Advanced Medical
// region Against the Bot
private int originalUnitWeight; // uses EntityWeightClass with 0 (Extra-Light) for no original unit
public static final int TECH_IS1 = 0;
public static final int TECH_IS2 = 1;
public static final int TECH_CLAN = 2;
private int originalUnitTech;
private UUID originalUnitId;
// endregion Against the Bot
// region Education
private EducationLevel eduHighestEducation;
private String eduAcademyName;
private String eduAcademySet;
private String eduAcademyNameInSet;
private String eduAcademyFaction;
private String eduAcademySystem;
private int eduCourseIndex;
private EducationStage eduEducationStage;
private int eduJourneyTime;
private int eduEducationTime;
private int eduDaysOfTravel;
private List<UUID> eduTagAlongs;
private List<String> eduFailedApplications;
// endregion Education
// region Personality
private Aggression aggression;
private int aggressionDescriptionIndex;
private Ambition ambition;
private int ambitionDescriptionIndex;
private Greed greed;
private int greedDescriptionIndex;
private Social social;
private int socialDescriptionIndex;
private PersonalityQuirk personalityQuirk;
private int personalityQuirkDescriptionIndex;
private Reasoning reasoning;
private int reasoningDescriptionIndex;
private String personalityDescription;
// endregion Personality
// region Flags
private boolean clanPersonnel;
private boolean commander;
private boolean divorceable;
private boolean founder; // +1 share if using shares system
private boolean immortal;
// this is a flag used in determine whether a person is a potential marriage
// candidate provided
// that they are not married, are old enough, etc.
private boolean marriageable;
// this is a flag used in random procreation to determine whether to attempt to
// procreate
private boolean tryingToConceive;
// endregion Flags
// Generic extra data, for use with plugins and mods
private ExtraData extraData;
private final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.Personnel",
MekHQ.getMHQOptions().getLocale());
private static final MMLogger logger = MMLogger.create(Person.class);
// initializes the AtB ransom values
static {
MEKWARRIOR_AERO_RANSOM_VALUES = new HashMap<>();
// no official AtB rules for really inexperienced scrubs, but...
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_NONE, Money.of(2500));
// no official AtB rules for really inexperienced scrubs, but...
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_ULTRA_GREEN, Money.of(5000));
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_GREEN, Money.of(10000));
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_REGULAR, Money.of(25000));
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_VETERAN, Money.of(50000));
MEKWARRIOR_AERO_RANSOM_VALUES.put(SkillType.EXP_ELITE, Money.of(100000));
OTHER_RANSOM_VALUES = new HashMap<>();
OTHER_RANSOM_VALUES.put(SkillType.EXP_NONE, Money.of(1250));
OTHER_RANSOM_VALUES.put(SkillType.EXP_ULTRA_GREEN, Money.of(2500));
OTHER_RANSOM_VALUES.put(SkillType.EXP_GREEN, Money.of(5000));
OTHER_RANSOM_VALUES.put(SkillType.EXP_REGULAR, Money.of(10000));
OTHER_RANSOM_VALUES.put(SkillType.EXP_VETERAN, Money.of(25000));
OTHER_RANSOM_VALUES.put(SkillType.EXP_ELITE, Money.of(50000));
}
// endregion Variable Declarations
// region Constructors
protected Person(final UUID id) {
this.id = id;
this.genealogy = new Genealogy(this);
}
public Person(final Campaign campaign) {
this(RandomNameGenerator.UNNAMED, RandomNameGenerator.UNNAMED_SURNAME, campaign);
}
public Person(final Campaign campaign, final String factionCode) {
this(RandomNameGenerator.UNNAMED, RandomNameGenerator.UNNAMED_SURNAME, campaign, factionCode);
}
public Person(final String givenName, final String surname, final Campaign campaign) {
this(givenName, surname, campaign, campaign.getFactionCode());
}
public Person(final String givenName, final String surname, final @Nullable Campaign campaign,
final String factionCode) {
this("", givenName, surname, "", campaign, factionCode);
}
/**
* Primary Person constructor, variables are initialized in the exact same order as they are saved to the XML file
*
* @param preNominal the person's pre-nominal
* @param givenName the person's given name
* @param surname the person's surname
* @param postNominal the person's post-nominal
* @param campaign the campaign this person is a part of, or null (unit testing only)
* @param factionCode the faction this person was borne into
*/
public Person(final String preNominal, final String givenName, final String surname, final String postNominal,
final @Nullable Campaign campaign, final String factionCode) {
// We assign the variables in XML file order
id = UUID.randomUUID();
// region Name
setPreNominalDirect(preNominal);
setGivenNameDirect(givenName);
setSurnameDirect(surname);
setPostNominalDirect(postNominal);
setMaidenName(null); // this is set to null to handle divorce cases
setCallsignDirect("");
// endregion Name
primaryRole = PersonnelRole.NONE;
secondaryRole = PersonnelRole.NONE;
primaryDesignator = ROMDesignation.NONE;
secondaryDesignator = ROMDesignation.NONE;
setDateOfBirth(LocalDate.now());
originFaction = Factions.getInstance().getFaction(factionCode);
originPlanet = null;
becomingBondsmanEndDate = null;
phenotype = Phenotype.NONE;
bloodname = "";
biography = "";
this.genealogy = new Genealogy(this);
dueDate = null;
expectedDueDate = null;
setPortrait(new Portrait());
setXPDirect(0);
setTotalXPEarnings(0);
daysToWaitForHealing = 0;
setGender(Gender.MALE);
setRankSystemDirect((campaign == null) ? null : campaign.getRankSystem());
setRank(0);
setRankLevel(0);
setManeiDominiClassDirect(ManeiDominiClass.NONE);
setManeiDominiRankDirect(ManeiDominiRank.NONE);
nTasks = 0;
doctorId = null;
salary = Money.of(-1);
totalEarnings = Money.of(0);
status = PersonnelStatus.ACTIVE;
prisonerStatus = PrisonerStatus.FREE;
hits = 0;
hitsPrior = 0;
toughness = 0;
connections = 0;
wealth = 0;
hasPerformedExtremeExpenditure = false;
reputation = 0;
unlucky = 0;
atowAttributes = new Attributes();
dateOfDeath = null;
recruitment = null;
joinedCampaign = null;
lastRankChangeDate = null;
autoAwardSupportPoints = 0;
retirement = null;
loyalty = 9;
fatigue = 0;
isRecoveringFromFatigue = false;
skills = new Skills();
options = new PersonnelOptions();
currentEdge = 0;
techUnits = new ArrayList<>();
personnelLog = new ArrayList<>();
scenarioLog = new ArrayList<>();
awardController = new PersonAwardController(this);
injuries = new ArrayList<>();
originalUnitWeight = EntityWeightClass.WEIGHT_ULTRA_LIGHT;
originalUnitTech = TECH_IS1;
originalUnitId = null;
acquisitions = 0;
eduHighestEducation = EducationLevel.EARLY_CHILDHOOD;
eduAcademyName = null;
eduAcademySystem = null;
eduCourseIndex = 0;
eduEducationStage = EducationStage.NONE;
eduJourneyTime = 0;
eduEducationTime = 0;
eduDaysOfTravel = 0;
eduTagAlongs = new ArrayList<>();
eduFailedApplications = new ArrayList<>();
eduAcademySet = null;
eduAcademyNameInSet = null;
eduAcademyFaction = null;
aggression = Aggression.NONE;
aggressionDescriptionIndex = randomInt(Aggression.MAXIMUM_VARIATIONS);
ambition = Ambition.NONE;
ambitionDescriptionIndex = randomInt(Ambition.MAXIMUM_VARIATIONS);
greed = Greed.NONE;
greedDescriptionIndex = randomInt(Greed.MAXIMUM_VARIATIONS);
social = Social.NONE;
socialDescriptionIndex = randomInt(Social.MAXIMUM_VARIATIONS);
personalityQuirk = PersonalityQuirk.NONE;
personalityQuirkDescriptionIndex = randomInt(PersonalityQuirk.MAXIMUM_VARIATIONS);
reasoning = Reasoning.AVERAGE;
reasoningDescriptionIndex = randomInt(Reasoning.MAXIMUM_VARIATIONS);
personalityDescription = "";
// This assigns minutesLeft and overtimeLeft. Must be after skills to avoid an NPE.
if (campaign != null) {
// The reason for this paranoid checking is to allow us to Unit Test with real Person objects without
// needing
// to initialize CampaignOptions
CampaignOptions campaignOptions = campaign.getCampaignOptions();
if (campaignOptions != null) {
resetMinutesLeft(campaignOptions.isTechsUseAdministration());
}
}
// region Flags
setClanPersonnel(originFaction.isClan());
setCommander(false);
setDivorceable(true);
setFounder(false);
setImmortal(false);
setMarriageable(true);
setTryingToConceive(true);
// endregion Flags
extraData = new ExtraData();
// Initialize Data based on these settings
setFullName();
}
// endregion Constructors
public Phenotype getPhenotype() {
return phenotype;
}
public void setPhenotype(final Phenotype phenotype) {
this.phenotype = phenotype;
}
public String getBloodname() {
return bloodname;
}
public void setBloodname(final String bloodname) {
this.bloodname = bloodname;
setFullName();
}
public Faction getOriginFaction() {
return originFaction;
}
public void setOriginFaction(final Faction originFaction) {
this.originFaction = originFaction;
}
public Planet getOriginPlanet() {
return originPlanet;
}
public void setOriginPlanet(final Planet originPlanet) {
this.originPlanet = originPlanet;
}
public LocalDate getBecomingBondsmanEndDate() {
return becomingBondsmanEndDate;
}
public void setBecomingBondsmanEndDate(final LocalDate becomingBondsmanEndDate) {
this.becomingBondsmanEndDate = becomingBondsmanEndDate;
}
public PrisonerStatus getPrisonerStatus() {
return prisonerStatus;
}
/**
* This requires expanded checks because a number of functionalities are strictly dependent on the current person's
* prisoner status.
*
* @param campaign the campaign the person is a part of
* @param prisonerStatus The new prisoner status for the person in question
* @param log whether to log the change or not
*/
public void setPrisonerStatus(final Campaign campaign, final PrisonerStatus prisonerStatus, final boolean log) {
// This must be processed completely, as the unchanged prisoner status of Free
// to Free is
// used during recruitment
final boolean freed = !getPrisonerStatus().isFree();
final boolean isPrisoner = prisonerStatus.isCurrentPrisoner();
setPrisonerStatusDirect(prisonerStatus);
// Now, we need to fix values and ranks based on the Person's status
switch (prisonerStatus) {
case PRISONER:
case PRISONER_DEFECTOR:
case BECOMING_BONDSMAN:
setRecruitment(null);
setLastRankChangeDate(null);
if (log) {
if (isPrisoner) {
ServiceLogger.madePrisoner(this, campaign.getLocalDate(), campaign.getName(), "");
} else {
ServiceLogger.madeBondsman(this, campaign.getLocalDate(), campaign.getName(), "");
}
}
break;
case BONDSMAN:
LocalDate today = campaign.getLocalDate();
setRecruitment(today);
setLastRankChangeDate(today);
break;
case FREE:
if (!getPrimaryRole().isDependent()) {
if (campaign.getCampaignOptions().isUseTimeInService()) {
setRecruitment(campaign.getLocalDate());
}
if (campaign.getCampaignOptions().isUseTimeInRank()) {
setLastRankChangeDate(campaign.getLocalDate());
}
}
if (log) {
if (freed) {
ServiceLogger.freed(this, campaign.getLocalDate(), campaign.getName(), "");
} else {
ServiceLogger.joined(this, campaign.getLocalDate(), campaign.getName(), "");
}
}
break;
}
if (!prisonerStatus.isFree()) {
if (getUnit() != null) {
getUnit().remove(this, true);
}
}
MekHQ.triggerEvent(new PersonChangedEvent(this));
}
/**
* This is public for unit testing reasons
*
* @param prisonerStatus the person's new prisoner status
*/
public void setPrisonerStatusDirect(final PrisonerStatus prisonerStatus) {
this.prisonerStatus = prisonerStatus;
}
// region Text Getters
public String pregnancyStatus() {
return isPregnant() ? " (Pregnant)" : "";
}
// endregion Text Getters
// region Name
/**
* @return the person's full name
*/
public String getFullName() {
return fullName;
}
/**
* @return a hyperlinked string for the person's name
*/
public String getHyperlinkedName() {
return String.format("<a href='PERSON:%s'>%s</a>", getId(), getFullName());
}
/**
* This is used to create the full name of the person, based on their first and last names
*/
public void setFullName() {
final String lastName = getLastName();
setFullNameDirect(getFirstName() +
(getCallsign().isBlank() ? "" : (" \"" + getCallsign() + '"')) +
(lastName.isBlank() ? "" : ' ' + lastName));
}
/**
* @param fullName this sets the full name to be equal to the input string. This can ONLY be called by
* {@link Person#setFullName()} or its overrides.
*/
protected void setFullNameDirect(final String fullName) {
this.fullName = fullName;
}
/**
* @return a String containing the person's first name including their pre-nominal
*/
public String getFirstName() {
return (getPreNominal().isBlank() ? "" : (getPreNominal() + ' ')) + getGivenName();
}
/**
* Return a full last name which may be a bloodname or a surname with or without a post-nominal. A bloodname will
* overrule a surname but we do not disallow surnames for clan personnel, if the player wants to input them
*
* @return a String of the person's last name
*/
public String getLastName() {
String lastName = !StringUtility.isNullOrBlank(getBloodname()) ?
getBloodname() :
!StringUtility.isNullOrBlank(getSurname()) ? getSurname() : "";
if (!StringUtility.isNullOrBlank(getPostNominal())) {
lastName += (lastName.isBlank() ? "" : " ") + getPostNominal();
}
return lastName;
}
/**
* @return the person's pre-nominal
*/
public String getPreNominal() {
return preNominal;
}
/**
* @param preNominal the person's new pre-nominal
*/
public void setPreNominal(final String preNominal) {
setPreNominalDirect(preNominal);
setFullName();
}
protected void setPreNominalDirect(final String preNominal) {
this.preNominal = preNominal;
}
/**
* @return the person's given name
*/
public String getGivenName() {
return givenName;
}
/**
* @param givenName the person's new given name
*/
public void setGivenName(final String givenName) {
setGivenNameDirect(givenName);
setFullName();
}
protected void setGivenNameDirect(final String givenName) {
this.givenName = givenName;
}
/**
* @return the person's surname
*/
public String getSurname() {
return surname;
}
/**
* @param surname the person's new surname
*/
public void setSurname(final String surname) {
setSurnameDirect(surname);
setFullName();
}
protected void setSurnameDirect(final String surname) {
this.surname = surname;
}
/**
* @return the person's post-nominal
*/
public String getPostNominal() {
return postNominal;
}
/**
* @param postNominal the person's new post-nominal
*/
public void setPostNominal(final String postNominal) {
setPostNominalDirect(postNominal);
setFullName();
}
protected void setPostNominalDirect(final String postNominal) {
this.postNominal = postNominal;
}
/**
* @return the person's maiden name
*/
public @Nullable String getMaidenName() {
return maidenName;
}
/**
* @param maidenName the person's new maiden name
*/
public void setMaidenName(final @Nullable String maidenName) {
this.maidenName = maidenName;
}
/**
* @return the person's callsign
*/
public String getCallsign() {
return callsign;
}
/**
* @param callsign the person's new callsign
*/
public void setCallsign(final String callsign) {
setCallsignDirect(callsign);
setFullName();
}
protected void setCallsignDirect(final String callsign) {
this.callsign = callsign;
}
/**
* This method is used to migrate names from being a joined name to split between given name and surname, as part of
* the Personnel changes in MekHQ 0.47.4, and is used to migrate from MM-style names to MHQ-style names
*
* @param text text containing the name to be migrated
*/
public void migrateName(final String text) {
// How this works:
// Takes the input name, and splits it into individual parts.
// Then, it depends on whether the person is Clan or not.
// For Clan names:
// Takes the input name, and assumes that person does not have a surname
// Bloodnames are assumed to have been assigned by MekHQ
// For Inner Sphere names:
// Depending on the length of the resulting array, the name is processed
// differently
// Array of length 1: the name is assumed to not have a surname, just a given
// name
// Array of length 2: the name is assumed to be a given name and a surname
// Array of length 3: the name is assumed to be a given name and two surnames
// Array of length 4+: the name is assumed to be as many given names as possible
// and two surnames
//
// Then, the full name is set
final String[] name = text.trim().split("\\s+");
final StringBuilder givenName = new StringBuilder(name[0]);
if (isClanPersonnel()) {
if (name.length > 1) {
int i;
for (i = 1; i < name.length - 1; i++) {
givenName.append(' ').append(name[i]);
}
if (!(!StringUtility.isNullOrBlank(getBloodname()) && getBloodname().equals(name[i]))) {
givenName.append(' ').append(name[i]);
}
}
} else {
if (name.length == 2) {
setSurnameDirect(name[1]);
} else if (name.length == 3) {
setSurnameDirect(name[1] + ' ' + name[2]);
} else if (name.length > 3) {
int i;
for (i = 1; i < name.length - 2; i++) {
givenName.append(' ').append(name[i]);
}
setSurnameDirect(name[i] + ' ' + name[i + 1]);
}
}
if ((getSurname() == null) || getSurname().equals(RandomNameGenerator.UNNAMED_SURNAME)) {
setSurnameDirect("");
}
setGivenNameDirect(givenName.toString());
setFullName();
}
// endregion Names
public Portrait getPortrait() {
return portrait;
}
public void setPortrait(final Portrait portrait) {
this.portrait = Objects.requireNonNull(portrait, "Illegal assignment: cannot have a null Portrait");
}
// region Personnel Roles
public PersonnelRole getPrimaryRole() {
return primaryRole;
}
public void setPrimaryRole(final Campaign campaign, final PersonnelRole primaryRole) {
// don't need to do any processing for no changes
if (primaryRole == getPrimaryRole()) {
return;
}
// We need to make some secondary role assignments to None here for better UX in
// assigning roles, following these rules:
// 1) Cannot have the same primary and secondary roles
// 2) Must have a None secondary role if you are a Dependent
// 3) Cannot be a primary tech and a secondary Astech
// 4) Cannot be a primary Astech and a secondary tech
// 5) Cannot be primary medical staff and a secondary Medic
// 6) Cannot be a primary Medic and secondary medical staff
if ((primaryRole == getSecondaryRole()) ||
primaryRole.isDependent() ||
(primaryRole.isTech() && getSecondaryRole().isAstech()) ||
(primaryRole.isAstech() && getSecondaryRole().isTechSecondary()) ||
(primaryRole.isMedicalStaff() && getSecondaryRole().isMedic()) ||
(primaryRole.isMedic() && getSecondaryRole().isMedicalStaff())) {
setSecondaryRoleDirect(PersonnelRole.NONE);
}
// Now, we can perform the time in service and last rank change tracking change
// for dependents
if (primaryRole.isDependent()) {
setRecruitment(null);
setLastRankChangeDate(null);
} else if (getPrimaryRole().isDependent()) {
setRecruitment(campaign.getLocalDate());
setLastRankChangeDate(campaign.getLocalDate());
}
// Finally, we can set the primary role
setPrimaryRoleDirect(primaryRole);
// and trigger the update event
MekHQ.triggerEvent(new PersonChangedEvent(this));
}
public void setPrimaryRoleDirect(final PersonnelRole primaryRole) {
this.primaryRole = primaryRole;
}
public PersonnelRole getSecondaryRole() {
return secondaryRole;
}
public void setSecondaryRole(final PersonnelRole secondaryRole) {
if (secondaryRole == getSecondaryRole()) {
return;
}
setSecondaryRoleDirect(secondaryRole);
MekHQ.triggerEvent(new PersonChangedEvent(this));
}
public void setSecondaryRoleDirect(final PersonnelRole secondaryRole) {
this.secondaryRole = secondaryRole;
}
/**
* This is used to determine if a person has a specific role as either their primary OR their secondary role
*
* @param role the role to determine
*
* @return true if the person has the specific role either as their primary or secondary role
*/
public boolean hasRole(final PersonnelRole role) {
return (getPrimaryRole() == role) || (getSecondaryRole() == role);
}
/**
* @return true if the person has a primary or secondary combat role
*/
public boolean hasCombatRole() {
return getPrimaryRole().isCombat() || getSecondaryRole().isCombat();
}
/**
* @param excludeUnmarketable whether to exclude the unmarketable roles from the comparison
*
* @return true if the person has a primary or secondary support role
*/
public boolean hasSupportRole(final boolean excludeUnmarketable) {
return getPrimaryRole().isSupport(excludeUnmarketable) || getSecondaryRole().isSupport(excludeUnmarketable);
}
public String getRoleDesc() {
String role = getPrimaryRoleDesc();
if (!getSecondaryRole().isNone()) {
role += '/' + getSecondaryRoleDesc();
}
return role;
}
public String getPrimaryRoleDesc() {
String bgPrefix = "";
if (isClanPersonnel()) {
bgPrefix = getPhenotype().getShortName() + ' ';
}
return bgPrefix + getPrimaryRole().getName(isClanPersonnel());
}
public String getSecondaryRoleDesc() {
return getSecondaryRole().getName(isClanPersonnel());
}
public boolean canPerformRole(LocalDate today, final PersonnelRole role, final boolean primary) {
if (primary) {
// Primary Role:
// We only do a few here, as it is better on the UX-side to correct the issues when assigning the primary
// role
// 1) Can always be Dependent
// 2) Cannot be None
if (role.isDependent()) {