changeset 306:886d28c1b6e5

Re #99: Define points systems * Simplify the code and leave translations until we support them Re #329 and re #327: Use "points" in UI * Use new method in UnitEquipmentItem object's ToString() method
author IBBoard <dev@ibboard.co.uk>
date Sun, 13 Feb 2011 16:24:12 +0000
parents 92d10b06ab0f
children afa7a5dd0eea
files api/Objects/EquipmentItem.cs api/Objects/GameSystem.cs api/Objects/UnitEquipmentItem.cs
diffstat 3 files changed, 129 insertions(+), 95 deletions(-) [+]
line diff
     1.1 --- a/api/Objects/EquipmentItem.cs	Wed Jan 26 20:27:50 2011 +0000
     1.2 +++ b/api/Objects/EquipmentItem.cs	Sun Feb 13 16:24:12 2011 +0000
     1.3 @@ -44,6 +44,11 @@
     1.4  		{
     1.5  			get { return equipForRace; }
     1.6  		}
     1.7 +		
     1.8 +		public GameSystem GameSystem
     1.9 +		{
    1.10 +			get { return equipForRace.GameSystem; }
    1.11 +		}
    1.12  
    1.13  		public bool CanBeUsedWithItem(EquipmentItem item)
    1.14  		{
     2.1 --- a/api/Objects/GameSystem.cs	Wed Jan 26 20:27:50 2011 +0000
     2.2 +++ b/api/Objects/GameSystem.cs	Sun Feb 13 16:24:12 2011 +0000
     2.3 @@ -1,14 +1,9 @@
     2.4 -// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
     2.5 +// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009, 2010, 2011 IBBoard.
     2.6  //
     2.7  // 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.
     2.8  
     2.9 -using System;
    2.10  using System.Collections.Generic;
    2.11 -using System.Xml;
    2.12 -using System.IO;
    2.13 -using IBBoard.Logging;
    2.14  using IBBoard.WarFoundry.API.Factories;
    2.15 -using ICSharpCode.SharpZipLib.Zip;
    2.16  
    2.17  namespace IBBoard.WarFoundry.API.Objects
    2.18  {
    2.19 @@ -17,41 +12,65 @@
    2.20  	/// </summary>
    2.21  	public class GameSystem : WarFoundryStagedLoadingObject
    2.22  	{
    2.23 -        private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000;
    2.24 -        private bool warnOnError;
    2.25 +		private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000;
    2.26 +		private bool warnOnError;
    2.27  		private bool allowAllies;
    2.28 -		private Dictionary<string, Category> categories = new Dictionary<string,Category>();
    2.29 -		private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>();
    2.30 +		private Dictionary<string, Category> categories = new Dictionary<string, Category>();
    2.31 +		private Dictionary<string, SystemStats> stats = new Dictionary<string, SystemStats>();
    2.32  		private string defaultStats;
    2.33 -        private int defaultArmySize;
    2.34 +		private int defaultArmySize;
    2.35 +		private string systemPtsAbbrevSingle;
    2.36 +		private string systemPtsAbbrevPlural;
    2.37 +		private string systemPtsNameSingle;
    2.38 +		private string systemPtsNamePlural;
    2.39  
    2.40  		public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory)
    2.41  		{
    2.42 -			stats = new Dictionary<string,SystemStats>();
    2.43 +			stats = new Dictionary<string, SystemStats>();
    2.44  		}
    2.45  
    2.46 -        public int SystemArmyDefaultSize
    2.47 -        {
    2.48 -            get { return  defaultArmySize; }
    2.49 -            set
    2.50 -            {
    2.51 -                if (value == 0)
    2.52 -                {
    2.53 -                    defaultArmySize = SYSTEM_DEFAULT_ARMY_SIZE;
    2.54 -                }
    2.55 -                else
    2.56 -                {
    2.57 -                    defaultArmySize = value;
    2.58 -                }
    2.59 -            }
    2.60 -        }
    2.61 -		
    2.62 +		public int SystemArmyDefaultSize
    2.63 +		{
    2.64 +			get { return defaultArmySize; }
    2.65 +			set
    2.66 +			{
    2.67 +				if (value == 0)
    2.68 +				{
    2.69 +					defaultArmySize = SYSTEM_DEFAULT_ARMY_SIZE;
    2.70 +				}
    2.71 +				else
    2.72 +				{
    2.73 +					defaultArmySize = value;
    2.74 +				}
    2.75 +			}
    2.76 +			}
    2.77 +
    2.78 +		public string SystemPtsAbbrevSingle
    2.79 +		{
    2.80 +			get { return systemPtsAbbrevSingle; }
    2.81 +			set { systemPtsAbbrevSingle = value; }
    2.82 +		}
    2.83 +		public string SystemPtsAbbrevPlural
    2.84 +		{
    2.85 +			get { return systemPtsAbbrevPlural; }
    2.86 +			set { systemPtsAbbrevPlural = value; }
    2.87 +		}
    2.88 +		public string SystemPtsNameSingle
    2.89 +		{
    2.90 +			get { return systemPtsNameSingle; }
    2.91 +			set { systemPtsNameSingle = value; }
    2.92 +		}
    2.93 +		public string SystemPtsNamePlural
    2.94 +		{
    2.95 +			get { return systemPtsNamePlural; }
    2.96 +			set { systemPtsNamePlural = value; }
    2.97 +		}
    2.98  		public bool AllowAllies
    2.99  		{
   2.100  			get { return allowAllies; }
   2.101  			set { allowAllies = value; }
   2.102  		}
   2.103 -		
   2.104 +
   2.105  		public void AddCategory(Category cat)
   2.106  		{
   2.107  			RawCategories[cat.ID] = cat;
   2.108 @@ -64,25 +83,25 @@
   2.109  			RawCategories.TryGetValue(id, out cat);
   2.110  			return cat;
   2.111  		}
   2.112 -		
   2.113 +
   2.114  		public void SetCategory(Category cat)
   2.115  		{
   2.116  			Category old;
   2.117  			RawCategories.TryGetValue(cat.ID, out old);
   2.118 -			
   2.119 -			if(old == null)
   2.120 +
   2.121 +			if (old == null)
   2.122  			{
   2.123  				AddCategory(cat);
   2.124  			}
   2.125  			else
   2.126  			{
   2.127 -				if(!old.Equals(cat))
   2.128 +				if (!old.Equals(cat))
   2.129  				{
   2.130  					RawCategories[old.ID] = cat;
   2.131  				}
   2.132  			}
   2.133  		}
   2.134 -		
   2.135 +
   2.136  		public void RemoveCategory(string id)
   2.137  		{
   2.138  			RawCategories.Remove(id);
   2.139 @@ -90,13 +109,13 @@
   2.140  
   2.141  		public Category[] Categories
   2.142  		{
   2.143 -			get 
   2.144 -			{ 
   2.145 +			get
   2.146 +			{
   2.147  				EnsureFullyLoaded();
   2.148 -				return DictionaryUtils.ToArray<string, Category>(RawCategories); 
   2.149 +				return DictionaryUtils.ToArray<string, Category>(RawCategories);
   2.150  			}
   2.151  		}
   2.152 -		
   2.153 +
   2.154  		protected Dictionary<string, Category> RawCategories
   2.155  		{
   2.156  			get { return categories; }
   2.157 @@ -110,12 +129,12 @@
   2.158  			}
   2.159  			set { warnOnError = value; }
   2.160  		}
   2.161 -		
   2.162 +
   2.163  		public void AddSystemStats(SystemStats sysStats)
   2.164  		{
   2.165  			stats[sysStats.ID] = sysStats;
   2.166  		}
   2.167 -		
   2.168 +
   2.169  		public SystemStats StandardSystemStats
   2.170  		{
   2.171  			get
   2.172 @@ -124,7 +143,7 @@
   2.173  				return stats[defaultStats];
   2.174  			}
   2.175  		}
   2.176 -		
   2.177 +
   2.178  		public string StandardSystemStatsID
   2.179  		{
   2.180  			get
   2.181 @@ -132,7 +151,7 @@
   2.182  				EnsureFullyLoaded();
   2.183  				return defaultStats;
   2.184  			}
   2.185 -			
   2.186 +
   2.187  			set
   2.188  			{
   2.189  				if (value != null && value.Trim().Length > 0)
   2.190 @@ -144,15 +163,15 @@
   2.191  
   2.192  		public SystemStats[] SystemStats
   2.193  		{
   2.194 -			get 
   2.195 -			{ 
   2.196 +			get
   2.197 +			{
   2.198  				EnsureFullyLoaded();
   2.199  				SystemStats[] statsArray = new SystemStats[stats.Count];
   2.200  				stats.Values.CopyTo(statsArray, 0);
   2.201  				return statsArray;
   2.202  			}
   2.203  		}
   2.204 -		
   2.205 +
   2.206  		public SystemStats GetSystemStatsForID(string id)
   2.207  		{
   2.208  			EnsureFullyLoaded();
   2.209 @@ -160,30 +179,30 @@
   2.210  			stats.TryGetValue(id, out statsForID);
   2.211  			return statsForID;
   2.212  		}
   2.213 -		
   2.214 +
   2.215  		public void SetSystemStats(SystemStats newStats)
   2.216  		{
   2.217  			SystemStats old;
   2.218  			stats.TryGetValue(newStats.ID, out old);
   2.219 -			
   2.220 -			if(old == null)
   2.221 +
   2.222 +			if (old == null)
   2.223  			{
   2.224  				AddSystemStats(newStats);
   2.225  			}
   2.226  			else
   2.227  			{
   2.228 -				if(!old.Equals(newStats))
   2.229 +				if (!old.Equals(newStats))
   2.230  				{
   2.231  					stats[old.ID] = newStats;
   2.232  				}
   2.233  			}
   2.234  		}
   2.235 -		
   2.236 +
   2.237  		public void RemoveSystemStats(string id)
   2.238  		{
   2.239  			stats.Remove(id);
   2.240  		}
   2.241 -		
   2.242 +
   2.243  		public Race SystemDefaultRace
   2.244  		{
   2.245  			get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
   2.246 @@ -191,7 +210,7 @@
   2.247  
   2.248  		public bool Matches(GameSystem otherSystem)
   2.249  		{
   2.250 -			if (otherSystem==null)
   2.251 +			if (otherSystem == null)
   2.252  			{
   2.253  				return false;
   2.254  			}
   2.255 @@ -203,9 +222,9 @@
   2.256  		{
   2.257  			if (obj == null)
   2.258  			{
   2.259 -				return false;		
   2.260 +				return false;
   2.261  			}
   2.262 -			
   2.263 +
   2.264  			if (obj.GetType().Equals(this.GetType()))
   2.265  			{
   2.266  				GameSystem otherSystem = (GameSystem)obj;
   2.267 @@ -220,95 +239,105 @@
   2.268  
   2.269  		public override int GetHashCode()
   2.270  		{
   2.271 -			return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
   2.272 +			return ID.GetHashCode() + Name.GetHashCode() + (RawCategories != null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
   2.273  		}
   2.274  
   2.275  		public bool UnitTypeMaxed(UnitType unitType, Army army)
   2.276  		{
   2.277 -			return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
   2.278 +			return unitType.MaxNumber != WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
   2.279  		}
   2.280  
   2.281  		public bool UnitTypeMinned(UnitType unitType, Army army)
   2.282  		{
   2.283  			return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
   2.284  		}
   2.285 -		
   2.286 +
   2.287  		public List<EquipmentItem> GetSystemEquipmentList()
   2.288  		{
   2.289  			List<EquipmentItem> items = new List<EquipmentItem>();
   2.290  			Race defaultRace = SystemDefaultRace;
   2.291 -			
   2.292 -			if (defaultRace!=null)
   2.293 -			{				
   2.294 +
   2.295 +			if (defaultRace != null)
   2.296 +			{
   2.297  				items = defaultRace.GetEquipmentList();
   2.298  			}
   2.299 -			
   2.300 +
   2.301  			return items;
   2.302  		}
   2.303 -				
   2.304 +
   2.305  		public EquipmentItem GetSystemEquipmentItem(string id)
   2.306  		{
   2.307  			EquipmentItem item = null;
   2.308  			Race defaultRace = SystemDefaultRace;
   2.309 -			
   2.310 -			if (defaultRace!=null)
   2.311 -			{				
   2.312 +
   2.313 +			if (defaultRace != null)
   2.314 +			{
   2.315  				item = defaultRace.GetEquipmentItem(id);
   2.316  			}
   2.317 -			
   2.318 +
   2.319  			return item;
   2.320  		}
   2.321 -		
   2.322 +
   2.323  		public UnitType[] GetSystemUnitTypes(Category cat)
   2.324  		{
   2.325  			UnitType[] items = new UnitType[0];
   2.326  			Race defaultRace = SystemDefaultRace;
   2.327 -			
   2.328 -			if (defaultRace!=null)
   2.329 -			{				
   2.330 +
   2.331 +			if (defaultRace != null)
   2.332 +			{
   2.333  				items = defaultRace.GetUnitTypes(cat);
   2.334  			}
   2.335 -			
   2.336 +
   2.337  			return items;
   2.338  		}
   2.339 -				
   2.340 +
   2.341  		public UnitType GetSystemUnitType(string id)
   2.342  		{
   2.343  			UnitType unit = null;
   2.344  			Race defaultRace = SystemDefaultRace;
   2.345 -			
   2.346 -			if (defaultRace!=null)
   2.347 -			{				
   2.348 +
   2.349 +			if (defaultRace != null)
   2.350 +			{
   2.351  				unit = defaultRace.GetUnitType(id);
   2.352  			}
   2.353 -			
   2.354 +
   2.355  			return unit;
   2.356  		}
   2.357 -		
   2.358 +
   2.359  		public List<Ability> GetSystemAbilityList()
   2.360  		{
   2.361  			List<Ability> items = new List<Ability>();
   2.362  			Race defaultRace = SystemDefaultRace;
   2.363 -			
   2.364 -			if (defaultRace!=null)
   2.365 -			{				
   2.366 +
   2.367 +			if (defaultRace != null)
   2.368 +			{
   2.369  				items = defaultRace.GetAbilityList();
   2.370  			}
   2.371 -			
   2.372 +
   2.373  			return items;
   2.374  		}
   2.375 -				
   2.376 +
   2.377  		public Ability GetSystemAbility(string id)
   2.378  		{
   2.379  			Ability ability = null;
   2.380  			Race defaultRace = SystemDefaultRace;
   2.381 -			
   2.382 -			if (defaultRace!=null)
   2.383 -			{				
   2.384 +
   2.385 +			if (defaultRace != null)
   2.386 +			{
   2.387  				ability = defaultRace.GetAbility(id);
   2.388  			}
   2.389 -			
   2.390 +
   2.391  			return ability;
   2.392  		}
   2.393 +		
   2.394 +		public string GetPointsAbbrev(double pointTemp)
   2.395 +		{
   2.396 +			return (pointTemp == 1 ? SystemPtsAbbrevSingle : SystemPtsAbbrevPlural);
   2.397 +		}
   2.398 +
   2.399 +		public string GetPointsName(double pointTemp)
   2.400 +		{
   2.401 +			return (pointTemp == 1 ? SystemPtsNameSingle : SystemPtsNamePlural);
   2.402 +		}
   2.403  	}
   2.404  }
     3.1 --- a/api/Objects/UnitEquipmentItem.cs	Wed Jan 26 20:27:50 2011 +0000
     3.2 +++ b/api/Objects/UnitEquipmentItem.cs	Sun Feb 13 16:24:12 2011 +0000
     3.3 @@ -5,7 +5,8 @@
     3.4  using System;
     3.5  using IBBoard.CustomMath;
     3.6  using IBBoard.Limits;
     3.7 -using IBBoard.WarFoundry.API.Util;
     3.8 +using IBBoard.WarFoundry.API.Util;
     3.9 +using IBBoard.Lang;
    3.10  //using IBBoard.WarFoundry.API.Objects;
    3.11  
    3.12  namespace IBBoard.WarFoundry.API.Objects
    3.13 @@ -24,12 +25,7 @@
    3.14  		private UnitType unitType;
    3.15  		private string slotName = "";
    3.16  		private ILimit minLimit;
    3.17 -		private ILimit maxLimit;
    3.18 -        public GameSystem CurrentGameSystem
    3.19 -        {
    3.20 -            get { return WarFoundryCore.CurrentGameSystem; }
    3.21 -            set { WarFoundryCore.CurrentGameSystem = value; }
    3.22 -        }
    3.23 +		private ILimit maxLimit;
    3.24  		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor)
    3.25  			: this(equipmentItem, equipmentFor, new string[0])
    3.26  		{
    3.27 @@ -68,7 +64,6 @@
    3.28  			}
    3.29  		}
    3.30  
    3.31 -
    3.32  		public string EquipmentItemID
    3.33  		{
    3.34  			get { return item.ID; }
    3.35 @@ -111,6 +106,11 @@
    3.36  			get { return roundUp; }
    3.37  			set { roundUp = value; }
    3.38  		}
    3.39 +		
    3.40 +		public GameSystem GameSystem
    3.41 +		{
    3.42 +			get { return EquipmentItem.GameSystem; }
    3.43 +		}
    3.44  
    3.45  		public String[] MutexGroups
    3.46  		{
    3.47 @@ -198,7 +198,7 @@
    3.48  
    3.49  		public override string ToString()
    3.50  		{
    3.51 -            return CurrentGameSystem.setUnitEquipmentItemName(EquipmentItem.Name, Cost);
    3.52 +            return Translation.GetTranslation("UnitEquipmentItemName", "{0} ({1}{2} each)", Name, Cost, GameSystem.GetPointsAbbrev(Cost));
    3.53  		}
    3.54  
    3.55  		public bool HasAlternatives()