annotate api/Objects/UnitEquipmentNumericForRatioSelection.cs @ 136:413a7a049e41

Fixes #146: Incorrect logic in Unit.AddEquipmentAmount() * Logic error was in UnitEquipmentNumericForRatioSelection where we didn't treat percentages as decimal numbers and got ranges of "125 to 500" for a unit of 5!
author IBBoard <dev@ibboard.co.uk>
date Tue, 08 Sep 2009 19:27:51 +0000
parents 2f3cafb69799
children 70808ff799e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
97
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (UnitEquipmentNumericForRatioSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
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.
97
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Lang;
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard.WarFoundry.API.Objects
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 /// <summary>
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// An object to hold the selection of a unit's equipment where the selection was made as an absolute number and the
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// equipment item has a ratio limit
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// </summary>
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class UnitEquipmentNumericForRatioSelection : UnitEquipmentNumericSelection
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public UnitEquipmentNumericForRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 }
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public UnitEquipmentNumericForRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, IBBMath.Round(unit.Size * item.MinPercentage, item.RoundNumberUp))
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 protected override bool IsInRange (double newValue)
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
136
413a7a049e41 Fixes #146: Incorrect logic in Unit.AddEquipmentAmount()
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
26 int minLimit = (int) IBBMath.Round(EquipmentForUnit.Size * EquipmentItem.MinPercentage / 100, EquipmentItem.RoundNumberUp);
413a7a049e41 Fixes #146: Incorrect logic in Unit.AddEquipmentAmount()
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
27 int maxLimit = (int)IBBMath.Round(EquipmentForUnit.Size * EquipmentItem.MaxPercentage / 100, EquipmentItem.RoundNumberUp);
413a7a049e41 Fixes #146: Incorrect logic in Unit.AddEquipmentAmount()
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
28 newValue = (newValue == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : newValue);
97
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 bool isInRange = (minLimit <= newValue) && (newValue <= maxLimit);
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 return isInRange && IsWholeNumber(newValue);
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }