Enemy Loadout Generation
Modified zone generator to scale the radius and mass of a zone according to galaxy density Added loadout generator which procedurally generates ships and turrets Generating 3 randomized ships in each occupied zone Fixed DatabaseCache.GetAll for parent types Fixed wormhole traversal bug for returning to previous zone (ZoneRenderer subscriptions not being properly disposed)
This commit is contained in:
parent
c0494ee3d8
commit
ebde23a64d
25 changed files with 5421 additions and 148 deletions
|
|
@ -32,31 +32,32 @@ public static class Extensions
|
|||
|
||||
public static T[] WeightedRandomElements<T>(this IEnumerable<T> collection, ref Random random, Func<T, float> weightFunction, int count)
|
||||
{
|
||||
var weights = new Dictionary<T, float>(collection.Count());
|
||||
var elements = collection as T[] ?? collection.ToArray();
|
||||
var weights = new Dictionary<T, float>(elements.Length);
|
||||
var totalWeight = 0f;
|
||||
foreach (var x in collection)
|
||||
foreach (var x in elements)
|
||||
{
|
||||
weights[x] = weightFunction(x);
|
||||
totalWeight += weights[x];
|
||||
}
|
||||
|
||||
var elements = new T[count];
|
||||
var randomElements = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var targetWeight = random.NextFloat(totalWeight);
|
||||
var accumWeight = 0f;
|
||||
foreach (var x in collection)
|
||||
foreach (var x in elements)
|
||||
{
|
||||
accumWeight += weights[x];
|
||||
if (accumWeight > targetWeight)
|
||||
{
|
||||
elements[i] = x;
|
||||
randomElements[i] = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
return randomElements;
|
||||
}
|
||||
|
||||
// Thanks, https://stackoverflow.com/a/48599119
|
||||
|
|
|
|||
Loading…
Reference in a new issue