From f732cff9e6bd6f78d985923d620a23869b908480 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 17 Sep 2026 14:00:22 +0200 Subject: [PATCH] Spawn neutral wanderers so combat has something non-hostile to target ZoneGenerator now spawns NeutralWandererCount ships (default 2, authored on ZoneGenerationSettings) from a galaxy faction that is neither the zone owner nor its nearest faction, using the zone's existing seeded Random so placement stays deterministic per zone. None spawn when no faction qualifies. The faction-pool rule is pulled into ZoneGenerator.EligibleWandererFactions so it is unit-testable without running the full generation pipeline. Co-Authored-By: Claude Opus 5 --- Assets/Scripts/ServerShared/Settings.cs | 5 +++++ Assets/Scripts/ServerShared/ZoneGenerator.cs | 22 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 2f4a40afc..ff5980109 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -149,6 +149,11 @@ public class ZoneGenerationSettings public ExponentialLerp GasGiantBandBrightness; public string[] NameData; + + // Non-hostile ships for hand-testing combat/targeting: belong to a galaxy faction that is + // neither the zone owner nor the zone's nearest faction, so derived hostility rules leave + // them non-hostile to the player. Zero eligible factions means none are spawned. + public int NeutralWandererCount = 2; } [Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject] diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index d182c9e19..c36d5e9f6 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -311,9 +311,31 @@ public static class ZoneGenerator pack.Entities.Add(ship); } + // Neutral wanderers: ships belonging to a faction that neither owns the zone nor is its + // nearest faction, so existing hostility rules leave them non-hostile to the player. + // Testing affordance for hand-testing combat/targeting; none spawn if no faction qualifies. + var eligibleWandererFactions = EligibleWandererFactions(galaxy.Factions, galaxyZone.Owner, nearestFaction); + if (zoneSettings.NeutralWandererCount > 0 && eligibleWandererFactions.Length > 0) + { + var wandererFaction = eligibleWandererFactions[random.NextInt(eligibleWandererFactions.Length)]; + var wandererLoadoutGenerator = GetLoadoutGenerator(wandererFaction); + for (int i = 0; i < zoneSettings.NeutralWandererCount; i++) + { + var ship = wandererLoadoutGenerator.GenerateShipLoadout(); + if (ship == null) continue; + pack.Entities.Add(ship); + } + } + return pack; } + // The neutral-wanderer faction pool: every galaxy faction except the zone owner and the nearest + // faction (whose ships are already the zone's hostile-when-trespassing/enemy spawns). Extracted so + // the selection rule is testable without running the full zone-generation pipeline. + public static Faction[] EligibleWandererFactions(Faction[] factions, Faction owner, Faction nearest) => + factions.Where(f => f != owner && f != nearest).ToArray(); + // static float ResourceValue(ref Random random, ZoneGenerationSettings settings, SimpleCommodityData resource, float density) // { // return random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,