Пример #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
            );
    }