internal override void Link() { if (ParentCiv?.Entity != null) { if (ParentCiv.Entity.Children == null) { ParentCiv.Entity.Children = new ConcurrentBag <Entity>(); } if (!ParentCiv.Entity.Children.Contains(this)) { ParentCiv.Entity.Children.Add(this); } if (ChildrenIDs != null) { foreach (var child in ChildrenIDs) { if (Children == null) { Children = new ConcurrentBag <Entity>(); } if (World.Entities.ContainsKey(child)) { Children.Add(World.Entities[child]); } } } } if (EntityLinks != null && EntityLinks.ContainsKey(EntityEntityLink.LinkTypes.IndexOf("PARENT"))) { if (EntityLinks[EntityEntityLink.LinkTypes.IndexOf("PARENT")].Count == 1) { var parentEnt = EntityLinks[EntityEntityLink.LinkTypes.IndexOf("PARENT")][0].Target; if (parentEnt.Civilization != null) { ParentCiv = parentEnt.Civilization; } else if (parentEnt.ParentCiv != null) { ParentCiv = parentEnt.ParentCiv; } } } if (WorshipHfid.HasValue && World.HistoricalFigures.ContainsKey(WorshipHfid.Value)) { WorshipHf = World.HistoricalFigures[WorshipHfid.Value]; } }
internal override void Plus(XDocument xdoc) { foreach (var element in xdoc.Root.Elements()) { var val = element.Value; int valI; int.TryParse(val, out valI); switch (element.Name.LocalName) { case "id": break; case "race_id": if (valI != -1 && World.Races.ContainsKey(valI)) { Race = World.Races[valI]; } break; case "type": if (!Types.Contains(val)) { Types.Add(val); } _entityType = (short)Types.IndexOf(val); break; case "site_link": var newSl = new EntitySiteLink(element, this); if (SiteLinks == null) { SiteLinks = new Dictionary <int, List <EntitySiteLink> >(); } if (!SiteLinks.ContainsKey(newSl.LinkType)) { SiteLinks.Add(newSl.LinkType, new List <EntitySiteLink>()); } SiteLinks[newSl.LinkType].Add(newSl); break; case "entity_link": var newEl = new EntityEntityLink(element, this); if (EntityLinks == null) { EntityLinks = new Dictionary <int, List <EntityEntityLink> >(); } if (!EntityLinks.ContainsKey(newEl.LinkType)) { EntityLinks.Add(newEl.LinkType, new List <EntityEntityLink>()); } EntityLinks[newEl.LinkType].Add(newEl); break; case "children": ChildrenIDs = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList(); break; case "worship_id": WorshipHfid = valI; break; case "coords": if (Coords == null) { Coords = new List <Point>(); } foreach (var coordSplit in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(coord => coord.Split(',')).Where(coordSplit => coordSplit.Length == 2)) { Coords.Add(new Point(Convert.ToInt32(coordSplit[0]), Convert.ToInt32(coordSplit[1]))); } break; case "claims": Claims = val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(coord => coord.Split(',')) .Where(coordSplit => coordSplit.Length == 2) .Select(split => new Point(Convert.ToInt32(split[0]), Convert.ToInt32(split[1]))) .ToList(); break; case "entity_position": var newPosition = new EntityPosition(element, this); if (Positions == null) { Positions = new List <EntityPosition>(); } Positions.Add(newPosition); break; case "entity_position_assignment": var newPositionAssignment = new EntityPositionAssignment(element, this); if (PositionAssignments == null) { PositionAssignments = new List <EntityPositionAssignment>(); } PositionAssignments.Add(newPositionAssignment); break; case "histfig_id": if (MemberHfids == null) { MemberHfids = new List <int>(); } MemberHfids.Add(valI); break; case "histfig_ids": MemberHfids = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList(); break; case "occasion": var newOccasion = new EntityOccasion(element, this); if (Occasions == null) { Occasions = new List <EntityOccasion>(); } Occasions.Add(newOccasion); break; default: DFXMLParser.UnexpectedXmlElement(xdoc.Root.Name.LocalName + "\t", element, xdoc.Root.ToString()); break; } } }