comparison api/Objects/UnitEquipmentNumericSelection.cs @ 183:36adabb1c3ea

Re #198: Add slots with counts to units * Remove old Min/MaxNumber/Percentage for equipment and replace with limits * Refactor equipment selections and remove "numeric for ratio" as the limits handle the upper/lower limit differences * Stop equipment selections taking an amount of 0 for out of range amounts * Add "IsValid" property for selections * Removed use of "-1" as an 'infinity' limit - now use 100% as a more correct value * Change "unlimitedSize" limit in schema to "unitSizeLimit"
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Oct 2009 20:55:04 +0000
parents 2f3cafb69799
children dce340f9cedc
comparison
equal deleted inserted replaced
182:6fe336109128 183:36adabb1c3ea
13 { 13 {
14 public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount) 14 public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
15 { 15 {
16 } 16 }
17 17
18 public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinNumber) 18 public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinLimit.GetLimit(unit.Size))
19 { 19 {
20 } 20 }
21 21
22 public override int NumberTaken 22 public override int NumberTaken
23 { 23 {
24 get 24 get
25 { 25 {
26 return (AmountTaken == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : (int) AmountTaken); 26 return (int) AmountTaken;
27 } 27 }
28 } 28 }
29 29
30 protected bool IsWholeNumber(double newValue) 30 protected bool IsWholeNumber(double newValue)
31 { 31 {
32 return newValue == Math.Round(newValue); 32 return newValue == Math.Round(newValue);
33 } 33 }
34 34
35 protected override bool IsInRange(double newValue) 35 protected override bool IsValidValue (double newValue)
36 { 36 {
37 bool isInRange = IsWholeNumber(newValue); 37 return base.IsValidValue(newValue) && IsWholeNumber(newValue);
38
39 if (newValue == WarFoundryCore.INFINITY)
40 {
41 isInRange = (EquipmentItem.MaxNumber == WarFoundryCore.INFINITY);
42 }
43 else if (isInRange)
44 {
45 int minLimit = (EquipmentItem.MinNumber == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : EquipmentItem.MinNumber);
46 int maxLimit = (EquipmentItem.MaxNumber == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : EquipmentItem.MaxNumber);
47 isInRange = (minLimit <= newValue) && (newValue <= maxLimit);
48 }
49
50 return isInRange;
51 } 38 }
52 39
53 public override string GetEquipmentAmountString () 40 public override string GetEquipmentAmountString ()
54 { 41 {
55 return GetEquipmentAmountString(AmountTaken); 42 return GetEquipmentAmountString(AmountTaken);
64 /// <returns> 51 /// <returns>
65 /// A <see cref="System.String"/> 52 /// A <see cref="System.String"/>
66 /// </returns> 53 /// </returns>
67 public static string GetEquipmentAmountString(double amount) 54 public static string GetEquipmentAmountString(double amount)
68 { 55 {
69 string amountString; 56 return amount.ToString();
70
71 if (amount == WarFoundryCore.INFINITY)
72 {
73 amountString = "all"; //TODO: Translate
74 }
75 else
76 {
77 amountString = amount.ToString();
78 }
79
80 return amountString;
81 } 57 }
82 } 58 }
83 } 59 }