public void insertObstructions(Map chart, AIMesh mesh)
        {
            if (mesh != null)
            {
                // Now to draw the mesh onto the thing.
                if (mesh.isLoaded())                     // if we have loaded the mesh
                {
                    for (int x = 0; x < GRID_WIDTH; x++) // for every grid piece
                    {
                        for (int y = 0; y < GRID_HEIGHT; y++)
                        {
                            Vector2 translated = fromGridToPosition(new Vector2(x, y));
                            if (!mesh.isWalkable(translated.X, translated.Y)) // If there's nothing at this position
                            {
                                map[x, y].occupied = true;                    // This is obstructed
                            }
                        }
                    }
                }
            }

            if (chart != null)
            {
                var objects = chart.GetObjects();
                foreach (var i in objects) // For every object
                {
                    if (!(i.Value is Minion) && !(i.Value is Champion))
                    {
                        continue;
                    }

                    Vector2 gridPos = fromPositionToGrid(i.Value.GetPosition());                                                         // get the position in grid size

                    int radius = ((int)Math.Ceiling((float)i.Value.CollisionRadius / (float)PATH_DEFAULT_BOX_SIZE(mesh.getSize()))) / 2; // How many boxes does the radius of this object cover?

                    for (int dx = -radius; dx < radius; dx++)                                                                            // For the whole radius in the width
                    {
                        if (gridPos.X + dx >= 0 && gridPos.X + dx < GRID_WIDTH)                                                          // As long as we're in the map (x)
                        {
                            for (int dy = -radius; dy < radius; dy++)                                                                    // for the whole radius in the y
                            {
                                if (gridPos.Y + dy >= 0 && gridPos.Y + dy < GRID_HEIGHT)                                                 // As long as we're in the map (y)
                                {
                                    map[(int)gridPos.X + dx, (int)gridPos.Y + dy].occupied = true;                                       // Occupy this piece of the map.
                                }
                            }
                        }
                    }
                }
            }

            /*  if (debugOutput())
             * {
             *    auto width = GRID_WIDTH;
             *    auto height = GRID_HEIGHT;
             #define MIN(a,b) (((a)>(b))?(b):(a))
             #define MAX(a,b) (((a)>(b))?(a):(b))
             *    std::ofstream imageFile("..\\..\\test.tga", std::ios::out | std::ios::binary);
             *    if (!imageFile) return;
             *
             *    // The image header
             *    unsigned char header[18] = { 0 };
             *    header[2] = 1;  // truecolor
             *    header[12] = width & 0xFF;
             *    header[13] = (width >> 8) & 0xFF;
             *    header[14] = height & 0xFF;
             *    header[15] = (height >> 8) & 0xFF;
             *    header[16] = 24;  // bits per pixel
             *
             *    imageFile.write((const char*)header, 18);
             *
             *    //for (int y = 0; y < height; y++)
             *    for (int y = height - 1; y >= 0; y--)
             *        for (int x = 0; x < width; x++)
             *        {
             *            // blue
             *            imageFile.put(map[x][y].occupied * 128);
             *            // green
             *            imageFile.put(map[x][y].occupied * 128);
             *            // red
             *            imageFile.put(map[x][y].occupied * 128);
             *        }
             *
             *    // The file footer. This part is totally optional.
             *    static const char footer[26] =
             *        "\0\0\0\0"  // no extension area
             *
             * "\0\0\0\0"  // no developer directory
             *
             * "TRUEVISION-XFILE"  // Yep, this is a TGA file
             *
             * ".";
             *    imageFile.write(footer, 26);
             *
             *    imageFile.close();
             * }*/
        }
예제 #2
0
 public bool IsWalkable(float x, float y)
 {
     return(AIMesh.isWalkable(x, y));
 }
예제 #3
0
        public void insertObstructions(Map chart, AIMesh mesh)
        {
            if (mesh != null)
            {
                // Now to draw the mesh onto the thing.
                if (mesh.isLoaded()) // if we have loaded the mesh
                    for (int x = 0; x < GRID_WIDTH; x++) // for every grid piece
                        for (int y = 0; y < GRID_HEIGHT; y++)
                        {
                            Vector2 translated = fromGridToPosition(new Vector2(x, y));
                            if (!mesh.isWalkable(translated.X, translated.Y)) // If there's nothing at this position
                                map[x, y].occupied = true; // This is obstructed
                        }
            }

            if (chart != null)
            {
                var objects = chart.getObjects();
                foreach (var i in objects) // For every object
                {
                    if (!(i.Value is Minion) && !(i.Value is Champion))
                        continue;

                    Vector2 gridPos = fromPositionToGrid(i.Value.getPosition()); // get the position in grid size

                    int radius = ((int)Math.Ceiling((float)i.Value.getCollisionRadius() / (float)PATH_DEFAULT_BOX_SIZE(mesh.getSize()))) / 2; // How many boxes does the radius of this object cover?

                    for (int dx = -radius; dx < radius; dx++) // For the whole radius in the width
                        if (gridPos.X + dx >= 0 && gridPos.X + dx < GRID_WIDTH) // As long as we're in the map (x)
                            for (int dy = -radius; dy < radius; dy++) // for the whole radius in the y
                                if (gridPos.Y + dy >= 0 && gridPos.Y + dy < GRID_HEIGHT) // As long as we're in the map (y)
                                    map[(int)gridPos.X + dx, (int)gridPos.Y + dy].occupied = true; // Occupy this piece of the map.
                }
            }

            /*  if (debugOutput())
              {
                  auto width = GRID_WIDTH;
                  auto height = GRID_HEIGHT;
  #define MIN(a,b) (((a)>(b))?(b):(a))
  #define MAX(a,b) (((a)>(b))?(a):(b))
                  std::ofstream imageFile("..\\..\\test.tga", std::ios::out | std::ios::binary);
                  if (!imageFile) return;

                  // The image header
                  unsigned char header[18] = { 0 };
                  header[2] = 1;  // truecolor
                  header[12] = width & 0xFF;
                  header[13] = (width >> 8) & 0xFF;
                  header[14] = height & 0xFF;
                  header[15] = (height >> 8) & 0xFF;
                  header[16] = 24;  // bits per pixel

                  imageFile.write((const char*)header, 18);

                  //for (int y = 0; y < height; y++)
                  for (int y = height - 1; y >= 0; y--)
                      for (int x = 0; x < width; x++)
                      {
                          // blue
                          imageFile.put(map[x][y].occupied * 128);
                          // green 
                          imageFile.put(map[x][y].occupied * 128);
                          // red 
                          imageFile.put(map[x][y].occupied * 128);
                      }

                  // The file footer. This part is totally optional.
                  static const char footer[26] =
                      "\0\0\0\0"  // no extension area

              "\0\0\0\0"  // no developer directory

              "TRUEVISION-XFILE"  // Yep, this is a TGA file

              ".";
                  imageFile.write(footer, 26);

                  imageFile.close();
              }*/
        }