Beispiel #1
0
    public void Initialize(GameField gameField, Cell mpos, Cell dest)
    {
        this.gameField = gameField;
        controlledPawn.Initialize(gameField, mpos);
        detector.Initialize(gameField.characterInstance, this);

        pathFinder = new PathFinder(gameField.field);
        path       = pathFinder.CalcPath(mpos, dest);
        Debug.Log("path " + path.Count);

        meshRender.material = defaulMat;


        ResetPathIndex();
        nextCell = path[GetNextPathIndex()];
        MoveToTargetStep();
        isInit = true;
    }
Beispiel #2
0
 private void ResetPath()
 {
     path = pathFinder.CalcPath(controlledPawn.mPosition, gameField.characterInstance.mPosition);
     ResetPathIndex();
     //DEBUG_DRAW_PATH();
 }
Beispiel #3
0
    private void CalculateStartPoints()
    {
        for (int i = 0; i < hevGenMaxCount; i++)
        {
            Cell sc = field.GetRandomCell();
            Cell ec = field.GetRandomCell();
            if ((sc - ec).GetLength() >= hevDist)
            {
                startCell = sc;
                endCell   = ec;
                break;
            }
        }
        var path1 = pathFinder.CalcPath(startCell, endCell);

        List <Cell> blackList = new List <Cell>(2);

        //field.GetNeight(startCell);
        //blackList.AddRange(field.GetNeight(endCell));
        blackList.Add(startCell);
        blackList.Add(endCell);
        blackList.AddRange(field.GetNeight(endCell));
        blackList.AddRange(field.GetNeight(startCell));

        Cell c1 = field.GetRandomCellNotInList(blackList);
        Cell c2 = field.GetRandomCellNotInList(blackList);
        Cell c3 = field.GetRandomCellNotInList(blackList);
        Cell c4 = field.GetRandomCellNotInList(blackList);

        //Cell c1 = field.GetRandomCell();
        //Cell c2 = field.GetRandomCell();
        //Cell c3 = field.GetRandomCell();
        //Cell c4 = field.GetRandomCell();

        bool isBad(Cell x1, Cell x2, Cell x3, Cell x4) => Cell.GetCityLength(x1, x2) <= minEnemyRegPathDistance || Cell.GetCityLength(x3, x4) <= minEnemyRegPathDistance;

        for (int i = 0; isBad(c1, c2, c3, c4) && i < hevGenMaxCount * hevGenMaxCount; i++)
        {
            c1 = field.GetRandomCellNotInList(blackList);
            c2 = field.GetRandomCellNotInList(blackList);
            c3 = field.GetRandomCellNotInList(blackList);
            c4 = field.GetRandomCellNotInList(blackList);
        }
        if (isBad(c1, c2, c3, c4))
        {
            ReGeneratField();
        }
        //Debug.Log(c1 + " " + c2);
        //Debug.Log(c3 + " " + c4);

        enemy1StartCell = c1;
        enemy2StartCell = c3;
        enemyPath1      = pathFinder.CalcPath(c1, c2);
        enemyPath2      = pathFinder.CalcPath(c3, c4);
        //Debug.Log(enemyPath1.Count);
        //Debug.Log(enemyPath2.Count);


        //DrawColor1Path(path1);
        //DrawColor2Path(enemyPath1);
        //DrawColor1Path(enemyPath2);
    }