public static void GenerateShips(IEnumerable <ShipSystemModel> ships, IEnumerable <ShipDriver> drivers, Vector3 position, Quaternion rotation, Vector3 up, Vector3 right, Vector3 forward, DistributionCube cube, ICollection <ShipController> outGeneratedShips) { int shipsAmount = drivers.Count(); int[] shipsDistribution = Algs.Split(shipsAmount, Enumerable.Range(0, cube.cubesAmount).Select(i => UnityEngine.Random.value).ToArray()); int n = 0; var driver = drivers.GetEnumerator(); var ship = ships.GetEnumerator(); foreach (var pos in cube.Distribute(position, up, right, forward)) { for (int m = 0; m < shipsDistribution[n]; m++) { driver.MoveNext(); ship.MoveNext(); var oldShip = driver.Current.ship; var s = new CustomShipInitializerModel(ship.Current, driver.Current) .Init(pos + right * (20 * m), rotation); outGeneratedShips.Add(s); } n++; } }
public static ShipSystemModel[] GenerateShipModels(ShipSystemModel[] models, int amount, float[] classWeights, IEnumerable <ShipIndexPair> specialShips = null) { var ships = models .GroupBy(s => GameResources.GetShipHull(s.hull.hullName).shipClass) .Where(s => s.Key > 0 && s.Key < 4) .OrderBy(s => s.Key) .Select(s => s.ToArray()).ToArray(); int[] kShips = Algs.Split(amount, classWeights); var result = new LimitedRandomList <MyRandom <ShipSystemModel> >(ships .Select(kShips, (s, k) => new LimitedProperty <MyRandom <ShipSystemModel> >(new MyRandom <ShipSystemModel>(s), k)).ToArray() ).Select(v => (ShipSystemModel)v).ToArray(); if (specialShips != null) { foreach (var s in specialShips) { int specialShipClass = s.GetShipClass(ships); ShipSystemModel specialShipModel = s.GetModel(ships); if (result[s.index] == specialShipModel) { continue; } else { //looking for same model in other position for (int i = 0; i < amount; i++) { // next if index used by other special model if (specialShips.Any(p => p.index == i)) { continue; } if (result[i] == specialShipModel) { var t = result[i]; result[i] = result[s.index]; result[s.index] = t; goto NEXT; } } } if (GetShipClass(ships, result[s.index]) == specialShipClass) { result[s.index] = specialShipModel; continue; } else { //looking for same model class in other position; for (int i = 0; i < amount; i++) { // next if index used by other special model if (specialShips.Any(p => p.index == i)) { continue; } if (GetShipClass(ships, result[i]) == specialShipClass) { result[i] = result[s.index]; result[s.index] = specialShipModel; goto NEXT; } } } //Brute setting model result[s.index] = specialShipModel; NEXT: continue; } } return(result); }