annotate api/Objects/UnitEquipmentRatioSelection.cs @ 232:f5009a00a50d

Re #236: Handle null game system in race * Fix error message text no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Thu, 24 Dec 2009 14:57:32 +0000
parents ece26f6a62f3
children 92d10b06ab0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
6c6cfe5594fc Re #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 (UnitEquipmentRatioSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
6c6cfe5594fc Re #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: 101
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.
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
6c6cfe5594fc Re #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;
212
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
6 using IBBoard.CustomMath;
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
7 using IBBoard.Limits;
212
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
8 using IBBoard.WarFoundry.API.Util;
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Objects
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// <summary>
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// An object to hold the selection of a unit's equipment where the selection was made as a percentage or ratio
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 /// of the total size of the unit
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 /// </summary>
6c6cfe5594fc Re #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 class UnitEquipmentRatioSelection : AbstractUnitEquipmentItemSelection
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount)
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 }
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
22 public UnitEquipmentRatioSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, ((IPercentageLimit)item.MinLimit).Percentage)
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 }
97
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
25
95746083d037 Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
26 public override int NumberTaken
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 {
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 get
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
30 return CalculateNumberTaken (EquipmentForUnit, EquipmentItem, AmountTaken);
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
32 }
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
33
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
34 internal static int CalculateNumberTaken (Unit unit, UnitEquipmentItem item, double ratioTaken)
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
35 {
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
36 double exactNumberTaken = (ratioTaken / 100) * unit.Size;
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
37 int wholeNumberTaken = (int)IBBMath.Round (exactNumberTaken, item.RoundNumberUp);
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
38 int maxTaken = UnitEquipmentUtil.GetMaxEquipmentCount (unit, item);
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
39 int minTaken = UnitEquipmentUtil.GetMinEquipmentCount (unit, item);
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 212
diff changeset
40 return Math.Min (Math.Max (wholeNumberTaken, minTaken), maxTaken);
212
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
41 }
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
42
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
43 [Obsolete("Implementation is down to the UI")]
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
44 public override string GetEquipmentAmountString ()
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
45 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
46 return GetEquipmentAmountString(AmountTaken);
212
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
47 }
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
48
dce340f9cedc Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents: 183
diff changeset
49 [Obsolete("Implementation is down to the UI")]
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
50 public static string GetEquipmentAmountString(double amount)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
51 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
52 string amountString;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
53
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
54 if (amount == 100)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
55 {
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
56 amountString = "all";
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
57 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
58 else
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
59 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
60 amountString = amount + "%";
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
61 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
62
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
63 return amountString;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
64 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
65
95
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
6c6cfe5594fc Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 }