File size: 1,098 Bytes
bcf0302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random

class BirthPlugin:
    def __init__(self, birth_rate, min_birth_age=20, birth_age_range=15):
        self.birth_rate = birth_rate
        self.birth_age = min_birth_age
        self.birth_age_range = birth_age_range

    def perform_births(self, characters):
        new_birth_count = 0
        for character in characters:
            if character.partner and character.apparent_age > self.birth_age and character.apparent_age < self.birth_age + self.birth_age_range and character.partner.apparent_age > self.birth_age and character.partner.apparent_age < self.birth_age + self.birth_age_range:
                if random.random() < self.birth_rate / 2:
                    child = character.give_birth()
                    if child:
                        characters.append(child)
                        new_birth_count += 1

        print(f"共{new_birth_count}对夫妻生了孩子!")

    def set_birth_rate(self, birth_rate):
        self.birth_rate = birth_rate

    # 统一插件接口
    def execute(self, *args, **kwargs):
        self.perform_births(*args, **kwargs)