Skip to content

Sprint 3.3: Introduce Trust/Threat axes for faction diplomacy#103

Merged
makr-code merged 2 commits into
mainfrom
copilot/sprint-3-3-trust-threat-achsen-einfuehren
Apr 12, 2026
Merged

Sprint 3.3: Introduce Trust/Threat axes for faction diplomacy#103
makr-code merged 2 commits into
mainfrom
copilot/sprint-3-3-trust-threat-achsen-einfuehren

Conversation

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Currently the diplomacy system tracks only a single standing value per faction. This PR introduces independent trust_level and threat_level axes (as specified in COMBAT_SYSTEM_DESIGN §6.1), wires them into trade/agreement/war mechanics, and surfaces both values in the UI.

DB

sql/migrate_trust_threat_v1.sql — adds to diplomacy:

  • trust_level DECIMAL(5,2) (0–100) — bilateral trust built via cooperation
  • threat_level DECIMAL(5,2) (0–100) — threat perception from aggression/fleet
  • trust_decay_rate DECIMAL(4,3) — hourly decay rate (default 0.5)

Seeds initial values from existing standing (positive standing → trust, negative → threat).

API

api/faction_relations.php

  • standing action now returns trust_level + threat_level per faction
  • New GET ?action=trust_threat — per-faction trust/threat + derived stance
  • New POST ?action=update_trust_threat — write trust/threat deltas with clamping
  • _diplo_stance(trust, threat) helper: ALLY | FRIENDLY | NEUTRAL | TENSE | HOSTILE

api/diplomacy.php

  • fa_ai_acceptance() now factors trust (+15 max) and threat (−20 max) into NPC acceptance probability
  • Alliance proposals blocked when threat_level ≥ 75
  • Accepted agreements award type-specific trust gains (trade +5, research +8, alliance +10, non_aggression +3)
  • Cancellations apply trust penalties (−5 default, −15 for alliance)

api/factions.php

  • trade_offers applies a threat surcharge: every 10 threat points above 50 reduces effective standing by 1, narrowing the visible offer pool

UI

RuntimeDiplomacyDataModel.js — new pure helpers:

dm.trustMeta(60)              // { cls: 'trust-moderate', label: 'Moderate Trust' }
dm.threatMeta(80)             // { cls: 'threat-critical', label: 'Critical Threat' }
dm.diploStance(80, 10)        // { code: 'ALLY', label: 'Ally', cls: 'stance-ally' }
dm.trustThreatBarsHTML(65, 20) // dual progress bars + stance chip HTML

RuntimeDiplomacyPanel.js — trust/threat bars rendered in faction panel header alongside agreements.

RuntimeFactionsController.js — each faction card gains 🤝 N / ⚠️ N badges and a derived stance chip; syncFactionCard() keeps them live on standing updates.

Tests

18 new tests in diplomacy-panel.test.js covering all trust/threat helpers (trustMeta, threatMeta, diploStance, trustThreatBarsHTML) and panel rendering with trust/threat data (40 tests total).

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
- sql/migrate_trust_threat_v1.sql: ADD trust_level, threat_level, trust_decay_rate to diplomacy table; seed from existing standing
- api/faction_relations.php: standing action returns trust/threat; new trust_threat GET + update_trust_threat POST; _diplo_stance() helper
- api/diplomacy.php: fa_ai_acceptance() factors in trust/threat; propose blocks alliance at threat>=75; accept/cancel write trust delta
- api/factions.php: trade_offers applies threat surcharge to effective standing
- js/engine/runtime/RuntimeDiplomacyDataModel.js: trustMeta, threatMeta, diploStance, trustThreatBarsHTML helpers
- js/engine/runtime/RuntimeDiplomacyPanel.js: render trust/threat bars in panel header
- js/engine/runtime/RuntimeFactionsController.js: trust/threat row in faction cards, syncFactionCard syncs badges
- tests/js/diplomacy-panel.test.js: 18 new tests covering trust/threat helpers and UI rendering

Agent-Logs-Url: https://github.com/makr-code/GalaxyQuest/sessions/d837dce5-f59f-4223-bd41-d8a4b42f780b

Co-authored-by: makr-code <150588092+makr-code@users.noreply.github.com>
Copilot AI changed the title [WIP] Add trust and threat values for factions and NPCs Sprint 3.3: Introduce Trust/Threat axes for faction diplomacy Apr 12, 2026
Copilot AI requested a review from makr-code April 12, 2026 06:46
@makr-code makr-code marked this pull request as ready for review April 12, 2026 06:49
@makr-code makr-code merged commit 2b349f1 into main Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sprint 3.3: Trust/Threat-Achsen einführen

2 participants