Example #1
0
		//----------------------------------------------------------------------
		// Actual XML load-out and node iteration
		//----------------------------------------------------------------------
		private static bool LoadXml()
		{
			XmlLinePreservingDocument xmlDoc = new XmlLinePreservingDocument( m_EncountersFile );

			try
			{
				xmlDoc.DoLoad();

				string language = "en-US";
				string skipHidden = "true";
				string picker = "sqrt";
				string delay = "60";
				string interval = "1800";
				string cleanup = "300";
				string cleanupgrace = "1";
				string debug = "false";
				string debugEffect = "false";
				string RTFM = "true";

				//------------------------------------------------------------------
				// Pull out initial information for configuration tags
				//------------------------------------------------------------------

				XmlNode root = xmlDoc["RandomEncounters"];

				try { language = root.Attributes["language"].Value; }
				catch { }
				try { skipHidden = root.Attributes["skiphidden"].Value; }
				catch { }
				try { picker = root.Attributes["picker"].Value; }
				catch { }
				try { delay = root.Attributes["delay"].Value; }
				catch { }
				try { interval = root.Attributes["interval"].Value; }
				catch { }
				try { cleanup = root.Attributes["cleanup"].Value; }
				catch { }
				try { cleanupgrace = root.Attributes["cleanupGrace"].Value; }
				catch { }
				try { debug = root.Attributes["debug"].Value; }
				catch { }
				try { debugEffect = root.Attributes["debugEffect"].Value; }
				catch { }
				try { RTFM = root.Attributes["RTFM"].Value; }
				catch { }

				m_Language = new CultureInfo( language );
				m_SkipHidden = bool.Parse( skipHidden );
				m_Picker = picker;
				m_Delay = float.Parse( delay, m_Language );
				m_Cleanup = float.Parse( cleanup, m_Language );
				m_CleanupGrace = int.Parse( cleanupgrace, m_Language );
				m_Debug = bool.Parse( debug );
				m_DebugEffect = bool.Parse( debugEffect );

				bool rtfm = bool.Parse( RTFM );

				if( !rtfm )
				{
					Console.WriteLine(
						"\n" +
						"##### RandomEncounters: SYSTEM CONFIG FILE FOUND, HOWEVER IT APPEARS THAT YOU DID NOT ACTUALLY READ IT!\n\n" +
						"                        RandomEncounters will **NOT** work if you have not read and edited the config file.\n" +
						"                        It is suggested that you do so now; the file can be found here:\n\n" +
						"                        \"{0}\"\n",
						m_EncountersFile
						);

					throw new Exception( "RTFM" );
				}

				//  Break out our intervals into our acceptible set; careful here, 
				//  changing this to return less than 3 intervals will break other code
				//  Dungeon Wilderness Guarded House Jail
				{
					string[] tokens = interval.Split( new Char[] { ':' } );

					int n = tokens.Length < 3 ? 3 : tokens.Length;

					m_Intervals = new float[n];

					if( tokens.Length == 5 )
					{
						m_Intervals[4] = float.Parse( tokens[4], m_Language ); // Jail
					}
					if( tokens.Length >= 4 )
					{
						m_Intervals[3] = float.Parse( tokens[3], m_Language ); // House
					}
					if( tokens.Length >= 3 )
					{
						m_Intervals[0] = float.Parse( tokens[0], m_Language ); // Guarded
						m_Intervals[1] = float.Parse( tokens[1], m_Language ); // Guarded
						m_Intervals[2] = float.Parse( tokens[2], m_Language ); // Guarded
					}

					if( tokens.Length == 2 )
					{
						m_Intervals[0] = float.Parse( tokens[0], m_Language ); // Dungeon
						m_Intervals[1] = float.Parse( tokens[1], m_Language ); // Wilderness
						m_Intervals[2] = float.Parse( tokens[1], m_Language ); // Guarded
					}

					if( tokens.Length == 1 )
					{
						m_Intervals[0] = float.Parse( tokens[0], m_Language ); // Dungeon
						m_Intervals[1] = float.Parse( tokens[0], m_Language ); // Wilderness
						m_Intervals[2] = float.Parse( tokens[0], m_Language ); // Guarded
					}

				}

				XmlNodeList facetNodes = xmlDoc.GetElementsByTagName( "Facet" );
				//------------------------------------------------------------------
				// Iterate over facets
				//------------------------------------------------------------------
				foreach( XmlNode facetNode in facetNodes )
				{
					string facetName = "";

					try { facetName = facetNode.Attributes["name"].Value; }
					catch
					{
						Console.WriteLine(
							"RandomEncounters: Facet at {1} had no name. THIS IS ILLEGAL. IGNORED ENTIRE FACET!",
							facetNode.Attributes["lineNumber"].Value
							);
						continue;
					}

					XmlNodeList regionNodes = facetNode.SelectNodes( "./Region" );
					if( regionNodes.Count == 0 ) Console.WriteLine(
						   "RandomEncounters: Facet \"{0}\" at {1} had no elements. IGNORED.",
						   facetName,
						   facetNode.Attributes["lineNumber"].Value
						   );
					//--------------------------------------------------------------
					// Now over regions
					//--------------------------------------------------------------
					foreach( XmlNode regionNode in regionNodes )
					{
						string regionType = "Wilderness";
						string regionName = "default";
						string failed = "";

						try { regionType = regionNode.Attributes["type"].Value; }
						catch { failed = "type"; }
						try { regionName = regionNode.Attributes["name"].Value; }
						catch { ; }

						if( failed != "" )
						{
							Console.WriteLine( "Attempted to add an element without a {0} at {1}. IGNORING.",
								failed,
								regionNode.Attributes["lineNumber"].Value
								);
							return false;
						}


						XmlNodeList encounterNodes = regionNode.SelectNodes( "./Encounter" );
						if( encounterNodes.Count == 0 ) Console.WriteLine(
							   "RandomEncounters: {0} Region \"{1}\" at {2} had no elements. IGNORED.",
							   regionType,
							   regionName,
							   regionNode.Attributes["lineNumber"].Value
							   );

						//------------------------------------------------------
						// Now over encounters
						//------------------------------------------------------
						foreach( XmlNode encounterNode in encounterNodes )
						{
							string encounterProbability = "1.0";
							string encounterDistance = "7";
							string encounterLand = "AnyLand";
							string encounterTime = "AnyTime";
							string encounterWater = "false";
							string encounterLevel = "1";
							string encounterScale = "false";

							try { encounterDistance = encounterNode.Attributes["distance"].Value; }
							catch { }
							try { encounterProbability = encounterNode.Attributes["p"].Value; }
							catch { }
							try { encounterLand = encounterNode.Attributes["landType"].Value; }
							catch { }
							try { encounterWater = encounterNode.Attributes["water"].Value; }
							catch { }
							try { encounterTime = encounterNode.Attributes["time"].Value; }
							catch { }
							try { encounterLevel = encounterNode.Attributes["level"].Value; }
							catch { }
							try { encounterScale = encounterNode.Attributes["scaleUp"].Value; }
							catch { }

							if( bool.Parse( encounterWater ) == true )
							{
								if( m_Debug ) Console.WriteLine(
									 "RandomEncounters, WARNING: \"water\" tag is deprecated; use landType=\"Water\" instead"
									 );
								encounterLand = "Water";
							}

							string[] distance_tok = encounterDistance.Split( new Char[] { ':' } ); // splits to shortest:farthest, or just distance if no ':'

							string[] level_tok = encounterLevel.Split( new Char[] { ':' } );

							RandomEncounter randomEncounter = new RandomEncounter(
									encounterNode,
									facetName,
									regionType,
									regionName,
									encounterProbability,
									distance_tok[0],
									(distance_tok.Length > 1 ? distance_tok[1] : distance_tok[0]),
									encounterLand,
									encounterTime,
									level_tok[0],
									(level_tok.Length > 1 ? level_tok[1] : "Overall"),
									encounterScale
									);

							XmlNodeList elementNodes = encounterNode.SelectNodes( "Mobile | Item " );

							if( elementNodes.Count == 0 ) Console.WriteLine(
								   "RandomEncounters: Encounter on line {0} had no children. IGNORED.",
								   encounterNode.Attributes["lineNumber"].Value
								   );

							//----------------------------------------------
							// Now iterate over subelements
							//----------------------------------------------
							foreach( XmlNode elementNode in elementNodes )
								AddRecursiveMobilesAndItems(
									encounterNode,
									elementNode,
									randomEncounter
									);

							//------------------------------------------
							// Now they we've built it up, process it:
							//------------------------------------------
							ProcessNewEncounter( randomEncounter );
						}
					}
				}
				return true;
			}
			catch( Exception e )
			{
				Console.WriteLine( "RandomEncounters: Exception caught attempting to load file: " + m_EncountersFile );
				Console.WriteLine( "{0}", e );
				xmlDoc.Close();
				return false;
			}
		}
Example #2
0
        //----------------------------------------------------------------------
        // Actual XML load-out and node iteration
        //----------------------------------------------------------------------
        private bool LoadXml()
        {
            XmlLinePreservingDocument     xmlDoc      = new XmlLinePreservingDocument( m_ConfigFile );

            try
            {
            xmlDoc.DoLoad();

            string          rtfm                = "true";
            string          on                  = "false";
            string          facetsOn            = "Felucca";
            string          mobiles             = "true";
            string          items               = "true";
            string          losForMobs          = "true";
            string          symmetric           = "false";
            string          highWalls           = "true";
            string          squelchNames        = "-1";
            string          edgeRange           = "1";
            string          windowRange         = "1";
            string          treeRange           = "1";
            string          cacheRatio          = "100";
            string          backingStore        = "true";

            XmlNode         root                = xmlDoc["LOS"];

            try { rtfm                          = root.Attributes[ "RTFM" ].Value; } catch {}
            try { on                            = root.Attributes[ "on" ].Value; } catch {}
            try { facetsOn                      = root.Attributes[ "facets" ].Value; } catch {}
            try { mobiles                       = root.Attributes[ "mobiles" ].Value; } catch {}
            try { items                         = root.Attributes[ "items" ].Value; } catch {}
            try { losForMobs                    = root.Attributes[ "losForMobs" ].Value; } catch {}
            try { symmetric                     = root.Attributes[ "symmetric" ].Value; } catch {}
            try { highWalls                     = root.Attributes[ "highWalls" ].Value; } catch {}
            try { squelchNames                  = root.Attributes[ "squelchNames" ].Value; } catch {}
            try { edgeRange                     = root.Attributes[ "edgeRange" ].Value; } catch {}
            try { windowRange                   = root.Attributes[ "windowRange" ].Value; } catch {}
            try { treeRange                     = root.Attributes[ "treeRange" ].Value; } catch {}
            try { cacheRatio                    = root.Attributes[ "cacheRatio" ].Value; } catch {}
            try { backingStore                  = root.Attributes[ "backingStore" ].Value; } catch {}

            m_RTFM                              = bool.Parse( rtfm );
            m_On                                = bool.Parse( on );
            m_Mobiles                           = bool.Parse( mobiles );
            m_Items                             = bool.Parse( items );
            m_LosForMobs                        = bool.Parse( losForMobs );
            m_Symmetric                         = bool.Parse( symmetric );
            m_HighWalls                         = bool.Parse( highWalls );
            m_SquelchNames                      = int.Parse( squelchNames );
            m_EdgeRange                         = int.Parse( edgeRange );
            m_WindowRange                       = int.Parse( windowRange );
            m_TreeRange                         = int.Parse( treeRange );
            m_CacheRatio                        = int.Parse( cacheRatio );
            m_BackingStore                      = bool.Parse( backingStore );

            string[] facets = facetsOn.Split(new Char[]{','});

            foreach( string facet in facets )
            {
                m_FacetsOn.Add( facet, facet );
            }

            //--------------------------------------------------------------
            // Load various tile sets
            //--------------------------------------------------------------

            LoadTileList( root, "NotLossed", NumberStyles.HexNumber, m_NotLossed );
            LoadTileList( root, "WhiteList", NumberStyles.HexNumber, m_WhiteListed );
            LoadTileList( root, "BlackList", NumberStyles.HexNumber, m_BlackListed );
            LoadTileList( root, "Trees",     NumberStyles.HexNumber, m_Trees );
            LoadTileList( root, "Mountains", NumberStyles.None,      m_Mountains );

            LoadWarmups( root );

            return true;
            }
            catch (Exception e)
            {
            Console.WriteLine("LOS: Exception encountered attempting to load file: " + m_ConfigFile);
            Console.WriteLine("{0}", e);
            xmlDoc.Close();
            return false;
            }
        }