コード例 #1
0
        public static SpaceVehicle testShip(SimulatedEmpire emp, Design <Ship> design, int ID)
        {
            SimulatedSpaceObject simveh = new SimulatedSpaceObject((SpaceVehicle)design.Instantiate());

            simveh.SpaceObject.ID = ID;
            SpaceVehicle spaceveh = (SpaceVehicle)simveh.SpaceObject;

            spaceveh.Owner = emp.Empire;
            emp.SpaceObjects.Add(simveh);
            return(spaceveh);
        }
コード例 #2
0
        private void btnAddVehicle_Click(object sender, EventArgs e)
        {
            var dsn = designReport.Design;

            if (CurrentEmpire == null)
            {
                MessageBox.Show("Please select an empire before clicking\"Add Vehicle\".");
                return;
            }
            if (dsn == null)
            {
                MessageBox.Show("Please select a design before clicking \"Add Vehicle\".");
                return;
            }
            if (IsGroundCombat)
            {
                if (!(dsn is IDesign <Troop>))
                {
                    MessageBox.Show("Only troop designs can be added to the vehicle list for ground combat.");
                    return;
                }
            }
            else
            {
                if (!(dsn is IDesign <SpaceVehicle>))
                {
                    MessageBox.Show("Only space vehicle designs can be added to the vehicle list for space combat.");
                    return;
                }
            }

            // need to set owner *after* copying vehicle!
            if (IsGroundCombat)
            {
                var sv = new SimulatedUnit((Troop)dsn.Instantiate());
                var v  = (Troop)sv.Unit;
                v.Owner = CurrentEmpire.Empire;
                CurrentEmpire.Troops.Add(sv);
            }
            else
            {
                var sv = new SimulatedSpaceObject((SpaceVehicle)dsn.Instantiate());
                var v  = (SpaceVehicle)sv.SpaceObject;
                v.Owner           = CurrentEmpire.Empire;
                v.SupplyRemaining = v.SupplyStorage;
                CurrentEmpire.SpaceObjects.Add(sv);
            }

            BindSpaceObjectList();
        }
コード例 #3
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);
        }
コード例 #4
0
 private void btnAddPlanet_Click(object sender, EventArgs e)
 {
     if (IsGroundCombat)
     {
         MessageBox.Show("Planets cannot be added to ground battles.");
     }
     else
     {
         // TODO - let player choose a planet?
         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 = CurrentEmpire.Empire;
         // TODO - let player choose population?
         simPlanet.Colony.Population.Add(CurrentEmpire.Empire.PrimaryRace, simPlanet.MaxPopulation);
         CurrentEmpire.SpaceObjects.Add(sim);
         BindSpaceObjectList();
     }
 }