Exemple #1
0
        public Spot GetToSpot(PathGraph pg, int i)
        {
            float x, y, z;

            GetPath(i, out x, out y, out z);
            return(pg.GetSpot(x, y, z));
        }
Exemple #2
0
        public List <Spot> GetPathsToSpots(PathGraph pg)
        {
            var list = new List <Spot>(n_paths);

            for (int i = 0; i < n_paths; i++)
            {
                list.Add(GetToSpot(pg, i));
            }
            return(list);
        }
Exemple #3
0
 public bool HasPathTo(PathGraph pg, Spot s)
 {
     for (int i = 0; i < n_paths; i++)
     {
         Spot to = GetToSpot(pg, i);
         if (to == s)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
        public List <Spot> GetPathsToSpots(PathGraph pg)
        {
            List <Spot> list = new List <Spot>(n_paths);

            for (int i = 0; i < n_paths; i++)
            {
                Spot spot = GetToSpot(pg, i);
                if (spot != null)
                {
                    list.Add(spot);
                }
            }
            return(list);
        }
Exemple #5
0
        public void RemovePathTo(float x, float y, float z)
        {
            // look for it
            int found_index = -1;

            for (int i = 0; i < n_paths && found_index == -1; i++)
            {
                int off = i * 3;
                if (paths[off] == x &&
                    paths[off + 1] == y &&
                    paths[off + 2] == z)
                {
                    found_index = i;
                }
            }
            if (found_index != -1)
            {
                PathGraph.Log("Remove path (" + found_index + ") to " + x + " " + y + " " + n_paths);
                for (int i = found_index; i < n_paths - 1; i++)
                {
                    int off = i * 3;
                    paths[off]     = paths[off + 3];
                    paths[off + 1] = paths[off + 4];
                    paths[off + 2] = paths[off + 5];
                }
                n_paths--;
                if (chunk != null)
                {
                    chunk.modified = true;
                }
            }
            else
            {
                PathGraph.Log("Found not path to remove (" + found_index + ") to " + x + " " + y + " ");
            }
        }
 private void Log(String s)
 {
     //PathGraph.Log(s);
     PathGraph.Log(s);
 }
        // Per spot:
        // uint32 magic
        // uint32 reserved;
        // uint32 flags;
        // float x;
        // float y;
        // float z;
        // uint32 no_paths
        //   for each path
        //     float x;
        //     float y;
        //     float z;


        public bool Load(string baseDir)
        {
            string fileName    = FileName();
            string filenamebin = baseDir + fileName;

            Stream       stream  = null;
            BinaryReader file    = null;
            int          n_spots = 0;
            int          n_steps = 0;

            try
            {
                stream = File.OpenRead(filenamebin);
                if (stream != null)
                {
                    file = new BinaryReader(stream);
                    if (file != null)
                    {
                        uint magic = file.ReadUInt32();
                        if (magic == FILE_MAGIC)
                        {
                            uint type;
                            while ((type = file.ReadUInt32()) != FILE_ENDMAGIC)
                            {
                                n_spots++;
                                uint  reserved = file.ReadUInt32();
                                uint  flags    = file.ReadUInt32();
                                float x        = file.ReadSingle();
                                float y        = file.ReadSingle();
                                float z        = file.ReadSingle();
                                uint  n_paths  = file.ReadUInt32();
                                var   s        = new Spot(x, y, z);
                                s.flags = flags;

                                for (uint i = 0; i < n_paths; i++)
                                {
                                    n_steps++;
                                    float sx = file.ReadSingle();
                                    float sy = file.ReadSingle();
                                    float sz = file.ReadSingle();
                                    s.AddPathTo(sx, sy, sz);
                                }
                                AddSpot(s);
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                PathGraph.Log(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                PathGraph.Log(e.Message);
            }

            if (file != null)
            {
                file.Close();
            }
            if (stream != null)
            {
                stream.Close();
            }


            Log("Loaded " + fileName + " " + n_spots + " spots " + n_steps + " steps");

            modified = false;
            return(false);
        }