예제 #1
0
        internal Line(MetaLine AMetaLine, string ID, string MeasureID, MeasureShowMode Mode, int FHierID)
        {
            fM         = AMetaLine;
            fID        = ID;
            fMeasureID = MeasureID;
            fMode      = Mode;
            fHierId    = FHierID;
            fDepthes   = new List <int>(AMetaLine.fHierArray.Count);
            for (var i = 0; i < AMetaLine.fHierArray.Count; i++)
            {
                fDepthes.Add(0);
            }
            var a = FHierID;

            for (var i = AMetaLine.fLevels.Count - 1; i > 0; i--)
            {
                fDepthes[i] = a / AMetaLine.fHierArray[i];
                a           = a % AMetaLine.fHierArray[i];
            }
            if (AMetaLine.fLevels.Count > 0)
            {
                fDepthes[0] = a;
            }
            //fM.FGrid.FEngine.RetrieveLine(this, Address);
        }
예제 #2
0
 public static void AddToList(List <Coord> list, MetaLine line)
 {
     if (line.count == 0)
     {
         return;
     }
     if (line.count >= 1)
     {
         list.Add(line.c0);
     }
     if (line.count >= 2)
     {
         list.Add(line.c1);
     }
     if (line.count >= 3)
     {
         list.Add(line.c2);
     }
     if (line.count == 4)
     {
         list.Add(line.c3);
     }
     if (line.closed)
     {
         list.Add(line.c0);
     }
 }
예제 #3
0
 internal void ClearIncludedMetalines(Level Level)
 {
     for (var i = FMetaLines.Count - 1; i >= 0; i--)
     {
         var IsDelete = false;
         foreach (var l in FMetaLines.Values[i].fLevels)
         {
             if (l == Level)
             {
                 IsDelete = true;
                 break;
             }
         }
         if (IsDelete)
         {
             var ml = FMetaLines.Values[i];
             if (ml == cache_ml)
             {
                 cache_ml      = null;
                 cache_indexes = null;
             }
             FMetaLines.RemoveAt(i);
         }
     }
 }
예제 #4
0
        void IStreamedObject.ReadStream(BinaryReader reader, object options)
        {
            fM = (MetaLine)options;
            StreamUtils.CheckTag(reader, Tags.tgLine);
            for (var exit = false; !exit;)
            {
                int c;
                var tag = StreamUtils.ReadTag(reader);
                switch (tag)
                {
                case Tags.tgLine_CacheKey:
                    fCacheKey = StreamUtils.ReadString(reader);
                    break;

                case Tags.tgLine_Depthes:
                    c        = StreamUtils.ReadInt32(reader);
                    fDepthes = new List <int>(c);
                    for (var i = 0; i < c; i++)
                    {
                        fDepthes.Add(StreamUtils.ReadInt32(reader));
                    }
                    break;

                case Tags.tgLine_ID:
                    fID = StreamUtils.ReadString(reader);
                    break;

                case Tags.tgLine_HierID:
                    fHierId = StreamUtils.ReadInt32(reader);
                    break;

                case Tags.tgLine_Measure:
                    fMeasureID = StreamUtils.ReadString(reader);
                    break;

                case Tags.tgLine_Mode:
                    fMode = Measure.ShowModes.ShowModeById(StreamUtils.ReadGuid(reader));
                    break;

                case Tags.tgLine_CurrentMap:
                    StreamUtils.ReadStreamedObject(reader, CurrentMap, fM.FGrid);
                    break;

                case Tags.tgLine_EOT:
                    exit = true;
                    break;

                default:
                    DoReadStream(reader, tag);
                    break;
                }
            }
        }
예제 #5
0
 /// <summary>Clears all the already aggregated data</summary>
 public void Clear()
 {
     for (var i = FMetaLines.Count - 1; i >= 0; i--)
     {
         var ml = FMetaLines.Values[i];
         if (ml == cache_ml)
         {
             cache_ml      = null;
             cache_indexes = null;
         }
         ml.Clear();
         ml.FGrid = null;
         FMetaLines.RemoveAt(i);
     }
 }
예제 #6
0
        internal virtual void SetActive(bool Value)
        {
            DebugLogging.WriteLine("Engine.SetActive(Value={0})", Value);

            if (FGrid != null)
            {
                FGrid.SetActive(Value);
            }
            if (!Value)
            {
                foreach (var ml in FMetaLines.Values)
                {
                    ml.Clear();
                }
                FMetaLines.Clear();
                cache_indexes = null;
                cache_ml      = null;
                FLevelsList.Clear();
            }
        }
예제 #7
0
        internal MetaLine GetMetaline(IList <int> LevelIndexes)
        {
            if (cache_indexes != null && cache_indexes.Length == LevelIndexes.Count &&
                cache_ml != null)
            {
                var b = true;
                for (var i = 0; i < LevelIndexes.Count; i++)
                {
                    if (LevelIndexes[i] != cache_indexes[i])
                    {
                        b = false;
                        break;
                    }
                }
                if (b)
                {
                    return(cache_ml);
                }
            }
            cache_indexes = new int[LevelIndexes.Count];
            LevelIndexes.CopyTo(cache_indexes, 0);

            var key = RadarUtils.Join('.', LevelIndexes);

            MetaLine M;

            FMetaLines.TryGetValue(key, out M);
            if (M != null)
            {
                cache_ml = M;
                return(M);
            }
            M = CreateMetaline(FGrid, LevelIndexes);
            FMetaLines.Add(key, M);
            cache_ml = M;
            return(M);
        }
예제 #8
0
        public static List <List <Coord> > WeldMetaLines(List <MetaLine> metaLines)
        {
            //metaLines start coord lut
            Dictionary <Coord, int> startLut = new Dictionary <Coord, int>(capacity: metaLines.Count);
            int metaLinesCount = metaLines.Count;

            for (int i = 0; i < metaLinesCount; i++)
            {
                startLut.Add(metaLines[i].c0, i);
            }

            //meta lines with the start coordinate that is not covered with other metaline end coordinate
            //they will begin a new line
            Stack <Coord> initialCoords = new Stack <Coord>();

            HashSet <Coord> endCoords = new HashSet <Coord>();

            for (int i = 0; i < metaLinesCount; i++)
            {
                endCoords.Add(metaLines[i].Last);
            }

            for (int i = 0; i < metaLinesCount; i++)
            {
                if (!endCoords.Contains(metaLines[i].c0))
                {
                    initialCoords.Push(metaLines[i].c0);
                }
            }

            //welded lines
            List <List <Coord> > weldedLines = new List <List <Coord> >();
            List <Coord>         currentLine = new List <Coord>();

            //welding
            while (startLut.Count != 0)
            {
                //finding first point to weld
                Coord start;
                if (initialCoords.Count != 0)
                {
                    start = initialCoords.Pop();
                }
                else
                {
                    start = startLut.AnyKey();                             //if no initial coords left - then only looped lines remain - and then starting anywhere
                }
                for (int i = 0; i < metaLinesCount + 2; i++)               //should not reach maximum
                {
                    if (startLut.TryGetValue(start, out int num))          //if has continuation
                    {
                        MetaLine.AddToList(currentLine, metaLines[num]);
                        startLut.Remove(start);
                        start = metaLines[num].Last;
                        continue;
                    }

                    else                             //finishing line
                    {
                        weldedLines.Add(currentLine);
                        currentLine = new List <Coord>();
                        break;
                    }

                    throw new Exception("Welding reached maximum");
                }
            }

            return(weldedLines);
        }
예제 #9
0
        private void LoadMap()
        {
            Console.Clear();
            Console.WriteLine("LoadMap() -- WIC Map Engine\nFileName: " + Global.MapEditor_CurrentMapName + "\nCurrent Operation:");

            MapTiles.Clear();
            MapObjects.Clear();
            MapBackground.Clear();

            try
            {
                string[] MapFileRead = File.ReadAllText(Global.MAP_SourceFolder + "/" + Global.MapEditor_CurrentMapName + ".map").Split('|');
                string[] MapBGData   = MapFileRead[0].Split(new[] { '\r', '\n' });
                string[] MapTileData = MapFileRead[1].Split(new[] { '\r', '\n' });
                string[] MapObjData  = MapFileRead[2].Split(new[] { '\r', '\n' });
                string[] MapMetaData = MapFileRead[3].Split(';');


                foreach (var tile in MapBGData)
                {
                    if (tile.Length < 2)
                    {
                        continue;
                    }


                    // Split Line arguments
                    string[] LineArgs       = tile.Split(';');
                    int      TileX          = Convert.ToInt32(LineArgs[0]);
                    int      TileY          = Convert.ToInt32(LineArgs[1]);
                    string[] TileProperties = LineArgs[2].Split(',');

                    MapTile ThisTile = new MapTile(TileX, TileY, TileProperties, MapBackground.Count);

                    MapBackground.Add(ThisTile);
                }

                foreach (var tile in MapTileData)
                {
                    if (tile.Length < 2)
                    {
                        continue;
                    }
                    // Split Line arguments
                    string[] LineArgs       = tile.Split(';');
                    int      TileX          = Convert.ToInt32(LineArgs[0]);
                    int      TileY          = Convert.ToInt32(LineArgs[1]);
                    string[] TileProperties = LineArgs[2].Split(',');

                    MapTile ThisTile = new MapTile(TileX, TileY, TileProperties, MapTiles.Count);

                    MapTiles.Add(ThisTile);
                }

                foreach (var tile in MapObjData)
                {
                    if (tile.Length < 2)
                    {
                        continue;
                    }

                    // Split Line arguments
                    string[] LineArgs       = tile.Split(';');
                    int      TileX          = Convert.ToInt32(LineArgs[0]);
                    int      TileY          = Convert.ToInt32(LineArgs[1]);
                    string[] TileProperties = LineArgs[2].Split(',');

                    MapTile ThisTile = new MapTile(TileX, TileY, TileProperties, MapObjects.Count);

                    MapObjects.Add(ThisTile);
                }

                List <string> LinesWitoutIt = new List <string>();
                CustomMapProperty = "";
                foreach (var MetaLine in MapMetaData)
                {
                    string[] SplitedArgs = MetaLine.Split(':');

                    switch (SplitedArgs[0])
                    {
                    case "width":
                        MapWidth = Convert.ToInt32(SplitedArgs[1]);
                        break;

                    case "height":
                        MapHeight = Convert.ToInt32(SplitedArgs[1]);
                        break;

                    default:
                        try
                        {
                            LinesWitoutIt.Add(SplitedArgs[0] + ":" + SplitedArgs[1]);
                        }
                        catch (IndexOutOfRangeException)
                        {
                        }
                        break;
                    }
                }
                foreach (var CustomProp in LinesWitoutIt)
                {
                    if (CustomProp.Contains("end"))
                    {
                        break;
                    }
                    CustomMapProperty += CustomProp + ";";
                }

                System.Console.WriteLine(CustomMapProperty);
                Console.WriteLine("Operation Completed.");
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Error while loading Mapfile: [" + Global.MapEditor_CurrentMapName + "]\nInvalid map file.");

                DialogMessage(Registry.ReadKeyValue("/editor/map_load_error_1"));
            }

            catch (FileNotFoundException)
            {
                Console.WriteLine("Error while loading Mapfile: [" + Global.MapEditor_CurrentMapName + "]\nCannot find map file.");

                DialogMessage(Registry.ReadKeyValue("/editor/map_load_error_2"));
            }

            MapHasBeenLoaded = true;
        }
예제 #10
0
        public override void Initialize()
        {
            string pMapFileToLoad;

            Taiyou.Global.Reload();
            CurrentPlayer = null;

            if (!Global.ForceReloadMap)
            {
                pMapFileToLoad = Registry.ReadKeyValue("/defaultMap");
            }
            else
            {
                pMapFileToLoad = Global.CurrentMapName;
            }

            // Check if MapFile Exists
            if (!File.Exists(pMapFileToLoad))
            {
                MapLoadingError = true; Console.WriteLine("Cannot find Map file {" + pMapFileToLoad + "}."); return;
            }
            MapLoadingError = false;


            try
            {
                string[] MapFileRead       = File.ReadAllText(pMapFileToLoad).Split('|');
                string[] MapBackgroundFile = MapFileRead[0].Split(new[] { '\r', '\n' });
                string[] MapDataFile       = MapFileRead[1].Split(new[] { '\r', '\n' });
                string[] MapObjFile        = MapFileRead[2].Split(new[] { '\r', '\n' });
                string[] MapMetadataFile   = MapFileRead[3].Split(';');

                foreach (var MetaLine in MapMetadataFile)
                {
                    try
                    {
                        string[] SplitedArgs = MetaLine.Split(':');

                        if (SplitedArgs[0] == "width")
                        {
                            MapWidth = Convert.ToInt32(SplitedArgs[1]);
                        }

                        if (SplitedArgs[0] == "height")
                        {
                            MapHeight = Convert.ToInt32(SplitedArgs[1]);
                        }

                        if (SplitedArgs[0] == "world_ilumination")
                        {
                            WorldIlumination = Convert.ToInt32(SplitedArgs[1]);
                        }


                        if (SplitedArgs[0] == "end")
                        {
                            break;
                        }

                        MapProperties.Add(SplitedArgs[0]);
                        MapPropertiesValues.Add(SplitedArgs[1]);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        Console.WriteLine("Invalid data in Metadata");
                    }
                }


                MapView = new MapRenderer(MapDataFile, MapBackgroundFile);
                ReloadObjMap(MapObjFile);


                Global.ForceReloadMap = false;
            }
            catch (IndexOutOfRangeException)
            {
                MapLoadingError = true;
                Console.WriteLine("Error while loading MapFile [" + pMapFileToLoad + "].\nMap is invalid.");
            }

            Global.CurrentMapName = pMapFileToLoad;

            Initialized = true;
            base.Initialize();
        }