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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-17 14:00:22 +02:00
commit f732cff9e6
2 changed files with 27 additions and 0 deletions

View file

@ -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]

View file

@ -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,