def have_child(self, child_data={}, spouse=None, event_id=0): father = self if self.gender is 'Male' else spouse mother = spouse if self.gender is 'Male' else self if not isinstance(father, Person): father = Person(self.world_obj, father, 'Male', 'Father') spouse = father if not isinstance(mother, Person): mother = Person(self.world_obj, mother, 'Female', 'Mother') spouse = mother child_dna, temp = dna_helpers.combine_dna(mother=mother.dna, father=father.dna) child_gender = dna_helpers.gender_from_dna(child_dna) child_dna = math_helpers.get_val(child_data, 'dna', child_dna) child_data_new = { "dna": child_dna, "gender": child_gender, "father_name": father.name, "mother_name": mother.name } child_data = math_helpers.extend(child_data, child_data_new) child = Person(self.world_obj, child_data, gender=child_gender, role='Child') child.create_name() world_data = self.world_obj.world_data birth_place = create_random_item(world_data=world_data, set_random_key=False, pattern='birthplace') birth_event_data = apply_event_effects(person_data=child.pointer, world_data=world_data, age=0, event_data=birth_place, event_type='birthplace', event_id=event_id, tag_manager=self.world_obj.tag_manager) child.set('birth_year', int(self.world_obj.get('year'))) child.set('birth_event', birth_event_data) if spouse is None: child.set('parents_unmarried_while_born', True) child.set('family_name', mother.family_name) self.conflict += 2 spouse.conflict += 2 self.economic -= 2 spouse.economic -= 2 else: child.set('family_name', self.family_name if self.gender is 'Male' else mother.family_name) self.conflict -= 1 self.economic -= 1 spouse.economic -= 1 self.education += 1 child.create_name(set_to_person=True) self.world_obj.add_person(child) self.attribute_mod_update('Happiness', numpy.random.randint(-2, 2)) self.attribute_mod_update('Constitution', numpy.random.randint(-2, 0)) self.attribute_mod_update('Passion', numpy.random.randint(-4, -1)) if self.gender is 'Female': self.attribute_mod_update('Happiness', -1) self.attribute_mod_update('Constitution', -1) return child
def initialize_family_settings_from_request(req_obj): rand_seed = req_obj.get('rand_seed') or '' if req_obj.get('regenerate', None): # A button was pushed with the name 'regenerate' rand_seed = '' world_json = req_obj.get('world_json') or '' world_data = json.loads(world_json) if world_json else {} mother_dna = req_obj.get('mother_dna') or '' mother_race = req_obj.get('mother_race') or 'Human' mother_profession = req_obj.get('mother_profession') or '' mother_education = req_obj.get('mother_education') or '' mother_economic = req_obj.get('mother_economic') or '' mother_conflict = req_obj.get('mother_conflict') or '' mother = {"dna": mother_dna, "race": mother_race, "profession": mother_profession, "education": mother_education, "economic": mother_economic, "conflict": mother_conflict} father_dna = req_obj.get('father_dna') or '' father_race = req_obj.get('father_race') or 'Human' father_profession = req_obj.get('father_profession') or '' father_education = req_obj.get('father_education') or '' father_economic = req_obj.get('father_economic') or '' father_conflict = req_obj.get('father_conflict') or '' father = {"dna": father_dna, "race": father_race, "profession": father_profession, "education": father_education, "economic": father_economic, "conflict": father_conflict} family = world_data.get("family", {}) mother_f = family.get("mother", {}) father_f = family.get("father", {}) family["mother"] = math_helpers.extend(PERSON_DEFAULT_DICT, mother_f, mother) family["father"] = math_helpers.extend(PERSON_DEFAULT_DICT, father_f, father) world_data = math_helpers.extend(WORLD_DEFAULT_DICT, world_data) world_data["rand_seed"] = rand_seed world_data["family"] = family return world_data
def __init__(self, world_data={}): self.world_data = world_data self.year = self.get('year', numpy.random.randint(1000, 2000)) self.world_data = math_helpers.extend(WORLD_DEFAULT_DICT, self.world_data) self.tag_manager = {} starting_tags = math_helpers.get_val(world_data, 'tags', '') math_helpers.add_tags(self.tag_manager, 'initial', starting_tags) magic = self.get('magic', random_number=True) magic = round(magic, 1) self.set('magic', magic) tech = self.get('technology', random_number=True) tech = round(tech, 1) self.set('technology', tech) self.people = self.get('people', []) self.people_objects = []
def __init__(self, world_obj, data={}, gender=None, role='Child'): if isinstance(world_obj, World): self.world_obj = world_obj else: raise Exception('Non-World Object passed to Person') if not data: data = {} if isinstance(data, Person): data = data.output if not isinstance(data, dict): raise Exception('Non-dict Data passed to Person') self.pointer = math_helpers.extend(PERSON_DEFAULT_DICT, data) self.rand_seed_counter = numpy.random.randint(1, 100000) self.attribute_base = {} self.attribute_mods_dict = {} self.qualities_base = {} self.quality_mods_dict = {} self.role = role # if not self.dna: # self.generate_dna() if gender: self.gender = gender family_name = self.get('family_name', None) if family_name: self.family_name = family_name self.create_name() else: self.create_name(create_new_last=True) self.world_obj.add_person(self)