Exemplo n.º 1
0
        private static bool precache(string name)
        {
            FOMapParser parser = new FOMapParser(Config.PresetsPath + @"\" + name);

            if (!parser.Parse())
            {
                return(false);
            }

            FOMap map = parser.Map;

            Preset p = new Preset();

            foreach (FOCommon.Maps.Tile tile in map.Tiles)
            {
                BigTile bt = p.GetBigTile(tile.X / (2 * (Config.BigTileEdgeSize + 1)),
                                          (tile.Y / (2 * (Config.BigTileEdgeSize + 1)) + 1), true);
                bt.AddTileClone(tile);
            }

            foreach (MapObject obj in map.Objects)
            {
                BigTile bt = p.GetBigTile(obj.MapX / (2 * (Config.BigTileEdgeSize + 1)),
                                          (obj.MapY / (2 * (Config.BigTileEdgeSize + 1)) + 1), true);
                bt.AddObjectClone(obj);
            }

            cache.Add(name, p);
            return(true);
        }
Exemplo n.º 2
0
        public static MapperMap Load(string fileName)
        {
            parser = new FOMapParser(fileName);
            if (parser.Parse())
            {
                instance = new MapperMap(parser.Map);
                return(instance);
            }

            return(null);
        }
Exemplo n.º 3
0
        private static MapHeaderCache ReadMapHeaderFile(string MapPath)
        {
            FOMapParser parser = new FOMapParser(MapPath);

            parser.Parse(true);

            MapHeaderCache hdc = new MapHeaderCache();

            hdc.Data             = parser.Map.Header;
            hdc.LastWriteTime    = File.GetLastWriteTime(MapPath);
            _mapHeaders[MapPath] = hdc;
            return(hdc);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compile the map instance.
        /// </summary>
        /// <param name="fileName">Output file name</param>
        /// <param name="header">Map header to be included</param>
        public void Compile(string fileName, MapHeader header)
        {
            FOCommon.Utils.Log("Compiling " + fileName + " using preset '" + Config.CurrentPreset + "'.");
            Preset p = PresetsManager.GetPreset(Config.CurrentPreset);

            if (p == null)
            {
                FOCommon.Utils.Log("Error: preset '" + Config.CurrentPreset + "' not found.");
                throw new CompilerException("internal: preset '" + Config.CurrentPreset + "' not found");
            }

            FOMap m = new FOMap();

            m.Header = header;

            header.MaxHexX  = (ushort)(2 * Config.BigTileEdgeSize * Width);
            header.MaxHexY  = (ushort)(2 * Config.BigTileEdgeSize * Height);
            header.Version  = 4;
            header.WorkHexX = (ushort)(header.MaxHexX / 2);
            header.WorkHexY = (ushort)(header.MaxHexY / 2);

            // tiles
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    compileTile(m, p, x, y);
                }
            }

            // scrollblockers
            if (scrollBlockers.Count > 3)
            {
                for (int i = 2; i < scrollBlockers.Count; i++)
                {
                    Pair <int, int> from = scrollBlockers[i - 1];
                    Pair <int, int> to   = scrollBlockers[i];
                    LineTracer.TraceHex(new ScrollblockersPlacer(from, to, this, m));
                }
                LineTracer.TraceHex(new ScrollblockersPlacer(scrollBlockers[scrollBlockers.Count - 1], scrollBlockers[1], this, m));
            }

            FOMapParser parser = new FOMapParser(fileName);

            parser.Map = m;
            parser.Save();
            FOCommon.Utils.Log("Compilation successful.");
        }