# HG changeset patch # User snowblizz # Date 1295887363 0 # Node ID d051f8f44e6c44a9b0c0609c70ff46e247cf8388 # Parent 4e0031339bcb524c729b407aadfea3e9e82473b2 Re #99: added points name system to GameSystem diff -r 4e0031339bcb -r d051f8f44e6c api/Objects/GameSystem.cs --- a/api/Objects/GameSystem.cs Sun Dec 12 15:27:07 2010 +0000 +++ b/api/Objects/GameSystem.cs Mon Jan 24 16:42:43 2011 +0000 @@ -7,33 +7,44 @@ using System.Xml; using System.IO; using IBBoard.Logging; +using IBBoard.Lang; 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; + /// + /// Summary description for GameSystem. + /// + public class GameSystem : WarFoundryStagedLoadingObject + { + private static decimal 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; + private bool allowAllies; + private Dictionary categories = new Dictionary(); + private Dictionary stats = new Dictionary(); + private string defaultStats; + private decimal defaultArmySize; + private string systemPtsAbbrevSingle; + private string systemPtsAbbrevPlural; + private string systemPtsNameSingle; + private string systemPtsNamePlural; + private string pointsAbbrevSingle; + private string pointsAbbrevPlural; + public string pointsAbbreviation; + private string pointsNameSingle; + private string pointsNamePlural; + public string pointsName; public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) - { - stats = new Dictionary(); - } + { + stats = new Dictionary(); + } - public int SystemArmyDefaultSize + public decimal SystemArmyDefaultSize { - get { return defaultArmySize; } + get { return defaultArmySize; } set { if (value == 0) @@ -46,224 +57,383 @@ } } } - - public bool AllowAllies - { - get { return allowAllies; } - set { allowAllies = value; } - } - - public void AddCategory(Category cat) - { - RawCategories[cat.ID] = cat; - } + + public string SystemPtsAbbrevSingle + { + get { return systemPtsAbbrevSingle; } + set { systemPtsAbbrevSingle = value; } + } + public string SystemPtsAbbrevPlural + { + get { return systemPtsAbbrevPlural; } + set { systemPtsAbbrevPlural = value; } + } + public string SystemPtsNameSingle + { + get { return systemPtsNameSingle; } + set { systemPtsNameSingle = value; } + } + public string SystemPtsNamePlural + { + get { return systemPtsNamePlural; } + set { systemPtsNamePlural = 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 void SetCategory(Category cat) + { + Category old; + RawCategories.TryGetValue(cat.ID, out old); - public Category GetCategory(string id) - { - EnsureFullyLoaded(); - Category cat = null; - RawCategories.TryGetValue(id, out cat); - return cat; - } + if (old == null) + { + AddCategory(cat); + } + else + { + if (!old.Equals(cat)) + { + RawCategories[old.ID] = cat; + } + } + } + + public void RemoveCategory(string id) + { + RawCategories.Remove(id); + } - public Category[] Categories - { - get - { - EnsureFullyLoaded(); - return DictionaryUtils.ToArray(RawCategories); - } - } - - protected Dictionary RawCategories - { - get { return categories; } - } + 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 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 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 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 void SetSystemStats(SystemStats newStats) + { + SystemStats old; + stats.TryGetValue(newStats.ID, out old); + + if (old == null) + { + AddSystemStats(newStats); + } + else + { + if (!old.Equals(newStats)) + { + stats[old.ID] = newStats; + } + } + } + + public void RemoveSystemStats(string id) + { + stats.Remove(id); + } - public bool Matches(GameSystem otherSystem) - { - if (otherSystem==null) - { - return false; - } + 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; - } + 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; - 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; + } - return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); - } - else - { - return false; - } - } + 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); + } - public override int GetHashCode() - { - return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); - } + return unit; + } + + public List GetSystemAbilityList() + { + List items = new List(); + Race defaultRace = SystemDefaultRace; + + if (defaultRace != null) + { + items = defaultRace.GetAbilityList(); + } - public bool UnitTypeMaxed(UnitType unitType, Army army) - { - return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; - } + return items; + } + + public Ability GetSystemAbility(string id) + { + Ability ability = null; + Race defaultRace = SystemDefaultRace; + + if (defaultRace != null) + { + ability = defaultRace.GetAbility(id); + } - 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; - } - } + return ability; + } + public string UsePointsAbbrev(double pointTemp) + { + if (pointTemp == 1) + { + pointsAbbreviation = pointsAbbrevSingle; + } + else + { + pointsAbbreviation = pointsAbbrevPlural; + } + return pointsAbbreviation; + } + + public string UsePointsName(double pointTemp) + { + + if (pointTemp == 1) + { + pointsName = pointsNameSingle; + } + else + { + pointsName = pointsNamePlural; + } + return pointsName; + } + public void LoadPointsSystemNames() + { + if (this != null) + { + LoadPointsAbbrevPlural(); + LoadPointsAbbrevSingle(); + LoadPointsNamePlural(); + LoadPointsNameSingle(); + } + } + private void LoadPointsAbbrevPlural() + { + // Use this before calling on pointsAbbreviationPlural to "populate" the variable + + if (SystemPtsAbbrevPlural == "") + { + pointsAbbrevPlural = String.Format(Translation.GetTranslation("PointsLocalisationAbbrevPlural")); + } + else + { + pointsAbbrevPlural = SystemPtsAbbrevPlural; + } + + } + private void LoadPointsAbbrevSingle() + { + // Use this before calling on pointsAbbreviationSingle to "populate" the variable + if (SystemPtsAbbrevSingle == "") + { + pointsAbbrevSingle = String.Format(Translation.GetTranslation("PointsLocalisationAbbrevSingle")); + } + else + { + pointsAbbrevSingle = SystemPtsAbbrevSingle; + } + } + private void LoadPointsNamePlural() + { + // Use this before calling on pointsNamePlural to "populate" the variable + if (SystemPtsNamePlural == "") + { + pointsNamePlural = String.Format(Translation.GetTranslation("PointsLocalisationNamePlural")); + } + else + { + pointsNamePlural = SystemPtsNamePlural; + } + + } + + private void LoadPointsNameSingle() + { + // Use this before calling on pointsNameSingle to "populate" the variable + if (SystemPtsNameSingle == "") + { + pointsNameSingle = String.Format(Translation.GetTranslation("PointsLocalisationNameSingle")); + } + else + { + pointsNameSingle = SystemPtsNameSingle; + } + } + + public string setUnitEquipmentItemName(string itemName,double pointsTemp) + { + return itemName + Translation.GetTranslation("setUnitEquipmentItemName", "({0}pts each)", pointsTemp, UsePointsAbbrev(pointsTemp)); + } + } }