protected void AssignTacticFormations() { int skirmIndex = -1; ManageFormationCounts(2, 1, 2, 1); _mainInfantry = ChooseAndSortByPriority(Formations, (Formation f) => f.QuerySystem.IsInfantryFormation, (Formation f) => f.IsAIControlled, (Formation f) => f.QuerySystem.FormationPower).FirstOrDefault(); if (_mainInfantry != null) { _mainInfantry.AI.IsMainFormation = true; _mainInfantry.AI.Side = FormationAI.BehaviorSide.Middle; List <Agent> skirmishersList = new List <Agent>(); List <Agent> meleeList = new List <Agent>(); _mainInfantry.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { bool isSkirmisher = false; //for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) //{ // if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) // { // if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown) // { // isSkirmisher = true; // break; // } // } //} if (Utilities.CheckIfSkirmisherAgent(agent)) { isSkirmisher = true; } if (isSkirmisher) { skirmishersList.Add(agent); } else { meleeList.Add(agent); } }); int i = 0; foreach (Formation formation in Formations.ToList()) { formation.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { if (i != 0 && formation.IsInfantry()) { bool isSkirmisher = false; //for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) //{ // if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) // { // if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown) // { // isSkirmisher = true; // break; // } // } //} if (Utilities.CheckIfSkirmisherAgent(agent, 2)) { isSkirmisher = true; } if (isSkirmisher) { skirmishersList.Add(agent); } else { meleeList.Add(agent); } skirmIndex = i; } }); i++; } //Formations.ToList()[1].ApplyActionOnEachUnitViaBackupList(delegate (Agent agent) //{ // bool isSkirmisher = false; // //for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) // //{ // // if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) // // { // // if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown) // // { // // isSkirmisher = true; // // break; // // } // // } // //} // if (agent.HasThrownCached) // { // isSkirmisher = true; // } // if (isSkirmisher) // { // skirmishersList.Add(agent); // } // else // { // meleeList.Add(agent); // } //}); skirmishersList = skirmishersList.OrderBy(o => o.CharacterPowerCached).ToList(); int j = 0; int infCount = Formations.ToList()[0].CountOfUnits + Formations.ToList()[skirmIndex].CountOfUnits; foreach (Agent agent in skirmishersList.ToList()) { if (j < infCount / 4f) { agent.Formation = Formations.ToList()[skirmIndex]; } else { agent.Formation = Formations.ToList()[0]; } j++; } foreach (Agent agent in meleeList.ToList()) { if (j < infCount / 4f) { agent.Formation = Formations.ToList()[skirmIndex]; } else { agent.Formation = Formations.ToList()[0]; } j++; } } _archers = ChooseAndSortByPriority(Formations, (Formation f) => f.QuerySystem.IsRangedFormation, (Formation f) => f.IsAIControlled, (Formation f) => f.QuerySystem.FormationPower).FirstOrDefault(); List <Formation> list = ChooseAndSortByPriority(Formations, (Formation f) => f.QuerySystem.IsCavalryFormation, (Formation f) => f.IsAIControlled, (Formation f) => f.QuerySystem.FormationPower); if (list.Count > 0) { _leftCavalry = list[0]; _leftCavalry.AI.Side = FormationAI.BehaviorSide.Left; if (list.Count > 1) { _rightCavalry = list[1]; _rightCavalry.AI.Side = FormationAI.BehaviorSide.Right; } else { _rightCavalry = null; } } else { _leftCavalry = null; _rightCavalry = null; } _rangedCavalry = ChooseAndSortByPriority(Formations, (Formation f) => f.QuerySystem.IsRangedCavalryFormation, (Formation f) => f.IsAIControlled, (Formation f) => f.QuerySystem.FormationPower).FirstOrDefault(); if (Formations.Count() > skirmIndex && Formations.ToList()[skirmIndex].QuerySystem.IsInfantryFormation) { _skirmishers = Formations.ToList()[skirmIndex]; _skirmishers.AI.IsMainFormation = false; } //if (_skirmishers != null) //{ //_skirmishers.AI.Side = FormationAI.BehaviorSide.BehaviorSideNotSet; //_skirmishers.AI.IsMainFormation = false; //_skirmishers.AI.ResetBehaviorWeights(); //SetDefaultBehaviorWeights(_skirmishers); //team.ClearRecentlySplitFormations(_skirmishers); //_skirmishers = Formations.ToList()[1]; //} IsTacticReapplyNeeded = true; }