Exemple #1
0
        // Connect according to MPQ data
        public Spot AddAndConnectSpot(Spot s)
        {
            s = AddSpot(s);
            List <Spot> close = FindAllSpots(s.location, MaxStepLength);

            if (!s.IsFlagSet(Spot.FLAG_MPQ_MAPPED))
            {
                foreach (Spot cs in close)
                {
                    if (cs.HasPathTo(this, s) && s.HasPathTo(this, cs) || cs.IsBlocked())
                    {
                    }
                    else if (!triangleWorld.IsStepBlocked(s.X, s.Y, s.Z, cs.X, cs.Y, cs.Z, toonHeight, toonSize, null))
                    {
                        float mid_x = (s.X + cs.X) / 2;
                        float mid_y = (s.Y + cs.Y) / 2;
                        float mid_z = (s.Z + cs.Z) / 2;
                        float stand_z;
                        int   flags;
                        if (triangleWorld.FindStandableAt(mid_x, mid_y, mid_z - WantedStepLength * .75f, mid_z + WantedStepLength * .75f, out stand_z, out flags, toonHeight, toonSize))
                        {
                            s.AddPathTo(cs);
                            cs.AddPathTo(s);
                        }
                    }
                }
            }
            return(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;

            System.IO.Stream       stream = null;
            System.IO.BinaryReader file   = null;
            int n_spots = 0;
            int n_steps = 0;

            try
            {
                stream = System.IO.File.OpenRead(filenamebin);
                if (stream != null)
                {
                    file = new System.IO.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();
                                if (x != 0 && y != 0)
                                {
                                    Spot 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 (System.IO.FileNotFoundException e)
            {
                logger.Debug(e.Message);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                logger.Debug(e.Message);
            }
            catch (Exception e)
            {
                logger.Debug(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);
        }