Ejemplo 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);
        }
Ejemplo n.º 2
0
        private void lstLog_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var item = lstLog.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                var message = (LogMessage)item.Tag;
                if (message is IPictorialLogMessage <IPictorial> )
                {
                    var context = ((IPictorialLogMessage <IPictorial>)message).Context;
                    if (context is ISpaceObject)
                    {
                        // go to space object
                        mainGameForm.SelectSpaceObject((ISpaceObject)context);
                        Close();
                    }
                    else if (context is IUnit)
                    {
                        // go to whatever contains the unit
                        var unit      = (IUnit)context;
                        var container = unit.FindContainer();
                        if (container != null)
                        {
                            if (container is Sector)
                            {
                                mainGameForm.SelectSpaceObject((ISpaceObject)unit);
                            }
                            else
                            {
                                mainGameForm.SelectSpaceObject((ISpaceObject)container);
                            }
                            Close();
                        }
                    }
                    else if (context is Facility)
                    {
                        // go to the planet
                        var facility  = (Facility)context;
                        var container = facility.Container;
                        mainGameForm.SelectSpaceObject(container);
                        Close();
                    }
                    else if (context is Technology)
                    {
                        // go to research screen
                        mainGameForm.ShowResearchForm();
                        Close();
                    }
                    else if (context is IHull <IVehicle> )
                    {
                        // go to design screen and create a new design using this hull
                        var hull = (IHull <IVehicle>)context;
                        mainGameForm.ShowVehicleDesignForm(new VehicleDesignForm(hull));
                        Close();
                    }
                    else if (context is ComponentTemplate || context is Mount)
                    {
                        // go to design screen
                        mainGameForm.ShowVehicleDesignForm(new VehicleDesignForm());
                        Close();
                    }
                    else if (context is IBattle)
                    {
                        // show battle results
                        var form = new BattleResultsForm((IBattle)context);
                        this.ShowChildForm(form);
                    }
                    else if (context is IMessage)
                    {
                        // show diplomacy screen
                        var form = new DiplomacyForm((IMessage)context);
                        mainGameForm.ShowChildForm(form);
                        Close();
                    }
                    else if (context is StarSystem sys)
                    {
                        // navigate game form to that system
                        mainGameForm.SelectStarSystem(sys);
                        Close();
                    }

                    // TODO - more types of goto-messages
                }
            }
        }