Mercurial > repos > IBBoard.WarFoundry.API
diff api/Objects/GameSystem.cs @ 392:db6713d5b35f default-army-size
RRe #97: Default army size issues
author | snowblizz |
---|---|
date | Wed, 01 Dec 2010 20:00:58 +0000 |
parents | d576034ad1dd |
children | b90db11edc64 |
line wrap: on
line diff
--- a/api/Objects/GameSystem.cs Mon Oct 18 19:59:25 2010 +0000 +++ b/api/Objects/GameSystem.cs Wed Dec 01 20:00:58 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> - /// Summary description for GameSystem. - /// </summary> - public class GameSystem : WarFoundryStagedLoadingObject - { - private bool warnOnError; - private bool allowAllies; - private Dictionary<string, Category> categories = new Dictionary<string,Category>(); - private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); - private string defaultStats; - - public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) - { - stats = new Dictionary<string,SystemStats>(); - } - - 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<string, Category>(RawCategories); - } - } - - protected Dictionary<string, Category> 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<EquipmentItem> GetSystemEquipmentList() - { - List<EquipmentItem> items = new List<EquipmentItem>(); - 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<Ability> GetSystemAbilityList() - { - List<Ability> items = new List<Ability>(); - 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> + /// Summary description for GameSystem. + /// </summary> + public class GameSystem : WarFoundryStagedLoadingObject + { + + private bool warnOnError; + private bool allowAllies; + private Dictionary<string, Category> categories = new Dictionary<string,Category>(); + private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); + private string defaultStats; + private int defaultArmySize; + + public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) + : base(systemID, systemName, creatingFactory) + { + stats = new Dictionary<string,SystemStats>(); + } + + public int SystemArmyDefaultSize + { + get { return defaultArmySize; } + set + { + if (value == 0) + { + defaultArmySize = 1; + throw new ArgumentException("No default system army size"); + + } + + 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<string, Category>(RawCategories); + } + } + + protected Dictionary<string, Category> 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<EquipmentItem> GetSystemEquipmentList() + { + List<EquipmentItem> items = new List<EquipmentItem>(); + 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<Ability> GetSystemAbilityList() + { + List<Ability> items = new List<Ability>(); + 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; + } + } +}