comparison API/Objects/UnitEquipmentRatioSelection.cs @ 337:3c4a6403a88c

* Fix capitalisation so that new files are in the namespace no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Apr 2011 18:50:32 +0000
parents
children 7179c585d31d
comparison
equal deleted inserted replaced
336:3631c1493c7f 337:3c4a6403a88c
1 // This file (UnitEquipmentRatioSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
2 //
3 // 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.
4
5 using System;
6 using IBBoard.CustomMath;
7 using IBBoard.Limits;
8 using IBBoard.WarFoundry.API.Util;
9
10 namespace IBBoard.WarFoundry.API.Objects
11 {
12 /// <summary>
13 /// An object to hold the selection of a unit's equipment where the selection was made as a percentage or ratio
14 /// of the total size of the unit
15 /// </summary>
16 public class UnitEquipmentRatioSelection : AbstractUnitEquipmentItemSelection
17 {
18 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
19 {
20 }
21
22 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, ((IPercentageLimit)item.MinLimit).Percentage)
23 {
24 }
25
26 public override int NumberTaken
27 {
28 get
29 {
30 return CalculateNumberTaken (EquipmentForUnit, EquipmentItem, AmountTaken);
31 }
32 }
33
34 internal static int CalculateNumberTaken (Unit unit, UnitEquipmentItem item, double ratioTaken)
35 {
36 double exactNumberTaken = (ratioTaken / 100) * unit.Size;
37 int wholeNumberTaken = (int)IBBMath.Round (exactNumberTaken, item.RoundNumberUp);
38 int maxTaken = UnitEquipmentUtil.GetMaxEquipmentCount (unit, item);
39 int minTaken = UnitEquipmentUtil.GetMinEquipmentCount (unit, item);
40 return Math.Min (Math.Max (wholeNumberTaken, minTaken), maxTaken);
41 }
42 }
43 }