private void Save() { if (changedLoad) { if (clTo.CargoContainer is ICargoTransferrer) { // loading from a ship, planet, etc. var order = new TransferCargoOrder(true, clLoad.CargoDelta, (ICargoTransferrer)clTo.CargoContainer); ((ICargoTransferrer)clFrom.CargoContainer).IssueOrder(order); } else if (clTo.CargoContainer is Sector) { // recovering from space // NOTE - if movement orders prior to this order are changed, the sector being recovered from will change! var order = new TransferCargoOrder(true, clLoad.CargoDelta, null); ((ICargoTransferrer)clFrom.CargoContainer).IssueOrder(order); } changedLoad = false; } if (changedDrop) { if (clTo.CargoContainer is ICargoTransferrer) { // dropping to a ship, planet, etc. var order = new TransferCargoOrder(false, clDrop.CargoDelta, (ICargoTransferrer)clTo.CargoContainer); ((ICargoTransferrer)clFrom.CargoContainer).IssueOrder(order); } else if (clTo.CargoContainer is Sector) { // launching to space // NOTE - if movement orders prior to this order are changed, the sector being launched to will change! var order = new TransferCargoOrder(false, clDrop.CargoDelta, null); ((ICargoTransferrer)clFrom.CargoContainer).IssueOrder(order); } changedDrop = false; } }
private void colonizeToolStripMenuItem_Click(object sender, EventArgs e) { var p = (Planet)grid.SelectedItem; if (p == null) { MessageBox.Show("No planet is selected to colonize."); return; } var goodColonizers = availableColonizers.Where(c => c.HasAbility("Colonize Planet - " + p.Surface)); if (!goodColonizers.Any()) { MessageBox.Show("We have no colonizers capable of landing on a " + p.Surface + " planet."); return; } var paths = goodColonizers.Select(c => new { Colonizer = c, Path = Pathfinder.Pathfind(c, c.Sector, p.Sector, true, true, c.DijkstraMap) }); var goodPaths = paths.Where(path => path.Path.Last() == p.Sector); if (!goodPaths.Any()) { MessageBox.Show("We have no colonizers capable of reaching " + p + "."); } var shortest = paths.WithMin(path => path.Path.Count()).First(); var colonizer = (MajorSpaceVehicle)shortest.Colonizer; // HACK - what if units want to colonize? // load population // prefer population of breathers of target planet's atmosphere - don't load nonbreathers races if breathers are present bool foundBreathers = false; var planets = colonizer.FinalSector().SpaceObjects.OfType <Planet>().Where(pl => pl.Owner == Empire.Current); foreach (var pHere in planets) { var delta = new CargoDelta(); foreach (var kvp in pHere.AllPopulation) { if (kvp.Key.NativeAtmosphere == p.Atmosphere) { delta.RacePopulation[kvp.Key] = null; // load all population of this race foundBreathers = true; } } if (foundBreathers) { var loadPopOrder = new TransferCargoOrder(true, delta, pHere); colonizer.IssueOrder(loadPopOrder); } } if (!foundBreathers) { foreach (var pHere in planets) { var delta = new CargoDelta(); delta.AllPopulation = true; var loadPopOrder = new TransferCargoOrder(true, delta, pHere); colonizer.IssueOrder(loadPopOrder); } } // move and colonize colonizer.IssueOrder(new MoveOrder(p.Sector, true)); colonizer.IssueOrder(new ColonizeOrder(p)); }