comparison api/Objects/UnitEquipmentRatioSelection.cs @ 95:6c6cfe5594fc

Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts * Create new "equipment selection" objects to track equipment selection amounts and cost * Create ratio version * Creat absolute amount version
author IBBoard <dev@ibboard.co.uk>
date Sun, 09 Aug 2009 10:34:09 +0000
parents
children 95746083d037
comparison
equal deleted inserted replaced
94:49a83020174e 95:6c6cfe5594fc
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 under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
4
5 using System;
6
7 namespace IBBoard.WarFoundry.API.Objects
8 {
9 /// <summary>
10 /// An object to hold the selection of a unit's equipment where the selection was made as a percentage or ratio
11 /// of the total size of the unit
12 /// </summary>
13 public class UnitEquipmentRatioSelection : AbstractUnitEquipmentItemSelection
14 {
15 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
16 {
17 }
18
19 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinPercentage)
20 {
21 }
22
23 public override double TotalCost
24 {
25 get
26 {
27 return CalculateAmount() * EquipmentItem.Cost;
28 }
29 }
30
31 private double CalculateAmount()
32 {
33 double numberTaken = AmountTaken * EquipmentForUnit.Size;
34 return (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
35 }
36
37 protected override bool IsValidValue (double newValue)
38 {
39 return (EquipmentItem.MinPercentage <= newValue) && (newValue <= EquipmentItem.MaxPercentage);
40 }
41 }
42 }