Beispiel #1
0
        public Unit(XDocument xdoc, World world)
            : base(xdoc, world)
        {
            foreach (var element in xdoc.Root.Elements())
            {
                var val = element.Value.Trim();
                int valI;
                int.TryParse(val, out valI);
                switch (element.Name.LocalName)
                {
                case "id":
                    break;

                case "name":
                    Name = val;
                    break;

                case "name2":
                    AltName = val;
                    break;

                case "profession":
                    if (!JobTypes.Contains(val))
                    {
                        JobTypes.Add(val);
                    }
                    ProfessionId = JobTypes.IndexOf(val);
                    break;

                case "profession2":
                    if (!JobTypes.Contains(val))
                    {
                        JobTypes.Add(val);
                    }
                    Profession2Id = JobTypes.IndexOf(val);
                    break;

                case "race":
                    if (valI != -1)
                    {
                        Race = World.GetAddRace(val);
                    }
                    break;

                case "caste":
                    if (valI != -1)
                    {
                        if (!HistoricalFigure.Castes.Contains(val))
                        {
                            HistoricalFigure.Castes.Add(val);
                        }
                        CasteID = HistoricalFigure.Castes.IndexOf(val);
                    }
                    break;

                case "coords":
                    Coords = new Point3(
                        Convert.ToInt32(val.Split(',')[0]),
                        Convert.ToInt32(val.Split(',')[1]),
                        Convert.ToInt32(val.Split(',')[2]));
                    break;

                case "sex":
                    Sex = valI;
                    break;

                case "civ_id":
                    if (valI != -1)
                    {
                        CivID = valI;
                    }
                    break;

                case "population_id":
                    if (valI != -1)
                    {
                        PopID = valI;
                    }
                    break;

                case "squad_id":
                    if (valI != -1)
                    {
                        SquadID = valI;
                    }
                    break;

                case "opponent_id":
                    if (valI != -1)
                    {
                        OpponentID = valI;
                    }
                    break;

                case "mood":
                    Mood = valI;
                    break;

                case "hist_figure_id":
                    if (valI != -1)
                    {
                        HistFigureID = valI;
                    }
                    break;

                case "hist_figure_id2":
                    if (valI != -1)
                    {
                        HistFigureID2 = valI;
                    }
                    break;

                case "labors":
                    var labors = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var labor in labors)
                    {
                        if (!Labors.Contains(labor))
                        {
                            Labors.Add(labor);
                        }
                        if (Labor == null)
                        {
                            Labor = new List <short>();
                        }
                        Labor.Add((short)Labors.IndexOf(labor));
                    }
                    break;

                case "flags":
                    var flags = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var flag in flags)
                    {
                        if (!Flags.Contains(flag))
                        {
                            Flags.Add(flag);
                        }
                        if (Flag == null)
                        {
                            Flag = new List <short>();
                        }
                        Flag.Add((short)Flags.IndexOf(flag));
                    }
                    break;

                case "health":
                    var healthflags = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var healthflag in healthflags)
                    {
                        if (!HealthFlags.Contains(healthflag))
                        {
                            HealthFlags.Add(healthflag);
                        }
                        if (HealthFlag == null)
                        {
                            HealthFlag = new List <short>();
                        }
                        HealthFlag.Add((short)HealthFlags.IndexOf(healthflag));
                    }
                    break;

                case "used_items":
                    UsedItemIds = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
                    break;

                case "owned_items":
                    OwnedItemIds = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
                    break;

                case "owned_buildings":
                    OwnedBuildingIds = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
                    break;

                case "traded_items":
                    TradedItemIds = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
                    break;

                case "inventory":
                    foreach (var inv in element.Elements())
                    {
                        if (InventoryItems == null)
                        {
                            InventoryItems = new List <UnitInventoryItem>();
                        }
                        InventoryItems.Add(new UnitInventoryItem(new XDocument(inv), world));
                    }
                    break;

                case "reference":
                    if (References == null)
                    {
                        References = new List <Reference>();
                    }
                    References.Add(new Reference(element, this));
                    break;

                case "in_item_id":
                case "nestbox_id":
                case "civzone_id":
                    break;

                case "nemesis_id":     // Relations with HFs
                case "pregnancy_spouse":
                case "following_unit":
                case "pet_owner_id":
                case "spouse_id":
                case "mother_id":
                case "father_id":
                case "last_attacker_id":
                case "group_leader_id":
                case "draggee_id":
                case "dragger_id":
                case "rider_mount_id":
                case "lover_id":
                    if (valI != -1)
                    {
                        if (RelationIDs == null)
                        {
                            RelationIDs = new Dictionary <string, int>();
                        }
                        RelationIDs.Add(string.Join(" ", element.Name.LocalName.Split('_').Reverse().Skip(1).Reverse().ToArray()), valI);
                    }
                    break;

                case "pregnancy_timer":
                case "pregnancy_caste":
                case "mood_copy":
                case "anon_1":
                case "birth_year":
                case "birth_time":
                case "curse_year":
                case "curse_time":
                case "birth_year_bias":
                case "birth_time_bias":
                case "old_year":
                case "old_time":
                case "unk_238":
                case "mount_type":
                    break;

                default:
                    DFXMLParser.UnexpectedXmlElement(xdoc.Root.Name.LocalName, element, xdoc.Root.ToString());
                    break;
                }
            }
        }
Beispiel #2
0
 public void AddLabor(Product labor)
 {
     Labor.Add(labor);
     labor.Jobs.Add(this);
 }