Exemplo n.º 1
0
        private void processAIMesh(XmlElement pElement)
        {
            AIMesh = new AIMesh();
            XmlElement aimeshVertexDataElement = (XmlElement)pElement.SelectSingleNode("aimesh_vertex_data");

            if (aimeshVertexDataElement != null)
            {
                foreach (XmlElement vertexData in aimeshVertexDataElement.ChildNodes)
                {
                    Vector3 vect = new Vector3();
                    vect.x = float.Parse(vertexData.Attributes["x"].Value.ToString());
                    vect.y = float.Parse(vertexData.Attributes["y"].Value.ToString());
                    vect.z = float.Parse(vertexData.Attributes["z"].Value.ToString());
                    AIMesh.AIMeshVertexData.Add(vect);
                }
            }
            XmlElement aimeshIndexDataElement = (XmlElement)pElement.SelectSingleNode("aimesh_index_data");

            if (aimeshIndexDataElement != null)
            {
                foreach (XmlElement indexData in aimeshIndexDataElement.ChildNodes)
                {
                    AIMeshIndexData idxData = new AIMeshIndexData();
                    foreach (XmlElement vertex in indexData.ChildNodes)
                    {
                        idxData.VertexNumber.Add(int.Parse(vertex.InnerText));
                    }
                    AIMesh.AIMeshIndicsData.Add(idxData);
                }
            }
        }
        public Vector2 fromPositionToGrid(Vector2 position)
        {
            AIMesh mesh = Pathfinder.getMesh();

            if (mesh == null)
            {
                _logger.LogCoreError("Tried to get a position without an initialised AIMesh!");
                return(new Vector2());
            }

            return(position / (float)PATH_DEFAULT_BOX_SIZE(mesh.getSize()));
        }
Exemplo n.º 3
0
        public Vector2 fromGridToPosition(Vector2 position)
        {
            AIMesh mesh = Pathfinder.getMesh();

            if (mesh == null)
            {
                Logger.LogCoreError("Tried to get a grid location without an initialised AIMesh!");
                return(new Vector2());
            }

            return(position * PATH_DEFAULT_BOX_SIZE(mesh.getSize()));
        }
Exemplo n.º 4
0
 public MovementVector ToMovementVector(float x, float y)
 {
     return(new MovementVector((short)((x - AIMesh.getWidth() / 2) / 2), (short)((y - AIMesh.getHeight() / 2) / 2)));
 }
Exemplo n.º 5
0
 public bool IsWalkable(float x, float y)
 {
     return(AIMesh.isWalkable(x, y));
 }
Exemplo n.º 6
0
 public float GetHeightAtLocation(Vector2 loc)
 {
     return(AIMesh.getY(loc.X, loc.Y));
 }
Exemplo n.º 7
0
 public float GetHeightAtLocation(float x, float y)
 {
     return(AIMesh.getY(x, y));
 }
Exemplo n.º 8
0
 public virtual float GetHeight()
 {
     return(AIMesh.getHeight());
 }
Exemplo n.º 9
0
 public virtual float GetWidth()
 {
     return(AIMesh.getWidth());
 }
Exemplo n.º 10
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.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();
             * }*/
        }
Exemplo n.º 11
0
 public void Save(List <Entity> objectsData,
                  AIMesh aimeshData,
                  TerrainGroup terrainData,
                  string xmlScene)
 {
 }
Exemplo n.º 12
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();
              }*/
        }