private static void AssignTacticalMarines(Dictionary <int, PlayerSoldier> unassignedSoldierMap, Unit chapter, string year, Faction faction, List <PlayerSoldier> tactList, List <PlayerSoldier> tactSgtList) { SoldierTemplate tactType = faction.SoldierTemplates.Values.First(st => st.Name == "Tactical Marine"); SoldierTemplate tactSgtType = faction.SoldierTemplates.Values.First(st => st.Name == "Sergeant"); foreach (Unit company in chapter.ChildUnits) { foreach (Squad squad in company.Squads) { if (squad.SquadTemplate.Name == "Tactical Squad") { if (tactSgtList.Count > 0) { squad.Name = tactSgtList[0].Name.Split(' ')[1] + " Squad"; AssignSoldier(unassignedSoldierMap, tactSgtList, squad, tactSgtType, year); } int tactSquadSize = CalculateSquadSize(tactList, tactSgtList); while (tactList.Count > 0 && squad.Members.Count < tactSquadSize) { AssignSoldier(unassignedSoldierMap, tactList, squad, tactType, year); } } } } }
private static void AssignSpecialistsToSquad(Dictionary <int, PlayerSoldier> unassignedSoldierMap, Squad squad, string year, SoldierTemplate specialistType, List <PlayerSoldier> sortedCandidates) { // minor hack to avoid assigning non-veteran specialists to veteran HQ squads if (squad == null || sortedCandidates.Count == 0 || (squad.SquadTemplate.SquadType & SquadTypes.Elite) > 0) { return; } IEnumerable <SquadTemplateElement> elements = squad.SquadTemplate.Elements .Where(e => e.SoldierTemplate == specialistType); foreach (SquadTemplateElement element in elements) { if (sortedCandidates.Count == 0) { return; } for (int i = 0; i < element.MinimumNumber; i++) { if (sortedCandidates.Count == 0) { return; } // assign top to HQ AssignSoldier(unassignedSoldierMap, sortedCandidates, squad, specialistType, year); } } }
private static void AddSquad(Squad squad) { squad.IsInReserve = false; foreach (SquadTemplateElement element in squad.SquadTemplate.Elements) { SoldierTemplate template = element.SoldierTemplate; Soldier[] soldiers = SoldierFactory.Instance.GenerateNewSoldiers(element.MaximumNumber, template); foreach (Soldier soldier in soldiers) { squad.AddSquadMember(soldier); soldier.AssignedSquad = squad; soldier.Template = template; soldier.Name = $"{soldier.Template.Name} {soldier.Id}"; } } if (squad.SquadTemplate.WeaponOptions != null) { foreach (SquadWeaponOption weaponOption in squad.SquadTemplate.WeaponOptions) { int taking = RNG.GetIntBelowMax(weaponOption.MinNumber, weaponOption.MaxNumber + 1); int maxIndex = weaponOption.Options.Count; for (int i = 0; i < taking; i++) { squad.Loadout.Add(weaponOption.Options[RNG.GetIntBelowMax(0, maxIndex)]); } } } }
private Dictionary <int, List <SquadTemplateElement> > GetSquadTemplateElementsBySquadId(IDbConnection connection, Dictionary <int, SoldierTemplate> soldierTemplateMap) { Dictionary <int, List <SquadTemplateElement> > elementsMap = new Dictionary <int, List <SquadTemplateElement> >(); IDbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM SquadTemplateElement"; var reader = command.ExecuteReader(); while (reader.Read()) { int squadTemplateId = reader.GetInt32(1); int soldierTemplateId = reader.GetInt32(2); int min = reader.GetInt32(3); int max = reader.GetInt32(4); SoldierTemplate template = soldierTemplateMap[soldierTemplateId]; if (!elementsMap.ContainsKey(squadTemplateId)) { elementsMap[squadTemplateId] = new List <SquadTemplateElement>(); } elementsMap[squadTemplateId].Add(new SquadTemplateElement(template, (byte)min, (byte)max)); } return(elementsMap); }
public Soldier[] GenerateNewSoldiers(int count, SoldierTemplate template) { Soldier[] soldierArray = new Soldier[count]; for (int i = 0; i < count; i++) { soldierArray[i] = GenerateNewSoldier(template); } return(soldierArray); }
private static void AssignExcessToScouts(Dictionary <int, PlayerSoldier> unassignedSoldierMap, Unit chapter, string year, Faction faction) { int sgtNeed = ((unassignedSoldierMap.Count - 1) / 10) + 1; var leaderList = unassignedSoldierMap.Values.OrderByDescending(s => s.LeadershipRating).Take(sgtNeed).ToList(); var scoutList = unassignedSoldierMap.Values.Except(leaderList).ToList(); Unit lastCompany = null; Squad lastSquad = null; SoldierTemplate scoutSgt = faction.SoldierTemplates.Values.First(st => st.Name == "Scout Sergeant"); SoldierTemplate scout = faction.SoldierTemplates.Values.First(st => st.Name == "Scout Marine"); foreach (Unit company in chapter.ChildUnits) { lastCompany = company; foreach (Squad squad in company.Squads) { if ((squad.SquadTemplate.SquadType & SquadTypes.Scout) > 0) { lastSquad = squad; // assign sgt to squad squad.Name = leaderList[0].Name.Split(' ')[1] + " Squad"; AssignSoldier(unassignedSoldierMap, leaderList, squad, scoutSgt, year); while (squad.Members.Count < 10 && scoutList.Count > 0) { AssignSoldier(unassignedSoldierMap, scoutList, squad, scout, year); } } } } while (scoutList.Count > 0 || leaderList.Count > 0) { int id = lastSquad.Id + 1; // add a new Scout Squad to the company Squad squad = new Squad("Scout Squad", lastCompany, faction.SquadTemplates.Values.First(st => st.Name == "Scout Squad")); lastCompany.AddSquad(squad); id++; lastSquad = squad; // assign sgt to squad squad.Name = leaderList[0].Name.Split(' ')[1] + " Squad"; AssignSoldier(unassignedSoldierMap, leaderList, squad, scoutSgt, year); //int squadSize = CalculateSquadSize(scoutList, leaderList); while (squad.Members.Count < 10 && scoutList.Count > 0) { AssignSoldier(unassignedSoldierMap, scoutList, squad, scout, year); } } if (unassignedSoldierMap.Count > 0) { Debug.WriteLine("Still did it wrong"); } }
public Soldier GenerateNewSoldier(SoldierTemplate template) { Soldier soldier = GenerateNewSoldier(template.Species, null); foreach (Tuple <BaseSkill, float> skillBoost in template.MosTraining) { soldier.AddSkillPoints(skillBoost.Item1, skillBoost.Item2); } return(soldier); }
private static void AssignSoldier(Dictionary <int, PlayerSoldier> unassignedSoldierMap, List <PlayerSoldier> soldierList, Squad squad, SoldierTemplate type, string year) { var soldier = soldierList[0]; soldier.Template = type; squad.AddSquadMember(soldier); soldier.AssignedSquad = squad; soldier.AddEntryToHistory(year + ": promoted to " + soldier.Template.Name + " and assigned to " + soldier.AssignedSquad.Name); unassignedSoldierMap.Remove(soldier.Id); soldierList.RemoveAt(0); }
private static void AssignDevastatorMarines(Dictionary <int, PlayerSoldier> unassignedSoldierMap, Unit chapter, string year, Faction faction, List <PlayerSoldier> devList, List <PlayerSoldier> devSgtList) { SoldierTemplate devType = faction.SoldierTemplates.Values.First(st => st.Name == "Devastator Marine"); SoldierTemplate devSgtType = faction.SoldierTemplates.Values.First(st => st.Name == "Sergeant (D)"); // since Devastators are assigned last, make sure the dev to sgt list is reasonable while (devSgtList.Count() * 9 >= devList.Count()) { // turn the last Sgt into a dev var demote = devSgtList[devSgtList.Count - 1]; devList.Add(demote); devSgtList.Remove(demote); } foreach (Unit company in chapter.ChildUnits) { foreach (Squad squad in company.Squads) { /*foreach(SquadTemplateElement element in squad.SquadTemplate.Elements) * { * if(element.SoldierType == devType) * { * * } * }*/ if (squad.SquadTemplate.Name == "Devastator Squad") { if (devSgtList.Count > 0) { squad.Name = devSgtList[0].Name.Split(' ')[1] + " Squad"; AssignSoldier(unassignedSoldierMap, devSgtList, squad, devSgtType, year); } int devSquadSize = CalculateSquadSize(devList, devSgtList); while (devList.Count > 0 && squad.Members.Count < devSquadSize) { AssignSoldier(unassignedSoldierMap, devList, squad, devType, year); } } } } }
private static void PopulateOrderOfBattle(string year, Dictionary <int, PlayerSoldier> unassignedSoldierMap, Unit oob, Faction faction) { // first, assign the Librarians AssignLibrarians(unassignedSoldierMap, oob, year, faction); // then, assign up to the top 50 as Techmarines AssignTechMarines(unassignedSoldierMap, oob, year, faction); // then, assign the top leader as Chapter Master AssignChapterMaster(unassignedSoldierMap, oob, year, faction); // then, assign Captains AssignCaptains(unassignedSoldierMap, oob, year, faction); // then, assigned twenty apothecaries AssignApothecaries(unassignedSoldierMap, oob, year, faction); // then, assign twenty Chaplains AssignChaplains(unassignedSoldierMap, oob, year, faction); // any dual gold awards are assigned to the first company AssignVeterans(unassignedSoldierMap, oob, year, faction); // assign Champtions to the CM and each Company var champions = unassignedSoldierMap.Values .OrderByDescending(s => s.MeleeRating) .ToList(); SoldierTemplate championType = faction.SoldierTemplates .Values .First(st => st.Name == "Champion"); AssignSpecialistsToUnit(unassignedSoldierMap, oob, year, championType, champions); // assign Ancients to the CM and each Company var ancients = unassignedSoldierMap.Values .OrderByDescending(s => s.AncientRating) .ToList(); SoldierTemplate ancientType = faction.SoldierTemplates .Values .First(st => st.Name == "Ancient"); AssignSpecialistsToUnit(unassignedSoldierMap, oob, year, ancientType, ancients); // assign all other soldiers who got at least bronze in one skill, starting with the second company AssignMarines(unassignedSoldierMap, oob, year, faction); //Assign excess to scouts AssignExcessToScouts(unassignedSoldierMap, oob, year, faction); }
private IEnumerable <SoldierTemplate> GetOpeningsInSquad(Squad squad, Squad currentSquad, SoldierTemplate soldierTemplate) { List <SoldierTemplate> openSpots = new List <SoldierTemplate>(); bool hasSquadLeader = squad.SquadLeader != null; // get the count of each soldier type in the squad // compare to the max count of each type Dictionary <SoldierTemplate, int> typeCountMap = squad.Members.GroupBy(s => s.Template) .ToDictionary(g => g.Key, g => g.Count()); foreach (SquadTemplateElement element in squad.SquadTemplate.Elements) { // if the squad has no squad leader, only squad leader elements can be added now if (!hasSquadLeader && !element.SoldierTemplate.IsSquadLeader) { continue; } if (currentSquad == squad && element.SoldierTemplate == soldierTemplate) { continue; } if (element.SoldierTemplate.Rank < soldierTemplate.Rank || element.SoldierTemplate.Rank > soldierTemplate.Rank + 1) { continue; } int existingHeadcount = 0; if (typeCountMap.ContainsKey(element.SoldierTemplate)) { existingHeadcount += typeCountMap[element.SoldierTemplate]; } if (existingHeadcount < element.MaximumNumber) { openSpots.Add(element.SoldierTemplate); } } return(openSpots); }
private List <Tuple <int, SoldierTemplate, string> > GetOpeningsInUnit(Unit unit, Squad currentSquad, SoldierTemplate soldierTemplate) { List <Tuple <int, SoldierTemplate, string> > openSlots = new List <Tuple <int, SoldierTemplate, string> >(); IEnumerable <SoldierTemplate> squadSlots; if (unit.HQSquad != null) { squadSlots = GetOpeningsInSquad(unit.HQSquad, currentSquad, soldierTemplate); if (squadSlots.Count() > 0) { foreach (SoldierTemplate template in squadSlots) { openSlots.Add(new Tuple <int, SoldierTemplate, string>( unit.HQSquad.Id, template, $"{template.Name}, {unit.HQSquad.Name}, {unit.Name}")); } } } foreach (Squad squad in unit.Squads) { squadSlots = GetOpeningsInSquad(squad, currentSquad, soldierTemplate); if (squadSlots.Count() > 0) { foreach (SoldierTemplate template in squadSlots) { openSlots.Add(new Tuple <int, SoldierTemplate, string>(squad.Id, template, $"{template.Name}, {squad.Name}, {unit.Name}")); } } } foreach (Unit childUnit in unit.ChildUnits ?? Enumerable.Empty <Unit>()) { openSlots.AddRange(GetOpeningsInUnit(childUnit, currentSquad, soldierTemplate)); } return(openSlots); }
private Dictionary <int, List <SoldierTemplate> > GetSoldierTemplatesByFactionId( IDbConnection connection, Dictionary <int, List <Tuple <BaseSkill, float> > > soldierTemplateTrainingMap, Dictionary <int, List <Species> > speciesMap) { Dictionary <int, List <SoldierTemplate> > soldierTemplatesByFactionId = new Dictionary <int, List <SoldierTemplate> >(); IDbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM SoldierTemplate"; var reader = command.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); int factionId = reader.GetInt32(1); int speciesId = reader.GetInt32(2); string name = reader[3].ToString(); int rank = reader.GetInt32(4); bool isSquadLeader = (bool)reader[5]; List <Tuple <BaseSkill, float> > trainingList = null; if (soldierTemplateTrainingMap.ContainsKey(id)) { trainingList = soldierTemplateTrainingMap[id]; } var species = speciesMap[factionId].First(s => s.Id == speciesId); SoldierTemplate soldierTemplate = new SoldierTemplate(id, species, name, isSquadLeader, (byte)rank, trainingList); if (!soldierTemplatesByFactionId.ContainsKey(factionId)) { soldierTemplatesByFactionId[factionId] = new List <SoldierTemplate>(); } soldierTemplatesByFactionId[factionId].Add(soldierTemplate); } return(soldierTemplatesByFactionId); }
private static void AssignSpecialistsToUnit(Dictionary <int, PlayerSoldier> unassignedSoldierMap, Unit chapter, string year, SoldierTemplate specialistType, List <PlayerSoldier> sortedCandidates) { AssignSpecialistsToSquad(unassignedSoldierMap, chapter.HQSquad, year, specialistType, sortedCandidates); foreach (Squad squad in chapter.Squads) { AssignSpecialistsToSquad(unassignedSoldierMap, squad, year, specialistType, sortedCandidates); } foreach (Unit company in chapter.ChildUnits) { AssignSpecialistsToSquad(unassignedSoldierMap, company.HQSquad, year, specialistType, sortedCandidates); foreach (Squad squad in chapter.Squads) { AssignSpecialistsToSquad(unassignedSoldierMap, squad, year, specialistType, sortedCandidates); } } }
public SquadTemplateElement(SoldierTemplate soldierTemplate, byte minNumber, byte maxNumber) { SoldierTemplate = soldierTemplate; MinimumNumber = minNumber; MaximumNumber = maxNumber; }