/***********************************************************************************************
         * GeneratePaths / 2014-08-01 / Wethospu                                                       *
         *                                                                                             *
         * Generates paths and their encounters for one dungeon.                                       *
         *                                                                                             *
         * Returns information about generated paths.                                                  *
         * dungeon: Paths will be generated for this dungeon.                                          *
         * enemies: List of enemies. Needed for enemy links.                                           *
         *                                                                                             *
         ***********************************************************************************************/
        public static EncounterData GeneratePaths(string dungeon, List<Enemy> enemies)
        {
            var rawDataLocation = Constants.DataEncounterRaw + dungeon + ".txt";
              string[] lines;
              if (File.Exists(rawDataLocation))
            lines = File.ReadAllLines(rawDataLocation, Constants.Encoding);
              else
              {
            Helper.ShowWarningMessage("File " + rawDataLocation + " doesn't exist!");
            return null;
              }
              var encounterData = new EncounterData();
              var currentEncounter = new Encounter();
              Helper.CurrentFile = rawDataLocation;
              for (var row = 0; row < lines.Length; row++)
              {
            Helper.InitializeWarningSystem(row + 1, lines[row]);
            HandleLine(lines[row], ref currentEncounter, encounterData.Encounters, encounterData.Paths);
              }
              if (!currentEncounter.Name.Equals(""))
            encounterData.Encounters.Add(currentEncounter);

              Helper.InitializeWarningSystem(-1, "");

              if (encounterData.Paths.Count == 0)
            encounterData.Paths.Add(new PathData(dungeon));
              // Set up unique indexes. These are used for tactics (tab system). / 2015-08-11 / Wethospu
              for (var i = 0; i < encounterData.Encounters.Count; i++)
            encounterData.Encounters[i].Index = i + Constants.UniqueIndexCounter;
              Constants.UniqueIndexCounter += encounterData.Encounters.Count;
              return encounterData;
        }
 /// <summary>
 /// Adds a line to encounter's active tactics.
 /// </summary>
 private static void HandleNormalLine(string data, Encounter encounter, List<PathData> paths)
 {
     // Preprocess the line to avoid doing same stuff 25+ times.
       data = LinkGenerator.CheckLinkSyntax(data);
       if (encounter.Tactics.Count == 0)
     encounter.Tactics.AddTactics("normal", "", paths);
       encounter.Tactics.AddLine(data);
 }
        private static void HandleLine(string line, ref Encounter currentEncounter, List<Encounter> encounters,  List<PathData> paths)
        {
            // Empty line or comment: continue
              if (line == "" || line[0] == '#')
            return;
              if (string.IsNullOrWhiteSpace(line))
              {
            Helper.ShowWarning("Line contains only whitespace (ignored). Please remove!");
            return;
              }
              // Check for weird characters but allow "|" to skip next line.
              if (!char.IsLetterOrDigit(line[0]) && line[0] != '|' && line[0] != '~')
              {
            Helper.ShowWarning("Line starts with a weird character. Please remove!");
            return;
              }
              if (line[0] == ' ')
            Helper.ShowWarning("Extra space detected. Please remove!");

              //// Split row to tag and data.
              var tagIndex = line.IndexOf(Constants.TagSeparator);
              // No data found. This will be handled later when tag has been analyzed.
              if (tagIndex < 0)
            tagIndex = line.Length - 1;
              var tag = line.Substring(0, tagIndex);
              tag = tag.ToLower();
              var data = "";
              if (tagIndex < line.Length)
            data = line.Substring(tagIndex + 1);
              //// Tag and data separated.

              if (tag.Equals("init"))
              {
            paths.Add(new PathData(line));
              }
              else if (tag.Equals("path"))
              {
            if (data.Length > 0)
            {
              if (data.Contains(" "))
              {
            Helper.ShowWarning("' ' found. Use syntax \"path='path1'|'path2'|'pathN'\"");
            data = data.Replace(' ', '|');
              }
              _currentPath = data.ToLower();
            }
            else
              Helper.ShowWarning("Missing info. Use \"path='path1'|'path2'|'pathN'\"!");
              }
              else if (tag.Equals("name"))
              {
            if (data.Length > 0)
            {
              data = LinkGenerator.CheckLinkSyntax(data);
              if (!currentEncounter.Name.Equals(""))
              {
            encounters.Add(currentEncounter);
            currentEncounter = new Encounter();
              }
              currentEncounter.Name = data;
              currentEncounter.Path = _currentPath;
            }
            else
              Helper.ShowWarning("Missing info. Use \"name='name'\"!");
              }
              else if (tag.Equals("image"))
              {
            if (data.Length > 0)
            {
              currentEncounter.Medias.Add(new Media(data));
            }
            else
              Helper.ShowWarning("Missing info. Use \"image='image'\"!");
              }
              else if (tag.Equals("tactic"))
              {
            if (data.Length > 0)
              currentEncounter.Tactics.AddTactics(data);
            else
              Helper.ShowWarning("Missing info. Use \"tactic='tactic1'|'tactic2'|'tacticN'\"!");
              }
              // Normal content.
              else
              {
            // Preprocess the line to avoid doing same stuff 25+ times.
            line = LinkGenerator.CreatePageLinks(LinkGenerator.CheckLinkSyntax(line));
            if (currentEncounter.Tactics.Count == 0)
              currentEncounter.Tactics.AddTactics("normal");
            currentEncounter.Tactics.AddLine(line);
              }
        }