comparison API/Objects/UnitEquipmentRatioSelection.cs @ 431:c8002429ab45

Re #366: Rewrite equipment handling and limits * Remove code added for #356 and work without limiting * Move "Calculate number taken" method to util class
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Nov 2011 20:35:15 +0000
parents 7179c585d31d
children
comparison
equal deleted inserted replaced
430:7e95b880f9cc 431:c8002429ab45
29 { 29 {
30 return CalculateNumberTaken(EquipmentForUnit, EquipmentItem, AmountTaken); 30 return CalculateNumberTaken(EquipmentForUnit, EquipmentItem, AmountTaken);
31 } 31 }
32 } 32 }
33 33
34 public override int RawNumberTaken 34 private static int CalculateNumberTaken(Unit unit, UnitEquipmentItem item, double ratioTaken)
35 {
36 get
37 {
38 return CalculateRawNumberTaken(EquipmentForUnit, EquipmentItem, AmountTaken);
39 }
40 }
41
42 internal static int CalculateNumberTaken(Unit unit, UnitEquipmentItem item, double ratioTaken)
43 {
44 int wholeNumberTaken = CalculateRawNumberTaken(unit, item, ratioTaken);
45 int maxTaken = Int32.MaxValue;
46 int minTaken = 0;
47
48 if (wholeNumberTaken > 0)
49 {
50 maxTaken = UnitEquipmentUtil.GetMaxEquipmentCount(unit, item);
51 }
52
53 minTaken = UnitEquipmentUtil.GetMinEquipmentCount(unit, item);
54 return Math.Min(Math.Max(wholeNumberTaken, minTaken), maxTaken);
55 }
56
57 private static int CalculateRawNumberTaken (Unit unit, UnitEquipmentItem item, double ratioTaken)
58 { 35 {
59 double exactNumberTaken = (ratioTaken / 100) * unit.Size; 36 double exactNumberTaken = (ratioTaken / 100) * unit.Size;
60 return (int)IBBMath.Round(exactNumberTaken, item.RoundNumberUp); 37 return (int)IBBMath.Round(exactNumberTaken, item.RoundNumberUp);
61 } 38 }
62 } 39 }