forked from james-owen-ryan/talktown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.py
2209 lines (2091 loc) · 105 KB
/
person.py
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
import random
import heapq
from corpora import Names
import life_event
from name import Name
from personality import Personality
import occupation
from face import Face
from mind import Mind
from routine import Routine
from whereabouts import Whereabouts
from relationship import Acquaintance
import face
class Person(object):
"""A person living in a procedurally generated American small town."""
def __init__(self, sim, birth):
"""Initialize a Person object."""
# Set location and sim instance
self.sim = sim
self.id = self.sim.current_person_id
self.sim.current_person_id += 1
self.type = "person"
self.birth = birth
if birth:
self.town = self.birth.town
if self.town:
self.town.residents.add(self)
# Set parents
self.biological_mother = birth.biological_mother
self.mother = birth.mother
self.biological_father = birth.biological_father
self.father = birth.father
self.parents = {self.mother, self.father}
# Set date of birth
self.birth_year = birth.year
self.birthday = (birth.month, birth.day) # This gets added to Simulation.birthdays by Birth.__init__()
# Set attributes pertaining to age
self.age = 0
self.adult = False
self.in_the_workforce = False # Not whether they are currently working, but just in the workforce broadly
else: # PersonExNihilo
self.town = None
self.biological_mother = None
self.mother = None
self.biological_father = None
self.father = None
self.parents = set()
self.birth_year = None # Gets set by PersonExNihilo.__init__()
self.birthday = (None, None) # Gets set by PersonExNihilo.get_random_day_of_year()
# Set attributes pertaining to age
self.age = None # These will get initialized by PersonExNihilo.__init__()
self.adult = False
self.in_the_workforce = False
# Set sex
self.male, self.female = (True, False) if random.random() < 0.5 else (False, True)
self.tag = '' # Allows players to tag characters with arbitrary strings
# Set misc attributes
self.alive = True
self.death_year = None
self.gravestone = None
self.home = None # Must come before setting routine
# Set biological characteristics
self.infertile = self._init_fertility(male=self.male, config=self.sim.config)
self.attracted_to_men, self.attracted_to_women = (
self._init_sexuality()
)
# Set face
self.face = Face(person=self)
# Set personality
self.personality = Personality(person=self)
# Set mental attributes (just memory currently)
self.mind = Mind(person=self)
# Set daily routine
self.routine = Routine(person=self)
# Prepare Whereabouts object, which tracks a person's whereabouts at every
# timestep of their life
self.whereabouts = Whereabouts(person=self)
# Prepare name attributes that get set by event.Birth._name_baby() (or PersonExNihilo._init_name())
self.first_name = None
self.middle_name = None
self.last_name = None
self.suffix = None
self.maiden_name = None
self.named_for = (None, None) # From whom first and middle name originate, respectively
# Prepare familial attributes that get populated by self.init_familial_attributes()
self.ancestors = set() # Biological only
self.descendants = set() # Biological only
self.immediate_family = set()
self.extended_family = set()
self.greatgrandparents = set()
self.grandparents = set()
self.aunts = set()
self.uncles = set()
self.siblings = set()
self.full_siblings = set()
self.half_siblings = set()
self.brothers = set()
self.full_brothers = set()
self.half_brothers = set()
self.sisters = set()
self.full_sisters = set()
self.half_sisters = set()
self.cousins = set()
self.kids = set()
self.sons = set()
self.daughters = set()
self.nephews = set()
self.nieces = set()
self.grandchildren = set()
self.grandsons = set()
self.granddaughters = set()
self.greatgrandchildren = set()
self.greatgrandsons = set()
self.greatgranddaughters = set()
self.bio_parents = set()
self.bio_grandparents = set()
self.bio_siblings = set()
self.bio_full_siblings = set()
self.bio_half_siblings = set()
self.bio_brothers = set()
self.bio_full_brothers = set()
self.bio_half_brothers = set()
self.bio_sisters = set()
self.bio_full_sisters = set()
self.bio_half_sisters = set()
self.bio_immediate_family = set()
self.bio_greatgrandparents = set()
self.bio_uncles = set()
self.bio_aunts = set()
self.bio_cousins = set()
self.bio_nephews = set()
self.bio_nieces = set()
self.bio_ancestors = set()
self.bio_extended_family = set()
# Set familial attributes; update those of family members
self._init_familial_attributes()
self._init_update_familial_attributes_of_family_members()
# Prepare attributes representing this person's romantic relationships
self.spouse = None
self.widowed = False
self.relationships = {}
self.sexual_partners = set()
# Prepare attributes representing this person's social relationships
self.acquaintances = set()
self.friends = set()
self.enemies = set()
self.neighbors = set()
self.former_neighbors = set()
self.coworkers = set()
self.former_coworkers = set()
self.best_friend = None
self.worst_enemy = None
self.love_interest = None
self.significant_other = None
self.charge_of_best_friend = 0.0 # These get used to track changes to a person's major relationships
self.charge_of_worst_enemy = 0.0
self.spark_of_love_interest = 0.0
self.talked_to_this_year = set()
self.befriended_this_year = set()
self.salience_of_other_people = {} # Maps potentially every other person to their salience to this person
self._init_salience_values()
# Prepare attributes pertaining to pregnancy
self.pregnant = False
self.impregnated_by = None
self.conception_year = None # Year of conception
self.due_date = None # Actual ordinal date 270 days from conception (currently)
# Prepare attributes representing events in this person's life
self.birth = birth
self.adoption = None
self.marriage = None
self.marriages = []
self.divorces = []
self.adoptions = []
self.moves = [] # From one home to another
self.lay_offs = [] # Being laid off by a company that goes out of business
self.name_changes = []
self.building_commissions = set() # Constructions of houses or buildings that they commissioned
self.home_purchases = []
self.retirement = None
self.departure = None # Leaving the town, i.e., leaving the simulation
self.death = None
# Set and prepare attributes pertaining to business affairs
self.money = self._init_money()
self.occupation = None
self.occupations = []
self.former_contractors = set()
self.retired = False
# Prepare attributes pertaining to education
self.college_graduate = False
# Prepare attributes pertaining to dynamic emotional considerations
self.grieving = False # After spouse dies
# Prepare attribute pertaining to exact location for the current timestep; this
# will always be modified by self.go_to()
self.location = None
# Prepare attributes pertaining to this person's knowledge
self.all_belief_facets = set() # Used to make batch calls to Facet.decay_strength()
# Miscellaneous attributes pertaining to artifacts this person is wearing
self.wedding_ring_on_finger = None
# Currently, whether a character is the player is only considered by Conversation
# objects (when deciding whether to elicit a dialogue move from the player)
self.player = False
def __str__(self):
"""Return string representation."""
if self.present:
return "{}, {} years old".format(self.name, self.age)
elif self.departure:
return "{}, left town in {}".format(self.name, self.departure.year)
else:
return "{}, {}-{}".format(self.name, self.birth_year, self.death_year)
def __repr__(self):
"""Return string representation."""
return self.name
@staticmethod
def _init_fertility(male, config):
"""Determine whether this person will be able to reproduce."""
x = random.random()
if male and x < config.male_infertility_rate:
infertile = True
elif not male and x < config.female_infertility_rate:
infertile = True
else:
infertile = False
return infertile
def _init_sexuality(self):
"""Determine this person's sexuality."""
config = self.sim.config
x = random.random()
if x < config.homosexuality_incidence:
# Homosexual
if self.male:
attracted_to_men = True
attracted_to_women = False
else:
attracted_to_men = False
attracted_to_women = True
elif x < config.homosexuality_incidence+config.bisexuality_incidence:
# Bisexual
attracted_to_men = True
attracted_to_women = True
elif x < config.homosexuality_incidence+config.bisexuality_incidence+config.asexuality_incidence:
# Asexual
attracted_to_men = True
attracted_to_women = True
else:
# Heterosexual
if self.male:
attracted_to_men = False
attracted_to_women = True
else:
attracted_to_men = True
attracted_to_women = False
return attracted_to_men, attracted_to_women
def _init_familial_attributes(self):
"""Populate lists representing this person's family members."""
self._init_immediate_family()
self._init_biological_immediate_family()
self._init_extended_family()
self._init_biological_extended_family()
def _init_immediate_family(self):
"""Populate lists representing this person's (legal) immediate family."""
self.grandparents = self.father.parents | self.mother.parents
self.siblings = self.father.kids | self.mother.kids
self.full_siblings = self.father.kids & self.mother.kids
self.half_siblings = self.father.kids ^ self.mother.kids
self.brothers = self.father.sons | self.mother.sons
self.full_brothers = self.father.sons & self.mother.sons
self.half_brothers = self.father.sons ^ self.mother.sons
self.sisters = self.father.daughters | self.mother.daughters
self.full_sisters = self.father.daughters & self.mother.daughters
self.half_sisters = self.father.daughters ^ self.mother.daughters
self.immediate_family = self.grandparents | self.parents | self.siblings
def _init_biological_immediate_family(self):
"""Populate lists representing this person's immediate."""
self.bio_parents = {self.biological_mother, self.biological_father}
self.bio_grandparents = self.biological_father.parents | self.biological_mother.parents
self.bio_siblings = self.biological_father.kids | self.biological_mother.kids
self.bio_full_siblings = self.biological_father.kids & self.biological_mother.kids
self.bio_half_siblings = self.biological_father.kids ^ self.biological_mother.kids
self.bio_brothers = self.biological_father.sons | self.biological_mother.sons
self.bio_full_brothers = self.biological_father.sons & self.biological_mother.sons
self.bio_half_brothers = self.biological_father.sons ^ self.biological_mother.sons
self.bio_sisters = self.biological_father.daughters | self.biological_mother.daughters
self.bio_full_sisters = self.biological_father.daughters & self.biological_mother.daughters
self.bio_half_sisters = self.biological_father.daughters ^ self.biological_mother.daughters
self.bio_immediate_family = self.bio_grandparents | self.bio_parents | self.bio_siblings
def _init_extended_family(self):
"""Populate lists representing this person's (legal) extended family."""
self.greatgrandparents = self.father.grandparents | self.mother.grandparents
self.uncles = self.father.brothers | self.mother.brothers
self.aunts = self.father.sisters | self.mother.sisters
self.cousins = self.father.nieces | self.father.nephews | self.mother.nieces | self.mother.nephews
self.nephews = self.father.grandsons | self.mother.grandsons
self.nieces = self.father.granddaughters | self.mother.granddaughters
self.ancestors = self.father.ancestors | self.mother.ancestors | self.parents
self.extended_family = (
self.greatgrandparents | self.immediate_family | self.uncles | self.aunts |
self.cousins | self.nieces | self.nephews
)
def _init_biological_extended_family(self):
"""Populate lists representing this person's (legal) extended family."""
self.bio_greatgrandparents = self.father.grandparents | self.mother.grandparents
self.bio_uncles = self.father.brothers | self.mother.brothers
self.bio_aunts = self.father.sisters | self.mother.sisters
self.bio_cousins = self.father.nieces | self.father.nephews | self.mother.nieces | self.mother.nephews
self.bio_nephews = self.father.grandsons | self.mother.grandsons
self.bio_nieces = self.father.granddaughters | self.mother.granddaughters
self.bio_ancestors = self.father.ancestors | self.mother.ancestors | self.parents
self.bio_extended_family = (
self.bio_greatgrandparents | self.bio_immediate_family | self.bio_uncles | self.bio_aunts |
self.bio_cousins | self.bio_nieces | self.bio_nephews
)
def _init_update_familial_attributes_of_family_members(self):
"""Update familial attributes of myself and family members."""
config = self.sim.config
for member in self.immediate_family:
member.immediate_family.add(self)
member.update_salience_of(
entity=self, change=config.salience_increment_from_relationship_change["immediate family"]
)
for member in self.extended_family:
member.extended_family.add(self)
member.update_salience_of(
entity=self, change=config.salience_increment_from_relationship_change["extended family"]
)
# Update for gender-specific familial attributes
if self.male:
for g in self.greatgrandparents:
g.greatgrandsons.add(self)
for g in self.grandparents:
g.grandsons.add(self)
for p in self.parents:
p.sons.add(self)
for u in self.uncles:
u.nephews.add(self)
for a in self.aunts:
a.nephews.add(self)
for b in self.full_brothers:
b.full_brothers.add(self)
b.brothers.add(self)
for s in self.full_sisters:
s.full_brothers.add(self)
s.brothers.add(self)
for b in self.half_brothers:
b.half_brothers.add(self)
b.brothers.add(self)
for s in self.half_sisters:
s.half_brothers.add(self)
s.brothers.add(self)
elif self.female:
for g in self.greatgrandparents:
g.greatgranddaughters.add(self)
for g in self.grandparents:
g.granddaughters.add(self)
for p in self.parents:
p.daughters.add(self)
for u in self.uncles:
u.nieces.add(self)
for a in self.aunts:
a.nieces.add(self)
for b in self.full_brothers:
b.full_sisters.add(self)
b.sisters.add(self)
for s in self.full_sisters:
s.full_sisters.add(self)
s.sisters.add(self)
for b in self.half_brothers:
b.half_sisters.add(self)
b.sisters.add(self)
for s in self.half_sisters:
s.half_sisters.add(self)
s.sisters.add(self)
# Update for non-gender-specific familial attributes
for a in self.ancestors:
a.descendants.add(self)
for g in self.greatgrandparents:
g.greatgrandchildren.add(self)
for g in self.grandparents:
g.grandchildren.add(self)
for p in self.parents:
p.kids.add(self)
for fs in self.full_siblings:
fs.siblings.add(self)
fs.full_siblings.add(self)
for hs in self.half_siblings:
hs.siblings.add(self)
hs.half_siblings.add(self)
for c in self.cousins:
c.cousins.add(self)
def _init_salience_values(self):
"""Determine an initial salience value for every other person associated with this newborn."""
config = self.sim.config
for person in self.ancestors:
self.update_salience_of(
entity=person, change=config.salience_increment_from_relationship_change["ancestor"]
)
for person in self.extended_family:
self.update_salience_of(
entity=person, change=config.salience_increment_from_relationship_change["extended family"]
)
for person in self.immediate_family:
self.update_salience_of(
entity=person, change=config.salience_increment_from_relationship_change["immediate family"]
)
self.update_salience_of(
entity=self, change=config.salience_increment_from_relationship_change["self"]
)
def _init_money(self):
"""Determine how much money this person has to start with."""
return 0
@property
def subject_pronoun(self):
"""Return the appropriately gendered third-person singular subject pronoun."""
return 'he' if self.male else 'she'
@property
def object_pronoun(self):
"""Return the appropriately gendered third-person singular object pronoun."""
return 'him' if self.male else 'her'
@property
def possessive_pronoun(self):
"""Return appropriately gendered possessive subject_pronoun."""
return 'his' if self.male else 'her'
@property
def reflexive_pronoun(self):
"""Return appropriately gendered reflexive subject_pronoun."""
return 'himself' if self.male else 'herself'
@property
def honorific(self):
"""Return the correct honorific (e.g., 'Mr.') for this person."""
if self.male:
return 'Mr.'
elif self.female:
if self.spouse:
return 'Mrs.'
else:
return 'Ms.'
@property
def full_name(self):
"""Return a person's full name."""
if self.suffix:
full_name = "{0} {1} {2} {3}".format(
self.first_name, self.middle_name, self.last_name, self.suffix
)
else:
full_name = "{0} {1} {2}".format(
self.first_name, self.middle_name, self.last_name
)
return full_name
@property
def full_name_without_suffix(self):
"""Return a person's full name sans suffix.
This is used to determine whether a child has the same full name as their parent,
which would necessitate them getting a suffix of their own to disambiguate.
"""
full_name = "{0} {1} {2}".format(
self.first_name, self.middle_name, self.last_name
)
return full_name
@property
def name(self):
"""Return a person's name."""
if self.suffix:
name = "{0} {1} {2}".format(self.first_name, self.last_name, self.suffix)
else:
name = "{0} {1}".format(self.first_name, self.last_name)
return name
@property
def nametag(self):
"""Return a person's name, appended with their tag, if any."""
if self.tag:
nametag = "{0} {1}".format(self.name, self.tag)
else:
nametag = self.name
return nametag
@property
def dead(self):
"""Return whether this person is dead."""
if not self.alive:
return True
else:
return False
@property
def queer(self):
"""Return whether this person is not heterosexual."""
if self.male and self.attracted_to_men:
queer = True
elif self.female and self.attracted_to_women:
queer = True
elif not self.attracted_to_men and not self.attracted_to_women:
queer = True
else:
queer = False
return queer
@property
def present(self):
"""Return whether the person is alive and in the town."""
if self.alive and not self.departure:
return True
else:
return False
@property
def next_of_kin(self):
"""Return next of kin.
A person's next of kin will make decisions about their estate and
so forth upon the person's eeath.
"""
if self.spouse and self.spouse.present:
next_of_kin = self.spouse
elif self.mother and self.mother.present:
next_of_kin = self.mother
elif self.father and self.father.present:
next_of_kin = self.father
elif any(k for k in self.kids if k.adult and k.present):
next_of_kin = next(k for k in self.kids if k.adult and k.present)
elif any(f for f in self.siblings if f.adult and f.present):
next_of_kin = next(f for f in self.siblings if f.adult and f.present)
elif any(f for f in self.extended_family if f.adult and f.present):
next_of_kin = next(f for f in self.extended_family if f.adult and f.present)
elif any(f for f in self.friends if f.adult and f.present):
next_of_kin = next(f for f in self.friends if f.adult and f.present)
else:
next_of_kin = random.choice(
[r for r in self.town.residents if r.adult and r.present]
)
return next_of_kin
@property
def nuclear_family(self):
"""Return this person's nuclear family."""
nuclear_family = {self}
if self.spouse and self.spouse.present:
nuclear_family.add(self.spouse)
for kid in self.spouse.kids & self.kids if self.spouse else self.kids:
if kid.home is self.home and kid.present:
nuclear_family.add(kid)
return nuclear_family
@property
def kids_at_home(self):
"""Return kids of this person that live with them, if any."""
kids_at_home = {k for k in self.kids if k.home is self.home and k.present}
return kids_at_home
@property
def life_events(self):
"""Return the major events of this person's life."""
events = [self.birth, self.adoption]
events += self.moves
events += self.lay_offs
events += [job.hiring for job in self.occupations]
events += self.marriages
events += [kid.birth for kid in self.kids]
events += self.divorces
events += self.name_changes
events += self.home_purchases
events += list(self.building_commissions)
if self.retirement:
events.append(self.retirement)
events += [self.departure, self.death]
while None in events:
events.remove(None)
events.sort(key=lambda ev: ev.event_number) # Sort chronologically
return events
@property
def year_i_moved_here(self):
"""Return the year this person moved to this town."""
return self.moves[0].year
@property
def years_i_lived_here(self):
"""Return the number of years this person has lived in this town"""
return self.sim.year - self.year_i_moved_here
@property
def age_and_gender_description(self):
"""Return a string broadly capturing this person's age."""
if self.age < 1:
return 'an infant boy' if self.male else 'an infant girl'
elif self.age < 4:
return 'a boy toddler' if self.male else 'a girl toddler'
elif self.age < 10:
return 'a young boy' if self.male else 'a young girl'
elif self.age < 13:
return 'a preteen boy' if self.male else 'a preteen girl'
elif self.age < 20:
return 'a teenage boy' if self.male else 'a teenage girl'
elif self.age < 25:
return 'a young man' if self.male else 'a young woman'
elif self.age < 45:
return 'a man' if self.male else 'a woman'
elif self.age < 65:
return 'a middle-aged man' if self.male else 'a middle-aged woman'
elif self.age < 75:
return 'an older man' if self.male else 'an older woman'
else:
return 'an elderly man' if self.male else 'an elderly woman'
@property
def basic_appearance_description(self):
"""Return a string broadly capturing this person's basic appearance."""
features = []
if self.face.distinctive_features.tattoo == 'yes':
features.append('a prominent tattoo')
if self.face.distinctive_features.scar == 'yes':
features.append('a visible scar')
if self.face.distinctive_features.birthmark == 'yes':
features.append('a noticeable birthmark')
if self.face.distinctive_features.freckles == 'yes':
features.append('freckles')
if self.face.distinctive_features.glasses == 'yes':
features.append('glasses')
if self.face.hair.length == 'bald':
features.append('a bald head')
else:
features.append('{} {} hair'.format(
'medium-length' if self.face.hair.length == 'medium' else self.face.hair.length,
'blond' if self.male and self.face.hair.color == 'blonde' else self.face.hair.color
)
)
if self.face.facial_hair.style == 'sideburns' and self.male and self.age > 14:
features.append('sideburns')
elif self.face.facial_hair.style != 'none' and self.male and self.age > 14:
features.append('a {}'.format(str(self.face.facial_hair.style)))
if len(features) > 2:
return '{}, and {}'.format(', '.join(feature for feature in features[:-1]), features[-1])
else:
return ' and '.join(features)
@property
def description(self):
"""Return a basic description of this person."""
broader_skin_color = {
'black': 'dark', 'brown': 'dark',
'beige': 'light', 'pink': 'light',
'white': 'light'
}
# Cut off the article ('a' or 'an') at the beginning of the
# age_and_gender_description so that we can prepend a
# skin-color tidbit
age_and_gender_description = ' '.join(self.age_and_gender_description.split()[1:])
return "a {broad_skin_color}-skinned {age_and_gender} with {prominent_features}{deceased}".format(
broad_skin_color=broader_skin_color[self.face.skin.color],
age_and_gender=age_and_gender_description,
prominent_features=self.basic_appearance_description,
deceased=' (deceased)' if self.dead else ''
)
@property
def boss(self):
"""Return this person's boss, if they have one, else None."""
if not self.occupation:
return None
elif self.occupation.company.owner and self.occupation.company.owner.person is self:
return None
elif self.occupation.company.owner:
return self.occupation.company.owner.person
else:
return None
@property
def first_home(self):
return self.moves[0].new_home
@property
def requited_love_interest(self):
"""Return whether this person is their love interest's love interest."""
return self.love_interest and self.love_interest.love_interest and self.love_interest.love_interest is self
@property
def unrequited_love_interest(self):
"""Return whether this person is not their love interest's love interest."""
return self.love_interest and self.love_interest.love_interest is not self
@property
def is_captivated_by(self):
"""The set of people that this person is romantically captivated by."""
spark_threshold_for_being_captivated = self.sim.config.spark_threshold_for_being_captivated
return [p for p in self.relationships if self.relationships[p].spark > spark_threshold_for_being_captivated]
def recount_life_history(self):
"""Print out the major life events in this person's simulated life."""
for life_event in self.life_events:
print life_event
def get_feature(self, feature_type):
"""Return this person's feature of the given type."""
# Sex
if feature_type == "sex":
return 'm' if self.male else 'f'
# Status
if feature_type == "status":
if self.present:
return "alive"
elif self.dead:
return "dead"
elif self.departure:
return "departed"
elif feature_type == "departure year":
return 'None' if not self.departure else str(self.departure.year)
elif feature_type == "marital status":
if self.spouse:
return 'married'
elif not self.marriages:
return 'single'
elif self.widowed:
return 'widowed'
else:
return 'divorced'
# Age
elif feature_type == "birth year":
return str(self.birth_year)
elif feature_type == "death year":
return str(self.death_year)
elif feature_type == "approximate age":
return '{}0s'.format(self.age/10)
# Name
elif feature_type == "first name":
return self.first_name
elif feature_type == "middle name":
return self.middle_name
elif feature_type == "last name":
return self.last_name
elif feature_type == "suffix":
return self.suffix if self.suffix else 'None' # Because '' reserve for forgettings
elif feature_type == "surname ethnicity":
return self.last_name.ethnicity
elif feature_type == "hyphenated surname":
return 'yes' if self.last_name.hyphenated else 'no'
# Occupation
elif feature_type == "workplace":
return "None" if not self.occupations else self.occupations[-1].company.name # Name of company
elif feature_type == "job title":
return "None" if not self.occupations else self.occupations[-1].vocation
elif feature_type == "job shift":
return "None" if not self.occupations else self.occupations[-1].shift
elif feature_type == "workplace address":
return "None" if not self.occupations else self.occupations[-1].company.address
elif feature_type == "workplace block":
return "None" if not self.occupations else self.occupations[-1].company.block
elif feature_type == "job status":
if self.occupation:
return "employed"
elif self.retired:
return "retired"
else:
return "unemployed"
# Home
elif feature_type == "home":
return self.home.name
elif feature_type == "home address":
return self.home.address
elif feature_type == "home block":
return self.home.block
# Appearance
elif feature_type == "skin color":
return self.face.skin.color
elif feature_type == "head size":
return self.face.head.size
elif feature_type == "head shape":
return self.face.head.shape
elif feature_type == "hair length":
return self.face.hair.length
elif feature_type == "hair color":
return self.face.hair.color
elif feature_type == "eyebrow size":
return self.face.eyebrows.size
elif feature_type == "eyebrow color":
return self.face.eyebrows.color
elif feature_type == "mouth size":
return self.face.mouth.size
elif feature_type == "ear size":
return self.face.ears.size
elif feature_type == "ear angle":
return self.face.ears.angle
elif feature_type == "nose size":
return self.face.nose.size
elif feature_type == "nose shape":
return self.face.nose.shape
elif feature_type == "eye size":
return self.face.eyes.size
elif feature_type == "eye shape":
return self.face.eyes.shape
elif feature_type == "eye color":
return self.face.eyes.color
elif feature_type == "eye horizontal settedness":
return self.face.eyes.horizontal_settedness
elif feature_type == "eye vertical settedness":
return self.face.eyes.vertical_settedness
elif feature_type == "facial hair style":
return self.face.facial_hair.style
elif feature_type == "freckles":
return self.face.distinctive_features.freckles
elif feature_type == "birthmark":
return self.face.distinctive_features.birthmark
elif feature_type == "scar":
return self.face.distinctive_features.scar
elif feature_type == "tattoo":
return self.face.distinctive_features.tattoo
elif feature_type == "glasses":
return self.face.distinctive_features.glasses
elif feature_type == "sunglasses":
return self.face.distinctive_features.sunglasses
# Have to do special thing for whereabouts, because they are indexed by date;
# specifically, we parse the feature type, which will look something like
# 'whereabouts 723099-1'
elif 'whereabouts' in feature_type:
timestep = feature_type[12:]
ordinal_date, day_or_night = timestep.split('-')
whereabout_object = self.whereabouts.date[(int(ordinal_date), int(day_or_night))]
return whereabout_object.location.name
def _common_familial_relation_to_me(self, person):
"""Return the immediate common familial relation to the given person, if any.
This method gets called by decision-making methods that get executed often,
since it runs much more quickly than known_relation_to_me, which itself is much
richer in the number of relations it checks for. Basically, this method
is meant for quick decision making, and known_relation_to_me for dialogue generation.
"""
if person is self.spouse:
return 'husband' if person.male else 'wife'
if person is self.father:
return 'father'
elif person is self.mother:
return 'mother'
elif person in self.brothers:
return 'brother'
elif person in self.sisters:
return 'sister'
elif person in self.aunts:
return 'aunt'
elif person in self.uncles:
return 'uncle'
elif person in self.sons:
return 'son'
elif person in self.daughters:
return 'daughter'
elif person in self.cousins:
return 'cousin'
elif person in self.nephews:
return 'nephew'
elif person in self.nieces:
return 'niece'
elif person in self.greatgrandparents:
return 'greatgrandfather' if person.male else 'greatgrandmother'
elif person in self.grandparents:
return 'grandfather' if person.male else 'grandmother'
elif person in self.grandchildren:
return 'grandson' if person.male else 'granddaughter'
else:
return None
def relation_to_me(self, person):
"""Return the primary relation of another person to me, if any.
This method is much richer than _common_familial_relation_to_me
in the number of relationships that it checks for. While the former is meant
for quick character decision making, this method should be used for things
like dialogue generation, where performance is much less important than
richness and expressivity. Because this method is meant to be used to generate
dialogue, it won't return specific relationships like 'first cousin, once removed',
because everyday people don't know or reference these relationships.
"""
if person is self:
return 'self'
elif person in self.greatgrandparents:
return 'greatgrandfather' if person.male else 'greatgrandmother'
elif person in self.grandparents:
return 'grandfather' if person.male else 'grandmother'
elif person is self.father:
return 'father'
elif person is self.mother:
return 'mother'
elif person in self.aunts:
return 'aunt'
elif person in self.uncles:
return 'uncle'
elif person in self.brothers:
return 'brother'
elif person in self.sisters:
return 'sister'
elif person in self.cousins:
return 'cousin'
elif person in self.sons:
return 'son'
elif person in self.daughters:
return 'daughter'
elif person in self.nephews:
return 'nephew'
elif person in self.nieces:
return 'niece'
elif person is self.spouse:
return 'husband' if person.male else 'wife'
elif self.divorces and any(d for d in self.divorces if person in d.subjects):
return 'ex-husband' if person.male else 'ex-wife'
elif self.widowed and any(m for m in self.marriages if person in m.subjects and m.terminus is person.death):
return 'deceased husband' if person.male else 'deceased wife'
elif person.spouse in self.siblings or self.spouse in person.siblings:
return 'brother in law' if person.male else 'sister in law'
elif self.father and any(d for d in self.father.divorces if person in d.subjects):
return "father's ex-{}".format('husband' if person.male else 'wife')
elif self.mother and any(d for d in self.mother.divorces if person in d.subjects):
return "mother's ex-{}".format('husband' if person.male else 'wife')
elif any(s for s in self.brothers if any(d for d in s.divorces if person in d.subjects)):
return "brother's ex-{}".format('husband' if person.male else 'wife')
elif any(s for s in self.sisters if any(d for d in s.divorces if person in d.subjects)):
return "sister's ex-{}".format('husband' if person.male else 'wife')
elif any(s for s in self.brothers if any(
m for m in s.marriages if person in m.subjects and m.terminus is person.death)):
return "brother's deceased {}".format('husband' if person.male else 'wife')
elif any(s for s in self.sisters if any(
m for m in s.marriages if person in m.subjects and m.terminus is person.death)):
return "sister's deceased {}".format('husband' if person.male else 'wife')
elif any(s for s in self.brothers if any(
m for m in s.marriages if person in m.subjects and m.terminus is s.death)):
return "deceased brother's former {}".format('husband' if person.male else 'wife')
elif any(s for s in self.sisters if any(
m for m in s.marriages if person in m.subjects and m.terminus is s.death)):
return "deceased sister's former {}".format('husband' if person.male else 'wife')
elif person.spouse in self.kids:
return 'son in law' if person.male else 'daughter in law'
elif self.spouse and person in self.spouse.parents:
return 'father in law' if person.male else 'mother in law'
elif self.spouse and person in self.spouse.sons:
return 'stepson'
elif self.spouse and person in self.spouse.daughters:
return 'stepdaughter'
elif self.mother and person is self.mother.spouse:
return 'stepfather' if person.male else 'stepmother'
elif self.father and person is self.father.spouse:
return 'stepfather' if person.male else 'stepmother'
elif self.greatgrandparents & person.greatgrandparents:
return 'second cousin'
elif self.greatgrandparents & person.siblings:
return 'great uncle' if person.male else 'great aunt'
elif person is self.best_friend:
return 'best friend'
elif person is self.worst_enemy:
return 'worst enemy'
elif person is self.significant_other:
return 'boyfriend' if person.male else 'girlfriend'
# elif person is self.love_interest: # Commented out because no one would say this
# return 'love interest'
elif person in self.coworkers:
return 'coworker'
elif person in self.neighbors:
return 'neighbor'
elif person in self.enemies:
return 'enemy'
elif any(p for p in self.parents if person is p.significant_other):
p = next(p for p in self.parents if person is p.significant_other)
return "{}'s {}".format(
'father' if p.male else 'mother', 'boyfriend' if person.male else 'girlfriend'
)
elif any(k for k in self.kids if person is k.significant_other):
k = next(k for k in self.kids if person is k.significant_other)
return "{}'s {}".format(
'son' if k.male else 'daughter', 'boyfriend' if person.male else 'girlfriend'
)
elif any(s for s in self.siblings if person is s.significant_other):
s = next(s for s in self.siblings if person is s.significant_other)
return "{}'s {}".format(
'brother' if s.male else 'sister', 'boyfriend' if person.male else 'girlfriend'
)
elif self.spouse and person is self.spouse.best_friend:
return "{}'s best friend".format('husband' if self.spouse.male else 'wife')
elif self.mother and person is self.mother.best_friend:
return "mother's best friend"
elif self.father and person is self.father.best_friend:
return "father's best friend"