comparison api/Objects/UnitEquipmentRatioSelection.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
1 // This file (UnitEquipmentRatioSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard 1 // This file (UnitEquipmentRatioSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
2 // 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. 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 4
5 using System; 5 using System;
6 using IBBoard.Limits;
6 7
7 namespace IBBoard.WarFoundry.API.Objects 8 namespace IBBoard.WarFoundry.API.Objects
8 { 9 {
9 /// <summary> 10 /// <summary>
10 /// An object to hold the selection of a unit's equipment where the selection was made as a percentage or ratio 11 /// An object to hold the selection of a unit's equipment where the selection was made as a percentage or ratio
14 { 15 {
15 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount) 16 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
16 { 17 {
17 } 18 }
18 19
19 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinPercentage) 20 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, ((IPercentageLimit)item.MinLimit).Percentage)
20 { 21 {
21 } 22 }
22 23
23 public override int NumberTaken 24 public override int NumberTaken
24 { 25 {
25 get 26 get
26 { 27 {
27 double numberTaken = (AmountTaken / 100) * EquipmentForUnit.Size; 28 double numberTaken = (AmountTaken / 100) * EquipmentForUnit.Size;
28 return (int) (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken)); 29 return (int) (EquipmentItem.RoundNumberUp ? Math.Ceiling(numberTaken) : Math.Floor(numberTaken));
29 } 30 }
30 }
31
32 protected override bool IsInRange (double newValue)
33 {
34 return (EquipmentItem.MinPercentage <= newValue) && (newValue <= EquipmentItem.MaxPercentage);
35 } 31 }
36 32
37 public override string GetEquipmentAmountString () 33 public override string GetEquipmentAmountString ()
38 { 34 {
39 return GetEquipmentAmountString(AmountTaken); 35 return GetEquipmentAmountString(AmountTaken);