Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/AbstractUnitEquipmentItemSelection.cs @ 101:f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
This revision will be broken for the WinForms UI, but as MonoDevelop/eSVN don't have a way of committing multiple projects in one go it can't be helped (Eclipse's Team Sync view could handle it)
Fixes #122: Make usage of percentage or ratio common
* All usage of ratio amounts for equipment items should now assume percentage
* Properly calculate number taken for ratio selection (divide by 0 now we're using percentages)
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
* Added extra commands that differentiate between ratio and absolute amounts
Fixes #120: Numeric limit equipment items show large percentages
* Now made formatting treat ratios as percentages (don't multiply by 100)
* Move string formatting to UnitEquipmentItem...Selection classes
* Add method to Unit to say whether an equipment item is a numeric or ratio amount
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 13 Aug 2009 21:09:20 +0000 |
parents | 95746083d037 |
children | 2f3cafb69799 |
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 (AbstractUnitEquipmentItemSelection.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 // |
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
|
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. |
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; |
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
|
6 |
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
|
7 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
|
8 { |
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 /// <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
|
10 /// An abstract class that defines a selection of equipment for a 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
|
11 /// </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
|
12 public abstract class 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
|
13 { |
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 private Unit selectionForUnit; |
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 private UnitEquipmentItem selectedItem; |
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 private double amountTaken; |
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 AbstractUnitEquipmentItemSelection(Unit unit, UnitEquipmentItem item, double 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 selectionForUnit = 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
|
21 selectedItem = item; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
22 AmountTaken = amount; |
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 |
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
|
25 public Unit EquipmentForUnit |
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
|
26 { |
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 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
|
28 { |
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 return selectionForUnit; |
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
|
30 } |
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 } |
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
|
32 |
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
|
33 public UnitEquipmentItem EquipmentItem |
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
|
34 { |
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
|
35 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
|
36 { |
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
|
37 return selectedItem; |
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
|
38 } |
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
|
39 } |
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
|
40 |
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
|
41 public double AmountTaken |
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
|
42 { |
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
|
43 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
|
44 { |
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
|
45 return amountTaken; |
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
|
46 } |
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
|
47 set |
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
|
48 { |
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
|
49 if (IsValidValue(value)) |
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
|
50 { |
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
|
51 amountTaken = value; |
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
|
52 } |
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
|
53 else |
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
|
54 { |
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
|
55 //Fire validation failed event (once we have one) |
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
|
56 } |
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
|
57 } |
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
|
58 } |
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
|
59 |
97
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
60 protected bool IsValidValue(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:
96
diff
changeset
|
61 { |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
62 return IsInRange(newValue); |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
63 } |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
64 |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
65 protected abstract 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:
96
diff
changeset
|
66 |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
67 public double TotalCost |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
68 { |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
69 get |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
70 { |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
71 return NumberTaken * EquipmentItem.Cost; |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
72 } |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
73 } |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
74 |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
75 public abstract int NumberTaken |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
76 { |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
77 get; |
95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
78 } |
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
|
79 |
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
|
80 public abstract string GetEquipmentAmountString(); |
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
|
81 } |
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
|
82 } |