comparison 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
comparison
equal deleted inserted replaced
96:ced5a18d9f52 97:95746083d037
17 } 17 }
18 18
19 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinPercentage) 19 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinPercentage)
20 { 20 {
21 } 21 }
22 22
23 public override double TotalCost 23 public override int NumberTaken
24 { 24 {
25 get 25 get
26 { 26 {
27 return CalculateAmount() * EquipmentItem.Cost; 27 double numberTaken = AmountTaken * EquipmentForUnit.Size;
28 return (int) (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
28 } 29 }
29 } 30 }
30
31 private double CalculateAmount()
32 {
33 double numberTaken = AmountTaken * EquipmentForUnit.Size;
34 return (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
35 }
36 31
37 protected override bool IsValidValue (double newValue) 32 protected override bool IsInRange (double newValue)
38 { 33 {
39 return (EquipmentItem.MinPercentage <= newValue) && (newValue <= EquipmentItem.MaxPercentage); 34 return (EquipmentItem.MinPercentage <= newValue) && (newValue <= EquipmentItem.MaxPercentage);
40 } 35 }
41 } 36 }
42 } 37 }