Esempio n. 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            IBattle battle;

            if (IsGroundCombat)
            {
                // TODO - let player pick a planet to fight on, or at least specify population for militia
                var template = Mod.Current.StellarObjectTemplates.OfType <Planet>().Where(p => p.Atmosphere == CurrentEmpire.Empire.PrimaryRace.NativeAtmosphere).PickRandom();
                var planet   = template.Instantiate();
                planet.Name = "Planet";
                var sim       = new SimulatedSpaceObject(planet);
                var simPlanet = (Planet)sim.SpaceObject;
                simPlanet.Colony       = new Colony();
                simPlanet.Colony.Owner = Empires.First().Empire;
                simPlanet.Sector       = new Sector(new StarSystem(0)
                {
                    Name = "Simulation"
                }, new Point());
                foreach (Troop t in Empires.SelectMany(se => se.Troops.Select(ss => ss.Unit)))
                {
                    planet.Cargo.Units.Add(t);
                }
                battle = new GroundBattle(planet);

                // simulate the battle
                battle.Resolve();
            }
            else
            {
                Sector location = new Sector(new StarSystem(0), new Point());
                foreach (ISpaceObject ispobj in (Empires.SelectMany(se => se.SpaceObjects.Select(ss => ss.SpaceObject))))
                {
                    ispobj.Sector = location;
                }
                // create battle with all our combatants
                //var battle = new Battle_Space(Empires.SelectMany(se => se.SpaceObjects.Select(ss => ss.SpaceObject)));
                battle = new SpaceBattle(location);

                // simulate the battle
                battle.Resolve();
            }

            // show the results
            var form = new BattleResultsForm(battle);

            Cursor = Cursors.Default;
            this.ShowChildForm(form);
        }