Faction.Relations at key 16 decides stance between NPC factions
Hated toward a claimed faction is kill on sight in any zone, owned or not; Hostile to Beloved govern presence by security level through the existing PresencePermitted and trespass path. Entity.Regard is the one reader of the map: unset either side is Neutral, a faction regards itself Beloved, absent is Neutral, and a faction the catalog does not hold is Neutral. Relations are directed and stance reads the claimed faction from telemetry. The catalog authors none, so behaviour equals base until the table lands; the schema id change is re-saved in the next commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5bf507aba0
commit
ea328b00e5
6 changed files with 189 additions and 9 deletions
|
|
@ -49,7 +49,10 @@ public class Faction
|
|||
|
||||
// Keys 13 to 15 (overworldMusic, combatMusic, bossMusic) held Wwise ids; retired, never reuse them.
|
||||
|
||||
// Key 16 is reserved for Relations (operator ruling faction-relations-field).
|
||||
// How this faction regards each other faction; absent is Neutral. Directed: this map says how this faction regards them, theirs
|
||||
// says how they regard it. Read only through Entity.Regard (ruling faction-relations-field).
|
||||
[Inspectable, CultReference(typeof(Faction), many: true), JsonProperty("relations"), Key(16)]
|
||||
public Dictionary<CultRecordRef<Faction>, FactionRelationship> Relations = new Dictionary<CultRecordRef<Faction>, FactionRelationship>();
|
||||
|
||||
// The faction's rules of engagement; null fights as FactionDoctrine.Default.
|
||||
[Inspectable, JsonProperty("doctrine"), Key(17)]
|
||||
|
|
@ -58,7 +61,7 @@ public class Faction
|
|||
// The maker's final assembly: the distribution every lot of theirs draws its own quality from, and the hard ceiling on each
|
||||
// of its roles (quality-lean-assembly-hard-ceiling). Null is not authored: a lot of theirs assembles at AssemblyDistribution's
|
||||
// defaults. assembly-from-maker derives it once at the part mean plus a tolerance margin (quality-min-tolerance-binned-assembly);
|
||||
// tune it in Studio after that. Key 16 is reserved for Relations and 18 for Livery. Key 20 was assemblyDeviation (retired); never reuse it.
|
||||
// tune it in Studio after that. Key 18 is reserved for Livery. Key 20 was assemblyDeviation (retired); never reuse it.
|
||||
[Inspectable, JsonProperty("assembly"), Key(19)]
|
||||
public AssemblyDistribution Assembly;
|
||||
|
||||
|
|
|
|||
|
|
@ -1261,13 +1261,15 @@ public abstract class Entity
|
|||
|
||||
// This observer's stance toward `other`: its own override, else its belief. Allies (the observer's own non-null faction) are
|
||||
// known by datalink; any other contact is believed by the telemetry received with its track, and unknown (never hostile)
|
||||
// without it. In a zone owned by a faction a contact is hostile when its claimed faction is the owner's and the owner does
|
||||
// not permit its presence, or when this is the owner's ship and believes the contact trespasses.
|
||||
// without it. A contact whose claimed faction this observer's faction Hates is hostile in any zone, owned or not; Hostile to
|
||||
// Beloved govern presence instead. In a zone owned by a faction a contact is hostile when its claimed faction is the owner's and
|
||||
// the owner does not permit its presence, or when this is the owner's ship and believes the contact trespasses.
|
||||
public bool IsHostileTo(Entity other)
|
||||
{
|
||||
if (_iffOverrides.TryGetValue(other, out var overrideHostile)) return overrideHostile;
|
||||
if (Faction != null && other.Faction == Faction) return false;
|
||||
if (!_telemetry.TryGetValue(other, out var claimed)) return false;
|
||||
if (Regard(Faction, claimed) == FactionRelationship.Hated) return true;
|
||||
var owner = Zone.GalaxyZone.Owner;
|
||||
if (owner == null) return false;
|
||||
return (claimed == owner && !(PresencePermitted?.Value ?? true)) || (Faction == owner && BelievesTrespassing(other));
|
||||
|
|
@ -1300,14 +1302,27 @@ public abstract class Entity
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: Inter-faction relationships
|
||||
// How `faction` regards this entity's faction.
|
||||
public FactionRelationship GetFactionRelationship(Faction faction)
|
||||
{
|
||||
if (faction == null)
|
||||
return FactionRelationship.Neutral;
|
||||
if (this is Ship {IsPlayerShip: true})
|
||||
return Zone.Galaxy.FactionRelationships[faction];
|
||||
return faction == Faction ? FactionRelationship.Beloved : FactionRelationship.Neutral;
|
||||
return Regard(faction, Faction);
|
||||
}
|
||||
|
||||
// The one reader of Faction.Relations: how `regarding` regards `regarded`. Unset either side is Neutral, a faction regards
|
||||
// itself Beloved, and absent from the map is Neutral. A faction the catalog does not hold has no key and is Neutral.
|
||||
private FactionRelationship Regard(Faction regarding, Faction regarded)
|
||||
{
|
||||
if (regarding == null || regarded == null) return FactionRelationship.Neutral;
|
||||
if (regarding == regarded) return FactionRelationship.Beloved;
|
||||
if (regarding.Relations == null || regarding.Relations.Count == 0) return FactionRelationship.Neutral;
|
||||
var key = ItemManager.ItemData.TryGetHandle(regarded)?.Key;
|
||||
return key != null && regarding.Relations.TryGetValue(new CultRecordRef<Faction>(key.Value), out var relationship)
|
||||
? relationship
|
||||
: FactionRelationship.Neutral;
|
||||
}
|
||||
|
||||
public static bool IsPresencePermitted(FactionRelationship relationship, SecurityLevel securityLevel) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue