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(); }
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); }
private void CollectSpoils(Region r, bool draw, Side winner) { ArrayList spoil_lists = new ArrayList(); spoil_lists.Add(Spoils); foreach (Soldier s in Soldiers) { if (s.OutOfAction && !s.FleedAway) { if (s.Person.Killed) { // If person killed, add items to Spoils for (int i = s.Person.Items.Count - 1; i >= 0; i--) { Item itm = s.Person.Items[i]; if (!itm.Type.NoGive) { s.Person.Items.RemoveAt(i); Spoils.AddItems(itm.Type, itm.Amount); } } } else if (!draw && s.Side != winner) { // If person stunned, allow to marauder givable items from it spoil_lists.Add(s.Person.Items); } } // If person killed, drop "drops" to Spoils if (s.OutOfAction && s.Person.Killed && s.Person.Man.Drops.Count > 0) { foreach (Item itm in s.Person.Man.Drops) { Spoils.AddItems(itm.Type, itm.Amount); } } } if (!draw) { foreach (Soldier s in Soldiers) { if (s.OutOfAction) { continue; } int space = s.Person.GetCapacity(Movement.Walk) - s.Person.GetWeight(); ItemList taken = new ItemList(); // Get item requested in spoils if (s.Person.Spoils.Count > 0) { foreach (ItemType wanted in s.Person.Spoils) { if (wanted.NoGive) { continue; } for (int i = spoil_lists.Count - 1; i >= 0; i--) { ItemList list = (ItemList)spoil_lists[i]; Item item = list.GetByType(wanted); if (item == null) { continue; } int amt; if (item.Type.Weight == 0) { amt = Math.Min(item.Amount, Constants.Random(20)); } else { amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight; } if (amt == 0) { continue; } s.Person.Items.AddItems(item.Type, amt); space -= item.Type.Weight * amt; list.RemoveItems(item.Type, amt); if (list.Count == 0) { spoil_lists.Remove(list); } taken.AddItems(item.Type, amt); } if (taken.Count > 0) { break; } } } // Get random items from spoils (as much as soldier can carry) if (taken.Count == 0) { int attempt = 0; while (attempt < 2) { if (spoil_lists.Count == 0) { break; } int list_idx = Constants.Random(spoil_lists.Count); ItemList givable = new ItemList(); foreach (Item itm in (ItemList)spoil_lists[list_idx]) { if (!itm.Type.NoGive) { givable.Add(itm); } } if (givable.Count == 0) { spoil_lists.RemoveAt(list_idx); continue; } int item_idx = Constants.Random(givable.Count); Item item = givable[item_idx]; int amt; if (item.Type.Weight == 0) { amt = Math.Min(item.Amount, Constants.Random(20)); } else { amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight; } if (amt > 0) { s.Person.Items.AddItems(item.Type, amt); space -= item.Type.Weight * amt; ((ItemList)spoil_lists[list_idx]).RemoveItems(item.Type, amt); taken.AddItems(item.Type, amt); } attempt++; } } if (taken.Count > 0) { BattleReport.Add(String.Format("{0} takes {1}|{2} берёт: {3}", s.Person.ToString(Lang.En), taken.ToString(Lang.En), s.Person.ToString(Lang.Ru), taken.ToString(Lang.Ru))); } } } // Add untaken spoils to Junk for (int i = Spoils.Count - 1; i >= 0; i--) { r.Junk.AddItems(Spoils[i].Type, Spoils[i].Amount); } }