Add logic to prevent multiple births for mothers in a single day: Implemented a new SQL query to check if a mother has already given birth today. Updated the FalukantFamilyWorker and UserCharacterWorker to utilize this check, enhancing the birth registration process and ensuring compliance with the new birth rule.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m35s

This commit is contained in:
Torsten Schulz (local)
2026-04-14 07:50:56 +02:00
parent 6e931c1069
commit b0ee0da722
3 changed files with 47 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ use super::sql::{
QUERY_COUNT_LOVER_CHILDREN_FOR_USER, QUERY_FAMILY_SCHEMA_READY,
QUERY_GET_ACTIVE_LOVER_ROWS_FOR_DAILY, QUERY_GET_ACTIVE_LOVER_ROWS_FOR_MONTHLY,
QUERY_GET_ACTIVE_LOVER_ROWS_FOR_INSTALLMENT, QUERY_GET_LOVER_PREGNANCY_CANDIDATES,
QUERY_HAS_MOTHER_BIRTH_TODAY,
QUERY_GET_MARRIAGE_ROWS, QUERY_GET_USER_HOUSE_ROW_BY_USER, QUERY_INSERT_CHILD,
QUERY_INSERT_CHILD_RELATION_LOVER, QUERY_LOVER_BIRTH_PENALTY_MARRIAGE,
QUERY_LOVER_BIRTH_PENALTY_REPUTATION, QUERY_LOVER_INSTALLMENT_SCHEMA_READY,
@@ -1015,6 +1016,7 @@ impl FalukantFamilyWorker {
conn.prepare("insert_child_rel_lover", QUERY_INSERT_CHILD_RELATION_LOVER)?;
conn.prepare("pen_mar", QUERY_LOVER_BIRTH_PENALTY_MARRIAGE)?;
conn.prepare("pen_rep", QUERY_LOVER_BIRTH_PENALTY_REPUTATION)?;
conn.prepare("has_mother_birth_today", QUERY_HAS_MOTHER_BIRTH_TODAY)?;
for row in rows {
let father_cid = parse_i32(&row, "father_cid", -1);
@@ -1027,6 +1029,9 @@ impl FalukantFamilyWorker {
let region_id = parse_i32(&row, "region_id", 0);
let father_uid = parse_opt_i32(&row, "father_uid");
let mother_uid = parse_opt_i32(&row, "mother_uid");
if mother_uid.is_some() && Self::mother_already_had_birth_today(&mut conn, mother_cid)? {
continue;
}
let gender = if self.dist.sample(&mut self.rng) < 0.5 {
"male"
@@ -1073,6 +1078,18 @@ impl FalukantFamilyWorker {
self.publish_falukant_update_family_and_status(user_id, "lover_birth");
}
fn mother_already_had_birth_today(
conn: &mut crate::db::DbConnection,
mother_character_id: i32,
) -> Result<bool, DbError> {
let rows = conn.execute("has_mother_birth_today", &[&mother_character_id])?;
Ok(rows
.first()
.and_then(|r| r.get("has_birth_today"))
.map(|v| v == "t" || v == "true")
.unwrap_or(false))
}
/// `falukantUpdateFamily` (mit `reason`) + `falukantUpdateStatus` — für UI-Refresh.
fn publish_falukant_update_family_and_status(&self, user_id: i32, reason: &str) {
let family = format!(