Sprint 3.3: Introduce Trust/Threat axes for faction diplomacy#103
Merged
makr-code merged 2 commits intoApr 12, 2026
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently the diplomacy system tracks only a single
standingvalue per faction. This PR introduces independenttrust_levelandthreat_levelaxes (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 todiplomacy:trust_level DECIMAL(5,2)(0–100) — bilateral trust built via cooperationthreat_level DECIMAL(5,2)(0–100) — threat perception from aggression/fleettrust_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.phpstandingaction now returnstrust_level+threat_levelper factionGET ?action=trust_threat— per-faction trust/threat + derived stancePOST ?action=update_trust_threat— write trust/threat deltas with clamping_diplo_stance(trust, threat)helper:ALLY | FRIENDLY | NEUTRAL | TENSE | HOSTILEapi/diplomacy.phpfa_ai_acceptance()now factors trust (+15 max) and threat (−20 max) into NPC acceptance probabilitythreat_level ≥ 75trade +5,research +8,alliance +10,non_aggression +3)api/factions.phptrade_offersapplies a threat surcharge: every 10 threat points above 50 reduces effective standing by 1, narrowing the visible offer poolUI
RuntimeDiplomacyDataModel.js— new pure helpers:RuntimeDiplomacyPanel.js— trust/threat bars rendered in faction panel header alongside agreements.RuntimeFactionsController.js— each faction card gains🤝 N/⚠️ Nbadges and a derived stance chip;syncFactionCard()keeps them live on standing updates.Tests
18 new tests in
diplomacy-panel.test.jscovering all trust/threat helpers (trustMeta,threatMeta,diploStance,trustThreatBarsHTML) and panel rendering with trust/threat data (40 tests total).