public bool Initialize(FileInfo file, Random r, out string reason)
{
XDocument doc = XDocument.Load(file.FullName);
XElement root = doc.Element("Race");
SetBaseDefaults();
RaceName = root.Attribute("name").Value;
SingularRaceName = root.Attribute("singularName").Value;
RaceDescription = root.Attribute("raceDescription").Value;
NeutralAvatar = SpriteManager.GetSprite(root.Attribute("neutralPortrait").Value, r);
HappyAvatar = SpriteManager.GetSprite(root.Attribute("happyPortrait").Value, r);
AngryAvatar = SpriteManager.GetSprite(root.Attribute("angryPortrait").Value, r);
MiniAvatar = SpriteManager.GetSprite(root.Attribute("thumbnail").Value, r);
GroundTroop = SpriteManager.GetSprite(root.Attribute("groundTroop").Value, r);
DyingTroop = SpriteManager.GetSprite(root.Attribute("dyingTroop").Value, r);
FleetIcon = SpriteManager.GetSprite(root.Attribute("fleetIcon").Value, r);
TransportIcon = SpriteManager.GetSprite(root.Attribute("transportIcon").Value, r);
City = SpriteManager.GetSprite(root.Attribute("city").Value, r);
LandingShip = SpriteManager.GetSprite(root.Attribute("landingShip").Value, r);
XElement shipTypes = root.Element("ShipTypes");
if (shipTypes == null)
{
reason = "ShipTypes not found in " + RaceName + " race";
return false;
}
ShipTypes = new List<RaceShipType>();
foreach (XElement shipType in shipTypes.Elements())
{
RaceShipType newType = new RaceShipType();
newType.TypeName = shipType.Attribute("name").Value;
newType.Space = int.Parse(shipType.Attribute("space").Value);
newType.Width = int.Parse(shipType.Attribute("width").Value);
newType.Height = int.Parse(shipType.Attribute("height").Value);
newType.Bodies = new List<BBSprite>();
foreach (XElement body in shipType.Elements())
{
newType.Bodies.Add(SpriteManager.GetSprite(body.Attribute("sprite").Value, r));
}
ShipTypes.Add(newType);
}
//Order ships based on space
ShipTypes.Sort((a, b) => { return a.Space.CompareTo(b.Space); });
reason = null;
return true;
}