// Load a system's description. void System::Load(const DataNode &node, Set<Planet> &planets) { if(node.Size() < 2) return; name = node.Token(1); // If this is truly a change and not just being called by Load(), these sets // of objects will be entirely replaced by any new ones, rather than adding // the new ones on to the end of the list: bool resetLinks = !links.empty(); bool resetAsteroids = !asteroids.empty(); bool resetFleets = !fleets.empty(); bool resetObjects = !objects.empty(); for(const DataNode &child : node) { if(child.Token(0) == "pos" && child.Size() >= 3) position.Set(child.Value(1), child.Value(2)); else if(child.Token(0) == "government" && child.Size() >= 2) government = GameData::Governments().Get(child.Token(1)); else if(child.Token(0) == "link") { if(resetLinks) { resetLinks = false; links.clear(); } if(child.Size() >= 2) links.push_back(GameData::Systems().Get(child.Token(1))); } else if(child.Token(0) == "habitable" && child.Size() >= 2) habitable = child.Value(1); else if(child.Token(0) == "asteroids") { if(resetAsteroids) { resetAsteroids = false; asteroids.clear(); } if(child.Size() >= 4) asteroids.emplace_back(child.Token(1), child.Value(2), child.Value(3)); } else if(child.Token(0) == "trade" && child.Size() >= 3) trade[child.Token(1)].SetBase(child.Value(2)); else if(child.Token(0) == "fleet") { if(resetFleets) { resetFleets = false; fleets.clear(); } if(child.Size() >= 3) fleets.emplace_back(GameData::Fleets().Get(child.Token(1)), child.Value(2)); } else if(child.Token(0) == "object") { if(resetObjects) { for(StellarObject &object : objects) if(object.GetPlanet()) { Planet *planet = planets.Get(object.GetPlanet()->Name()); planet->RemoveSystem(this); } resetObjects = false; objects.clear(); } LoadObject(child, planets); } else child.PrintTrace("Skipping unrecognized attribute:"); } // Set planet messages based on what zone they are in. for(StellarObject &object : objects) { if(object.message || object.planet) continue; const StellarObject *root = &object; while(root->parent >= 0) root = &objects[root->parent]; static const string STAR = "You cannot land on a star!"; static const string HOTPLANET = "This planet is too hot to land on."; static const string COLDPLANET = "This planet is too cold to land on."; static const string UNINHABITEDPLANET = "This planet is uninhabited."; static const string HOTMOON = "This moon is too hot to land on."; static const string COLDMOON = "This moon is too cold to land on."; static const string UNINHABITEDMOON = "This moon is uninhabited."; static const string STATION = "This station cannot be docked with."; double fraction = root->distance / habitable; if(object.IsStar()) object.message = &STAR; else if (object.IsStation()) object.message = &STATION; else if (object.IsMoon()) { if(fraction < .5) object.message = &HOTMOON; else if(fraction >= 2.) object.message = &COLDMOON; else object.message = &UNINHABITEDMOON; } else { if(fraction < .5) object.message = &HOTPLANET; else if(fraction >= 2.) object.message = &COLDPLANET; else object.message = &UNINHABITEDPLANET; } } }