Every Unity.Mathematics using, alias and qualified name under Assets\Scripts and tools now names CultMath. The nine `using static ...noise;` lines are gone: snoise lives on CultMath's math. UnityExtensions loses float4.ToColor and Color.ToFloat4, which duplicate the bridge's ToColor and ToCultMath; the float3 colour pair stays because the bridge has none. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
51 lines
No EOL
1.2 KiB
C#
51 lines
No EOL
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MessagePack;
|
|
using Random = CultMath.Random;
|
|
|
|
public abstract class ZoneSelector
|
|
{
|
|
public abstract GalaxyZone SelectZone(List<GalaxyZone> candidates);
|
|
}
|
|
|
|
public abstract class OrderedZoneSelector : ZoneSelector
|
|
{
|
|
public bool Flip = false;
|
|
|
|
protected abstract Func<GalaxyZone, IComparable> Comparison { get; }
|
|
|
|
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
|
|
{
|
|
var sorted = candidates.OrderBy(Comparison);
|
|
return Flip ? sorted.Last() : sorted.First();
|
|
}
|
|
}
|
|
|
|
public class DistanceSelector : OrderedZoneSelector
|
|
{
|
|
private GalaxyZone Target { get; }
|
|
|
|
|
|
public DistanceSelector(string[] args, IZoneResolver zoneResolver)
|
|
{
|
|
Target = zoneResolver.ResolveZone(args[0].Trim());
|
|
}
|
|
|
|
protected override Func<GalaxyZone, IComparable> Comparison => zone => Target?.Distance[zone] ?? 0;
|
|
}
|
|
|
|
public class RandomSelector : ZoneSelector
|
|
{
|
|
private Random Random { get; }
|
|
|
|
public RandomSelector(ref Random random)
|
|
{
|
|
Random = random;
|
|
}
|
|
|
|
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
|
|
{
|
|
return candidates[Random.NextInt(candidates.Count)];
|
|
}
|
|
} |