Пример #1
0
    // gets manhattan distance to the closest player (array 0) controlled unit
    private int getMinDistance(int curX, int curY)
    {
        int  minD     = 9999;
        int  thisD    = minD;
        Unit tempUnit = controller.GetCommander(0).getUnitStack();

        // go through stack and find the min distance
        while (tempUnit != null)
        {
            // if the unit isn't dead...
            if (!tempUnit.isDead())
            {
                thisD = Mathf.Abs(curX - tempUnit.getX()) + Mathf.Abs(curY - tempUnit.getY());

                if (thisD < minD)
                {
                    minD = thisD;
                }
            }

            // get next unit
            tempUnit = tempUnit.nextUnit;
        }

        return(minD);
    }