public Battle(Person attacker, Person defender, Region region) { PersonList attackers = new PersonList(); attackers.Add(attacker); Init(attackers, defender, region); }
public new PersonList Clone() { PersonList res = new PersonList(); foreach (Person p in this) { res.Add(p); } return(res); }
public PersonList GetTeamAndLeader() { PersonList list = new PersonList(); list.Add(this); foreach (Person p in Team) { list.Add(p); } return(list); }
private void Init(PersonList attackers, Person defender, Region region) { Soldiers = new ArrayList(); ArrayList check_persons = new ArrayList(); this.region = region; // Add attackers and their teams foreach (Person attacker in attackers) { foreach (Person atk in attacker.GetTeamAndLeader()) { if (check_persons.Contains(atk)) { throw new Exception("Soldier already added"); } check_persons.Add(atk); Soldiers.Add(new Soldier(this, atk, Side.Attacker)); FirstDefender++; } } // Add target person and his team if (defender.Leader != null) { foreach (Person def in defender.Leader.GetTeamAndLeader()) { if (check_persons.Contains(def)) { throw new Exception("Soldier already added"); } check_persons.Add(def); Soldiers.Add(new Soldier(this, def, Side.Defender)); } } else { foreach (Person def in defender.GetTeamAndLeader()) { if (check_persons.Contains(def)) { throw new Exception("Soldier already added"); } check_persons.Add(def); Soldiers.Add(new Soldier(this, def, Side.Defender)); } } // Add region patrol foreach (Person p in region.Persons) { if (p.Patrolling && p.AttitudeTo(defender) == Attitude.Ally && !check_persons.Contains(p)) { Soldiers.Add(new Soldier(this, p, Side.Defender)); } } // Remove from attackers all further ATTACK orders directed on defenders for (int i = 0; i < FirstDefender; i++) { Person p = ((Soldier)Soldiers[i]).Person; foreach (Order ord in p.Orders) { if (ord.GetType() == typeof(AttackOrder)) { AttackOrder aord = (AttackOrder)ord; for (int k = FirstDefender; k < Soldiers.Count; k++) { if (aord.PersonNum == ((Soldier)Soldiers[k]).Person.Num) { aord.PersonNum = -1; break; } } } } } BattleReport.Add( String.Format("{0} attacks {1} in {2}!", attackers[0].ToString(Lang.En), defender.ToString(Lang.En), region.ToString(Lang.En)) + String.Format("|{2}: {0} и {1} вступили в бой!", attackers[0].ToString(Lang.Ru), defender.ToString(Lang.Ru), region.ToString(Lang.Ru))); region.BattleReports.Add(BattleReport); BattleReport.Add(""); BattleReport.Add("Attackers:|Атакующие:"); for (int i = 0; i < FirstDefender; i++) { PrintSoldier((Soldier)Soldiers[i]); } BattleReport.Add(""); BattleReport.Add("Defenders:|Защитники:"); for (int i = FirstDefender; i < Soldiers.Count; i++) { PrintSoldier((Soldier)Soldiers[i]); } this.Run(); // Promote skills foreach (Soldier s in Soldiers) { if (!s.Person.Killed && s.Person.Leader == null) { s.PromoteSkill(); } } // Set had-battle flag foreach (Soldier s in Soldiers) { s.Person.HadBattle = true; } // Set AVOID on incapacitated persons foreach (Soldier s in Soldiers) { if (s.OutOfAction && !s.FleedAway && !s.Person.Killed) { s.Person.Avoiding = true; s.Person.Patrolling = false; } } BattleReport.Add(""); if (AttackersOOA == FirstDefender) { BattleReport.Add(String.Format("{0} wins.|{1} побеждает.", defender.ToString(Lang.En), defender.ToString(Lang.Ru))); CollectSpoils(region, false, Side.Defender); DefendersWin = true; } else if (DefendersOOA == Soldiers.Count - FirstDefender) { BattleReport.Add(String.Format("{0} wins.|{1} побеждает.", attackers[0].ToString(Lang.En), attackers[0].ToString(Lang.Ru))); CollectSpoils(region, false, Side.Attacker); AttackersWin = true; } else { BattleReport.Add("The battle is a draw.|Бой закончен вничью."); CollectSpoils(region, true, Side.Attacker); } BattleReport.Add(""); }
public Battle(PersonList attackers, Person defender, Region region) { Init(attackers, defender, region); }