Mercurial > repos > snowblizz-super-API-ideas
changeset 359:2a9c046be55a
Re #345: Add failure message to requirements
* Implement message creation for "at least" requirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 May 2011 14:23:51 +0000 |
parents | dbe7ccb1e557 |
children | 777725613edb |
files | API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs |
diffstat | 1 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun May 01 13:56:20 2011 +0000 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun May 01 14:23:51 2011 +0000 @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using IBBoard.WarFoundry.API.Objects; +using System.Text; namespace IBBoard.WarFoundry.API.Objects.Requirement { @@ -180,8 +181,28 @@ protected override string GetValidationFailedMessage (Army army) { - string message = ""; - return message; + StringBuilder sb = new StringBuilder(); + sb.Append("Army must contain: "); + sb.Append(String.Join("; ", GetFailedRequirements(army).ToArray())); + sb.Append("."); + return sb.ToString(); + } + + private List<string> GetFailedRequirements(Army army) + { + List<string> failures = new List<string>(); + + foreach (UnitCountRequirementData requirement in requiredTypes) + { + int unitCount = army.GetUnitTypeCount(requirement.UnitType); + + if (unitCount < requirement.Count) + { + failures.Add(requirement.Count + " × " + requirement.UnitType.Name + " (have " + unitCount + ")"); + } + } + + return failures; } } }