示例#1
0
        private static TradeOrder ReadTradeOrder(string s)
        {
            TradeOrder ord = new TradeOrder();

            string t1 = MyStrings.GetToken(ref s).ToLower();

            if (t1 == "with")
            {
                string num = MyStrings.GetToken(ref s);
                if (!MyStrings.IsNumber(num))
                {
                    throw new Exception("Bad target");
                }
                ord.PersonNum = Convert.ToInt32(num);
                t1            = MyStrings.GetToken(ref s).ToLower();
            }
            else
            {
                ord.PersonNum = 0;
            }

            if (t1 == "all")
            {
                ord.SellAmount = -1;
            }
            else
            {
                if (!MyStrings.IsNumber(t1))
                {
                    throw new Exception("Bad sell amount");
                }
                ord.SellAmount = Convert.ToInt32(t1);
            }

            ord.SellWhat = ItemType.GetByAnyName(MyStrings.GetQuotedToken(ref s));
            if (ord.SellWhat == null)
            {
                throw new Exception("Bad sell item");
            }

            string t2 = MyStrings.GetToken(ref s).ToLower();

            if (t2 == "all")
            {
                ord.BuyAmount = -1;
            }
            else
            {
                if (!MyStrings.IsNumber(t2))
                {
                    throw new Exception("Bad buy amount");
                }
                ord.BuyAmount = Convert.ToInt32(t2);
            }

            ord.BuyWhat = ItemType.GetByAnyName(MyStrings.GetQuotedToken(ref s));
            if (ord.BuyWhat == null)
            {
                throw new Exception("Bad buy item");
            }

            return(ord);
        }
示例#2
0
        private static XmlElement WritePerson(XmlElement parent, Person p)
        {
            XmlElement elPerson = doc.CreateElement("person");

            parent.AppendChild(elPerson);
            if (faction.Options.Lang == Lang.En)
            {
                elPerson.SetAttribute("name", MyStrings.Translit(p.Name));
                if (p.Description != "")
                {
                    elPerson.SetAttribute("description", MyStrings.Translit(p.Description));
                }
            }
            else
            {
                elPerson.SetAttribute("name", p.Name);
                if (p.Description != "")
                {
                    elPerson.SetAttribute("description", p.Description);
                }
            }
            elPerson.SetAttribute("n", p.Num.ToString());

            // Faction
            if (p.Faction == faction || !p.HideFaction)
            {
                ShowFaction(p.Faction);
                elPerson.SetAttribute("faction", p.Faction.Num.ToString());
            }

            // Flags
            if (p.IsDangerouslyInsane())
            {
                elPerson.SetAttribute("insane", "True");
            }
            if (p.Chosen)
            {
                elPerson.SetAttribute("chosen", "True");
            }
            if (p.Patrolling)
            {
                elPerson.SetAttribute("patrolling", "True");
            }
            if (p.Age <= Constants.ChildTurns)
            {
                elPerson.SetAttribute("child", "True");
            }

            if (p.Faction == faction)
            {
                if (p.Avoiding)
                {
                    elPerson.SetAttribute("avoiding", "True");
                }
                if (p.Greedy)
                {
                    elPerson.SetAttribute("greedy", "True");
                }
                if (p.Hide)
                {
                    elPerson.SetAttribute("hiding", "person");
                }
                else if (p.HideFaction)
                {
                    elPerson.SetAttribute("hiding", "faction");
                }
            }

            // Items
            foreach (Item itm in p.Items)
            {
                if (itm.Type.Weight == 0 && p.Faction != faction)
                {
                    continue;
                }
                AddItem(elPerson, itm, "item");
            }

            if (p.Faction == faction)
            {
                foreach (Skill sk in p.Skills)
                {
                    AddSkill(elPerson, sk, "skill");
                }

                elPerson.SetAttribute("insanity", p.Insanity.ToString());
                int hire = p.GetHireAmount();
                if (hire >= 1)
                {
                    elPerson.SetAttribute("hire-demand", hire.ToString());
                }

                foreach (ItemType it in p.Consume)
                {
                    AddItemType(elPerson, it, "consume");
                }
                foreach (ItemType it in p.Burn)
                {
                    AddItemType(elPerson, it, "burn");
                }
                foreach (ItemType it in p.Equipment)
                {
                    AddItemType(elPerson, it, "equipment");
                }
                foreach (ItemType it in p.Spoils)
                {
                    AddItemType(elPerson, it, "spoils");
                }
            }
            else if (!faction.IsNPC)
            {
                // Show talents of other factions' persons if Chosen in region
                Person chosen = faction.GetChosen();
                if (chosen != null && p.Region == chosen.Region)
                {
                    foreach (Skill sk in p.Skills)
                    {
                        if (sk.Type.BasedOn == null)
                        {
                            XmlElement el = doc.CreateElement("skill");
                            elPerson.AppendChild(el);
                            el.SetAttribute("id", sk.Type.Name);
                            ShowSkillType(sk.Type);
                        }
                    }
                }
            }

            // Trade order
            if (p.TradeOrder != null)
            {
                Person receiver = null;
                if (p.TradeOrder.PersonNum != 0)
                {
                    receiver = p.Region.Persons.GetByNumber(p.TradeOrder.PersonNum);
                }
                if (p.TradeOrder.PersonNum == 0 || (receiver != null && receiver.Faction == faction))
                {
                    XmlElement elTrade = doc.CreateElement("trade");
                    elPerson.AppendChild(elTrade);
                    AddItem(elTrade, new Item(p.TradeOrder.SellWhat, p.TradeOrder.SellAmount), "sell");
                    AddItem(elTrade, new Item(p.TradeOrder.BuyWhat, p.TradeOrder.BuyAmount), "buy");
                    if (receiver != null)
                    {
                        elTrade.SetAttribute("with", receiver.Num.ToString());
                    }
                }
            }

            // Orders
            if (p.Faction == faction)
            {
                string orders = "";
                foreach (string s in p.RepeatingLines)
                {
                    if (orders != "")
                    {
                        orders += "\\n";
                    }
                    orders += s.Replace("\\", "\\\\").Replace("<", "").Replace(">", "");
                }
                if (orders != "")
                {
                    XmlElement elOrders = doc.CreateElement("orders");
                    elOrders.InnerText = orders;
                    elPerson.AppendChild(elOrders);
                }
            }

            return(elPerson);
        }
示例#3
0
        public static void Load(string filename, bool checker)
        {
            TextReader tr = new StreamReader(filename, System.Text.Encoding.GetEncoding(1251));

            bool      do_read       = false;
            Person    person        = null;
            Faction   faction       = null;
            bool      errors        = false;
            ArrayList CheckerOutput = new ArrayList();

            while (true)
            {
                try
                {
                    string line = tr.ReadLine();
                    string s    = line;
                    if (s == null)
                    {
                        break;
                    }

                    // Store repeating lines
                    if (s.Length > 0 && s[0] == '@')
                    {
                        if (person != null)
                        {
                            person.RepeatingLines.Add(line);
                        }
                        s = s.Substring(1);
                    }

                    // Strip comments
                    s = MyStrings.Uncomment(s).Trim();

                    // Get first word as command
                    string cmd = MyStrings.GetToken(ref s).ToLower();

                    // Directives
                    if (cmd == "#orders")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad faction");
                        }
                        int    num      = Convert.ToInt32(t2);
                        string password = MyStrings.GetQuotedToken(ref s);
                        faction = (Faction)Faction.Get(num);
                        if (faction == null)
                        {
                            throw new Exception("No such faction");
                        }
                        if (password != faction.Password || faction.IsNPC)
                        {
                            throw new Exception("Wrong password");
                        }

                        Console.WriteLine("..orders for " + faction.Num.ToString());

                        CheckerOutput.Add("To: " + faction.Email);
                        CheckerOutput.Add("Subject: Checker Output");
                        CheckerOutput.Add("");
                        CheckerOutput.Add(line);

                        do_read = true;
                        continue;
                    }
                    if (cmd == "#end")
                    {
                        do_read = false;
                    }
                    if (!do_read || cmd == "")
                    {
                        continue;
                    }
                    if (cmd == "person")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad person");
                        }
                        int num = Convert.ToInt32(t2);
                        person = faction.Persons.GetByNumber(num);
                        if (person == null)
                        {
                            throw new Exception("This person is not in your faction");
                        }
                        CheckerOutput.Add("\r\n" + line);
                        continue;
                    }

                    CheckerOutput.Add(line);

                    if (person == null)
                    {
                        throw new Exception("Order given with no person specified");
                    }

                    Order order;

                    if (cmd == "address")
                    {
                        order = ReadAddressOrder(s);
                    }
                    else if (cmd == "attack")
                    {
                        order = ReadPersonNumOrder(s, new AttackOrder());
                    }
                    else if (cmd == "avoid")
                    {
                        order = ReadAvoidOrder(s);
                    }
                    else if (cmd == "build")
                    {
                        order = ReadBuildOrder(s);
                    }
                    else if (cmd == "burn")
                    {
                        order = ReadItemTypeListOrder(s, new BurnOrder());
                    }
                    else if (cmd == "consume")
                    {
                        order = ReadItemTypeListOrder(s, new ConsumeOrder());
                    }
                    else if (cmd == "cure")
                    {
                        order = ReadCureOrder(s);
                    }
                    else if (cmd == "declare")
                    {
                        order = ReadDeclareOrder(faction, s);
                    }
                    else if (cmd == "describe")
                    {
                        order = ReadDescribeOrder(s);
                    }
                    else if (cmd == "drive")
                    {
                        order = ReadDriveOrder(s);
                    }
                    else if (cmd == "enter")
                    {
                        order = ReadEnterOrder(s);
                    }
                    else if (cmd == "equipment")
                    {
                        order = ReadItemTypeListOrder(s, new EquipmentOrder());
                    }
                    else if (cmd == "evict")
                    {
                        order = ReadPersonNumOrder(s, new EvictOrder());
                    }
                    else if (cmd == "give")
                    {
                        order = ReadGiveOrder(s);
                    }
                    else if (cmd == "hide")
                    {
                        order = ReadHideOrder(s);
                    }
                    else if (cmd == "install")
                    {
                        order = ReadInstallOrder(s);
                    }
                    else if (cmd == "kick")
                    {
                        order = new KickOrder();
                    }
                    else if (cmd == "leave")
                    {
                        order = new LeaveOrder();
                    }
                    else if (cmd == "maintain")
                    {
                        order = new MaintainOrder();
                    }
                    else if (cmd == "move")
                    {
                        order = ReadMoveOrder(s);
                    }
                    else if (cmd == "name")
                    {
                        order = ReadNameOrder(s);
                    }
                    else if (cmd == "option")
                    {
                        order = ReadOptionOrder(s);
                    }
                    else if (cmd == "password")
                    {
                        order = ReadPasswordOrder(s);
                    }
                    else if (cmd == "patrol")
                    {
                        order = new PatrolOrder();
                    }
                    else if (cmd == "produce")
                    {
                        order = ReadProduceOrder(s);
                    }
                    else if (cmd == "quit")
                    {
                        order = ReadQuitOrder(s, faction);
                    }
                    else if (cmd == "scavenge")
                    {
                        order = ReadItemTypeListOrder(s, new ScavengeOrder());
                    }
                    else if (cmd == "show")
                    {
                        order = ReadShowOrder(s);
                    }
                    else if (cmd == "team")
                    {
                        order = ReadTeamOrder(s);
                    }
                    else if (cmd == "trade")
                    {
                        order = ReadTradeOrder(s);
                    }
                    else if (cmd == "uninstall")
                    {
                        order = ReadUninstallOrder(s);
                    }
                    else
                    {
                        throw new Exception("Bad order");
                    }

                    // Overwrite monthlong order
                    if (order.IsMonthlong)
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (((Order)person.Orders[i]).IsMonthlong)
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous monthlong order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    // Overwrite trade order
                    if (order.GetType() == typeof(TradeOrder))
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (person.Orders[i].GetType() == typeof(TradeOrder))
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous trade order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    person.Orders.Add(order);
                }
                catch (Exception ex)
                {
                    CheckerOutput.Add("; **** " + ex.Message + " ****\r\n");
                    errors = true;
                }
            }

            tr.Close();

            if (checker)
            {
                TextWriter tw = new StreamWriter(filename + ".checker", false, System.Text.Encoding.GetEncoding(1251));
                if (errors)
                {
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                    }
                }
                else
                {
                    // Write only message header
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                        if (s == "")
                        {
                            break;
                        }
                    }
                    tw.WriteLine("Your order was accepted without errors.");
                }
                tw.Close();
            }
        }
示例#4
0
        public static string Generate(Faction f)
        {
            faction = f;
            doc     = new XmlDocument();
            doc.LoadXml("<report/>");
            XmlElement elReport = doc.DocumentElement;

            elReport.AppendChild(doc.CreateElement("factions"));
            elReport.AppendChild(doc.CreateElement("items"));
            elReport.AppendChild(doc.CreateElement("skills"));
            elReport.AppendChild(doc.CreateElement("objects"));
            elReport.AppendChild(doc.CreateElement("terrains"));
            foreach (ItemType it in faction.ItemsToShow)
            {
                ShowItemType(it);
            }
            foreach (SkillType st in faction.SkillsToShow)
            {
                ShowSkillType(st);
            }
            foreach (BuildingType bt in faction.BuildingsToShow)
            {
                ShowBuildingType(bt);
            }
            foreach (int faction_num in faction.Attitudes.Keys)
            {
                if (Faction.Get(faction_num) != null)
                {
                    ShowFaction(Faction.Get(faction_num));
                }
            }

            // Header
            elReport.SetAttribute("for", faction.Num.ToString());
            elReport.SetAttribute("turn", Map.Turn.ToString());
            if (faction.Options.Lang == Lang.En)
            {
                elReport.SetAttribute("season", Month.Current.NameEn);
            }
            else
            {
                elReport.SetAttribute("season", Month.Current.NameRu);
            }
            elReport.SetAttribute("engine", MainClass.EngineVersion);
            elReport.SetAttribute("password", faction.Password);
            if (faction.Options.Lang == Lang.En)
            {
                elReport.SetAttribute("language", "en");
            }
            else
            {
                elReport.SetAttribute("language", "ru");
            }
            ShowFaction(faction);

            // Events
            XmlElement elEvents = doc.CreateElement("events");

            elReport.AppendChild(elEvents);
            foreach (Event evt in faction.Events)
            {
                XmlElement elEvent = doc.CreateElement("event");
                elEvents.AppendChild(elEvent);
                if (evt.Person != null)
                {
                    elEvent.SetAttribute("n", evt.Person.Num.ToString());
                    if (evt.Person.Faction != faction)
                    {
                        elEvent.SetAttribute("name", evt.Person.Name);
                    }
                }
                elEvent.SetAttribute("text", evt.ToString(faction.Options.Lang, false));
            }

            // Regions
            XmlElement elMap = doc.CreateElement("map");

            elReport.AppendChild(elMap);
            elMap.SetAttribute("width", Map.Width.ToString());
            elMap.SetAttribute("height", Map.Height.ToString());

            foreach (Region r in Map.Regions)
            {
                // Is region visible
                int j = r.Persons.Count - 1;
                while (j >= 0 && ((Person)r.Persons[j]).Faction != faction)
                {
                    j--;
                }
                if (j < 0)
                {
                    continue;
                }

                // Print region
                XmlElement elRegion = doc.CreateElement("region");
                elMap.AppendChild(elRegion);
                elRegion.SetAttribute("x", r.X.ToString());
                elRegion.SetAttribute("y", r.Y.ToString());
                AddTerrainAttribute(elRegion, r.Terrain, "terrain");
                if (faction.Options.Lang == Lang.En)
                {
                    elRegion.SetAttribute("in", MyStrings.Translit(r.Name));
                }
                else
                {
                    elRegion.SetAttribute("in", r.Name);
                }

                Map.Turn++;
                elRegion.SetAttribute("weather", r.Weather.ToString(faction.Options.Lang));
                elRegion.SetAttribute("t", r.Temperature.ToString());
                elRegion.SetAttribute("radiation", r.Radiation.ToString());
                foreach (Item itm in r.TurnResources)
                {
                    AddItem(elRegion, itm, "res");
                }
                Map.Turn--;

                foreach (Item itm in r.Junk)
                {
                    AddItem(elRegion, itm, "junk");
                }

                // Exits
                for (Direction i = Direction.North; i <= Direction.Northwest; i++)
                {
                    Region exit = r.RegionInDir((Direction)i);
                    if (exit == null)
                    {
                        continue;
                    }
                    XmlElement elExit = doc.CreateElement("exit");
                    elRegion.AppendChild(elExit);
                    elExit.SetAttribute("to", Map.DirectionNames[(int)i - 1]);
                    elExit.SetAttribute("x", exit.X.ToString());
                    elExit.SetAttribute("y", exit.Y.ToString());
                    AddTerrainAttribute(elExit, exit.Terrain, "terrain");
                    if (faction.Options.Lang == Lang.En)
                    {
                        elExit.SetAttribute("in", MyStrings.Translit(exit.Name));
                    }
                    else
                    {
                        elExit.SetAttribute("in", exit.Name);
                    }
                }

                // Persons
                WritePersons(elRegion, r, null);

                // Buildings and persons inside
                foreach (Building b in r.Buildings)
                {
                    XmlElement elBuilding = doc.CreateElement("obj");
                    elRegion.AppendChild(elBuilding);

                    if (faction.Options.Lang == Lang.En)
                    {
                        elBuilding.SetAttribute("name", MyStrings.Translit(b.Name));
                        if (b.Description != "")
                        {
                            elBuilding.SetAttribute("description", MyStrings.Translit(b.Description));
                        }
                    }
                    else
                    {
                        elBuilding.SetAttribute("name", b.Name);
                        if (b.Description != "")
                        {
                            elBuilding.SetAttribute("description", b.Description);
                        }
                    }

                    elBuilding.SetAttribute("n", b.Num.ToString());
                    elBuilding.SetAttribute("id", b.Type.Name);
                    ShowBuildingType(b.Type);

                    foreach (Item itm in b.Installed)
                    {
                        AddItem(elBuilding, itm, "item");
                    }
                    foreach (Item itm in b.GetNeeds())
                    {
                        AddItem(elBuilding, itm, "needs");
                    }

                    WritePersons(elBuilding, r, b);
                }
            }

            return("<?xml version=\"1.0\" encoding=\"windows-1251\"?>" +
                   doc.OuterXml);
        }
示例#5
0
        private static void WritePerson(Person p, Faction f, int indent)
        {
            Lang lng = faction.Options.Lang;

            string s = "";

            if (p.Faction == f)
            {
                s = "* ";
            }
            else
            {
                s = "- ";
            }
            for (int i = 0; i < indent; i++)
            {
                s = "  " + s;
            }
            s += p.ToString(lng);

            if (p.Faction == f || !p.HideFaction)
            {
                s += ", " + p.Faction.ToString(lng);
            }

            if (p.IsDangerouslyInsane())
            {
                s += (lng == Lang.En ? ", insane" : ", безумен");
            }
            if (p.Chosen)
            {
                s += (lng == Lang.En ? ", chosen one" : ", избранный");
            }
            if (p.Patrolling)
            {
                s += (lng == Lang.En ? ", patrolling" : ", патрулирует");
            }
            if (p.Age <= Constants.ChildTurns)
            {
                s += (lng == Lang.En ? ", child" : ", ребёнок");
            }

            if (p.Faction == f)
            {
                if (p.Avoiding)
                {
                    s += (lng == Lang.En ? ", avoiding" : ", избегает боя");
                }
                if (p.Greedy)
                {
                    s += (lng == Lang.En ? ", greedy" : ", не делится");
                }
                if (p.Hide)
                {
                    s += (lng == Lang.En ? ", hiding" : ", скрывается");
                }
                else if (p.HideFaction)
                {
                    s += (lng == Lang.En ? ", hiding faction" : ", скрывает фракцию");
                }
            }

            if (p.Faction == faction)
            {
                s += ", " + p.Items.ToString(lng);
            }
            else
            {
                ItemList items = new ItemList();
                foreach (Item itm in p.Items)
                {
                    if (itm.Type.Weight > 0)
                    {
                        items.Add(itm);
                    }
                }
                s += ", " + items.ToString(lng);
            }

            if (p.Faction == f)
            {
                int weight = p.GetWeight();
                if (p.Man != null)
                {
                    weight -= p.Man.Weight;
                }

                s += (lng == Lang.En ? " Load: " : " Груз: ") +
                     weight.ToString() + ((lng == Lang.En) ? " kg." : " кг.");
                s += (lng == Lang.En ? " Skills: " : " Навыки: ") +
                     p.Skills.ToString(lng);

                if (p.Consume.Count > 0)
                {
                    s += (lng == Lang.En ? " Consuming: " : " Еда: ") +
                         p.Consume.ToString(lng);
                }
                if (p.Burn.Count > 0)
                {
                    s += (lng == Lang.En ? " Burning: " : " Топливо: ") +
                         p.Burn.ToString(lng);
                }
                if (p.Equipment.Count > 0)
                {
                    s += (lng == Lang.En ? " Equipment: " : " Снаряжение: ") +
                         p.Equipment.ToString(lng);
                }
                if (p.Spoils.Count > 0)
                {
                    s += (lng == Lang.En ? " Wanted spoils: " : " Желаемые трофеи: ") +
                         p.Spoils.ToString(lng);
                }

                s += (lng == Lang.En ? " Insanity: " : " Безумие: ") +
                     p.Insanity.ToString() + ".";

                int hire = p.GetHireAmount();
                if (hire == 1)
                {
                    s += (lng == Lang.En ? " Hire demand: day ration." : " Найм: дневной рацион.");
                }
                else if (hire > 1)
                {
                    s += String.Format((lng == Lang.En ? " Hire demand: {0} day rations." :
                                        " Найм: {0} рационов."), hire);
                }

                int rad_danger   = Math.Abs(p.RadiationDanger(true));
                int tempr_danger = p.TemperatureDanger(true);

                if (rad_danger > 0 || tempr_danger > 0)
                {
                    s += (lng == Lang.En ? " Danger:" : " Опасность:");
                    if (rad_danger > 0)
                    {
                        s += " " + rad_danger.ToString() + (lng == Lang.En ? " mR/h" : " мР/ч");
                    }
                    if (tempr_danger > 0)
                    {
                        if (rad_danger > 0)
                        {
                            s += ",";
                        }
                        s += " " + tempr_danger.ToString() + (lng == Lang.En ? "°C" : "°C");
                    }
                    s += ".";
                }
            }
            else if (!f.IsNPC)
            {
                // Show talents of other factions' persons if Chosen in region
                Person chosen = f.GetChosen();
                if (chosen != null && p.Region == chosen.Region)
                {
                    SkillTypeList talents = new SkillTypeList();
                    foreach (Skill sk in p.Skills)
                    {
                        if (sk.Type.BasedOn == null)
                        {
                            talents.Add(sk.Type);
                        }
                    }
                    s += (lng == Lang.En ? " Skills: " : " Навыки: ") +
                         talents.ToString(lng);
                }
            }

            if (p.TradeOrder != null)
            {
                Person receiver = null;
                if (p.TradeOrder.PersonNum != 0)
                {
                    receiver = p.Region.Persons.GetByNumber(p.TradeOrder.PersonNum);
                }
                if (p.TradeOrder.PersonNum == 0 || (receiver != null && receiver.Faction == f))
                {
                    if (lng == Lang.En)
                    {
                        s += " Trade: sells " + p.TradeOrder.SellWhat.ToString(p.TradeOrder.SellAmount, Lang.En) +
                             " for " + p.TradeOrder.BuyWhat.ToString(p.TradeOrder.BuyAmount, Lang.En);
                        if (receiver != null)
                        {
                            s += " to " + receiver.ToString(Lang.En);
                        }
                        s += ".";
                    }
                    else
                    {
                        s += " Бартер: предлагает: " + p.TradeOrder.SellWhat.ToString(p.TradeOrder.SellAmount, Lang.Ru) +
                             ", просит: " + p.TradeOrder.BuyWhat.ToString(p.TradeOrder.BuyAmount, Lang.Ru);
                        if (receiver != null)
                        {
                            s += ", покупатель:  " + receiver.ToString(Lang.Ru);
                        }
                        s += ".";
                    }
                }
            }

            if (p.Description != "")
            {
                if (lng == Lang.En)
                {
                    s = s.Substring(0, s.Length - 1) + "; " + MyStrings.Translit(p.Description);
                }
                else
                {
                    s = s.Substring(0, s.Length - 1) + "; " + p.Description;
                }
            }

            Write(s);
        }
示例#6
0
        private static void GenerateFaction(string filename)
        {
            Faction f = faction;

            tw = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding(1251));

            // Header
            Write("To: " + f.Email);
            Write("Subject: [Wasteland] Report for turn " + Map.Turn.ToString());
            Write("Content-Disposition: attachment");
            Write("");
            Write("Wasteland Report For:|Отчёт фракции:");
            Write(f.ToString(lng));
            Write(String.Format("Turn {0}, {1}|Ход {0}, {2}",
                                Map.Turn, Month.Current.NameEn, Month.Current.NameRu));
            Write("");

            if (f.Options.TextReport)
            {
                // Engine
                Write("Wasteland Engine Version: " + MainClass.EngineVersion +
                      "|Версия сервера Wasteland: " + MainClass.EngineVersion);
                Write("");

                if (!faction.IsNPC)
                {
                    // Skill reports
                    if (f.SkillsToShow.Count > 0)
                    {
                        Write("Skill reports:|Описания навыков:");
                        Write("");
                        foreach (SkillType st in f.SkillsToShow)
                        {
                            WriteSkillReport(st);
                        }
                    }

                    // Item reports
                    if (f.ItemsToShow.Count > 0)
                    {
                        Write("Item reports:|Описания вещей:");
                        Write("");
                        foreach (ItemType it in f.ItemsToShow)
                        {
                            WriteItemReport(it);
                        }
                    }

                    // Object reports
                    if (f.BuildingsToShow.Count > 0)
                    {
                        Write("Object reports:|Описания объектов:");
                        Write("");
                        foreach (BuildingType bt in f.BuildingsToShow)
                        {
                            WriteBuildingReport(bt);
                        }
                    }

                    // Battles
                    foreach (Region r in Map.Regions)
                    {
                        if (r.BattleReports.Count == 0 || (!RegionIsVisible(r, f) &&
                                                           !f.BattleRegions.Contains(r)))
                        {
                            continue;
                        }

                        Write("Battle reports:|Отчёты о сражениях:");
                        Write("");
                        foreach (ArrayList BattleReport in r.BattleReports)
                        {
                            foreach (object obj in BattleReport)
                            {
                                if (obj.GetType() == typeof(string))
                                {
                                    Write((string)obj);
                                }
                                else
                                {
                                    Write(((ILocalized)obj).ToString(lng));
                                }
                            }
                            Write("");
                        }
                    }
                }

                // Events
                Write("Events during turn:|События этого хода:");
                foreach (Event obj in f.Events)
                {
                    Write(obj.ToString(lng));
                }
                Write("");

                // The Greatest
                if (Faction.TheGreatest != null && Faction.TheGreatest.GetChosen() != null)
                {
                    Write(String.Format("Rumors are, {0} is the strongest leader in Wasteland.|" +
                                        "Люди говорят, что самый сильный вождь Пустошей - {1}.",
                                        Faction.TheGreatest.GetChosen().ToString(Lang.En) + ", " +
                                        Faction.TheGreatest.ToString(Lang.En),
                                        Faction.TheGreatest.GetChosen().ToString(Lang.Ru) + ", " +
                                        Faction.TheGreatest.ToString(Lang.Ru)));
                    Write("");
                }

                // Attitudes
                Write(String.Format("Declared Attitudes (default {0}):|Отношения (по умолчанию {0}):",
                                    f.DefaultAttitude.ToString()));
                for (Attitude a = Attitude.Hostile; a <= Attitude.Ally; a++)
                {
                    Write(a + " : " + AttitudeListString(f, a));
                }
                Write("");

                // Regions
                foreach (Region r in Map.Regions)
                {
                    if (!faction.IsNPC && !RegionIsVisible(r, f))
                    {
                        continue;
                    }

                    // Print region
                    Write("");
                    Write(r.ToString(lng));
                    Write("------------------------------------------------------------");

                    // Weather and resources shown is for next turn
                    Map.Turn++;
                    Write(String.Format("  Weather forecast: {0}, {1}°C, {2} mR/h.|" +
                                        "  Прогноз погоды: {3}, {1}°C, {2} мР/ч.",
                                        r.Weather.ToString(Lang.En), r.Temperature,
                                        r.Radiation, r.Weather.ToString(Lang.Ru)));
                    Write((lng == Lang.En ? "  Resources: " : "  Ресурсы: ") +
                          r.TurnResources.ToString(lng));
                    Map.Turn--;

                    Write((lng == Lang.En ? "  Junk: " : "  Мусор: ") +
                          r.Junk.ToString(lng));

                    Write("");

                    // Exits
                    Write("Exits:|Выходы:");
                    for (Direction i = Direction.North; i <= Direction.Northwest; i++)
                    {
                        Region exit = r.RegionInDir((Direction)i);
                        if (exit != null)
                        {
                            if (lng == Lang.Ru)
                            {
                                Write("  " + Map.DirectionFullNamesRu[(int)i - 1] + " : " + exit.ToString(lng));
                            }
                            else
                            {
                                Write("  " + i.ToString() + " : " + exit.ToString(lng));
                            }
                        }
                    }
                    Write("");

                    // Persons
                    WritePersons(r, null, f);
                    Write("");

                    // Buildings and persons inside
                    foreach (Building b in r.Buildings)
                    {
                        string s = "+ " + b.ToString(lng) + " : " + b.Type.ToString(lng);
                        if (b.Installed.Count > 0)
                        {
                            s += ", " + b.Installed.ToString(lng);
                        }
                        else
                        {
                            s += ".";
                        }
                        ItemList needs = b.GetNeeds();
                        if (needs.Count > 0)
                        {
                            s += (lng == Lang.En ? " Needs: " : " Нужно: ") + needs.ToString(lng);
                        }

                        if (b.Description != "")
                        {
                            if (lng == Lang.En)
                            {
                                s = s.Substring(0, s.Length - 1) + "; " + MyStrings.Translit(b.Description);
                            }
                            else
                            {
                                s = s.Substring(0, s.Length - 1) + "; " + b.Description;
                            }
                        }

                        Write(s);
                        WritePersons(r, b, f);
                        Write("");
                    }
                }

                if (faction.IsNPC)
                {
                    return;
                }

                // Orders template
                Write("");
                Write("Orders Template:|Шаблон приказов:");
                Write("");
                Write(String.Format("#orders {0} \"{1}\"", f.Num, f.Password));
                Write("");

                foreach (Person p in f.Persons)
                {
                    if (f.Options.Template == TemplateType.Long)
                    {
                        string line = (lng == Lang.En ? MyStrings.Translit(p.Name) : p.Name);
                        foreach (SkillType talent in p.GetTalents())
                        {
                            line += ", " + (lng == Lang.En ? talent.FullNameEn : talent.FullNameRu);
                        }
                        line += ".";
                        if (p.Leader != null)
                        {
                            line += (lng == Lang.En ? " Leader: " : " Бригадир: ") +
                                    (lng == Lang.En ? MyStrings.Translit(p.Leader.Name) : p.Leader.Name) + ".";
                        }

                        while (true)
                        {
                            int j = 70;
                            while (line.Length > j && line[j] != ' ')
                            {
                                j--;
                            }
                            if (line.Length > j)
                            {
                                tw.WriteLine(";" + line.Substring(0, j));
                                line = line.Substring(j + 1);
                            }
                            else
                            {
                                tw.WriteLine(";" + line);
                                break;
                            }
                        }
                    }

                    Write(String.Format("person {0}", p.Num));
                    foreach (string s in p.RepeatingLines)
                    {
                        Write(s);
                    }
                    Write("");
                }

                Write("#end");
                Write("");
            }

            if (faction.Options.XmlReport)
            {
                Write("");
                Write("XML version (for client applications):|XML-версия (для программ-клиентов):");
                Write("");
                Write(XmlReport.Generate(faction), false, false);

                /*
                 * TextWriter tw1 = new StreamWriter("report.xml", false, System.Text.Encoding.GetEncoding(1251));
                 * tw1.Write(XmlReport.Generate(faction));
                 * tw1.Close();
                 */
            }

            tw.Close();
            f.AllShown();
        }
示例#7
0
        public static void Load(string folder)
        {
            if (folder == "")
            {
                folder = Directory.GetCurrentDirectory();
            }
            DirectoryInfo di = new DirectoryInfo(folder);

            foreach (FileInfo fi in di.GetFiles("request.*"))
            {
                TextReader tr = new StreamReader(fi.FullName, Encoding.GetEncoding(1251));

                string email        = "";
                string faction_name = "Faction";
                string gender       = "MAN";
                string chosen_name  = "";
                string special      = "";
                Lang   lng          = Lang.En;
                bool   body         = false;

                while (true)
                {
                    string s = tr.ReadLine();
                    if (s == null)
                    {
                        break;
                    }
                    if (s.Trim() == "")
                    {
                        body = true;
                    }

                    if (s.IndexOf(":") == -1)
                    {
                        continue;
                    }
                    string name = s.Substring(0, s.IndexOf(":")).ToLower();
                    string val  = s.Substring(s.IndexOf(":") + 2);

                    if (name == "from")
                    {
                        email = val;
                    }

                    if (!body)
                    {
                        continue;
                    }

                    if (name == "faction")
                    {
                        faction_name = MyStrings.GetValidString(val);
                    }
                    if (name == "chosen" && val.ToLower() == "woman")
                    {
                        gender = "WOMA";
                    }
                    if (name == "name")
                    {
                        chosen_name = MyStrings.GetValidString(val);
                    }
                    if (name == "language" && val.ToLower() == "ru")
                    {
                        lng = Lang.Ru;
                    }
                    if (name == "skill")
                    {
                        special = val;
                    }
                }
                tr.Close();

                if (email != "")
                {
                    // Create new faction
                    Faction f = new Faction();
                    f.Email        = email;
                    f.Name         = faction_name;
                    f.Options.Lang = lng;
                    for (int i = 0; i < 6; i++)
                    {
                        f.Password += (Char)('a' + Constants.Random('z' - 'a'));
                    }

                    // Select region with less faction players and monsters and more wanderers
                    Region r        = Map.Regions[Constants.Random(Map.Regions.Count)];
                    int    unwanted = 0;
                    int    wanted   = 0;
                    foreach (Person p in r.Persons)
                    {
                        if (!p.Faction.IsNPC || p.Man.IsMonster)
                        {
                            unwanted++;
                        }
                        else
                        {
                            wanted++;
                        }
                    }

                    int j     = Map.Regions.IndexOf(r);
                    int start = j;
                    while (true)
                    {
                        j++;
                        if (j >= Map.Regions.Count)
                        {
                            j = 0;
                        }
                        if (j == start)
                        {
                            break;
                        }
                        Region r2 = Map.Regions[j];
                        if (r2._radiation >= 90 || r2.Radiation >= 90 || !r2.Terrain.Walking)
                        {
                            continue;
                        }
                        int unwanted2 = 0;
                        int wanted2   = 0;
                        foreach (Person p in r2.Persons)
                        {
                            if (!p.Faction.IsNPC || p.Man.IsMonster || p.Insanity >= Constants.DangerousInsanity)
                            {
                                unwanted2++;
                            }
                            else
                            {
                                wanted2++;
                            }
                        }

                        if (unwanted2 < unwanted ||
                            (unwanted2 == unwanted && wanted2 > wanted))
                        {
                            r        = r2;
                            unwanted = unwanted2;
                            wanted   = wanted2;
                        }
                    }

                    if (r._radiation >= 90 || !r.Terrain.Walking)
                    {
                        throw new Exception("What region you picked you?");
                    }

                    // Create Chosen One
                    Person chosen = new Person(f, r);
                    chosen.Chosen = true;
                    if (chosen_name != "")
                    {
                        chosen.Name = chosen_name;
                    }
                    else
                    {
                        chosen.Name = NameGenerator.Name(gender);
                    }
                    chosen.Avoiding = true;

                    chosen.AddItems(ItemType.Get(gender), 1);
                    foreach (Item itm in DataFile.ChosenItems)
                    {
                        chosen.AddItems(itm.Type, itm.Amount);
                    }
                    foreach (Skill sk in DataFile.ChosenSkills)
                    {
                        chosen.AddSkill(sk.Type).Level = sk.Level;
                    }

                    // Special skill
                    if (special != "")
                    {
                        SkillType spec = SkillType.GetByAnyName(special);
                        if (spec != null)
                        {
                            Skill spec_skill = DataFile.ChosenSpecial.GetByType(spec);
                            if (spec_skill != null)
                            {
                                chosen.AddSkill(spec_skill.Type).Level = spec_skill.Level;
                            }
                        }
                    }

                    // Show all buildable objects
                    foreach (Skill sk in chosen.Skills)
                    {
                        foreach (BuildingType bt in BuildingType.List)
                        {
                            if (!bt.NoBuild && bt.Materials.Count > 0 &&
                                bt.Materials[0].Type.InstallSkill.Type == sk.Type)
                            {
                                f.ShowBuilding(bt);
                            }
                        }
                    }

                    Console.WriteLine("..Faction created for " + email);
                }
            }
        }
示例#8
0
        public static void Load(string filename, bool checker)
        {
            TextReader tr = new StreamReader(filename, System.Text.Encoding.GetEncoding(1251));

            bool      do_read       = false;
            Person    person        = null;
            Faction   faction       = null;
            bool      errors        = false;
            ArrayList CheckerOutput = new ArrayList();

            while (true)
            {
                try
                {
                    string line = tr.ReadLine();
                    string s    = line;
                    if (s == null)
                    {
                        break;
                    }

                    // Store repeating lines
                    if (s.Length > 0 && s[0] == '@')
                    {
                        if (person != null)
                        {
                            person.RepeatingLines.Add(line);
                        }
                        s = s.Substring(1);
                    }

                    // Strip comments
                    s = MyStrings.Uncomment(s).Trim();

                    // Get first word as command
                    string cmd = MyStrings.GetToken(ref s).ToLower();

                    // Directives
                    if (cmd == "#orders")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad faction");
                        }
                        int    num      = Convert.ToInt32(t2);
                        string password = MyStrings.GetQuotedToken(ref s);
                        faction = (Faction)Faction.Get(num);
                        if (faction == null)
                        {
                            throw new Exception("No such faction");
                        }
                        if (password != faction.Password || faction.IsNPC)
                        {
                            throw new Exception("Wrong password");
                        }

                        Console.WriteLine("..orders for " + faction.Num.ToString());

                        CheckerOutput.Add("To: " + faction.Email);
                        CheckerOutput.Add("Subject: [Wasteland] Checker Output");
                        CheckerOutput.Add("");
                        CheckerOutput.Add(line);

                        do_read = true;
                        continue;
                    }
                    if (cmd == "#end")
                    {
                        do_read = false;
                    }
                    if (!do_read || cmd == "")
                    {
                        continue;
                    }
                    if (cmd == "person")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad person");
                        }
                        int num = Convert.ToInt32(t2);
                        person = faction.Persons.GetByNumber(num);
                        if (person == null)
                        {
                            throw new Exception("This person is not in your faction");
                        }
                        CheckerOutput.Add("\r\n" + line);
                        continue;
                    }

                    CheckerOutput.Add(line);

                    if (person == null)
                    {
                        throw new Exception("Order given with no person specified");
                    }

                    Order order = OrdersReader.ParseOrder(person, faction, cmd, s);

                    // Overwrite monthlong order
                    if (order.IsMonthlong)
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (((Order)person.Orders[i]).IsMonthlong)
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous monthlong order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    // Overwrite trade order
                    if (order.GetType() == typeof(TradeOrder))
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (person.Orders[i].GetType() == typeof(TradeOrder))
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous trade order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    person.Orders.Add(order);
                }
                catch (Exception ex)
                {
                    CheckerOutput.Add("; **** " + ex.Message + " ****\r\n");
                    errors = true;
                }
            }

            tr.Close();

            if (checker)
            {
                string checkername = Path.Combine(Path.GetDirectoryName(filename),
                                                  "checker." + Path.GetFileName(filename));
                TextWriter tw = new StreamWriter(checkername, false, System.Text.Encoding.GetEncoding(1251));
                if (errors)
                {
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                    }
                }
                else
                {
                    // Write only message header
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                        if (s == "")
                        {
                            break;
                        }
                    }
                    tw.WriteLine("Your order was accepted without errors.");
                }
                tw.Close();
            }
        }