changeset 392:db6713d5b35f default-army-size

RRe #97: Default army size issues
author snowblizz
date Wed, 01 Dec 2010 20:00:58 +0000
parents 83c82e5c740c
children b90db11edc64
files IBBoard.WarFoundry.API.csproj api/Exporters/WarFoundryHtmlExporter.cs api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/GameSystem.cs schemas/system.xsd
diffstat 6 files changed, 375 insertions(+), 355 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Mon Oct 18 19:59:25 2010 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Wed Dec 01 20:00:58 2010 +0000
     1.3 @@ -60,7 +60,6 @@
     1.4    </Target>
     1.5    -->
     1.6    <ItemGroup>
     1.7 -    <None Include="app.config" />
     1.8      <None Include="COPYING" />
     1.9      <Compile Include="api\Objects\ICostedWarFoundryObject.cs" />
    1.10      <Compile Include="api\Commands\CreateAndAddUnitCommand.cs" />
    1.11 @@ -186,6 +185,10 @@
    1.12      <Content Include="libs\ICSharpCode.SharpZipLib.dll" />
    1.13    </ItemGroup>
    1.14    <ItemGroup>
    1.15 +    <Reference Include="IBBoard, Version=1.0.3896.41664, Culture=neutral, processorArchitecture=MSIL">
    1.16 +      <SpecificVersion>False</SpecificVersion>
    1.17 +      <HintPath>..\IBBoard\bin\Release\IBBoard.dll</HintPath>
    1.18 +    </Reference>
    1.19      <Reference Include="System.Data" />
    1.20      <Reference Include="System.Xml" />
    1.21      <Reference Include="System" />
    1.22 @@ -195,12 +198,6 @@
    1.23      </Reference>
    1.24    </ItemGroup>
    1.25    <ItemGroup>
    1.26 -    <ProjectReference Include="..\IBBoard\IBBoard.csproj">
    1.27 -      <Project>{5DFD64F6-FC2B-4B4F-B92E-483BAC468105}</Project>
    1.28 -      <Name>IBBoard</Name>
    1.29 -    </ProjectReference>
    1.30 -  </ItemGroup>
    1.31 -  <ItemGroup>
    1.32      <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
    1.33        <Visible>False</Visible>
    1.34        <ProductName>.NET Framework Client Profile</ProductName>
     2.1 --- a/api/Exporters/WarFoundryHtmlExporter.cs	Mon Oct 18 19:59:25 2010 +0000
     2.2 +++ b/api/Exporters/WarFoundryHtmlExporter.cs	Wed Dec 01 20:00:58 2010 +0000
     2.3 @@ -57,7 +57,7 @@
     2.4  			metaCharset.SetAttribute("content", "text/html;charset=UTF-8");
     2.5  			head.AppendChild(metaCharset);
     2.6  			XmlElement style = doc.CreateElement("style");
     2.7 -			style.InnerText = "able, th, td { border: 1px solid #000; border-spacing: 0; border-collapse: collapse; margin: 0 }\n"
     2.8 +			style.InnerText = "table, th, td { border: 1px solid #000; border-spacing: 0; border-collapse: collapse; margin: 0 }\n"
     2.9  				+"table table { width: 100%; border-width: 0; margin: -2px }\n"
    2.10  				+"table table td { border-width:0 1px }";
    2.11  			head.AppendChild(style);
     3.1 --- a/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Mon Oct 18 19:59:25 2010 +0000
     3.2 +++ b/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Wed Dec 01 20:00:58 2010 +0000
     3.3 @@ -1,97 +1,100 @@
     3.4 -//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
     3.5 -// 
     3.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     3.7 -
     3.8 -using System;
     3.9 -using System.Collections.Generic;
    3.10 -using System.IO;
    3.11 -using System.Xml;
    3.12 -using ICSharpCode.SharpZipLib.Zip;
    3.13 -using IBBoard.Xml;
    3.14 -using IBBoard.WarFoundry.API.Objects;
    3.15 -
    3.16 -namespace IBBoard.WarFoundry.API.Factories.Xml
    3.17 -{
    3.18 -	/// <summary>
    3.19 -	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
    3.20 -	/// </summary>
    3.21 -	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
    3.22 -	{	
    3.23 -		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
    3.24 -		
    3.25 -		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
    3.26 -		{
    3.27 -		}
    3.28 -		
    3.29 -		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
    3.30 -		{
    3.31 -			extraData[wfObject] = elem.OwnerDocument;
    3.32 -		}
    3.33 -	
    3.34 -		private XmlDocument GetExtraData(GameSystem obj)
    3.35 -		{
    3.36 -			XmlDocument extra = null;
    3.37 -			extraData.TryGetValue(obj, out extra);			
    3.38 -			return extra;
    3.39 -		}
    3.40 -		
    3.41 -		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
    3.42 -		{
    3.43 -			string id = elem.GetAttribute("id");
    3.44 -			string name = elem.GetAttribute("name");
    3.45 -			GameSystem system = new GameSystem(id, name, mainFactory);
    3.46 -			StoreExtraData(system, elem);
    3.47 -			return system;
    3.48 -		}		
    3.49 -		
    3.50 -		public void CompleteLoading(GameSystem system)
    3.51 -		{
    3.52 -			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
    3.53 -			{
    3.54 -				return;
    3.55 -			}
    3.56 -			
    3.57 -			system.SetAsLoading();			
    3.58 -			XmlDocument extraData = GetExtraData(system);
    3.59 -			LoadCategoriesForSystem(system, extraData);
    3.60 -			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
    3.61 -			string defaultStatsID = statsElem.GetAttribute("defaultStats");
    3.62 -			LoadSystemStatsForSystem(system, extraData);
    3.63 -			system.StandardSystemStatsID = defaultStatsID;
    3.64 -			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
    3.65 -			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
    3.66 -			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
    3.67 -			system.SetAsFullyLoaded();
    3.68 -		}
    3.69 -
    3.70 -		
    3.71 -		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
    3.72 -		{
    3.73 -			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
    3.74 -			{
    3.75 -				system.AddCategory(CreateCategoryFromElement(cat));
    3.76 -			}
    3.77 -		}	
    3.78 -		
    3.79 -		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
    3.80 -		{
    3.81 -			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
    3.82 -			{
    3.83 -				SystemStats sysStats = CreateSystemStatsFromElement(stats);
    3.84 -				system.AddSystemStats(sysStats);
    3.85 -			}
    3.86 -		}
    3.87 -		
    3.88 -		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
    3.89 -		{
    3.90 -			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
    3.91 -			
    3.92 -			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
    3.93 -			{
    3.94 -				sysStats.AddStatSlot(slot.GetAttribute("name"));
    3.95 -			}
    3.96 -
    3.97 -			return sysStats;
    3.98 -		}	
    3.99 -	}
   3.100 -}
   3.101 +//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
   3.102 +// 
   3.103 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
   3.104 +
   3.105 +using System;
   3.106 +using System.Collections.Generic;
   3.107 +using System.IO;
   3.108 +using System.Xml;
   3.109 +using ICSharpCode.SharpZipLib.Zip;
   3.110 +using IBBoard.Xml;
   3.111 +using IBBoard.WarFoundry.API.Objects;
   3.112 +
   3.113 +namespace IBBoard.WarFoundry.API.Factories.Xml
   3.114 +{
   3.115 +	/// <summary>
   3.116 +	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
   3.117 +	/// </summary>
   3.118 +	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
   3.119 +	{	
   3.120 +		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
   3.121 +		
   3.122 +		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
   3.123 +		{
   3.124 +		}
   3.125 +		
   3.126 +		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
   3.127 +		{
   3.128 +			extraData[wfObject] = elem.OwnerDocument;
   3.129 +		}
   3.130 +	
   3.131 +		private XmlDocument GetExtraData(GameSystem obj)
   3.132 +		{
   3.133 +			XmlDocument extra = null;
   3.134 +			extraData.TryGetValue(obj, out extra);			
   3.135 +			return extra;
   3.136 +		}
   3.137 +		
   3.138 +		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
   3.139 +		{
   3.140 +			string id = elem.GetAttribute("id");
   3.141 +			string name = elem.GetAttribute("name");
   3.142 +            GameSystem system = new GameSystem(id, name, mainFactory);
   3.143 +            int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem,"defaultArmySize");
   3.144 +            system.SystemArmyDefaultSize = defaultarmysize;
   3.145 +			StoreExtraData(system, elem);
   3.146 +			return system;
   3.147 +            
   3.148 +		}		
   3.149 +		
   3.150 +		public void CompleteLoading(GameSystem system)
   3.151 +        {
   3.152 +			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
   3.153 +			{
   3.154 +				return;
   3.155 +			}
   3.156 +			
   3.157 +			system.SetAsLoading();			
   3.158 +			XmlDocument extraData = GetExtraData(system);
   3.159 +			LoadCategoriesForSystem(system, extraData);
   3.160 +			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
   3.161 +			string defaultStatsID = statsElem.GetAttribute("defaultStats");
   3.162 +			LoadSystemStatsForSystem(system, extraData);
   3.163 +			system.StandardSystemStatsID = defaultStatsID;
   3.164 +			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
   3.165 +			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
   3.166 +			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
   3.167 +			system.SetAsFullyLoaded();
   3.168 +		}
   3.169 +
   3.170 +		
   3.171 +		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
   3.172 +		{
   3.173 +			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
   3.174 +			{
   3.175 +				system.AddCategory(CreateCategoryFromElement(cat));
   3.176 +			}
   3.177 +		}	
   3.178 +		
   3.179 +		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
   3.180 +		{
   3.181 +			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
   3.182 +			{
   3.183 +				SystemStats sysStats = CreateSystemStatsFromElement(stats);
   3.184 +				system.AddSystemStats(sysStats);
   3.185 +			}
   3.186 +		}
   3.187 +		
   3.188 +		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
   3.189 +		{
   3.190 +			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
   3.191 +			
   3.192 +			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
   3.193 +			{
   3.194 +				sysStats.AddStatSlot(slot.GetAttribute("name"));
   3.195 +			}
   3.196 +
   3.197 +			return sysStats;
   3.198 +		}	
   3.199 +	}
   3.200 +}
     4.1 Binary file api/Factories/Xml/WarFoundryXmlRaceFactory.cs has changed
     5.1 --- a/api/Objects/GameSystem.cs	Mon Oct 18 19:59:25 2010 +0000
     5.2 +++ b/api/Objects/GameSystem.cs	Wed Dec 01 20:00:58 2010 +0000
     5.3 @@ -1,250 +1,269 @@
     5.4 -// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
     5.5 -//
     5.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     5.7 -
     5.8 -using System;
     5.9 -using System.Collections.Generic;
    5.10 -using System.Xml;
    5.11 -using System.IO;
    5.12 -using IBBoard.Logging;
    5.13 -using IBBoard.WarFoundry.API.Factories;
    5.14 -using ICSharpCode.SharpZipLib.Zip;
    5.15 -
    5.16 -namespace IBBoard.WarFoundry.API.Objects
    5.17 -{
    5.18 -	/// <summary>
    5.19 -	/// Summary description for GameSystem.
    5.20 -	/// </summary>
    5.21 -	public class GameSystem : WarFoundryStagedLoadingObject
    5.22 -	{
    5.23 -		private bool warnOnError;
    5.24 -		private bool allowAllies;
    5.25 -		private Dictionary<string, Category> categories = new Dictionary<string,Category>();
    5.26 -		private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>();
    5.27 -		private string defaultStats;
    5.28 -
    5.29 -		public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory)
    5.30 -		{
    5.31 -			stats = new Dictionary<string,SystemStats>();
    5.32 -		}
    5.33 -		
    5.34 -		public bool AllowAllies
    5.35 -		{
    5.36 -			get { return allowAllies; }
    5.37 -			set { allowAllies = value; }
    5.38 -		}
    5.39 -		
    5.40 -		public void AddCategory(Category cat)
    5.41 -		{
    5.42 -			RawCategories[cat.ID] = cat;
    5.43 -		}
    5.44 -
    5.45 -		public Category GetCategory(string id)
    5.46 -		{
    5.47 -			EnsureFullyLoaded();
    5.48 -			Category cat = null;
    5.49 -			RawCategories.TryGetValue(id, out cat);
    5.50 -			return cat;
    5.51 -		}
    5.52 -
    5.53 -		public Category[] Categories
    5.54 -		{
    5.55 -			get 
    5.56 -			{ 
    5.57 -				EnsureFullyLoaded();
    5.58 -				return DictionaryUtils.ToArray<string, Category>(RawCategories); 
    5.59 -			}
    5.60 -		}
    5.61 -		
    5.62 -		protected Dictionary<string, Category> RawCategories
    5.63 -		{
    5.64 -			get { return categories; }
    5.65 -		}
    5.66 -
    5.67 -		public bool WarnOnError
    5.68 -		{
    5.69 -			get
    5.70 -			{
    5.71 -				return warnOnError;
    5.72 -			}
    5.73 -			set { warnOnError = value; }
    5.74 -		}
    5.75 -		
    5.76 -		public void AddSystemStats(SystemStats sysStats)
    5.77 -		{
    5.78 -			stats[sysStats.ID] = sysStats;
    5.79 -		}
    5.80 -		
    5.81 -		public SystemStats StandardSystemStats
    5.82 -		{
    5.83 -			get
    5.84 -			{
    5.85 -				EnsureFullyLoaded();
    5.86 -				return stats[defaultStats];
    5.87 -			}
    5.88 -		}
    5.89 -		
    5.90 -		public string StandardSystemStatsID
    5.91 -		{
    5.92 -			get
    5.93 -			{
    5.94 -				EnsureFullyLoaded();
    5.95 -				return defaultStats;
    5.96 -			}
    5.97 -			
    5.98 -			set
    5.99 -			{
   5.100 -				if (value != null && value.Trim().Length > 0)
   5.101 -				{
   5.102 -					defaultStats = value;
   5.103 -				}
   5.104 -			}
   5.105 -		}
   5.106 -
   5.107 -		public SystemStats[] SystemStats
   5.108 -		{
   5.109 -			get 
   5.110 -			{ 
   5.111 -				EnsureFullyLoaded();
   5.112 -				SystemStats[] statsArray = new SystemStats[stats.Count];
   5.113 -				stats.Values.CopyTo(statsArray, 0);
   5.114 -				return statsArray;
   5.115 -			}
   5.116 -		}
   5.117 -		
   5.118 -		public SystemStats GetSystemStatsForID(string id)
   5.119 -		{
   5.120 -			EnsureFullyLoaded();
   5.121 -			SystemStats statsForID;
   5.122 -			stats.TryGetValue(id, out statsForID);
   5.123 -			return statsForID;
   5.124 -		}
   5.125 -		
   5.126 -		public Race SystemDefaultRace
   5.127 -		{
   5.128 -			get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
   5.129 -		}
   5.130 -
   5.131 -		public bool Matches(GameSystem otherSystem)
   5.132 -		{
   5.133 -			if (otherSystem==null)
   5.134 -			{
   5.135 -				return false;
   5.136 -			}
   5.137 -
   5.138 -			return this.ID == otherSystem.ID;
   5.139 -		}
   5.140 -
   5.141 -		public override bool Equals(object obj)
   5.142 -		{
   5.143 -			if (obj == null)
   5.144 -			{
   5.145 -				return false;		
   5.146 -			}
   5.147 -			
   5.148 -			if (obj.GetType().Equals(this.GetType()))
   5.149 -			{
   5.150 -				GameSystem otherSystem = (GameSystem)obj;
   5.151 -
   5.152 -				return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
   5.153 -			}
   5.154 -			else
   5.155 -			{
   5.156 -				return false;
   5.157 -			}
   5.158 -		}
   5.159 -
   5.160 -		public override int GetHashCode()
   5.161 -		{
   5.162 -			return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
   5.163 -		}
   5.164 -
   5.165 -		public bool UnitTypeMaxed(UnitType unitType, Army army)
   5.166 -		{
   5.167 -			return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
   5.168 -		}
   5.169 -
   5.170 -		public bool UnitTypeMinned(UnitType unitType, Army army)
   5.171 -		{
   5.172 -			return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
   5.173 -		}
   5.174 -		
   5.175 -		public List<EquipmentItem> GetSystemEquipmentList()
   5.176 -		{
   5.177 -			List<EquipmentItem> items = new List<EquipmentItem>();
   5.178 -			Race defaultRace = SystemDefaultRace;
   5.179 -			
   5.180 -			if (defaultRace!=null)
   5.181 -			{				
   5.182 -				items = defaultRace.GetEquipmentList();
   5.183 -			}
   5.184 -			
   5.185 -			return items;
   5.186 -		}
   5.187 -				
   5.188 -		public EquipmentItem GetSystemEquipmentItem(string id)
   5.189 -		{
   5.190 -			EquipmentItem item = null;
   5.191 -			Race defaultRace = SystemDefaultRace;
   5.192 -			
   5.193 -			if (defaultRace!=null)
   5.194 -			{				
   5.195 -				item = defaultRace.GetEquipmentItem(id);
   5.196 -			}
   5.197 -			
   5.198 -			return item;
   5.199 -		}
   5.200 -		
   5.201 -		public UnitType[] GetSystemUnitTypes(Category cat)
   5.202 -		{
   5.203 -			UnitType[] items = new UnitType[0];
   5.204 -			Race defaultRace = SystemDefaultRace;
   5.205 -			
   5.206 -			if (defaultRace!=null)
   5.207 -			{				
   5.208 -				items = defaultRace.GetUnitTypes(cat);
   5.209 -			}
   5.210 -			
   5.211 -			return items;
   5.212 -		}
   5.213 -				
   5.214 -		public UnitType GetSystemUnitType(string id)
   5.215 -		{
   5.216 -			UnitType unit = null;
   5.217 -			Race defaultRace = SystemDefaultRace;
   5.218 -			
   5.219 -			if (defaultRace!=null)
   5.220 -			{				
   5.221 -				unit = defaultRace.GetUnitType(id);
   5.222 -			}
   5.223 -			
   5.224 -			return unit;
   5.225 -		}
   5.226 -		
   5.227 -		public List<Ability> GetSystemAbilityList()
   5.228 -		{
   5.229 -			List<Ability> items = new List<Ability>();
   5.230 -			Race defaultRace = SystemDefaultRace;
   5.231 -			
   5.232 -			if (defaultRace!=null)
   5.233 -			{				
   5.234 -				items = defaultRace.GetAbilityList();
   5.235 -			}
   5.236 -			
   5.237 -			return items;
   5.238 -		}
   5.239 -				
   5.240 -		public Ability GetSystemAbility(string id)
   5.241 -		{
   5.242 -			Ability ability = null;
   5.243 -			Race defaultRace = SystemDefaultRace;
   5.244 -			
   5.245 -			if (defaultRace!=null)
   5.246 -			{				
   5.247 -				ability = defaultRace.GetAbility(id);
   5.248 -			}
   5.249 -			
   5.250 -			return ability;
   5.251 -		}
   5.252 -	}
   5.253 -}
   5.254 +// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
   5.255 +//
   5.256 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
   5.257 +
   5.258 +using System;
   5.259 +using System.Collections.Generic;
   5.260 +using System.Xml;
   5.261 +using System.IO;
   5.262 +using IBBoard.Logging;
   5.263 +using IBBoard.WarFoundry.API.Factories;
   5.264 +using ICSharpCode.SharpZipLib.Zip;
   5.265 +
   5.266 +namespace IBBoard.WarFoundry.API.Objects
   5.267 +{
   5.268 +	/// <summary>
   5.269 +	/// Summary description for GameSystem.
   5.270 +	/// </summary>
   5.271 +	public class GameSystem : WarFoundryStagedLoadingObject
   5.272 +	{
   5.273 +        
   5.274 +        private bool warnOnError;
   5.275 +		private bool allowAllies;
   5.276 +		private Dictionary<string, Category> categories = new Dictionary<string,Category>();
   5.277 +		private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>();
   5.278 +		private string defaultStats;
   5.279 +        private int defaultArmySize;
   5.280 +
   5.281 +        public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory)
   5.282 +            : base(systemID, systemName, creatingFactory)
   5.283 +		{
   5.284 +			stats = new Dictionary<string,SystemStats>();
   5.285 +		}
   5.286 +
   5.287 +        public int SystemArmyDefaultSize
   5.288 +        {
   5.289 +            get { return  defaultArmySize; }
   5.290 +            set
   5.291 +            {
   5.292 +                if (value == 0)
   5.293 +                {
   5.294 +                    defaultArmySize = 1;
   5.295 +                    throw new ArgumentException("No default system army size");
   5.296 +                    
   5.297 +                }
   5.298 +                
   5.299 +                 defaultArmySize =  value;
   5.300 +            }
   5.301 +        }
   5.302 +		
   5.303 +		public bool AllowAllies
   5.304 +		{
   5.305 +			get { return allowAllies; }
   5.306 +			set { allowAllies = value; }
   5.307 +		}
   5.308 +		
   5.309 +		public void AddCategory(Category cat)
   5.310 +		{
   5.311 +			RawCategories[cat.ID] = cat;
   5.312 +		}
   5.313 +
   5.314 +		public Category GetCategory(string id)
   5.315 +		{
   5.316 +			EnsureFullyLoaded();
   5.317 +			Category cat = null;
   5.318 +			RawCategories.TryGetValue(id, out cat);
   5.319 +			return cat;
   5.320 +		}
   5.321 +
   5.322 +		public Category[] Categories
   5.323 +		{
   5.324 +			get 
   5.325 +			{ 
   5.326 +				EnsureFullyLoaded();
   5.327 +				return DictionaryUtils.ToArray<string, Category>(RawCategories); 
   5.328 +			}
   5.329 +		}
   5.330 +		
   5.331 +		protected Dictionary<string, Category> RawCategories
   5.332 +		{
   5.333 +			get { return categories; }
   5.334 +		}
   5.335 +
   5.336 +		public bool WarnOnError
   5.337 +		{
   5.338 +			get
   5.339 +			{
   5.340 +				return warnOnError;
   5.341 +			}
   5.342 +			set { warnOnError = value; }
   5.343 +		}
   5.344 +		
   5.345 +		public void AddSystemStats(SystemStats sysStats)
   5.346 +		{
   5.347 +			stats[sysStats.ID] = sysStats;
   5.348 +		}
   5.349 +		
   5.350 +		public SystemStats StandardSystemStats
   5.351 +		{
   5.352 +			get
   5.353 +			{
   5.354 +				EnsureFullyLoaded();
   5.355 +				return stats[defaultStats];
   5.356 +			}
   5.357 +		}
   5.358 +		
   5.359 +		public string StandardSystemStatsID
   5.360 +		{
   5.361 +			get
   5.362 +			{
   5.363 +				EnsureFullyLoaded();
   5.364 +				return defaultStats;
   5.365 +			}
   5.366 +			
   5.367 +			set
   5.368 +			{
   5.369 +				if (value != null && value.Trim().Length > 0)
   5.370 +				{
   5.371 +					defaultStats = value;
   5.372 +				}
   5.373 +			}
   5.374 +		}
   5.375 +
   5.376 +		public SystemStats[] SystemStats
   5.377 +		{
   5.378 +			get 
   5.379 +			{ 
   5.380 +				EnsureFullyLoaded();
   5.381 +				SystemStats[] statsArray = new SystemStats[stats.Count];
   5.382 +				stats.Values.CopyTo(statsArray, 0);
   5.383 +				return statsArray;
   5.384 +			}
   5.385 +		}
   5.386 +		
   5.387 +		public SystemStats GetSystemStatsForID(string id)
   5.388 +		{
   5.389 +			EnsureFullyLoaded();
   5.390 +			SystemStats statsForID;
   5.391 +			stats.TryGetValue(id, out statsForID);
   5.392 +			return statsForID;
   5.393 +		}
   5.394 +		
   5.395 +		public Race SystemDefaultRace
   5.396 +		{
   5.397 +			get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
   5.398 +		}
   5.399 +
   5.400 +		public bool Matches(GameSystem otherSystem)
   5.401 +		{
   5.402 +			if (otherSystem==null)
   5.403 +			{
   5.404 +				return false;
   5.405 +			}
   5.406 +
   5.407 +			return this.ID == otherSystem.ID;
   5.408 +		}
   5.409 +
   5.410 +		public override bool Equals(object obj)
   5.411 +		{
   5.412 +			if (obj == null)
   5.413 +			{
   5.414 +				return false;		
   5.415 +			}
   5.416 +			
   5.417 +			if (obj.GetType().Equals(this.GetType()))
   5.418 +			{
   5.419 +				GameSystem otherSystem = (GameSystem)obj;
   5.420 +
   5.421 +				return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
   5.422 +			}
   5.423 +			else
   5.424 +			{
   5.425 +				return false;
   5.426 +			}
   5.427 +		}
   5.428 +
   5.429 +		public override int GetHashCode()
   5.430 +		{
   5.431 +			return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
   5.432 +		}
   5.433 +
   5.434 +		public bool UnitTypeMaxed(UnitType unitType, Army army)
   5.435 +		{
   5.436 +			return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
   5.437 +		}
   5.438 +
   5.439 +		public bool UnitTypeMinned(UnitType unitType, Army army)
   5.440 +		{
   5.441 +			return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
   5.442 +		}
   5.443 +		
   5.444 +		public List<EquipmentItem> GetSystemEquipmentList()
   5.445 +		{
   5.446 +			List<EquipmentItem> items = new List<EquipmentItem>();
   5.447 +			Race defaultRace = SystemDefaultRace;
   5.448 +			
   5.449 +			if (defaultRace!=null)
   5.450 +			{				
   5.451 +				items = defaultRace.GetEquipmentList();
   5.452 +			}
   5.453 +			
   5.454 +			return items;
   5.455 +		}
   5.456 +				
   5.457 +		public EquipmentItem GetSystemEquipmentItem(string id)
   5.458 +		{
   5.459 +			EquipmentItem item = null;
   5.460 +			Race defaultRace = SystemDefaultRace;
   5.461 +			
   5.462 +			if (defaultRace!=null)
   5.463 +			{				
   5.464 +				item = defaultRace.GetEquipmentItem(id);
   5.465 +			}
   5.466 +			
   5.467 +			return item;
   5.468 +		}
   5.469 +		
   5.470 +		public UnitType[] GetSystemUnitTypes(Category cat)
   5.471 +		{
   5.472 +			UnitType[] items = new UnitType[0];
   5.473 +			Race defaultRace = SystemDefaultRace;
   5.474 +			
   5.475 +			if (defaultRace!=null)
   5.476 +			{				
   5.477 +				items = defaultRace.GetUnitTypes(cat);
   5.478 +			}
   5.479 +			
   5.480 +			return items;
   5.481 +		}
   5.482 +				
   5.483 +		public UnitType GetSystemUnitType(string id)
   5.484 +		{
   5.485 +			UnitType unit = null;
   5.486 +			Race defaultRace = SystemDefaultRace;
   5.487 +			
   5.488 +			if (defaultRace!=null)
   5.489 +			{				
   5.490 +				unit = defaultRace.GetUnitType(id);
   5.491 +			}
   5.492 +			
   5.493 +			return unit;
   5.494 +		}
   5.495 +		
   5.496 +		public List<Ability> GetSystemAbilityList()
   5.497 +		{
   5.498 +			List<Ability> items = new List<Ability>();
   5.499 +			Race defaultRace = SystemDefaultRace;
   5.500 +			
   5.501 +			if (defaultRace!=null)
   5.502 +			{				
   5.503 +				items = defaultRace.GetAbilityList();
   5.504 +			}
   5.505 +			
   5.506 +			return items;
   5.507 +		}
   5.508 +				
   5.509 +		public Ability GetSystemAbility(string id)
   5.510 +		{
   5.511 +			Ability ability = null;
   5.512 +			Race defaultRace = SystemDefaultRace;
   5.513 +			
   5.514 +			if (defaultRace!=null)
   5.515 +			{				
   5.516 +				ability = defaultRace.GetAbility(id);
   5.517 +			}
   5.518 +			
   5.519 +			return ability;
   5.520 +		}
   5.521 +	}
   5.522 +}
     6.1 --- a/schemas/system.xsd	Mon Oct 18 19:59:25 2010 +0000
     6.2 +++ b/schemas/system.xsd	Wed Dec 01 20:00:58 2010 +0000
     6.3 @@ -39,6 +39,7 @@
     6.4  		</xs:sequence>
     6.5  		<xs:attribute name="id" type="xs:string" />
     6.6  		<xs:attribute name="name" type="xs:string" use="required"/>
     6.7 +    <xs:attribute name="defaultArmySize" type="core:nonNegativeNonInfiniteDouble" default="0"/>
     6.8  		<xs:attribute name="warn" type="xs:boolean" default="false"/>
     6.9  		<xs:attribute name="allowAllies" type="xs:boolean" default="true"/>
    6.10  		<xs:anyAttribute processContents="lax"/>