Exemple #1
0
    void OnFormation1(int sType, int sNum, int kNum)
    {
        int num      = sNum + kNum;
        int frontNum = Mathf.CeilToInt(num * 7 / 10f);
        int backNum  = Mathf.FloorToInt(num * 3 / 10f);
        int fRowNum  = 0;
        int bRowNum  = 0;

        int[] fRows = new int[7];
        int[] bRows = new int[3];

        if (frontNum <= 12)
        {
            fRowNum = frontNum / 4;
            if (fRowNum == 0)
            {
                if (frontNum % 4 > 0)
                {
                    fRowNum  = 1;
                    fRows[0] = frontNum;
                }
            }
            else if (fRowNum == 1)
            {
                fRows[0] = 4;
                if (frontNum % 4 > 0)
                {
                    fRowNum  = 2;
                    fRows[1] = frontNum % 4;
                }
            }
            else
            {
                fRows[0] = 4;
                fRows[1] = 4;
                fRows[2] = frontNum % 8;
                if (frontNum % 4 > 0)
                {
                    fRowNum++;
                }
            }
        }
        else if (frontNum >= 49)
        {
            fRowNum = 7;
            int left = frontNum % 7;
            int row  = frontNum / 7;
            for (int i = 0; i < 7; i++)
            {
                if (i < left)
                {
                    fRows[i] = row + 1;
                }
                else
                {
                    fRows[i] = row;
                }
            }
        }
        else
        {
            for (int i = 4; i <= 7; i++)
            {
                if (i * i > frontNum && i * (i - 1) <= frontNum)
                {
                    fRowNum = i;
                    int left = frontNum % (i - 1);
                    int row  = frontNum / (i - 1);
                    for (int j = 0; j < i - 1; j++)
                    {
                        fRows[j] = row;
                    }
                    fRows[i - 1] = left;
                }
                else if (i * i <= frontNum && i * (i + 1) > frontNum)
                {
                    fRowNum = i;
                    int left = frontNum % i;
                    int row  = frontNum / i;
                    for (int j = 0; j < i; j++)
                    {
                        if (j < left)
                        {
                            fRows[j] = row + 1;
                        }
                        else
                        {
                            fRows[j] = row;
                        }
                    }
                }
            }
        }

        if (backNum <= 12)
        {
            bRowNum = backNum / 4;
            if (bRowNum == 0)
            {
                if (backNum % 4 > 0)
                {
                    bRowNum  = 1;
                    bRows[0] = backNum;
                }
            }
            else if (bRowNum == 1)
            {
                bRows[0] = 4;
                if (backNum % 4 > 0)
                {
                    bRowNum  = 2;
                    bRows[1] = backNum % 4;
                }
            }
            else
            {
                bRows[0] = 4;
                bRows[1] = 4;
                bRows[2] = backNum % 8;
                if (backNum % 4 > 0)
                {
                    bRowNum++;
                }
            }
        }
        else
        {
            bRowNum = 3;
            int left = backNum % 3;
            int row  = backNum / 3;
            for (int i = 0; i < 3; i++)
            {
                if (i < left)
                {
                    bRows[i] = row + 1;
                }
                else
                {
                    bRows[i] = row;
                }
            }
        }

        int     soliderIndex = 0;
        int     knightNum    = kNum;
        int     soliderNum   = frontNum - knightNum;
        Vector3 posBase      = Vector3.zero;
        int     xSpace       = 4 * (int)WarSceneController.locationStepX;
        int     ySpace       = 4 * (int)WarSceneController.locationStepY;

        if (side == WarSceneController.WhichSide.Left)
        {
            xSpace  = 4 * (int)WarSceneController.locationStepX;
            posBase = new Vector3(-600 + xSpace, 0, 0);
        }
        else
        {
            xSpace  = -4 * (int)WarSceneController.locationStepX;
            posBase = new Vector3(600 + xSpace, 0, 0);
        }

        for (int i = 0; i < fRowNum; i++)
        {
            for (int j = 0; j < fRows[i]; j++)
            {
                Vector3 pos = Vector3.zero;
                if (j % 2 == 0)
                {
                    pos = new Vector3(posBase.x + xSpace * i, posBase.y - ySpace * j / 2, 0);
                }
                else
                {
                    pos = new Vector3(posBase.x + xSpace * i, posBase.y + ySpace * ((int)(j + 1) / 2), 0);
                }

                if (soliderNum > 0)
                {
                    soliderNum--;
                    SolidersController sCtrl = SetSolider(sType, pos, soliderIndex, false);
                    warCtrl.AddSolider(side, sCtrl);
                    warCtrl.AddFrontSolider(side, sCtrl);
                }
                else if (knightNum > 0)
                {
                    knightNum--;
                    SolidersController sCtrl = SetSolider(sType, pos, soliderIndex, true);
                    warCtrl.AddSolider(side, sCtrl);
                    warCtrl.AddFrontSolider(side, sCtrl);
                }
                soliderIndex++;
            }
        }

        if (side == WarSceneController.WhichSide.Left)
        {
            xSpace  = -4 * (int)WarSceneController.locationStepX;
            posBase = new Vector3(-600 + xSpace, 0, 0);
        }
        else
        {
            xSpace  = 4 * (int)WarSceneController.locationStepX;
            posBase = new Vector3(600 + xSpace, 0, 0);
        }

        for (int i = 0; i < bRowNum; i++)
        {
            for (int j = 0; j < bRows[i]; j++)
            {
                Vector3 pos = Vector3.zero;
                if (j % 2 == 0)
                {
                    pos = new Vector3(posBase.x + xSpace * i, posBase.y - ySpace * j / 2, 0);
                }
                else
                {
                    pos = new Vector3(posBase.x + xSpace * i, posBase.y + ySpace * ((int)(j + 1) / 2), 0);
                }

                if (knightNum > 0)
                {
                    knightNum--;
                    SolidersController sCtrl = SetSolider(sType, pos, soliderIndex, true);
                    warCtrl.AddSolider(side, sCtrl);
                    warCtrl.AddBackSolider(side, sCtrl);
                }
                else
                {
                    SolidersController sCtrl = SetSolider(sType, pos, soliderIndex, false);
                    warCtrl.AddSolider(side, sCtrl);
                    warCtrl.AddBackSolider(side, sCtrl);
                }
                soliderIndex++;
            }
        }
    }