From 342eb512b48f26f3028d630970bc9201beeb37c7 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 21 May 2026 10:54:28 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20Logik=20zur=20Berechnung=20von=20Re?= =?UTF-8?q?putation=20und=20Ehezufriedenheit=20basierend=20auf=20Liebschaf?= =?UTF-8?q?ten=20hinzu:=20Implementiere=20Funktionen=20zur=20Bewertung=20d?= =?UTF-8?q?er=20Standsgruppe=20und=20zur=20Berechnung=20t=C3=A4glicher=20D?= =?UTF-8?q?eltas=20f=C3=BCr=20Reputation=20und=20Ehezufriedenheit,=20um=20?= =?UTF-8?q?die=20Auswirkungen=20von=20Liebschaften=20auf=20die=20Beziehung?= =?UTF-8?q?en=20zu=20ber=C3=BCcksichtigen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/worker/falukant_family.rs | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/src/worker/falukant_family.rs b/src/worker/falukant_family.rs index c1bb446..e462619 100644 --- a/src/worker/falukant_family.rs +++ b/src/worker/falukant_family.rs @@ -251,10 +251,15 @@ impl FalukantFamilyWorker { } conn.prepare("upd_vd", QUERY_UPDATE_LOVER_VISIBILITY_DISCRETION)?; + conn.prepare("upd_rep", QUERY_UPDATE_CHARACTER_REPUTATION)?; conn.prepare("deactivate_lover", QUERY_DEACTIVATE_LOVER_RELATIONSHIP)?; let mut ended_rel_ids: HashSet = HashSet::new(); let mut breakup_socket_users: HashSet = HashSet::new(); let mut breakup_risk_notified: HashSet<(i32, i32)> = HashSet::new(); + + // Sammeln von Ehepartner-Charakteren für Ehezufriedenheits-Deltas + let mut spouse_satisfaction_delta: HashMap = HashMap::new(); + for l in &mut lovers { let ehe_conflict = marriages.iter().any(|m| { (m.m1 == l.c1 || m.m2 == l.c1 || m.m1 == l.c2 || m.m2 == l.c2) && m.satisfaction < 40 @@ -301,6 +306,33 @@ impl FalukantFamilyWorker { )?; l.visibility = new_vis; l.discretion = new_disc; + + // Standsabhängige Auswirkungen auf Reputation der Liebhaber + let rep_delta = calculate_lover_reputation_delta(l); + if rep_delta.abs() > 0.01 { + // Reputation beider Liebhaber erhöhen/senken + for cid in [l.c1, l.c2] { + if cid > 0 { + let rep_s = format!("{:.2}", rep_delta); + // Nutzen des UPDATE CHARACTER ... reputation = reputation + $1 Pattern + let _ = conn.execute("upd_rep", &[&rep_s, &cid]); + } + } + } + + // Standsabhängige Auswirkungen auf Ehezufriedenheit sammeln + let marriage_sat_delta = calculate_lover_marriage_satisfaction_delta(l); + if marriage_sat_delta != 0 { + // Sammeln der Ehepartnerschaften, auf die diese Liebschaft Einfluss hat + for spouse_char_id in [l.c1, l.c2] { + let spouse_marriage = marriages.iter().find(|m| { + m.m1 == spouse_char_id || m.m2 == spouse_char_id + }); + if let Some(m) = spouse_marriage { + *spouse_satisfaction_delta.entry(m.id).or_insert(0) += marriage_sat_delta; + } + } + } // Je niedriger die Zuneigung, desto höher das tägliche Trennungsrisiko. let breakup_risk_pct = breakup_risk_percent(l); @@ -423,6 +455,10 @@ impl FalukantFamilyWorker { if touching.iter().any(|l| l.min_age_years <= 15) { delta -= 1; } + // Standsabhängige Deltas aus der Liebschaften-Verarbeitung anwenden + if let Some(extra_delta) = spouse_satisfaction_delta.get(&m.id) { + delta += extra_delta; + } sat = clamp_i32(sat + delta, 0, 100); } @@ -1291,6 +1327,88 @@ fn visibility_young_penalty(min_age_years: i32, visibility: i32) -> f64 { } } +/// Bewertet die Standsgruppe basierend auf Titeln der beiden Liebhaber. +/// Rückgabe: 0 = niedrig (noncivil/civil), 1 = mittel (townlord/etc.), 2+ = hoch (knight/etc.). +fn lover_status_category(title1: &str, title2: &str) -> u8 { + let t1 = title_group(title1); + let t2 = title_group(title2); + let max_group = t1.max(t2); + // Vereinfacht: 0 -> "niedrig", 1 -> "mittel", 2+ -> "hoch" + if max_group >= 2 { + 2 // hoch (knight, baron, count, ruler, etc.) + } else if max_group == 1 { + 1 // mittel (townlord, by, landlord) + } else { + 0 // niedrig (noncivil, civil, sir) + } +} + +/// Berechnet tägl. Reputations-Delta basierend auf Stand, Sichtbarkeit und Status der Liebschaft. +/// Regel: +/// - Hoher Stand: +Reputation (unabhängig von Sichtbarkeit) +/// - Mittlerer Stand: +Reputation wenn heimlich/diskret, -Reputation wenn öffentlich +/// - Niedriger Stand: neutral wenn heimlich, -Reputation wenn öffentlich +fn calculate_lover_reputation_delta(l: &LoverData) -> f64 { + let category = lover_status_category(&l.title1_tr, &l.title2_tr); + let is_public = l.visibility >= 60; // öffentlich wenn hohe Sichtbarkeit + + match category { + 2 => { + // Hoher Stand: immer +0,5 pro Tag (positiv) + 0.5 + } + 1 => { + // Mittlerer Stand: heimlich +0,3, öffentlich -0,4 + if is_public { + -0.4 + } else { + 0.3 + } + } + _ => { + // Niedriger Stand: heimlich/diskret 0, öffentlich -0,5 + if is_public { + -0.5 + } else { + 0.0 + } + } + } +} + +/// Berechnet tägl. Ehezufriedenheits-Delta für Ehe-Partner, wenn dieser eine Liebschaft hat. +/// Regel: +/// - Hoher Stand: +Zufriedenheit (sogar öffentliche Liebschaften sind akzeptabel) +/// - Mittlerer Stand: +Zufriedenheit wenn heimlich, -Zufriedenheit wenn öffentlich +/// - Niedriger Stand: neutral wenn heimlich, -Zufriedenheit wenn öffentlich +fn calculate_lover_marriage_satisfaction_delta(l: &LoverData) -> i32 { + let category = lover_status_category(&l.title1_tr, &l.title2_tr); + let is_public = l.visibility >= 60; + + match category { + 2 => { + // Hoher Stand: +1 pro Tag (Liebschaft ist gesellschaftlich akzeptabel/vorteilhaft) + 1 + } + 1 => { + // Mittlerer Stand: +0 wenn heimlich, -2 wenn öffentlich (Skandal) + if is_public { + -2 + } else { + 0 + } + } + _ => { + // Niedriger Stand: 0 wenn heimlich, -1 wenn öffentlich + if is_public { + -1 + } else { + 0 + } + } + } +} + fn breakup_risk_percent(l: &LoverData) -> f64 { if l.affection >= 45 { return 0.0;