Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Requirements/UnitRequiresAtLeastRequirement.cs @ 297:349e521785c1
Re #338: WarFoundry.API - Save System Data
Created IWarFoundryGameSystemSaver
Created WarFoundryXmlGameSystemSaver
Updated WarFoundrySaver
Created GetGameSystemSaver
Created SetGameSystemSaver
author | Tsudico |
---|---|
date | Fri, 07 Jan 2011 03:35:50 +0000 |
parents | d1c90159547a |
children |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1 // This file (UnitRequiresAtLeastRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
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. |
15 | 4 |
82 | 5 using System; |
0 | 6 using System.Collections.Generic; |
7 using System.Text; | |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
8 using IBBoard.Lang; |
0 | 9 using IBBoard.WarFoundry.API; |
82 | 10 using IBBoard.WarFoundry.API.Objects; |
11 | |
12 namespace IBBoard.WarFoundry.API.Requirements | |
13 { | |
14 /// <summary> | |
15 /// Summary description for UnitRequiresRequirement. | |
16 /// </summary> | |
17 public class UnitRequiresAtLeastRequirement : UnitRequirement | |
18 { | |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
19 private UnitRequirementItem[] requiredTypes; |
82 | 20 private String unitList; |
21 | |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
22 public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitRequirementItem[]{new UnitRequirementItem(requiredUnitType)}) |
82 | 23 { |
0 | 24 } |
25 | |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
26 public UnitRequiresAtLeastRequirement(UnitType type, UnitRequirementItem[] requiredUnitTypes) : base(type) |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
27 { |
0 | 28 requiredTypes = requiredUnitTypes; |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
29 bool first = true; |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
30 |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
31 foreach (UnitRequirementItem req in requiredTypes) |
82 | 32 { |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
33 string reqString = Translation.GetTranslation("requirementUnitTypeAtLeastSingle", "{1} {0}", req.UnitType.Name, req.Amount); |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
34 |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
35 if (first) |
82 | 36 { |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
37 first = false; |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
38 unitList = reqString; |
82 | 39 } |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
40 else |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
41 { |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
42 unitList = Translation.GetTranslation("requirementUnitTypeAtLeastJoiner", "{0}, {1}", unitList, reqString); |
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
43 } |
82 | 44 } |
45 } | |
46 | |
47 public override string Description | |
48 { | |
229
6083010a005c
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
49 get { return Translation.GetTranslation("requirementUnitTypeAtLeast", "the army must include at least the following units to include a unit of type {0}: {1}", unitType.Name, unitList); } |
82 | 50 } |
51 | |
52 protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) | |
53 { | |
54 return null; | |
55 } | |
56 | |
57 protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) | |
0 | 58 { |
59 FailedRequirement failure = null; | |
60 | |
230
73da8d13ce69
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
61 foreach (UnitRequirementItem req in requiredTypes) |
82 | 62 { |
230
73da8d13ce69
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
63 if (army.GetUnitTypeCount(req.UnitType) < req.Amount) |
82 | 64 { |
0 | 65 failure = new FailedRequirement(this); |
82 | 66 break; |
0 | 67 } |
68 } | |
69 | |
82 | 70 return failure; |
71 } | |
72 } | |
73 } |