/// <summary> /// Load: initializing constructor to read in a Star from an XmlNode (from a saved file). /// </summary> /// <param name="node">An XmlNode representing a Star.</param> public Star(XmlNode node) : base(node) { Starbase = null; XmlNode mainNode = node.FirstChild; // Read the node while (mainNode != null) { try { switch (mainNode.Name.ToLower()) { case "hasfleetsinorbit": HasFleetsInOrbit = bool.Parse(mainNode.FirstChild.Value); break; case "productionqueue": ManufacturingQueue = new ProductionQueue(mainNode); break; case "mineralconcentration": MineralConcentration = new Resources(mainNode); break; case "resourcesonhand": ResourcesOnHand = new Resources(mainNode); break; case "colonists": Colonists = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "defenses": Defenses = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "factories": Factories = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "mines": Mines = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "researchallocation": ResearchAllocation = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "onlyleftover": OnlyLeftover = bool.Parse(mainNode.FirstChild.Value); break; case "scanrange": ScanRange = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "defensetype": DefenseType = mainNode.FirstChild.Value; break; case "scannertype": ScannerType = mainNode.FirstChild.Value; break; case "gravity": Gravity = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "radiation": Radiation = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "temperature": Temperature = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "originalgravity": OriginalGravity = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "originalradiation": OriginalRadiation = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; case "originaltemperature": OriginalTemperature = int.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture); break; // These are placeholder objects that will be linked to the real objects once // loading from the file is complete (as they may not exist yet, and cannot be // referenced from here). The node will only hold enough information to identify // the referenced object. // ThisRace will point to the Race that owns the Star, // for now create a placeholder Race and load its Name case "thisrace": ThisRace = new Race(); ThisRace.Name = mainNode.FirstChild.Value; break; // Starbase will point to the Fleet that is this planet's starbase (if any), // for now create a placeholder Fleet and load its FleetID case "starbase": Starbase = new Fleet(long.Parse(mainNode.FirstChild.Value, NumberStyles.HexNumber)); break; default: break; } } catch (Exception e) { Report.FatalError(e.Message + "\n Details: \n" + e.ToString()); } mainNode = mainNode.NextSibling; } }
/// <summary> /// Update the population of a star system. /// </summary> /// <param name="race"></param> /// <remarks> /// See Update(). /// </remarks> public void UpdatePopulation(Race race) { Colonists += CalculateGrowth(race); }