# HG changeset patch
# User snowblizz
# Date 1292167627 0
# Node ID 4e0031339bcb524c729b407aadfea3e9e82473b2
# Parent 121d9d1ba53c8ce58b92deacbb6870227291945f
Re #97: Default army size papercut.
Updated GameSystem.cs, system.xsd and Factories to accommodate default system size.
diff -r 121d9d1ba53c -r 4e0031339bcb api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs
--- a/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sun Nov 21 21:53:16 2010 +0000
+++ b/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sun Dec 12 15:27:07 2010 +0000
@@ -1,97 +1,100 @@
-// This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
-//
-// 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.
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Xml;
-using ICSharpCode.SharpZipLib.Zip;
-using IBBoard.Xml;
-using IBBoard.WarFoundry.API.Objects;
-
-namespace IBBoard.WarFoundry.API.Factories.Xml
-{
- ///
- /// A sub-factory specifically for loading GameSystems from WarFoundry XML files
- ///
- public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
- {
- private Dictionary extraData = new Dictionary();
-
- public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
- {
- }
-
- private void StoreExtraData(GameSystem wfObject, XmlElement elem)
- {
- extraData[wfObject] = elem.OwnerDocument;
- }
-
- private XmlDocument GetExtraData(GameSystem obj)
- {
- XmlDocument extra = null;
- extraData.TryGetValue(obj, out extra);
- return extra;
- }
-
- public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
- {
- string id = elem.GetAttribute("id");
- string name = elem.GetAttribute("name");
- GameSystem system = new GameSystem(id, name, mainFactory);
- StoreExtraData(system, elem);
- return system;
- }
-
- public void CompleteLoading(GameSystem system)
- {
- if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
- {
- return;
- }
-
- system.SetAsLoading();
- XmlDocument extraData = GetExtraData(system);
- LoadCategoriesForSystem(system, extraData);
- XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
- string defaultStatsID = statsElem.GetAttribute("defaultStats");
- LoadSystemStatsForSystem(system, extraData);
- system.StandardSystemStatsID = defaultStatsID;
- XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
- system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
- system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
- system.SetAsFullyLoaded();
- }
-
-
- private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
- {
- foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
- {
- system.AddCategory(CreateCategoryFromElement(cat));
- }
- }
-
- private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
- {
- foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
- {
- SystemStats sysStats = CreateSystemStatsFromElement(stats);
- system.AddSystemStats(sysStats);
- }
- }
-
- private SystemStats CreateSystemStatsFromElement(XmlElement elem)
- {
- SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
-
- foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
- {
- sysStats.AddStatSlot(slot.GetAttribute("name"));
- }
-
- return sysStats;
- }
- }
-}
+// This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
+//
+// 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.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using ICSharpCode.SharpZipLib.Zip;
+using IBBoard.Xml;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Factories.Xml
+{
+ ///
+ /// A sub-factory specifically for loading GameSystems from WarFoundry XML files
+ ///
+ public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
+ {
+ private Dictionary extraData = new Dictionary();
+
+ public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
+ {
+ }
+
+ private void StoreExtraData(GameSystem wfObject, XmlElement elem)
+ {
+ extraData[wfObject] = elem.OwnerDocument;
+ }
+
+ private XmlDocument GetExtraData(GameSystem obj)
+ {
+ XmlDocument extra = null;
+ extraData.TryGetValue(obj, out extra);
+ return extra;
+ }
+
+ public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
+ {
+ string id = elem.GetAttribute("id");
+ string name = elem.GetAttribute("name");
+ GameSystem system = new GameSystem(id, name, mainFactory);
+ int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem,"defaultArmySize");
+ system.SystemArmyDefaultSize = defaultarmysize;
+ StoreExtraData(system, elem);
+ return system;
+
+ }
+
+ public void CompleteLoading(GameSystem system)
+ {
+ if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
+ {
+ return;
+ }
+
+ system.SetAsLoading();
+ XmlDocument extraData = GetExtraData(system);
+ LoadCategoriesForSystem(system, extraData);
+ XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
+ string defaultStatsID = statsElem.GetAttribute("defaultStats");
+ LoadSystemStatsForSystem(system, extraData);
+ system.StandardSystemStatsID = defaultStatsID;
+ XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
+ system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
+ system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
+ system.SetAsFullyLoaded();
+ }
+
+
+ private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
+ {
+ foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
+ {
+ system.AddCategory(CreateCategoryFromElement(cat));
+ }
+ }
+
+ private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
+ {
+ foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
+ {
+ SystemStats sysStats = CreateSystemStatsFromElement(stats);
+ system.AddSystemStats(sysStats);
+ }
+ }
+
+ private SystemStats CreateSystemStatsFromElement(XmlElement elem)
+ {
+ SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
+
+ foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
+ {
+ sysStats.AddStatSlot(slot.GetAttribute("name"));
+ }
+
+ return sysStats;
+ }
+ }
+}
diff -r 121d9d1ba53c -r 4e0031339bcb api/Objects/GameSystem.cs
--- a/api/Objects/GameSystem.cs Sun Nov 21 21:53:16 2010 +0000
+++ b/api/Objects/GameSystem.cs Sun Dec 12 15:27:07 2010 +0000
@@ -1,250 +1,269 @@
-// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
-//
-// 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.
-
-using System;
-using System.Collections.Generic;
-using System.Xml;
-using System.IO;
-using IBBoard.Logging;
-using IBBoard.WarFoundry.API.Factories;
-using ICSharpCode.SharpZipLib.Zip;
-
-namespace IBBoard.WarFoundry.API.Objects
-{
- ///
- /// Summary description for GameSystem.
- ///
- public class GameSystem : WarFoundryStagedLoadingObject
- {
- private bool warnOnError;
- private bool allowAllies;
- private Dictionary categories = new Dictionary();
- private Dictionary stats = new Dictionary();
- private string defaultStats;
-
- public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory)
- {
- stats = new Dictionary();
- }
-
- public bool AllowAllies
- {
- get { return allowAllies; }
- set { allowAllies = value; }
- }
-
- public void AddCategory(Category cat)
- {
- RawCategories[cat.ID] = cat;
- }
-
- public Category GetCategory(string id)
- {
- EnsureFullyLoaded();
- Category cat = null;
- RawCategories.TryGetValue(id, out cat);
- return cat;
- }
-
- public Category[] Categories
- {
- get
- {
- EnsureFullyLoaded();
- return DictionaryUtils.ToArray(RawCategories);
- }
- }
-
- protected Dictionary RawCategories
- {
- get { return categories; }
- }
-
- public bool WarnOnError
- {
- get
- {
- return warnOnError;
- }
- set { warnOnError = value; }
- }
-
- public void AddSystemStats(SystemStats sysStats)
- {
- stats[sysStats.ID] = sysStats;
- }
-
- public SystemStats StandardSystemStats
- {
- get
- {
- EnsureFullyLoaded();
- return stats[defaultStats];
- }
- }
-
- public string StandardSystemStatsID
- {
- get
- {
- EnsureFullyLoaded();
- return defaultStats;
- }
-
- set
- {
- if (value != null && value.Trim().Length > 0)
- {
- defaultStats = value;
- }
- }
- }
-
- public SystemStats[] SystemStats
- {
- get
- {
- EnsureFullyLoaded();
- SystemStats[] statsArray = new SystemStats[stats.Count];
- stats.Values.CopyTo(statsArray, 0);
- return statsArray;
- }
- }
-
- public SystemStats GetSystemStatsForID(string id)
- {
- EnsureFullyLoaded();
- SystemStats statsForID;
- stats.TryGetValue(id, out statsForID);
- return statsForID;
- }
-
- public Race SystemDefaultRace
- {
- get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
- }
-
- public bool Matches(GameSystem otherSystem)
- {
- if (otherSystem==null)
- {
- return false;
- }
-
- return this.ID == otherSystem.ID;
- }
-
- public override bool Equals(object obj)
- {
- if (obj == null)
- {
- return false;
- }
-
- if (obj.GetType().Equals(this.GetType()))
- {
- GameSystem otherSystem = (GameSystem)obj;
-
- return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
- }
- else
- {
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
- }
-
- public bool UnitTypeMaxed(UnitType unitType, Army army)
- {
- return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
- }
-
- public bool UnitTypeMinned(UnitType unitType, Army army)
- {
- return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
- }
-
- public List GetSystemEquipmentList()
- {
- List items = new List();
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- items = defaultRace.GetEquipmentList();
- }
-
- return items;
- }
-
- public EquipmentItem GetSystemEquipmentItem(string id)
- {
- EquipmentItem item = null;
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- item = defaultRace.GetEquipmentItem(id);
- }
-
- return item;
- }
-
- public UnitType[] GetSystemUnitTypes(Category cat)
- {
- UnitType[] items = new UnitType[0];
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- items = defaultRace.GetUnitTypes(cat);
- }
-
- return items;
- }
-
- public UnitType GetSystemUnitType(string id)
- {
- UnitType unit = null;
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- unit = defaultRace.GetUnitType(id);
- }
-
- return unit;
- }
-
- public List GetSystemAbilityList()
- {
- List items = new List();
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- items = defaultRace.GetAbilityList();
- }
-
- return items;
- }
-
- public Ability GetSystemAbility(string id)
- {
- Ability ability = null;
- Race defaultRace = SystemDefaultRace;
-
- if (defaultRace!=null)
- {
- ability = defaultRace.GetAbility(id);
- }
-
- return ability;
- }
- }
-}
+// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
+//
+// 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.
+
+using System;
+using System.Collections.Generic;
+using System.Xml;
+using System.IO;
+using IBBoard.Logging;
+using IBBoard.WarFoundry.API.Factories;
+using ICSharpCode.SharpZipLib.Zip;
+
+namespace IBBoard.WarFoundry.API.Objects
+{
+ ///
+ /// Summary description for GameSystem.
+ ///
+ public class GameSystem : WarFoundryStagedLoadingObject
+ {
+ private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000;
+ private bool warnOnError;
+ private bool allowAllies;
+ private Dictionary categories = new Dictionary();
+ private Dictionary stats = new Dictionary();
+ private string defaultStats;
+ private int defaultArmySize;
+
+ public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory)
+ : base(systemID, systemName, creatingFactory)
+ {
+ stats = new Dictionary();
+ }
+
+ public int SystemArmyDefaultSize
+ {
+ get { return defaultArmySize; }
+ set
+ {
+ if (value == 0)
+ {
+ defaultArmySize = SYSTEM_DEFAULT_ARMY_SIZE;
+ }
+ else
+ {
+ defaultArmySize = value;
+ }
+ }
+ }
+
+ public bool AllowAllies
+ {
+ get { return allowAllies; }
+ set { allowAllies = value; }
+ }
+
+ public void AddCategory(Category cat)
+ {
+ RawCategories[cat.ID] = cat;
+ }
+
+ public Category GetCategory(string id)
+ {
+ EnsureFullyLoaded();
+ Category cat = null;
+ RawCategories.TryGetValue(id, out cat);
+ return cat;
+ }
+
+ public Category[] Categories
+ {
+ get
+ {
+ EnsureFullyLoaded();
+ return DictionaryUtils.ToArray(RawCategories);
+ }
+ }
+
+ protected Dictionary RawCategories
+ {
+ get { return categories; }
+ }
+
+ public bool WarnOnError
+ {
+ get
+ {
+ return warnOnError;
+ }
+ set { warnOnError = value; }
+ }
+
+ public void AddSystemStats(SystemStats sysStats)
+ {
+ stats[sysStats.ID] = sysStats;
+ }
+
+ public SystemStats StandardSystemStats
+ {
+ get
+ {
+ EnsureFullyLoaded();
+ return stats[defaultStats];
+ }
+ }
+
+ public string StandardSystemStatsID
+ {
+ get
+ {
+ EnsureFullyLoaded();
+ return defaultStats;
+ }
+
+ set
+ {
+ if (value != null && value.Trim().Length > 0)
+ {
+ defaultStats = value;
+ }
+ }
+ }
+
+ public SystemStats[] SystemStats
+ {
+ get
+ {
+ EnsureFullyLoaded();
+ SystemStats[] statsArray = new SystemStats[stats.Count];
+ stats.Values.CopyTo(statsArray, 0);
+ return statsArray;
+ }
+ }
+
+ public SystemStats GetSystemStatsForID(string id)
+ {
+ EnsureFullyLoaded();
+ SystemStats statsForID;
+ stats.TryGetValue(id, out statsForID);
+ return statsForID;
+ }
+
+ public Race SystemDefaultRace
+ {
+ get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
+ }
+
+ public bool Matches(GameSystem otherSystem)
+ {
+ if (otherSystem==null)
+ {
+ return false;
+ }
+
+ return this.ID == otherSystem.ID;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+
+ if (obj.GetType().Equals(this.GetType()))
+ {
+ GameSystem otherSystem = (GameSystem)obj;
+
+ return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
+ }
+
+ public bool UnitTypeMaxed(UnitType unitType, Army army)
+ {
+ return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
+ }
+
+ public bool UnitTypeMinned(UnitType unitType, Army army)
+ {
+ return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
+ }
+
+ public List GetSystemEquipmentList()
+ {
+ List items = new List();
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ items = defaultRace.GetEquipmentList();
+ }
+
+ return items;
+ }
+
+ public EquipmentItem GetSystemEquipmentItem(string id)
+ {
+ EquipmentItem item = null;
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ item = defaultRace.GetEquipmentItem(id);
+ }
+
+ return item;
+ }
+
+ public UnitType[] GetSystemUnitTypes(Category cat)
+ {
+ UnitType[] items = new UnitType[0];
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ items = defaultRace.GetUnitTypes(cat);
+ }
+
+ return items;
+ }
+
+ public UnitType GetSystemUnitType(string id)
+ {
+ UnitType unit = null;
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ unit = defaultRace.GetUnitType(id);
+ }
+
+ return unit;
+ }
+
+ public List GetSystemAbilityList()
+ {
+ List items = new List();
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ items = defaultRace.GetAbilityList();
+ }
+
+ return items;
+ }
+
+ public Ability GetSystemAbility(string id)
+ {
+ Ability ability = null;
+ Race defaultRace = SystemDefaultRace;
+
+ if (defaultRace!=null)
+ {
+ ability = defaultRace.GetAbility(id);
+ }
+
+ return ability;
+ }
+ }
+}
diff -r 121d9d1ba53c -r 4e0031339bcb schemas/system.xsd
--- a/schemas/system.xsd Sun Nov 21 21:53:16 2010 +0000
+++ b/schemas/system.xsd Sun Dec 12 15:27:07 2010 +0000
@@ -39,6 +39,7 @@
+