diff api/Objects/UnitEquipmentRatioSelection.cs @ 97:95746083d037

Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts * Add extra "NumericSelection" type so that ratio selections check the absolute value is within their ratio range * Update structure of checking for valid values * Move cost calculation for equipment selection in to abstract class and add abstract method to get "number of items taken" * Handle numeric selection and numeric selection for ratio differently in Unit
author IBBoard <dev@ibboard.co.uk>
date Sun, 09 Aug 2009 12:02:35 +0000
parents 6c6cfe5594fc
children f7b9423c2a5a
line wrap: on
line diff
--- a/api/Objects/UnitEquipmentRatioSelection.cs	Sun Aug 09 11:09:12 2009 +0000
+++ b/api/Objects/UnitEquipmentRatioSelection.cs	Sun Aug 09 12:02:35 2009 +0000
@@ -19,22 +19,17 @@
 		public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinPercentage)
 		{
 		}
-		
-		public override double TotalCost
+					
+		public override int NumberTaken
 		{
 			get
 			{
-				return CalculateAmount() * EquipmentItem.Cost;
+				double numberTaken = AmountTaken * EquipmentForUnit.Size;
+				return (int) (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
 			}
 		}
-					
-		private double CalculateAmount()
-		{
-			double numberTaken = AmountTaken * EquipmentForUnit.Size;
-			return (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
-		}
 		
-		protected override bool IsValidValue (double newValue)
+		protected override bool IsInRange (double newValue)
 		{
 			return (EquipmentItem.MinPercentage <= newValue) && (newValue <= EquipmentItem.MaxPercentage);
 		}