changeset 231:d1c90159547a

Fixes #236: Race loading should fail cleanly if system doesn't exist * Exception if we get a null game system Also: * Remove unused variable
author IBBoard <dev@ibboard.co.uk>
date Thu, 24 Dec 2009 14:54:43 +0000
parents 73da8d13ce69
children f5009a00a50d
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Requirements/UnitRequiresAtLeastRequirement.cs
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Thu Dec 24 10:33:20 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Thu Dec 24 14:54:43 2009 +0000
@@ -35,7 +35,7 @@
 		private XmlDocument GetExtraData(Race obj)
 		{
 			XmlDocument extra = null;
-			extraData.TryGetValue(obj, out extra);			
+			extraData.TryGetValue(obj, out extra);
 			return extra;
 		}
 		
@@ -45,7 +45,14 @@
 			string subid = elem.GetAttribute("subid");
 			string systemID = elem.GetAttribute("system");
 			string name = elem.GetAttribute("name");
-			Race race = new Race(id, subid, name, WarFoundryLoader.GetDefault().GetGameSystem(systemID), mainFactory);
+			GameSystem gameSystem = WarFoundryLoader.GetDefault ().GetGameSystem (systemID);
+			
+			if (gameSystem == null)
+			{
+				throw new InvalidFileException("Referenced game system, "+systemID+" did not exist");
+			}
+			
+			Race race = new Race(id, subid, name, gameSystem, mainFactory);
 			StoreExtraData(race, elem);
 			return race;
 		}
--- a/api/Requirements/UnitRequiresAtLeastRequirement.cs	Thu Dec 24 10:33:20 2009 +0000
+++ b/api/Requirements/UnitRequiresAtLeastRequirement.cs	Thu Dec 24 14:54:43 2009 +0000
@@ -57,7 +57,6 @@
 		protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type)
 		{
 			FailedRequirement failure = null;
-			int count = requiredTypes.Length;
 			
 			foreach (UnitRequirementItem req in requiredTypes)
 			{