Refactor pregnancy handling in UserCharacterWorker: Changed the pregnancy check from a daily to an hourly basis, updating the associated method and SQL query to reflect this new frequency. This adjustment improves the accuracy of pregnancy probability calculations and aligns with the updated family dynamics logic.

This commit is contained in:
Torsten Schulz (local)
2026-03-22 09:43:36 +01:00
parent ac5ec3a245
commit 4086e9a207
3 changed files with 76 additions and 53 deletions

View File

@@ -85,7 +85,7 @@ impl UserCharacterWorker {
self.maybe_run_hourly_tasks();
self.maybe_run_mood_updates();
self.maybe_run_daily_pregnancies();
self.maybe_run_hourly_pregnancies();
// Entspricht in etwa der 1-Sekunden-Schleife im C++-Code
std::thread::sleep(Duration::from_secs(1));
@@ -123,11 +123,13 @@ impl UserCharacterWorker {
Ok(())
}
fn maybe_run_daily_pregnancies(&mut self) {
/// Ehe-Schwangerschaft: höchstens einmal pro Stunde (Daemon-Schleife ~1 s).
/// SQL nutzt stündliche Zerlegung der Jahres-Wahrscheinlichkeit (`1/8760`), siehe `QUERY_GET_PREGNANCY_CANDIDATES`.
fn maybe_run_hourly_pregnancies(&mut self) {
let now = Instant::now();
let should_run = match self.last_pregnancy_run {
None => true,
Some(last) => now.saturating_duration_since(last) >= Duration::from_secs(24 * 3600),
Some(last) => now.saturating_duration_since(last) >= Duration::from_secs(3600),
};
if !should_run {