Ejemplo n.º 1
0
		public static RuleSet Parse( string filename, string name )
		{
			m_ruleset = new RuleSet();
			m_ruleset.Name = name;

			if( !File.Exists( filename ) )
			{
				m_ruleset.Errors.Add( string.Format( "File not found: {0}", filename ) );
				return m_ruleset;
			}

			using( FileStream fs = new FileStream( filename, FileMode.Open ) )
			{
				try
				{
					ParadoxParser.Parse( fs, ParseRule );
					m_ruleset.LawRules.ParentRuleSet = m_ruleset;
				} catch( Exception ex )
				{
					m_ruleset.Errors.Add( ex.ToString() );
				}
			}

			return m_ruleset;
		}
Ejemplo n.º 2
0
		private bool LoadRulesets()
		{
			m_rules = new RuleSet();

			m_log.Log( "Loading Rule Sets", Logger.LogType.Data );
			var rules = cbRuleList.CheckedItems;
			RuleSet rs;
			List<RuleSet> ruleSets = new List<RuleSet>();
			foreach( string s in rules )
			{
				rs = RuleSet.Parse( m_ruleSets[s].FullName, s );

				if( rs.Errors.Count > 0 )
				{
					m_rules = rs;
					return false;
				}

				ruleSets.Add( rs );
			}

			m_log.Log( "Loaded " + ruleSets.Count + " Rule Sets", Logger.LogType.Data );

			#region Check Rule Sets Have Loaded Required Rules.
			bool hasAllLoaded = true;
			List<string> reqList = new List<string>();
			foreach( RuleSet r in ruleSets )
			{
				foreach( string requiredRule in r.RequiredRules )
				{
					if( !rules.Contains( requiredRule ) )
					{
						hasAllLoaded = false;
						reqList.Add( requiredRule );
					}
				}
			}

			if( !hasAllLoaded )
			{
				StringBuilder errorSb = new StringBuilder();
				errorSb.AppendLine( "One or more selected rule sets have requirements that are not checked." );
				errorSb.AppendLine().AppendLine();
				reqList.ForEach( s => errorSb.AppendLine( s ) );
				errorSb.AppendLine();
				errorSb.Append( "Please check the required rule sets." );

				m_log.Log( errorSb.ToString(), Logger.LogType.Data );
				ShowError( errorSb.ToString(), "Rule Sets Required." );
				return false;
			}
			#endregion

			#region Sort Rule Sets
			if( ruleSets.Count > 1 )
			{
				for( int i = 1; i < ruleSets.Count; i++ )
				{
					for( int j = 0; j < i; j++ )
					{
						RuleSet curr = ruleSets[j];
						RuleSet next = ruleSets[i];
						if( curr.RequiredRules.Contains( next.Name ) && next.RequiredRules.Count != 0 )
							continue;

						ruleSets[j] = next;
						ruleSets[i] = curr;
					}
				}
			}
			#endregion

			m_log.Log( "Combining Rule Sets", Logger.LogType.Data );
			#region Combining
			foreach( RuleSet rule in ruleSets )
			{
				foreach( CharacterRule cr in rule.CharRules )
					if( !m_rules.CharRules.Contains( cr ) )
						m_rules.CharRules.Add( cr );

				foreach( string s in rule.IgnoredTitles )
					if( !m_rules.IgnoredTitles.Contains( s ) )
						m_rules.IgnoredTitles.Add( s );

				foreach( string s in rule.FemaleCultures )
					if( !m_rules.FemaleCultures.Contains( s ) )
						m_rules.FemaleCultures.Add( s );

				foreach( string s in rule.FemaleReligions )
					if( !m_rules.FemaleReligions.Contains( s ) )
						m_rules.FemaleReligions.Add( s );

				foreach( string s in rule.MaleCultures )
					if( !m_rules.MaleCultures.Contains( s ) )
						m_rules.MaleCultures.Add( s );

				foreach( string s in rule.MaleReligions )
					if( !m_rules.MaleReligions.Contains( s ) )
						m_rules.MaleReligions.Add( s );

				foreach( string s in rule.MuslimLawFollowers )
					if( !m_rules.MuslimLawFollowers.Contains( s ) )
						m_rules.MuslimLawFollowers.Add( s );

				foreach( Law l in rule.LawRules.GenderLaws )
					if( !m_rules.LawRules.GenderLaws.Contains( l ) )
						m_rules.LawRules.GenderLaws.Add( l );

				foreach( Law l in rule.LawRules.SuccessionLaws )
					if( !m_rules.LawRules.SuccessionLaws.Contains( l ) )
						m_rules.LawRules.SuccessionLaws.Add( l );

				if( rule.LawRules.LevyTax.Min != 0
				  && rule.LawRules.LevyTax.Normal != 0
				  && rule.LawRules.LevyTax.Large != 0
				  && rule.LawRules.LevyTax.Max != 0 )
				{
					m_rules.LawRules.LevyTax = rule.LawRules.LevyTax;
					m_rules.LawRules.ParentRuleSet = m_rules;
				}

				if( rule.LiegeCultureChance != -1 )
					m_rules.LiegeCultureChance = rule.LiegeCultureChance;
				if( rule.LiegeReligionChance != -1 )
					m_rules.LiegeReligionChance = rule.LiegeReligionChance;
				if( rule.FemaleRulerChance != -1 )
					m_rules.FemaleRulerChance = rule.FemaleRulerChance;
				if( rule.RulerSpouseChance != -1 )
					m_rules.RulerSpouseChance = rule.RulerSpouseChance;
				if( rule.RepsForceCustomDuchies != null )
					m_rules.RepsForceCustomDuchies = rule.RepsForceCustomDuchies;
				if( rule.RepublicExpandChance != -1 )
					m_rules.RepublicExpandChance = rule.RepublicExpandChance;
				if( rule.RepublicExpandMax != -1 )
					m_rules.RepublicExpandMax = rule.RepublicExpandMax;

				if( rule.EmpireMinSize != -1 )
					m_rules.EmpireMinSize = rule.EmpireMinSize;
				if( rule.KingdomMinSize != -1 )
					m_rules.KingdomMinSize = rule.KingdomMinSize;
				if( rule.DuchyMinSize != -1 )
					m_rules.DuchyMinSize = rule.DuchyMinSize;

				if( rule.ClearCharacters != null )
					m_rules.ClearCharacters = rule.ClearCharacters;
				if( rule.CharacterStartID != -1 )
					m_rules.CharacterStartID = rule.CharacterStartID;

				if( rule.CulGenDynastyPrefix != -1 )
					m_rules.CulGenDynastyPrefix = rule.CulGenDynastyPrefix;
				if( rule.CulGenBastardPrefix != -1 )
					m_rules.CulGenBastardPrefix = rule.CulGenBastardPrefix;

				if( rule.CulGenPatronymIsPrefix != -1 )
					m_rules.CulGenPatronymIsPrefix = rule.CulGenPatronymIsPrefix;
				if( rule.CulGenMalePatronym != -1 )
					m_rules.CulGenMalePatronym = rule.CulGenMalePatronym;
				if( rule.CulGenFemalePatronym != -1 )
					m_rules.CulGenFemalePatronym = rule.CulGenFemalePatronym;

				if( rule.CulGenAncestorName != -1 )
					m_rules.CulGenAncestorName = rule.CulGenAncestorName;
				if( rule.CulGenDisinheritFromBlinding != -1 )
					m_rules.CulGenDisinheritFromBlinding = rule.CulGenDisinheritFromBlinding;
				if( rule.CulGenDukesCalledKings != -1 )
					m_rules.CulGenDukesCalledKings = rule.CulGenDukesCalledKings;
				if( rule.CulGenFounderNamesDynasty != -1 )
					m_rules.CulGenFounderNamesDynasty = rule.CulGenFounderNamesDynasty;
				if( rule.CulGenDynastyTitleNames != -1 )
					m_rules.CulGenDynastyTitleNames = rule.CulGenDynastyTitleNames;
			}
			#endregion

			return true;
		}