# HG changeset patch # User IBBoard # Date 1316980347 -3600 # Node ID 71fceea2725b2d8b65af2b739ef6c2aeec7926ef # Parent 6798a59c1b49d0650428938e62888558740dc451 Code tidy-up - remove warnings * Add missing GetHashcode() implementations * Remove unused exception variables * Use unused event * Remove dead code * Properly override some methods diff -r 6798a59c1b49 -r 71fceea2725b API/AbstractWarFoundryLoader.cs --- a/API/AbstractWarFoundryLoader.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/AbstractWarFoundryLoader.cs Sun Sep 25 20:52:27 2011 +0100 @@ -129,6 +129,7 @@ /// public List LoadFiles() { + OnFileLoadingStarted(); PrepareForFileLoad(); Dictionary loadableRaces = new Dictionary(); Dictionary loadableGameSystems = new Dictionary(); @@ -140,6 +141,14 @@ return failedLoads; } + private void OnFileLoadingStarted() + { + if (FileLoadingStarted != null) + { + FileLoadingStarted(); + } + } + private void OnFileLoadingFinished(List failures) { if (FileLoadingFinished != null) diff -r 6798a59c1b49 -r 71fceea2725b API/Exporters/WarFoundryXMLWithXSLExporter.cs --- a/API/Exporters/WarFoundryXMLWithXSLExporter.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Exporters/WarFoundryXMLWithXSLExporter.cs Sun Sep 25 20:52:27 2011 +0100 @@ -132,15 +132,7 @@ armyEquipmentItem.SetAttribute("name", equip.Name); int armyEquipAmount = 0; - - if (UnitEquipmentUtil.GetEquipmentAmount(uni, equip) == null) - { - armyEquipAmount = 0; - } - else - { - armyEquipAmount = (int)UnitEquipmentUtil.GetEquipmentAmount(uni, equip); - } + armyEquipAmount = (int)UnitEquipmentUtil.GetEquipmentAmount(uni, equip); if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(uni, equip)) { diff -r 6798a59c1b49 -r 71fceea2725b API/Factories/Xml/WarFoundryXmlFactory.cs --- a/API/Factories/Xml/WarFoundryXmlFactory.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Factories/Xml/WarFoundryXmlFactory.cs Sun Sep 25 20:52:27 2011 +0100 @@ -167,7 +167,7 @@ { raceFactory.CompleteLoading(race); } - catch (InvalidFileException ex) + catch (InvalidFileException) { WarFoundryLoader.GetDefault().RemoveRace(race); throw; @@ -180,7 +180,7 @@ { gameSystemFactory.CompleteLoading(system); } - catch (InvalidFileException ex) + catch (InvalidFileException) { WarFoundryLoader.GetDefault().RemoveGameSystem(system); throw; diff -r 6798a59c1b49 -r 71fceea2725b API/Factories/Xml/WarFoundryXmlFactoryUtils.cs --- a/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs Sun Sep 25 20:52:27 2011 +0100 @@ -98,15 +98,15 @@ { cache.Add(xmlNamespace, schemaLocation); } - catch (IOException ex) + catch (IOException) { //TODO: Warn on schema failure } - catch (XmlSchemaException ex) + catch (XmlSchemaException) { //TODO: Warn on schema failure } - catch (XmlException ex) + catch (XmlException) { //TODO: Warn on schema failure } diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/GameSystem.cs --- a/API/Objects/GameSystem.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/GameSystem.cs Sun Sep 25 20:52:27 2011 +0100 @@ -238,7 +238,19 @@ public override int GetHashCode() { - return ID.GetHashCode() + Name.GetHashCode() + (RawCategories != null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); + return ID.GetHashCode() + Name.GetHashCode() + GetCategoryHash() + warnOnError.GetHashCode(); + } + + private int GetCategoryHash() + { + int hash = 0; + + foreach (Category cat in RawCategories.Values) + { + hash += cat.ID.GetHashCode(); + } + + return hash; } public bool UnitTypeMaxed(UnitType unitType, Army army) diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/Race.cs --- a/API/Objects/Race.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/Race.cs Sun Sep 25 20:52:27 2011 +0100 @@ -60,6 +60,11 @@ } } + public override int GetHashCode() + { + return ID.GetHashCode() + SubID.GetHashCode() + GameSystem.GetHashCode() + ArmyDefaultName.GetHashCode(); + } + public string SubID { get { return subID; } diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/Requirement/AbstractRequirement.cs --- a/API/Objects/Requirement/AbstractRequirement.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/Requirement/AbstractRequirement.cs Sun Sep 25 20:52:27 2011 +0100 @@ -24,6 +24,8 @@ } } + public override abstract int GetHashCode(); + /// /// Type-specific equality checking - must be implemented by each class /// diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun Sep 25 20:52:27 2011 +0100 @@ -39,6 +39,18 @@ } } + public override int GetHashCode() + { + int hash = 0; + + foreach (UnitCountRequirementData req in requiredTypes) + { + hash += req.UnitType.GetHashCode(); + } + + return hash; + } + /// /// Checks whether the supplied WarFoundryObject can be added to the supplied army. /// diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Sun Sep 25 20:52:27 2011 +0100 @@ -120,6 +120,18 @@ return Collections.Collections.AreEqual(limitedTypes, other.limitedTypes); } + public override int GetHashCode() + { + int hash = 0; + + foreach (UnitCountRequirementData limit in limitedTypes) + { + hash += limit.UnitType.GetHashCode(); + } + + return hash; + } + protected string FailureStringPrefix { get; set; } protected override string GetValidationFailedMessage (Army army) diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Sun Sep 25 20:52:27 2011 +0100 @@ -38,19 +38,19 @@ } - private bool IsApplicable(WarFoundryObject toObject, Army toArmy) + protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy) { return IsApplicable(toArmy) || IsApplicable(toObject); } - private bool IsApplicable(Army toArmy) + protected override bool IsApplicable(Army toArmy) { return toArmy.GetUnitTypeCount(requirementOnType) > 0; } - private bool IsApplicable(WarFoundryObject toObject) + protected override bool IsApplicable(WarFoundryObject toObject) { return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType)); } diff -r 6798a59c1b49 -r 71fceea2725b API/Objects/UnitType.cs --- a/API/Objects/UnitType.cs Sat Sep 24 11:59:39 2011 +0100 +++ b/API/Objects/UnitType.cs Sun Sep 25 20:52:27 2011 +0100 @@ -69,6 +69,11 @@ } } + public override int GetHashCode() + { + return Race.GetHashCode() + ID.GetHashCode() + Name.GetHashCode(); + } + public GameSystem GameSystem { get { return Race.GameSystem; }