Beispiel #1
0
    private List <Script_Sheep> SenseNearbySheep(int p_range)
    {
        List <Script_Sheep> allSheep         = _grid.GetSheep();
        List <Script_Sheep> SheepWithinRange = new List <Script_Sheep>();
        int xCurrent = GetPositionAsInt().x;
        int zCurrent = GetPositionAsInt().z;


        int xMin = xCurrent;
        int xMax = xCurrent;
        int zMin = zCurrent;
        int zMax = zCurrent;

        for (int x = xCurrent - p_range; x <= xCurrent; x++)
        {
            if (x < 0)
            {
                continue;
            }

            xMin = x;
            break;
        }
        for (int x = xCurrent + p_range; x >= xCurrent; x--)
        {
            if (x >= _grid.GetWidth())
            {
                continue;
            }

            xMax = x;
            break;
        }
        for (int z = zCurrent - p_range; z <= zCurrent; z++)
        {
            if (z < 0)
            {
                continue;
            }

            zMin = z;
            break;
        }
        for (int z = zCurrent + p_range; z >= zCurrent; z--)
        {
            if (z >= _grid.GetHeight())
            {
                continue;
            }

            zMax = z;
            break;
        }

        for (int z = zMin; z <= zMax; z++)
        {
            for (int x = xMin; x <= xMax; x++)
            {
                foreach (Script_Sheep sheep in allSheep)
                {
                    int sheepX = sheep.GetCurrentGridPosition().x;
                    int sheepZ = sheep.GetCurrentGridPosition().z;
                    if (sheepX >= xMin && sheepX <= xMax &&
                        sheepZ >= zMin && sheepZ <= zMax)
                    {
                        SheepWithinRange.Add(sheep);
                    }
                }
            }
        }

        if (SheepWithinRange.Count > 0)
        {
            return(SheepWithinRange);
        }


        return(null);
    }