private static Unit GenerateNewArmy(PlanetFaction planetFaction, Planet planet) { int factionId = planetFaction.Faction.Id; // if we got here, the assaulting force doesn't have an army generated // generate an army (and decrement it from the population Unit newArmy = TempArmyBuilder.GenerateArmyFromPlanetFaction(planetFaction); if (!planet.FactionSquadListMap.ContainsKey(factionId)) { planet.FactionSquadListMap[factionId] = new List <Squad>(); } // add unit to faction planetFaction.Faction.Units.Add(newArmy); // add unit to planet foreach (Squad squad in newArmy.GetAllSquads()) { squad.IsInReserve = false; squad.Location = planet; planet.FactionSquadListMap[factionId].Add(squad); } // modify planetFaction based on new unit int headcount = newArmy.GetAllMembers().Count(); float ratio = ((float)planetFaction.PDFMembers) / (planetFaction.Population + planetFaction.PDFMembers); int pdfHeadcount = (int)(headcount * ratio); headcount -= pdfHeadcount; planetFaction.PDFMembers -= pdfHeadcount; if (planetFaction.PDFMembers < 0) { headcount -= planetFaction.PDFMembers; planetFaction.PDFMembers = 0; } planetFaction.Population -= headcount; if (planetFaction.Population < 0) { planetFaction.Population = 0; // TODO: remove this planetFaction from the planet? } return(newArmy); }
private void PlaceStartingForces() { // For now, put the chapter on their home planet foreach (Planet planet in GameSettings.Galaxy.Planets) { if (planet.ControllingFaction == GameSettings.Galaxy.PlayerFaction) { planet.FactionSquadListMap[GameSettings.Galaxy.PlayerFaction.Id] = GameSettings.Chapter.SquadMap.Values.ToList(); SetChapterSquadsLocation(planet); foreach (Fleet fleet in GameSettings.Chapter.Fleets) { fleet.Planet = planet; fleet.Position = planet.Position; GameSettings.Galaxy.AddNewFleet(fleet); } } else if (planet.ControllingFaction.UnitTemplates != null) { int potentialArmies = planet.ControllingFaction .UnitTemplates .Values .Where(ut => ut.IsTopLevelUnit) .Count(); // TODO: generalize this Unit newArmy = TempArmyBuilder.GenerateArmy( RNG.GetIntBelowMax(0, potentialArmies), planet.ControllingFaction); planet.ControllingFaction.Units.Add(newArmy); planet.FactionSquadListMap[planet.ControllingFaction.Id] = newArmy.GetAllSquads().ToList(); foreach (Squad squad in newArmy.GetAllSquads()) { squad.Location = planet; } } } }