final Game game = GameFactory.getInstance().getGame(gameId);
final Complex complex = new Complex(game);
final FactoryFactory factoryFactory = game.getFactoryFactory();
final SectorFactory sectorFactory = game.getSectorFactory();
final WareFactory wareFactory = game.getWareFactory();
final SunFactory sunsFactory = game.getSunFactory();
complex.setSuns(sunsFactory.getSun(Integer.parseInt(root
.attributeValue("suns"))));
complex.setSector(sectorFactory
.getSector(root.attributeValue("sector")));
complex.setAddBaseComplex(Boolean.parseBoolean(root.attributeValue(
"addBaseComplex", "false")));
complex.showingProductionStats = Boolean.parseBoolean(root
.attributeValue("showingProductionStats", "false"));
complex.showingShoppingList = Boolean.parseBoolean(root.attributeValue(
"showingShoppingList", "false"));
complex.showingStorageCapacities = Boolean.parseBoolean(root
.attributeValue("showingStorageCapacities", "false"));
complex.showingComplexSetup = Boolean.parseBoolean(root.attributeValue(
"showingComplexSetup", "true"));
// Get the factories parent element (In older version this was the root
// node)
Element factoriesE = root.element("complexFactories");
if (factoriesE == null) factoriesE = root;
// Read the complex factories
for (final Object item: factoriesE.elements("complexFactory"))
{
final Element element = (Element) item;
final Factory factory = factoryFactory.getFactory(element
.attributeValue("factory"));
final ComplexFactory complexFactory;
final Element yieldsE = element.element("yields");
if (yieldsE == null)
{
final int yield =
Integer.parseInt(element.attributeValue("yield", "0"));
final int quantity = Integer.parseInt(element
.attributeValue("quantity"));
complexFactory =
new ComplexFactory(game, factory, quantity, yield);
}
else
{
final List<Integer> yields = new ArrayList<Integer>();
for (final Object yieldItem: yieldsE.elements("yield"))
{
final Element yieldE = (Element) yieldItem;
yields.add(Integer.parseInt(yieldE.getText()));
}
complexFactory = new ComplexFactory(game, factory, yields);
}
if (Boolean.parseBoolean(element
.attributeValue("disabled", "false")))
complexFactory.disable();
complex.addFactory(complexFactory);
}
// Read the complex wares
final Element waresE = root.element("complexWares");
if (waresE != null)
{
complex.customPrices.clear();
for (final Object item: waresE.elements("complexWare"))
{
final Element element = (Element) item;
final Ware ware = wareFactory.getWare(element
.attributeValue("ware"));
final boolean use = Boolean.parseBoolean(element
.attributeValue("use"));
final int price = Integer.parseInt(element
.attributeValue("price"));