Esempio n. 1
0
    Cell MoveDir(AgentUtilities.Dir direction)
    {
        FindNeighbors();
        Cell cell = neighbors[(int)direction];

        return(cell);
    }
Esempio n. 2
0
    void FindNeighbors()
    {
        Array.Clear(neighbors, 0, 6);
        if (currentCell.neighbors.Length == 0)
        {
            ReduceLife();
            return;
        }
        foreach (Cell neighbor in currentCell.neighbors)
        {
            if (!neighbor.occupied || overlap)
            {
                Vector3Int coords = neighbor.coords - currentCell.coords;
                switch (coords)
                {
                case Vector3Int v when v.Equals(Vector3Int.up):
                    dir = AgentUtilities.Dir.UP;

                    neighbors[(int)dir] = neighbor;
                    break;

                case Vector3Int v when v.Equals(Vector3Int.down):
                    dir = AgentUtilities.Dir.DOWN;

                    neighbors[(int)dir] = neighbor;
                    break;

                case Vector3Int v when v.Equals(Vector3Int.left):
                    dir = AgentUtilities.Dir.LEFT;

                    neighbors[(int)dir] = neighbor;
                    break;

                case Vector3Int v when v.Equals(Vector3Int.right):
                    dir = AgentUtilities.Dir.RIGHT;

                    neighbors[(int)dir] = neighbor;
                    break;

                case Vector3Int v when v.Equals(new Vector3Int(0, 0, 1)):
                    dir = AgentUtilities.Dir.FORWARD;

                    neighbors[(int)dir] = neighbor;
                    break;

                case Vector3Int v when v.Equals(new Vector3Int(0, 0, -1)):
                    dir = AgentUtilities.Dir.BACKWARD;

                    neighbors[(int)dir] = neighbor;
                    break;
                }
            }
        }
    }
Esempio n. 3
0
    void Move()
    {
        if (!alive)
        {
            return;
        }
        float moveAxis     = (float)random.NextDouble() * dirChance;
        int   moveDistance = 0;

        AgentUtilities.Dir moveDirection = 0;

        if (moveAxis < yChance)
        {
            moveDistance  = (yAmplitude == 0) ? yDistFloor : ((int)yDist.Evaluate((float)random.NextDouble() * yAmplitude) + yDistFloor);
            moveDirection = (AgentUtilities.Dir)random.Next(2);
        }
        else
        {
            moveDistance  = (yAmplitude == 0) ? xzDistFloor : ((int)(xzDist.Evaluate((float)random.NextDouble() * xzAmplitude)) + xzDistFloor);
            moveDirection = (AgentUtilities.Dir)random.Next(4) + 2;
        }

        //Make sure that the agent is moving in multiples of distMod
        moveDistance = (int)Mathf.Round(moveDistance / distMod) * distMod;

        Cell        moveNext = currentCell;
        List <Cell> movePath = new List <Cell>();

        lastCell = currentCell;
        for (int i = 0; i < moveDistance; i++)
        {
            moveNext = MoveDir(moveDirection);
            if (moveNext == null)
            {
                ReduceLife();
                movePath.Clear();
                MoveTo(lastCell);
                Move();
                break;
            }
            else
            {
                movePath.Add(moveNext);
                MoveTo(moveNext);
            }
            ReduceLife();
        }
        foreach (Cell cell in movePath)
        {
            PlaceTunnel(cell);
        }
    }
Esempio n. 4
0
    public void Init(Cell cell, AgentUtilities.Dir dir)
    {
        //base.Init();
        this.cellOrigin = cellOrigin;
        this.cells      = cell.GetCellNeighbors(size);
        this.dir        = dir;
        cell.occupied   = true;
        cell.tunnel     = this;

        this.transform.localScale = (Vector3.one * size) * SimulationManager.Instance.cellSizeInWorld;

        GetComponent <Renderer>().material.color = color;
    }