From 6ed88f7ad776f2f56c15c6fb8857030b94202a82 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 22 Jun 2026 16:17:20 +0200 Subject: [PATCH] multiple fixes --- src/worker/falukant_family.rs | 40 ++++++----- src/worker/sql.rs | 126 +++------------------------------- 2 files changed, 31 insertions(+), 135 deletions(-) diff --git a/src/worker/falukant_family.rs b/src/worker/falukant_family.rs index dfa8f80..5e47b41 100644 --- a/src/worker/falukant_family.rs +++ b/src/worker/falukant_family.rs @@ -266,6 +266,9 @@ impl FalukantFamilyWorker { }); let mut v_net = 0i32; + if l.min_age_years <= 12 { + v_net += 3; + } if l.maintenance_level < 35 { v_net += 1; } @@ -289,6 +292,9 @@ impl FalukantFamilyWorker { let new_vis = clamp_i32(l.visibility + v_net, 0, 100); let mut d_net = 0i32; + if l.min_age_years <= 12 { + d_net -= 3; + } if l.maintenance_level >= 70 { d_net += 1; } @@ -452,8 +458,8 @@ impl FalukantFamilyWorker { { delta -= 1; } - if touching.iter().any(|l| l.min_age_years <= 15) { - delta -= 1; + if touching.iter().any(|l| l.min_age_years <= 12) { + delta -= 4; } // Standsabhängige Deltas aus der Liebschaften-Verarbeitung anwenden if let Some(extra_delta) = spouse_satisfaction_delta.get(&m.id) { @@ -499,8 +505,8 @@ impl FalukantFamilyWorker { if (g1 as i32 - g2 as i32).abs() >= 2 { pst -= 1; } - if touching.iter().any(|l| l.min_age_years <= 15) { - pst -= 2; + if touching.iter().any(|l| l.min_age_years <= 12) { + pst -= 4; } let ho_avg = (m.household_order_1 + m.household_order_2) / 2; if ho_avg < 35 { @@ -1307,12 +1313,10 @@ fn rank_rep_modifier(g: u8, scandal: bool, order_ok: bool) -> f64 { /// Spec 5a: Altersmalus (jüngeres Alter der Beteiligten), zusätzlich zur Basis-Reputation. fn age_reputation_delta(min_age_years: i32) -> f64 { - if min_age_years <= 13 { - -1.5 - } else if min_age_years <= 15 { - -0.8 - } else if min_age_years <= 17 { - -0.3 + if min_age_years <= 10 { + -6.0 + } else if min_age_years <= 12 { + -3.0 } else { 0.0 } @@ -1320,8 +1324,10 @@ fn age_reputation_delta(min_age_years: i32) -> f64 { /// Spec 5a: minAge <= 15 und hohe Sichtbarkeit. fn visibility_young_penalty(min_age_years: i32, visibility: i32) -> f64 { - if min_age_years <= 15 && visibility >= 50 { - -0.5 + if min_age_years <= 10 && visibility >= 20 { + -4.0 + } else if min_age_years <= 12 && visibility >= 25 { + -2.0 } else { 0.0 } @@ -1414,12 +1420,10 @@ fn breakup_risk_percent(l: &LoverData) -> f64 { /// Spec Skandalrisiko: stufenweise Zusatz (exklusiv). fn scandal_age_extra_pct(min_age_years: i32) -> f64 { - if min_age_years <= 13 { - 6.0 - } else if min_age_years <= 15 { - 3.0 - } else if min_age_years <= 17 { - 1.0 + if min_age_years <= 10 { + 12.0 + } else if min_age_years <= 12 { + 8.0 } else { 0.0 } diff --git a/src/worker/sql.rs b/src/worker/sql.rs index b48a212..ce29d68 100644 --- a/src/worker/sql.rs +++ b/src/worker/sql.rs @@ -2161,13 +2161,7 @@ pub const QUERY_TRY_MARRIAGE_CONCEPTION_UPDATE: &str = r#" CASE WHEN c1.gender = 'male' THEN c1.region_id ELSE c2.region_id END AS region_id, CASE WHEN c1.gender = 'male' THEN fu1.id ELSE fu2.id END AS father_uid, CASE WHEN c1.gender = 'female' THEN fu1.id ELSE fu2.id END AS mother_uid, - (CURRENT_DATE - c_female.birthdate::date)::int AS mother_age_days, - ( - SELECT COUNT(*)::int - FROM falukant_data.child_relation cr - WHERE cr.father_character_id = (CASE WHEN c1.gender = 'male' THEN c1.id ELSE c2.id END) - AND cr.mother_character_id = (CASE WHEN c1.gender = 'female' THEN c1.id ELSE c2.id END) - ) AS shared_children_count + (CURRENT_DATE - c_female.birthdate::date)::int AS mother_age_days FROM falukant_data.relationship r JOIN falukant_type.relationship r2 ON r2.id = r.relationship_type_id AND r2.tr = 'married' @@ -2194,58 +2188,13 @@ pub const QUERY_TRY_MARRIAGE_CONCEPTION_UPDATE: &str = r#" p.father_uid, p.mother_uid, p.mother_age_days, - p.shared_children_count, - CASE - WHEN p.mother_age_days < 4380 THEN 0.005 - WHEN p.mother_age_days < 4745 THEN 0.30 - WHEN p.mother_age_days < 5110 THEN 0.45 - WHEN p.mother_age_days < 5475 THEN 0.55 - WHEN p.mother_age_days < 5840 THEN 0.60 - WHEN p.mother_age_days < 6205 THEN 0.725 - WHEN p.mother_age_days < 6570 THEN 0.80 - WHEN p.mother_age_days < 7305 THEN 0.855 - WHEN p.mother_age_days < 9125 THEN 0.875 - WHEN p.mother_age_days < 10950 THEN 0.84 - WHEN p.mother_age_days < 11315 THEN 0.785 - WHEN p.mother_age_days < 11680 THEN 0.765 - WHEN p.mother_age_days < 12045 THEN 0.74 - WHEN p.mother_age_days < 12410 THEN 0.72 - WHEN p.mother_age_days < 12775 THEN 0.695 - WHEN p.mother_age_days < 13140 THEN 0.65 - WHEN p.mother_age_days < 13505 THEN 0.63 - WHEN p.mother_age_days < 13870 THEN 0.60 - WHEN p.mother_age_days < 14235 THEN 0.55 - WHEN p.mother_age_days < 14600 THEN 0.50 - WHEN p.mother_age_days < 14965 THEN 0.45 - WHEN p.mother_age_days < 15330 THEN 0.35 - WHEN p.mother_age_days < 15695 THEN 0.25 - WHEN p.mother_age_days < 16060 THEN 0.15 - WHEN p.mother_age_days < 16425 THEN 0.075 - WHEN p.mother_age_days < 16790 THEN 0.03 - WHEN p.mother_age_days < 17155 THEN 0.02 - WHEN p.mother_age_days < 17520 THEN 0.015 - WHEN p.mother_age_days < 18250 THEN 0.005 - ELSE 0.001 - END AS prob_year_raw + 0.72::float AS prob_year FROM paired p ), - mother_age_final AS ( - SELECT - ma.*, - CASE - WHEN ma.shared_children_count = 0 - AND ma.mother_age_days >= 6570 - AND ma.mother_age_days < 16000 - THEN GREATEST(ma.prob_year_raw, 1.0) - ELSE ma.prob_year_raw - END AS prob_year - FROM mother_age ma - ), conceivable AS ( SELECT ma.relationship_id - FROM mother_age_final ma - WHERE ma.mother_age_days >= 4380 - AND ma.mother_age_days < 18993 + FROM mother_age ma + WHERE ma.mother_age_days >= 5110 AND random() < ma.prob_year ) UPDATE falukant_data.relationship r @@ -2275,13 +2224,7 @@ pub const QUERY_GET_LEGACY_MARRIAGE_INSTANT_PREGNANCY_CANDIDATES: &str = r#" CASE WHEN c1.gender = 'male' THEN c1.region_id ELSE c2.region_id END AS region_id, CASE WHEN c1.gender = 'male' THEN fu1.id ELSE fu2.id END AS father_uid, CASE WHEN c1.gender = 'female' THEN fu1.id ELSE fu2.id END AS mother_uid, - (CURRENT_DATE - c_female.birthdate::date)::int AS mother_age_days, - ( - SELECT COUNT(*)::int - FROM falukant_data.child_relation cr - WHERE cr.father_character_id = (CASE WHEN c1.gender = 'male' THEN c1.id ELSE c2.id END) - AND cr.mother_character_id = (CASE WHEN c1.gender = 'female' THEN c1.id ELSE c2.id END) - ) AS shared_children_count + (CURRENT_DATE - c_female.birthdate::date)::int AS mother_age_days FROM falukant_data.relationship r JOIN falukant_type.relationship r2 ON r2.id = r.relationship_type_id AND r2.tr = 'married' @@ -2312,52 +2255,8 @@ pub const QUERY_GET_LEGACY_MARRIAGE_INSTANT_PREGNANCY_CANDIDATES: &str = r#" p.father_uid, p.mother_uid, p.mother_age_days, - p.shared_children_count, - CASE - WHEN p.mother_age_days < 4380 THEN 0.005 - WHEN p.mother_age_days < 4745 THEN 0.30 - WHEN p.mother_age_days < 5110 THEN 0.45 - WHEN p.mother_age_days < 5475 THEN 0.55 - WHEN p.mother_age_days < 5840 THEN 0.60 - WHEN p.mother_age_days < 6205 THEN 0.725 - WHEN p.mother_age_days < 6570 THEN 0.80 - WHEN p.mother_age_days < 7305 THEN 0.855 - WHEN p.mother_age_days < 9125 THEN 0.875 - WHEN p.mother_age_days < 10950 THEN 0.84 - WHEN p.mother_age_days < 11315 THEN 0.785 - WHEN p.mother_age_days < 11680 THEN 0.765 - WHEN p.mother_age_days < 12045 THEN 0.74 - WHEN p.mother_age_days < 12410 THEN 0.72 - WHEN p.mother_age_days < 12775 THEN 0.695 - WHEN p.mother_age_days < 13140 THEN 0.65 - WHEN p.mother_age_days < 13505 THEN 0.63 - WHEN p.mother_age_days < 13870 THEN 0.60 - WHEN p.mother_age_days < 14235 THEN 0.55 - WHEN p.mother_age_days < 14600 THEN 0.50 - WHEN p.mother_age_days < 14965 THEN 0.45 - WHEN p.mother_age_days < 15330 THEN 0.35 - WHEN p.mother_age_days < 15695 THEN 0.25 - WHEN p.mother_age_days < 16060 THEN 0.15 - WHEN p.mother_age_days < 16425 THEN 0.075 - WHEN p.mother_age_days < 16790 THEN 0.03 - WHEN p.mother_age_days < 17155 THEN 0.02 - WHEN p.mother_age_days < 17520 THEN 0.015 - WHEN p.mother_age_days < 18250 THEN 0.005 - ELSE 0.001 - END AS prob_year_raw + 0.72::float AS prob_year FROM paired p - ), - mother_age_final AS ( - SELECT - ma.*, - CASE - WHEN ma.shared_children_count = 0 - AND ma.mother_age_days >= 6570 - AND ma.mother_age_days < 16000 - THEN GREATEST(ma.prob_year_raw, 1.0) - ELSE ma.prob_year_raw - END AS prob_year - FROM mother_age ma ) SELECT father_cid, @@ -2369,9 +2268,8 @@ pub const QUERY_GET_LEGACY_MARRIAGE_INSTANT_PREGNANCY_CANDIDATES: &str = r#" mother_uid, mother_age_days, prob_year * 100.0 AS prob_pct - FROM mother_age_final - WHERE mother_age_days >= 4380 - AND mother_age_days < 18993 + FROM mother_age + WHERE mother_age_days >= 5110 AND random() < prob_year; "#; @@ -3927,8 +3825,7 @@ pub const QUERY_GET_LOVER_PREGNANCY_CANDIDATES: &str = r#" WHERE cr.mother_character_id = c_female.id AND cr.created_at::date = CURRENT_DATE ) - AND (CURRENT_DATE - c_female.birthdate::date) >= 4380 - AND (CURRENT_DATE - c_female.birthdate::date) < 18993 + AND (CURRENT_DATE - c_female.birthdate::date) >= 5110 AND random() * 100.0 < ( LEAST(12.0, GREATEST(0.0, CASE rs.lover_role @@ -3939,11 +3836,6 @@ pub const QUERY_GET_LOVER_PREGNANCY_CANDIDATES: &str = r#" END + CASE WHEN rs.affection >= 75 THEN 2.0 ELSE 0.0 END + CASE WHEN rs.visibility >= 70 AND rs.affection < 50 THEN -2.0 ELSE 0.0 END - + CASE - WHEN (CURRENT_DATE - c_female.birthdate::date) > 14600 - THEN -3.0 - ELSE 0.0 - END )) ); "#;