Пример #1
0
        /// <summary>
        /// get the trade classifications
        /// </summary>
        /// <param name="filename">string - filename of trade class file to use</param>
        /// <remarks>loads the trade class</remarks>
        private void setTradeClasses(string prefix)
        {
            this.tradeclass = new ArrayList();              // create a valid array list

            StreamReader rd = new StreamReader("Assets/" + prefix + "TradeCodes.txt");
            string line = "";

            while ((line = rd.ReadLine()) != null)
            {
                if (line.StartsWith("#"))
                    continue;                   // notes
                if (line.StartsWith(" "))
                    continue;                   // comment or white space
                if (line.Length < 12)
                    continue;

                stTrade tc = new stTrade();
                tc.code = line.Substring(0, 2); // code
                string[] ln = line.Split(new char[] { ',' });
                tc.desc = ln[0].Substring(3);
                tc.size = ln[1];
                tc.atm = ln[2];
                tc.hyd = ln[3];
                tc.pop = ln[4];
                tc.gov = ln[5];
                tc.law = ln[6];
                tc.TL = ln[7];
                try
                {
                    tc.buymod = Convert.ToInt32(ln[8]);
                }
                catch
                {
                    tc.buymod = 0;
                }

                // and see if the parameters match
                TravUtils util = new TravUtils();
                if ((tc.size.Contains(util.convertToHex(this.size)) | tc.size == "-") &
                    (tc.atm.Contains(util.convertToHex(this.atmo)) | tc.atm == "-") &
                    (tc.hyd.Contains(util.convertToHex(this.hydro)) | tc.hyd == "-") &
                    (tc.pop.Contains(util.convertToHex(this.pop)) | tc.pop == "-") &
                    (tc.gov.Contains(util.convertToHex(this.gov)) | tc.gov == "-") &
                    (tc.law.Contains(util.convertToHex(this.law)) | tc.law == "-") &
                    (tc.TL.Contains(util.convertToHex(this.tech)) | tc.TL == "-"))
                {
                    this.tradeclass.Add(tc);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// get a list of systems within jump range
        /// </summary>
        /// <param name="filename">string - file we are using as our source</param>
        /// <param name="jump">int - jump range</param>
        /// <returns>List - a list of SEC strings in jump range</returns>
        public List<string> jumpRange(string filename, int jump)
        {
            List<string> range = new List<string>();
            string[] systems = File.ReadAllLines("Assets/" + filename);

            // figure the max/min ranges for our hex positions
            // 1st two are horizontal, 2nd pair vertical
            int origH = Convert.ToInt32(this.hex.Substring(0, 2));
            int origV = Convert.ToInt32(this.hex.Substring(2, 2));

            int maxV = origV + jump;        // jump distance down from origin
            int minV = origV - jump;        // jump distance up from origin
            if (minV < 0)
                minV = 0;                   // can't go off the top
            int maxH = origH + jump;        // jump distance to the right
            int minH = origH - jump;        // jump distance to the left
            if (minH < 0)
                minH = 0;                   // can't go off the left side

            Traveller.TravUtils util = new TravUtils();

            // now we have our box - find all systems inside that range
            foreach (string sec in systems)
            {
                if (isValidSEC(sec))
                {
                    Match worldMatch = worldRegex.Match(sec);
                    string hex = worldMatch.Groups["hex"].Value;
                    int h = Convert.ToInt32(hex.Substring(0, 2));
                    int v = Convert.ToInt32(hex.Substring(2, 2));
                    if (h >= minH & h <= maxH & v >= minV & v <= maxV)
                    {
                        int distance = util.calcDistance(hex, this.hex);
                        if (distance <= jump)
                            range.Add(sec);
                    }
                }
            }

            return range;
        }