示例#1
0
    void Respawn(List <ShipDriver> drivers)
    {
        int count = drivers.Count;

        Vector3 forward = (BattleBehaviour.current.battleCenter - point.position).normalized;
        Vector3 right   = Vector3.Cross(point.up, forward);

        Quaternion rotation = Quaternion.LookRotation(forward);
        Vector3    position = forward * -distanceToCenter;

        DistributionCube cube = new DistributionCube(count * 40, count * 20, count * 20, 4, 2, 2);

        BattleGenerator.GenerateShips(
            drivers,
            position,
            rotation,
            point.up,
            right,
            forward,
            cube,
            shipContainer
            );
    }
示例#2
0
    void GenerateShips(Vector3 team1Pos, Vector3 team2Pos)
    {
        int playerTeam = Random.Range(0, 2);

        //Get ships from assets. Distribute them in arrays by classes
        var shipModels = GameResources.GetAllShips();

        int shipAmount = config.shipsAmount.value;

        //Get ships distribution by classes { 1, 2, 3 }
        if (config.lightShipsWeight == 0 && config.averageShipsWeight == 0 && config.heavyShipsWeight == 0f)
        {
            config.lightShipsWeight.value   = 1;
            config.averageShipsWeight.value = 1;
            config.heavyShipsWeight.value   = 1;
        }

        BattleGenerator.ShipIndexPair[] playerShip;
        int playerPosition = Random.Range(0, shipAmount);

        switch (config.playerShip.type)
        {
        case PlayerShip.ShipType.Concrete:
            playerShip = new BattleGenerator.ShipIndexPair[] { new BattleGenerator.ShipIndexPair(shipModels.First(m => m.name == config.playerShip.shipName), playerPosition) };
            break;

        case PlayerShip.ShipType.RandomOfClass:
            playerShip = new BattleGenerator.ShipIndexPair[] { new BattleGenerator.ShipIndexPair(config.playerShip.shipClass, playerPosition) };
            break;

        default:
            playerShip = null;
            break;
        }

        DistributionCube cube = new DistributionCube(500, 500, 200, 5, 10, 2);

        BattleGenerator.GenerateShips(
            BattleGenerator.GenerateShipModels(shipModels, shipAmount, config.lightShipsWeight, config.averageShipsWeight, config.heavyShipsWeight, playerShip),
            BattleGenerator.GenerateDrivers(teams[0], shipAmount, playerTeam == 0 ? playerPosition : -1),
            team1Pos,
            Quaternion.LookRotation(-Vector3.forward, Vector3.up),
            Vector3.up,
            Vector3.right,
            -Vector3.forward,
            cube,
            this.ships
            );

        BattleGenerator.GenerateShips(
            BattleGenerator.GenerateShipModels(shipModels, shipAmount, config.lightShipsWeight, config.averageShipsWeight, config.heavyShipsWeight, playerShip),
            BattleGenerator.GenerateDrivers(teams[1], shipAmount, playerTeam == 1 ? playerPosition : -1),
            team2Pos,
            Quaternion.LookRotation(Vector3.forward, Vector3.up),
            Vector3.up,
            -Vector3.right,
            Vector3.forward,
            cube,
            this.ships
            );
    }
示例#3
0
        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++;
            }
        }
示例#4
0
        public static List <ShipController> GenerateShips(IEnumerable <ShipSystemModel> ships, IEnumerable <ShipDriver> drivers, Vector3 position, Quaternion rotation, Vector3 up, Vector3 right, Vector3 forward, DistributionCube cube)
        {
            List <ShipController> result = new List <ShipController>();

            GenerateShips(ships, drivers, position, rotation, up, right, forward, cube, result);
            return(result);
        }
示例#5
0
 public static List <ShipController> GenerateShips(IEnumerable <ShipDriver> drivers, Vector3 position, Quaternion rotation, Vector3 up, Vector3 right, Vector3 forward, DistributionCube cube)
 {
     return(GenerateShips(drivers.Select(d => d.ship.shipSystem.model), drivers, position, rotation, up, right, forward, cube));
 }
示例#6
0
 public static void GenerateShips(IEnumerable <ShipDriver> drivers, Vector3 position, Quaternion rotation, Vector3 up, Vector3 right, Vector3 forward, DistributionCube cube, ICollection <ShipController> outGeneratedShips)
 {
     GenerateShips(drivers.Select(d => d.ship.shipSystem.model), drivers, position, rotation, up, right, forward, cube, outGeneratedShips);
 }