예제 #1
0
 public static void AddElements(XmlElement elSource, XmlElement elDestination)
 {
     foreach (XmlElement el in elSource.SelectNodes("*"))
     {
         if (el.Name == "terrain")
         {
             continue;
         }
         if (el.Name == "attribute")
         {
             elDestination.SetAttribute(el.GetAttribute("name"), el.GetAttribute("value"));
             continue;
         }
         if (el.Name == "num-attribute")
         {
             SetNumAttributes(elSource, elDestination);
             continue;
         }
         if (el.Name == "group")
         {
             XmlElement elGroup = RandomElement.Select(el.SelectNodes("or"));
             if (elGroup != null)
             {
                 AddElements(elGroup, elDestination);
             }
         }
         else
         {
             XmlElement elCopy = (XmlElement)elDestination.OwnerDocument.ImportNode(el.Clone(), true);
             SetNumAttributes(elCopy, elCopy);
             elDestination.AppendChild(elCopy);
         }
     }
 }
예제 #2
0
        public static void AddEntity(string name, ref int num, XmlElement elMap, XmlDocument input)
        {
            foreach (XmlElement elPerson in input.SelectNodes("data/" + name))
            {
                int amount = Convert.ToInt32(elPerson.GetAttribute("amount"));
                for (int i = 0; i < amount; i++)
                {
                    // Select terrain type
                    XmlElement elTerrain = RandomElement.Select(elPerson.SelectNodes("terrain"));

                    // Select region
                    XmlNodeList regions = elMap.SelectNodes("region[@terrain='" +
                                                            elTerrain.GetAttribute("type") + "']");
                    XmlElement elRegion = (XmlElement)regions[Constants.Random(regions.Count)];

                    // Add person to region
                    XmlElement elRegionPerson = elMap.OwnerDocument.CreateElement(name);
                    elRegion.AppendChild(elRegionPerson);
                    elRegionPerson.SetAttribute("num", num.ToString());
                    num++;

                    // Nodes
                    AddElements(elPerson, elRegionPerson);

                    if (name == "person")
                    {
                        // Generate name
                        string gender = "man";
                        if (elRegionPerson.SelectSingleNode("item[@type='WOMA']") != null)
                        {
                            gender = "woma";
                        }
                        elRegionPerson.SetAttribute("name", NameGenerator.Name(gender, "",
                                                                               elPerson.GetAttribute("name-group")));
                    }
                }
            }
            Console.WriteLine(num.ToString() + " " + name);
        }
예제 #3
0
        public static string Name(string gender, string ancestor, string group)
        {
            XmlElement elGroup         = null;
            string     res             = "";
            string     ancestor_second = "";

            // Select group by ancestor second name
            if (ancestor != "")
            {
                for (int i = ancestor.Length - 1; i >= 0; i--)
                {
                    if (ancestor[i] == ' ')
                    {
                        break;
                    }
                    else
                    {
                        ancestor_second = ancestor[i] + ancestor_second;
                    }
                }

                elGroup = (XmlElement)elBase.SelectSingleNode("group[second/name[@value='" +
                                                              ancestor_second + "']]");
            }

            if (elGroup == null)
            {
                // Select predefined group
                elGroup = (XmlElement)elBase.SelectSingleNode("group[@name='" + group + "']");
            }

            if (elGroup == null)
            {
                // Select group at random
                ancestor_second = "";
                elGroup         = RandomElement.Select(elBase.SelectNodes("group"));
                if (elGroup == null)
                {
                    return("");
                }
            }

            // Get first name for gender
            XmlNodeList first = elGroup.SelectNodes("first/name[@" + gender + "]");

            // If none, change gender to "man"
            if (first.Count == 0)
            {
                gender = "man";
                first  = elGroup.SelectNodes("first/name[@" + gender + "]");
                if (first.Count == 0)
                {
                    return("");
                }
            }

            XmlElement elFirst = (XmlElement)first[Constants.Random(first.Count)];

            res += elFirst.GetAttribute("value");

            if (ancestor_second != "")
            {
                return(res + " " + ancestor_second);
            }
            else
            {
                // Get second name
                XmlNodeList second = elGroup.SelectNodes("second/name[@" + gender + "]");
                if (second.Count == 0)
                {
                    return(res);
                }

                XmlElement elSecond = (XmlElement)second[Constants.Random(second.Count)];
                res += " " + elSecond.GetAttribute("value");
                return(res);
            }
        }